public boolean addComaSeparated()

in src/main/java/org/apache/maven/plugin/compiler/Options.java [174:258]


    public boolean addComaSeparated(
            final String option, String values, Collection<String> valids, UnaryOperator<String[]> filter) {
        if (values == null) {
            return false;
        }
        /*
         * Rebuild the comma-separated list of options with spaces removed, empty values omitted and case
         * changed to lower-case. The split list will be reused for diagnostic if the option is not accepted.
         */
        String[] split = values.split(",");
        int count = 0;
        for (String value : split) {
            value = value.strip();
            if (!value.isEmpty()) {
                split[count++] = value.toLowerCase(Locale.US);
            }
        }
        /*
         * If a filter is specified, replace the user-specified list by the filtered one.
         * The filtering may result in an empty list, which is interpreted as an option without value.
         * This is different than an absence of user-supplied values, which is interpreted as no option.
         * This subtle difference explains why the check for absence of values is done before filtering,
         * and is needed for making possible to replace "-g:all" by "-g" (because the "all" value is a
         * Maven addition).
         */
        if (count == 0) {
            return false;
        }
        if (filter != null) {
            if (count != split.length) {
                split = Arrays.copyOfRange(split, 0, count);
            }
            split = filter.apply(split);
            if (split == null) {
                return false;
            }
            count = split.length;
        }
        /*
         * Format the option (possibly with no values), then validate.
         */
        var sb = new StringBuilder(option);
        for (int i = 0; i < count; i++) {
            sb.append(i == 0 ? ':' : ',').append(split[i]);
        }
        String s = sb.toString();
        if (checkNumberOfArguments(s, 0, false)) {
            options.add(s);
            return true;
        }
        /*
         * A log message has been prepared in the `warning` field for saying that the option is not supported.
         * If a collection of valid options was provided, use it for identifying which option was invalid.
         */
        if (valids != null) {
            for (int i = 0; i < count; i++) {
                String value = split[i];
                if (!valids.contains(value)) {
                    sb.setLength(0);
                    sb.append(warning);
                    sb.setLength(sb.length() - 1); // Remove the trailing dot.
                    sb.append(", because the specified ")
                            .append(option)
                            .append(" value '")
                            .append(value)
                            .append("' is unexpected. Legal values are: ");
                    int j = 0;
                    for (String valid : valids) {
                        if (j++ != 0) {
                            sb.append(", ");
                            if (j == valids.size()) {
                                sb.append("and ");
                            }
                        }
                        sb.append('\'').append(valid).append('\'');
                    }
                    warning = sb.append('.').toString();
                    break;
                }
            }
        }
        logger.warn(warning);
        warning = null;
        return false;
    }