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 * http://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.configuration.builders;
20
21 import java.util.Objects;
22
23 import org.apache.commons.lang3.StringUtils;
24 import org.apache.rat.ConfigurationException;
25 import org.apache.rat.analysis.matchers.SPDXMatcherFactory;
26 import org.apache.rat.config.parameters.MatcherBuilder;
27
28 /**
29 * A builder for SPDX matchers.
30 */
31 @MatcherBuilder(SPDXMatcherFactory.Match.class)
32 public class SpdxBuilder extends AbstractBuilder {
33 /** The SPDX name */
34 private String name;
35
36 /**
37 * Sets the name for the SPDX matcher. This is the same as the identifier in the SPDX license list.
38 *
39 * @param name The text that follows the colon ':' in the SPDX tag.
40 * @return this builder.
41 * @see <a href="https://spdx.org/licenses/">SPDX license list</a>
42 */
43 public SpdxBuilder setName(final String name) {
44 Objects.requireNonNull(name, "SPDX name must not be null");
45 this.name = name;
46 super.setId("SPDX:" + name);
47 return this;
48 }
49
50 /**
51 * Set the id for the matcher.
52 *
53 * @param id the id to use.
54 * @return this builder.
55 */
56 @Override
57 public AbstractBuilder setId(final String id) {
58 if (StringUtils.isNotBlank(id)) {
59 throw new ConfigurationException("'id' is not supported for SPDX matchers. "
60 + "SPXD matchers always have 'SPDX:<name>' as their id");
61 }
62 return this;
63 }
64
65 @Override
66 public SPDXMatcherFactory.Match build() {
67 return SPDXMatcherFactory.INSTANCE.create(name);
68 }
69
70 @Override
71 public String toString() {
72 return "SpdxBuilder: " + name;
73 }
74 }