X-Git-Url: http://git.argeo.org/?a=blobdiff_plain;f=org.argeo.slc%2Fsrc%2Fmain%2Fjava%2Forg%2Fargeo%2Fslc%2Fant%2FAntRegistryUtil.java;h=d257f55b2650f0309972b5240bcbe3d233d282db;hb=2052d0beab9c68880b3e8b0172a707274004b35f;hp=c495b9253616202f293c84b869130482e69679e4;hpb=40768ea8b087bc653a49c2400045f4c191e8e3b4;p=gpl%2Fargeo-slc.git diff --git a/org.argeo.slc/src/main/java/org/argeo/slc/ant/AntRegistryUtil.java b/org.argeo.slc/src/main/java/org/argeo/slc/ant/AntRegistryUtil.java index c495b9253..d257f55b2 100644 --- a/org.argeo.slc/src/main/java/org/argeo/slc/ant/AntRegistryUtil.java +++ b/org.argeo.slc/src/main/java/org/argeo/slc/ant/AntRegistryUtil.java @@ -9,17 +9,19 @@ import org.apache.commons.logging.LogFactory; import org.apache.tools.ant.Project; import org.apache.tools.ant.ProjectHelper; -import org.argeo.slc.core.structure.StructureElement; import org.argeo.slc.core.structure.StructurePath; import org.argeo.slc.core.structure.StructureRegistry; +/** Utilities to manipulate the structure registry in SLC Ant. */ public class AntRegistryUtil { private static Log log = LogFactory.getLog(AntRegistryUtil.class); + /** Read a structure registry from an Ant file without executing it. */ public static StructureRegistry readRegistry(File antFile) { Project p = new Project(); p.setUserProperty("ant.file", antFile.getAbsolutePath()); + p.setBaseDir(antFile.getParentFile()); p.init(); ProjectHelper helper = new SlcProjectHelper(); p.addReference("ant.projectHelper", helper); @@ -33,17 +35,19 @@ public class AntRegistryUtil { return registry; } + /** Execute only the active paths of teh Ant files. */ public static void runActive(File antFile, List activePaths) { Project p = new Project(); p.setUserProperty("ant.file", antFile.getAbsolutePath()); + p.setBaseDir(antFile.getParentFile()); p.init(); ProjectHelper helper = new SlcProjectHelper(); p.addReference("ant.projectHelper", helper); helper.parse(p, antFile); StructureRegistry registry = (StructureRegistry) p - .getReference(SlcProjectHelper.REF_STRUCTURE_REGISTRY); + .getReference(SlcProjectHelper.REF_STRUCTURE_REGISTRY); registry.setMode(StructureRegistry.ACTIVE); registry.setActivePaths(activePaths); p.executeTarget(p.getDefaultTarget()); @@ -51,22 +55,19 @@ public class AntRegistryUtil { public static void main(String[] args) { File antFile = new File( - "C:/dev/workspaces/default/org.argeo.slc/src/test/ant/build.xml"); - System - .setProperty(SlcProjectHelper.PROP_APPLICATION_CONTEXT, - "C:/dev/workspaces/default/org.argeo.slc/src/test/ant/applicationContext.xml"); + "C:/dev/workspaces/default/org.argeo.slc/src/test/slc/root/Category1/SubCategory2/build.xml"); StructureRegistry registry = AntRegistryUtil.readRegistry(antFile); StringBuffer buf = new StringBuffer(""); int count = 0; List activePaths = new Vector(); - for (StructureElement element : registry.listElements()) { - buf.append(element.getPath()); - if (count != 0 && count % 2 == 0) { + for (StructurePath path : registry.listPaths()) { + buf.append(path); + if (count != 0 && count % 3 == 0) { // skip } else { - activePaths.add(element.getPath()); + activePaths.add(path); buf.append(" <"); } buf.append('\n'); @@ -77,5 +78,4 @@ public class AntRegistryUtil { runActive(antFile, activePaths); } - }