--- /dev/null
+<?xml version="1.0" encoding="UTF-8"?>\r
+<beans xmlns="http://www.springframework.org/schema/beans"\r
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p"\r
+ xmlns:aop="http://www.springframework.org/schema/aop"\r
+ xsi:schemaLocation="\r
+ http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd\r
+ http://www.springframework.org/schema/lang http://www.springframework.org/schema/lang/spring-lang-2.5.xsd\r
+ http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.5.xsd">\r
+\r
+ <bean id="attachments" parent="slcTemplate.simpleFlow">\r
+ <property name="executables">\r
+ <list>\r
+ <bean parent="task.echo">\r
+ <property name="message" value="DATA" />\r
+ <property name="writeTo" ref="attachment.writeTo" />\r
+ </bean>\r
+\r
+ <bean parent="task.uploadAttachments">\r
+ <property name="attachmentUploader" ref="attachmentUploader" />\r
+ <property name="attachment">\r
+ <bean parent="taskArg.attachment">\r
+ <property name="name" value="myAttachment" />\r
+ <property name="contentType" value="text/xml" />\r
+ </bean>\r
+ </property>\r
+ <property name="resource" ref="attachment.writeTo" />\r
+ <property name="attachTo">\r
+ <list>\r
+ <ref bean="attachments.testResult" />\r
+ </list>\r
+ </property>\r
+ </bean>\r
+\r
+ <bean parent="task.closeTestResult" scope="execution">\r
+ <property name="testResult" ref="attachments.testResult" />\r
+ </bean>\r
+ </list>\r
+ </property>\r
+ </bean>\r
+\r
+ <bean id="attachments.testResult" parent="slcDefault.test.basicTreeTestResult"\r
+ scope="execution">\r
+ <property name="listeners" ref="resultListeners" />\r
+ <aop:scoped-proxy />\r
+ </bean>\r
+\r
+ <bean id="attachment.writeTo" factory-bean="attachment.resourcesManager"\r
+ factory-method="getWritableResource" scope="execution">\r
+ <constructor-arg value="subdir/writeTo" />\r
+ <aop:scoped-proxy />\r
+ </bean>\r
+\r
+ <bean id="attachment.resourcesManager" parent="slcTemplate.fileResources">\r
+ <property name="executionContext" ref="executionContext" />\r
+ </bean>\r
+\r
+</beans>
\ No newline at end of file
<property name="testData" ref="ref1" />\r
</bean>\r
\r
+ <!-- Attachments -->\r
+ <bean parent="task.echo">\r
+ <property name="message" value="DATA" />\r
+ <property name="writeTo" ref="basic.writeTo" />\r
+ </bean>\r
+\r
<bean parent="task.uploadAttachments">\r
<property name="attachmentUploader" ref="attachmentUploader" />\r
<property name="attachment">\r
<bean parent="taskArg.attachment">\r
<property name="name" value="myAttachment" />\r
- <property name="contentType" value="text/xml" />\r
- <property name="uuid" value="1" />\r
+ <property name="contentType" value="text/plain" />\r
</bean>\r
</property>\r
- <property name="resource" value="osgibundle:/conf/main.xml" />\r
+ <property name="resource" ref="basic.writeTo" />\r
<property name="attachTo">\r
<list>\r
<ref bean="basic.testResult" />\r
<property name="testResult" ref="basic.testResult" />\r
</bean>\r
\r
+ <bean id="basic.writeTo" factory-bean="attachment.resourcesManager"\r
+ factory-method="getWritableResource" scope="execution">\r
+ <constructor-arg value="subdir/writeTo" />\r
+ <aop:scoped-proxy />\r
+ </bean>\r
+\r
+ <bean id="basic.resourcesManager" parent="slcTemplate.fileResources">\r
+ <property name="executionContext" ref="executionContext" />\r
+ </bean>\r
+\r
+\r
\r
</beans>
\ No newline at end of file
</class>
</bind-xml>
</field>
+ <field name="attachments" collection="arraylist"
+ type="org.argeo.slc.core.attachment.SimpleAttachment">
+ <bind-xml auto-naming="deriveByClass" location="attachments" />
+ </field>
</class>
import org.argeo.slc.SlcException;
public class FileAttachmentsStorage implements AttachmentsStorage {
- private File attachmentsDirectory = new File(System
- .getProperty("java.io.tmpdir")
- + File.separator + "slcAttachments");
+ private File attachmentsDirectory;
+
+ public FileAttachmentsStorage() {
+ String osgiInstanceArea = System.getProperty("osgi.instance.area");
+ if (osgiInstanceArea != null) {
+ if (osgiInstanceArea.startsWith("file:"))
+ osgiInstanceArea = osgiInstanceArea.substring("file:".length());
+ attachmentsDirectory = new File(osgiInstanceArea + File.separator
+ + "executionResources");
+ }
+
+ if (attachmentsDirectory == null) {
+ String tempDir = System.getProperty("java.io.tmpdir");
+ attachmentsDirectory = new File(tempDir + File.separator
+ + "slcAttachments");
+ }
+ }
public void retrieveAttachment(Attachment attachment,
OutputStream outputStream) {
package org.argeo.slc.core.attachment;
+import java.util.UUID;
+
public class SimpleAttachment implements Attachment {
- private String uuid;
+ private String uuid = UUID.randomUUID().toString();
private String name;
private String contentType;
--- /dev/null
+package org.argeo.slc.core.execution;
+
+import org.springframework.core.io.Resource;
+
+public interface ExecutionResources {
+ public Resource getWritableResource(String relativePath);
+}
--- /dev/null
+package org.argeo.slc.core.execution;
+
+import java.io.File;
+
+import org.argeo.slc.execution.ExecutionContext;
+import org.springframework.core.io.FileSystemResource;
+import org.springframework.core.io.Resource;
+
+public class FileExecutionResources implements ExecutionResources {
+ private File baseDir;
+ private ExecutionContext executionContext;
+
+ public FileExecutionResources() {
+ String osgiInstanceArea = System.getProperty("osgi.instance.area");
+ if (osgiInstanceArea != null) {
+ if (osgiInstanceArea.startsWith("file:"))
+ osgiInstanceArea = osgiInstanceArea.substring("file:".length());
+ baseDir = new File(osgiInstanceArea + File.separator
+ + "executionResources");
+ }
+
+ if (baseDir == null) {
+ String tempDir = System.getProperty("java.io.tmpdir");
+ baseDir = new File(tempDir + File.separator
+ + "slcExecutionResources");
+ }
+ }
+
+ public Resource getWritableResource(String relativePath) {
+ File file = getFile(relativePath);
+ file.getParentFile().mkdirs();
+ return new FileSystemResource(file);
+ }
+
+ public File getFile(String relativePath) {
+ File executionDir = new File(baseDir.getPath() + File.separator
+ + executionContext.getUuid());
+ if (!executionDir.exists())
+ executionDir.mkdirs();
+ return new File(executionDir.getPath() + File.separator + relativePath);
+ }
+
+ public void setBaseDir(File baseDir) {
+ this.baseDir = baseDir;
+ }
+
+ public void setExecutionContext(ExecutionContext executionContext) {
+ this.executionContext = executionContext;
+ }
+
+}
package org.argeo.slc.core.execution.tasks;
+import java.io.File;
+import java.io.IOException;
+
+import org.apache.commons.io.FileUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
+import org.argeo.slc.SlcException;
+import org.springframework.core.io.Resource;
public class Echo implements Runnable {
private final static Log defaultLog = LogFactory.getLog(Echo.class);
+ private Resource writeTo = null;
private Log log;
private String message;
public void run() {
log().info(message);
+
+ if (writeTo != null) {
+ try {
+ File file = writeTo.getFile();
+ if (log().isDebugEnabled())
+ log().debug("Write to " + file);
+ FileUtils.writeStringToFile(file, message);
+ } catch (IOException e) {
+ throw new SlcException("Could not write to " + writeTo, e);
+ }
+ }
}
protected Log log() {
this.message = message;
}
+ public void setWriteTo(Resource writeTo) {
+ this.writeTo = writeTo;
+ }
+
}
package org.argeo.slc.core.test.tree;
+import java.util.ArrayList;
import java.util.Date;
import java.util.Hashtable;
+import java.util.List;
import java.util.Map;
+import org.argeo.slc.core.attachment.SimpleAttachment;
+
public class ResultAttributes {
private String uuid = null;
private Date closeDate = null;
private Map<String, String> attributes = new Hashtable<String, String>();
+ private List<SimpleAttachment> attachments = new ArrayList<SimpleAttachment>();
public ResultAttributes() {
super();
this.uuid = ttr.getUuid();
this.attributes = ttr.getAttributes();
this.closeDate = ttr.getCloseDate();
+ this.attachments = ttr.getAttachments();
}
public String getUuid() {
this.closeDate = closeDate;
}
+ public List<SimpleAttachment> getAttachments() {
+ return attachments;
+ }
+
+ public void setAttachments(List<SimpleAttachment> attachments) {
+ this.attachments = attachments;
+ }
+
}
import org.argeo.slc.SlcException;\r
import org.argeo.slc.core.attachment.Attachment;\r
import org.argeo.slc.core.attachment.AttachmentsEnabled;\r
+import org.argeo.slc.core.attachment.SimpleAttachment;\r
import org.argeo.slc.core.structure.tree.TreeSPath;\r
import org.argeo.slc.structure.StructureAware;\r
import org.argeo.slc.structure.StructureElement;\r
\r
private SortedMap<TreeSPath, PartSubList> resultParts = new TreeMap<TreeSPath, PartSubList>();\r
private SortedMap<TreeSPath, StructureElement> elements = new TreeMap<TreeSPath, StructureElement>();\r
- private List<Attachment> attachments = new ArrayList<Attachment>();\r
+ private List<SimpleAttachment> attachments = new ArrayList<SimpleAttachment>();\r
\r
private Map<String, String> attributes = new TreeMap<String, String>();\r
\r
this.warnIfAlreadyClosed = warnIfAlreadyClosed;\r
}\r
\r
- public List<Attachment> getAttachments() {\r
+ public List<SimpleAttachment> getAttachments() {\r
return attachments;\r
}\r
\r
- public void setAttachments(List<Attachment> attachments) {\r
+ public void setAttachments(List<SimpleAttachment> attachments) {\r
this.attachments = attachments;\r
}\r
\r
public void addAttachment(Attachment attachment) {\r
- attachments.add(attachment);\r
+ attachments.add((SimpleAttachment) attachment);\r
synchronized (listeners) {\r
for (TestResultListener<TreeTestResult> listener : listeners) {\r
if (listener instanceof TreeTestResultListener)\r
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.5.xsd">
<import resource="specs.xml" />
+ <import resource="templates.xml" />
<import resource="tasks/core.xml" />
<bean class="org.springframework.beans.factory.config.CustomScopeConfigurer">
--- /dev/null
+<?xml version="1.0" encoding="UTF-8"?>
+<beans xmlns="http://www.springframework.org/schema/beans"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p"
+ xsi:schemaLocation="
+ http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd">
+
+ <bean id="slcTemplate.fileResources" class="org.argeo.slc.core.execution.FileExecutionResources"
+ abstract="true" />
+
+</beans>
\ No newline at end of file