compat/maven-embedder/src/main/java/org/apache/maven/cli/CleanArgument.java [28:101]:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
public class CleanArgument {
    public static String[] cleanArgs(String[] args) {
        try {
            return doCleanArgs(args);
        } catch (RuntimeException e) {
            for (String a : args) {
                System.out.println("Arg: '" + a + "'");
            }
            throw e;
        }
    }

    private static String[] doCleanArgs(String[] args) {
        List<String> cleaned = new ArrayList<>();

        StringBuilder currentArg = null;

        for (String arg : args) {
            boolean addedToBuffer = false;

            if (arg.startsWith("\"")) {
                // if we're in the process of building up another arg, push it and start over.
                // this is for the case: "-Dfoo=bar "-Dfoo2=bar two" (note the first unterminated quote)
                if (currentArg != null) {
                    cleaned.add(currentArg.toString());
                }

                // start building an argument here.
                currentArg = new StringBuilder(arg.substring(1));
                addedToBuffer = true;
            }

            // this has to be a separate "if" statement, to capture the case of: "-Dfoo=bar"
            if (addedToBuffer && arg.endsWith("\"")) {
                // if we're building an argument, keep doing so.
                // if this is the case of "-Dfoo=bar", then we need to adjust the buffer.
                if (!currentArg.isEmpty()) {
                    currentArg.setLength(currentArg.length() - 1);
                }

                cleaned.add(currentArg.toString());

                currentArg = null;
                continue;
            }

            // if we haven't added this arg to the buffer, and we ARE building an argument
            // buffer, then append it with a preceding space...again, not sure what else to
            // do other than collapse whitespace.
            // NOTE: The case of a trailing quote is handled by nullifying the arg buffer.
            if (!addedToBuffer) {
                if (currentArg != null) {
                    currentArg.append(' ').append(arg);
                } else {
                    cleaned.add(arg);
                }
            }
        }

        if (currentArg != null) {
            cleaned.add(currentArg.toString());
        }

        int cleanedSz = cleaned.size();

        String[] cleanArgs;

        if (cleanedSz == 0) {
            cleanArgs = args;
        } else {
            cleanArgs = cleaned.toArray(new String[0]);
        }

        return cleanArgs;
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -



impl/maven-cli/src/main/java/org/apache/maven/cling/invoker/CleanArgument.java [27:100]:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
public class CleanArgument {
    public static String[] cleanArgs(String[] args) {
        try {
            return doCleanArgs(args);
        } catch (RuntimeException e) {
            for (String a : args) {
                System.out.println("Arg: '" + a + "'");
            }
            throw e;
        }
    }

    private static String[] doCleanArgs(String[] args) {
        List<String> cleaned = new ArrayList<>();

        StringBuilder currentArg = null;

        for (String arg : args) {
            boolean addedToBuffer = false;

            if (arg.startsWith("\"")) {
                // if we're in the process of building up another arg, push it and start over.
                // this is for the case: "-Dfoo=bar "-Dfoo2=bar two" (note the first unterminated quote)
                if (currentArg != null) {
                    cleaned.add(currentArg.toString());
                }

                // start building an argument here.
                currentArg = new StringBuilder(arg.substring(1));
                addedToBuffer = true;
            }

            // this has to be a separate "if" statement, to capture the case of: "-Dfoo=bar"
            if (addedToBuffer && arg.endsWith("\"")) {
                // if we're building an argument, keep doing so.
                // if this is the case of "-Dfoo=bar", then we need to adjust the buffer.
                if (!currentArg.isEmpty()) {
                    currentArg.setLength(currentArg.length() - 1);
                }

                cleaned.add(currentArg.toString());

                currentArg = null;
                continue;
            }

            // if we haven't added this arg to the buffer, and we ARE building an argument
            // buffer, then append it with a preceding space...again, not sure what else to
            // do other than collapse whitespace.
            // NOTE: The case of a trailing quote is handled by nullifying the arg buffer.
            if (!addedToBuffer) {
                if (currentArg != null) {
                    currentArg.append(' ').append(arg);
                } else {
                    cleaned.add(arg);
                }
            }
        }

        if (currentArg != null) {
            cleaned.add(currentArg.toString());
        }

        int cleanedSz = cleaned.size();

        String[] cleanArgs;

        if (cleanedSz == 0) {
            cleanArgs = args;
        } else {
            cleanArgs = cleaned.toArray(new String[0]);
        }

        return cleanArgs;
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -



