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