mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-10-08 14:51:49 +00:00
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:
@@ -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
|
||||
|
Reference in New Issue
Block a user