]> git.argeo.org Git - gpl/argeo-slc.git/blobdiff - org.argeo.slc/src/main/java/org/argeo/slc/ant/AntRegistryUtil.java
Introduce directory based structure
[gpl/argeo-slc.git] / org.argeo.slc / src / main / java / org / argeo / slc / ant / AntRegistryUtil.java
index c495b9253616202f293c84b869130482e69679e4..d257f55b2650f0309972b5240bcbe3d233d282db 100644 (file)
@@ -9,17 +9,19 @@ import org.apache.commons.logging.LogFactory;
 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
@@ -33,17 +35,19 @@ public class AntRegistryUtil {
                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
@@ -51,22 +55,19 @@ public class AntRegistryUtil {
 \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
-                       if (count != 0 && count % 2 == 0) {\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
@@ -77,5 +78,4 @@ public class AntRegistryUtil {
                runActive(antFile, activePaths);\r
 \r
        }\r
-\r
 }\r