Uploaded image for project: 'Maven Surefire'
  1. Maven Surefire
  2. SUREFIRE-128

Argline splits on spaces, should not when quoted

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Blocker
    • Resolution: Duplicate
    • 2.0 (2.2 plugin)
    • None
    • None
    • None

    Description

      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.equals("-"))
      r.set(n, "");
      n++;
      }
      return r.toArray(new String[0]);
      }

      Attachments

        Issue Links

          Activity

            People

              Unassigned Unassigned
              aaime Andrea Aime
              Votes:
              3 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: