import org.apache.tools.ant.ProjectHelper;
import org.apache.tools.ant.helper.ProjectHelper2;
import org.apache.tools.ant.listener.CommonsLoggingListener;
+import org.argeo.slc.core.SlcException;
import org.argeo.slc.core.process.SlcExecution;
import org.argeo.slc.core.structure.DefaultSRegistry;
import org.argeo.slc.core.structure.SimpleSElement;
public void init() {
try {
+ try {
+ if (rootDir != null)
+ System.setProperty(SlcAntConstants.ROOT_DIR_PROPERTY,
+ rootDir.getURL().toString());
+ if (confDir != null)
+ System.setProperty(SlcAntConstants.CONF_DIR_PROPERTY,
+ confDir.getURL().toString());
+ } catch (IOException e) {
+ throw new SlcAntException("Cannot interpret dir as URL.", e);
+ }
+ if (workDir != null)
+ System.setProperty(SlcAntConstants.WORK_DIR_PROPERTY, workDir
+ .toString());
+
if (confDir != null && contextLocation == null) {
contextLocation = confDir
.createRelative("applicationContext.xml");
public SlcExecutionContext execute(SlcExecution slcExecution,
Properties properties, Map<String, Object> references) {
+ log.info("### Start SLC execution " + slcExecution.getUuid() + " ###");
if (log.isDebugEnabled()) {
- log.debug("### Start SLC execution " + slcExecution.getUuid()
- + " ###");
log.debug("rootDir=" + rootDir);
log.debug("confDir=" + confDir);
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<String> targets = findAntTargets(slcExecution);
log.trace("script(absolute)=" + script);
if (script.exists())
return script;
-
+
script = new FileSystemResource(scriptStr);
if (log.isTraceEnabled())
log.trace("script(fs)=" + script);
.toString()));
}
+ if (System.getProperty(SlcAntConstants.DEFAULT_TEST_RUN_PROPERTY) == null) {
+ System.setProperty(SlcAntConstants.DEFAULT_TEST_RUN_PROPERTY,
+ "defaultTestRun");
+ }
+
try {
GenericApplicationContext ctx = new GenericApplicationContext(
context);
}
log.debug("scriptPath=" + scriptPath);
- List<String> dirNames = new Vector<String>();
StringTokenizer st = new StringTokenizer(scriptPath, "/");
TreeSPath currPath = null;
while (st.hasMoreTokens()) {
// SLC CONF PROPERTIES\r
/** Path to the root Spring application context */\r
public static String APPLICATION_CONTEXT_PROPERTY = "slc.applicationContext";\r
- /** Name of the Spring bean used by default */\r
- public static String DEFAULT_TEST_RUN_PROPERTY = "slc.defaultTestRun";\r
-\r
// SLC LOCAL PROPERTIES\r
/** Property for the dir label (SLC local property file). */\r
public static String DIR_LABEL_PROPERTY = "slc.dirLabel";\r
+ "/applicationContext.xml");\r
}\r
// Default test run\r
- if (all.getProperty(DEFAULT_TEST_RUN_PROPERTY) == null) {\r
- all.setProperty(DEFAULT_TEST_RUN_PROPERTY, "defaultTestRun");\r
+ if (all.getProperty(SlcAntConstants.DEFAULT_TEST_RUN_PROPERTY) == null) {\r
+ all.setProperty(SlcAntConstants.DEFAULT_TEST_RUN_PROPERTY, "defaultTestRun");\r
}\r
\r
// Default log4j\r
public final static String CONF_DIR_PROPERTY = "slc.confDir";
/** Property for the work dir (SLC root property file). */
public final static String WORK_DIR_PROPERTY = "slc.workDir";
+ /** Name of the Spring bean used by default */
+ public final static String DEFAULT_TEST_RUN_PROPERTY = "slc.defaultTestRun";
}
import org.apache.commons.logging.LogFactory;\r
import org.apache.tools.ant.BuildException;\r
import org.argeo.slc.ant.SlcAntConfig;\r
+import org.argeo.slc.ant.SlcAntConstants;\r
import org.argeo.slc.ant.spring.SpringArg;\r
import org.argeo.slc.ant.structure.SAwareTask;\r
import org.argeo.slc.core.deploy.DeployedSystem;\r
if (testRunBean != null) {\r
testRunBeanT = testRunBean;\r
} else {\r
- testRunBeanT = getProject().getUserProperty(\r
- SlcAntConfig.DEFAULT_TEST_RUN_PROPERTY);\r
+ testRunBeanT = getProject().getProperty(\r
+ SlcAntConstants.DEFAULT_TEST_RUN_PROPERTY);\r
}\r
WritableTestRun testRun = null;\r
\r
public SlcExecutionContext executeScript(Resource script,
Properties properties, Map<String, Object> references) {
- if (runtimeContext == null)
- runtimeContext = new GenericApplicationContext();
+ if (runtimeContext == null) {
+ GenericApplicationContext ctx = new GenericApplicationContext();
+ ctx.refresh();
+ runtimeContext = ctx;
+ }
SlcExecution slcExecution = new SlcExecution();
slcExecution.setUuid(UUID.randomUUID().toString());
slcExecution.setUser(System.getProperty("user.name"));
slcExecution.setStatus(SlcExecution.STATUS_RUNNING);
- slcExecution.getAttributes().put(SlcAntConstants.EXECATTR_ANT_FILE,
- script.toString());
+ try {
+ slcExecution.getAttributes().put(SlcAntConstants.EXECATTR_ANT_FILE,
+ script.getURL().toString());
+ } catch (IOException e) {
+ throw new SlcException("Cannot interpret script " + script
+ + " as URL.", e);
+ }
AntSlcApplication application = new AntSlcApplication();
prepareApplication(slcExecution, application, script);
Resource confDir = null;
File workDir = null;
// Root dir
- final Resource rootDir = getParentOfFile(slcRootFile);
+ final Resource rootDir = getParent(slcRootFile);
// Conf dir
String confDirStr = rootProps
confDir = runtimeContext.getResource(confDirStr);
if (confDir == null || !confDir.exists()) {
- confDir = rootDir.createRelative("../conf");
+ // confDir = rootDir.createRelative("../conf");
+ confDir = getParent(rootDir).createRelative("conf/");
}
// Work dir
application.setConfDir(confDir);
application.setRootDir(rootDir);
application.setWorkDir(workDir);
-
+
application.setSlcRuntime(this);
+
+ application.init();
} catch (IOException e) {
throw new SlcException(
"Could not prepare SLC application for SLC execution "
if (currPath.equals("/") || currPath.equals("")) {
return null;
} else {
- return findSlcRootFile(getParentOfDir(currDir));
+ return findSlcRootFile(getParent(currDir));
}
// int indx = currPath.lastIndexOf('/',currPath.length()-1);
return p;
}
- private Resource getParentOfDir(Resource dir) {
+ private Resource getParent(Resource res) {
try {
- return dir.createRelative("..");
- } catch (IOException e) {
- throw new SlcException("Cannot get parent for resource " + dir, e);
- }
- }
+ if (res.getURL().getPath().equals("/"))
+ return null;
- private Resource getParentOfFile(Resource file) {
- try {
- return file.createRelative(".");
+ String urlStr = res.getURL().toString();
+ if (urlStr.charAt(urlStr.length() - 1) == '/')
+ urlStr = urlStr.substring(0, urlStr.length() - 2);
+
+ String parentUrlStr = urlStr.substring(0, urlStr.lastIndexOf('/'));
+ return runtimeContext.getResource(parentUrlStr + '/');
} catch (IOException e) {
- throw new SlcException("Cannot get parent for resource " + file, e);
+ throw new SlcException("Cannot get parent for resource " + res, e);
}
}
+
+ // private Resource getParentOfFile(Resource file) {
+ // try {
+ // return file.createRelative(".");
+ // } catch (IOException e) {
+ // throw new SlcException("Cannot get parent for resource " + file, e);
+ // }
+ // }
}
printUsage();
}
+ // Execution
if (mode.equals(Mode.single)) {
DefaultSlcRuntime runtime = new DefaultSlcRuntime();
runtime.executeScript(new FileSystemResource(script), properties,