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=37bdff0dce8f93f352dd6dbfaf4e8e5fb1306998;hb=e95a183611a40be7aca3233bb19b89bdc5043338;hp=76c8331178a6f5a02dd7141d0482ec5cd939af71;hpb=25d89428acf5108e3732511573ffc9ed80796d99;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 76c833117..37bdff0dc 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; @@ -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(AntConstants.REF_ROOT_CONTEXT, ctx); project.addReference(AntConstants.REF_SLC_EXECUTION, slcExecution); - initProject(project, properties, references); - parseProject(project, scriptRelativePath); - // 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) { @@ -109,11 +112,9 @@ public class AntSlcApplication { try { if (rootDir != null) - System.setProperty(AntConstants.ROOT_DIR_PROPERTY, rootDir - .getURL().toString()); + setSystemPropertyForRes(AntConstants.ROOT_DIR_PROPERTY, rootDir); if (confDir != null) - System.setProperty(AntConstants.CONF_DIR_PROPERTY, confDir - .getURL().toString()); + setSystemPropertyForRes(AntConstants.CONF_DIR_PROPERTY, confDir); if (workDir != null) System.setProperty(AntConstants.WORK_DIR_PROPERTY, workDir .getCanonicalPath()); @@ -133,7 +134,8 @@ public class AntSlcApplication { IOUtils.closeQuietly(in); } - for (String key : slcProperties.stringPropertyNames()) { + for (Object obj : slcProperties.keySet()) { + String key = obj.toString(); if (!System.getProperties().containsKey(key)) { String value = SystemPropertyUtils .resolvePlaceholders(slcProperties @@ -148,6 +150,21 @@ public class AntSlcApplication { } } + /** + * Set property as an absolute file path if the resource can be located on + * the file system, or as an url. + */ + private void setSystemPropertyForRes(String key, Resource res) + throws IOException { + String value = null; + try { + value = res.getFile().getCanonicalPath(); + } catch (IOException e) { + value = res.getURL().toString(); + } + System.setProperty(key, value); + } + protected ConfigurableApplicationContext createExecutionContext( SlcExecution slcExecution) { try { @@ -157,7 +174,8 @@ public class AntSlcApplication { String runtimeStr = slcExecution.getAttributes().get( AntConstants.EXECATTR_RUNTIME); if (runtimeStr == null) - runtimeStr = "default"; + runtimeStr = System.getProperty(AntConstants.RUNTIME_PROPERTY, + "default"); ResourceLoader rl = new DefaultResourceLoader(getClass() .getClassLoader()); @@ -248,8 +266,9 @@ public class AntSlcApplication { ListableBeanFactory context = (ListableBeanFactory) project .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); }