\r
import java.io.File;\r
import java.util.List;\r
-import java.util.Vector;\r
\r
import org.apache.commons.logging.Log;\r
import org.apache.commons.logging.LogFactory;\r
import org.apache.tools.ant.Project;\r
import org.apache.tools.ant.ProjectHelper;\r
\r
-import org.argeo.slc.core.structure.StructureElement;\r
import org.argeo.slc.core.structure.StructurePath;\r
import org.argeo.slc.core.structure.StructureRegistry;\r
\r
-/** Utilities to manipulate the structure registry in SLC Ant.*/\r
+/** Utilities to manipulate the structure registry in SLC Ant. */\r
public class AntRegistryUtil {\r
private static Log log = LogFactory.getLog(AntRegistryUtil.class);\r
\r
- /** Read a structure registry from an Ant file without executing it. */\r
+ /** Reads a structure registry from an Ant file without executing it. */\r
public static StructureRegistry readRegistry(File antFile) {\r
-\r
+ if (log.isDebugEnabled())\r
+ log.debug("Reads registry for Ant file " + antFile);\r
Project p = new Project();\r
p.setUserProperty("ant.file", antFile.getAbsolutePath());\r
+ p.setBaseDir(antFile.getParentFile());\r
p.init();\r
ProjectHelper helper = new SlcProjectHelper();\r
p.addReference("ant.projectHelper", helper);\r
return registry;\r
}\r
\r
- /** Execute only the active paths of teh Ant files. */\r
- public static void runActive(File antFile, List<StructurePath> activePaths) {\r
-\r
+ /** Executes only the active paths of the Ant file. */\r
+ public static Project runActive(File antFile,\r
+ List<StructurePath> activePaths) {\r
+ if (log.isDebugEnabled())\r
+ log.debug("Runs the " + activePaths.size()\r
+ + " provided active paths of Ant file " + antFile);\r
Project p = new Project();\r
p.setUserProperty("ant.file", antFile.getAbsolutePath());\r
+ p.setBaseDir(antFile.getParentFile());\r
p.init();\r
ProjectHelper helper = new SlcProjectHelper();\r
p.addReference("ant.projectHelper", helper);\r
registry.setMode(StructureRegistry.ACTIVE);\r
registry.setActivePaths(activePaths);\r
p.executeTarget(p.getDefaultTarget());\r
+ return p;\r
}\r
\r
- public static void main(String[] args) {\r
- File antFile = new File(\r
- "C:/dev/workspaces/default/org.argeo.slc/src/test/ant/build.xml");\r
- System\r
- .setProperty(SlcAntConfig.APPLICATION_CONTEXT_PROPERTY,\r
- "C:/dev/workspaces/default/org.argeo.slc/src/test/ant/applicationContext.xml");\r
- StructureRegistry registry = AntRegistryUtil.readRegistry(antFile);\r
-\r
- StringBuffer buf = new StringBuffer("");\r
-\r
- int count = 0;\r
- List<StructurePath> activePaths = new Vector<StructurePath>();\r
- for (StructureElement element : registry.listElements()) {\r
- buf.append(element.getPath());\r
- if (count != 0 && count % 3 == 0) {\r
- // skip\r
- } else {\r
- activePaths.add(element.getPath());\r
- buf.append(" <");\r
- }\r
- buf.append('\n');\r
- count++;\r
- }\r
- log.info(buf);\r
-\r
- runActive(antFile, activePaths);\r
-\r
+ /** Executes all paths of the default target of the Ant file. */\r
+ public static Project runAll(File antFile) {\r
+ if (log.isDebugEnabled())\r
+ log.debug("Runs all paths of Ant file " + antFile);\r
+ Project p = new Project();\r
+ p.setUserProperty("ant.file", antFile.getAbsolutePath());\r
+ p.setBaseDir(antFile.getParentFile());\r
+ p.init();\r
+ ProjectHelper helper = new SlcProjectHelper();\r
+ p.addReference("ant.projectHelper", helper);\r
+ helper.parse(p, antFile);\r
+ p.executeTarget(p.getDefaultTarget());\r
+ return p;\r
}\r
-\r
}\r