X-Git-Url: http://git.argeo.org/?a=blobdiff_plain;f=org.argeo.slc.agent%2Fsrc%2Fmain%2Fjava%2Forg%2Fargeo%2Fslc%2Fant%2FAntSlcApplication.java;h=b6c98ebbc3e44f6c571783fd190c05a0c8ce0872;hb=c0460581ca0679267f9c66759ea9ecf598e1b6d0;hp=8b8d2e4e5e3f564e85f646851f167603c2d6d3fa;hpb=489db3e2297debe1a32e5e98534d5dbf059e1c1d;p=gpl%2Fargeo-slc.git diff --git a/org.argeo.slc.agent/src/main/java/org/argeo/slc/ant/AntSlcApplication.java b/org.argeo.slc.agent/src/main/java/org/argeo/slc/ant/AntSlcApplication.java index 8b8d2e4e5..b6c98ebbc 100644 --- a/org.argeo.slc.agent/src/main/java/org/argeo/slc/ant/AntSlcApplication.java +++ b/org.argeo.slc.agent/src/main/java/org/argeo/slc/ant/AntSlcApplication.java @@ -28,10 +28,10 @@ import org.argeo.slc.core.structure.tree.TreeSPath; import org.argeo.slc.core.structure.tree.TreeSRegistry; import org.argeo.slc.logging.Log4jUtils; import org.argeo.slc.runtime.SlcExecutionOutput; +import org.springframework.beans.factory.BeanFactoryUtils; import org.springframework.beans.factory.ListableBeanFactory; import org.springframework.beans.factory.config.PropertyPlaceholderConfigurer; import org.springframework.beans.factory.xml.XmlBeanDefinitionReader; -import org.springframework.context.ApplicationContext; import org.springframework.context.ConfigurableApplicationContext; import org.springframework.context.support.GenericApplicationContext; import org.springframework.core.io.DefaultResourceLoader; @@ -45,7 +45,7 @@ public class AntSlcApplication { private final static Log log = LogFactory.getLog(AntSlcApplication.class); private Resource contextLocation; - private ApplicationContext parentContext; + private ConfigurableApplicationContext parentContext; private Resource rootDir; private Resource confDir; @@ -67,29 +67,32 @@ public class AntSlcApplication { log.debug("workDir=" + workDir); } - // Spring initialization - ConfigurableApplicationContext ctx = createExecutionContext(slcExecution); - // Ant coordinates String scriptRelativePath = findAntScript(slcExecution); List targets = findAntTargets(slcExecution); + // Spring initialization + ConfigurableApplicationContext ctx = createExecutionContext(slcExecution); + // Ant project initialization Project project = new Project(); AntExecutionContext executionContext = new AntExecutionContext(project); - project.addReference(SlcAntConstants.REF_ROOT_CONTEXT, ctx); - project.addReference(SlcAntConstants.REF_SLC_EXECUTION, slcExecution); - initProject(project, properties, references); - parseProject(project, scriptRelativePath); + project.addReference(AntConstants.REF_ROOT_CONTEXT, ctx); + project.addReference(AntConstants.REF_SLC_EXECUTION, slcExecution); - // Execute project - initStructure(project, scriptRelativePath); - runProject(project, targets); + try { + initProject(project, properties, references); + parseProject(project, scriptRelativePath); - if (executionOutput != null) - executionOutput.postExecution(executionContext); + // Execute project + initStructure(project, scriptRelativePath); + runProject(project, targets); - ctx.close(); + if (executionOutput != null) + executionOutput.postExecution(executionContext); + } finally { + ctx.close(); + } } protected void initSystemProperties(Properties userProperties) { @@ -102,20 +105,20 @@ public class AntSlcApplication { } } - if (System.getProperty(SlcAntConstants.DEFAULT_TEST_RUN_PROPERTY) == null) { - System.setProperty(SlcAntConstants.DEFAULT_TEST_RUN_PROPERTY, + if (System.getProperty(AntConstants.DEFAULT_TEST_RUN_PROPERTY) == null) { + System.setProperty(AntConstants.DEFAULT_TEST_RUN_PROPERTY, "defaultTestRun"); } try { if (rootDir != null) - System.setProperty(SlcAntConstants.ROOT_DIR_PROPERTY, rootDir + System.setProperty(AntConstants.ROOT_DIR_PROPERTY, rootDir .getURL().toString()); if (confDir != null) - System.setProperty(SlcAntConstants.CONF_DIR_PROPERTY, confDir + System.setProperty(AntConstants.CONF_DIR_PROPERTY, confDir .getURL().toString()); if (workDir != null) - System.setProperty(SlcAntConstants.WORK_DIR_PROPERTY, workDir + System.setProperty(AntConstants.WORK_DIR_PROPERTY, workDir .getCanonicalPath()); // Additional properties in slc.properties file. Already set sytem @@ -155,7 +158,7 @@ public class AntSlcApplication { // Find runtime definition Resource runtimeRes = null; String runtimeStr = slcExecution.getAttributes().get( - SlcAntConstants.EXECATTR_RUNTIME); + AntConstants.EXECATTR_RUNTIME); if (runtimeStr == null) runtimeStr = "default"; @@ -208,7 +211,7 @@ public class AntSlcApplication { protected String findAntScript(SlcExecution slcExecution) { String scriptStr = slcExecution.getAttributes().get( - SlcAntConstants.EXECATTR_ANT_FILE); + AntConstants.EXECATTR_ANT_FILE); if (scriptStr == null) throw new SlcException("No Ant script provided"); @@ -217,7 +220,7 @@ public class AntSlcApplication { protected List findAntTargets(SlcExecution slcExecution) { String targetList = slcExecution.getAttributes().get( - SlcAntConstants.EXECATTR_ANT_TARGETS); + AntConstants.EXECATTR_ANT_TARGETS); List targets = new Vector(); if (targetList != null) { StringTokenizer stTargets = new StringTokenizer(targetList, ","); @@ -246,16 +249,17 @@ public class AntSlcApplication { project.addBuildListener(new CommonsLoggingListener()); ListableBeanFactory context = (ListableBeanFactory) project - .getReference(SlcAntConstants.REF_ROOT_CONTEXT); + .getReference(AntConstants.REF_ROOT_CONTEXT); // Register build listeners - Map listeners = context.getBeansOfType( - BuildListener.class, false, true); + Map listeners = BeanFactoryUtils + .beansOfTypeIncludingAncestors(context, BuildListener.class, + false, false); for (BuildListener listener : listeners.values()) { project.addBuildListener(listener); } // Register log4j appenders from context - MDC.put(SlcAntConstants.MDC_ANT_PROJECT, project); + MDC.put(AntConstants.MDC_ANT_PROJECT, project); Map appenders = context.getBeansOfType( Appender.class, false, true); for (Appender appender : appenders.values()) { @@ -269,7 +273,7 @@ public class AntSlcApplication { /** Loads the SLC specific Ant tasks. */ protected void addCustomTaskAndTypes(Project project) { Properties taskdefs = getDefs(project, - SlcAntConstants.SLC_TASKDEFS_RESOURCE_PATH); + AntConstants.SLC_TASKDEFS_RESOURCE_PATH); for (Object o : taskdefs.keySet()) { String name = o.toString(); try { @@ -280,7 +284,7 @@ public class AntSlcApplication { } } Properties typedefs = getDefs(project, - SlcAntConstants.SLC_TYPEDEFS_RESOURCE_PATH); + AntConstants.SLC_TYPEDEFS_RESOURCE_PATH); for (Object o : typedefs.keySet()) { String name = o.toString(); try { @@ -307,7 +311,7 @@ public class AntSlcApplication { protected void initStructure(Project project, String scriptRelativePath) { // Init structure registry StructureRegistry registry = new TreeSRegistry(); - project.addReference(SlcAntConstants.REF_STRUCTURE_REGISTRY, registry); + project.addReference(AntConstants.REF_STRUCTURE_REGISTRY, registry); // Lowest levels StringTokenizer st = new StringTokenizer(scriptRelativePath, "/"); @@ -334,7 +338,7 @@ public class AntSlcApplication { .getDescription() : projectPath.getName(); registry.register(projectPath, new SimpleSElement(projectDesc)); - project.addReference(SlcAntConstants.REF_PROJECT_PATH, projectPath); + project.addReference(AntConstants.REF_PROJECT_PATH, projectPath); if (log.isDebugEnabled()) log.debug("Project path: " + projectPath); @@ -399,7 +403,7 @@ public class AntSlcApplication { this.workDir = workDir; } - public void setParentContext(ApplicationContext runtimeContext) { + public void setParentContext(ConfigurableApplicationContext runtimeContext) { this.parentContext = runtimeContext; }