1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.rat.testhelpers;
20
21 import org.apache.commons.lang3.StringUtils;
22 import org.apache.rat.analysis.IHeaderMatcher;
23 import org.apache.rat.license.ILicense;
24 import org.apache.rat.license.ILicenseFamily;
25
26
27
28
29 public class TestingLicense implements ILicense {
30
31 private final ILicenseFamily family;
32 private IHeaderMatcher matcher;
33 private String derivedFrom;
34 private String notes;
35 private String name;
36 private String id;
37
38
39
40
41
42
43 public TestingLicense() {
44 this("DfltTst", new TestingMatcher());
45 }
46
47
48
49
50
51
52 public TestingLicense(String id) {
53 this(id, new TestingMatcher());
54 }
55
56
57
58
59
60
61 public TestingLicense(String id, IHeaderMatcher matcher) {
62 this(matcher, ILicenseFamily.builder().setLicenseFamilyCategory(id)
63 .setLicenseFamilyName("TestingLicense: " + id).build());
64 }
65
66
67
68
69
70
71 public TestingLicense(IHeaderMatcher matcher, ILicenseFamily family) {
72 this.family = family;
73 this.matcher = matcher;
74 this.derivedFrom = null;
75 this.notes = null;
76 }
77
78
79
80
81
82
83 public TestingLicense(ILicenseFamily family) {
84 this(new TestingMatcher(), family );
85 }
86
87 @Override
88 public String toString() {
89 return family.toString();
90 }
91
92
93
94
95
96 public ILicenseFamily getFamily() {
97 return family;
98 }
99
100
101
102
103
104 public IHeaderMatcher getMatcher() {
105 return matcher;
106 }
107
108
109
110
111
112 public void setDerivedFrom(String derivedFrom) {
113 this.derivedFrom = derivedFrom;
114 }
115
116
117
118
119
120 public void setName(String name) {
121 this.name = name;
122 }
123
124 public void setId(String id) {
125 this.id = id;
126 }
127 @Override
128 public String getId() {
129 return StringUtils.defaultIfBlank(id, family.getFamilyCategory().trim());
130 }
131
132 @Override
133 public void reset() {
134 matcher.reset();
135 }
136
137 @Override
138 public State matches(String line) {
139 return matcher.matches(line);
140 }
141
142 @Override
143 public State finalizeState() {
144 return matcher.finalizeState();
145 }
146
147 @Override
148 public State currentState() {
149 return matcher.currentState();
150 }
151
152 @Override
153 public ILicenseFamily getLicenseFamily() {
154 return family;
155 }
156
157 @Override
158 public int compareTo(ILicense other) {
159 return ILicense.getComparator().compare(this, other);
160 }
161
162 @Override
163 public String getNotes() {
164 return notes;
165 }
166
167 @Override
168 public String getName() {
169 return StringUtils.defaultIfBlank(name, family.getFamilyName());
170 }
171
172 @Override
173 public String derivedFrom() {
174 return derivedFrom;
175 }
176
177 }