import java.util.Properties;\r
import java.util.Vector;\r
\r
-import org.springframework.context.ApplicationContext;\r
+import org.springframework.context.support.AbstractApplicationContext;\r
import org.springframework.context.support.FileSystemXmlApplicationContext;\r
\r
import org.apache.commons.logging.Log;\r
import org.apache.tools.ant.helper.ProjectHelperImpl;\r
\r
import org.argeo.slc.core.structure.DefaultSRegistry;\r
+import org.argeo.slc.core.structure.SimpleSElement;\r
import org.argeo.slc.core.structure.StructureRegistry;\r
-import org.argeo.slc.core.structure.tree.TreeSElement;\r
import org.argeo.slc.core.structure.tree.TreeSPath;\r
\r
/**\r
* application context and a structure registry with the Ant project.\r
*/\r
public class SlcProjectHelper extends ProjectHelperImpl {\r
- private static Log log = LogFactory.getLog(SlcProjectHelper.class);\r
+ private static Log log ;\r
\r
public static String REF_ROOT_CONTEXT = "slcApplicationContext";\r
public static String REF_STRUCTURE_REGISTRY = "slcStructureRegistry";\r
\r
@Override\r
public void parse(Project project, Object source) throws BuildException {\r
- log.debug("Entered SLC project helper");\r
\r
// look for root file\r
File projectBaseDir = project.getBaseDir();\r
throw new SlcAntException("Cannot find SLC root file");\r
}\r
SlcAntConfig.initProject(project, slcRootFile);\r
+ \r
+ if(log == null){\r
+ // log4j is initialized only now\r
+ log = LogFactory.getLog(SlcProjectHelper.class);\r
+ }\r
+ log.debug("SLC properties are set, starting initialization..");\r
\r
// init Spring application context\r
- String acPath = project\r
- .getUserProperty(SlcAntConfig.APPLICATION_CONTEXT_PROPERTY);\r
- ApplicationContext context = new FileSystemXmlApplicationContext(acPath);\r
- project.addReference(REF_ROOT_CONTEXT, context);\r
-\r
- // init structure register if it does not exist\r
+ initSpringContext(project);\r
+ \r
+ // init structure registry\r
DefaultSRegistry registry = new DefaultSRegistry();\r
project.addReference(REF_STRUCTURE_REGISTRY, registry);\r
\r
// call the underlying implementation to do the actual work\r
super.parse(project, source);\r
\r
- addSlcTasks(project);\r
-\r
// create structure root\r
registerProjectAndParents(project);\r
\r
- // TreeSElement element = new TreeSElement(project.getDescription(),\r
- // "Root");\r
- // registry.register(getProjectPath(project), element);\r
+ addSlcTasks(project);\r
\r
}\r
\r
.getAbsolutePath());\r
description = properties\r
.getProperty(SlcAntConfig.DIR_DESCRIPTION_PROPERTY);\r
+ } else {\r
+ if (i == 0) {// project it self\r
+ description = project.getDescription() != null ? project\r
+ .getDescription() : "";\r
+ }\r
}\r
- TreeSElement element = new TreeSElement(description);\r
+ SimpleSElement element = new SimpleSElement(description);\r
\r
if (dir.equals(rootDir)) {\r
currPath = TreeSPath.createRootPath(rootDir.getName());\r
\r
/** Get the path of a project (root). */\r
public static TreeSPath getProjectPath(Project project) {\r
- // return TreeSPath.createRootPath(getProjectPathName(project));\r
return (TreeSPath) project.getReference(REF_PROJECT_PATH);\r
}\r
\r
- private static String getProjectPathName(Project project) {\r
- String projectName = project.getName() != null ? project.getName()\r
- : "project";\r
- return projectName;\r
- }\r
-\r
private File findSlcRootFile(File dir) {\r
for (File file : dir.listFiles()) {\r
if (!file.isDirectory() && file.getName().equals(slcRootFileName)) {\r
}\r
}\r
\r
+ private void initSpringContext(Project project) {\r
+ System.getProperties().putAll(project.getProperties());\r
+ String acPath = project\r
+ .getUserProperty(SlcAntConfig.APPLICATION_CONTEXT_PROPERTY);\r
+ AbstractApplicationContext context = new FileSystemXmlApplicationContext(acPath);\r
+ context.registerShutdownHook();\r
+ project.addReference(REF_ROOT_CONTEXT, context);\r
+ }\r
+\r
private void addSlcTasks(Project project) {\r
Properties taskdefs = new Properties();\r
try {\r