]> source.dussan.org Git - xmlgraphics-fop.git/commitdiff
Only update the generated files if any source file is newer than the generated ones.
authorJeremias Maerki <jeremias@apache.org>
Wed, 23 Jul 2008 19:33:24 +0000 (19:33 +0000)
committerJeremias Maerki <jeremias@apache.org>
Wed, 23 Jul 2008 19:33:24 +0000 (19:33 +0000)
git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@679164 13f79535-47bb-0310-9956-ffa450edef68

src/codegen/java/org/apache/fop/tools/EventProducerCollector.java
src/codegen/java/org/apache/fop/tools/EventProducerCollectorTask.java

index ebb960a8effd0bb4e0d86c8c9b143a9d12e20390..2e008a1303a21beb9f1226323164a7ab8b0bf723 100644 (file)
@@ -46,7 +46,7 @@ public class EventProducerCollector {
 
     private static final String CLASSNAME_EVENT_PRODUCER = EventProducer.class.getName();
     private static final Map PRIMITIVE_MAP;
-    
+
     static {
         Map m = new java.util.HashMap();
         m.put("boolean", Boolean.class);
@@ -59,7 +59,7 @@ public class EventProducerCollector {
         m.put("double", Double.class);
         PRIMITIVE_MAP = Collections.unmodifiableMap(m);
     }
-    
+
     private DocletTagFactory tagFactory;
     private EventModel model = new EventModel();
 
@@ -81,21 +81,25 @@ public class EventProducerCollector {
     /**
      * Scans a file and processes it if it extends the {@link EventProducer} interface.
      * @param src the source file (a Java source file)
+     * @return true if the file contained an EventProducer interface
      * @throws IOException if an I/O error occurs
      * @throws EventConventionException if the EventProducer conventions are violated
      * @throws ClassNotFoundException if a required class cannot be found
      */
-    public void scanFile(File src)
+    public boolean scanFile(File src)
             throws IOException, EventConventionException, ClassNotFoundException {
         JavaDocBuilder builder = new JavaDocBuilder(this.tagFactory);
         builder.addSource(src);
         JavaClass[] classes = builder.getClasses();
+        boolean eventProducerFound = false;
         for (int i = 0, c = classes.length; i < c; i++) {
             JavaClass clazz = classes[i];
             if (clazz.isInterface() && implementsInterface(clazz, CLASSNAME_EVENT_PRODUCER)) {
                 processEventProducerInterface(clazz);
+                eventProducerFound = true;
             }
         }
+        return eventProducerFound;
     }
 
     private boolean implementsInterface(JavaClass clazz, String intf) {
@@ -146,13 +150,13 @@ public class EventProducerCollector {
             throw new EventConventionException("The first parameter of the method " + methodSig
                     + " must be: 'Object source'!");
         }
-        
+
         //build method model
         DocletTag tag = method.getTagByName("event.severity");
         EventSeverity severity;
         if (tag != null) {
             severity = EventSeverity.valueOf(tag.getValue());
-        } else { 
+        } else {
             severity = EventSeverity.INFO;
         }
         EventMethodModel methodMeta = new EventMethodModel(
@@ -192,7 +196,7 @@ public class EventProducerCollector {
     public EventModel getModel() {
         return this.model;
     }
-    
+
     /**
      * Saves the accumulated event model to an XML file.
      * @param modelFile the target model file
@@ -201,5 +205,5 @@ public class EventProducerCollector {
     public void saveModelToXML(File modelFile) throws IOException {
         getModel().saveToXML(modelFile);
     }
-    
+
 }
index e00b05b557d451a6c30214ddba873a8ee3ce6862..b089a361e37e75460dccedebd293a63553ca0397 100644 (file)
@@ -63,16 +63,21 @@ public class EventProducerCollectorTask extends Task {
     public void execute() throws BuildException {
         try {
             EventProducerCollector collector = new EventProducerCollector();
-            processFileSets(collector);
+            long lastModified = processFileSets(collector);
             File parentDir = getModelFile().getParentFile();
             if (!parentDir.exists() && !parentDir.mkdirs()) {
                 throw new BuildException(
                         "Could not create target directory for event model file: " + parentDir);
             }
-            collector.saveModelToXML(getModelFile());
-            log("Event model written to " + getModelFile());
+            if (!getModelFile().exists() || lastModified > getModelFile().lastModified()) {
+                collector.saveModelToXML(getModelFile());
+                log("Event model written to " + getModelFile());
+            }
             if (getTranslationFile() != null) {
-                updateTranslationFile();
+                if (!getTranslationFile().exists()
+                        || lastModified > getTranslationFile().lastModified()) {
+                    updateTranslationFile();
+                }
             }
         } catch (ClassNotFoundException e) {
             throw new BuildException(e);
@@ -164,12 +169,14 @@ public class EventProducerCollectorTask extends Task {
     /**
      * Processes the file sets defined for the task.
      * @param collector the collector to use for collecting the event producers
+     * @return the time of the latest modification of any of the files inspected
      * @throws IOException if an I/O error occurs
      * @throws EventConventionException if the EventProducer conventions are violated
      * @throws ClassNotFoundException if a required class cannot be found
      */
-    protected void processFileSets(EventProducerCollector collector)
+    protected long processFileSets(EventProducerCollector collector)
             throws IOException, EventConventionException, ClassNotFoundException {
+        long lastModified = 0;
         Iterator iter = filesets.iterator();
         while (iter.hasNext()) {
             FileSet fs = (FileSet)iter.next();
@@ -179,9 +186,13 @@ public class EventProducerCollectorTask extends Task {
             for (int i = 0, c = srcFiles.length; i < c; i++) {
                 String filename = srcFiles[i];
                 File src = new File(directory, filename);
-                collector.scanFile(src);
+                boolean eventProducerFound = collector.scanFile(src);
+                if (eventProducerFound) {
+                    lastModified = Math.max(lastModified, src.lastModified());
+                }
             }
         }
+        return lastModified;
     }
 
     /**