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=76865aef57d8fafe032add61fd3f4a0f00d81632;hb=48d35a213a2b0d792b11b5df276158159105043b;hp=79f325a9c781dbd0032ecaac10330804498254dc;hpb=787d5761e4d125e527104a0455ab47d4eaf38ac1;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 79f325a9c..76865aef5 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 @@ -23,12 +23,14 @@ import org.argeo.slc.core.structure.SimpleSElement; import org.argeo.slc.core.structure.StructureRegistry; import org.argeo.slc.core.structure.tree.TreeSPath; import org.argeo.slc.core.structure.tree.TreeSRegistry; +import org.argeo.slc.runtime.SlcExecutionContext; import org.argeo.slc.runtime.SlcRuntime; import org.springframework.beans.factory.BeanDefinitionStoreException; 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.FileSystemResource; import org.springframework.core.io.Resource; public class AntSlcApplication { @@ -41,7 +43,7 @@ public class AntSlcApplication { private Resource rootDir; private Resource confDir; - private Resource workDir; + private File workDir; public void init() { try { @@ -66,8 +68,8 @@ public class AntSlcApplication { } - public void execute(SlcExecution slcExecution, Properties properties, - Map references) { + public SlcExecutionContext execute(SlcExecution slcExecution, + Properties properties, Map references) { if (log.isDebugEnabled()) { log.debug("### Start SLC execution " + slcExecution.getUuid() + " ###"); @@ -76,13 +78,24 @@ public class AntSlcApplication { log.debug("workDir=" + workDir); } + if (rootDir != null) + properties.put(SlcAntConstants.ROOT_DIR_PROPERTY, rootDir + .toString()); + if (confDir != null) + properties.put(SlcAntConstants.CONF_DIR_PROPERTY, confDir + .toString()); + if (workDir != null) + properties.put(SlcAntConstants.WORK_DIR_PROPERTY, workDir + .toString()); + // Ant coordinates Resource script = findAntScript(slcExecution); List targets = findAntTargets(slcExecution); - ConfigurableApplicationContext ctx = createExecutionContext(); + ConfigurableApplicationContext ctx = createExecutionContext(properties); 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); @@ -90,8 +103,10 @@ public class AntSlcApplication { initStructure(project, script); runProject(project, targets); - + ctx.close(); + + return executionContext; } protected Resource findAntScript(SlcExecution slcExecution) { @@ -118,11 +133,18 @@ public class AntSlcApplication { log.trace("script(absolute)=" + script); if (script.exists()) return script; + + script = new FileSystemResource(scriptStr); + if (log.isTraceEnabled()) + log.trace("script(fs)=" + script); + if (script.exists()) + return script; - throw new SlcAntException("Cannot find Ant script " + scriptStr); } catch (Exception e) { throw new SlcAntException("Cannot find Ant script " + scriptStr, e); } + + throw new SlcAntException("Cannot find Ant script " + scriptStr); } protected List findAntTargets(SlcExecution slcExecution) { @@ -138,7 +160,15 @@ public class AntSlcApplication { return targets; } - protected ConfigurableApplicationContext createExecutionContext() { + protected ConfigurableApplicationContext createExecutionContext( + Properties userProperties) { + // Set user properties as system properties so that Spring can access + // them + for (Object key : userProperties.keySet()) { + System.setProperty(key.toString(), userProperties.getProperty(key + .toString())); + } + try { GenericApplicationContext ctx = new GenericApplicationContext( context); @@ -311,7 +341,7 @@ public class AntSlcApplication { this.confDir = confDir; } - public void setWorkDir(Resource workDir) { + public void setWorkDir(File workDir) { this.workDir = workDir; }