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.analysis.license;
20  
21  import java.util.Arrays;
22  
23  import org.apache.rat.DeprecationReporter;
24  import org.apache.rat.configuration.builders.AbstractBuilder;
25  import org.apache.rat.configuration.builders.AnyBuilder;
26  import org.apache.rat.configuration.builders.TextBuilder;
27  import org.apache.rat.license.ILicense;
28  
29  
30  /**
31   * @since Rat 0.8
32   * @deprecated Use new configuration options
33   */
34  @Deprecated // Since 0.16
35  @DeprecationReporter.Info(since = "0.16", forRemoval = true, use = "new configuration options")
36  public class SimplePatternBasedLicense  extends BaseLicense {
37      private String[] patterns;
38  
39  
40      public SimplePatternBasedLicense() {
41          DeprecationReporter.logDeprecated(SimplePatternBasedLicense.class);
42      }
43  
44      
45      public String[] getPatterns() {
46          return patterns;
47      }
48  
49      public void setPatterns(String[] pPatterns) {
50          patterns = pPatterns;
51      }
52  
53      private AbstractBuilder getMatcher() {
54          if (patterns.length == 1) {
55              return new TextBuilder().setSimpleText(patterns[0]);
56          } else {
57              AnyBuilder any = new AnyBuilder();
58              Arrays.stream(patterns).map(s -> new TextBuilder().setSimpleText(s)).forEach(any::addEnclosed);
59              return any;
60          }
61      }
62  
63      @Override
64      public ILicense.Builder getLicense() {
65          return ILicense.builder()
66          .setFamily(getLicenseFamilyCategory())
67          .setName(getLicenseFamilyName())
68          .setMatcher( getMatcher() )
69          .setNote(getNotes());
70      }
71  }