ant-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From peterrei...@apache.org
Subject svn commit: r577308 - in /ant/core/trunk/src/main/org/apache/tools/ant/taskdefs: ProcessDestroyer.java RecorderEntry.java Redirector.java Sleep.java StreamPumper.java Tar.java Zip.java
Date Wed, 19 Sep 2007 14:07:35 GMT
Author: peterreilly
Date: Wed Sep 19 07:07:35 2007
New Revision: 577308

URL: http://svn.apache.org/viewvc?rev=577308&view=rev
Log:
more magic numbers

Modified:
    ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/ProcessDestroyer.java
    ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/RecorderEntry.java
    ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/Redirector.java
    ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/Sleep.java
    ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/StreamPumper.java
    ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/Tar.java
    ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/Zip.java

Modified: ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/ProcessDestroyer.java
URL: http://svn.apache.org/viewvc/ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/ProcessDestroyer.java?rev=577308&r1=577307&r2=577308&view=diff
==============================================================================
--- ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/ProcessDestroyer.java (original)
+++ ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/ProcessDestroyer.java Wed Sep 19
07:07:35 2007
@@ -29,7 +29,7 @@
  * @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 @@
             }
             // 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

Modified: ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/RecorderEntry.java
URL: http://svn.apache.org/viewvc/ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/RecorderEntry.java?rev=577308&r1=577307&r2=577308&view=diff
==============================================================================
--- ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/RecorderEntry.java (original)
+++ ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/RecorderEntry.java Wed Sep 19 07:07:35
2007
@@ -267,6 +267,7 @@
 
 
     private static String formatTime(long millis) {
+        // CheckStyle:MagicNumber OFF
         long seconds = millis / 1000;
         long minutes = seconds / 60;
 
@@ -280,7 +281,7 @@
             return Long.toString(seconds) + " second"
                  + (seconds % 60 == 1 ? "" : "s");
         }
-
+        // CheckStyle:MagicNumber ON
     }
 
     /**

Modified: ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/Redirector.java
URL: http://svn.apache.org/viewvc/ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/Redirector.java?rev=577308&r1=577307&r2=577308&view=diff
==============================================================================
--- ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/Redirector.java (original)
+++ ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/Redirector.java Wed Sep 19 07:07:35
2007
@@ -53,6 +53,7 @@
  * @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 @@
                         // Ignore exception
                     }
                 }
-                wait(1000);
+                wait(ONE_SECOND);
             } catch (InterruptedException eyeEx) {
                 Thread[] thread = new Thread[threadGroup.activeCount()];
                 threadGroup.enumerate(thread);

Modified: ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/Sleep.java
URL: http://svn.apache.org/viewvc/ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/Sleep.java?rev=577308&r1=577307&r2=577308&view=diff
==============================================================================
--- ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/Sleep.java (original)
+++ ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/Sleep.java Wed Sep 19 07:07:35 2007
@@ -144,8 +144,10 @@
      */
 
     private long getSleepTime() {
+        // CheckStyle:MagicNumber OFF
         return ((((long) hours * 60) + minutes) * 60 + seconds) * 1000
             + milliseconds;
+        // CheckStyle:MagicNumber ON
     }
 
 

Modified: ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/StreamPumper.java
URL: http://svn.apache.org/viewvc/ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/StreamPumper.java?rev=577308&r1=577307&r2=577308&view=diff
==============================================================================
--- ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/StreamPumper.java (original)
+++ ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/StreamPumper.java Wed Sep 19 07:07:35
2007
@@ -28,6 +28,8 @@
  */
 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 @@
     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;
 
     /**

Modified: ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/Tar.java
URL: http://svn.apache.org/viewvc/ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/Tar.java?rev=577308&r1=577307&r2=577308&view=diff
==============================================================================
--- ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/Tar.java (original)
+++ ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/Tar.java Wed Sep 19 07:07:35 2007
@@ -58,6 +58,7 @@
  * @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 @@
             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);

Modified: ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/Zip.java
URL: http://svn.apache.org/viewvc/ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/Zip.java?rev=577308&r1=577307&r2=577308&view=diff
==============================================================================
--- ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/Zip.java (original)
+++ ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/Zip.java Wed Sep 19 07:07:35 2007
@@ -66,6 +66,8 @@
  * @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 @@
         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 @@
             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 @@
             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 @@
                     // 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 @@
 
                 } 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 @@
             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 @@
         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();



---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@ant.apache.org
For additional commands, e-mail: dev-help@ant.apache.org


Mime
View raw message