]> git.argeo.org Git - gpl/argeo-slc.git/commitdiff
New runtime end to end (working)
authorMathieu Baudier <mbaudier@argeo.org>
Thu, 19 Jun 2008 16:54:58 +0000 (16:54 +0000)
committerMathieu Baudier <mbaudier@argeo.org>
Thu, 19 Jun 2008 16:54:58 +0000 (16:54 +0000)
git-svn-id: https://svn.argeo.org/slc/trunk@1255 4cfe0d0a-d680-48aa-b62c-e0a02a3f76cc

org.argeo.slc.agent/src/main/java/org/argeo/slc/ant/AntSlcApplication.java
org.argeo.slc.agent/src/main/java/org/argeo/slc/ant/SlcAntConfig.java
org.argeo.slc.agent/src/main/java/org/argeo/slc/ant/SlcAntConstants.java
org.argeo.slc.agent/src/main/java/org/argeo/slc/ant/test/SlcTestTask.java
org.argeo.slc.agent/src/main/java/org/argeo/slc/cli/DefaultSlcRuntime.java
org.argeo.slc.agent/src/main/java/org/argeo/slc/cli/SlcMain.java

index 76865aef57d8fafe032add61fd3f4a0f00d81632..1a69c493bf7509eac155dfbc3d4e4e10ab15f8da 100644 (file)
@@ -17,6 +17,7 @@ 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.DefaultSRegistry;
 import org.argeo.slc.core.structure.SimpleSElement;
@@ -47,6 +48,20 @@ public class AntSlcApplication {
 
        public void init() {
                try {
+                       try {
+                               if (rootDir != null)
+                                       System.setProperty(SlcAntConstants.ROOT_DIR_PROPERTY,
+                                                       rootDir.getURL().toString());
+                               if (confDir != null)
+                                       System.setProperty(SlcAntConstants.CONF_DIR_PROPERTY,
+                                                       confDir.getURL().toString());
+                       } catch (IOException e) {
+                               throw new SlcAntException("Cannot interpret dir as URL.", e);
+                       }
+                       if (workDir != null)
+                               System.setProperty(SlcAntConstants.WORK_DIR_PROPERTY, workDir
+                                               .toString());
+
                        if (confDir != null && contextLocation == null) {
                                contextLocation = confDir
                                                .createRelative("applicationContext.xml");
@@ -70,24 +85,13 @@ public class AntSlcApplication {
 
        public SlcExecutionContext execute(SlcExecution slcExecution,
                        Properties properties, Map<String, Object> references) {
+               log.info("### Start SLC execution " + slcExecution.getUuid() + " ###");
                if (log.isDebugEnabled()) {
-                       log.debug("### Start SLC execution " + slcExecution.getUuid()
-                                       + " ###");
                        log.debug("rootDir=" + rootDir);
                        log.debug("confDir=" + confDir);
                        log.debug("workDir=" + workDir);
                }
 
-               if (rootDir != null)
-                       properties.put(SlcAntConstants.ROOT_DIR_PROPERTY, rootDir
-                                       .toString());
-               if (confDir != null)
-                       properties.put(SlcAntConstants.CONF_DIR_PROPERTY, confDir
-                                       .toString());
-               if (workDir != null)
-                       properties.put(SlcAntConstants.WORK_DIR_PROPERTY, workDir
-                                       .toString());
-
                // Ant coordinates
                Resource script = findAntScript(slcExecution);
                List<String> targets = findAntTargets(slcExecution);
@@ -133,7 +137,7 @@ public class AntSlcApplication {
                                log.trace("script(absolute)=" + script);
                        if (script.exists())
                                return script;
-                       
+
                        script = new FileSystemResource(scriptStr);
                        if (log.isTraceEnabled())
                                log.trace("script(fs)=" + script);
@@ -169,6 +173,11 @@ public class AntSlcApplication {
                                        .toString()));
                }
 
+               if (System.getProperty(SlcAntConstants.DEFAULT_TEST_RUN_PROPERTY) == null) {
+                       System.setProperty(SlcAntConstants.DEFAULT_TEST_RUN_PROPERTY,
+                                       "defaultTestRun");
+               }
+
                try {
                        GenericApplicationContext ctx = new GenericApplicationContext(
                                        context);
@@ -253,7 +262,6 @@ public class AntSlcApplication {
                        }
                        log.debug("scriptPath=" + scriptPath);
 
-                       List<String> dirNames = new Vector<String>();
                        StringTokenizer st = new StringTokenizer(scriptPath, "/");
                        TreeSPath currPath = null;
                        while (st.hasMoreTokens()) {
index 61b78cc7cd4207a7b7c41e4559a22bf1de5ce827..4c8981c174765570c8927405a0d51aae7e4cfbc4 100644 (file)
@@ -117,9 +117,6 @@ public class SlcAntConfig {
        // SLC CONF PROPERTIES\r
        /** Path to the root Spring application context */\r
        public static String APPLICATION_CONTEXT_PROPERTY = "slc.applicationContext";\r
-       /** Name of the Spring bean used by default */\r
-       public static String DEFAULT_TEST_RUN_PROPERTY = "slc.defaultTestRun";\r
-\r
        // SLC LOCAL PROPERTIES\r
        /** Property for the dir label (SLC local property file). */\r
        public static String DIR_LABEL_PROPERTY = "slc.dirLabel";\r
@@ -239,8 +236,8 @@ public class SlcAntConfig {
                                                + "/applicationContext.xml");\r
                        }\r
                        // Default test run\r
-                       if (all.getProperty(DEFAULT_TEST_RUN_PROPERTY) == null) {\r
-                               all.setProperty(DEFAULT_TEST_RUN_PROPERTY, "defaultTestRun");\r
+                       if (all.getProperty(SlcAntConstants.DEFAULT_TEST_RUN_PROPERTY) == null) {\r
+                               all.setProperty(SlcAntConstants.DEFAULT_TEST_RUN_PROPERTY, "defaultTestRun");\r
                        }\r
 \r
                        // Default log4j\r
index 2a8405e35f2b622ebf2bda74d6dc047d743d0132..a170b1e33e095e51dda7eafea4bdf4e2aff665f1 100644 (file)
@@ -30,5 +30,7 @@ public interface SlcAntConstants {
        public final static String CONF_DIR_PROPERTY = "slc.confDir";
        /** Property for the work dir (SLC root property file). */
        public final static String WORK_DIR_PROPERTY = "slc.workDir";
+       /** Name of the Spring bean used by default */
+       public final static String DEFAULT_TEST_RUN_PROPERTY = "slc.defaultTestRun";
 
 }
index ece9d350617a80bf449e2fc8c4785143323221e4..651ccad7b959eefd4c79f6825b7454a214dc6fef 100644 (file)
@@ -4,6 +4,7 @@ import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;\r
 import org.apache.tools.ant.BuildException;\r
 import org.argeo.slc.ant.SlcAntConfig;\r
+import org.argeo.slc.ant.SlcAntConstants;\r
 import org.argeo.slc.ant.spring.SpringArg;\r
 import org.argeo.slc.ant.structure.SAwareTask;\r
 import org.argeo.slc.core.deploy.DeployedSystem;\r
@@ -38,8 +39,8 @@ public class SlcTestTask extends SAwareTask {
                if (testRunBean != null) {\r
                        testRunBeanT = testRunBean;\r
                } else {\r
-                       testRunBeanT = getProject().getUserProperty(\r
-                                       SlcAntConfig.DEFAULT_TEST_RUN_PROPERTY);\r
+                       testRunBeanT = getProject().getProperty(\r
+                                       SlcAntConstants.DEFAULT_TEST_RUN_PROPERTY);\r
                }\r
                WritableTestRun testRun = null;\r
 \r
index 15aca3d86f57ebea423b7d8789e261d958a2a19a..7bb77e578d65ef067475cdc85f3be5a1cb3592bc 100644 (file)
@@ -36,8 +36,11 @@ public class DefaultSlcRuntime extends SimpleSlcRuntime implements
        public SlcExecutionContext executeScript(Resource script,
                        Properties properties, Map<String, Object> references) {
 
-               if (runtimeContext == null)
-                       runtimeContext = new GenericApplicationContext();
+               if (runtimeContext == null) {
+                       GenericApplicationContext ctx = new GenericApplicationContext();
+                       ctx.refresh();
+                       runtimeContext = ctx;
+               }
 
                SlcExecution slcExecution = new SlcExecution();
                slcExecution.setUuid(UUID.randomUUID().toString());
@@ -51,8 +54,13 @@ public class DefaultSlcRuntime extends SimpleSlcRuntime implements
 
                slcExecution.setUser(System.getProperty("user.name"));
                slcExecution.setStatus(SlcExecution.STATUS_RUNNING);
-               slcExecution.getAttributes().put(SlcAntConstants.EXECATTR_ANT_FILE,
-                               script.toString());
+               try {
+                       slcExecution.getAttributes().put(SlcAntConstants.EXECATTR_ANT_FILE,
+                                       script.getURL().toString());
+               } catch (IOException e) {
+                       throw new SlcException("Cannot interpret script " + script
+                                       + " as URL.", e);
+               }
 
                AntSlcApplication application = new AntSlcApplication();
                prepareApplication(slcExecution, application, script);
@@ -80,7 +88,7 @@ public class DefaultSlcRuntime extends SimpleSlcRuntime implements
                        Resource confDir = null;
                        File workDir = null;
                        // Root dir
-                       final Resource rootDir = getParentOfFile(slcRootFile);
+                       final Resource rootDir = getParent(slcRootFile);
 
                        // Conf dir
                        String confDirStr = rootProps
@@ -89,7 +97,8 @@ public class DefaultSlcRuntime extends SimpleSlcRuntime implements
                                confDir = runtimeContext.getResource(confDirStr);
 
                        if (confDir == null || !confDir.exists()) {
-                               confDir = rootDir.createRelative("../conf");
+                               // confDir = rootDir.createRelative("../conf");
+                               confDir = getParent(rootDir).createRelative("conf/");
                        }
 
                        // Work dir
@@ -116,8 +125,10 @@ public class DefaultSlcRuntime extends SimpleSlcRuntime implements
                        application.setConfDir(confDir);
                        application.setRootDir(rootDir);
                        application.setWorkDir(workDir);
-                       
+
                        application.setSlcRuntime(this);
+
+                       application.init();
                } catch (IOException e) {
                        throw new SlcException(
                                        "Could not prepare SLC application for SLC execution "
@@ -161,7 +172,7 @@ public class DefaultSlcRuntime extends SimpleSlcRuntime implements
                                if (currPath.equals("/") || currPath.equals("")) {
                                        return null;
                                } else {
-                                       return findSlcRootFile(getParentOfDir(currDir));
+                                       return findSlcRootFile(getParent(currDir));
                                }
                                // int indx = currPath.lastIndexOf('/',currPath.length()-1);
 
@@ -197,19 +208,27 @@ public class DefaultSlcRuntime extends SimpleSlcRuntime implements
                return p;
        }
 
-       private Resource getParentOfDir(Resource dir) {
+       private Resource getParent(Resource res) {
                try {
-                       return dir.createRelative("..");
-               } catch (IOException e) {
-                       throw new SlcException("Cannot get parent for resource " + dir, e);
-               }
-       }
+                       if (res.getURL().getPath().equals("/"))
+                               return null;
 
-       private Resource getParentOfFile(Resource file) {
-               try {
-                       return file.createRelative(".");
+                       String urlStr = res.getURL().toString();
+                       if (urlStr.charAt(urlStr.length() - 1) == '/')
+                               urlStr = urlStr.substring(0, urlStr.length() - 2);
+
+                       String parentUrlStr = urlStr.substring(0, urlStr.lastIndexOf('/'));
+                       return runtimeContext.getResource(parentUrlStr + '/');
                } catch (IOException e) {
-                       throw new SlcException("Cannot get parent for resource " + file, e);
+                       throw new SlcException("Cannot get parent for resource " + res, e);
                }
        }
+
+       // private Resource getParentOfFile(Resource file) {
+       // try {
+       // return file.createRelative(".");
+       // } catch (IOException e) {
+       // throw new SlcException("Cannot get parent for resource " + file, e);
+       // }
+       // }
 }
index 6184c5a7630a27b0b6dc1cca3099d92a5915ae48..821e0f679223039e46ef8b43f3e1be5ab6513ae6 100644 (file)
@@ -91,6 +91,7 @@ public class SlcMain {
                        printUsage();
                }
 
+               // Execution
                if (mode.equals(Mode.single)) {
                        DefaultSlcRuntime runtime = new DefaultSlcRuntime();
                        runtime.executeScript(new FileSystemResource(script), properties,