1 /*
2 * Licensed to the Apache Software Foundation (ASF) under one
3 * or more contributor license agreements. See the NOTICE file
4 * distributed with this work for additional information
5 * regarding copyright ownership. The ASF licenses this file
6 * to you under the Apache License, Version 2.0 (the
7 * "License"); you may not use this file except in compliance
8 * with the License. You may obtain a copy of the License at
9 *
10 * https://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing,
13 * software distributed under the License is distributed on an
14 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 * KIND, either express or implied. See the License for the
16 * specific language governing permissions and limitations
17 * under the License.
18 */
19 package org.apache.rat.documentation.options;
20
21 import java.util.HashMap;
22 import java.util.Map;
23 import java.util.Objects;
24 import java.util.TreeMap;
25
26 import org.apache.commons.cli.Option;
27 import org.apache.commons.lang3.StringUtils;
28 import org.apache.rat.commandline.Arg;
29 import org.apache.rat.ui.UIOptionCollection;
30
31 /**
32 * The collection of MavenOptions equivalent to the CLI options
33 * with any unsupported options removed.
34 */
35 public final class MavenOptionCollection extends UIOptionCollection<MavenOption> {
36 /**
37 * Mapping of standard name to non-conflicting name.
38 */
39 private static final Map<String, String> RENAME_MAP;
40
41 static {
42 Map<String, String> map = new HashMap<>();
43 map.put("addLicense", "add-license");
44 RENAME_MAP = map;
45 }
46
47 /**
48 * Gets the map of renamed Options indexed by original option name.
49 * @return the map of renamed Options indexed by original option name.
50 */
51 public static Map<String, String> getRenameMap() {
52 return new TreeMap<>(RENAME_MAP);
53 }
54
55 /**
56 * Create an instance.
57 */
58 public MavenOptionCollection() {
59 super(new Builder());
60 }
61
62 @Override
63 public String rename(final Option option) {
64 String key = super.rename(option);
65 return StringUtils.defaultIfEmpty(RENAME_MAP.get(key), key);
66 }
67
68 /**
69 * The Builder for the MavenOptionCollection.
70 */
71 public static final class Builder extends UIOptionCollection.Builder<MavenOption, Builder> {
72 private Builder() {
73 super(MavenOption.MavenOptionBuilder::new);
74 Arg.getOptions().getOptions()
75 .stream().filter(o -> Objects.isNull(o.getLongOpt()))
76 .forEach(this::unsupported);
77 unsupported(Arg.DIR).unsupported(Arg.LOG_LEVEL);
78 }
79 }
80 }