X-Git-Url: http://git.argeo.org/?a=blobdiff_plain;f=org.argeo.slc%2Fsrc%2Fmain%2Fjava%2Forg%2Fargeo%2Fslc%2Fant%2FSlcProjectHelper.java;h=cefa61f69ab4e4ff462046393f2f5df0a60ed94f;hb=2f6d4fafcbd3fb0560c178356b91ddc9833d325d;hp=8fdefc23f7b61e612792148c939b279df4aa6eac;hpb=2052d0beab9c68880b3e8b0172a707274004b35f;p=gpl%2Fargeo-slc.git
diff --git a/org.argeo.slc/src/main/java/org/argeo/slc/ant/SlcProjectHelper.java b/org.argeo.slc/src/main/java/org/argeo/slc/ant/SlcProjectHelper.java
index 8fdefc23f..cefa61f69 100644
--- a/org.argeo.slc/src/main/java/org/argeo/slc/ant/SlcProjectHelper.java
+++ b/org.argeo.slc/src/main/java/org/argeo/slc/ant/SlcProjectHelper.java
@@ -4,10 +4,11 @@ import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.util.List;
+import java.util.Map;
import java.util.Properties;
import java.util.Vector;
-import org.springframework.context.ApplicationContext;
+import org.springframework.context.support.AbstractApplicationContext;
import org.springframework.context.support.FileSystemXmlApplicationContext;
import org.apache.commons.logging.Log;
@@ -17,56 +18,67 @@ import org.apache.tools.ant.Project;
import org.apache.tools.ant.helper.ProjectHelperImpl;
import org.argeo.slc.core.structure.DefaultSRegistry;
+import org.argeo.slc.core.structure.SimpleSElement;
import org.argeo.slc.core.structure.StructureRegistry;
-import org.argeo.slc.core.structure.tree.TreeSElement;
import org.argeo.slc.core.structure.tree.TreeSPath;
/**
- * Custom implementation of a ProjectHelper
binding a Spring
+ * Custom implementation of an Ant ProjectHelper
binding a Spring
* application context and a structure registry with the Ant project.
*/
public class SlcProjectHelper extends ProjectHelperImpl {
- private static Log log = LogFactory.getLog(SlcProjectHelper.class);
+ private static Log log;
+ /** The Ant reference to the Spring application context used. */
public static String REF_ROOT_CONTEXT = "slcApplicationContext";
+ /** The Ant reference to the SLC structure registry used. */
public static String REF_STRUCTURE_REGISTRY = "slcStructureRegistry";
- public static String REF_PROJECT_PATH = "slcProjectPath";
-
- private String slcRootFileName = "slcRoot.properties";
- private String slcLocalFileName = "slcLocal.properties";
+ /** The Ant reference to the TreePath
of the current project */
+ private static String REF_PROJECT_PATH = "slcProjectPath";
+ /**
+ * Resource path to the property file listing the SLC specific Ant tasks:
+ * /org/argeo/slc/ant/taskdefs.properties
+ */
+ private static String SLC_TASKDEFS_RESOURCE_PATH = "/org/argeo/slc/ant/taskdefs.properties";
@Override
public void parse(Project project, Object source) throws BuildException {
- log.debug("Entered SLC project helper");
- // look for root file
- File projectBaseDir = project.getBaseDir();
- File slcRootFile = findSlcRootFile(projectBaseDir);
- if (slcRootFile == null) {
- throw new SlcAntException("Cannot find SLC root file");
+ // initialize config
+ SlcAntConfig slcAntConfig = new SlcAntConfig();
+
+ if(!slcAntConfig.initProject(project)){
+ // not SLC compatible, do normal Ant
+ super.parse(project, source);
+ return;
+ }
+
+ if (log == null) {
+ // log4j is initialized only now
+ log = LogFactory.getLog(SlcProjectHelper.class);
}
- SlcAntConfig.initProject(project, slcRootFile);
+ log.debug("SLC properties are set, starting initialization..");
// init Spring application context
- String acPath = project
- .getUserProperty(SlcAntConfig.APPLICATION_CONTEXT_PROPERTY);
- ApplicationContext context = new FileSystemXmlApplicationContext(acPath);
- project.addReference(REF_ROOT_CONTEXT, context);
+ initSpringContext(project);
- // init structure register if it does not exist
+ // init structure registry
DefaultSRegistry registry = new DefaultSRegistry();
project.addReference(REF_STRUCTURE_REGISTRY, registry);
// call the underlying implementation to do the actual work
super.parse(project, source);
+ // create structure root
+ registerProjectAndParents(project, slcAntConfig);
+
addSlcTasks(project);
- // create structure root
- registerProjectAndParents(project);
}
- private void registerProjectAndParents(Project project) {
+ /** Creates the tree-based structure for this project. */
+ private void registerProjectAndParents(Project project,
+ SlcAntConfig slcAntConfig) {
StructureRegistry registry = (StructureRegistry) project
.getReference(REF_STRUCTURE_REGISTRY);
File rootDir = new File(project
@@ -79,32 +91,27 @@ public class SlcProjectHelper extends ProjectHelperImpl {
do {
dirs.add(currentDir);
currentDir = currentDir.getParentFile();
- log.trace("List " + currentDir);
+ if (log.isTraceEnabled())
+ log.trace("List " + currentDir);
} while (!currentDir.equals(rootDir.getParentFile()));
- TreeSPath currPath = null;
+ // first path is root dir (because of previous algorithm)
+ TreeSPath currPath = TreeSPath.createRootPath(rootDir.getName());
for (int i = dirs.size() - 1; i >= 0; i--) {
File dir = dirs.get(i);
- String description = dir.getName();
- File slcLocal = new File(dir.getPath() + File.separator
- + slcLocalFileName);
- if (slcLocal.exists()) {
- Properties properties = SlcAntConfig.loadFile(slcLocal
- .getAbsolutePath());
- description = properties
- .getProperty(SlcAntConfig.DIR_DESCRIPTION_PROPERTY);
+ // retrieves description for this path
+ final String description;
+ if (i == 0) {// project itself
+ description = project.getDescription() != null ? project
+ .getDescription() : "";
} else {
- if (i == 0) {// project it self
- description = project.getDescription() != null ? project
- .getDescription() : "";
- }
+ description = slcAntConfig.getDescriptionForDir(dir);
}
- TreeSElement element = new TreeSElement(description);
+ SimpleSElement element = new SimpleSElement(description);
- if (dir.equals(rootDir)) {
- currPath = TreeSPath.createRootPath(rootDir.getName());
- } else {
+ // creates and register path
+ if (!dir.equals(rootDir)) {// already set
currPath = currPath.createChild(dir.getName());
}
registry.register(currPath, element);
@@ -112,31 +119,28 @@ public class SlcProjectHelper extends ProjectHelperImpl {
project.addReference(REF_PROJECT_PATH, currPath);
}
- /** Get the path of a project (root). */
+ /** Gets the path of a project (root). */
public static TreeSPath getProjectPath(Project project) {
return (TreeSPath) project.getReference(REF_PROJECT_PATH);
}
- private File findSlcRootFile(File dir) {
- for (File file : dir.listFiles()) {
- if (!file.isDirectory() && file.getName().equals(slcRootFileName)) {
- return file;
- }
- }
-
- File parentDir = dir.getParentFile();
- if (parentDir == null) {
- return null;// stop condition: not found
- } else {
- return findSlcRootFile(parentDir);
- }
+ /** Initializes the Spring application context. */
+ private void initSpringContext(Project project) {
+ System.getProperties().putAll((Map, ?>) project.getProperties());
+ String acPath = project
+ .getUserProperty(SlcAntConfig.APPLICATION_CONTEXT_PROPERTY);
+ AbstractApplicationContext context = new FileSystemXmlApplicationContext(
+ acPath);
+ context.registerShutdownHook();
+ project.addReference(REF_ROOT_CONTEXT, context);
}
+ /** Loads the SLC specific Ant tasks. */
private void addSlcTasks(Project project) {
Properties taskdefs = new Properties();
try {
InputStream in = project.getClass().getResourceAsStream(
- "/org/argeo/slc/ant/taskdefs.properties");
+ SLC_TASKDEFS_RESOURCE_PATH);
taskdefs.load(in);
in.close();
} catch (IOException e) {