git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@577308 13f79535-47bb-0310-9956-ffa450edef68master
@@ -29,7 +29,7 @@ import java.util.Vector; | |||||
* @since Ant 1.5 | * @since Ant 1.5 | ||||
*/ | */ | ||||
class ProcessDestroyer implements Runnable { | class ProcessDestroyer implements Runnable { | ||||
private static final int TWENTY_SECONDS = 20000; | |||||
private Vector processes = new Vector(); | private Vector processes = new Vector(); | ||||
// methods to register and unregister shutdown hooks | // methods to register and unregister shutdown hooks | ||||
private Method addShutdownHookMethod; | private Method addShutdownHookMethod; | ||||
@@ -150,7 +150,7 @@ class ProcessDestroyer implements Runnable { | |||||
} | } | ||||
// this should return quickly, since it basically is a NO-OP. | // this should return quickly, since it basically is a NO-OP. | ||||
try { | try { | ||||
destroyProcessThread.join(20000); | |||||
destroyProcessThread.join(TWENTY_SECONDS); | |||||
} catch (InterruptedException ie) { | } catch (InterruptedException ie) { | ||||
// the thread didn't die in time | // the thread didn't die in time | ||||
// it should not kill any processes unexpectedly | // it should not kill any processes unexpectedly | ||||
@@ -267,6 +267,7 @@ public class RecorderEntry implements BuildLogger, SubBuildListener { | |||||
private static String formatTime(long millis) { | private static String formatTime(long millis) { | ||||
// CheckStyle:MagicNumber OFF | |||||
long seconds = millis / 1000; | long seconds = millis / 1000; | ||||
long minutes = seconds / 60; | long minutes = seconds / 60; | ||||
@@ -280,7 +281,7 @@ public class RecorderEntry implements BuildLogger, SubBuildListener { | |||||
return Long.toString(seconds) + " second" | return Long.toString(seconds) + " second" | ||||
+ (seconds % 60 == 1 ? "" : "s"); | + (seconds % 60 == 1 ? "" : "s"); | ||||
} | } | ||||
// CheckStyle:MagicNumber ON | |||||
} | } | ||||
/** | /** | ||||
@@ -53,6 +53,7 @@ import org.apache.tools.ant.util.KeepAliveOutputStream; | |||||
* @since Ant 1.6 | * @since Ant 1.6 | ||||
*/ | */ | ||||
public class Redirector { | public class Redirector { | ||||
private static final int ONE_SECOND = 1000; | |||||
private static final String DEFAULT_ENCODING | private static final String DEFAULT_ENCODING | ||||
= System.getProperty("file.encoding"); | = System.getProperty("file.encoding"); | ||||
@@ -779,7 +780,7 @@ public class Redirector { | |||||
// Ignore exception | // Ignore exception | ||||
} | } | ||||
} | } | ||||
wait(1000); | |||||
wait(ONE_SECOND); | |||||
} catch (InterruptedException eyeEx) { | } catch (InterruptedException eyeEx) { | ||||
Thread[] thread = new Thread[threadGroup.activeCount()]; | Thread[] thread = new Thread[threadGroup.activeCount()]; | ||||
threadGroup.enumerate(thread); | threadGroup.enumerate(thread); | ||||
@@ -144,8 +144,10 @@ public class Sleep extends Task { | |||||
*/ | */ | ||||
private long getSleepTime() { | private long getSleepTime() { | ||||
// CheckStyle:MagicNumber OFF | |||||
return ((((long) hours * 60) + minutes) * 60 + seconds) * 1000 | return ((((long) hours * 60) + minutes) * 60 + seconds) * 1000 | ||||
+ milliseconds; | + milliseconds; | ||||
// CheckStyle:MagicNumber ON | |||||
} | } | ||||
@@ -28,6 +28,8 @@ import java.io.OutputStream; | |||||
*/ | */ | ||||
public class StreamPumper implements Runnable { | public class StreamPumper implements Runnable { | ||||
private static final int SMALL_BUFFER_SIZE = 128; | |||||
private InputStream is; | private InputStream is; | ||||
private OutputStream os; | private OutputStream os; | ||||
private volatile boolean finish; | private volatile boolean finish; | ||||
@@ -35,7 +37,7 @@ public class StreamPumper implements Runnable { | |||||
private boolean closeWhenExhausted; | private boolean closeWhenExhausted; | ||||
private boolean autoflush = false; | private boolean autoflush = false; | ||||
private Exception exception = null; | private Exception exception = null; | ||||
private int bufferSize = 128; | |||||
private int bufferSize = SMALL_BUFFER_SIZE; | |||||
private boolean started = false; | private boolean started = false; | ||||
/** | /** | ||||
@@ -58,6 +58,7 @@ import org.apache.tools.tar.TarOutputStream; | |||||
* @ant.task category="packaging" | * @ant.task category="packaging" | ||||
*/ | */ | ||||
public class Tar extends MatchingTask { | public class Tar extends MatchingTask { | ||||
private static final int BUFFER_SIZE = 8 * 1024; | |||||
/** | /** | ||||
* @deprecated since 1.5.x. | * @deprecated since 1.5.x. | ||||
@@ -466,7 +467,7 @@ public class Tar extends MatchingTask { | |||||
if (!r.isDirectory()) { | if (!r.isDirectory()) { | ||||
in = r.getInputStream(); | in = r.getInputStream(); | ||||
byte[] buffer = new byte[8 * 1024]; | |||||
byte[] buffer = new byte[BUFFER_SIZE]; | |||||
int count = 0; | int count = 0; | ||||
do { | do { | ||||
tOut.write(buffer, 0, count); | tOut.write(buffer, 0, count); | ||||
@@ -66,6 +66,8 @@ import org.apache.tools.zip.ZipOutputStream; | |||||
* @ant.task category="packaging" | * @ant.task category="packaging" | ||||
*/ | */ | ||||
public class Zip extends MatchingTask { | public class Zip extends MatchingTask { | ||||
private static final int BUFFER_SIZE = 8 * 1024; | |||||
private static final int ROUNDUP_MILLIS = 1999; // 2 seconds - 1 | |||||
// CheckStyle:VisibilityModifier OFF - bc | // CheckStyle:VisibilityModifier OFF - bc | ||||
protected File zipFile; | protected File zipFile; | ||||
@@ -927,6 +929,7 @@ public class Zip extends MatchingTask { | |||||
OutputStream os = null; | OutputStream os = null; | ||||
try { | try { | ||||
os = new FileOutputStream(zipFile); | os = new FileOutputStream(zipFile); | ||||
// CheckStyle:MagicNumber OFF | |||||
// Cf. PKZIP specification. | // Cf. PKZIP specification. | ||||
byte[] empty = new byte[22]; | byte[] empty = new byte[22]; | ||||
empty[0] = 80; // P | empty[0] = 80; // P | ||||
@@ -934,6 +937,7 @@ public class Zip extends MatchingTask { | |||||
empty[2] = 5; | empty[2] = 5; | ||||
empty[3] = 6; | empty[3] = 6; | ||||
// remainder zeros | // remainder zeros | ||||
// CheckStyle:MagicNumber ON | |||||
os.write(empty); | os.write(empty); | ||||
} catch (IOException ioe) { | } catch (IOException ioe) { | ||||
throw new BuildException("Could not create empty ZIP archive " | throw new BuildException("Could not create empty ZIP archive " | ||||
@@ -1404,10 +1408,11 @@ public class Zip extends MatchingTask { | |||||
ZipEntry ze = new ZipEntry (vPath); | ZipEntry ze = new ZipEntry (vPath); | ||||
if (dir != null && dir.exists()) { | if (dir != null && dir.exists()) { | ||||
// ZIPs store time with a granularity of 2 seconds, round up | // ZIPs store time with a granularity of 2 seconds, round up | ||||
ze.setTime(dir.lastModified() + (roundUp ? 1999 : 0)); | |||||
ze.setTime(dir.lastModified() + (roundUp ? ROUNDUP_MILLIS : 0)); | |||||
} else { | } else { | ||||
// ZIPs store time with a granularity of 2 seconds, round up | // ZIPs store time with a granularity of 2 seconds, round up | ||||
ze.setTime(System.currentTimeMillis() + (roundUp ? 1999 : 0)); | |||||
ze.setTime(System.currentTimeMillis() | |||||
+ (roundUp ? ROUNDUP_MILLIS : 0)); | |||||
} | } | ||||
ze.setSize (0); | ze.setSize (0); | ||||
ze.setMethod (ZipEntry.STORED); | ze.setMethod (ZipEntry.STORED); | ||||
@@ -1479,7 +1484,7 @@ public class Zip extends MatchingTask { | |||||
// Store data into a byte[] | // Store data into a byte[] | ||||
ByteArrayOutputStream bos = new ByteArrayOutputStream(); | ByteArrayOutputStream bos = new ByteArrayOutputStream(); | ||||
byte[] buffer = new byte[8 * 1024]; | |||||
byte[] buffer = new byte[BUFFER_SIZE]; | |||||
int count = 0; | int count = 0; | ||||
do { | do { | ||||
size += count; | size += count; | ||||
@@ -1491,7 +1496,7 @@ public class Zip extends MatchingTask { | |||||
} else { | } else { | ||||
in.mark(Integer.MAX_VALUE); | in.mark(Integer.MAX_VALUE); | ||||
byte[] buffer = new byte[8 * 1024]; | |||||
byte[] buffer = new byte[BUFFER_SIZE]; | |||||
int count = 0; | int count = 0; | ||||
do { | do { | ||||
size += count; | size += count; | ||||
@@ -1507,7 +1512,7 @@ public class Zip extends MatchingTask { | |||||
ze.setUnixMode(mode); | ze.setUnixMode(mode); | ||||
zOut.putNextEntry(ze); | zOut.putNextEntry(ze); | ||||
byte[] buffer = new byte[8 * 1024]; | |||||
byte[] buffer = new byte[BUFFER_SIZE]; | |||||
int count = 0; | int count = 0; | ||||
do { | do { | ||||
if (count != 0) { | if (count != 0) { | ||||
@@ -1544,7 +1549,7 @@ public class Zip extends MatchingTask { | |||||
try { | try { | ||||
// ZIPs store time with a granularity of 2 seconds, round up | // ZIPs store time with a granularity of 2 seconds, round up | ||||
zipFile(fIn, zOut, vPath, | zipFile(fIn, zOut, vPath, | ||||
file.lastModified() + (roundUp ? 1999 : 0), | |||||
file.lastModified() + (roundUp ? ROUNDUP_MILLIS : 0), | |||||
null, mode); | null, mode); | ||||
} finally { | } finally { | ||||
fIn.close(); | fIn.close(); | ||||