import org.apache.tools.ant.Project;\r
import org.apache.tools.ant.helper.ProjectHelper2;\r
\r
-import org.argeo.slc.core.UnsupportedException;\r
import org.argeo.slc.core.structure.DefaultSRegistry;\r
import org.argeo.slc.core.structure.SimpleSElement;\r
import org.argeo.slc.core.structure.StructureRegistry;\r
private static String SLC_TASKDEFS_RESOURCE_PATH = "/org/argeo/slc/ant/taskdefs.properties";\r
private static String SLC_TYPEDEFS_RESOURCE_PATH = "/org/argeo/slc/ant/typedefs.properties";\r
\r
+ protected SlcAntConfig slcAntConfig = null;\r
+\r
@Override\r
public void parse(Project project, Object source) throws BuildException {\r
- if (!(source instanceof File)) {\r
- throw new UnsupportedException("Ant file", source);\r
+\r
+ if (source instanceof File) {\r
+ File sourceFile = (File) source;\r
+ // Reset basedir property, in order to avoid base dir override when\r
+ // running in Maven\r
+ project.setProperty("basedir", sourceFile.getParentFile()\r
+ .getAbsolutePath());\r
+ }\r
+\r
+ if (slcAntConfig != null) {\r
+ // Config already initialized (probably import), only parse\r
+ super.parse(project, source);\r
+ return;\r
}\r
- File sourceFile = (File) source;\r
\r
- // initialize config\r
- SlcAntConfig slcAntConfig = new SlcAntConfig();\r
+ // Initialize config\r
+ slcAntConfig = new SlcAntConfig();\r
\r
- // Reset basedir property, in order to avoid base dir override when\r
- // running in Maven\r
- project.setProperty("basedir", sourceFile.getParentFile()\r
- .getAbsolutePath());\r
if (!slcAntConfig.initProject(project)) {\r
// not SLC compatible, do normal Ant\r
super.parse(project, source);\r
return;\r
}\r
- \r
+\r
if (log == null) {\r
// log4j is initialized only now\r
log = LogFactory.getLog(SlcProjectHelper.class);\r
}\r
- log.debug("SLC properties are set, starting initialization for "+sourceFile);\r
\r
- // init Spring application context\r
+ if (log.isDebugEnabled())\r
+ log.debug("SLC properties are set, starting initialization for "\r
+ + source + " (projectHelper=" + this + ")");\r
+\r
+ beforeParsing(project);\r
+\r
+ // Calls the underlying implementation to do the actual work\r
+ super.parse(project, source);\r
+\r
+ afterParsing(project);\r
+ }\r
+\r
+ /**\r
+ * Performs operations after config initialization and before Ant file\r
+ * parsing. Performed only once when the main project file is parsed. Should\r
+ * be called by overriding methods.\r
+ */\r
+ protected void beforeParsing(Project project) {\r
+ // Init Spring application context\r
initSpringContext(project);\r
\r
- // init structure registry\r
+ // Init structure registry\r
DefaultSRegistry registry = new DefaultSRegistry();\r
project.addReference(REF_STRUCTURE_REGISTRY, registry);\r
+ }\r
\r
- // call the underlying implementation to do the actual work\r
- super.parse(project, source);\r
-\r
- // create structure root\r
+ /**\r
+ * Performs operations after parsing of the main file. Called only once (not\r
+ * for imports).\r
+ */\r
+ protected void afterParsing(Project project) {\r
+ // Creates structure root\r
registerProjectAndParents(project, slcAntConfig);\r
-\r
addCustomTaskAndTypes(project);\r
-\r
}\r
\r
/** Creates the tree-based structure for this project. */\r
private void registerProjectAndParents(Project project,\r
SlcAntConfig slcAntConfig) {\r
- StructureRegistry registry = (StructureRegistry) project\r
+ StructureRegistry<TreeSPath> registry = (StructureRegistry<TreeSPath>) project\r
.getReference(REF_STRUCTURE_REGISTRY);\r
File rootDir = new File(project\r
.getUserProperty(SlcAntConfig.ROOT_DIR_PROPERTY))\r
if (i == 0) {// project itself\r
description = project.getDescription() != null\r
&& !project.getDescription().equals("") ? project\r
- .getDescription() : slcAntConfig\r
- .getDescriptionForDir(dir);\r
+ .getDescription() : project.getName() != null ? project\r
+ .getName() : slcAntConfig.getDescriptionForDir(dir);\r
} else {\r
description = slcAntConfig.getDescriptionForDir(dir);\r
if (log.isTraceEnabled())\r