in apache-rat-core/src/main/java/org/apache/rat/annotation/AbstractLicenseAppender.java [288:335]
public void append(final File document) throws IOException {
int type = getType(document);
if (type == TYPE_UNKNOWN) {
return;
}
boolean expectsHashPling = expectsHashPling(type);
boolean expectsAtEcho = expectsAtEcho(type);
boolean expectsPackage = expectsPackage(type);
boolean expectsXMLDecl = expectsXMLDecl(type);
boolean expectsPhpPI = expectsPhpPI(type);
boolean expectsMSVSSF = expectsMSVisualStudioSolutionFileHeader(type);
File newDocument = new File(document.getAbsolutePath() + ".new");
try (FileWriter writer = new FileWriter(newDocument)) {
if (!attachLicense(writer, document,
expectsHashPling, expectsAtEcho, expectsPackage,
expectsXMLDecl, expectsPhpPI, expectsMSVSSF)) {
// Java File without package, XML file without decl or PHP
// file without PI
// for Java just place the license at the front, for XML add
// an XML decl first - don't know how to handle PHP
if (expectsPackage || expectsXMLDecl) {
try (FileWriter writer2 = new FileWriter(newDocument)) {
if (expectsXMLDecl) {
writer2.write("<?xml version='1.0'?>");
writer2.write(LINE_SEP);
}
attachLicense(writer2, document,
false, false, false, false, false, false);
}
}
}
}
if (isOverwrite) {
try {
Path docPath = document.toPath();
boolean isExecutable = Files.isExecutable(docPath);
Files.move(newDocument.toPath(), docPath, StandardCopyOption.REPLACE_EXISTING);
if (isExecutable && !document.setExecutable(true)) {
DefaultLog.getInstance().warn(String.format("Could not set %s as executable.", document));
}
} catch (InvalidPathException | IOException e) {
DefaultLog.getInstance().error(String.format("Failed to rename new file to %s, Original file is unchanged.", document), e);
}
}
}