newFileHashCodeMap.put(zipPath, compressedFileHashcode);
}
}
// copy all raw files
StreamCopyDigest copyDigester = new StreamCopyDigest();
for (Map.Entry<File, File> rawFile : this.deploymentData.getRawFiles().entrySet()) {
// determine where the original file is and where it needs to go
File currentLocationFile = rawFile.getKey();
File newLocationFile = rawFile.getValue();
String newLocationPath = rawFile.getValue().getPath();
newLocationPath = newFileHashCodeMap.convertPath(newLocationPath);
if (currentFilesToLeaveAlone != null && currentFilesToLeaveAlone.containsKey(newLocationPath)) {
continue;
}
if (!newLocationFile.isAbsolute()) {
newLocationFile = new File(this.deploymentData.getDestinationDir(), newLocationFile.getPath());
}
if (!dryRun) {
File newLocationParentDir = newLocationFile.getParentFile();
newLocationParentDir.mkdirs();
if (!newLocationParentDir.isDirectory()) {
throw new Exception("Failed to create new parent directory for raw file [" + newLocationFile + "]");
}
}
String hashcode;
boolean realize = false;
if (this.deploymentData.getRawFilesToRealize() != null) {
realize = this.deploymentData.getRawFilesToRealize().contains(currentLocationFile);
}
if (realize) {
debug("Realizing file [", currentLocationFile, "] to [", newLocationFile, "]. dryRun=", dryRun);
// this entry needs to be realized, do it now in-memory (we assume realizable files will not be large)
// note: tempateEngine will never be null if we got here
FileInputStream in = new FileInputStream(currentLocationFile);
byte[] rawFileContent = StreamUtil.slurp(in);
String content = this.deploymentData.getTemplateEngine().replaceTokens(new String(rawFileContent));
if (diff != null) {
diff.addRealizedFile(newLocationPath, content);
}
// now write the realized content to the filesystem
byte[] bytes = content.getBytes();
if (!dryRun) {
BufferedOutputStream out = new BufferedOutputStream(new FileOutputStream(newLocationFile));
try {
out.write(bytes);
} finally {
out.close();
}
}
MessageDigestGenerator hashcodeGenerator = copyDigester.getMessageDigestGenerator();
hashcodeGenerator.add(bytes);
hashcode = hashcodeGenerator.getDigestString();
} else {
debug("Copying raw file [", currentLocationFile, "] to [", newLocationFile, "]. dryRun=", dryRun);
FileInputStream in = new FileInputStream(currentLocationFile);
try {
if (!dryRun) {
BufferedOutputStream out = new BufferedOutputStream(new FileOutputStream(newLocationFile));
try {
hashcode = copyDigester.copyAndCalculateHashcode(in, out);
} finally {
out.close();
}
} else {
hashcode = MessageDigestGenerator.getDigestString(in);