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
.StructureElement
;
13 import org
.argeo
.slc
.core
.structure
.StructurePath
;
14 import org
.argeo
.slc
.core
.structure
.StructureRegistry
;
16 public class AntRegistryUtil
{
17 private static Log log
= LogFactory
.getLog(AntRegistryUtil
.class);
19 public static StructureRegistry
readRegistry(File antFile
) {
21 Project p
= new Project();
22 p
.setUserProperty("ant.file", antFile
.getAbsolutePath());
24 ProjectHelper helper
= new SlcProjectHelper();
25 p
.addReference("ant.projectHelper", helper
);
26 helper
.parse(p
, antFile
);
28 StructureRegistry registry
= (StructureRegistry
) p
29 .getReference(SlcProjectHelper
.REF_STRUCTURE_REGISTRY
);
30 registry
.setMode(StructureRegistry
.READ
);
32 p
.executeTarget(p
.getDefaultTarget());
36 public static void runActive(File antFile
, List
<StructurePath
> activePaths
) {
38 Project p
= new Project();
39 p
.setUserProperty("ant.file", antFile
.getAbsolutePath());
41 ProjectHelper helper
= new SlcProjectHelper();
42 p
.addReference("ant.projectHelper", helper
);
43 helper
.parse(p
, antFile
);
45 StructureRegistry registry
= (StructureRegistry
) p
46 .getReference(SlcProjectHelper
.REF_STRUCTURE_REGISTRY
);
47 registry
.setMode(StructureRegistry
.ACTIVE
);
48 registry
.setActivePaths(activePaths
);
49 p
.executeTarget(p
.getDefaultTarget());
52 public static void main(String
[] args
) {
53 File antFile
= new File(
54 "C:/dev/workspaces/default/org.argeo.slc/src/test/ant/build.xml");
56 .setProperty(SlcProjectHelper
.PROP_APPLICATION_CONTEXT
,
57 "C:/dev/workspaces/default/org.argeo.slc/src/test/ant/applicationContext.xml");
58 StructureRegistry registry
= AntRegistryUtil
.readRegistry(antFile
);
60 StringBuffer buf
= new StringBuffer("");
63 List
<StructurePath
> activePaths
= new Vector
<StructurePath
>();
64 for (StructureElement element
: registry
.listElements()) {
65 buf
.append(element
.getPath());
66 if (count
!= 0 && count
% 2 == 0) {
69 activePaths
.add(element
.getPath());
77 runActive(antFile
, activePaths
);