]> git.argeo.org Git - gpl/argeo-slc.git/blobdiff - runtime/org.argeo.slc.core/src/main/java/org/argeo/slc/core/execution/FileExecutionResources.java
Improve executions and system calls
[gpl/argeo-slc.git] / runtime / org.argeo.slc.core / src / main / java / org / argeo / slc / core / execution / FileExecutionResources.java
index 361cede76ee3e17979433316a748e0495e056ef6..0f3a8dc5841051cca98785f68c2967e8280ea66b 100644 (file)
@@ -80,17 +80,17 @@ public class FileExecutionResources implements ExecutionResources {
        }
 
        public String getAsOsPath(Resource resource, Boolean overwrite) {
-               File file = null;
-               try {
-                       file = resource.getFile();
-                       return file.getCanonicalPath();
-               } catch (IOException e) {
-                       if (log.isTraceEnabled())
-                               log
-                                               .trace("Resource "
-                                                               + resource
-                                                               + " is not available on the file system. Retrieving it...");
-               }
+               File file = fileFromResource(resource);
+               if (file != null)
+                       try {
+                               return file.getCanonicalPath();
+                       } catch (IOException e1) {
+                               // silent
+                       }
+
+               if (log.isTraceEnabled())
+                       log.trace("Resource " + resource
+                                       + " is not available on the file system. Retrieving it...");
 
                InputStream in = null;
                OutputStream out = null;
@@ -116,12 +116,30 @@ public class FileExecutionResources implements ExecutionResources {
                }
        }
 
+       /**
+        * Extract the underlying file from the resource.
+        * 
+        * @return the file or null if no files support this resource.
+        */
+       protected File fileFromResource(Resource resource) {
+               try {
+                       return resource.getFile();
+               } catch (IOException e) {
+                       return null;
+               }
+
+       }
+
        public File getFile(String relativePath) {
 
                if (withExecutionSubdirectory) {
                        Assert.notNull(executionContext, "execution context is null");
-                       String path = baseDir.getPath() + File.separator
-                                       + sdf().format(executionContext.getCreationDate())
+                       String path = baseDir.getPath()
+                                       + File.separator
+                                       + sdf()
+                                                       .format(
+                                                                       executionContext
+                                                                                       .getVariable(ExecutionContext.VAR_EXECUTION_CONTEXT_CREATION_DATE))
                                        + executionContext.getUuid();
                        File executionDir = new File(path);