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);
m.put("double", Double.class);
PRIMITIVE_MAP = Collections.unmodifiableMap(m);
}
-
+
private DocletTagFactory tagFactory;
private EventModel model = new EventModel();
/**
* 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) {
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(
public EventModel getModel() {
return this.model;
}
-
+
/**
* Saves the accumulated event model to an XML file.
* @param modelFile the target model file
public void saveModelToXML(File modelFile) throws IOException {
getModel().saveToXML(modelFile);
}
-
+
}
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);
/**
* 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();
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;
}
/**