in plugins/license-headers/src/main/java/co/elastic/gradle/license_headers/CheckLicenseHeadersTask.java [54:80]
public void doCheck() throws IOException {
if (getConfigs().get().isEmpty()) {
throw new GradleException("No license header configurations defined, use `licenseHeaders { checkAll() }` or `licenseHeaders { matching(...) { }}`");
}
for (LicenseHeaderConfig c : getConfigs().get()) {
final String[] expectedHeader = Files.readAllLines(RegularFileUtils.toPath(c.getHeaderFile())).toArray(String[]::new);
Path projectDir = getProjectLayout().getProjectDirectory().getAsFile().toPath();
final List<File> files = c.getFiles().get();
files.forEach(f -> getLogger().info("Checking {}", f));
getLogger().lifecycle("Scanning {} files for headers", files.size());
if (files.isEmpty()) {
throw new GradleException("Nothing to scan");
}
final Map<Path, ViolationReason> brokenFiles = LicenseCheckUtils.nonCompliantFilesWithReason(projectDir, expectedHeader, files);
if (!brokenFiles.isEmpty()) {
throw new GradleException("Incorrect header:\n" +
brokenFiles.entrySet().stream()
.map(entry -> projectDir.relativize(entry.getKey()) + " : " + entry.getValue().reason())
.collect(Collectors.joining("\n"))
);
}
}
Files.writeString(RegularFileUtils.toPath(getMarkerFile()), "Header is present in all files");
}