X-Git-Url: http://git.argeo.org/?a=blobdiff_plain;f=org.argeo.slc.core%2Fsrc%2Fmain%2Fjava%2Forg%2Fargeo%2Fslc%2Fant%2FSlcProjectHelper.java;h=ab2cc176385bca9a387adbb13e0553654df6bad9;hb=8d05b68f46cccfcea47117b6116abbd14d1dfcee;hp=9dcd2e83523d86a309cb779c688e280d6987f207;hpb=d1b3fde3da7ac28974953cf918c5dc766e5b2632;p=gpl%2Fargeo-slc.git diff --git a/org.argeo.slc.core/src/main/java/org/argeo/slc/ant/SlcProjectHelper.java b/org.argeo.slc.core/src/main/java/org/argeo/slc/ant/SlcProjectHelper.java index 9dcd2e835..ab2cc1763 100644 --- a/org.argeo.slc.core/src/main/java/org/argeo/slc/ant/SlcProjectHelper.java +++ b/org.argeo.slc.core/src/main/java/org/argeo/slc/ant/SlcProjectHelper.java @@ -17,7 +17,6 @@ import org.apache.tools.ant.BuildException; import org.apache.tools.ant.Project; import org.apache.tools.ant.helper.ProjectHelper2; -import org.argeo.slc.core.UnsupportedException; import org.argeo.slc.core.structure.DefaultSRegistry; import org.argeo.slc.core.structure.SimpleSElement; import org.argeo.slc.core.structure.StructureRegistry; @@ -43,53 +42,79 @@ public class SlcProjectHelper extends ProjectHelper2 { private static String SLC_TASKDEFS_RESOURCE_PATH = "/org/argeo/slc/ant/taskdefs.properties"; private static String SLC_TYPEDEFS_RESOURCE_PATH = "/org/argeo/slc/ant/typedefs.properties"; + protected SlcAntConfig slcAntConfig = null; + @Override public void parse(Project project, Object source) throws BuildException { - if (!(source instanceof File)) { - throw new UnsupportedException("Ant file", source); + + if (source instanceof File) { + File sourceFile = (File) source; + // Reset basedir property, in order to avoid base dir override when + // running in Maven + project.setProperty("basedir", sourceFile.getParentFile() + .getAbsolutePath()); + } + + if (slcAntConfig != null) { + // Config already initialized (probably import), only parse + super.parse(project, source); + return; } - File sourceFile = (File) source; - // initialize config - SlcAntConfig slcAntConfig = new SlcAntConfig(); + // Initialize config + slcAntConfig = new SlcAntConfig(); - // Reset basedir property, in order to avoid base dir override when - // running in Maven - project.setProperty("basedir", sourceFile.getParentFile() - .getAbsolutePath()); if (!slcAntConfig.initProject(project)) { // not SLC compatible, do normal Ant super.parse(project, source); return; } - + if (log == null) { // log4j is initialized only now log = LogFactory.getLog(SlcProjectHelper.class); } - log.debug("SLC properties are set, starting initialization for "+sourceFile); - // init Spring application context + if (log.isDebugEnabled()) + log.debug("SLC properties are set, starting initialization for " + + source + " (projectHelper=" + this + ")"); + + beforeParsing(project); + + // Calls the underlying implementation to do the actual work + super.parse(project, source); + + afterParsing(project); + } + + /** + * Performs operations after config initialization and before Ant file + * parsing. Performed only once when the main project file is parsed. Should + * be called by overriding methods. + */ + protected void beforeParsing(Project project) { + // Init Spring application context initSpringContext(project); - // init structure registry + // Init structure registry DefaultSRegistry registry = new DefaultSRegistry(); project.addReference(REF_STRUCTURE_REGISTRY, registry); + } - // call the underlying implementation to do the actual work - super.parse(project, source); - - // create structure root + /** + * Performs operations after parsing of the main file. Called only once (not + * for imports). + */ + protected void afterParsing(Project project) { + // Creates structure root registerProjectAndParents(project, slcAntConfig); - addCustomTaskAndTypes(project); - } /** Creates the tree-based structure for this project. */ private void registerProjectAndParents(Project project, SlcAntConfig slcAntConfig) { - StructureRegistry registry = (StructureRegistry) project + StructureRegistry registry = (StructureRegistry) project .getReference(REF_STRUCTURE_REGISTRY); File rootDir = new File(project .getUserProperty(SlcAntConfig.ROOT_DIR_PROPERTY)) @@ -114,8 +139,8 @@ public class SlcProjectHelper extends ProjectHelper2 { if (i == 0) {// project itself description = project.getDescription() != null && !project.getDescription().equals("") ? project - .getDescription() : slcAntConfig - .getDescriptionForDir(dir); + .getDescription() : project.getName() != null ? project + .getName() : slcAntConfig.getDescriptionForDir(dir); } else { description = slcAntConfig.getDescriptionForDir(dir); if (log.isTraceEnabled())