in convert/src/convert/CategorizeLicenses.java [43:105]
public static void main(String[] args) throws IOException {
if (args.length != 2) {
System.err.println("Use: CategorizeLicenses <source-directory> <target-directory>");
return ;
}
Path root = Paths.get(args[0]);
int[] recognizedCount = new int[1];
Map<String, List<String>> licenses = new HashMap<>();
Map<String, List<String>> paragraphs = new HashMap<>();
Set<String> noCDDL = new HashSet<>();
Set<String> cddlNotRecognized = new HashSet<>();
Files.find(root, Integer.MAX_VALUE, (p, attr) -> attr.isRegularFile())
.forEach(p -> {
try {
String path = root.relativize(p).toString();
String code = new String(Files.readAllBytes(p));
if (code.contains("CDDL")) {
Description lic = snipUnifiedLicenseOrNull(code, p);
if (lic != null) {
recognizedCount[0]++;
licenses.computeIfAbsent(lic.header, l -> new ArrayList<>()).add(path);
for (String par : lic.header.split("\n")) {
paragraphs.computeIfAbsent(par, l -> new ArrayList<>()).add(path);
}
return ;
}
cddlNotRecognized.add(path);
return ;
}
noCDDL.add(path);
} catch (IOException ex) {
ex.printStackTrace();
}
});
Path target = Paths.get(args[1]);
int i = 0;
for (Map.Entry<String, List<String>> e : licenses.entrySet()) {
try (Writer w = Files.newBufferedWriter(target.resolve("lic" + i++))) {
w.write(e.getKey());
w.write("\n\n");
for (String file : e.getValue()) {
w.write(file);
w.write("\n");
}
}
}
System.err.println("files with recognized license headers: " + recognizedCount[0]);
System.err.println("licenses count: " + licenses.size());
System.err.println("paragraphs count: " + paragraphs.size());
System.err.println("cddl, unrecognized file: " + cddlNotRecognized.size());
System.err.println("no cddl license: " + noCDDL.size());
dump(licenses, target, "lic");
dump(paragraphs, target, "par");
dump(Collections.singletonMap("Files which contain string CDDL, but their comment structure is not (yet) recognized.", cddlNotRecognized), target, "have-cddl-not-recognized-filetype");
dump(Collections.singletonMap("Files which do not contain string CDDL", noCDDL), target, "do-not-have-cddl");
}