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.generation;
20  
21  import java.util.regex.Pattern;
22  
23  import org.apache.rat.analysis.IHeaderMatcher;
24  import org.apache.rat.analysis.RatHeaderAnalysisException;
25  import org.apache.rat.api.Document;
26  import org.apache.rat.api.MetaData;
27  
28  public class GeneratedLicenseNotRequired implements IHeaderMatcher {
29  
30      private static final Pattern[] DEFAULT_PATTERNS = {Pattern.compile(".*generated by Cayenne.*"),
31          Pattern.compile(".*Generated By:JJTree.*"),
32          Pattern.compile(".*Generated By:JavaCC.*"),
33          Pattern.compile(".*THIS FILE IS AUTOMATICALLY GENERATED.*"),
34          Pattern.compile(".*NOTE: this file is autogenerated by XBeans.*"),
35          Pattern.compile(".*This file was automatically generated by .*"),
36          Pattern.compile(".*# WARNING: DO NOT EDIT OR DELETE THIS WORKSPACE FILE!.*"),
37          Pattern.compile(".*# Microsoft Developer Studio Generated NMAKE File.*"),
38          Pattern.compile(".*# Microsoft Developer Studio Generated Build File.*"),
39          Pattern.compile(".*Generated from configure.ac by autoheader.*"),
40          Pattern.compile(".*generated automatically by aclocal.*"),
41          Pattern.compile(".*build.xml generated by maven from project.xml.*"),
42          Pattern.compile(".*This file was generated by.*"),
43          Pattern.compile(".*This file has been automatically generated..*"),
44          Pattern.compile(".*Automatically generated - do not modify!.*"),
45          Pattern.compile(".*Javadoc style sheet.*"),
46          Pattern.compile(".*SOURCE FILE GENERATATED.*"),
47          Pattern.compile(".*Generated by the Batik.*"),
48          Pattern.compile(".*this file is autogenerated.*"),
49          Pattern.compile(".*This class was autogenerated.*"),
50          Pattern.compile(".*Generated by Maven.*"),
51          Pattern.compile(".*This class was generated by.*")};
52      
53      
54      private final Pattern[] linePatterns;
55      private final int numberOfPatterns;
56      
57      public GeneratedLicenseNotRequired() {
58          this(DEFAULT_PATTERNS);
59      }
60      
61      public GeneratedLicenseNotRequired(final Pattern[] linePatterns) {
62          this.linePatterns = linePatterns;
63          this.numberOfPatterns = linePatterns.length;
64      }
65  
66      public boolean match(Document subject, String line) throws RatHeaderAnalysisException {
67          boolean result = false;
68          for (int i=0;i<numberOfPatterns;i++) {
69              if (linePatterns[i].matcher(line).matches()) {
70                  result = true;
71                  reportOnLicense(subject);
72                  break;
73              }
74          }
75          return result;
76      }
77  
78      private void reportOnLicense(Document subject) throws RatHeaderAnalysisException {
79          subject.getMetaData().set(MetaData.RAT_LICENSE_FAMILY_CATEGORY_DATUM_GEN);
80      }
81  
82      public void reset() {
83          // stateless
84      }
85  
86  }