19 #include <boost/tokenizer.hpp> 20 #include "ninkawrapper.hpp" 23 string scanFileWithNinka(
const State& state,
const fo::File& file)
30 if (!(in = popen(command.c_str(),
"r")))
32 cout <<
"could not execute ninka command: " << command << endl;
36 while (fgets(buffer,
sizeof(buffer), in) != NULL)
43 cout <<
"could not execute ninka command: " << command << endl;
50 vector<string> extractLicensesFromNinkaResult(
string ninkaResult)
52 string licensePart = extractLicensePartFromNinkaResult(ninkaResult);
53 return splitLicensePart(licensePart);
57 string extractLicensePartFromNinkaResult(
string ninkaResult)
59 string delimiters =
";\r\n";
61 size_t first = ninkaResult.find_first_of(delimiters);
62 size_t last = ninkaResult.find_first_of(delimiters, first + 1);
64 return ninkaResult.substr(first + 1, last - 1 - first);
67 vector<string> splitLicensePart(
string licensePart)
69 typedef boost::tokenizer<boost::char_separator<char>> tokenizer;
70 boost::char_separator<char> separator(
",");
71 tokenizer tokens(licensePart, separator);
73 vector<string> licenses;
75 for (tokenizer::iterator iter = tokens.begin(); iter != tokens.end(); ++iter)
77 licenses.push_back(*iter);
83 vector<LicenseMatch> createMatches(vector<string> ninkaLicenseNames)
85 vector<LicenseMatch> matches;
86 for (vector<string>::const_iterator it = ninkaLicenseNames.begin(); it != ninkaLicenseNames.end(); ++it)
88 const string& ninkaLicenseName = *it;
89 if(isLicenseCollection(ninkaLicenseName,matches))
93 string fossologyLicenseName = mapLicenseFromNinkaToFossology(ninkaLicenseName);
94 unsigned percentage = (ninkaLicenseName.compare(
"NONE") == 0 || ninkaLicenseName.compare(
"UNKNOWN") == 0) ? 0 : 100;
96 matches.push_back(match);
101 string mapLicenseFromNinkaToFossology(
string name)
103 if (name.compare(
"NONE") == 0)
return string(
"No_license_found");
104 if (name.compare(
"UNKNOWN") == 0)
return string(
"UnclassifiedLicense");
105 if (name.compare(
"spdxMIT") ==0 )
return string(
"MIT");
106 if (name.compare(
"Apachev1.0") == 0)
return string(
"Apache-1.0");
107 if (name.compare(
"Apachev2") == 0
108 || name.compare(
"Apache-2") == 0)
return string(
"Apache-2.0");
109 if (name.compare(
"GPLv1+") == 0)
return string(
"GPL-1.0+");
110 if (name.compare(
"GPLv2") == 0)
return string(
"GPL-2.0");
111 if (name.compare(
"GPLv2+") == 0)
return string(
"GPL-2.0+");
112 if (name.compare(
"GPLv3") == 0)
return string(
"GPL-3.0");
113 if (name.compare(
"GPLv3+") == 0)
return string(
"GPL-3.0+");
114 if (name.compare(
"LGPLv2") == 0)
return string(
"LGPL-2.0");
115 if (name.compare(
"LGPLv2+") == 0)
return string(
"LGPL-2.0+");
116 if (name.compare(
"LGPLv2_1") == 0
117 || name.compare(
"LGPLv2.1") == 0)
return string(
"LGPL-2.1");
118 if (name.compare(
"LGPLv2_1+") == 0)
return string(
"LGPL-2.1+");
119 if (name.compare(
"LGPLv3") == 0)
return string(
"LGPL-3.0");
120 if (name.compare(
"LGPLv3+") == 0)
return string(
"LGPL-3.0+");
121 if (name.compare(
"GPLnoVersion") == 0)
return string(
"GPL");
122 if (name.compare(
"LesserGPLnoVersion") == 0
123 || name.compare(
"LibraryGPLnoVersion")==0)
return string(
"LGPL");
124 if (name.compare(
"intelBSDLicense") == 0)
return string(
"Intel-EULA");
125 if (name.compare(
"spdxSleepyCat") == 0
126 || name.compare(
"SleepyCat") == 0)
return string(
"Sleepycat");
127 if (name.compare(
"spdxBSD2") == 0
128 || name.compare(
"BSD2") == 0)
return string(
"BSD-2-Clause");
129 if (name.compare(
"spdxBSD3") == 0
130 || name.compare(
"BSD3") == 0)
return string(
"BSD-3-Clause");
131 if (name.compare(
"BSD3") == 0)
return string(
"BSD-4-Clause");
132 if (name.compare(
"spdxMIT") == 0)
return string(
"MIT");
133 if (name.compare(
"ZLIB") == 0)
return string(
"Zlib");
134 if (name.compare(
"openSSL") == 0
135 || name.compare(
"openSSLvar1") ==0
136 || name.compare(
"openSSLvar3") ==0)
return string(
"OpenSSL");
137 if (name.compare(
"QPLt") == 0)
return string(
"QT(Commercial)");
138 if (name.compare(
"Cecill") == 0)
return string(
"CECILL");
139 if (name.compare(
"QPLv1") == 0)
return string(
"QPL-1.0");
140 if (name.compare(
"MPLv1_1") == 0)
return string(
"MPL-1.1");
141 if (name.compare(
"NPLv1_1") == 0)
return string(
"NPL-1.1");
142 if (name.compare(
"MPLv1_0") == 0)
return string(
"MPL-1.0");
143 if (name.compare(
"NPLv1_0") == 0)
return string(
"NPL-1.0");
144 if (name.compare(
"MPLv2") == 0)
return string(
"MPL-2.0");
145 if (name.compare(
"MITVariant") == 0)
return string(
"MIT-style");
146 if (name.compare(
"EPLv1") == 0)
return string(
"EPL-1.0");
147 if (name.compare(
"CDDLic") == 0)
return string(
"CDDL");
148 if (name.compare(
"CDDLicV1") == 0)
return string(
"CDDL-1.0");
149 if (name.compare(
"publicDomain") == 0)
return string(
"Public-domain");
150 if (name.compare(
"ClassPathExceptionGPLv2") == 0)
return string(
"GPL-2.0-with-classpath-exception");
151 if (name.compare(
"CPLv1") == 0)
return string(
"CPL-1.0");
152 if (name.compare(
"CPLv0.5") == 0)
return string(
"CPL-0.5");
153 if (name.compare(
"SeeFile") == 0)
return string(
"See-file");
154 if (name.compare(
"LibGCJLic") == 0)
return string(
"LIBGCJ");
155 if (name.compare(
"W3CLic") == 0)
return string(
"W3C");
156 if (name.compare(
"IBMv1") == 0)
return string(
"IPL-1.0");
157 if (name.compare(
"ArtisticLicensev1") == 0)
return string(
"Artistic-1.0");
158 if (name.compare(
"MX4JLicensev1") == 0)
return string(
"MX4J-1.0");
159 if (name.compare(
"phpLicV3.01") == 0)
return string(
"PHP-3.01");
160 if (name.compare(
"postgresql") == 0
161 || name.compare(
"postgresqlRef") == 0)
return string(
"PostgreSQL");
162 if (name.compare(
"FSFUnlimited") == 0)
return string(
"FSF");
167 bool isLicenseCollection(
string name, vector<LicenseMatch>& matches)
169 if (name.compare(
"spdxBSD4") == 0)
171 matches.push_back(
LicenseMatch(
string(
"BSD-4-Clause"), 50));
172 matches.push_back(
LicenseMatch(
string(
"BSD-4-Clause-UC"), 50));
175 if (name.compare(
"GPL2orBSD3") == 0)
177 matches.push_back(
LicenseMatch(
string(
"BSD-3-Clause"), 50));
181 if (name.compare(
"LGPLv2orv3") == 0)
183 matches.push_back(
LicenseMatch(
string(
"LGPL-2.0"), 50));
184 matches.push_back(
LicenseMatch(
string(
"LGPL-3.0"), 50));
187 if (name.compare(
"LGPLv2_1orv3") == 0)
189 matches.push_back(
LicenseMatch(
string(
"LGPL-2.1"), 50));
190 matches.push_back(
LicenseMatch(
string(
"LGPL-3.0"), 50));
193 if (name.compare(
"LGPLv2+MISTAKE") == 0)
195 matches.push_back(
LicenseMatch(
string(
"LGPL-2.1+"), 50));
196 matches.push_back(
LicenseMatch(
string(
"LGPL-2.0+"), 50));
199 if (name.compare(
"LGPLv2MISTAKE") == 0)
201 matches.push_back(
LicenseMatch(
string(
"LGPL-2.1"), 50));
202 matches.push_back(
LicenseMatch(
string(
"LGPL-2.0"), 50));
205 if (name.compare(
"GPLv1orArtistic") == 0)
208 matches.push_back(
LicenseMatch(
string(
"Artistic-1.0"), 25));
209 matches.push_back(
LicenseMatch(
string(
"Artistic-2.0"), 25));
212 if (name.compare(
"GPL2orOpenIB") == 0)
215 matches.push_back(
LicenseMatch(
string(
"BSD-2-Clause"), 50));
218 if (name.compare(
"CDDLv1orGPLv2") == 0)
220 matches.push_back(
LicenseMatch(
string(
"CDDL-1.0"), 50));
224 if (name.compare(
"Apache-2orLGPLgeneric") == 0)
226 matches.push_back(
LicenseMatch(
string(
"Apache-2.0"), 50));
230 if (name.compare(
"orLGPLVer2.1") == 0)
232 matches.push_back(
LicenseMatch(
string(
"QT(Commercial)"), 50));
233 matches.push_back(
LicenseMatch(
string(
"LGPL-2.1"), 50));
236 if (name.compare(
"orLGPLVer2") == 0)
238 matches.push_back(
LicenseMatch(
string(
"QT(Commercial)"), 50));
239 matches.push_back(
LicenseMatch(
string(
"LGPL-2.0"), 50));
242 if (name.compare(
"orGPLv3") == 0)
244 matches.push_back(
LicenseMatch(
string(
"QT(Commercial)"), 50));
248 if (name.compare(
"CDDLv1orGPLv2") == 0)
250 matches.push_back(
LicenseMatch(
string(
"CDDL-1.0"), 50));
254 if (name.compare(
"CDDLorGPLv2") == 0)
260 if (name.compare(
"MPLGPL2orLGPLv2_1") == 0)
264 matches.push_back(
LicenseMatch(
string(
"LGPL-2.1"), 34));
267 if (name.compare(
"MPL1_1andLGPLv2_1") == 0)
273 if (name.compare(
"MPL_LGPLsee") == 0)
279 if (name.compare(
"MITX11BSDvar") == 0)
283 matches.push_back(
LicenseMatch(
string(
"BSD-style"), 34));
286 if (name.compare(
"MITCMU") == 0 || name.compare(
"MITCMUvar2") == 0 || name.compare(
"MITCMUvar3") == 0)
292 if (name.compare(
"MITX11") == 0 || name.compare(
"MITX11noNotice") == 0 || name.compare(
"MITX11simple") == 0)
298 if (name.compare(
"MITandGPL") == 0)
304 if (name.compare(
"BisonException") == 0)
306 matches.push_back(
LicenseMatch(
string(
"GPL-2.0-with-bison-exception"), 50));
307 matches.push_back(
LicenseMatch(
string(
"GPL-3.0-with-bison-exception"), 50));
310 if (name.compare(
"ClassPathException") == 0)
312 matches.push_back(
LicenseMatch(
string(
"GPL-2.0-with-classpath-exception"), 30));
313 matches.push_back(
LicenseMatch(
string(
"GPL-2.0+-with-classpath-exception"), 30));
314 matches.push_back(
LicenseMatch(
string(
"GPL-3.0-with-classpath-exception"), 40));
317 if (name.compare(
"autoConfException") == 0)
319 matches.push_back(
LicenseMatch(
string(
"GPL-2.0-with-autoconf-exception"), 50));
320 matches.push_back(
LicenseMatch(
string(
"GPL-3.0-with-autoconf-exception"), 50));
323 if (name.compare(
"CPLv1orGPLv2+orLGPLv2+") == 0)
326 matches.push_back(
LicenseMatch(
string(
"GPL-2.0+"), 33));
327 matches.push_back(
LicenseMatch(
string(
"LGPL-2.0+"), 33));
330 if (name.compare(
"GPLVer2or3KDE+") == 0)
332 matches.push_back(
LicenseMatch(
string(
"GPL-2.0+-KDE-exception"), 50));
333 matches.push_back(
LicenseMatch(
string(
"GPL-3.0+-KDE-exception"), 50));
336 if (name.compare(
"LGPLVer2.1or3KDE+") == 0)
338 matches.push_back(
LicenseMatch(
string(
"LGPL-2.1+-KDE-exception"), 50));
339 matches.push_back(
LicenseMatch(
string(
"LGPL-3.0+-KDE-exception"), 50));
342 if (name.compare(
"GPLv2orLGPLv2.1") == 0)
345 matches.push_back(
LicenseMatch(
string(
"LGPL-2.1"), 50));
348 if (name.compare(
"GPLv2+orLGPLv2.1") == 0)
350 matches.push_back(
LicenseMatch(
string(
"GPL-2.0+"), 50));
351 matches.push_back(
LicenseMatch(
string(
"LGPL-2.1"), 50));
void bail(int exitval)
Disconnect with scheduler returning an error code and exit.
Store the results of a regex match.
Class to handle file related operations.
char buffer[2048]
The last thing received from the scheduler.
const std::string & getFileName() const