X-Git-Url: http://git.argeo.org/?a=blobdiff_plain;f=runtime%2Forg.argeo.slc.support.simple%2Fsrc%2Fmain%2Fjava%2Forg%2Fargeo%2Fslc%2Fcore%2Fexecution%2FFileExecutionResources.java;fp=runtime%2Forg.argeo.slc.support.simple%2Fsrc%2Fmain%2Fjava%2Forg%2Fargeo%2Fslc%2Fcore%2Fexecution%2FFileExecutionResources.java;h=e35ff0014c418bd1eb16e75b0bef814bb41d3f0d;hb=d47f40b5d798eb0f3814ddd166749f13ca96a258;hp=0000000000000000000000000000000000000000;hpb=42b1fe5c5c5090b64eb6ca279ca0a865eaa2c2f8;p=gpl%2Fargeo-slc.git diff --git a/runtime/org.argeo.slc.support.simple/src/main/java/org/argeo/slc/core/execution/FileExecutionResources.java b/runtime/org.argeo.slc.support.simple/src/main/java/org/argeo/slc/core/execution/FileExecutionResources.java new file mode 100644 index 000000000..e35ff0014 --- /dev/null +++ b/runtime/org.argeo.slc.support.simple/src/main/java/org/argeo/slc/core/execution/FileExecutionResources.java @@ -0,0 +1,51 @@ +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; + } + +}