public void run() {
try {
for (Runnable executable : executables) {
- doExecuteRunnable(executable);
+ this.doExecuteRunnable(executable);
}
} catch (RuntimeException e) {
if (failOnError)
package org.argeo.slc.core.execution;
+import java.io.File;
+
import org.springframework.core.io.Resource;
public interface ExecutionResources {
+ /** The base directory where this execution can write */
+ public File getWritableBaseDir();
+
/** Allocates a local file in the writable area and return it as a resource. */
public Resource getWritableResource(String relativePath);
+ /**
+ * Allocates a local file in the writable area and return it as a fully
+ * qualified OS path.
+ */
+ public String getWritableOsPath(String relativePath);
+
+ /**
+ * Allocates a local file in the writable area and return it as a
+ * {@link File}.
+ */
+ public File getWritableOsFile(String relativePath);
+
/**
* Returns the resource as a file path. If the resource is not writable it
* is copied as a file in the writable area and the path to this local file
return resource;
}
+ public String getWritableOsPath(String relativePath) {
+ try {
+ return getFile(relativePath).getCanonicalPath();
+ } catch (IOException e) {
+ throw new SlcException("Cannot find canonical path", e);
+ }
+ }
+
+ public File getWritableOsFile(String relativePath) {
+ return getFile(relativePath);
+ }
+
public String getAsOsPath(Resource resource, Boolean overwrite) {
File file = fileFromResource(resource);
if (file != null)
}
- public File getFile(String relativePath) {
+ protected File getFile(String relativePath) {
+ File writableBaseDir = getWritableBaseDir();
+ return new File(writableBaseDir.getPath() + File.separator
+ + relativePath.replace('/', File.separatorChar));
+ }
+ public File getWritableBaseDir() {
if (withExecutionSubdirectory) {
Assert.notNull(executionContext, "execution context is null");
String path = baseDir.getPath()
executionContext
.getVariable(ExecutionContext.VAR_EXECUTION_CONTEXT_CREATION_DATE))
+ executionContext.getUuid();
- File executionDir = new File(path);
-
- return new File(executionDir.getPath() + File.separator
- + relativePath.replace('/', File.separatorChar));
+ return new File(path);
} else {
- return new File(baseDir.getPath() + File.separator
- + relativePath.replace('/', File.separatorChar));
+ return baseDir;
}
}
import org.argeo.slc.SlcException;
import org.argeo.slc.UnsupportedException;
import org.argeo.slc.core.execution.ExecutionResources;
-import org.argeo.slc.core.structure.tree.TreeSRelatedHelper;
import org.argeo.slc.core.test.SimpleResultPart;
import org.argeo.slc.test.TestResult;
import org.argeo.slc.test.TestStatus;
import org.springframework.core.io.Resource;
/** Execute an OS specific system call. */
-public class SystemCall extends TreeSRelatedHelper implements Runnable {
+public class SystemCall implements Runnable {
public final static String LOG_STDOUT = "System.out";
private final Log log = LogFactory.getLog(getClass());
if (log.isTraceEnabled())
log.trace(msg);
if (testResult != null) {
- forwardPath(testResult, null);
+ forwardPath(testResult);
testResult.addResultPart(new SimpleResultPart(
TestStatus.PASSED, msg));
}
public void onProcessFailed(ExecuteException e) {
String msg = "System call '" + commandLine + "' failed.";
if (testResult != null) {
- forwardPath(testResult, null);
+ forwardPath(testResult);
testResult.addResultPart(new SimpleResultPart(
TestStatus.ERROR, msg, e));
} else {
};
}
+ protected void forwardPath(TestResult testResult) {
+ // TODO: allocate a TreeSPath
+ }
+
/**
* Shortcut method getting the execDir to use
*/
/** Append the argument (for chaining) */
public SystemCall arg(String arg) {
+ if (command == null)
+ command = new ArrayList<Object>();
command.add(arg);
return this;
}
/** Append the argument (for chaining) */
public SystemCall arg(String arg, String value) {
+ if (command == null)
+ command = new ArrayList<Object>();
command.add(arg);
command.add(value);
return this;
import org.argeo.slc.SlcException;
import org.argeo.slc.core.execution.DefaultExecutionFlow;
+import org.argeo.slc.execution.ExecutionFlow;
+import org.springframework.beans.factory.BeanDefinitionStoreException;
import org.springframework.beans.factory.config.RuntimeBeanReference;
+import org.springframework.beans.factory.support.AbstractBeanDefinition;
import org.springframework.beans.factory.support.BeanDefinitionBuilder;
import org.springframework.beans.factory.support.ManagedList;
import org.springframework.beans.factory.support.ManagedMap;
if (StringUtils.hasText(parent))
builder.setParentName(parent);
-
- builder.getBeanDefinition().setDescription(DomUtils.getChildElementValueByTagName(element,
- "description"));
-
+ builder.getBeanDefinition().setDescription(
+ DomUtils.getChildElementValueByTagName(element, "description"));
+
List<Element> execElems = new ArrayList<Element>();
List<Element> argsElems = new ArrayList<Element>();
NodeList nodeList = element.getChildNodes();
if (node instanceof Element) {
if (DomUtils.nodeNameEquals(node, "arg"))
argsElems.add((Element) node);
- else if(!DomUtils.nodeNameEquals(node, "description"))
+ else if (!DomUtils.nodeNameEquals(node, "description"))
execElems.add((Element) node);
}
}
// Executables
if (execElems.size() != 0) {
ManagedList executables = new ManagedList(execElems.size());
- for(Element child : execElems) {
- // child validity check is performed in xsd
+ for (Element child : execElems) {
+ // child validity check is performed in xsd
executables.add(NamespaceUtils.parseBeanOrReference(child,
- parserContext, builder.getBeanDefinition()));
+ parserContext, builder.getBeanDefinition()));
}
- builder.addPropertyValue("executables", executables);
+ if (executables.size() > 0)
+ builder.addPropertyValue("executables", executables);
}
}
+ @SuppressWarnings("unchecked")
@Override
- protected Class<DefaultExecutionFlow> getBeanClass(Element element) {
- return DefaultExecutionFlow.class;
+ protected Class<? extends ExecutionFlow> getBeanClass(Element element) {
+ String clss = element.getAttribute("class");
+ if (StringUtils.hasText(clss))
+ // TODO: check that it actually works
+ try {
+ return (Class<? extends ExecutionFlow>) getClass()
+ .getClassLoader().loadClass(clss);
+ } catch (ClassNotFoundException e) {
+ try {
+ return (Class<? extends ExecutionFlow>) Thread
+ .currentThread().getContextClassLoader().loadClass(
+ clss);
+ } catch (ClassNotFoundException e1) {
+ throw new SlcException("Cannot load class " + clss, e);
+ }
+ }
+ else
+ return DefaultExecutionFlow.class;
}
// parse nested bean definition
// builder.getBeanDefinition());
// }
+ @Override
+ protected String resolveId(Element element,
+ AbstractBeanDefinition definition, ParserContext parserContext)
+ throws BeanDefinitionStoreException {
+ String name = element.getAttribute("name");
+ if (StringUtils.hasText(name)) {
+ return name;
+ } else {
+ return super.resolveId(element, definition, parserContext);
+ }
+ }
+
protected boolean shouldGenerateIdAsFallback() {
return true;
}