ant-notifications mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bode...@apache.org
Subject svn commit: r710101 - in /ant/core/trunk/src/main/org/apache/tools/ant/taskdefs: Ear.java Jar.java War.java Zip.java
Date Mon, 03 Nov 2008 16:40:42 GMT
Author: bodewig
Date: Mon Nov  3 08:40:42 2008
New Revision: 710101

URL: http://svn.apache.org/viewvc?rev=710101&view=rev
Log:
make sure log messages to get emmitted twice in double-pass mode.  PR 39426.

Modified:
    ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/Ear.java
    ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/Jar.java
    ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/War.java
    ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/Zip.java

Modified: ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/Ear.java
URL: http://svn.apache.org/viewvc/ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/Ear.java?rev=710101&r1=710100&r2=710101&view=diff
==============================================================================
--- ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/Ear.java (original)
+++ ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/Ear.java Mon Nov  3 08:40:42 2008
@@ -130,7 +130,7 @@
             if (deploymentDescriptor != null
                 || !FILE_UTILS.fileNameEquals(deploymentDescriptor, file)
                 || descriptorAdded) {
-                log("Warning: selected " + archiveType
+                logOnFirstPass("Warning: selected " + archiveType
                     + " files include a " + XML_DESCRIPTOR_PATH + " which will"
                     + " be ignored (please use appxml attribute to "
                     + archiveType + " task)",

Modified: ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/Jar.java
URL: http://svn.apache.org/viewvc/ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/Jar.java?rev=710101&r1=710100&r2=710101&view=diff
==============================================================================
--- ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/Jar.java (original)
+++ ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/Jar.java Mon Nov  3 08:40:42 2008
@@ -632,11 +632,11 @@
                            long lastModified, File fromArchive, int mode)
         throws IOException {
         if (MANIFEST_NAME.equalsIgnoreCase(vPath))  {
-            if (!doubleFilePass || skipWriting) {
+            if (isFirstPass()) {
                 filesetManifest(fromArchive, is);
             }
         } else if (INDEX_NAME.equalsIgnoreCase(vPath) && index) {
-            log("Warning: selected " + archiveType
+            logOnFirstPass("Warning: selected " + archiveType
                 + " files include a " + INDEX_NAME + " which will"
                 + " be replaced by a newly generated one.", Project.MSG_WARN);
         } else {
@@ -671,7 +671,7 @@
         } else if (filesetManifestConfig != null
                     && !filesetManifestConfig.getValue().equals("skip")) {
             // we add this to our group of fileset manifests
-            log("Found manifest to merge in file " + file,
+            logOnFirstPass("Found manifest to merge in file " + file,
                 Project.MSG_VERBOSE);
 
             try {
@@ -754,13 +754,13 @@
             try {
                 originalManifest = getManifestFromJar(zipFile);
                 if (originalManifest == null) {
-                    log("Updating jar since the current jar has no manifest",
+                    logOnFirstPass("Updating jar since the current jar has no manifest",
                         Project.MSG_VERBOSE);
                     needsUpdate = true;
                 } else {
                     Manifest mf = createManifest();
                     if (!mf.equals(originalManifest)) {
-                        log("Updating jar since jar manifest has changed",
+                        logOnFirstPass("Updating jar since jar manifest has changed",
                             Project.MSG_VERBOSE);
                         needsUpdate = true;
                     }
@@ -801,9 +801,11 @@
         }
 
         if (emptyBehavior.equals("skip")) {
+            if (!skipWriting) {
                 log("Warning: skipping " + archiveType + " archive "
                     + zipFile + " because no files were included.",
                     Project.MSG_WARN);
+            }
                 return true;
         } else if (emptyBehavior.equals("fail")) {
             throw new BuildException("Cannot create " + archiveType
@@ -814,8 +816,10 @@
 
         ZipOutputStream zOut = null;
         try {
+            if (!skipWriting) {
             log("Building MANIFEST-only jar: "
                 + getDestFile().getAbsolutePath());
+            }
             zOut = new ZipOutputStream(new FileOutputStream(getDestFile()));
 
             zOut.setEncoding(getEncoding());
@@ -894,7 +898,7 @@
             if (strict.getValue().equalsIgnoreCase("fail")) {
                 throw new BuildException(message.toString(), getLocation());
             } else {
-                log(message.toString(), strict.getLogLevel());
+                logOnFirstPass(message.toString(), strict.getLogLevel());
             }
         }
     }

Modified: ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/War.java
URL: http://svn.apache.org/viewvc/ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/War.java?rev=710101&r1=710100&r2=710101&view=diff
==============================================================================
--- ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/War.java (original)
+++ ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/War.java Mon Nov  3 08:40:42 2008
@@ -188,7 +188,7 @@
                 addFile = false;
                 //check to see if we warn or not
                 if (!FILE_UTILS.fileNameEquals(addedWebXmlFile, file)) {
-                    log("Warning: selected " + archiveType
+                    logOnFirstPass("Warning: selected " + archiveType
                             + " files include a second " + XML_DESCRIPTOR_PATH
                             + " which will be ignored.\n"
                             + "The duplicate entry is at " + file + '\n'

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=710101&r1=710100&r2=710101&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 Mon Nov  3 08:40:42 2008
@@ -93,9 +93,37 @@
     protected Hashtable addedDirs = new Hashtable();
     private Vector addedFiles = new Vector();
 
+    /**
+     * If this flag is true, execute() will run most operations twice,
+     * the first time with {@link #skipWriting skipWriting} set to
+     * true and the second time with setting it to false.
+     *
+     * <p>The only situation in Ant's current code base where this is
+     * ever going to be true is if the jar task has been configured
+     * with a filesetmanifest other than "skip".</p>
+     */
     protected boolean doubleFilePass = false;
+    /**
+     * whether the methods should just perform some sort of dry-run.
+     *
+     * <p>Will only ever be true in the first pass if the task
+     * performs two passes because {@link #doubleFilePass
+     * doubleFilePass} is true.</p>
+     */
     protected boolean skipWriting = false;
 
+    /**
+     * Whether this is the first time the archive building methods are invoked.
+     *
+     * @return true if either {@link #doubleFilePass doubleFilePass}
+     * is false or {@link #skipWriting skipWriting} is true.
+     *
+     * @since Ant 1.8.0
+     */
+    protected final boolean isFirstPass() {
+        return !doubleFilePass || skipWriting;
+    }
+
     private static final FileUtils FILE_UTILS = FileUtils.getFileUtils();
 
     // CheckStyle:VisibilityModifier ON
@@ -502,7 +530,9 @@
 
             String action = doUpdate ? "Updating " : "Building ";
 
-            log(action + archiveType + ": " + zipFile.getAbsolutePath());
+            if (!skipWriting) {
+                log(action + archiveType + ": " + zipFile.getAbsolutePath());
+            }
 
             ZipOutputStream zOut = null;
             try {
@@ -673,7 +703,7 @@
         // we don't need to update if the original file doesn't exist
         if (doUpdate && !zipFile.exists()) {
             doUpdate = false;
-            log("ignoring update attribute as " + archiveType
+            logOnFirstPass("ignoring update attribute as " + archiveType
                 + " doesn't exist.", Project.MSG_DEBUG);
         }
     }
@@ -683,14 +713,14 @@
         // Add the files found in groupfileset to fileset
         for (int i = 0; i < groupfilesets.size(); i++) {
 
-            log("Processing groupfileset ", Project.MSG_VERBOSE);
+            logOnFirstPass("Processing groupfileset ", Project.MSG_VERBOSE);
             FileSet fs = (FileSet) groupfilesets.elementAt(i);
             FileScanner scanner = fs.getDirectoryScanner(getProject());
             String[] files = scanner.getIncludedFiles();
             File basedir = scanner.getBasedir();
             for (int j = 0; j < files.length; j++) {
 
-                log("Adding file " + files[j] + " to fileset",
+                logOnFirstPass("Adding file " + files[j] + " to fileset",
                     Project.MSG_VERBOSE);
                 ZipFileSet zf = new ZipFileSet();
                 zf.setProject(getProject());
@@ -958,8 +988,10 @@
         // In this case using java.util.zip will not work
         // because it does not permit a zero-entry archive.
         // Must create it manually.
-        log("Note: creating empty " + archiveType + " archive " + zipFile,
-            Project.MSG_INFO);
+        if (!skipWriting) {
+            log("Note: creating empty " + archiveType + " archive " + zipFile,
+                Project.MSG_INFO);
+        }
         OutputStream os = null;
         try {
             os = new FileOutputStream(zipFile);
@@ -1120,11 +1152,11 @@
 
             if (emptyBehavior.equals("skip")) {
                 if (doUpdate) {
-                    log(archiveType + " archive " + zipFile
+                    logOnFirstPass(archiveType + " archive " + zipFile
                         + " not updated because no new files were included.",
                         Project.MSG_VERBOSE);
                 } else {
-                    log("Warning: skipping " + archiveType + " archive "
+                    logOnFirstPass("Warning: skipping " + archiveType + " archive "
                         + zipFile + " because no files were included.",
                         Project.MSG_WARN);
                 }
@@ -1425,7 +1457,7 @@
                           int mode, ZipExtraField[] extra)
         throws IOException {
         if (doFilesonly) {
-            log("skipping directory " + vPath + " for file-only archive",
+            logOnFirstPass("skipping directory " + vPath + " for file-only archive",
                     Project.MSG_VERBOSE);
             return;
         }
@@ -1435,7 +1467,7 @@
             return;
         }
 
-        log("adding directory " + vPath, Project.MSG_VERBOSE);
+        logOnFirstPass("adding directory " + vPath, Project.MSG_VERBOSE);
         addedDirs.put(vPath, vPath);
 
         if (!skipWriting) {
@@ -1483,7 +1515,7 @@
         if (entries.contains(vPath)) {
 
             if (duplicate.equals("preserve")) {
-                log(vPath + " already added, skipping", Project.MSG_INFO);
+                logOnFirstPass(vPath + " already added, skipping", Project.MSG_INFO);
                 return;
             } else if (duplicate.equals("fail")) {
                 throw new BuildException("Duplicate file " + vPath
@@ -1491,11 +1523,11 @@
                                          + "attribute is 'fail'.");
             } else {
                 // duplicate equal to add, so we continue
-                log("duplicate file " + vPath
+                logOnFirstPass("duplicate file " + vPath
                     + " found, adding.", Project.MSG_VERBOSE);
             }
         } else {
-            log("adding entry " + vPath, Project.MSG_VERBOSE);
+            logOnFirstPass("adding entry " + vPath, Project.MSG_VERBOSE);
         }
 
         entries.put(vPath, vPath);
@@ -1712,7 +1744,7 @@
             if (!orig[i].isDirectory()) {
                 v.addElement(orig[i]);
             } else {
-                log("Ignoring directory " + orig[i].getName()
+                logOnFirstPass("Ignoring directory " + orig[i].getName()
                     + " as only files will be added.", Project.MSG_VERBOSE);
             }
         }
@@ -1726,6 +1758,18 @@
     }
 
     /**
+     * Logs a message at the given output level, but only if this is
+     * the {@link #isFirstPass first pass}.
+     *
+     * @since Ant 1.8.0
+     */
+    protected void logOnFirstPass(String msg, int level) {
+        if (isFirstPass()) {
+            log(msg, level);
+        }
+    }
+
+    /**
      * Possible behaviors when a duplicate file is added:
      * "add", "preserve" or "fail"
      */



Mime
View raw message