You are viewing a plain text version of this content. The canonical link for it is here.
Posted to fop-commits@xmlgraphics.apache.org by je...@apache.org on 2008/07/23 21:33:24 UTC

svn commit: r679164 - in /xmlgraphics/fop/trunk/src/codegen/java/org/apache/fop/tools: EventProducerCollector.java EventProducerCollectorTask.java

Author: jeremias
Date: Wed Jul 23 12:33:24 2008
New Revision: 679164

URL: http://svn.apache.org/viewvc?rev=679164&view=rev
Log:
Only update the generated files if any source file is newer than the generated ones.

Modified:
    xmlgraphics/fop/trunk/src/codegen/java/org/apache/fop/tools/EventProducerCollector.java
    xmlgraphics/fop/trunk/src/codegen/java/org/apache/fop/tools/EventProducerCollectorTask.java

Modified: xmlgraphics/fop/trunk/src/codegen/java/org/apache/fop/tools/EventProducerCollector.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/src/codegen/java/org/apache/fop/tools/EventProducerCollector.java?rev=679164&r1=679163&r2=679164&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/src/codegen/java/org/apache/fop/tools/EventProducerCollector.java (original)
+++ xmlgraphics/fop/trunk/src/codegen/java/org/apache/fop/tools/EventProducerCollector.java Wed Jul 23 12:33:24 2008
@@ -46,7 +46,7 @@
 
     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 @@
         m.put("double", Double.class);
         PRIMITIVE_MAP = Collections.unmodifiableMap(m);
     }
-    
+
     private DocletTagFactory tagFactory;
     private EventModel model = new EventModel();
 
@@ -81,21 +81,25 @@
     /**
      * 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 @@
             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 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 void saveModelToXML(File modelFile) throws IOException {
         getModel().saveToXML(modelFile);
     }
-    
+
 }

Modified: xmlgraphics/fop/trunk/src/codegen/java/org/apache/fop/tools/EventProducerCollectorTask.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/src/codegen/java/org/apache/fop/tools/EventProducerCollectorTask.java?rev=679164&r1=679163&r2=679164&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/src/codegen/java/org/apache/fop/tools/EventProducerCollectorTask.java (original)
+++ xmlgraphics/fop/trunk/src/codegen/java/org/apache/fop/tools/EventProducerCollectorTask.java Wed Jul 23 12:33:24 2008
@@ -63,16 +63,21 @@
     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 @@
     /**
      * 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 @@
             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;
     }
 
     /**



---------------------------------------------------------------------
To unsubscribe, e-mail: fop-commits-unsubscribe@xmlgraphics.apache.org
For additional commands, e-mail: fop-commits-help@xmlgraphics.apache.org