git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@576370 13f79535-47bb-0310-9956-ffa450edef68master
@@ -39,6 +39,8 @@ import org.apache.tools.bzip2.CBZip2InputStream; | |||||
public class BUnzip2 extends Unpack { | public class BUnzip2 extends Unpack { | ||||
private static final int BUFFER_SIZE = 8 * 1024; | |||||
private static final String DEFAULT_EXTENSION = ".bz2"; | private static final String DEFAULT_EXTENSION = ".bz2"; | ||||
/** | /** | ||||
@@ -74,7 +76,7 @@ public class BUnzip2 extends Unpack { | |||||
throw new BuildException("Invalid bz2 file.", getLocation()); | throw new BuildException("Invalid bz2 file.", getLocation()); | ||||
} | } | ||||
zIn = new CBZip2InputStream(bis); | zIn = new CBZip2InputStream(bis); | ||||
byte[] buffer = new byte[8 * 1024]; | |||||
byte[] buffer = new byte[BUFFER_SIZE]; | |||||
int count = 0; | int count = 0; | ||||
do { | do { | ||||
out.write(buffer, 0, count); | out.write(buffer, 0, count); | ||||
@@ -58,6 +58,12 @@ import org.apache.tools.ant.util.StringUtils; | |||||
* @ant.task category="control" | * @ant.task category="control" | ||||
*/ | */ | ||||
public class Checksum extends MatchingTask implements Condition { | public class Checksum extends MatchingTask implements Condition { | ||||
private static final int NIBBLE = 4; | |||||
private static final int WORD = 16; | |||||
private static final int BUFFER_SIZE = 8 * 1024; | |||||
private static final int BYTE_MASK = 0xFF; | |||||
private static class FileUnion extends Restrict { | private static class FileUnion extends Restrict { | ||||
private Union u; | private Union u; | ||||
FileUnion() { | FileUnion() { | ||||
@@ -144,7 +150,7 @@ public class Checksum extends MatchingTask implements Condition { | |||||
/** | /** | ||||
* Size of the read buffer to use. | * Size of the read buffer to use. | ||||
*/ | */ | ||||
private int readBufferSize = 8 * 1024; | |||||
private int readBufferSize = BUFFER_SIZE; | |||||
/** | /** | ||||
* Formater for the checksum file. | * Formater for the checksum file. | ||||
@@ -572,7 +578,7 @@ public class Checksum extends MatchingTask implements Condition { | |||||
private String createDigestString(byte[] fileDigest) { | private String createDigestString(byte[] fileDigest) { | ||||
StringBuffer checksumSb = new StringBuffer(); | StringBuffer checksumSb = new StringBuffer(); | ||||
for (int i = 0; i < fileDigest.length; i++) { | for (int i = 0; i < fileDigest.length; i++) { | ||||
String hexStr = Integer.toHexString(0x00ff & fileDigest[i]); | |||||
String hexStr = Integer.toHexString(BYTE_MASK & fileDigest[i]); | |||||
if (hexStr.length() < 2) { | if (hexStr.length() < 2) { | ||||
checksumSb.append("0"); | checksumSb.append("0"); | ||||
} | } | ||||
@@ -604,9 +610,9 @@ public class Checksum extends MatchingTask implements Condition { | |||||
// two characters form the hex value. | // two characters form the hex value. | ||||
for (int i = 0, j = 0; j < l; i++) { | for (int i = 0, j = 0; j < l; i++) { | ||||
int f = Character.digit(data[j++], 16) << 4; | |||||
f = f | Character.digit(data[j++], 16); | |||||
out[i] = (byte) (f & 0xFF); | |||||
int f = Character.digit(data[j++], WORD) << NIBBLE; | |||||
f = f | Character.digit(data[j++], WORD); | |||||
out[i] = (byte) (f & BYTE_MASK); | |||||
} | } | ||||
return out; | return out; | ||||
@@ -43,13 +43,13 @@ import org.apache.tools.ant.util.FileUtils; | |||||
*/ | */ | ||||
public class ExecTask extends Task { | public class ExecTask extends Task { | ||||
// CheckStyle:VisibilityModifier OFF - bc | |||||
private static final FileUtils FILE_UTILS = FileUtils.getFileUtils(); | private static final FileUtils FILE_UTILS = FileUtils.getFileUtils(); | ||||
private String os; | private String os; | ||||
private String osFamily; | private String osFamily; | ||||
private File dir; | private File dir; | ||||
// CheckStyle:VisibilityModifier OFF - bc | |||||
protected boolean failOnError = false; | protected boolean failOnError = false; | ||||
protected boolean newEnvironment = false; | protected boolean newEnvironment = false; | ||||
private Long timeout = null; | private Long timeout = null; | ||||
@@ -433,7 +433,7 @@ public class ExecTask extends Task { | |||||
if (environment != null) { | if (environment != null) { | ||||
for (int i = 0; i < environment.length; i++) { | for (int i = 0; i < environment.length; i++) { | ||||
if (isPath(environment[i])) { | if (isPath(environment[i])) { | ||||
p = new Path(getProject(), environment[i].substring(5)); | |||||
p = new Path(getProject(), getPath(environment[i])); | |||||
break; | break; | ||||
} | } | ||||
} | } | ||||
@@ -444,7 +444,7 @@ public class ExecTask extends Task { | |||||
while (e.hasMoreElements()) { | while (e.hasMoreElements()) { | ||||
String line = (String) e.nextElement(); | String line = (String) e.nextElement(); | ||||
if (isPath(line)) { | if (isPath(line)) { | ||||
p = new Path(getProject(), line.substring(5)); | |||||
p = new Path(getProject(), getPath(line)); | |||||
break; | break; | ||||
} | } | ||||
} | } | ||||
@@ -703,7 +703,11 @@ public class ExecTask extends Task { | |||||
} | } | ||||
private boolean isPath(String line) { | private boolean isPath(String line) { | ||||
return line.startsWith("PATH=") || line.startsWith("Path="); | |||||
return line.startsWith("PATH=") | |||||
|| line.startsWith("Path="); | |||||
} | } | ||||
private String getPath(String line) { | |||||
return line.substring("PATH=".length()); | |||||
} | |||||
} | } |
@@ -49,6 +49,8 @@ import org.apache.tools.ant.util.StringUtils; | |||||
*/ | */ | ||||
public class Execute { | public class Execute { | ||||
private static final int ONE_SECOND = 1000; | |||||
/** Invalid exit code. | /** Invalid exit code. | ||||
* set to {@link Integer#MAX_VALUE} | * set to {@link Integer#MAX_VALUE} | ||||
*/ | */ | ||||
@@ -518,7 +520,7 @@ public class Execute { | |||||
useVMLauncher); | useVMLauncher); | ||||
if (Os.isFamily("windows")) { | if (Os.isFamily("windows")) { | ||||
try { | try { | ||||
Thread.sleep(1000); | |||||
Thread.sleep(ONE_SECOND); | |||||
} catch (InterruptedException e) { | } catch (InterruptedException e) { | ||||
project.log("interruption in the sleep after having spawned a" | project.log("interruption in the sleep after having spawned a" | ||||
+ " process", Project.MSG_VERBOSE); | + " process", Project.MSG_VERBOSE); | ||||
@@ -911,6 +913,7 @@ public class Execute { | |||||
final int preCmdLength = 7; | final int preCmdLength = 7; | ||||
final String cmdDir = commandDir.getAbsolutePath(); | final String cmdDir = commandDir.getAbsolutePath(); | ||||
String[] newcmd = new String[cmd.length + preCmdLength]; | String[] newcmd = new String[cmd.length + preCmdLength]; | ||||
// CheckStyle:MagicNumber OFF - do not bother | |||||
newcmd[0] = "cmd"; | newcmd[0] = "cmd"; | ||||
newcmd[1] = "/c"; | newcmd[1] = "/c"; | ||||
newcmd[2] = cmdDir.substring(0, 2); | newcmd[2] = cmdDir.substring(0, 2); | ||||
@@ -918,6 +921,7 @@ public class Execute { | |||||
newcmd[4] = "cd"; | newcmd[4] = "cd"; | ||||
newcmd[5] = cmdDir.substring(2); | newcmd[5] = cmdDir.substring(2); | ||||
newcmd[6] = "&&"; | newcmd[6] = "&&"; | ||||
// CheckStyle:MagicNumber ON | |||||
System.arraycopy(cmd, 0, newcmd, preCmdLength, cmd.length); | System.arraycopy(cmd, 0, newcmd, preCmdLength, cmd.length); | ||||
return exec(project, newcmd, env); | return exec(project, newcmd, env); | ||||
@@ -959,12 +963,14 @@ public class Execute { | |||||
// the command | // the command | ||||
final int preCmdLength = 6; | final int preCmdLength = 6; | ||||
String[] newcmd = new String[cmd.length + preCmdLength]; | String[] newcmd = new String[cmd.length + preCmdLength]; | ||||
// CheckStyle:MagicNumber OFF - do not bother | |||||
newcmd[0] = "cmd"; | newcmd[0] = "cmd"; | ||||
newcmd[1] = "/c"; | newcmd[1] = "/c"; | ||||
newcmd[2] = "cd"; | newcmd[2] = "cd"; | ||||
newcmd[3] = "/d"; | newcmd[3] = "/d"; | ||||
newcmd[4] = commandDir.getAbsolutePath(); | newcmd[4] = commandDir.getAbsolutePath(); | ||||
newcmd[5] = "&&"; | newcmd[5] = "&&"; | ||||
// CheckStyle:MagicNumber ON | |||||
System.arraycopy(cmd, 0, newcmd, preCmdLength, cmd.length); | System.arraycopy(cmd, 0, newcmd, preCmdLength, cmd.length); | ||||
return exec(project, newcmd, env); | return exec(project, newcmd, env); | ||||
@@ -58,6 +58,7 @@ import org.apache.tools.zip.ZipFile; | |||||
* name="unwar" | * name="unwar" | ||||
*/ | */ | ||||
public class Expand extends Task { | public class Expand extends Task { | ||||
private static final int BUFFER_SIZE = 1024; | |||||
private File dest; //req | private File dest; //req | ||||
private File source; // req | private File source; // req | ||||
private boolean overwrite = true; | private boolean overwrite = true; | ||||
@@ -275,7 +276,7 @@ public class Expand extends Task { | |||||
if (isDirectory) { | if (isDirectory) { | ||||
f.mkdirs(); | f.mkdirs(); | ||||
} else { | } else { | ||||
byte[] buffer = new byte[1024]; | |||||
byte[] buffer = new byte[BUFFER_SIZE]; | |||||
int length = 0; | int length = 0; | ||||
FileOutputStream fos = null; | FileOutputStream fos = null; | ||||
try { | try { | ||||
@@ -36,7 +36,7 @@ import org.apache.tools.ant.util.FileUtils; | |||||
*/ | */ | ||||
public class GUnzip extends Unpack { | public class GUnzip extends Unpack { | ||||
private static final int BUFFER_SIZE = 8 * 1024; | |||||
private static final String DEFAULT_EXTENSION = ".gz"; | private static final String DEFAULT_EXTENSION = ".gz"; | ||||
/** | /** | ||||
@@ -62,7 +62,7 @@ public class GUnzip extends Unpack { | |||||
out = new FileOutputStream(dest); | out = new FileOutputStream(dest); | ||||
fis = srcResource.getInputStream(); | fis = srcResource.getInputStream(); | ||||
zIn = new GZIPInputStream(fis); | zIn = new GZIPInputStream(fis); | ||||
byte[] buffer = new byte[8 * 1024]; | |||||
byte[] buffer = new byte[BUFFER_SIZE]; | |||||
int count = 0; | int count = 0; | ||||
do { | do { | ||||
out.write(buffer, 0, count); | out.write(buffer, 0, count); | ||||
@@ -44,7 +44,7 @@ import java.util.Date; | |||||
* @ant.task category="network" | * @ant.task category="network" | ||||
*/ | */ | ||||
public class Get extends Task { | public class Get extends Task { | ||||
private static final int BIG_BUFFER_SIZE = 100 * 1024; | |||||
private static final FileUtils FILE_UTILS = FileUtils.getFileUtils(); | private static final FileUtils FILE_UTILS = FileUtils.getFileUtils(); | ||||
private URL source; // required | private URL source; // required | ||||
@@ -202,7 +202,7 @@ public class Get extends Task { | |||||
progress.beginDownload(); | progress.beginDownload(); | ||||
boolean finished = false; | boolean finished = false; | ||||
try { | try { | ||||
byte[] buffer = new byte[100 * 1024]; | |||||
byte[] buffer = new byte[BIG_BUFFER_SIZE]; | |||||
int length; | int length; | ||||
while ((length = is.read(buffer)) >= 0) { | while ((length = is.read(buffer)) >= 0) { | ||||
fos.write(buffer, 0, length); | fos.write(buffer, 0, length); | ||||
@@ -35,7 +35,7 @@ import org.apache.tools.ant.types.resources.FileResource; | |||||
*/ | */ | ||||
public abstract class Pack extends Task { | public abstract class Pack extends Task { | ||||
private static final int BUFFER_SIZE = 8 * 1024; | |||||
// CheckStyle:VisibilityModifier OFF - bc | // CheckStyle:VisibilityModifier OFF - bc | ||||
protected File zipFile; | protected File zipFile; | ||||
protected File source; | protected File source; | ||||
@@ -148,7 +148,7 @@ public abstract class Pack extends Task { | |||||
*/ | */ | ||||
private void zipFile(InputStream in, OutputStream zOut) | private void zipFile(InputStream in, OutputStream zOut) | ||||
throws IOException { | throws IOException { | ||||
byte[] buffer = new byte[8 * 1024]; | |||||
byte[] buffer = new byte[BUFFER_SIZE]; | |||||
int count = 0; | int count = 0; | ||||
do { | do { | ||||
zOut.write(buffer, 0, count); | zOut.write(buffer, 0, count); | ||||