From cf0ef30fc7cf60c49eee6a447639dc1f62aa0807 Mon Sep 17 00:00:00 2001 From: Gethin James Date: Tue, 7 Feb 2012 16:57:13 +0000 Subject: [PATCH] FIXED : ALF-12533: When run with -directory, MMT should only backup the alfresco.war file once git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@33735 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261 --- .../module/tool/ModuleManagementTool.java | 48 ++++++++++++------- 1 file changed, 32 insertions(+), 16 deletions(-) diff --git a/source/java/org/alfresco/repo/module/tool/ModuleManagementTool.java b/source/java/org/alfresco/repo/module/tool/ModuleManagementTool.java index 8753c81e37..3936de9cb5 100644 --- a/source/java/org/alfresco/repo/module/tool/ModuleManagementTool.java +++ b/source/java/org/alfresco/repo/module/tool/ModuleManagementTool.java @@ -145,6 +145,10 @@ public class ModuleManagementTool java.io.File dir = new java.io.File(directoryLocation); if (dir.exists() == true) { + if (backupWAR) { + backupWar(warFileLocation,true); + backupWAR = false; //Set it to false so a backup doesn't occur again. + } installModules(dir, warFileLocation, preview, forceInstall,backupWAR); } else @@ -215,22 +219,7 @@ public class ModuleManagementTool { moduleDir.mkdir(); } - File backUpDir = new File(warFileLocation + BACKUP_DIR, DETECTOR_AMP_AND_WAR); - if (backUpDir.exists() == false) - { - backUpDir.mkdir(); - } - - // Make a backup of the war we are going to modify - if (backupWAR == true) - { - java.io.File warFile = new java.io.File(warFileLocation); - String backupLocation = warFileLocation + "-" + System.currentTimeMillis() + ".bak"; - java.io.File backup = new java.io.File(backupLocation); - copyFile(warFile, backup); - - outputMessage("WAR has been backed up to '" + backupLocation + "'"); - } + backupWar(warFileLocation, backupWAR); } // Get the details of the installing module @@ -382,6 +371,33 @@ public class ModuleManagementTool throw new ModuleManagementToolException("An IO error was encountered during deployment of the AEP into the WAR", exception); } } + + private void backupWar(String warFileLocation, boolean backupWAR) + { + + // Make a backup of the war we are going to modify + if (backupWAR == true) + { + File backUpDir = new File(warFileLocation + BACKUP_DIR, DETECTOR_AMP_AND_WAR); + if (backUpDir.exists() == false) + { + backUpDir.mkdir(); + } + java.io.File warFile = new java.io.File(warFileLocation); + String backupLocation = warFileLocation + "-" + System.currentTimeMillis() + ".bak"; + java.io.File backup = new java.io.File(backupLocation); + try + { + copyFile(warFile, backup); + } + catch (IOException exception) + { + throw new ModuleManagementToolException("An IO error was encountered when backing up the WAR", exception); + } + + outputMessage("WAR has been backed up to '" + backupLocation + "'"); + } + } /** * @return Returns the custom file mapping properties or null if they weren't overwritten