incubator-sling-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bdelacre...@apache.org
Subject svn commit: r1078781 - in /sling/trunk/testing: samples/integration-tests/pom.xml tools/src/main/java/org/apache/sling/testing/tools/jarexec/JarExecutor.java
Date Mon, 07 Mar 2011 14:31:35 GMT
Author: bdelacretaz
Date: Mon Mar  7 14:31:35 2011
New Revision: 1078781

URL: http://svn.apache.org/viewvc?rev=1078781&view=rev
Log:
SLING-2002 - new JarExecutor options: work dir and options for the jar under test

Modified:
    sling/trunk/testing/samples/integration-tests/pom.xml
    sling/trunk/testing/tools/src/main/java/org/apache/sling/testing/tools/jarexec/JarExecutor.java

Modified: sling/trunk/testing/samples/integration-tests/pom.xml
URL: http://svn.apache.org/viewvc/sling/trunk/testing/samples/integration-tests/pom.xml?rev=1078781&r1=1078780&r2=1078781&view=diff
==============================================================================
--- sling/trunk/testing/samples/integration-tests/pom.xml (original)
+++ sling/trunk/testing/samples/integration-tests/pom.xml Mon Mar  7 14:31:35 2011
@@ -67,6 +67,13 @@
         
         <!-- Change this to use longer or shorter timeouts for testing -->
         <sling.testing.timeout.multiplier>1.0</sling.testing.timeout.multiplier>
+        
+        <!-- Set this to run the executable jar in a specified filesystem folder -->
+        <jar.executor.work.folder></jar.executor.work.folder>
+        
+        <!-- Options for the jar to execute. $JAREXEC_SERVER_PORT$ is replaced by the
+            selected port number -->
+        <jar.executor.jar.options>-p $JAREXEC_SERVER_PORT$</jar.executor.jar.options>
     </properties>
     
     <scm>
@@ -159,6 +166,8 @@
                         <jar.executor.vm.options>${jar.executor.vm.options}</jar.executor.vm.options>
                         <jar.executor.jar.folder>${project.basedir}/target/dependency</jar.executor.jar.folder>
                         <jar.executor.jar.name.regexp>org.apache.sling.launchpad.*jar$</jar.executor.jar.name.regexp>
+                        <jar.executor.work.folder>${jar.executor.work.folder}</jar.executor.work.folder>
+                        <jar.executor.jar.options>${jar.executor.jar.options}</jar.executor.jar.options>
                         <additional.bundles.path>${project.basedir}/target/sling/additional-bundles</additional.bundles.path>
                         <keepJarRunning>${keepJarRunning}</keepJarRunning>
                         <server.ready.timeout.seconds>60</server.ready.timeout.seconds>

Modified: sling/trunk/testing/tools/src/main/java/org/apache/sling/testing/tools/jarexec/JarExecutor.java
URL: http://svn.apache.org/viewvc/sling/trunk/testing/tools/src/main/java/org/apache/sling/testing/tools/jarexec/JarExecutor.java?rev=1078781&r1=1078780&r2=1078781&view=diff
==============================================================================
--- sling/trunk/testing/tools/src/main/java/org/apache/sling/testing/tools/jarexec/JarExecutor.java
(original)
+++ sling/trunk/testing/tools/src/main/java/org/apache/sling/testing/tools/jarexec/JarExecutor.java
Mon Mar  7 14:31:35 2011
@@ -17,6 +17,7 @@
 package org.apache.sling.testing.tools.jarexec;
 
 import java.io.File;
+import java.io.IOException;
 import java.util.Arrays;
 import java.util.Properties;
 import java.util.regex.Pattern;
@@ -28,7 +29,6 @@ import org.apache.commons.exec.ExecuteRe
 import org.apache.commons.exec.Executor;
 import org.apache.commons.exec.PumpStreamHandler;
 import org.apache.commons.exec.ShutdownHookProcessDestroyer;
-import org.apache.commons.exec.util.StringUtils;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -39,6 +39,7 @@ public class JarExecutor {
     private final File jarToExecute;
     private final String javaExecutable;
     private final int serverPort;
+    private final Properties config;
     
     private final Logger log = LoggerFactory.getLogger(getClass());
 
@@ -49,6 +50,9 @@ public class JarExecutor {
     public static final String PROP_SERVER_PORT = PROP_PREFIX + "server.port";
     public static final String PROP_JAR_FOLDER = PROP_PREFIX + "jar.folder";
     public static final String PROP_JAR_NAME_REGEXP = PROP_PREFIX + "jar.name.regexp";
+    public static final String PROP_VM_OPTIONS = PROP_PREFIX + "vm.options";
+    public static final String PROP_WORK_FOLDER = PROP_PREFIX + "work.folder";
+    public static final String PROP_JAR_OPTIONS = PROP_PREFIX + "jar.options";
     
     @SuppressWarnings("serial")
     public static class ExecutorException extends Exception {
@@ -66,6 +70,7 @@ public class JarExecutor {
 
     /** Build a JarExecutor, locate the jar to run, etc */
     public JarExecutor(Properties config) throws ExecutorException {
+        this.config = config;
         final boolean isWindows = System.getProperty("os.name").toLowerCase().contains("windows");
 
         String portStr = config.getProperty(PROP_SERVER_PORT);
@@ -119,21 +124,36 @@ public class JarExecutor {
                 log.info("Process execution complete, exit code=" + result);
             }
         };
-
-        final String vmOptions = System.getProperty("jar.executor.vm.options");
+        
+        final String vmOptions = config.getProperty(PROP_VM_OPTIONS);
         final Executor e = new DefaultExecutor();
         final CommandLine cl = new CommandLine(javaExecutable);
         if (vmOptions != null && vmOptions.length() > 0) {
-            // TODO: this will fail if one of the vm options as a quoted value with a space
in it, but this is
-            // not the case for common usage patterns
-            for (String option : StringUtils.split(vmOptions, " ")) {
-                cl.addArgument(option);
-            }
+            cl.addArguments(vmOptions);
         }
         cl.addArgument("-jar");
         cl.addArgument(jarToExecute.getAbsolutePath());
-        cl.addArgument("-p");
-        cl.addArgument(String.valueOf(serverPort));
+        
+        // Additional options for the jar that's executed.
+        // $JAREXEC_SERVER_PORT$ is replaced our serverPort value
+        String jarOptions = config.getProperty(PROP_JAR_OPTIONS);
+        if(jarOptions != null && jarOptions.length() > 0) {
+            jarOptions = jarOptions.replaceAll("\\$JAREXEC_SERVER_PORT\\$", String.valueOf(serverPort));
+            log.info("Executable jar options: {}", jarOptions);
+            cl.addArguments(jarOptions);
+        }
+        
+        final String workFolderOption = config.getProperty(PROP_WORK_FOLDER);
+        if(workFolderOption != null && workFolderOption.length() > 0) {
+            final File workFolder = new File(workFolderOption);
+            if(!workFolder.isDirectory()) {
+                throw new IOException("Work dir set by " + PROP_WORK_FOLDER + " option does
not exist: " 
+                        + workFolder.getAbsolutePath());
+            }
+            log.info("Setting working directory for executable jar: {}", workFolder.getAbsolutePath());
+            e.setWorkingDirectory(workFolder);
+        }
+
         log.info("Executing " + cl);
         e.setStreamHandler(new PumpStreamHandler());
         e.setProcessDestroyer(new ShutdownHookProcessDestroyer());



Mime
View raw message