commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mt...@apache.org
Subject svn commit: r1102572 - in /commons/sandbox/runtime/trunk/src/main: java/org/apache/commons/runtime/ java/org/apache/commons/runtime/platform/unix/ java/org/apache/commons/runtime/platform/windows/ native/os/unix/ native/os/win32/ test/org/apache/common...
Date Fri, 13 May 2011 06:17:30 GMT
Author: mturk
Date: Fri May 13 06:17:29 2011
New Revision: 1102572

URL: http://svn.apache.org/viewvc?rev=1102572&view=rev
Log:
Make exec implementation private and rename public api from run tu exec

Modified:
    commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/Exec.java
    commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/ExecImpl.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/unix/PosixExecImpl.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/platform/windows/WindowsExecImpl.java
    commons/sandbox/runtime/trunk/src/main/native/os/unix/exec.c
    commons/sandbox/runtime/trunk/src/main/native/os/win32/exec.c
    commons/sandbox/runtime/trunk/src/main/test/org/apache/commons/runtime/TestExec.java

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=1102572&r1=1102571&r2=1102572&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 Fri May
13 06:17:29 2011
@@ -71,14 +71,14 @@ public abstract class Exec
         return impl.newInstance();
     }
 
-    public abstract int run(List<String> argv, int timeout);
-    public abstract int run(List<String> argv);
+    public abstract int exec(List<String> argv, int timeout);
+    public abstract int exec(List<String> argv);
 
-    public abstract int runShellScript(File script, List<String> args, int timeout);
-    public abstract int runShellScript(File script, List<String> args);
+    public abstract int execShellScript(File script, List<String> args, int timeout);
+    public abstract int execShellScript(File script, List<String> args);
 
-    public abstract int runCommand(String cmd, int timeout);
-    public abstract int runCommand(String cmd);
+    public abstract int execCommand(String cmd, int timeout);
+    public abstract int execCommand(String cmd);
 
     /**
      * Return the process exit value.

Modified: commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/ExecImpl.java
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/ExecImpl.java?rev=1102572&r1=1102571&r2=1102572&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/ExecImpl.java (original)
+++ commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/ExecImpl.java Fri
May 13 06:17:29 2011
@@ -32,7 +32,6 @@ public abstract class ExecImpl
         impl = init0();
     }
 
-    protected String shell;
     protected ExecImpl()
     {
         // No Instance
@@ -48,9 +47,5 @@ public abstract class ExecImpl
 
     public abstract Exec newInstance();
 
-    public final String getShell()
-    {
-        return shell;
-    }
 }
 

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=1102572&r1=1102571&r2=1102572&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
Fri May 13 06:17:29 2011
@@ -35,25 +35,27 @@ import java.util.Vector;
 final class PosixExec extends Exec
 {
 
-    public PosixExec()
-    {
-
-    }
-
-    private static native long run0(String executable,
-                                    String[] args,
-                                    String[] envp,
-                                    String cwd,
-                                    byte[] inp,
-                                    byte[][] out,
-                                    int redir,
-                                    int timeout);
+    private PosixExecImpl impl;
+    
+    public PosixExec(PosixExecImpl impl)
+    {
+        this.impl = impl;
+    }
+
+    private static native long exec0(String executable,
+                                     String[] args,
+                                     String[] envp,
+                                     String cwd,
+                                     byte[] inp,
+                                     byte[][] out,
+                                     int redir,
+                                     int timeout);
     @Override
-    public int run(List<String> argv, int timeout)
+    public int exec(List<String> argv, int timeout)
     {
         byte[][] isa = new byte[2][0];
         String[] args = argv.toArray(new String[0]);
-        long rv = run0(args[0], args, env, cwd, inp, isa, redirect, timeout);
+        long rv = exec0(args[0], args, env, cwd, inp, isa, redirect, timeout);
         exitval = (int)(rv & 0xffffffffL);
         int res = (int)(rv >>> 32);
         out     = isa[0];
@@ -62,43 +64,43 @@ final class PosixExec extends Exec
     }
 
     @Override
-    public int run(List<String> argv)
+    public int exec(List<String> argv)
     {
-        return run(argv, -1);
+        return exec(argv, -1);
     }
 
     @Override
-    public int runShellScript(File script, List<String> args, int timeout)
+    public int execShellScript(File script, List<String> args, int timeout)
     {
         Vector<String> argv = new Vector<String>();
-        argv.add(ExecImpl.getInstance().getShell());
+        argv.add(impl.getShell());
         argv.add(script.getPath());
         argv.addAll(args);
 
-        return run(argv, timeout);
+        return exec(argv, timeout);
     }
 
     @Override
-    public int runShellScript(File script, List<String> args)
+    public int execShellScript(File script, List<String> args)
     {
-        return runShellScript(script, args, -1);
+        return execShellScript(script, args, -1);
     }
 
     @Override
-    public int runCommand(String cmd, int timeout)
+    public int execCommand(String cmd, int timeout)
     {
         Vector<String> argv = new Vector<String>();
-        argv.add(ExecImpl.getInstance().getShell());
+        argv.add(impl.getShell());
         argv.add("-c");
         argv.add(cmd);
 
-        return run(argv, timeout);
+        return exec(argv, timeout);
     }
 
     @Override
-    public int runCommand(String cmd)
+    public int execCommand(String cmd)
     {
-        return runCommand(cmd, -1);
+        return execCommand(cmd, -1);
     }
 
 }

Modified: commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/platform/unix/PosixExecImpl.java
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/platform/unix/PosixExecImpl.java?rev=1102572&r1=1102571&r2=1102572&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/platform/unix/PosixExecImpl.java
(original)
+++ commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/platform/unix/PosixExecImpl.java
Fri May 13 06:17:29 2011
@@ -28,6 +28,7 @@ import org.apache.commons.runtime.ExecIm
 final class PosixExecImpl extends ExecImpl
 {
 
+    private String shell;
     private PosixExecImpl()
     {
         // No Instance
@@ -41,7 +42,11 @@ final class PosixExecImpl extends ExecIm
     @Override
     public Exec newInstance()
     {
-        return new PosixExec();
+        return new PosixExec(this);
     }
 
+    public final String getShell()
+    {
+        return shell;
+    }
 }

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=1102572&r1=1102571&r2=1102572&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
Fri May 13 06:17:29 2011
@@ -39,21 +39,22 @@ import java.util.Vector;
 final class WindowsExec extends Exec
 {
 
-    public WindowsExec()
+    private WindowsExecImpl impl;
+    public WindowsExec(WindowsExecImpl impl)
     {
-
+        this.impl = impl;
     }
-    private static native long run0(String executable,
-                                    String cmdline,
-                                    char[] envb,
-                                    String cwd,
-                                    byte[] inp,
-                                    byte[][] out,
-                                    int redir,
-                                    int timeout);
+    private static native long exec0(String executable,
+                                     String cmdline,
+                                     char[] envb,
+                                     String cwd,
+                                     byte[] inp,
+                                     byte[][] out,
+                                     int redir,
+                                     int timeout);
 
     @Override
-    public int run(List<String> argv, int timeout)
+    public int exec(List<String> argv, int timeout)
     {
         String executable = null;
         StringBuffer args = new StringBuffer();
@@ -87,7 +88,7 @@ final class WindowsExec extends Exec
         }
         byte[][] isa = new byte[2][0];
         char[] eb = Utils.stringArrayToCharBlock(env);
-        long rv = run0(executable, args.toString(), eb, cwd, inp, isa, redirect, timeout);
+        long rv = exec0(executable, args.toString(), eb, cwd, inp, isa, redirect, timeout);
         exitval = (int)(rv & 0xffffffffL);
         int res = (int)(rv >>> 32);
         out     = isa[0];
@@ -97,46 +98,46 @@ final class WindowsExec extends Exec
     }
 
     @Override
-    public int run(List<String> argv)
+    public int exec(List<String> argv)
     {
-        return run(argv, -1);
+        return exec(argv, -1);
     }
 
     @Override
-    public int runShellScript(File script, List<String> args, int timeout)
+    public int execShellScript(File script, List<String> args, int timeout)
     {
         Vector<String> argv = new Vector<String>();
-        argv.add(ExecImpl.getInstance().getShell());
+        argv.add(impl.getComspec());
         argv.add("/D");
         argv.add("/C");
         argv.add("CALL");
         argv.add(script.getPath());
         argv.addAll(args);
 
-        return run(argv, timeout);
+        return exec(argv, timeout);
     }
 
     @Override
-    public int runShellScript(File script, List<String> args)
+    public int execShellScript(File script, List<String> args)
     {
-        return runShellScript(script, args, -1);
+        return execShellScript(script, args, -1);
     }
 
     @Override
-    public int runCommand(String cmd, int timeout)
+    public int execCommand(String cmd, int timeout)
     {
         Vector<String> argv = new Vector<String>();
-        argv.add(ExecImpl.getInstance().getShell());
+        argv.add(impl.getComspec());
         argv.add("/D");
         argv.add("/C");
         argv.add(cmd);
 
-        return run(argv, timeout);
+        return exec(argv, timeout);
     }
 
     @Override
-    public int runCommand(String cmd)
+    public int execCommand(String cmd)
     {
-        return runCommand(cmd, -1);
+        return execCommand(cmd, -1);
     }
 }

Modified: commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/platform/windows/WindowsExecImpl.java
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/platform/windows/WindowsExecImpl.java?rev=1102572&r1=1102571&r2=1102572&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/platform/windows/WindowsExecImpl.java
(original)
+++ commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/platform/windows/WindowsExecImpl.java
Fri May 13 06:17:29 2011
@@ -28,19 +28,25 @@ import org.apache.commons.runtime.ExecIm
 final class WindowsExecImpl extends ExecImpl
 {
 
+    private String comspec;
     private WindowsExecImpl()
     {
         // No Instance
     }
 
-    public WindowsExecImpl(String shell)
+    public WindowsExecImpl(String comspec)
     {
-        this.shell = shell;
+        this.comspec = comspec;
     }
 
     public Exec newInstance()
     {
-        return new WindowsExec();
+        return new WindowsExec(this);
+    }
+
+    public final String getComspec()
+    {
+        return comspec;
     }
 
 }

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=1102572&r1=1102571&r2=1102572&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 Fri May 13 06:17:29 2011
@@ -586,11 +586,11 @@ ACR_JNI_EXPORT(jobject, ExecImpl, init0)
     return (*env)->NewObject(env, _clazzn.i, J4MID(0000), AcrNewJavaStringA(env, SHELL_PATH));
 }
 
-ACR_UNX_EXPORT(jlong, PosixExec, run0)(JNI_STDARGS, jstring executable,
-                                       jobjectArray args, jobjectArray envp,
-                                       jstring cwd, jbyteArray inp,
-                                       jobjectArray out, jint redir,
-                                       jint timeout)
+ACR_UNX_EXPORT(jlong, PosixExec, exec0)(JNI_STDARGS, jstring executable,
+                                        jobjectArray args, jobjectArray envp,
+                                        jstring cwd, jbyteArray inp,
+                                        jobjectArray out, jint redir,
+                                        jint timeout)
 {
     int rv = 0;
     int rc = 0;

Modified: commons/sandbox/runtime/trunk/src/main/native/os/win32/exec.c
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/os/win32/exec.c?rev=1102572&r1=1102571&r2=1102572&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/os/win32/exec.c (original)
+++ commons/sandbox/runtime/trunk/src/main/native/os/win32/exec.c Fri May 13 06:17:29 2011
@@ -532,11 +532,11 @@ ACR_JNI_EXPORT(jobject, ExecImpl, init0)
     return (*env)->NewObject(env, _clazzn.i, J4MID(0000), shell);
 }
 
-ACR_WIN_EXPORT(jlong, WindowsExec, run0)(JNI_STDARGS, jstring executable,
-                                         jstring args, jcharArray envb,
-                                         jstring cwd, jbyteArray inp,
-                                         jobjectArray out, jint redir,
-                                         jint timeout)
+ACR_WIN_EXPORT(jlong, WindowsExec, exec0)(JNI_STDARGS, jstring executable,
+                                          jstring args, jcharArray envb,
+                                          jstring cwd, jbyteArray inp,
+                                          jobjectArray out, jint redir,
+                                          jint timeout)
 {
     int rv = 0;
     int rc = 0;

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=1102572&r1=1102571&r2=1102572&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 Fri
May 13 06:17:29 2011
@@ -27,7 +27,7 @@ public class TestExec extends Assert
 
 
     @Test(groups = { "posix" })
-    public void runPosix()
+    public void execPosix()
         throws Exception
     {
         Exec e = Exec.newInstance();
@@ -37,7 +37,7 @@ public class TestExec extends Assert
         args.add("-al");
         e.redirectStdout(true);
         e.redirectStderr(true);
-        int r = e.run(args);
+        int r = e.exec(args);
         assertEquals(r, Status.CHILD_DONE);
         byte[] stdout = e.getStdout();
         assertNotNull(stdout);
@@ -47,7 +47,7 @@ public class TestExec extends Assert
     }
 
     @Test(groups = { "posix" })
-    public void runCat()
+    public void execCat()
         throws Exception
     {
         Exec e = Exec.newInstance();
@@ -56,7 +56,7 @@ public class TestExec extends Assert
         args.add("/bin/cat");
         e.setInput("hello world".getBytes());
         e.redirectStdout(true);
-        int r = e.run(args);
+        int r = e.exec(args);
         assertEquals(r, Status.CHILD_DONE);
         byte[] stdout = e.getStdout();
         assertNotNull(stdout);
@@ -65,17 +65,14 @@ public class TestExec extends Assert
     }
 
     @Test(groups = { "windows" })
-    public void runWindows()
+    public void execWindows()
         throws Exception
     {
         Exec e = Exec.newInstance();
         assertNotNull(e);
-        ArrayList<String> args = new ArrayList<String>();
-        args.add(ExecImpl.getInstance().getShell());
-        args.add("/V");
         e.redirectStdout(true);
         e.redirectStderr(true);
-        int r = e.run(args);
+        int r = e.execCommand("VER");
         assertEquals(r, Status.CHILD_DONE);
         byte[] stdout = e.getStdout();
         assertNotNull(stdout);
@@ -83,19 +80,19 @@ public class TestExec extends Assert
     }
 
     @Test(groups = { "core" })
-    public void runError()
+    public void execError()
         throws Exception
     {
         Exec e = Exec.newInstance();
         assertNotNull(e);
         ArrayList<String> args = new ArrayList<String>();
         args.add("/foo/bar/errorpath");
-        int r = e.run(args);
+        int r = e.exec(args);
         assertEquals(r, Status.CHILD_ERROR);
     }
 
     @Test(groups = { "core" })
-    public void runJavaVersion()
+    public void execJavaVersion()
         throws Exception
     {
         Exec e = Exec.newInstance();
@@ -104,7 +101,7 @@ public class TestExec extends Assert
         args.add(Vm.executable().getPath());
         args.add("-version");
         e.redirectStdout(true);
-        int r = e.run(args);
+        int r = e.exec(args);
         assertEquals(r, Status.CHILD_DONE);
         assertEquals(e.exitval(), 0);
         byte[] stdout = e.getStdout();
@@ -113,13 +110,13 @@ public class TestExec extends Assert
     }
 
     @Test(groups = { "core" })
-    public void runCommand()
+    public void execCommand()
         throws Exception
     {
         Exec e = Exec.newInstance();
         assertNotNull(e);
         e.redirectStdout(true);
-        int r = e.runCommand("echo foo");
+        int r = e.execCommand("echo foo");
         assertEquals(r, Status.CHILD_DONE);
         assertEquals(e.exitval(), 0);
         byte[] stdout = e.getStdout();



Mime
View raw message