diff options
author | Vincent Hennebert <vhennebert@apache.org> | 2010-04-09 16:48:27 +0000 |
---|---|---|
committer | Vincent Hennebert <vhennebert@apache.org> | 2010-04-09 16:48:27 +0000 |
commit | 9a00e131fd3f2f97ba9cc80f4b65cb6da6b368b4 (patch) | |
tree | 0f6c777ebbf99810e193bd3e4315d790dc638851 | |
parent | a5a17890ada3d6f569131f82466fa3791330349a (diff) | |
download | xmlgraphics-fop-9a00e131fd3f2f97ba9cc80f4b65cb6da6b368b4.tar.gz xmlgraphics-fop-9a00e131fd3f2f97ba9cc80f4b65cb6da6b368b4.zip |
Generate event models in the same directory as the corresponding EventProducer interfaces and name it event-model.xml by default
The eventResourceGenerator task now takes a destination directory parameter instead of modelfile
git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@932502 13f79535-47bb-0310-9956-ffa450edef68
-rw-r--r-- | build.xml | 34 | ||||
-rw-r--r-- | src/codegen/java/org/apache/fop/tools/EventProducerCollector.java | 21 | ||||
-rw-r--r-- | src/codegen/java/org/apache/fop/tools/EventProducerCollectorTask.java | 76 |
3 files changed, 72 insertions, 59 deletions
@@ -360,57 +360,57 @@ list of possible build targets. <pathelement location="${build.codegen-classes.dir}"/> </classpath> </taskdef> - <eventResourceGenerator modelfile="${build.gensrc.dir}/org/apache/fop/area/event-model.xml" + <eventResourceGenerator destdir="${build.gensrc.dir}" translationfile="${src.java.dir}/org/apache/fop/area/AreaEventProducer.xml"> <fileset dir="${src.java.dir}"> <include name="org/apache/fop/area/AreaEventProducer.java"/> </fileset> </eventResourceGenerator> - <eventResourceGenerator modelfile="${build.gensrc.dir}/org/apache/fop/event-model.xml" + <eventResourceGenerator destdir="${build.gensrc.dir}" translationfile="${src.java.dir}/org/apache/fop/ResourceEventProducer.xml"> <fileset dir="${src.java.dir}"> <include name="org/apache/fop/ResourceEventProducer.java"/> </fileset> </eventResourceGenerator> <eventResourceGenerator - modelfile="${build.gensrc.dir}/org/apache/fop/fo/flow/table/event-model.xml" + destdir="${build.gensrc.dir}" translationfile="${src.java.dir}/org/apache/fop/fo/flow/table/TableEventProducer.xml"> <fileset dir="${src.java.dir}"> <include name="org/apache/fop/fo/flow/table/TableEventProducer.java"/> </fileset> </eventResourceGenerator> - <eventResourceGenerator modelfile="${build.gensrc.dir}/org/apache/fop/fo/event-model.xml" + <eventResourceGenerator destdir="${build.gensrc.dir}" translationfile="${src.java.dir}/org/apache/fop/fo/FOValidationEventProducer.xml"> <fileset dir="${src.java.dir}"> <include name="org/apache/fop/fo/FOValidationEventProducer.java"/> </fileset> </eventResourceGenerator> - <eventResourceGenerator modelfile="${build.gensrc.dir}/org/apache/fop/layoutmgr/event-model.xml" + <eventResourceGenerator destdir="${build.gensrc.dir}" translationfile="${src.java.dir}/org/apache/fop/layoutmgr/BlockLevelEventProducer.xml"> <fileset dir="${src.java.dir}"> <include name="org/apache/fop/layoutmgr/BlockLevelEventProducer.java"/> </fileset> </eventResourceGenerator> <eventResourceGenerator - modelfile="${build.gensrc.dir}/org/apache/fop/layoutmgr/inline/event-model.xml" + destdir="${build.gensrc.dir}" translationfile="${src.java.dir}/org/apache/fop/layoutmgr/inline/InlineLevelEventProducer.xml"> <fileset dir="${src.java.dir}"> <include name="org/apache/fop/layoutmgr/inline/InlineLevelEventProducer.java"/> </fileset> </eventResourceGenerator> - <eventResourceGenerator modelfile="${build.gensrc.dir}/org/apache/fop/render/event-model.xml" + <eventResourceGenerator destdir="${build.gensrc.dir}" translationfile="${src.java.dir}/org/apache/fop/render/RendererEventProducer.xml"> <fileset dir="${src.java.dir}"> <include name="org/apache/fop/render/RendererEventProducer.java"/> </fileset> </eventResourceGenerator> - <eventResourceGenerator modelfile="${build.gensrc.dir}/org/apache/fop/svg/event-model.xml" + <eventResourceGenerator destdir="${build.gensrc.dir}" translationfile="${src.java.dir}/org/apache/fop/svg/SVGEventProducer.xml"> <fileset dir="${src.java.dir}"> <include name="org/apache/fop/svg/SVGEventProducer.java"/> </fileset> </eventResourceGenerator> - <eventResourceGenerator modelfile="${build.gensrc.dir}/org/apache/fop/fonts/event-model.xml" + <eventResourceGenerator destdir="${build.gensrc.dir}" translationfile="${src.java.dir}/org/apache/fop/fonts/FontEventProducer.xml"> <fileset dir="${src.java.dir}"> <include name="org/apache/fop/fonts/FontEventProducer.java"/> @@ -418,14 +418,14 @@ list of possible build targets. </eventResourceGenerator> <eventResourceGenerator - modelfile="${build.gensrc.dir}/org/apache/fop/accessibility/event-model.xml" + destdir="${build.gensrc.dir}" translationfile="${src.java.dir}/org/apache/fop/accessibility/AccessibilityEventProducer.xml"> <fileset dir="${src.java.dir}"> <include name="org/apache/fop/accessibility/**/*.java"/> </fileset> </eventResourceGenerator> <fixcrlf file="${src.java.dir}/org/apache/fop/afp/AFPEventProducer.xml" tab="remove" tablength="2"/> - <eventResourceGenerator modelfile="${build.gensrc.dir}/org/apache/fop/afp/event-model.xml" + <eventResourceGenerator destdir="${build.gensrc.dir}" translationfile="${src.java.dir}/org/apache/fop/afp/AFPEventProducer.xml"> <fileset dir="${src.java.dir}"> <include name="org/apache/fop/afp/**/*.java"/> @@ -433,7 +433,7 @@ list of possible build targets. </eventResourceGenerator> <fixcrlf file="${src.java.dir}/org/apache/fop/afp/AFPEventProducer.xml" tab="remove" tablength="2"/> <eventResourceGenerator - modelfile="${build.gensrc.dir}/org/apache/fop/render/bitmap/event-model.xml" + destdir="${build.gensrc.dir}" translationfile="${src.java.dir}/org/apache/fop/render/bitmap/BitmapRendererEventProducer.xml"> <fileset dir="${src.java.dir}"> <include name="org/apache/fop/render/bitmap/**/*.java"/> @@ -441,7 +441,7 @@ list of possible build targets. </eventResourceGenerator> <fixcrlf file="${src.java.dir}/org/apache/fop/render/bitmap/BitmapRendererEventProducer.xml" tab="remove" tablength="2"/> <eventResourceGenerator - modelfile="${build.gensrc.dir}/org/apache/fop/render/pcl/event-model.xml" + destdir="${build.gensrc.dir}" translationfile="${src.java.dir}/org/apache/fop/render/pcl/PCLEventProducer.xml"> <fileset dir="${src.java.dir}"> <include name="org/apache/fop/render/pcl/**/*.java"/> @@ -449,14 +449,14 @@ list of possible build targets. </eventResourceGenerator> <fixcrlf file="${src.java.dir}/org/apache/fop/render/pcl/PCLEventProducer.xml" tab="remove" tablength="2"/> <eventResourceGenerator - modelfile="${build.gensrc.dir}/org/apache/fop/render/pdf/event-model.xml" + destdir="${build.gensrc.dir}" translationfile="${src.java.dir}/org/apache/fop/render/pdf/PDFEventProducer.xml"> <fileset dir="${src.java.dir}"> <include name="org/apache/fop/render/pdf/**/*.java"/> </fileset> </eventResourceGenerator> <fixcrlf file="${src.java.dir}/org/apache/fop/render/pdf/PDFEventProducer.xml" tab="remove" tablength="2"/> - <eventResourceGenerator modelfile="${build.gensrc.dir}/org/apache/fop/render/ps/event-model.xml" + <eventResourceGenerator destdir="${build.gensrc.dir}" translationfile="${src.java.dir}/org/apache/fop/render/ps/PSEventProducer.xml"> <fileset dir="${src.java.dir}"> <include name="org/apache/fop/render/ps/**/*.java"/> @@ -464,7 +464,7 @@ list of possible build targets. </eventResourceGenerator> <fixcrlf file="${src.java.dir}/org/apache/fop/render/ps/PSEventProducer.xml" tab="remove" tablength="2"/> <eventResourceGenerator - modelfile="${build.gensrc.dir}/org/apache/fop/render/rtf/event-model.xml" + destdir="${build.gensrc.dir}" translationfile="${src.java.dir}/org/apache/fop/render/rtf/RTFEventProducer.xml"> <fileset dir="${src.java.dir}"> <include name="org/apache/fop/render/rtf/**/*.java"/> @@ -838,7 +838,7 @@ list of possible build targets. </target> <target name="junit-compile-copy-resources" if="junit.present"> <eventResourceGenerator - modelfile="${build.dir}/test-gensrc/org/apache/fop/events/event-model.xml"> + destdir="${build.dir}/test-gensrc"> <fileset dir="${test.dir}/java"> <include name="**/*.java"/> </fileset> diff --git a/src/codegen/java/org/apache/fop/tools/EventProducerCollector.java b/src/codegen/java/org/apache/fop/tools/EventProducerCollector.java index 5cefc1d4a..4721f41df 100644 --- a/src/codegen/java/org/apache/fop/tools/EventProducerCollector.java +++ b/src/codegen/java/org/apache/fop/tools/EventProducerCollector.java @@ -21,7 +21,9 @@ package org.apache.fop.tools; import java.io.File; import java.io.IOException; +import java.util.ArrayList; import java.util.Collections; +import java.util.List; import java.util.Map; import org.apache.fop.events.EventProducer; @@ -61,7 +63,7 @@ class EventProducerCollector { } private DocletTagFactory tagFactory; - private EventModel model = new EventModel(); + private List models = new ArrayList(); /** * Creates a new EventProducerCollector. @@ -128,7 +130,9 @@ class EventProducerCollector { EventMethodModel methodMeta = createMethodModel(method); prodMeta.addMethod(methodMeta); } - this.model.addProducer(prodMeta); + EventModel model = new EventModel(); + model.addProducer(prodMeta); + models.add(model); } private EventMethodModel createMethodModel(JavaMethod method) @@ -193,17 +197,8 @@ class EventProducerCollector { * Returns the event model that has been accumulated. * @return the event model. */ - public EventModel getModel() { - return this.model; - } - - /** - * Saves the accumulated event model to an XML file. - * @param modelFile the target model file - * @throws IOException if an I/O error occurs - */ - public void saveModelToXML(File modelFile) throws IOException { - getModel().saveToXML(modelFile); + public List getModels() { + return this.models; } } diff --git a/src/codegen/java/org/apache/fop/tools/EventProducerCollectorTask.java b/src/codegen/java/org/apache/fop/tools/EventProducerCollectorTask.java index b089a361e..a79dfc975 100644 --- a/src/codegen/java/org/apache/fop/tools/EventProducerCollectorTask.java +++ b/src/codegen/java/org/apache/fop/tools/EventProducerCollectorTask.java @@ -47,6 +47,9 @@ import org.apache.tools.ant.Task; import org.apache.tools.ant.types.FileSet; import org.apache.tools.ant.types.selectors.FilenameSelector; +import org.apache.fop.events.model.EventModel; +import org.apache.fop.events.model.EventProducerModel; + /** * Ant task which inspects a file set for Java interfaces which extend the * {@link org.apache.fop.events.EventProducer} interface. For all such interfaces an event model @@ -56,7 +59,7 @@ import org.apache.tools.ant.types.selectors.FilenameSelector; public class EventProducerCollectorTask extends Task { private List filesets = new java.util.ArrayList(); - private File modelFile; + private File destDir; private File translationFile; /** {@inheritDoc} */ @@ -64,19 +67,23 @@ public class EventProducerCollectorTask extends Task { try { EventProducerCollector collector = new EventProducerCollector(); 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); - } - if (!getModelFile().exists() || lastModified > getModelFile().lastModified()) { - collector.saveModelToXML(getModelFile()); - log("Event model written to " + getModelFile()); - } - if (getTranslationFile() != null) { - if (!getTranslationFile().exists() - || lastModified > getTranslationFile().lastModified()) { - updateTranslationFile(); + for (Iterator iter = collector.getModels().iterator(); iter.hasNext();) { + EventModel model = (EventModel) iter.next(); + File parentDir = getParentDir(model); + if (!parentDir.exists() && !parentDir.mkdirs()) { + throw new BuildException( + "Could not create target directory for event model file: " + parentDir); + } + File modelFile = new File(parentDir, "event-model.xml"); + if (!modelFile.exists() || lastModified > modelFile.lastModified()) { + model.saveToXML(modelFile); + log("Event model written to " + modelFile); + } + if (getTranslationFile() != null) { + if (!getTranslationFile().exists() + || lastModified > getTranslationFile().lastModified()) { + updateTranslationFile(modelFile); + } } } } catch (ClassNotFoundException e) { @@ -91,18 +98,34 @@ public class EventProducerCollectorTask extends Task { private static final String MODEL2TRANSLATION = "model2translation.xsl"; private static final String MERGETRANSLATION = "merge-translation.xsl"; + private File getParentDir(EventModel model) { + Iterator iter = model.getProducers(); + assert iter.hasNext(); + EventProducerModel producer = (EventProducerModel) iter.next(); + assert !iter.hasNext(); + String interfaceName = producer.getInterfaceName(); + int startLocalName = interfaceName.lastIndexOf("."); + if (startLocalName < 0) { + return destDir; + } else { + String dirname = interfaceName.substring(0, startLocalName); + dirname = dirname.replace('.', File.separatorChar); + return new File(destDir, dirname); + } + } + /** * Updates the translation file with new entries for newly found event producer methods. * @throws IOException if an I/O error occurs */ - protected void updateTranslationFile() throws IOException { + protected void updateTranslationFile(File modelFile) throws IOException { try { boolean resultExists = getTranslationFile().exists(); SAXTransformerFactory tFactory = (SAXTransformerFactory)SAXTransformerFactory.newInstance(); //Generate fresh generated translation file as template - Source src = new StreamSource(getModelFile().toURI().toURL().toExternalForm()); + Source src = new StreamSource(modelFile.toURI().toURL().toExternalForm()); StreamSource xslt1 = new StreamSource( getClass().getResourceAsStream(MODEL2TRANSLATION)); if (xslt1.getInputStream() == null) { @@ -204,19 +227,15 @@ public class EventProducerCollectorTask extends Task { } /** - * Sets the model file to be written. - * @param f the model file + * Sets the destination directory for the event models. + * + * @param destDir the destination directory */ - public void setModelFile(File f) { - this.modelFile = f; - } - - /** - * Returns the model file to be written. - * @return the model file - */ - public File getModelFile() { - return this.modelFile; + public void setDestDir(File destDir) { + if (!destDir.isDirectory()) { + throw new IllegalArgumentException("destDir must be a directory"); + } + this.destDir = destDir; } /** @@ -257,7 +276,6 @@ public class EventProducerCollectorTask extends Task { File targetDir = new File("build/codegen1"); targetDir.mkdirs(); - generator.setModelFile(new File("D:/out.xml")); generator.setTranslationFile(new File("D:/out1.xml")); generator.execute(); } catch (Exception e) { |