*/
private String computeAndSaveSHA(File deploymentDirectory) {
String sha = null;
try {
if (deploymentDirectory.isDirectory()) {
MessageDigestGenerator messageDigest = new MessageDigestGenerator(MessageDigestGenerator.SHA_256);
Stack<File> unvisitedFolders = new Stack<File>();
unvisitedFolders.add(deploymentDirectory);
while (!unvisitedFolders.empty()) {
File[] files = unvisitedFolders.pop().listFiles();
Arrays.sort(files, new Comparator<File>() {
public int compare(File f1, File f2) {
try {
return f1.getCanonicalPath().compareTo(f2.getCanonicalPath());
} catch (IOException e) {
//do nothing if the sort fails at this point
}
return 0;
}
});
for (File file : files) {
if (file.isDirectory()) {
unvisitedFolders.add(file);
} else {
FileInputStream inputStream = null;
try {
inputStream = new FileInputStream(file);
messageDigest.add(inputStream);
} finally {
if (inputStream != null) {
inputStream.close();
}
}
}
}
}
sha = messageDigest.getDigestString();
writeSHAToManifest(deploymentDirectory, sha);
}
} catch (IOException e) {
throw new RuntimeException("Error creating artifact for contentFile: " + deploymentDirectory, e);
}