1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
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 String[] EMPTY_STRING_ARRAY = new String[0];
31
32 private static final Pattern[] EMPTY_PATTERN_ARRAY = new Pattern[0];
33
34 private static final String[] DEFAULT_PHRASES = {
35 "generated by Cayenne",
36 "Generated By:JJTree",
37 "Generated By:JavaCC",
38 "THIS FILE IS AUTOMATICALLY GENERATED",
39 "NOTE: this file is autogenerated by XBeans",
40 "This file was automatically generated by ",
41 "# WARNING: DO NOT EDIT OR DELETE THIS WORKSPACE FILE!",
42 "# Microsoft Developer Studio Generated NMAKE File",
43 "# Microsoft Developer Studio Generated Build File",
44 "Generated from configure.ac by autoheader",
45 "generated automatically by aclocal",
46 "build.xml generated by maven from project.xml",
47 "This file was generated by",
48 "This file has been automatically generated.",
49 "Automatically generated - do not modify!",
50 "Javadoc style sheet",
51 "SOURCE FILE GENERATATED",
52 "Generated by the Batik",
53 "this file is autogenerated",
54 "This class was autogenerated",
55 "Generated by Maven",
56 "Autogenerated by Thrift",
57 "DO NOT EDIT THIS FILE - it is machine generated",
58 "This class was generated by"};
59
60
61
62 private final Pattern[] linePatterns;
63 private final String[] phrases;
64
65 public GeneratedLicenseNotRequired() {
66 this(DEFAULT_PHRASES);
67 }
68
69 public GeneratedLicenseNotRequired(final Pattern[] linePatterns) {
70 this.linePatterns = linePatterns;
71 this.phrases = EMPTY_STRING_ARRAY;
72 }
73
74 public GeneratedLicenseNotRequired(final String[] lines) {
75 this.linePatterns = EMPTY_PATTERN_ARRAY;
76 this.phrases = lines;
77 }
78
79 public boolean match(Document subject, String line) throws RatHeaderAnalysisException {
80 boolean result = false;
81 for (Pattern pat : linePatterns) {
82 if (pat.matcher(line).matches()) {
83 result = true;
84 reportOnLicense(subject);
85 break;
86 }
87 }
88 for(String phrase : phrases) {
89 if (line.contains(phrase)) {
90 result = true;
91 reportOnLicense(subject);
92 break;
93 }
94 }
95 return result;
96 }
97
98 private void reportOnLicense(Document subject) {
99 subject.getMetaData().set(MetaData.RAT_LICENSE_FAMILY_CATEGORY_DATUM_GEN);
100 }
101
102 public void reset() {
103
104 }
105
106 }