]> git.argeo.org Git - gpl/argeo-slc.git/blobdiff - org.argeo.slc.agent/src/main/java/org/argeo/slc/ant/AntSlcApplication.java
Merge from 0.11.mbaudier (OSGi libraries)
[gpl/argeo-slc.git] / org.argeo.slc.agent / src / main / java / org / argeo / slc / ant / AntSlcApplication.java
index b6c98ebbc3e44f6c571783fd190c05a0c8ce0872..410098d212aceee51bdc7d31a8c87edd0b66e0a1 100644 (file)
@@ -19,7 +19,6 @@ import org.apache.tools.ant.BuildListener;
 import org.apache.tools.ant.Project;
 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.SimpleSElement;
@@ -112,11 +111,9 @@ public class AntSlcApplication {
 
                try {
                        if (rootDir != null)
-                               System.setProperty(AntConstants.ROOT_DIR_PROPERTY, rootDir
-                                               .getURL().toString());
+                               setSystemPropertyForRes(AntConstants.ROOT_DIR_PROPERTY, rootDir);
                        if (confDir != null)
-                               System.setProperty(AntConstants.CONF_DIR_PROPERTY, confDir
-                                               .getURL().toString());
+                               setSystemPropertyForRes(AntConstants.CONF_DIR_PROPERTY, confDir);
                        if (workDir != null)
                                System.setProperty(AntConstants.WORK_DIR_PROPERTY, workDir
                                                .getCanonicalPath());
@@ -136,7 +133,8 @@ public class AntSlcApplication {
                                                IOUtils.closeQuietly(in);
                                        }
 
-                                       for (String key : slcProperties.stringPropertyNames()) {
+                                       for (Object obj : slcProperties.keySet()) {
+                                               String key = obj.toString();
                                                if (!System.getProperties().containsKey(key)) {
                                                        String value = SystemPropertyUtils
                                                                        .resolvePlaceholders(slcProperties
@@ -151,6 +149,21 @@ public class AntSlcApplication {
                }
        }
 
+       /**
+        * Set property as an absolute file path if the resource can be located on
+        * the file system, or as an url.
+        */
+       private void setSystemPropertyForRes(String key, Resource res)
+                       throws IOException {
+               String value = null;
+               try {
+                       value = res.getFile().getCanonicalPath();
+               } catch (IOException e) {
+                       value = res.getURL().toString();
+               }
+               System.setProperty(key, value);
+       }
+
        protected ConfigurableApplicationContext createExecutionContext(
                        SlcExecution slcExecution) {
                try {
@@ -160,7 +173,8 @@ public class AntSlcApplication {
                        String runtimeStr = slcExecution.getAttributes().get(
                                        AntConstants.EXECATTR_RUNTIME);
                        if (runtimeStr == null)
-                               runtimeStr = "default";
+                               runtimeStr = System.getProperty(AntConstants.RUNTIME_PROPERTY,
+                                               "default");
 
                        ResourceLoader rl = new DefaultResourceLoader(getClass()
                                        .getClassLoader());
@@ -246,7 +260,7 @@ public class AntSlcApplication {
                        }
                }
 
-               project.addBuildListener(new CommonsLoggingListener());
+               //project.addBuildListener(new CommonsLoggingListener());
 
                ListableBeanFactory context = (ListableBeanFactory) project
                                .getReference(AntConstants.REF_ROOT_CONTEXT);