1 package org
.argeo
.slc
.ant
;
7 import java
.util
.Properties
;
9 import org
.apache
.commons
.logging
.Log
;
10 import org
.apache
.commons
.logging
.LogFactory
;
11 import org
.apache
.tools
.ant
.Project
;
12 import org
.apache
.tools
.ant
.ProjectHelper
;
14 import org
.argeo
.slc
.core
.structure
.StructurePath
;
15 import org
.argeo
.slc
.core
.structure
.StructureRegistry
;
17 /** Utilities to manipulate the structure registry in SLC Ant. */
18 public class AntRegistryUtil
{
19 private static Log log
= LogFactory
.getLog(AntRegistryUtil
.class);
21 /** Reads a structure registry from an Ant file without executing it. */
22 public static StructureRegistry
readRegistry(File antFile
) {
23 if (log
.isDebugEnabled())
24 log
.debug("Reads registry for Ant file " + antFile
);
25 Project p
= new Project();
26 p
.setUserProperty("ant.file", antFile
.getAbsolutePath());
27 p
.setBaseDir(antFile
.getParentFile());
29 ProjectHelper helper
= new SlcProjectHelper();
30 p
.addReference(ProjectHelper
.PROJECTHELPER_REFERENCE
, helper
);
31 helper
.parse(p
, antFile
);
33 StructureRegistry registry
= (StructureRegistry
) p
34 .getReference(SlcProjectHelper
.REF_STRUCTURE_REGISTRY
);
35 registry
.setMode(StructureRegistry
.READ
);
37 p
.executeTarget(p
.getDefaultTarget());
41 /** Executes only the active paths of the Ant file. */
42 public static Project
runActive(File antFile
,
43 List
<StructurePath
> activePaths
) {
44 if (log
.isDebugEnabled())
45 log
.debug("Runs the " + activePaths
.size()
46 + " provided active paths of Ant file " + antFile
);
47 Project p
= new Project();
48 p
.setUserProperty("ant.file", antFile
.getAbsolutePath());
49 p
.setBaseDir(antFile
.getParentFile());
51 ProjectHelper helper
= new SlcProjectHelper();
52 p
.addReference(ProjectHelper
.PROJECTHELPER_REFERENCE
, helper
);
53 helper
.parse(p
, antFile
);
55 StructureRegistry registry
= (StructureRegistry
) p
56 .getReference(SlcProjectHelper
.REF_STRUCTURE_REGISTRY
);
57 registry
.setMode(StructureRegistry
.ACTIVE
);
58 registry
.setActivePaths(activePaths
);
59 p
.executeTarget(p
.getDefaultTarget());
63 /** Executes all paths of the provided target of the Ant file. */
64 public static Project
runAll(File antFile
, String target
) {
65 if (log
.isDebugEnabled())
66 log
.debug("Runs all paths of Ant file " + antFile
);
67 Project p
= new Project();
68 p
.setUserProperty("ant.file", antFile
.getAbsolutePath());
69 p
.setBaseDir(antFile
.getParentFile());
71 ProjectHelper helper
= new SlcProjectHelper();
72 p
.addReference(ProjectHelper
.PROJECTHELPER_REFERENCE
, helper
);
73 helper
.parse(p
, antFile
);
74 p
.executeTarget(target
!= null ? target
: p
.getDefaultTarget());
78 /** Executes all paths of the provided target of the Ant URL. */
79 public static Project
runAll(URL url
, String target
, Properties properties
) {
80 if (log
.isDebugEnabled())
81 log
.debug("Runs all paths of Ant URL " + url
);
82 Project p
= new Project();
83 p
.setUserProperty("ant.file", url
.toString());
84 //p.setBaseDir(url.toString());
86 ProjectHelper helper
= new SlcProjectHelper();
87 p
.addReference(ProjectHelper
.PROJECTHELPER_REFERENCE
, helper
);
89 for(Map
.Entry
<Object
, Object
> entry
: properties
.entrySet()){
90 p
.setUserProperty(entry
.getKey().toString(), entry
.getValue().toString());
92 p
.executeTarget(target
!= null ? target
: p
.getDefaultTarget());
96 /** Executes all paths of the default target of the Ant file. */
97 public static Project
runAll(File antFile
) {
98 return runAll(antFile
, null);