You are viewing a plain text version of this content. The canonical link for it is here.
Posted to scm-dev@maven.apache.org by Tim Reilly <ti...@consultant.com> on 2004/04/21 06:25:38 UTC

Win2k CommandLine test failure

org.apache.maven.scm.util.CommandlineTest fails on Win2K

Testcase: testExecute took 0.02 sec
	FAILED
CreateProcess: echo Hello error=2
junit.framework.AssertionFailedError: CreateProcess: echo Hello error=2
	at
org.apache.maven.scm.util.CommandlineTest.testExecute(CommandlineTest.java:9
1)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39
)
	at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl
.java:25)

The test is perhaps flawed since the command asked to run is echo... it
would pass if the command to run were
#> cmd.exe /C echo Hello
instead, but perhaps its best to change CommandLine.java to do something
like in this article? I only skimmed the part about buffer sizes so I'm not
sure its needed or if the command line output needs to be captured in
CommandLine.java
~When Runtime.exec() won't:
http://www.javaworld.com/javaworld/jw-12-2000/jw-1229-traps.html

------
The following Foo.java demonstrates:
------
public class Foo {

	public static void main(String[] args) {
		try {
			Runtime.getRuntime().exec("cmd.exe /C echo Hello");
			System.out.println("Ok so far");
			Runtime.getRuntime().exec("echo Hello");
			System.out.println("Great done.");
		}
		catch (Exception e) {
			e.printStackTrace();
		}
	}
}
------
Generates this
------
Ok so far
java.io.IOException: CreateProcess: echo Hello error=2
	at java.lang.Win32Process.create(Native Method)
	at java.lang.Win32Process.<init>(Win32Process.java:63)
	at java.lang.Runtime.execInternal(Native Method)
	at java.lang.Runtime.exec(Runtime.java:550)
	at java.lang.Runtime.exec(Runtime.java:416)
	at java.lang.Runtime.exec(Runtime.java:358)
	at java.lang.Runtime.exec(Runtime.java:322)
	at Foo.main(Foo.java:8)

Hope that helps.
-TR

Also, if this type of email should go to jira let me know... I didn't see a
maven-scm though, so point me in the right direction as needed.


RE: Win2k CommandLine test failure

Posted by Tim Reilly <ti...@consultant.com>.
Ok, here is what I did to change the test case...


    public void testExecute()
    {
        try
        {
            Commandline cmd = new Commandline();
            cmd.setWorkingDirectory(baseDir);
            cmd.setExecutable("cmd.exe /C echo");
            assertEquals("cmd.exe \\C echo", cmd.getExecutable());
            cmd.createArgument().setValue("Hello");
            assertEquals("cmd.exe \\C echo Hello", cmd.toString());
            cmd.execute();
        }
        catch(Exception e)
        {
            fail(e.getMessage());
        }
    }

And here is what I got...


Testsuite: org.apache.maven.scm.util.CommandlineTest
Tests run: 7, Failures: 1, Errors: 0, Time elapsed: 0.061 sec
------------- Standard Output ---------------
Hello
"Hello World"
'"Hello World"'
------------- ---------------- ---------------
Testcase: testCommandlineWithoutArgumentInConstructor took 0.01 sec
Testcase: testCommandlineWithArgumentInConstructor took 0 sec
Testcase: testExecute took 0.02 sec
 FAILED
expected:<cmd.exe \C echo...> but was:<"cmd.exe \C echo"...>
junit.framework.ComparisonFailure: expected:<cmd.exe \C echo...> but
was:<"cmd.exe \C echo"...>
 at
org.apache.maven.scm.util.CommandlineTest.testExecute(CommandlineTest.java:8
5)
 at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
 at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39
)
 at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl
.java:25)
Testcase: testExecuteTestcase: testSetLine took 0 sec
Testcase: testCreateCommandInReverseOrder took 0 sec
Testcase: testSetFile took 0 sec
Testcase: testQuoteArguments took 0 sec


Re: Win2k CommandLine test failure

Posted by Emmanuel Venisse <em...@venisse.net>.
----- Original Message ----- 
From: "Tim Reilly" <ti...@consultant.com>
To: <sc...@maven.apache.org>
Sent: Thursday, April 22, 2004 6:09 AM
Subject: RE: Win2k CommandLine test failure


> So..
> I started changing CommandLine.java to use the concept of a shell (or
> command interpreter) argument.
> getCommandLine() builds up the String as follows:
> [shell] [executable] [arguments(0..*)]
>
> If I follow the idea behind the code; it's to abstract the strings in
> command line into an OO model.
> Currently the executable and it's arguments are modeled, so adding the
shell
> seems logical to me?
> It would also allow for.. say on unix changing to use sh, bash, csh etc
for
> whatever reason.
>
> I have the changes introduced, but at the last moment I realized I'd made
a
> mistake.
> Introducing 'shell' into the model there also would be shell agruments (/C
> /X for Windows)
> which is the mistake I made. As a quick hack I made the shell a String[]
> after doing everything with String, but it would become;
> [shell] [shellarguments(0..*)] [executable] [arguments(0..*)]
>
> Emmanuel if you agree with change(s) I'll continue on with this and open a
> ticket to send/attach a patch for it.
> I probably won't have it done for a couple of days, but maybe sooner.

OK for me.

>
> Below is a diff (not for applying) but may explain better than I have
above:
> (Note currently I changed String::shell to String[] shell makes it ugly.
> I would refactor to include String::shell + String[]::shellArguments
before
> sending a real patch.)
>
> Let me know if I should continue with it.

I think it's not necessary to have getter/setter and default method for
obtain the shell.
I think an only one method (getShell) is sufficient. Or getDefaultShell as
private method and getShell=getDefaultShell if shell is null.

Emmanuel


> Thanks,
> -TR
>
> --------------------
> Index: org/apache/maven/scm/command/Command.java
> ===================================================================
> RCS file:
>
/home/cvspublic/maven-scm/scm-api/src/main/java/org/apache/maven/scm/command
> /Command.java,v
> retrieving revision 1.1.1.1
> diff -u -r1.1.1.1 Command.java
> --- org/apache/maven/scm/command/Command.java 20 Apr 2004 19:05:49 -0000
> 1.1.1.1
> +++ org/apache/maven/scm/command/Command.java 22 Apr 2004 03:34:24 -0000
> @@ -61,4 +61,8 @@
>   StreamConsumer getConsumer();
>
>   Commandline getCommandLine() throws ScmException;
> +
> +    String getShell();
> +
> +    void setShell(String string);
>  }
> Index: org/apache/maven/scm/util/Commandline.java
> ===================================================================
> RCS file:
>
/home/cvspublic/maven-scm/scm-api/src/main/java/org/apache/maven/scm/util/Co
> mmandline.java,v
> retrieving revision 1.1.1.1
> diff -u -r1.1.1.1 Commandline.java
> --- org/apache/maven/scm/util/Commandline.java 20 Apr 2004 19:05:51 -0000
> 1.1.1.1
> +++ org/apache/maven/scm/util/Commandline.java 22 Apr 2004 03:34:24 -0000
> @@ -85,9 +85,14 @@
>   */
>  public class Commandline implements Cloneable
>  {
> +    protected static final String OS_NAME = "os.name";
> +    protected static final String WINDOWS = "Windows";
> +
>      private Vector arguments = new Vector();
>      private String executable = null;
>      private File workingDir = null;
> +    private String[] shell = getDefaultShell();
> +
>
>      public Commandline( String toProcess )
>      {
> @@ -283,14 +288,25 @@
>      public String[] getCommandline()
>      {
>          final String[] args = getArguments();
> -        if ( executable == null )
> +        Vector result = new Vector(args.length);
> +        for (int i = 0; i < args.length; i++ )
>          {
> -            return args;
> +            result.add(args[i]);
>          }
> -        final String[] result = new String[args.length + 1];
> -        result[0] = executable;
> -        System.arraycopy( args, 0, result, 1, args.length );
> -        return result;
> +
> +        if ( executable != null && executable.length() > 0)
> +        {
> +            result.insertElementAt(executable, 0);
> +        }
> +
> +        if ( shell != null && shell.length > 0)
> +        {
> +            for (int j = shell.length -1; j >= 0; j--) {
> +                result.insertElementAt(shell[j], 0);
> +            }
> +
> +        }
> +        return (String[]) result.toArray(new String[result.size()]);
>      }
>
>      /**
> @@ -371,14 +387,19 @@
>              if ( i > 0 )
>              {
>                  result.append( ' ' );
> +
> +                try
> +                {
> +                    result.append( quoteArgument( line[i] ) );
> +                }
> +                catch ( ScmException e )
> +                {
> +                    System.err.println( "Error quoting argument." );
> +                }
>              }
> -            try
> -            {
> -                result.append( quoteArgument( line[i] ) );
> -            }
> -            catch ( ScmException e )
> +            else
>              {
> -                System.err.println( "Error quoting argument." );
> +                result.append( line[i] );
>              }
>          }
>          return result.toString();
> @@ -566,4 +587,41 @@
>          return process;
>      }
>
> +    /**
> +     * <p>Gets the shell commands will be executed with.</p>
> +     *
> +     * <p>e.g. command.com [someExec] [argument1...]</p>
> +     * @return the shell commands will be executed with.
> +     */
> +    public String[] getShell() {
> +        return shell;
> +    }
> +
> +    /**
> +     * <p>Sets the shell commands will be executed with.</p>
> +     *
> +     * @param string the shell name. [cmd.exe|command.com|sh|etc]
> +     */
> +    public void setShell(String string[]) {
> +        shell = string;
> +    }
> +
> +    protected static String[] getDefaultShell() {
> +            String os = System.getProperty(OS_NAME);
> +            String[] osShell = null;
> +            if ( os.indexOf(WINDOWS) != -1 )
> +            {
> +                if (os.indexOf("95") != -1 || os.indexOf("98") != -1 ||
> os.indexOf("Me") != -1)
> +                {
> +                    String[] ar = {"command", "/C"};
> +                    return ar;
> +                }
> +                else
> +                {
> +                    String[] ar = {"cmd.exe", "/C", "/X"};
> +                    return ar;
> +                }
> +            }
> +        return osShell;
> +    }
>  }
> Index: org/apache/maven/scm/command/TestCommand.java
> ===================================================================
> RCS file:
>
/home/cvspublic/maven-scm/scm-api/src/test/java/org/apache/maven/scm/command
> /TestCommand.java,v
> retrieving revision 1.1.1.1
> diff -u -r1.1.1.1 TestCommand.java
> --- org/apache/maven/scm/command/TestCommand.java 20 Apr 2004
19:05:51 -0000
> 1.1.1.1
> +++ org/apache/maven/scm/command/TestCommand.java 22 Apr 2004
03:38:16 -0000
> @@ -101,4 +101,19 @@
>      {
>          return null;
>      }
> +
> +    /* (non-Javadoc)
> +     * @see org.apache.maven.scm.command.Command#setTag(java.lang.String)
> +     */
> +    public void setShell(String shellName)
> +    {
> +    }
> +
> +    /* (non-Javadoc)
> +     * @see org.apache.maven.scm.command.Command#getTag()
> +     */
> +    public String getShell()
> +    {
> +        return null;
> +    }
>  }
> Index: org/apache/maven/scm/util/CommandlineTest.java
> ===================================================================
> RCS file:
>
/home/cvspublic/maven-scm/scm-api/src/test/java/org/apache/maven/scm/util/Co
> mmandlineTest.java,v
> retrieving revision 1.1.1.1
> diff -u -r1.1.1.1 CommandlineTest.java
> --- org/apache/maven/scm/util/CommandlineTest.java 20 Apr 2004
> 19:05:52 -0000 1.1.1.1
> +++ org/apache/maven/scm/util/CommandlineTest.java 22 Apr 2004
> 03:38:16 -0000
> @@ -49,9 +49,10 @@
>          {
>              Commandline cmd = new Commandline();
>              cmd.setWorkingDirectory(baseDir);
> +            String baseline = cmd.toString();
>              cmd.createArgument().setValue("cd");
>              cmd.createArgument().setValue(".");
> -            assertEquals("cd .", cmd.toString());
> +            assertEquals(baseline + " cd .", cmd.toString());
>          }
>          catch(Exception e)
>          {
> @@ -65,7 +66,10 @@
>          {
>              Commandline cmd = new Commandline("cd .");
>              cmd.setWorkingDirectory(baseDir);
> -            assertEquals("cd .", cmd.toString());
> +            System.err.println(TstCommandLine.getDefShell()[0] + " cd
.");
> +            System.err.println(cmd.toString());
> +            String[] shellstuff = TstCommandLine.getDefShell();
> +            assertEquals(shellstuff[0] + " " + shellstuff[1] + " " +
> shellstuff[2] + " cd .", cmd.toString());
>          }
>          catch(Exception e)
>          {
> @@ -79,14 +83,16 @@
>          {
>              Commandline cmd = new Commandline();
>              cmd.setWorkingDirectory(baseDir);
> +            String baseline = cmd.toString();
>              cmd.setExecutable("echo");
>              assertEquals("echo", cmd.getExecutable());
>              cmd.createArgument().setValue("Hello");
> -            assertEquals("echo Hello", cmd.toString());
> +            assertEquals(baseline + " echo Hello", cmd.toString());
>              cmd.execute();
>          }
>          catch(Exception e)
>          {
> +            e.printStackTrace();
>              fail(e.getMessage());
>          }
>      }
> @@ -97,10 +103,11 @@
>          {
>              Commandline cmd = new Commandline();
>              cmd.setWorkingDirectory(baseDir);
> +            String baseline = cmd.toString();
>              cmd.setExecutable("echo");
>              cmd.createArgument().setLine(null);
>              cmd.createArgument().setLine("Hello");
> -            assertEquals("echo Hello", cmd.toString());
> +            assertEquals(baseline + " echo Hello", cmd.toString());
>          }
>          catch(Exception e)
>          {
> @@ -114,9 +121,10 @@
>          {
>              Commandline cmd = new Commandline();
>              cmd.setWorkingDirectory(baseDir);
> +            String baseline = cmd.toString();
>              cmd.createArgument().setValue(".");
>              cmd.createArgument(true).setValue("cd");
> -            assertEquals("cd .", cmd.toString());
> +            assertEquals(baseline + " cd .", cmd.toString());
>          }
>          catch(Exception e)
>          {
> @@ -129,11 +137,12 @@
>          try
>          {
>              Commandline cmd = new Commandline();
> +            String baseline = cmd.toString();
>              cmd.setWorkingDirectory(baseDir);
>              cmd.createArgument().setValue("more");
>              File f = new File("test.txt");
>              cmd.createArgument().setFile(f);
> -            assertEquals("more "+f.getAbsoluteFile(), cmd.toString());
> +            assertEquals(baseline + " more "+f.getAbsoluteFile(),
> cmd.toString());
>          }
>          catch(Exception e)
>          {
> @@ -169,5 +178,32 @@
>          }
>      }
>
> +    public void testSetShell()
> +    {
> +        Commandline cmd = new Commandline();
> +        String[] newShell = {"abash"};
> +        cmd.setShell(newShell);
> +        assertEquals(newShell, cmd.getShell());
> +    }
> +
> +    public void testGetDefaultShell()
> +    {
> +        TstCommandLine cmd = new TstCommandLine();
> +        if ( System.getProperty("os.name").indexOf("Windows") > -1)
> +        {
> +            String[] theShell = cmd.getDefShell();
> +            assertTrue(theShell[0].indexOf("command") == 0 ||
> theShell[0].indexOf("cmd") == 0);
> +        }
> +    }
> +
> +    /**
> +     * Inner class to help test/wrap non public methods.
> +     */
> +    static class TstCommandLine extends Commandline
> +    {
> +        public static String[] getDefShell() {
> +            return TstCommandLine.getDefaultShell();
> +        }
> +    }
>  }
>
>
>
>


RE: Win2k CommandLine test failure

Posted by Tim Reilly <ti...@consultant.com>.
So..
I started changing CommandLine.java to use the concept of a shell (or
command interpreter) argument.
getCommandLine() builds up the String as follows:
[shell] [executable] [arguments(0..*)]

If I follow the idea behind the code; it's to abstract the strings in
command line into an OO model.
Currently the executable and it's arguments are modeled, so adding the shell
seems logical to me?
It would also allow for.. say on unix changing to use sh, bash, csh etc for
whatever reason.

I have the changes introduced, but at the last moment I realized I'd made a
mistake.
Introducing 'shell' into the model there also would be shell agruments (/C
/X for Windows)
which is the mistake I made. As a quick hack I made the shell a String[]
after doing everything with String, but it would become;
[shell] [shellarguments(0..*)] [executable] [arguments(0..*)]

Emmanuel if you agree with change(s) I'll continue on with this and open a
ticket to send/attach a patch for it.
I probably won't have it done for a couple of days, but maybe sooner.

Below is a diff (not for applying) but may explain better than I have above:
(Note currently I changed String::shell to String[] shell makes it ugly.
I would refactor to include String::shell + String[]::shellArguments before
sending a real patch.)

Let me know if I should continue with it.
Thanks,
-TR

--------------------
Index: org/apache/maven/scm/command/Command.java
===================================================================
RCS file:
/home/cvspublic/maven-scm/scm-api/src/main/java/org/apache/maven/scm/command
/Command.java,v
retrieving revision 1.1.1.1
diff -u -r1.1.1.1 Command.java
--- org/apache/maven/scm/command/Command.java	20 Apr 2004 19:05:49 -0000
1.1.1.1
+++ org/apache/maven/scm/command/Command.java	22 Apr 2004 03:34:24 -0000
@@ -61,4 +61,8 @@
 	StreamConsumer getConsumer();

 	Commandline getCommandLine() throws ScmException;
+
+    String getShell();
+
+    void setShell(String string);
 }
Index: org/apache/maven/scm/util/Commandline.java
===================================================================
RCS file:
/home/cvspublic/maven-scm/scm-api/src/main/java/org/apache/maven/scm/util/Co
mmandline.java,v
retrieving revision 1.1.1.1
diff -u -r1.1.1.1 Commandline.java
--- org/apache/maven/scm/util/Commandline.java	20 Apr 2004 19:05:51 -0000
1.1.1.1
+++ org/apache/maven/scm/util/Commandline.java	22 Apr 2004 03:34:24 -0000
@@ -85,9 +85,14 @@
  */
 public class Commandline implements Cloneable
 {
+    protected static final String OS_NAME = "os.name";
+    protected static final String WINDOWS = "Windows";
+
     private Vector arguments = new Vector();
     private String executable = null;
     private File workingDir = null;
+    private String[] shell = getDefaultShell();
+

     public Commandline( String toProcess )
     {
@@ -283,14 +288,25 @@
     public String[] getCommandline()
     {
         final String[] args = getArguments();
-        if ( executable == null )
+        Vector result = new Vector(args.length);
+        for (int i = 0; i < args.length; i++ )
         {
-            return args;
+            result.add(args[i]);
         }
-        final String[] result = new String[args.length + 1];
-        result[0] = executable;
-        System.arraycopy( args, 0, result, 1, args.length );
-        return result;
+
+        if ( executable != null && executable.length() > 0)
+        {
+            result.insertElementAt(executable, 0);
+        }
+
+        if ( shell != null && shell.length > 0)
+        {
+            for (int j = shell.length -1; j >= 0; j--) {
+                result.insertElementAt(shell[j], 0);
+            }
+
+        }
+        return (String[]) result.toArray(new String[result.size()]);
     }

     /**
@@ -371,14 +387,19 @@
             if ( i > 0 )
             {
                 result.append( ' ' );
+
+                try
+                {
+                    result.append( quoteArgument( line[i] ) );
+                }
+                catch ( ScmException e )
+                {
+                    System.err.println( "Error quoting argument." );
+                }
             }
-            try
-            {
-                result.append( quoteArgument( line[i] ) );
-            }
-            catch ( ScmException e )
+            else
             {
-                System.err.println( "Error quoting argument." );
+                result.append( line[i] );
             }
         }
         return result.toString();
@@ -566,4 +587,41 @@
         return process;
     }

+    /**
+     * <p>Gets the shell commands will be executed with.</p>
+     *
+     * <p>e.g. command.com [someExec] [argument1...]</p>
+     * @return the shell commands will be executed with.
+     */
+    public String[] getShell() {
+        return shell;
+    }
+
+    /**
+     * <p>Sets the shell commands will be executed with.</p>
+     *
+     * @param string the shell name. [cmd.exe|command.com|sh|etc]
+     */
+    public void setShell(String string[]) {
+        shell = string;
+    }
+
+    protected static String[] getDefaultShell() {
+            String os = System.getProperty(OS_NAME);
+            String[] osShell = null;
+            if ( os.indexOf(WINDOWS) != -1 )
+            {
+                if (os.indexOf("95") != -1 || os.indexOf("98") != -1 ||
os.indexOf("Me") != -1)
+                {
+                    String[] ar = {"command", "/C"};
+                    return ar;
+                }
+                else
+                {
+                    String[] ar = {"cmd.exe", "/C", "/X"};
+                    return ar;
+                }
+            }
+        return osShell;
+    }
 }
Index: org/apache/maven/scm/command/TestCommand.java
===================================================================
RCS file:
/home/cvspublic/maven-scm/scm-api/src/test/java/org/apache/maven/scm/command
/TestCommand.java,v
retrieving revision 1.1.1.1
diff -u -r1.1.1.1 TestCommand.java
--- org/apache/maven/scm/command/TestCommand.java	20 Apr 2004 19:05:51 -0000
1.1.1.1
+++ org/apache/maven/scm/command/TestCommand.java	22 Apr 2004 03:38:16 -0000
@@ -101,4 +101,19 @@
     {
         return null;
     }
+
+    /* (non-Javadoc)
+     * @see org.apache.maven.scm.command.Command#setTag(java.lang.String)
+     */
+    public void setShell(String shellName)
+    {
+    }
+
+    /* (non-Javadoc)
+     * @see org.apache.maven.scm.command.Command#getTag()
+     */
+    public String getShell()
+    {
+        return null;
+    }
 }
Index: org/apache/maven/scm/util/CommandlineTest.java
===================================================================
RCS file:
/home/cvspublic/maven-scm/scm-api/src/test/java/org/apache/maven/scm/util/Co
mmandlineTest.java,v
retrieving revision 1.1.1.1
diff -u -r1.1.1.1 CommandlineTest.java
--- org/apache/maven/scm/util/CommandlineTest.java	20 Apr 2004
19:05:52 -0000	1.1.1.1
+++ org/apache/maven/scm/util/CommandlineTest.java	22 Apr 2004
03:38:16 -0000
@@ -49,9 +49,10 @@
         {
             Commandline cmd = new Commandline();
             cmd.setWorkingDirectory(baseDir);
+            String baseline = cmd.toString();
             cmd.createArgument().setValue("cd");
             cmd.createArgument().setValue(".");
-            assertEquals("cd .", cmd.toString());
+            assertEquals(baseline + " cd .", cmd.toString());
         }
         catch(Exception e)
         {
@@ -65,7 +66,10 @@
         {
             Commandline cmd = new Commandline("cd .");
             cmd.setWorkingDirectory(baseDir);
-            assertEquals("cd .", cmd.toString());
+            System.err.println(TstCommandLine.getDefShell()[0] + " cd .");
+            System.err.println(cmd.toString());
+            String[] shellstuff = TstCommandLine.getDefShell();
+            assertEquals(shellstuff[0] + " " + shellstuff[1] + " " +
shellstuff[2] + " cd .", cmd.toString());
         }
         catch(Exception e)
         {
@@ -79,14 +83,16 @@
         {
             Commandline cmd = new Commandline();
             cmd.setWorkingDirectory(baseDir);
+            String baseline = cmd.toString();
             cmd.setExecutable("echo");
             assertEquals("echo", cmd.getExecutable());
             cmd.createArgument().setValue("Hello");
-            assertEquals("echo Hello", cmd.toString());
+            assertEquals(baseline + " echo Hello", cmd.toString());
             cmd.execute();
         }
         catch(Exception e)
         {
+            e.printStackTrace();
             fail(e.getMessage());
         }
     }
@@ -97,10 +103,11 @@
         {
             Commandline cmd = new Commandline();
             cmd.setWorkingDirectory(baseDir);
+            String baseline = cmd.toString();
             cmd.setExecutable("echo");
             cmd.createArgument().setLine(null);
             cmd.createArgument().setLine("Hello");
-            assertEquals("echo Hello", cmd.toString());
+            assertEquals(baseline + " echo Hello", cmd.toString());
         }
         catch(Exception e)
         {
@@ -114,9 +121,10 @@
         {
             Commandline cmd = new Commandline();
             cmd.setWorkingDirectory(baseDir);
+            String baseline = cmd.toString();
             cmd.createArgument().setValue(".");
             cmd.createArgument(true).setValue("cd");
-            assertEquals("cd .", cmd.toString());
+            assertEquals(baseline + " cd .", cmd.toString());
         }
         catch(Exception e)
         {
@@ -129,11 +137,12 @@
         try
         {
             Commandline cmd = new Commandline();
+            String baseline = cmd.toString();
             cmd.setWorkingDirectory(baseDir);
             cmd.createArgument().setValue("more");
             File f = new File("test.txt");
             cmd.createArgument().setFile(f);
-            assertEquals("more "+f.getAbsoluteFile(), cmd.toString());
+            assertEquals(baseline + " more "+f.getAbsoluteFile(),
cmd.toString());
         }
         catch(Exception e)
         {
@@ -169,5 +178,32 @@
         }
     }

+    public void testSetShell()
+    {
+        Commandline cmd = new Commandline();
+        String[] newShell = {"abash"};
+        cmd.setShell(newShell);
+        assertEquals(newShell, cmd.getShell());
+    }
+
+    public void testGetDefaultShell()
+    {
+        TstCommandLine cmd = new TstCommandLine();
+        if ( System.getProperty("os.name").indexOf("Windows") > -1)
+        {
+            String[] theShell = cmd.getDefShell();
+            assertTrue(theShell[0].indexOf("command") == 0 ||
theShell[0].indexOf("cmd") == 0);
+        }
+    }
+
+    /**
+     * Inner class to help test/wrap non public methods.
+     */
+    static class TstCommandLine extends Commandline
+    {
+        public static String[] getDefShell() {
+            return TstCommandLine.getDefaultShell();
+        }
+    }
 }




RE: Win2k CommandLine test failure

Posted by Tim Reilly <ti...@consultant.com>.
> Could you test with "cmd.exe /C" before fix it in CVS?
> I'm works on Win XP and "echo Hello" works fine.

I tested last night.. after I sent the email (sorry) and it failed.
(I commented out the test to build 0.9 - to run maven test in Clearcase
provider.)
I will send the exception tonight after I'm home.

I think it was something to do with the spaces or the /C
Also on Win98 or lower it would be command.com instead of cmd.exe.

The error code 2 is file not found.
Turns out exec is looking for echo.exe,
but only cmd.exe and/or command.exe knows to resolve echo, dir, .., etc.

[I'm trying to think if something other than than echo would work?
I can't think of one that's cross platform and is an actually exe on windows
versions less than xp.]

-TR



Re: Win2k CommandLine test failure

Posted by Emmanuel Venisse <em...@venisse.net>.
----- Original Message ----- 
From: "Tim Reilly" <ti...@consultant.com>
To: <sc...@maven.apache.org>
Sent: Wednesday, April 21, 2004 6:25 AM
Subject: Win2k CommandLine test failure


> org.apache.maven.scm.util.CommandlineTest fails on Win2K
>
> Testcase: testExecute took 0.02 sec
> FAILED
> CreateProcess: echo Hello error=2
> junit.framework.AssertionFailedError: CreateProcess: echo Hello error=2
> at
>
org.apache.maven.scm.util.CommandlineTest.testExecute(CommandlineTest.java:9
> 1)
> at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
> at
>
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39
> )
> at
>
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl
> .java:25)
>
> The test is perhaps flawed since the command asked to run is echo... it
> would pass if the command to run were
> #> cmd.exe /C echo Hello
> instead, but perhaps its best to change CommandLine.java to do something
> like in this article? I only skimmed the part about buffer sizes so I'm
not
> sure its needed or if the command line output needs to be captured in
> CommandLine.java
> ~When Runtime.exec() won't:
> http://www.javaworld.com/javaworld/jw-12-2000/jw-1229-traps.html

Could you test with "cmd.exe /C" before fix it in CVS?
I'm works on Win XP and "echo Hello" works fine.

Thanks
Emmanuel

>
> ------
> The following Foo.java demonstrates:
> ------
> public class Foo {
>
> public static void main(String[] args) {
> try {
> Runtime.getRuntime().exec("cmd.exe /C echo Hello");
> System.out.println("Ok so far");
> Runtime.getRuntime().exec("echo Hello");
> System.out.println("Great done.");
> }
> catch (Exception e) {
> e.printStackTrace();
> }
> }
> }
> ------
> Generates this
> ------
> Ok so far
> java.io.IOException: CreateProcess: echo Hello error=2
> at java.lang.Win32Process.create(Native Method)
> at java.lang.Win32Process.<init>(Win32Process.java:63)
> at java.lang.Runtime.execInternal(Native Method)
> at java.lang.Runtime.exec(Runtime.java:550)
> at java.lang.Runtime.exec(Runtime.java:416)
> at java.lang.Runtime.exec(Runtime.java:358)
> at java.lang.Runtime.exec(Runtime.java:322)
> at Foo.main(Foo.java:8)
>
> Hope that helps.
> -TR
>
> Also, if this type of email should go to jira let me know... I didn't see
a
> maven-scm though, so point me in the right direction as needed.
>
>


Re: Win2k CommandLine test failure

Posted by Jason van Zyl <jv...@maven.org>.
On Wed, 2004-04-21 at 00:25, Tim Reilly wrote:
> org.apache.maven.scm.util.CommandlineTest fails on Win2K

I'll leave the windows stuff to Emmanuel :-)

> 
> Also, if this type of email should go to jira let me know... I didn't see a
> maven-scm though, so point me in the right direction as needed.

I just setup the JIRA project to prepare for a 0.9 release. Here ya go:

http://jira.codehaus.org/secure/BrowseProject.jspa?id=10527

Thanks for the feedback!

-- 
jvz.

Jason van Zyl
jason@maven.org
http://maven.apache.org

happiness is like a butterfly: the more you chase it, the more it will
elude you, but if you turn your attention to other things, it will come
and sit softly on your shoulder ...

 -- Thoreau 


Testing clearcase

Posted by Tim Reilly <ti...@consultant.com>.
Testing the ClearCase provider succeeds running from here:
\maven-scm\scm-providers\clearcase> maven test
...
[Build Successful]

Hopefully I did that correctly.

Friday is my last day with my employer (I'm jumping ship ;) 
- so I won't have ready access to Clearcase LT after that.

If more of the ClearCase tests are implemented before Fri I can test again.
Just drop me a note.

Thanks
-TR