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