|
a/tool/run/licenses/GPL.java |
|
b/tool/run/licenses/GPL.java |
1 |
|
1 |
|
2 |
import java.io.File;
|
2 |
import java.io.File;
|
3 |
import java.util.Date;
|
3 |
import java.util.Date;
|
4 |
import script.License;
|
4 |
import script.License;
|
|
|
5 |
import script.LicenseID;
|
|
|
6 |
import utils.time;
|
5 |
|
7 |
|
6 |
/*
|
8 |
/*
|
7 |
* SPDXVersion: SPDX-1.1
|
9 |
* SPDXVersion: SPDX-1.1
|
8 |
* Creator: Person: Nuno Brito (nuno.brito@triplecheck.de)
|
10 |
* Creator: Person: Nuno Brito (nuno.brito@triplecheck.de)
|
9 |
* Creator: Organization: TripleCheck (contact@triplecheck.de)
|
11 |
* Creator: Organization: TripleCheck (contact@triplecheck.de)
|
|
... |
|
... |
32 |
* @author Nuno Brito, 16th of November 2013 in Darmstadt, Germany.
|
34 |
* @author Nuno Brito, 16th of November 2013 in Darmstadt, Germany.
|
33 |
* nuno.brito@triplecheck.de | http://nunobrito.eu
|
35 |
* nuno.brito@triplecheck.de | http://nunobrito.eu
|
34 |
*/
|
36 |
*/
|
35 |
public class GPL implements License {
|
37 |
public class GPL implements License {
|
36 |
|
38 |
|
37 |
// the list of id's that we can use to identify a license
|
39 |
// the initial trigger before we dig deeper into the source code
|
38 |
String[] list = {
|
40 |
String[] initialTrigger = {
|
39 |
"gnu general public license",
|
41 |
"gnu general public license",
|
40 |
"gnu gpl",
|
42 |
"gnu gpl",
|
41 |
"gplv2 or later"
|
43 |
"gpl"
|
42 |
};
|
44 |
};
|
|
|
45 |
|
|
|
46 |
// default values for our short identifier and full name
|
|
|
47 |
// private String shortIdentifier = "GPL";
|
|
|
48 |
// private String fullName = "GNU General Public License";
|
|
|
49 |
|
|
|
50 |
|
|
|
51 |
LicenseID gplv2_only = new LicenseID();
|
|
|
52 |
LicenseID gplv2_plus = new LicenseID();
|
|
|
53 |
|
|
|
54 |
// set the default ID when asked
|
|
|
55 |
LicenseID defaultLicense;
|
|
|
56 |
|
|
|
57 |
|
|
|
58 |
LicenseID[] pool = {
|
|
|
59 |
gplv2_only,
|
|
|
60 |
gplv2_plus
|
|
|
61 |
};
|
|
|
62 |
|
|
|
63 |
/**
|
|
|
64 |
* Constructor
|
|
|
65 |
*/
|
|
|
66 |
public GPL(){
|
|
|
67 |
// how can we identify the different license variants?
|
|
|
68 |
|
|
|
69 |
gplv2_only.shortID = "GPL-2.0";
|
|
|
70 |
gplv2_only.longID = "GNU General Public License v2.0 only";
|
|
|
71 |
gplv2_only.URL = "http://spdx.org/licenses/GPL-2.0";
|
|
|
72 |
gplv2_plus.datePublished = time.getDate(1991, 6, 01);
|
|
|
73 |
|
|
|
74 |
gplv2_plus.shortID = "GPL-2.0+";
|
|
|
75 |
gplv2_plus.longID = "GNU General Public License v2.0 or later";
|
|
|
76 |
gplv2_plus.URL = "http://spdx.org/licenses/GPL-2.0+";
|
|
|
77 |
gplv2_plus.datePublished = time.getDate(1991, 6, 01);
|
|
|
78 |
gplv2_plus.identifiers = new String[]{
|
|
|
79 |
"either version 2 of the License",
|
|
|
80 |
"Version 2, June 1991"
|
|
|
81 |
};
|
|
|
82 |
|
|
|
83 |
|
|
|
84 |
// set the default ID when asked
|
|
|
85 |
defaultLicense = gplv2_only;
|
|
|
86 |
}
|
|
|
87 |
|
43 |
|
88 |
|
44 |
/**
|
89 |
/**
|
45 |
* Verifies if the provided text applies to the triggers that
|
90 |
* Verifies if the provided text applies to the triggers that
|
46 |
* included on this license.
|
91 |
* included on this license.
|
47 |
* @param text Text to be analysed
|
92 |
* @param text Text to be analysed
|
48 |
* @return
|
93 |
* @return
|
49 |
*/
|
94 |
*/
|
50 |
@Override
|
95 |
@Override
|
51 |
public Boolean isApplicable(String text){
|
96 |
public Boolean isApplicable(String text){
|
52 |
// iterate all our ids
|
97 |
// iterate all our ids to see if something triggers further interest
|
53 |
for(String id : list){
|
98 |
for(String trigger : initialTrigger){
|
54 |
if(text.contains(id)){
|
99 |
if(text.contains(trigger)){
|
|
|
100 |
investigateLicense(text);
|
55 |
return true;
|
101 |
return true;
|
56 |
}
|
102 |
}
|
57 |
}
|
103 |
}
|
58 |
return false;
|
104 |
return false;
|
59 |
}
|
105 |
}
|
60 |
|
106 |
|
61 |
@Override
|
107 |
@Override
|
62 |
public Boolean isApplicable(File file) {
|
108 |
public Boolean isApplicable(File file) {
|
63 |
throw new UnsupportedOperationException("Not supported yet.");
|
109 |
return null;
|
64 |
}
|
110 |
}
|
65 |
|
111 |
|
66 |
@Override
|
112 |
@Override
|
67 |
public String getShortIdentifier() {
|
113 |
public String getShortIdentifier() {
|
68 |
return "GPL";
|
114 |
return defaultLicense.shortID;
|
69 |
}
|
115 |
}
|
70 |
|
116 |
|
71 |
@Override
|
117 |
@Override
|
72 |
public String getURL() {
|
118 |
public String getURL() {
|
73 |
return "http://spdx.org/licenses/GPL-1.0+#licenseText";
|
119 |
return defaultLicense.URL;
|
74 |
}
|
120 |
}
|
75 |
|
121 |
|
76 |
@Override
|
122 |
@Override
|
77 |
public Boolean supportsBinaries() {
|
123 |
public Boolean supportsBinaries() {
|
|
|
124 |
// are we able to detect a license text inside binary files?
|
78 |
return false;
|
125 |
return false;
|
79 |
}
|
126 |
}
|
80 |
|
127 |
|
81 |
@Override
|
128 |
@Override
|
82 |
public Boolean supportsTextFiles() {
|
129 |
public Boolean supportsTextFiles() {
|
|
... |
|
... |
84 |
}
|
131 |
}
|
85 |
|
132 |
|
86 |
|
133 |
|
87 |
@Override
|
134 |
@Override
|
88 |
public Date getDatePublished() {
|
135 |
public Date getDatePublished() {
|
89 |
return null; //utils.time.getDate(2004, 02, 01);
|
136 |
return defaultLicense.datePublished; //utils.time.getDate(2004, 02, 01);
|
90 |
}
|
137 |
}
|
91 |
|
138 |
|
92 |
@Override
|
139 |
@Override
|
93 |
public String getQuickSummary() {
|
140 |
public String getQuickSummary() {
|
94 |
return "";
|
141 |
return "";
|
|
... |
|
... |
100 |
}
|
147 |
}
|
101 |
|
148 |
|
102 |
|
149 |
|
103 |
@Override
|
150 |
@Override
|
104 |
public String getFullName() {
|
151 |
public String getFullName() {
|
105 |
return "GNU General Public License";
|
152 |
return defaultLicense.longID;
|
|
|
153 |
}
|
|
|
154 |
|
|
|
155 |
/**
|
|
|
156 |
* Looks better into the provided text and tries to determinate which
|
|
|
157 |
* specific type of license is being applied
|
|
|
158 |
* @param text
|
|
|
159 |
*/
|
|
|
160 |
private void investigateLicense(String text) {
|
|
|
161 |
for(LicenseID thisId: pool){
|
|
|
162 |
if(thisId.hasId(text)){
|
|
|
163 |
defaultLicense = thisId;
|
|
|
164 |
return;
|
|
|
165 |
}
|
|
|
166 |
}
|
|
|
167 |
|
|
|
168 |
|
106 |
}
|
169 |
}
|
107 |
|
170 |
|
108 |
} |
171 |
} |