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=4731c2284621ed10fc00a7a3af516a92be952626;hpb=38033cb1dbfe8d9c3e8cb8beb8fa0e11299f7714;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 4731c2284..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,20 +42,28 @@ 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); @@ -67,29 +74,47 @@ public class SlcProjectHelper extends ProjectHelper2 { // log4j is initialized only now log = LogFactory.getLog(SlcProjectHelper.class); } - log.debug("SLC properties are set, starting initialization.."); - // 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)) @@ -112,10 +137,15 @@ public class SlcProjectHelper extends ProjectHelper2 { // retrieves description for this path final String description; if (i == 0) {// project itself - description = project.getDescription() != null ? project - .getDescription() : "[no desc]"; + description = project.getDescription() != null + && !project.getDescription().equals("") ? project + .getDescription() : project.getName() != null ? project + .getName() : slcAntConfig.getDescriptionForDir(dir); } else { description = slcAntConfig.getDescriptionForDir(dir); + if (log.isTraceEnabled()) + log.trace("Dir desc " + i + "/" + dirs.size() + ": " + + description); } SimpleSElement element = new SimpleSElement(description);