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 org.apache.rat.analysis.RatHeaderAnalysisException;
22  import org.apache.rat.api.Document;
23  import org.apache.rat.api.MetaData;
24  
25  /**
26   * Matches an applied AL 2.0 License header, including a <em>required</em>
27   * initial copyright header line, conforming the <a href="http://apache.org/licenses/LICENSE-2.0.html#apply">template</a>
28   * from the AL 2.0 license itself.
29   *
30   * @since Rat 0.9
31   */
32  public class AppliedApacheSoftwareLicense20 extends CopyrightHeader {
33  
34      public static final String ASL20_LICENSE_DEFN
35              = "Licensed under the Apache License, Version 2.0 (the \"License\");\n"
36              + "you may not use this file except in compliance with the License.\n"
37              + "You may obtain a copy of the License at\n"
38              + "http://www.apache.org/licenses/LICENSE-2.0\n"
39              + "Unless required by applicable law or agreed to in writing, software\n"
40              + "distributed under the License is distributed on an \"AS IS\" BASIS,\n"
41              + "WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n"
42              + "See the License for the specific language governing permissions and\n"
43              + "limitations under the License.\n";
44  
45      private final FullTextMatchingLicense textMatcher;
46  
47      public AppliedApacheSoftwareLicense20() {
48          super(MetaData.RAT_LICENSE_FAMILY_CATEGORY_DATUM_ASL, MetaData.RAT_LICENSE_FAMILY_NAME_DATUM_APACHE_LICENSE_VERSION_2_0,"");
49          textMatcher = new FullTextMatchingLicense(MetaData.RAT_LICENSE_FAMILY_CATEGORY_DATUM_ASL, MetaData.RAT_LICENSE_FAMILY_NAME_DATUM_APACHE_LICENSE_VERSION_2_0,"",ASL20_LICENSE_DEFN);
50      }
51  
52      public AppliedApacheSoftwareLicense20(String copyrightOwner) {
53          this();
54          setCopyrightOwner(copyrightOwner);
55      }
56  
57      @Override
58      public boolean match(Document subject, String s) throws RatHeaderAnalysisException {
59          boolean result = false;
60          if (isCopyrightMatch()) {
61              return textMatcher.match(subject, s); // will report the match if it has occurred
62          }
63          else {
64              matchCopyright(s);
65          }
66          return result;
67      }
68  
69      @Override
70      public void reset() {
71          super.reset();
72          textMatcher.reset();
73      }
74  }