diff --git a/apache-rat-core/pom.xml b/apache-rat-core/pom.xml index 4819f23bc..d4bf3b5df 100644 --- a/apache-rat-core/pom.xml +++ b/apache-rat-core/pom.xml @@ -176,6 +176,10 @@ + + com.github.spotbugs + spotbugs-annotations + org.apache.rat apache-rat-testdata diff --git a/apache-rat-core/src/main/java/org/apache/rat/OptionCollectionParser.java b/apache-rat-core/src/main/java/org/apache/rat/OptionCollectionParser.java new file mode 100644 index 000000000..21c343679 --- /dev/null +++ b/apache-rat-core/src/main/java/org/apache/rat/OptionCollectionParser.java @@ -0,0 +1,327 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one * + * or more contributor license agreements. See the NOTICE file * + * distributed with this work for additional information * + * regarding copyright ownership. The ASF licenses this file * + * to you under the Apache License, Version 2.0 (the * + * "License"); you may not use this file except in compliance * + * with the License. You may obtain a copy of the License at * + * * + * https://www.apache.org/licenses/LICENSE-2.0 * + * * + * Unless required by applicable law or agreed to in writing, * + * software distributed under the License is distributed on an * + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * + * KIND, either express or implied. See the License for the * + * specific language governing permissions and limitations * + * under the License. * + */ +package org.apache.rat; + +import java.io.File; +import java.io.IOException; +import java.io.PrintWriter; +import java.io.Serial; +import java.io.Serializable; +import java.nio.charset.StandardCharsets; +import java.util.Arrays; +import java.util.Comparator; +import java.util.function.Supplier; +import java.util.stream.Collectors; + +import org.apache.commons.cli.CommandLine; +import org.apache.commons.cli.DefaultParser; +import org.apache.commons.cli.Option; +import org.apache.commons.cli.Options; +import org.apache.commons.cli.ParseException; +import org.apache.rat.api.Document; +import org.apache.rat.commandline.Arg; +import org.apache.rat.commandline.ArgumentContext; +import org.apache.rat.commandline.StyleSheets; +import org.apache.rat.config.exclusion.StandardCollection; +import org.apache.rat.document.DocumentName; +import org.apache.rat.document.DocumentNameMatcher; +import org.apache.rat.document.FileDocument; +import org.apache.rat.help.Licenses; +import org.apache.rat.license.LicenseSetFactory; +import org.apache.rat.report.IReportable; +import org.apache.rat.report.claim.ClaimStatistic; +import org.apache.rat.ui.AbstractOptionCollection; +import org.apache.rat.utils.DefaultLog; +import org.apache.rat.utils.Log.Level; +import org.apache.rat.walker.ArchiveWalker; +import org.apache.rat.walker.DirectoryWalker; + +import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; + +import static java.lang.String.format; + +/** + * Uses the AbstractOptionCollection to parse the command line options. + * contains utility methods to ReportConfiguration from the options and an array of arguments. + */ +@SuppressFBWarnings("EI_EXPOSE_REP2") +public final class OptionCollectionParser { + /** The OptionCollection that we are working with */ + private final AbstractOptionCollection optionCollection; + + public OptionCollectionParser(final AbstractOptionCollection optionCollection) { + this.optionCollection = optionCollection; + } + + /** The Option comparator to sort the help */ + public static final Comparator