1 package org
.argeo
.slc
.ant
;
5 import java
.util
.Vector
;
7 import org
.apache
.commons
.logging
.Log
;
8 import org
.apache
.commons
.logging
.LogFactory
;
9 import org
.apache
.tools
.ant
.Project
;
10 import org
.apache
.tools
.ant
.ProjectHelper
;
12 import org
.argeo
.slc
.core
.structure
.StructurePath
;
13 import org
.argeo
.slc
.core
.structure
.StructureRegistry
;
15 /** Utilities to manipulate the structure registry in SLC Ant. */
16 public class AntRegistryUtil
{
17 private static Log log
= LogFactory
.getLog(AntRegistryUtil
.class);
19 /** Read a structure registry from an Ant file without executing it. */
20 public static StructureRegistry
readRegistry(File antFile
) {
22 Project p
= new Project();
23 p
.setUserProperty("ant.file", antFile
.getAbsolutePath());
24 p
.setBaseDir(antFile
.getParentFile());
26 ProjectHelper helper
= new SlcProjectHelper();
27 p
.addReference("ant.projectHelper", helper
);
28 helper
.parse(p
, antFile
);
30 StructureRegistry registry
= (StructureRegistry
) p
31 .getReference(SlcProjectHelper
.REF_STRUCTURE_REGISTRY
);
32 registry
.setMode(StructureRegistry
.READ
);
34 p
.executeTarget(p
.getDefaultTarget());
38 /** Execute only the active paths of teh Ant files. */
39 public static void runActive(File antFile
, List
<StructurePath
> activePaths
) {
41 Project p
= new Project();
42 p
.setUserProperty("ant.file", antFile
.getAbsolutePath());
43 p
.setBaseDir(antFile
.getParentFile());
45 ProjectHelper helper
= new SlcProjectHelper();
46 p
.addReference("ant.projectHelper", helper
);
47 helper
.parse(p
, antFile
);
49 StructureRegistry registry
= (StructureRegistry
) p
50 .getReference(SlcProjectHelper
.REF_STRUCTURE_REGISTRY
);
51 registry
.setMode(StructureRegistry
.ACTIVE
);
52 registry
.setActivePaths(activePaths
);
53 p
.executeTarget(p
.getDefaultTarget());
56 public static void main(String
[] args
) {
57 File antFile
= new File(
58 "C:/dev/workspaces/default/org.argeo.slc/src/test/slc/root/Category1/SubCategory2/build.xml");
59 StructureRegistry registry
= AntRegistryUtil
.readRegistry(antFile
);
61 StringBuffer buf
= new StringBuffer("");
64 List
<StructurePath
> activePaths
= new Vector
<StructurePath
>();
65 for (StructurePath path
: registry
.listPaths()) {
67 if (count
!= 0 && count
% 3 == 0) {
70 activePaths
.add(path
);
78 runActive(antFile
, activePaths
);