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