|
@@ -37,16 +37,21 @@ public class NoticeTask extends DefaultTask {
|
|
|
@OutputFile
|
|
|
File outputFile = new File(project.buildDir, "notices/${name}/NOTICE.txt")
|
|
|
|
|
|
- /** Configurations to inspect dependencies*/
|
|
|
- private List<Project> dependencies = new ArrayList<>()
|
|
|
+ /** Directories to include notices from */
|
|
|
+ private List<File> licensesDirs = new ArrayList<>()
|
|
|
|
|
|
public NoticeTask() {
|
|
|
description = 'Create a notice file from dependencies'
|
|
|
+ // Default licenses directory is ${projectDir}/licenses (if it exists)
|
|
|
+ File licensesDir = new File(project.projectDir, 'licenses')
|
|
|
+ if (licensesDir.exists()) {
|
|
|
+ licensesDirs.add(licensesDir)
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
- /** Add notices from licenses found in the given project. */
|
|
|
- public void dependencies(Project project) {
|
|
|
- dependencies.add(project)
|
|
|
+ /** Add notices from the specified directory. */
|
|
|
+ public void licensesDir(File licensesDir) {
|
|
|
+ licensesDirs.add(licensesDir)
|
|
|
}
|
|
|
|
|
|
@TaskAction
|
|
@@ -54,17 +59,29 @@ public class NoticeTask extends DefaultTask {
|
|
|
StringBuilder output = new StringBuilder()
|
|
|
output.append(inputFile.getText('UTF-8'))
|
|
|
output.append('\n\n')
|
|
|
- Set<String> seen = new HashSet<>()
|
|
|
- for (Project dep : dependencies) {
|
|
|
- File licensesDir = new File(dep.projectDir, 'licenses')
|
|
|
- if (licensesDir.exists() == false) continue
|
|
|
- licensesDir.eachFileMatch({ it ==~ /.*-NOTICE\.txt/ && seen.contains(it) == false}) { File file ->
|
|
|
+ // This is a map rather than a set so that the sort order is the 3rd
|
|
|
+ // party component names, unaffected by the full path to the various files
|
|
|
+ Map<String, File> seen = new TreeMap<>()
|
|
|
+ for (File licensesDir : licensesDirs) {
|
|
|
+ licensesDir.eachFileMatch({ it ==~ /.*-NOTICE\.txt/ }) { File file ->
|
|
|
String name = file.name.substring(0, file.name.length() - '-NOTICE.txt'.length())
|
|
|
- appendFile(file, name, 'NOTICE', output)
|
|
|
- appendFile(new File(file.parentFile, "${name}-LICENSE.txt"), name, 'LICENSE', output)
|
|
|
- seen.add(file.name)
|
|
|
+ if (seen.containsKey(name)) {
|
|
|
+ File prevFile = seen.get(name)
|
|
|
+ if (prevFile.text != file.text) {
|
|
|
+ throw new RuntimeException("Two different notices exist for dependency '" +
|
|
|
+ name + "': " + prevFile + " and " + file)
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ seen.put(name, file)
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
+ for (Map.Entry<String, File> entry : seen.entrySet()) {
|
|
|
+ String name = entry.getKey()
|
|
|
+ File file = entry.getValue()
|
|
|
+ appendFile(file, name, 'NOTICE', output)
|
|
|
+ appendFile(new File(file.parentFile, "${name}-LICENSE.txt"), name, 'LICENSE', output)
|
|
|
+ }
|
|
|
outputFile.setText(output.toString(), 'UTF-8')
|
|
|
}
|
|
|
|