commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kohs...@apache.org
Subject svn commit: r290021 - /jakarta/commons/sandbox/javaflow/trunk/src/java/org/apache/commons/javaflow/ant/AntRewriteTask.java
Date Sun, 18 Sep 2005 23:59:04 GMT
Author: kohsuke
Date: Sun Sep 18 16:59:01 2005
New Revision: 290021

URL: http://svn.apache.org/viewcvs?rev=290021&view=rev
Log:
- changed progress message to show the new-code-size/old-code-size (i.e., "192%" means 92%
code size increase due to the instrumentation.)
- added a setter for srcDir. I assumed that it's defined in the MatchingTask, but apparently
it's not.
- fixed a bug in the up-to-date detection logic (when srcDir==destDir)
- modified not to overwrite the file when a class was not instrumented. Ditto for jar.


Modified:
    jakarta/commons/sandbox/javaflow/trunk/src/java/org/apache/commons/javaflow/ant/AntRewriteTask.java

Modified: jakarta/commons/sandbox/javaflow/trunk/src/java/org/apache/commons/javaflow/ant/AntRewriteTask.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/sandbox/javaflow/trunk/src/java/org/apache/commons/javaflow/ant/AntRewriteTask.java?rev=290021&r1=290020&r2=290021&view=diff
==============================================================================
--- jakarta/commons/sandbox/javaflow/trunk/src/java/org/apache/commons/javaflow/ant/AntRewriteTask.java
(original)
+++ jakarta/commons/sandbox/javaflow/trunk/src/java/org/apache/commons/javaflow/ant/AntRewriteTask.java
Sun Sep 18 16:59:01 2005
@@ -42,6 +42,7 @@
     private ClassTransformer transformer = new BcelClassTransformer();
 
     private File destDir;
+    private File srcDir;
 
     public void setDestDir(File file) {
         destDir = file;
@@ -50,6 +51,10 @@
     public File getDestDir() {
         return destDir;
     }
+
+    public void setSrcDir(File file) {
+        srcDir = file;
+    }
     /**
      * Check that all required attributes have been set and nothing
      * silly has been entered.
@@ -57,20 +62,25 @@
      * @since Ant 1.5
      */
     protected void checkParameters() throws BuildException {
-        if (destDir==null) {
-            throw new BuildException("no destination directory is specified",getLocation());
+        checkDir(srcDir,"source");
+        checkDir(destDir,"destination");
+    }
+
+    private void checkDir(File dir,String name) {
+        if (dir==null) {
+            throw new BuildException("no "+name+" directory is specified",getLocation());
         }
-        if (!destDir.exists()) {
+        if (!dir.exists()) {
             throw new BuildException(
-                "destination directory \""
-                    + destDir
+                name+" directory \""
+                    + dir
                     + "\" does not exist ",
                 getLocation());
         }
-        if (!destDir.isDirectory()) {
+        if (!dir.isDirectory()) {
             throw new BuildException(
-                "destination directory \""
-                    + destDir
+                name+" directory \""
+                    + dir
                     + "\" is not a directory",
                 getLocation());
         }
@@ -80,9 +90,9 @@
         super.execute();
         checkParameters();
 
+        fileset.setDir(srcDir);
         DirectoryScanner ds = fileset.getDirectoryScanner(getProject());
         String[] files = ds.getIncludedFiles();
-        File srcDir = ds.getBasedir();
 
         try {
             for (int i = 0; i < files.length; i++) {
@@ -96,7 +106,7 @@
                 }
 
 
-                if (source.lastModified() <= destination.lastModified()) {
+                if (source.lastModified() < destination.lastModified()) {
                     log(source+" omitted as "+destination+" is up to date", Project.MSG_VERBOSE);
                     continue;
                 }
@@ -108,12 +118,15 @@
                     InputStream in = new FileInputStream(source);
                     byte[] bytes = IOUtils.toByteArray(in);
                     in.close();
-                    bytes = transformer.transform(bytes);
-                    FileOutputStream out = new FileOutputStream(destination);
-                    out.write(bytes);
-                    out.close();
-
-                    log("Payload: " + 100*(destination.length()-origSize)/origSize+ '%');
+                    byte[] newBytes = transformer.transform(bytes);
+                    if(bytes!=newBytes) {
+                        FileOutputStream out = new FileOutputStream(destination);
+                        out.write(newBytes);
+                        out.close();
+                        log("size: " + 100*destination.length()/origSize+ '%');
+                    } else {
+                        log("skipped");
+                    }
                 }
                 if (one.endsWith(".jar")
                     || one.endsWith(".ear")
@@ -179,12 +192,14 @@
                 long origSize = e.getSize();
                 byte[] bytes = IOUtils.toByteArray(in);
                 in.close();
-                bytes = transformer.transform(bytes);
+                byte[] newBytes = transformer.transform(bytes);
                 out.putNextEntry(e);
-                out.write(bytes);
+                out.write(newBytes);
                 out.closeEntry();
 
-                log("Payload: " + 100*(bytes.length-origSize)/origSize+ '%');
+                log("Size: " + 100*newBytes.length/origSize+ '%');
+
+                changed |= (bytes!=newBytes);
             }
             else
             if (one.endsWith(".jar")



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


Mime
View raw message