ant-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bode...@apache.org
Subject cvs commit: jakarta-ant/src/testcases/org/apache/tools/ant/types CommandlineTest.java
Date Fri, 09 Aug 2002 08:39:47 GMT
bodewig     2002/08/09 01:39:47

  Modified:    .        Tag: ANT_15_BRANCH WHATSNEW
               docs/manual Tag: ANT_15_BRANCH using.html
               src/main/org/apache/tools/ant/types Tag: ANT_15_BRANCH
                        Commandline.java
               src/testcases/org/apache/tools/ant/types Tag: ANT_15_BRANCH
                        CommandlineTest.java
  Log:
  Make <arg line="''"/> closer to what a shell would do.
  
  PR: 5906
  
  Don't use <arg line="..." />!
  
  Revision  Changes    Path
  No                   revision
  
  
  No                   revision
  
  
  1.263.2.70 +4 -0      jakarta-ant/WHATSNEW
  
  Index: WHATSNEW
  ===================================================================
  RCS file: /home/cvs/jakarta-ant/WHATSNEW,v
  retrieving revision 1.263.2.69
  retrieving revision 1.263.2.70
  diff -u -r1.263.2.69 -r1.263.2.70
  --- WHATSNEW	9 Aug 2002 06:49:17 -0000	1.263.2.69
  +++ WHATSNEW	9 Aug 2002 08:39:47 -0000	1.263.2.70
  @@ -21,6 +21,10 @@
   
   * <property>'s classpathref attribute was broken.
   
  +* <arg line="''" /> would result in no command line argument, will now
  +  be a single empty argument.  Use <arg value="''"/> if you need the
  +  quotes literally.
  +
   Other changes:
   --------------
   
  
  
  
  No                   revision
  
  
  No                   revision
  
  
  1.21.2.3  +10 -4     jakarta-ant/docs/manual/using.html
  
  Index: using.html
  ===================================================================
  RCS file: /home/cvs/jakarta-ant/docs/manual/using.html,v
  retrieving revision 1.21.2.2
  retrieving revision 1.21.2.3
  diff -u -r1.21.2.2 -r1.21.2.3
  --- using.html	4 Jul 2002 07:50:50 -0000	1.21.2.2
  +++ using.html	9 Aug 2002 08:39:47 -0000	1.21.2.3
  @@ -432,10 +432,6 @@
       <td align="center" rowspan="4">Exactly one of these.</td>
     </tr>
     <tr>
  -    <td valign="top">line</td>
  -    <td valign="top">a space-delimited list of command-line arguments.</td>
  -  </tr>
  -  <tr>
       <td valign="top">file</td>
       <td valign="top">The name of a file as a single command-line
         argument; will be replaced with the absolute filename of the file.</td>
  @@ -448,7 +444,17 @@
         path separators and Ant will convert it to the platform's local
         conventions.</td>
     </tr>
  +  <tr>
  +    <td valign="top">line</td>
  +    <td valign="top">a space-delimited list of command-line arguments.</td>
  +  </tr>
   </table>
  +
  +<p>It is highly recommended to avoid the <code>line</code> version
  +when possible.  Ant will try to split the command line in a way
  +similar to what a (Unix) shell would do, but may create something that
  +is very different from what you expect under some circumstances.</p>
  +
   <h4>Examples</h4>
   <blockquote><pre>
     &lt;arg value=&quot;-l -a&quot;/&gt;
  
  
  
  No                   revision
  
  
  No                   revision
  
  
  1.21.2.2  +6 -2      jakarta-ant/src/main/org/apache/tools/ant/types/Commandline.java
  
  Index: Commandline.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ant/src/main/org/apache/tools/ant/types/Commandline.java,v
  retrieving revision 1.21.2.1
  retrieving revision 1.21.2.2
  diff -u -r1.21.2.1 -r1.21.2.2
  --- Commandline.java	3 May 2002 04:50:20 -0000	1.21.2.1
  +++ Commandline.java	9 Aug 2002 08:39:47 -0000	1.21.2.2
  @@ -356,12 +356,14 @@
           StringTokenizer tok = new StringTokenizer(to_process, "\"\' ", true);
           Vector v = new Vector();
           StringBuffer current = new StringBuffer();
  +        boolean lastTokenHasBeenQuoted = false;
   
           while (tok.hasMoreTokens()) {
               String nextTok = tok.nextToken();
               switch (state) {
               case inQuote:
                   if ("\'".equals(nextTok)) {
  +                    lastTokenHasBeenQuoted = true;
                       state = normal;
                   } else {
                       current.append(nextTok);
  @@ -369,6 +371,7 @@
                   break;
               case inDoubleQuote:
                   if ("\"".equals(nextTok)) {
  +                    lastTokenHasBeenQuoted = true;
                       state = normal;
                   } else {
                       current.append(nextTok);
  @@ -380,18 +383,19 @@
                   } else if ("\"".equals(nextTok)) {
                       state = inDoubleQuote;
                   } else if (" ".equals(nextTok)) {
  -                    if (current.length() != 0) {
  +                    if (lastTokenHasBeenQuoted || current.length() != 0) {
                           v.addElement(current.toString());
                           current.setLength(0);
                       }
                   } else {
                       current.append(nextTok);
                   }
  +                lastTokenHasBeenQuoted = false;
                   break;
               }
           }
   
  -        if (current.length() != 0) {
  +        if (lastTokenHasBeenQuoted || current.length() != 0) {
               v.addElement(current.toString());
           }
   
  
  
  
  No                   revision
  
  
  No                   revision
  
  
  1.10.2.1  +26 -1     jakarta-ant/src/testcases/org/apache/tools/ant/types/CommandlineTest.java
  
  Index: CommandlineTest.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ant/src/testcases/org/apache/tools/ant/types/CommandlineTest.java,v
  retrieving revision 1.10
  retrieving revision 1.10.2.1
  diff -u -r1.10 -r1.10.2.1
  --- CommandlineTest.java	10 Jan 2002 10:13:13 -0000	1.10
  +++ CommandlineTest.java	9 Aug 2002 08:39:47 -0000	1.10.2.1
  @@ -1,7 +1,7 @@
   /*
    * The Apache Software License, Version 1.1
    *
  - * Copyright (c) 2000-2001 The Apache Software Foundation.  All rights
  + * Copyright (c) 2000-2002 The Apache Software Foundation.  All rights
    * reserved.
    *
    * Redistribution and use in source and binary forms, with or without
  @@ -118,6 +118,31 @@
           assertEquals("case with quoted whitespace", 4, s.length);
           assertEquals("backslash included", "2\\", s[1]);
   
  +        // "" should become a single empty argument, same for ''
  +        // PR 5906
  +        s = Commandline.translateCommandline("\"\" a");
  +        assertEquals("Doublequoted null arg prepend", 2, s.length);
  +        assertEquals("Doublequoted null arg prepend", "", s[0]);
  +        assertEquals("Doublequoted null arg prepend", "a", s[1]);
  +        s = Commandline.translateCommandline("a \"\"");
  +        assertEquals("Doublequoted null arg append", 2, s.length);
  +        assertEquals("Doublequoted null arg append", "a", s[0]);
  +        assertEquals("Doublequoted null arg append", "", s[1]);
  +        s = Commandline.translateCommandline("\"\"");
  +        assertEquals("Doublequoted null arg", 1, s.length);
  +        assertEquals("Doublequoted null arg", "", s[0]);
  +
  +        s = Commandline.translateCommandline("\'\' a");
  +        assertEquals("Singlequoted null arg prepend", 2, s.length);
  +        assertEquals("Singlequoted null arg prepend", "", s[0]);
  +        assertEquals("Singlequoted null arg prepend", "a", s[1]);
  +        s = Commandline.translateCommandline("a \'\'");
  +        assertEquals("Singlequoted null arg append", 2, s.length);
  +        assertEquals("Singlequoted null arg append", "a", s[0]);
  +        assertEquals("Singlequoted null arg append", "", s[1]);
  +        s = Commandline.translateCommandline("\'\'");
  +        assertEquals("Singlequoted null arg", 1, s.length);
  +        assertEquals("Singlequoted null arg", "", s[0]);
   
           // now to the expected failures
           
  
  
  

--
To unsubscribe, e-mail:   <mailto:ant-dev-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:ant-dev-help@jakarta.apache.org>


Mime
View raw message