Bug 21381 - [PATCH] Ant task mod-date patch for dev branch (see #21380)
Summary: [PATCH] Ant task mod-date patch for dev branch (see #21380)
Status: CLOSED FIXED
Alias: None
Product: Fop - Now in Jira
Classification: Unclassified
Component: general (show other bugs)
Version: trunk
Hardware: All All
: P3 enhancement
Target Milestone: ---
Assignee: fop-dev
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2003-07-07 20:47 UTC by Sean Gilligan
Modified: 2012-04-01 06:49 UTC (History)
0 users



Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Sean Gilligan 2003-07-07 20:47:20 UTC
The FOP Ant task currently always renders the output.  The attached patch will
render only when the source file (.fo) is newer then the target (.pdf, etc.). 
There is also a "force" flag that can be used to always render.

This is the patch for org.apache.fop.tools.anttasks.Fop on the HEAD branch that
corresponds to the patch on the 0_20_2-maintain branch.  (The changes to the XML
documentation are the same for both branches.)

cvs diff -u src/java/org/apache/fop/tools/anttasks/Fop.java                    
 Index: src/java/org/apache/fop/tools/anttasks/Fop.java
===================================================================
RCS file: /home/cvspublic/xml-fop/src/java/org/apache/fop/tools/anttasks/Fop.java,v
retrieving revision 1.4
diff -u -u -r1.4 Fop.java
--- src/java/org/apache/fop/tools/anttasks/Fop.java     17 Jun 2003 16:35:58
-0000      1.4
+++ src/java/org/apache/fop/tools/anttasks/Fop.java     7 Jul 2003 20:44:17 -0000
@@ -94,6 +94,8 @@
  *      non-error messages</li>
  * <li>logFiles -> Controls whether the names of the files that are processed
  *      are logged or not</li>
+ * <li>force -> Recreate target files, even if they are newer than their
+ *      corresponding source files</li>
  * </ul>
  */
 public class Fop extends Task {
@@ -107,6 +109,7 @@
     private File userConfig;
     private int messageType = Project.MSG_VERBOSE;
     private boolean logFiles = true;
+    boolean force = false;         // Ignore modification dates if true
 
     /**
      * Sets the filename for the userconfig.xml.
@@ -270,6 +273,20 @@
     }
 
     /**
+     * Sets force (ignore mod dates) flag 
+     */
+    public void setForce(boolean aBoolean) {
+        this.force = aBoolean;
+    }
+
+    /**
+     * Gets force (ignore mod dates) flag
+     */
+    public boolean getForce() {
+        return this.force;
+    }
+
+    /**
      * @see org.apache.tools.ant.Task#execute()
      */
     public void execute() throws BuildException {
@@ -410,8 +427,13 @@
                 if (task.getOutdir() != null) {
                     outf = new File(task.getOutdir(), outf.getName());
                 }
-                render(task.getFofile(), outf, rint);
-                actioncount++;
+                // Only render if "force" flag is set OR output file doesn't
exist OR
+                // output file is older than input file
+                if ( task.force || !outf.exists() ||
+                    (task.getFofile().lastModified() > outf.lastModified() ) ) {
+                    render(task.getFofile(), outf, rint);
+                    actioncount++;
+                }
             }
         }
 
@@ -449,14 +471,17 @@
                     task.log("Error setting base URL", Project.MSG_DEBUG);
                 }
 
-                render(f, outf, rint);
-                actioncount++;
+                // Only render if "force" flag is set OR output file doesn't
exist OR
+                // output file is older than input file
+                if ( task.force || !outf.exists() || (f.lastModified() >
outf.lastModified() ) ) {
+                    render(f, outf, rint);
+                    actioncount++;
+                }
             }
         }
 
         if (actioncount == 0) {
-            task.log("No files processed. No files were selected by the filesets "
-                + "and no fofile was set." , Project.MSG_WARN);
+            task.log("Nothing to do." , Project.MSG_WARN);
         }
     }
Comment 1 Glen Mazza 2003-07-30 22:06:56 UTC
Applied (w/minor changes)--thanks for the patch!

http://cvs.apache.org/viewcvs.cgi/xml-
fop/src/java/org/apache/fop/tools/anttasks/Fop.java

Comment 2 Glenn Adams 2012-04-01 06:49:28 UTC
batch transition pre-FOP1.0 resolved+fixed bugs to closed+fixed