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
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
public static StructureRegistry readRegistry(File antFile) {\r
\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
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
\r
StructureRegistry registry = (StructureRegistry) p\r
- .getReference(SlcProjectHelper.REF_STRUCTURE_REGISTRY);\r
+ .getReference(SlcProjectHelper.REF_STRUCTURE_REGISTRY);\r
registry.setMode(StructureRegistry.ACTIVE);\r
registry.setActivePaths(activePaths);\r
p.executeTarget(p.getDefaultTarget());\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(SlcProjectHelper.PROP_APPLICATION_CONTEXT,\r
- "C:/dev/workspaces/default/org.argeo.slc/src/test/ant/applicationContext.xml");\r
+ "C:/dev/workspaces/default/org.argeo.slc/src/test/slc/root/Category1/SubCategory2/build.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
+ for (StructurePath path : registry.listPaths()) {\r
+ buf.append(path);\r
if (count != 0 && count % 3 == 0) {\r
// skip\r
} else {\r
- activePaths.add(element.getPath());\r
+ activePaths.add(path);\r
buf.append(" <");\r
}\r
buf.append('\n');\r
runActive(antFile, activePaths);\r
\r
}\r
-\r
}\r