private static void revertFiles(final String configurationFileName) {
try {
JavaUtils.printToConsole("Loading configuration file...");
DeployerChangeSet changeset = new DeployerChangeSet(configurationFileName);
changeset.load();
if (0 == changeset.getSize()) {
JavaUtils.printToConsole("No changes found");
}
else {
final Document configurationXmlDocument = XmlUtils.loadXmlDocument(configurationFileName);
List<String> postProcessCallUrls = new ArrayList<String>();
List<DeployerCommandInfo> postProcessCallCommands = new ArrayList<DeployerCommandInfo>();
DeployerProjectUtils.loadPostProcessCallUrls(configurationXmlDocument, postProcessCallUrls);
DeployerProjectUtils.loadPostProcessCommands(configurationXmlDocument, postProcessCallCommands);
JavaUtils.printToConsole("Reverting changes...");
final List<String> changedFiles = new ArrayList<String>();
final List<File> filesToDelete = new ArrayList<File>();
for (int i = 0; i < changeset.getSize(); i++) {
final String changedFileName = changeset.getPath(i);
if (-1 == changedFiles.indexOf(changedFileName)) {
changedFiles.add(changedFileName);
}
final String backupFileName = changeset.getBackupPath(i);
JavaUtils.printToConsole(" reverting \"" + changedFileName + "\"...");
final File changedFile = new File(changedFileName);
if (StringUtils.isNullOrEmptyOrBlank(backupFileName)) {
filesToDelete.add(changedFile);
}
else {
final File backupFile = new File(backupFileName);
filesToDelete.add(backupFile);
FileUtils.copyFile(backupFile, changedFile);
}
}
changeset.delete();
for (File file : filesToDelete) {
if (file.exists()) {
file.delete();
}