Argline splits on spaces, should not when quoted
------------------------------------------------

         Key: MSUREFIRE-139
         URL: http://jira.codehaus.org/browse/MSUREFIRE-139
     Project: Maven 2.x Surefire Plugin
        Type: Bug

    Versions: 2.2    
    Reporter: Andrea Aime
    Priority: Blocker


I need to run surefire with the following argline:

<argline>-javaagent:\"${user.home}\.m2\repository\aspectj\aspectjweaver\1.5.0\aspectjweaver-1.5.0.jar\"</argline>
<argline>-javaagent:\"C:\Documents 
Settings\wolf\.m2\repository\aspectj\aspectjweaver\1.5.0\aspectjweaver-1.5.0.jar\"</argline>

The problem is, ForkConfiguration splits the arguments blindly with 
StringUtils.split and the above turns into three
separate arguments:
-javaagent:"C:\Documents
and 
Settings\wolf\.m2\repository\aspectj\aspectjweaver\1.5.0\aspectjweaver-1.5.0.jar"

And the the vm complains it cannot find the jar C:\Documents.
When quoted, the split should not happen!

The following method proved to support quoting properly when splitting on 
spaces (I'm using it in UmlGraph):

 public static String[] tokenize(String s) {
        ArrayList<String> r = new ArrayList<String>();
        String remain = s;
        int n = 0, pos;

        remain = remain.trim();
        while (remain.length() > 0) {
            if (remain.startsWith("\"")) {
                // Field in quotes
                pos = remain.indexOf('"', 1);
                if (pos == -1)
                    break;
                r.add(remain.substring(1, pos));
                if (pos + 1 < remain.length())
                    pos++;
            } else {
                // Space-separated field
                pos = remain.indexOf(' ', 0);
                if (pos == -1) {
                    r.add(remain);
                    remain = "";
                } else
                    r.add(remain.substring(0, pos));
            }
            remain = remain.substring(pos + 1);
            remain = remain.trim();
            // - is used as a placeholder for empy fields
            if (r.get(n).equals("-"))
                r.set(n, "");
            n++;
        }
        return r.toArray(new String[0]);
    }

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
   http://jira.codehaus.org/secure/Administrators.jspa
-
For more information on JIRA, see:
   http://www.atlassian.com/software/jira

Reply via email to