Merged HEAD-BUG-FIX (5.1/Cloud) to HEAD (5.1/Cloud)

106705: Made findManifest and backup public so they can be reused. UTF-77


git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@106796 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Alan Davis
2015-06-23 07:07:20 +00:00
parent 6e3fb93759
commit 70f7e4cf7c
5 changed files with 105 additions and 37 deletions

View File

@@ -397,7 +397,7 @@ public class ModuleManagementTool implements LogOutput
* @see ModuleManagementTool#installModule(String, String, boolean, boolean, boolean)
*
* @param warFile the location of the AMP file to be installed
* @param warFileLocation the location of the WAR file into which the AMP file is to be installed
* @param backupWAR true if you want it to perform the backup
*/
private void backupWar(TFile warFile, boolean backupWAR) throws IOException
{
@@ -405,24 +405,7 @@ public class ModuleManagementTool implements LogOutput
// Make a backup of the war we are going to modify
if (backupWAR == true)
{
String backupLocation = warFile.getAbsolutePath()+"-" + System.currentTimeMillis() + ".bak";
if (warFile.isArchive())
{
outputVerboseMessage("Backing up WAR file...");
TFile source = new TFile(warFile.getAbsolutePath(), TArchiveDetector.NULL);
TFile backup = new TFile(backupLocation, TArchiveDetector.NULL);
source.cp_rp(backup); //Just copy the file
}
else
{
outputVerboseMessage("Backing up war DIRECTORY...");
TFile backup = new TFile(backupLocation);
warFile.cp_rp(backup); //Copy the directory
}
outputVerboseMessage("WAR has been backed up to '" + backupLocation + "'");
warHelper.backup(warFile);
}
}

View File

@@ -4,7 +4,9 @@ import org.alfresco.service.cmr.module.ModuleDetails;
import de.schlichtherle.truezip.file.TFile;
import java.io.IOException;
import java.util.List;
import java.util.jar.Manifest;
/**
* Performs various actions on a war file or exploded war directory
@@ -37,7 +39,7 @@ public interface WarHelper
* @param war a valid war file or exploded directory from a war
*/
public void checkCompatibleVersion(TFile war, ModuleDetails installingModuleDetails);
/**
* This checks to see if the module that is being installed is compatible with the war.
* If not module edition is specfied then it will just return. However, if an edition is specified and it doesn't match
@@ -65,4 +67,23 @@ public interface WarHelper
* @throws ModuleManagementToolException
*/
List<ModuleDetails> listModules(TFile war);
/**
* Backs up a given file or directory.
*
* @since 5.1
* @param file the file to backup
* @return the absolute path to the backup file.
*/
public String backup(TFile file) throws IOException;
/**
* Finds a war manifest file.
* @since 5.1
* @param war the war
* @return Manifest
* @throws ModuleManagementToolException
*/
public Manifest findManifest(TFile war) throws ModuleManagementToolException;
}

View File

@@ -1,5 +1,6 @@
package org.alfresco.repo.module.tool;
import de.schlichtherle.truezip.file.TArchiveDetector;
import de.schlichtherle.truezip.file.TFile;
import de.schlichtherle.truezip.file.TFileInputStream;
import org.alfresco.error.AlfrescoRuntimeException;
@@ -110,20 +111,33 @@ public class WarHelperImpl implements WarHelper
* @throws ModuleManagementToolException
*/
protected String findManifestArtibute(TFile war, String attributeName) throws ModuleManagementToolException {
InputStream is = null;
try
{
is = new TFileInputStream(war+MANIFEST_FILE);
Manifest manifest = new Manifest(is);
Attributes attribs = manifest.getMainAttributes();
return attribs.getValue(attributeName);
}
catch (IOException e)
{
throw new ModuleManagementToolException("Unabled to read a manifest for the war file: "+ war);
}
Manifest manifest = findManifest(war);
Attributes attribs = manifest.getMainAttributes();
return attribs.getValue(attributeName);
}
/**
* Finds a single attribute from a war manifest file.
* @param war the war
* @return Manifest
* @throws ModuleManagementToolException
*/
@Override
public Manifest findManifest(TFile war) throws ModuleManagementToolException {
InputStream is = null;
try
{
is = new TFileInputStream(war+MANIFEST_FILE);
Manifest manifest = new Manifest(is);
return manifest;
}
catch (IOException e)
{
throw new ModuleManagementToolException("Unabled to read a manifest for the war file: "+ war);
}
finally
{
if (is != null)
@@ -131,8 +145,7 @@ public class WarHelperImpl implements WarHelper
try { is.close(); } catch (Throwable e ) {}
}
}
}
}
/**
* Compares the version information with the module details to see if their valid. If they are invalid then it throws an exception.
@@ -335,6 +348,36 @@ public class WarHelperImpl implements WarHelper
return moduleDetails;
}
/**
* Backs up a given file or directory.
*
* @param file the file to backup
* @return the absolute path to the backup file.
*/
@Override
public String backup(TFile file) throws IOException
{
String backupLocation = file.getAbsolutePath()+"-" + System.currentTimeMillis() + ".bak";
if (file.isArchive())
{
log.info("Backing up file...");
TFile source = new TFile(file.getAbsolutePath(), TArchiveDetector.NULL);
TFile backup = new TFile(backupLocation, TArchiveDetector.NULL);
source.cp_rp(backup); //Just copy the file
}
else
{
log.info("Backing up DIRECTORY...");
TFile backup = new TFile(backupLocation);
file.cp_rp(backup); //Copy the directory
}
log.info("The back up is at '" + backupLocation + "'");
return backupLocation;
}
/**
* Gets the module details for the specified module from the war.
* @param war a valid war file or exploded directory from a war