Improve packaging
authorMathieu Baudier <mbaudier@argeo.org>
Mon, 7 Jul 2008 11:25:59 +0000 (11:25 +0000)
committerMathieu Baudier <mbaudier@argeo.org>
Mon, 7 Jul 2008 11:25:59 +0000 (11:25 +0000)
git-svn-id: https://svn.argeo.org/slc/trunk@1379 4cfe0d0a-d680-48aa-b62c-e0a02a3f76cc

org.argeo.slc.agent/src/assembly/base.xml
org.argeo.slc.agent/src/base/bin/slc [changed mode: 0644->0755]
org.argeo.slc.agent/src/main/java/org/argeo/slc/ant/AntConstants.java
org.argeo.slc.agent/src/main/java/org/argeo/slc/ant/AntSlcApplication.java
org.argeo.slc.agent/src/main/java/org/argeo/slc/cli/SlcMain.java

index 6513362fcdea9ee3c61a95908a6166c4fac50a17..aef97a5cd963b64e84bd1ded5e9f88b882358946 100644 (file)
@@ -1,15 +1,16 @@
-<assembly xmlns="http://maven.apache.org/POM/4.0.0"\r
-       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"\r
-       xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/assembly-1.1.0-SNAPSHOT.xsd">\r
-       <id>base</id>\r
-       <includeBaseDirectory>false</includeBaseDirectory>\r
-       <formats>\r
-               <format>tar.gz</format>\r
-       </formats>\r
-       <fileSets>\r
-               <fileSet>\r
-                       <directory>src/base</directory>\r
-                       <outputDirectory></outputDirectory>\r
-               </fileSet>\r
-       </fileSets>\r
+<assembly xmlns="http://maven.apache.org/POM/4.0.0"
+       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+       xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/assembly-1.1.0-SNAPSHOT.xsd">
+       <id>base</id>
+       <includeBaseDirectory>false</includeBaseDirectory>
+       <formats>
+               <format>tar.gz</format>
+       </formats>
+       <fileSets>
+               <fileSet>
+                       <directory>src/base</directory>
+                       <outputDirectory></outputDirectory>
+                       <fileMode>0755</fileMode>
+               </fileSet>
+       </fileSets>
 </assembly>
\ No newline at end of file
old mode 100644 (file)
new mode 100755 (executable)
index fd1fd4f..ca8ef49
@@ -25,9 +25,11 @@ fi
 
 echo ARGEO_SLC_HOME=$ARGEO_SLC_HOME
 
-for i in "$ARGEO_SLC_HOME/lib/*.jar
+for i in "${ARGEO_SLC_HOME}"/lib/*.jar
        do
        CLASSPATH="$CLASSPATH:$i"
        done
 
-java -cp $CLASSPATH org.argeo.slc.cli.SlcMain $1 $2 $3 $4 $5 $6 $7 $8 $9
+#echo CLASSPATH=$CLASSPATH
+
+java -cp $CLASSPATH org.argeo.slc.cli.SlcMain "$@"
index 1e6cf142eb7cda1639707202111959baf2a7e9db..f89742d618706330482b08fd43211539e3ecb755 100644 (file)
@@ -38,6 +38,9 @@ public interface AntConstants {
        /** Name of the Spring bean used by default */
        public final static String DEFAULT_TEST_RUN_PROPERTY = "slc.defaultTestRun";
 
+       /** Property for the runtime to use. */
+       public final static String RUNTIME_PROPERTY = "slc.runtime";
+
        // LOG4J
        public final static String MDC_ANT_PROJECT = "slc.ant.project";
 
index 525c276af4004c3853331c4401be6bd9d069ffc0..51ff337e46d1c2d369a6b3546155c618be49f73f 100644 (file)
@@ -173,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());
index 10636f3d4191815a8a97d102dce1e10d8598828e..0267715c864246b6bcea319687aa6eecaba4312e 100644 (file)
@@ -1,5 +1,8 @@
 package org.argeo.slc.cli;
 
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
+import java.io.IOException;
 import java.util.Properties;
 
 import org.apache.commons.cli.CommandLine;
@@ -10,8 +13,10 @@ import org.apache.commons.cli.Option;
 import org.apache.commons.cli.OptionBuilder;
 import org.apache.commons.cli.Options;
 import org.apache.commons.cli.ParseException;
+import org.apache.commons.io.IOUtils;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
+import org.argeo.slc.ant.AntConstants;
 import org.argeo.slc.core.SlcException;
 import org.argeo.slc.logging.Log4jUtils;
 
@@ -25,7 +30,7 @@ public class SlcMain {
        private final static String BOOTSTRAP_LOG4J_CONFIG = "org/argeo/slc/cli/bootstrapLog4j.properties";
 
        private final static Option modeOpt = OptionBuilder.withLongOpt("mode")
-                       .withArgName("mode").hasArg().isRequired().withDescription(
+                       .withArgName("mode").hasArg().withDescription(
                                        "SLC execution mode, one of: " + listModeValues()).create(
                                        'm');
 
@@ -34,6 +39,11 @@ public class SlcMain {
                        .withValueSeparator(',').withDescription(
                                        "use value for given property").create('p');
 
+       private final static Option propertiesOpt = OptionBuilder.withLongOpt(
+                       "properties").withArgName("properties file").hasArgs()
+                       .withValueSeparator(',').withDescription(
+                                       "load properties from file (-p has priority)").create('P');
+
        private final static Option scriptOpt = OptionBuilder.withLongOpt("script")
                        .withArgName("script").hasArg().withDescription(
                                        "SLC script to execute").create('s');
@@ -57,6 +67,7 @@ public class SlcMain {
                options.addOption(scriptOpt);
                options.addOption(targetsOpt);
                options.addOption(propertyOpt);
+               options.addOption(propertiesOpt);
                options.addOption(runtimeOpt);
        }
 
@@ -74,10 +85,15 @@ public class SlcMain {
 
                        // Mode
                        String modeStr = cl.getOptionValue(modeOpt.getOpt());
-                       try {
-                               mode = Mode.valueOf(modeStr);
-                       } catch (IllegalArgumentException e) {
-                               throw new SlcException("Unrecognized mode '" + modeStr + "'", e);
+                       if (modeStr == null) {
+                               mode = Mode.single;
+                       } else {
+                               try {
+                                       mode = Mode.valueOf(modeStr);
+                               } catch (IllegalArgumentException e) {
+                                       throw new SlcException("Unrecognized mode '" + modeStr
+                                                       + "'", e);
+                               }
                        }
 
                        // Script
@@ -94,6 +110,12 @@ public class SlcMain {
                        }
 
                        // Properties
+                       if (cl.hasOption(propertiesOpt.getOpt())) {
+                               for (String propertyFile : cl.getOptionValues(propertiesOpt
+                                               .getOpt())) {
+                                       loadPropertyFile(properties, propertyFile);
+                               }
+                       }
                        if (cl.hasOption(propertyOpt.getOpt())) {
                                for (String property : cl.getOptionValues(propertyOpt.getOpt())) {
                                        addProperty(properties, property);
@@ -103,10 +125,7 @@ public class SlcMain {
                        // Runtime
                        if (cl.hasOption(runtimeOpt.getOpt())) {
                                runtimeStr = cl.getOptionValue(runtimeOpt.getOpt());
-                       } else {
-                               runtimeStr = "default";
                        }
-
                } catch (ParseException e) {
                        System.err.println("Problem with command line arguments. "
                                        + e.getMessage());
@@ -124,7 +143,8 @@ public class SlcMain {
                initLogging(properties);
                if (log.isDebugEnabled()) {
                        log.debug("Mode: " + mode);
-                       log.debug("Runtime: " + runtimeStr);
+                       if (runtimeStr != null)
+                               log.debug("Runtime: " + runtimeStr);
                        log.debug("User properties: " + properties);
                        if (script != null)
                                log.debug("Script: " + script);
@@ -154,7 +174,7 @@ public class SlcMain {
                return str.substring(0, str.length() - 2);
        }
 
-       private static void addProperty(Properties properties, String property) {
+       protected static void addProperty(Properties properties, String property) {
                int eqIndex = property.indexOf('=');
                if (eqIndex == 0)
                        throw new SlcException("Badly formatted property " + property);
@@ -167,7 +187,20 @@ public class SlcMain {
                } else {
                        properties.setProperty(property, "true");
                }
+       }
 
+       protected static void loadPropertyFile(Properties properties,
+                       String propertyFile) {
+               FileInputStream in = null;
+               try {
+                       in = new FileInputStream(propertyFile);
+                       properties.load(in);
+               } catch (Exception e) {
+                       throw new SlcException("Could not load proeprty file "
+                                       + propertyFile);
+               } finally {
+                       IOUtils.closeQuietly(in);
+               }
        }
 
        private static void initLogging(Properties userProperties) {