commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mt...@apache.org
Subject svn commit: r1181201 - in /commons/sandbox/runtime/trunk: ./ src/main/java/org/apache/commons/runtime/ src/main/java/org/apache/commons/runtime/net/ src/main/java/org/apache/commons/runtime/platform/unix/ src/main/java/org/apache/commons/runtime/platfo...
Date Mon, 10 Oct 2011 20:14:17 GMT
Author: mturk
Date: Mon Oct 10 20:14:16 2011
New Revision: 1181201

URL: http://svn.apache.org/viewvc?rev=1181201&view=rev
Log:
Add exec with usepath option. Remove File.getPath() usage

Modified:
    commons/sandbox/runtime/trunk/build.xml
    commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/Exec.java
    commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/net/LocalEndpointAddress.java
    commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/net/Sendfile.java
    commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/platform/unix/PosixExec.java
    commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/platform/windows/Service.java
    commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/platform/windows/ServiceControlManager.java
    commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/platform/windows/WindowsExec.java
    commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/ssl/SSLContext.java
    commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/ssl/SSLRandom.java
    commons/sandbox/runtime/trunk/src/main/native/os/unix/exec.c
    commons/sandbox/runtime/trunk/src/main/test/org/apache/commons/runtime/TestExec.java
    commons/sandbox/runtime/trunk/src/main/test/org/apache/commons/runtime/TestServerEndpoint.java

Modified: commons/sandbox/runtime/trunk/build.xml
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/build.xml?rev=1181201&r1=1181200&r2=1181201&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/build.xml (original)
+++ commons/sandbox/runtime/trunk/build.xml Mon Oct 10 20:14:16 2011
@@ -4,6 +4,7 @@
     <!-- Give user a chance to override without editing this file
         (and without typing -D each time it compiles it
     -->
+    <property environment="env"/>
     <property file="${user.home}/.ant.properties" />
     <property file="${user.home}/build.properties" />
     <property file="build.properties" />
@@ -450,8 +451,7 @@ The Apache Software Foundation (http://w
                 <classfileset dir="${build.dest}/test">
                     <include name="**/*.class"/>
                 </classfileset>
-                <env key="PATH" path="${runtime.library.path}${path.separator}${java.library.path}"/>
-                <env key="Path" path="${runtime.library.path}${path.separator}${java.library.path}"/>
+                <env key="PATH" path="${runtime.library.path}:${java.library.path}:${env.PATH}"/>
                 <jvmarg value="-Djava.library.path=${runtime.library.path}"/>
                 <jvmarg value="-Xmx512m"/>
                 <jvmarg line="${args}"/>
@@ -534,8 +534,7 @@ The Apache Software Foundation (http://w
               fork="yes"
               failonerror="${test.failonerror}">
             <classpath refid="examples.classpath"/>
-            <env key="PATH" path="${runtime.library.path}${path.separator}${java.library.path}"/>
-            <env key="Path" path="${runtime.library.path}${path.separator}${java.library.path}"/>
+            <env key="PATH" path="${runtime.library.path}:${java.library.path}:${env.PATH}"/>
             <jvmarg value="-Djava.library.path=${runtime.library.path}"/>
             <jvmarg value="-Xmx512m"/>
             <jvmarg line="${args}"/>

Modified: commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/Exec.java
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/Exec.java?rev=1181201&r1=1181200&r2=1181201&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/Exec.java (original)
+++ commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/Exec.java Mon Oct
10 20:14:16 2011
@@ -15,7 +15,6 @@
  */
 package org.apache.commons.runtime;
 
-import java.io.File;
 import java.util.List;
 
 /**
@@ -74,11 +73,27 @@ public abstract class Exec
     public abstract int exec(List<String> argv, int timeout);
     public abstract int exec(List<String> argv);
 
-    public abstract int execShellScript(File script, List<String> args, int timeout);
-    public abstract int execShellScript(File script, List<String> args);
+    public abstract int execShellScript(String script, List<String> args, int timeout);
 
-    public abstract int execCommand(String cmd, int timeout);
-    public abstract int execCommand(String cmd);
+    public final int execShellScript(String script, List<String> args)
+    {
+        return execShellScript(script, args, -1);
+    }
+
+    /**
+     * Execute shell command with timeout.
+     *
+     */
+    public abstract int execCommand(String cmd, int timeout, boolean usepath);
+
+    /**
+     * Execute shell command.
+     *
+     */
+    public final int execCommand(String cmd)
+    {
+        return execCommand(cmd, -1, true);
+    }
 
     /**
      * Return the process exit value.
@@ -106,9 +121,9 @@ public abstract class Exec
         inp = buf;
     }
 
-    public void setWorkingDirectory(File directory)
+    public void setWorkingDirectory(String path)
     {
-        cwd = directory.getPath();
+        cwd = path;
     }
 
     public void setEnvironment(List<String> envp)

Modified: commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/net/LocalEndpointAddress.java
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/net/LocalEndpointAddress.java?rev=1181201&r1=1181200&r2=1181201&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/net/LocalEndpointAddress.java
(original)
+++ commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/net/LocalEndpointAddress.java
Mon Oct 10 20:14:16 2011
@@ -55,17 +55,4 @@ public final class LocalEndpointAddress 
         super.sa = sockaddr0(name);
     }
 
-    /**
-     * Create a new local socket adrress.
-     */
-    public LocalEndpointAddress(File path)
-        throws NetworkException, InvalidArgumentException
-    {
-        super(AddressFamily.LOCAL);
-        String name = path.getPath();
-        if (name == null || name.length() == 0)
-            throw new InvalidArgumentException();
-        super.sa = sockaddr0(name);
-    }
-
 }

Modified: commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/net/Sendfile.java
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/net/Sendfile.java?rev=1181201&r1=1181200&r2=1181201&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/net/Sendfile.java
(original)
+++ commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/net/Sendfile.java
Mon Oct 10 20:14:16 2011
@@ -22,7 +22,6 @@ import java.io.Closeable;
 import java.io.Flushable;
 import java.io.IOException;
 import java.io.SyncFailedException;
-import java.io.File;
 import java.net.SocketException;
 import org.apache.commons.runtime.io.ClosedDescriptorException;
 import org.apache.commons.runtime.io.Descriptor;
@@ -73,23 +72,6 @@ public class Sendfile implements Closeab
     }
 
     /**
-     * Creates a new Sendfile object.
-     *
-     * @throws AccessDeniedException if the access to the file is not allowed.
-     * @throws NoSuchObjectException if the file doesn't exsist.
-     * @throws IOException if an I/O error occurs.
-     */
-    public Sendfile(File path)
-        throws AccessDeniedException,
-               NoSuchObjectException,
-               UnsupportedOperationException,
-               IOException
-    {
-        sf = open0(path.getPath());
-        closed = false;
-    }
-
-    /**
      * Free the allocated resource by the Operating system.
      * <p>
      * Note that {@code Object.finalize()} method will call

Modified: commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/platform/unix/PosixExec.java
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/platform/unix/PosixExec.java?rev=1181201&r1=1181200&r2=1181201&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/platform/unix/PosixExec.java
(original)
+++ commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/platform/unix/PosixExec.java
Mon Oct 10 20:14:16 2011
@@ -21,7 +21,6 @@ import org.apache.commons.runtime.Errno;
 import org.apache.commons.runtime.Status;
 import org.apache.commons.runtime.InvalidArgumentException;
 import org.apache.commons.runtime.SystemException;
-import java.io.File;
 import java.util.List;
 import java.util.Vector;
 
@@ -49,13 +48,14 @@ final class PosixExec extends Exec
                                      byte[] inp,
                                      byte[][] out,
                                      int redir,
-                                     int timeout);
+                                     int timeout,
+                                     boolean usepath);
     @Override
     public int exec(List<String> argv, int timeout)
     {
         byte[][] isa = new byte[2][0];
         String[] args = argv.toArray(new String[0]);
-        long rv = exec0(args[0], args, env, cwd, inp, isa, redirect, timeout);
+        long rv = exec0(args[0], args, env, cwd, inp, isa, redirect, timeout, false);
         exitval = (int)(rv & 0xffffffffL);
         int res = (int)(rv >>> 32);
         out     = isa[0];
@@ -70,37 +70,30 @@ final class PosixExec extends Exec
     }
 
     @Override
-    public int execShellScript(File script, List<String> args, int timeout)
+    public int execShellScript(String script, List<String> args, int timeout)
     {
         Vector<String> argv = new Vector<String>();
         argv.add(impl.getShell());
-        argv.add(script.getPath());
+        argv.add(script);
         argv.addAll(args);
 
         return exec(argv, timeout);
     }
 
     @Override
-    public int execShellScript(File script, List<String> args)
+    public int execCommand(String cmd, int timeout, boolean usepath)
     {
-        return execShellScript(script, args, -1);
-    }
-
-    @Override
-    public int execCommand(String cmd, int timeout)
-    {
-        Vector<String> argv = new Vector<String>();
-        argv.add(impl.getShell());
-        argv.add("-c");
-        argv.add(cmd);
-
-        return exec(argv, timeout);
-    }
-
-    @Override
-    public int execCommand(String cmd)
-    {
-        return execCommand(cmd, -1);
+        byte[][] isa  = new byte[2][0];
+        String[] args = new String[3];
+        args[0] = impl.getShell();
+        args[1] = "-c";
+        args[2] = cmd;
+        long rv = exec0(args[0], args, env, cwd, inp, isa, redirect, timeout, usepath);
+        exitval = (int)(rv & 0xffffffffL);
+        int res = (int)(rv >>> 32);
+        out     = isa[0];
+        err     = isa[1];
+        return res;        
     }
 
 }

Modified: commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/platform/windows/Service.java
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/platform/windows/Service.java?rev=1181201&r1=1181200&r2=1181201&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/platform/windows/Service.java
(original)
+++ commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/platform/windows/Service.java
Mon Oct 10 20:14:16 2011
@@ -17,7 +17,6 @@
 package org.apache.commons.runtime.platform.windows;
 
 import java.io.Closeable;
-import java.io.File;
 import java.io.IOException;
 import java.util.EnumSet;
 import java.util.List;
@@ -639,12 +638,6 @@ public final class Service implements Cl
         }
     }
 
-    public void setBinaryPathName(File path)
-        throws InvalidHandleException, SystemException
-    {
-        setBinaryPathName(path.getPath());
-    }
-
     public void setLoadOrderGroup(String group)
         throws InvalidHandleException, SystemException
     {

Modified: commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/platform/windows/ServiceControlManager.java
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/platform/windows/ServiceControlManager.java?rev=1181201&r1=1181200&r2=1181201&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/platform/windows/ServiceControlManager.java
(original)
+++ commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/platform/windows/ServiceControlManager.java
Mon Oct 10 20:14:16 2011
@@ -17,7 +17,6 @@
 package org.apache.commons.runtime.platform.windows;
 
 import java.io.Closeable;
-import java.io.File;
 import java.io.IOException;
 import java.util.EnumSet;
 import java.util.ArrayList;
@@ -174,7 +173,7 @@ public class ServiceControlManager imple
     public Service create(String name, String displayName,
                           ServiceType serviceType, ServiceStartType startType,
                           ServiceErrorControl errorControl,
-                          File binaryPath, String loadOrderGroup,
+                          String binaryPath, String loadOrderGroup,
                           String[] dependencies,
                           String username,
                           String password)
@@ -184,13 +183,12 @@ public class ServiceControlManager imple
         if (handle == 0L)
             throw new InvalidHandleException();
         // binaryPath is optional
-        String path = binaryPath == null ? null : binaryPath.getPath();
         long svc = Win32.CreateService(handle, name, displayName,
                                        Service.SERVICE_ALL_ACCESS,
                                        serviceType.valueOf(),
                                        startType.valueOf(),
                                        errorControl.valueOf(),
-                                       path, loadOrderGroup,
+                                       binaryPath, loadOrderGroup,
                                        Utils.stringArrayToCharBlock(dependencies),
                                        username, password);
         if (svc == 0L)

Modified: commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/platform/windows/WindowsExec.java
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/platform/windows/WindowsExec.java?rev=1181201&r1=1181200&r2=1181201&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/platform/windows/WindowsExec.java
(original)
+++ commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/platform/windows/WindowsExec.java
Mon Oct 10 20:14:16 2011
@@ -22,10 +22,6 @@ import org.apache.commons.runtime.Status
 import org.apache.commons.runtime.InvalidArgumentException;
 import org.apache.commons.runtime.SystemException;
 import org.apache.commons.runtime.util.Utils;
-import java.io.ByteArrayInputStream;
-import java.io.CharArrayWriter;
-import java.io.InputStream;
-import java.io.File;
 import java.util.List;
 import java.util.Vector;
 
@@ -104,27 +100,21 @@ final class WindowsExec extends Exec
     }
 
     @Override
-    public int execShellScript(File script, List<String> args, int timeout)
+    public int execShellScript(String script, List<String> args, int timeout)
     {
         Vector<String> argv = new Vector<String>();
         argv.add(impl.getComspec());
         argv.add("/D");
         argv.add("/C");
         argv.add("CALL");
-        argv.add(script.getPath());
+        argv.add(script);
         argv.addAll(args);
 
         return exec(argv, timeout);
     }
 
     @Override
-    public int execShellScript(File script, List<String> args)
-    {
-        return execShellScript(script, args, -1);
-    }
-
-    @Override
-    public int execCommand(String cmd, int timeout)
+    public int execCommand(String cmd, int timeout, boolean usepath)
     {
         Vector<String> argv = new Vector<String>();
         argv.add(impl.getComspec());
@@ -135,9 +125,4 @@ final class WindowsExec extends Exec
         return exec(argv, timeout);
     }
 
-    @Override
-    public int execCommand(String cmd)
-    {
-        return execCommand(cmd, -1);
-    }
 }

Modified: commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/ssl/SSLContext.java
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/ssl/SSLContext.java?rev=1181201&r1=1181200&r2=1181201&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/ssl/SSLContext.java
(original)
+++ commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/ssl/SSLContext.java
Mon Oct 10 20:14:16 2011
@@ -24,8 +24,6 @@ import org.apache.commons.runtime.Operat
 import org.apache.commons.runtime.Status;
 import org.apache.commons.runtime.SystemException;
 
-import java.io.File;
-
 /**
  * Contains the context structure for global default values for
  * multiple SSL connections and certificate verification information.

Modified: commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/ssl/SSLRandom.java
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/ssl/SSLRandom.java?rev=1181201&r1=1181200&r2=1181201&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/ssl/SSLRandom.java
(original)
+++ commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/ssl/SSLRandom.java
Mon Oct 10 20:14:16 2011
@@ -20,7 +20,6 @@ import org.apache.commons.runtime.Invali
 import org.apache.commons.runtime.Status;
 import org.apache.commons.runtime.SystemException;
 
-import java.io.File;
 import java.nio.ByteBuffer;
 
 /**
@@ -90,17 +89,16 @@ public final class SSLRandom
         return seed2(b, 0, b.length);
     }
 
-    public static void setSeedFile(File path)
+    public static void setSeedPath(String path)
         throws SystemException
     {
-        setdef0(path.getPath());
+        setdef0(path);
     }
 
-    public static File getSeedFile()
+    public static String getSeedPath()
         throws SystemException
     {
-        String path = getdef0();
-        return new File(path);
+        return getdef0();
     }
 
     public void nextBytes(byte[] bytes, int off, int len)

Modified: commons/sandbox/runtime/trunk/src/main/native/os/unix/exec.c
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/os/unix/exec.c?rev=1181201&r1=1181200&r2=1181201&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/os/unix/exec.c (original)
+++ commons/sandbox/runtime/trunk/src/main/native/os/unix/exec.c Mon Oct 10 20:14:16 2011
@@ -88,6 +88,7 @@ static int _run_exec(const char *executa
                      acr_buf_t *err,
                      acr_buf_t *inp,
                      int timeout,
+                     int usepath,
                      int *retval)
 {
     int   i, rc   = 0;
@@ -284,10 +285,20 @@ static int _run_exec(const char *executa
                 exit(0);
             }
         }
-        if (envp != 0)
-            execve(executable, argv, envp);
-        else
-            execv(executable,  argv);
+        if (usepath) {
+            /* XXX: Does this works on all platforms?
+             *      Do we need to duplicate it?
+             */
+            if (envp != 0)
+                environ = (char **)envp;
+            execvp(executable, argv);
+        }
+        else {
+            if (envp != 0)
+                execve(executable, argv, envp);
+            else
+                execv(executable,  argv);
+        }
         rc = ACR_GET_OS_ERROR();
 
 child_cleanup:
@@ -592,7 +603,7 @@ ACR_UNX_EXPORT(jlong, PosixExec, exec0)(
                                         jobjectArray args, jobjectArray envp,
                                         jstring cwd, jbyteArray inp,
                                         jobjectArray out, jint redir,
-                                        jint timeout)
+                                        jint timeout, jboolean usepath)
 {
     int rv = 0;
     int rc = 0;
@@ -636,7 +647,7 @@ ACR_UNX_EXPORT(jlong, PosixExec, exec0)(
         /* Call actual execute
          */
         rv = _run_exec(J2S(executable), argp, envs, J2S(cwd),
-                       ob, eb, ib, timeout, &rc);
+                       ob, eb, ib, timeout, usepath, &rc);
         if (inpcopy != 0) {
             (*env)->ReleasePrimitiveArrayCritical(env, inpcopy, ib->buf, 0);
             (*env)->DeleteLocalRef(env, inpcopy);

Modified: commons/sandbox/runtime/trunk/src/main/test/org/apache/commons/runtime/TestExec.java
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/test/org/apache/commons/runtime/TestExec.java?rev=1181201&r1=1181200&r2=1181201&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/test/org/apache/commons/runtime/TestExec.java (original)
+++ commons/sandbox/runtime/trunk/src/main/test/org/apache/commons/runtime/TestExec.java Mon
Oct 10 20:14:16 2011
@@ -64,6 +64,22 @@ public class TestExec extends Assert
         assertEquals(rs, "hello world");
     }
 
+    @Test(groups = { "posix" })
+    public void execShell()
+        throws Exception
+    {
+        Exec e = Exec.newInstance();
+        assertNotNull(e);
+        e.redirectStdout(true);
+        //e.redirectStderr(true);
+        int r = e.execCommand("echo \"foo bar\" | head -1");
+        assertEquals(r, Status.CHILD_DONE);
+        byte[] stdout = e.getStdout();
+        assertNotNull(stdout);
+        String rs = new String(stdout);
+        System.out.println("Out is " + rs);
+    }
+
     @Test(groups = { "windows" })
     public void execWindows()
         throws Exception

Modified: commons/sandbox/runtime/trunk/src/main/test/org/apache/commons/runtime/TestServerEndpoint.java
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/test/org/apache/commons/runtime/TestServerEndpoint.java?rev=1181201&r1=1181200&r2=1181201&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/test/org/apache/commons/runtime/TestServerEndpoint.java
(original)
+++ commons/sandbox/runtime/trunk/src/main/test/org/apache/commons/runtime/TestServerEndpoint.java
Mon Oct 10 20:14:16 2011
@@ -144,7 +144,7 @@ public class TestServerEndpoint extends 
             fs.write(b);
         fs.close();
         try {
-            Sendfile sf = new Sendfile(sendf);
+            Sendfile sf = new Sendfile(sendf.getPath());
             cs.setTimeout(200);
             assertFalse(cs.isBlocking());
             int send = sf.send(cs);



Mime
View raw message