Merged V3.4-BUG-FIX to HEAD

39015: Upgrade of truezip to 7.5.5 see ALF-14247
   39361: Added truezip-swing jar.  It seems that Truezip needs Swing :(


git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@39832 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Samuel Langlois
2012-07-26 16:41:46 +00:00
parent faa9ba7118
commit 68b4af4b11
8 changed files with 770 additions and 718 deletions

View File

@@ -20,6 +20,7 @@ package org.alfresco.repo.content.transform;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileOutputStream;
import java.io.FileReader;
import org.alfresco.repo.content.MimetypeMap;
@@ -30,8 +31,6 @@ import org.alfresco.service.cmr.repository.ContentWriter;
import org.alfresco.service.cmr.repository.TransformationOptions;
import org.alfresco.util.TempFileProvider;
import de.schlichtherle.io.FileOutputStream;
/**
* @see org.alfresco.repo.content.transform.MediaWikiContentTransformer
*

View File

@@ -21,15 +21,14 @@ package org.alfresco.repo.module.tool;
import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import de.schlichtherle.io.File;
import de.schlichtherle.io.FileInputStream;
import de.schlichtherle.io.FileOutputStream;
import de.schlichtherle.truezip.file.TFile;
import de.schlichtherle.truezip.file.TFileOutputStream;
import de.schlichtherle.truezip.file.TFileReader;
/**
* Details of the files installed during a module installation into a WAR
@@ -74,12 +73,12 @@ public class InstalledFiles
*/
public void load()
{
File file = new File(getFileLocation(), ModuleManagementTool.DETECTOR_AMP_AND_WAR);
TFile file = new TFile(getFileLocation());
if (file.exists() == true)
{
try
{
BufferedReader reader = new BufferedReader(new InputStreamReader(new FileInputStream(file)));
BufferedReader reader = new BufferedReader(new TFileReader(file));
try
{
String line = reader.readLine();
@@ -130,12 +129,12 @@ public class InstalledFiles
{
try
{
File file = new File(getFileLocation(), ModuleManagementTool.DETECTOR_AMP_AND_WAR);
TFile file = new TFile(getFileLocation());
if (file.exists() == false)
{
file.createNewFile();
}
FileOutputStream os = new FileOutputStream(file);
TFileOutputStream os = new TFileOutputStream(file);
try
{
for (String add : this.adds)

View File

@@ -18,6 +18,7 @@
*/
package org.alfresco.repo.module.tool;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
@@ -26,9 +27,9 @@ import java.util.Properties;
import org.alfresco.repo.module.ModuleDetailsImpl;
import org.alfresco.service.cmr.module.ModuleDetails;
import de.schlichtherle.io.File;
import de.schlichtherle.io.FileInputStream;
import de.schlichtherle.io.FileOutputStream;
import de.schlichtherle.truezip.file.TFile;
import de.schlichtherle.truezip.file.TFileInputStream;
import de.schlichtherle.truezip.file.TFileOutputStream;
/**
* Module details helper used by the module mangement tool
@@ -62,23 +63,35 @@ public class ModuleDetailsHelper
*
* @param location file location
* @return Returns the module details or null if the location points to nothing
* @throws IOException
*/
public static ModuleDetails createModuleDetailsFromPropertyLocation(String location)
public static ModuleDetails createModuleDetailsFromPropertyLocation(String location) throws IOException
{
ModuleDetails result = null;
TFileInputStream is;
try
{
File file = new File(location, ModuleManagementTool.DETECTOR_AMP_AND_WAR);
if (file.exists())
{
InputStream is = new FileInputStream(file);
result = createModuleDetailsFromPropertiesStream(is);
}
is = new TFileInputStream(location);
}
catch (FileNotFoundException error)
{
throw new ModuleManagementToolException("Unable to load module details from property file.", error);
}
try
{
result = createModuleDetailsFromPropertiesStream(is);
}
catch (IOException exception)
{
throw new ModuleManagementToolException("Unable to load module details from property file.", exception);
throw new ModuleManagementToolException(
"Unable to load module details from property file.", exception);
}
finally
{
is.close(); // ALWAYS close the stream!
}
return result;
}
@@ -89,8 +102,9 @@ public class ModuleDetailsHelper
* @param moduleId the module id
* @return Returns the module details for the given module ID as it occurs in the WAR, or <tt>null</tt>
* if there are no module details available.
* @throws IOException
*/
public static ModuleDetails createModuleDetailsFromWarAndId(String warLocation, String moduleId)
public static ModuleDetails createModuleDetailsFromWarAndId(String warLocation, String moduleId) throws IOException
{
String modulePropertiesFileLocation = ModuleDetailsHelper.getModulePropertiesFileLocation(warLocation, moduleId);
return ModuleDetailsHelper.createModuleDetailsFromPropertyLocation(modulePropertiesFileLocation);
@@ -102,10 +116,10 @@ public class ModuleDetailsHelper
* @return Returns a file handle to the module properties file within the given WAR.
* The file may or may not exist.
*/
public static File getModuleDetailsFileFromWarAndId(String warLocation, String moduleId)
public static TFile getModuleDetailsFileFromWarAndId(String warLocation, String moduleId)
{
String location = ModuleDetailsHelper.getModulePropertiesFileLocation(warLocation, moduleId);
File file = new File(location, ModuleManagementTool.DETECTOR_AMP_AND_WAR);
TFile file = new TFile(location);
return file;
}
@@ -143,7 +157,7 @@ public class ModuleDetailsHelper
try
{
String modulePropertiesFileLocation = getModulePropertiesFileLocation(warLocation, moduleId);
File file = new File(modulePropertiesFileLocation, ModuleManagementTool.DETECTOR_AMP_AND_WAR);
TFile file = new TFile(modulePropertiesFileLocation);
if (file.exists() == false)
{
file.createNewFile();
@@ -151,7 +165,7 @@ public class ModuleDetailsHelper
// Get all the module properties
Properties moduleProperties = moduleDetails.getProperties();
OutputStream os = new FileOutputStream(file);
OutputStream os = new TFileOutputStream(file);
try
{
moduleProperties.store(os, null);

View File

@@ -19,11 +19,8 @@
package org.alfresco.repo.module.tool;
import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.Date;
import java.util.Map;
import java.util.Map.Entry;
@@ -35,12 +32,13 @@ import org.alfresco.service.cmr.module.ModuleInstallState;
import org.alfresco.util.VersionNumber;
import org.safehaus.uuid.UUIDGenerator;
import de.schlichtherle.io.DefaultRaesZipDetector;
import de.schlichtherle.io.File;
import de.schlichtherle.io.FileInputStream;
import de.schlichtherle.io.ZipControllerException;
import de.schlichtherle.io.ZipDetector;
import de.schlichtherle.io.ZipWarningException;
import de.schlichtherle.truezip.file.TArchiveDetector;
import de.schlichtherle.truezip.file.TConfig;
import de.schlichtherle.truezip.file.TFile;
import de.schlichtherle.truezip.file.TFileInputStream;
import de.schlichtherle.truezip.file.TVFS;
import de.schlichtherle.truezip.fs.archive.zip.ZipDriver;
import de.schlichtherle.truezip.socket.sl.IOPoolLocator;
/**
* Module management tool.
@@ -83,9 +81,6 @@ public class ModuleManagementTool implements LogOutput
private static final int ERROR_EXIT_CODE = 1;
private static final int SUCCESS_EXIT_CODE = 0;
/** Default zip detector */
public static final ZipDetector DETECTOR_AMP_AND_WAR = new DefaultRaesZipDetector("amp|war");
/** File mapping properties */
private Properties defaultFileMappingProperties;
@@ -99,6 +94,9 @@ public class ModuleManagementTool implements LogOutput
*/
public ModuleManagementTool()
{
TConfig config = TConfig.get();
config.setArchiveDetector(new TArchiveDetector("war|amp", new ZipDriver(IOPoolLocator.SINGLETON)));
// Load the default file mapping properties
this.defaultFileMappingProperties = new Properties();
InputStream is = this.getClass().getClassLoader().getResourceAsStream(DEFAULT_FILE_MAPPING_PROPERTIES);
@@ -134,21 +132,22 @@ public class ModuleManagementTool implements LogOutput
/**
* Installs all modules within a folder into the given WAR file.
* @throws IOException
*
* @see #installModule(String, String, boolean, boolean, boolean)
*/
public void installModules(String directory, String warFileLocation)
public void installModules(String directory, String warFileLocation) throws IOException
{
installModules(directory, warFileLocation, false, false, true);
}
public void installModules(String directoryLocation, String warFileLocation, boolean preview, boolean forceInstall, boolean backupWAR)
public void installModules(String directoryLocation, String warFileLocation, boolean preview, boolean forceInstall, boolean backupWAR) throws IOException
{
java.io.File dir = new java.io.File(directoryLocation);
if (dir.exists() == true)
{
if (backupWAR) {
backupWar(warFileLocation,true);
backupWar(new TFile(warFileLocation),true);
backupWAR = false; //Set it to false so a backup doesn't occur again.
}
installModules(dir, warFileLocation, preview, forceInstall,backupWAR);
@@ -207,21 +206,20 @@ public class ModuleManagementTool implements LogOutput
try
{
outputVerboseMessage("Installing AMP '" + ampFileLocation + "' into WAR '" + warFileLocation + "'");
java.io.File theWar = new File(warFileLocation, DETECTOR_AMP_AND_WAR);
if (!theWar.exists())
TFile warFile = new TFile(warFileLocation);
if (!warFile.exists())
{
throw new ModuleManagementToolException("The war file '" + warFileLocation + "' does not exist.");
throw new ModuleManagementToolException("The war file '" + warFile + "' does not exist.");
}
if (preview == false)
{
// Make sure the module and backup directory exisits in the WAR file
File moduleDir = new File(warFileLocation + WarHelper.MODULE_NAMESPACE_DIR, DETECTOR_AMP_AND_WAR);
TFile moduleDir = new TFile(warFileLocation + WarHelper.MODULE_NAMESPACE_DIR);
if (moduleDir.exists() == false)
{
moduleDir.mkdir();
}
backupWar(warFileLocation, backupWAR);
backupWar(warFile, backupWAR);
}
// Get the details of the installing module
@@ -235,12 +233,12 @@ public class ModuleManagementTool implements LogOutput
VersionNumber installingVersion = installingModuleDetails.getVersion();
//A series of checks
warHelper.checkCompatibleVersion(theWar, installingModuleDetails);
warHelper.checkCompatibleEdition(theWar, installingModuleDetails);
warHelper.checkModuleDependencies(theWar, installingModuleDetails);
warHelper.checkCompatibleVersion(warFile, installingModuleDetails);
warHelper.checkCompatibleEdition(warFile, installingModuleDetails);
warHelper.checkModuleDependencies(warFile, installingModuleDetails);
// Try to find an installed module by the ID
ModuleDetails installedModuleDetails = warHelper.getModuleDetailsOrAlias(theWar, installingModuleDetails);
ModuleDetails installedModuleDetails = warHelper.getModuleDetailsOrAlias(warFile, installingModuleDetails);
uninstallIfNecessary(warFileLocation, installedModuleDetails, preview, forceInstall, installingVersion);
@@ -256,12 +254,9 @@ public class ModuleManagementTool implements LogOutput
{
for (Entry<Object, Object> entry : directoryChanges.entrySet())
{
File destination = new File((String) entry.getValue(), DETECTOR_AMP_AND_WAR);
File source = new File((String) entry.getKey(), DETECTOR_AMP_AND_WAR);
//Do the bulk copy since this is quicker than copying files one by one
//The changes aren't actuall "committed" until the File.update() is called (below)
destination.copyAllFrom(source);
TFile source = new TFile((String) entry.getKey());
TFile destination = new TFile((String) entry.getValue());
source.cp_rp(destination);
}
}
@@ -273,36 +268,24 @@ public class ModuleManagementTool implements LogOutput
installingModuleDetails.setInstallDate(new Date());
ModuleDetailsHelper.saveModuleDetails(warFileLocation, installingModuleDetails);
// Update the zip files
File.update();
// Set the modified date
java.io.File warFile = new java.io.File(warFileLocation);
if (warFile.exists())
{
warFile.setLastModified(System.currentTimeMillis());
}
// Update the zip filessync
TVFS.umount();
}
}
catch (ZipWarningException ignore)
{
// Only instances of the class ZipWarningException exist in the chain of
// exceptions. We choose to ignore this.
}
catch (ZipControllerException exception)
{
// At least one exception occured which is not just a ZipWarningException.
// This is a severe situation that needs to be handled.
throw new ModuleManagementToolException("A Zip error was encountered during deployment of the AEP into the WAR", exception);
}
catch (IOException exception)
{
throw new ModuleManagementToolException("An IO error was encountered during deployment of the AEP into the WAR", exception);
throw new ModuleManagementToolException("An IO error was encountered during deployment of the AMP into the WAR", exception);
}
}
private void uninstallIfNecessary(String warFileLocation, ModuleDetails installedModuleDetails, boolean preview,
boolean forceInstall, VersionNumber installingVersion)
boolean forceInstall, VersionNumber installingVersion) throws IOException
{
// Now clean up the old instance
if (installedModuleDetails != null)
@@ -392,6 +375,28 @@ public class ModuleManagementTool implements LogOutput
// Get a reference to the source folder (if it isn't present don't do anything)
File source = new File(ampFileLocation + "/" + mappingSource, DETECTOR_AMP_AND_WAR);
if (source != null && source.list() != null)
{
// The file mappings are expected to start with "/"
String mappingSource = (String) entry.getKey();
if (mappingSource.length() == 0 || !mappingSource.startsWith("/"))
{
throw new AlfrescoRuntimeException("File mapping sources must start with '/', but was: " + mappingSource);
}
String mappingTarget = (String) entry.getValue();
if (mappingTarget.length() == 0 || !mappingTarget.startsWith("/"))
{
throw new AlfrescoRuntimeException("File mapping targets must start with '/' but was '" + mappingTarget + "'");
}
mappingSource = mappingSource.trim(); //trim whitespace
mappingTarget = mappingTarget.trim(); //trim whitespace
// Run throught the files one by one figuring out what we are going to do during the copy
calculateCopyToWar(ampFileLocation, warFileLocation, mappingSource, mappingTarget, installedFiles, preview, forceInstall);
// Get a reference to the source folder (if it isn't present don't do anything)
TFile source = new TFile(ampFileLocation + "/" + mappingSource);
if (source != null && source.list() != null)
{
// Add to the list of directory changes so we can implement the changes later.
String sourceDir = ampFileLocation + mappingSource;
@@ -404,30 +409,30 @@ public class ModuleManagementTool implements LogOutput
return dirChanges;
}
private void backupWar(String warFileLocation, boolean backupWAR)
private void backupWar(TFile warFile, boolean backupWAR) throws IOException
{
// 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);
}
outputVerboseMessage("WAR has been backed up to '" + backupLocation + "'");
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 + "'");
}
}
@@ -436,7 +441,7 @@ public class ModuleManagementTool implements LogOutput
*/
private Properties getCustomFileMappings(String ampFileLocation)
{
File file = new File(ampFileLocation + "/" + FILE_MAPPING_PROPERTIES, ModuleManagementTool.DETECTOR_AMP_AND_WAR);
TFile file = new TFile(ampFileLocation + "/" + FILE_MAPPING_PROPERTIES);
if (!file.exists())
{
// Nothing there
@@ -446,7 +451,7 @@ public class ModuleManagementTool implements LogOutput
InputStream is = null;
try
{
is = new BufferedInputStream(new FileInputStream(file));
is = new BufferedInputStream(new TFileInputStream(file));
mappingProperties.load(is);
}
catch (IOException exception)
@@ -470,8 +475,9 @@ public class ModuleManagementTool implements LogOutput
* @param moduleId the module id
* @param preview indicates whether this is a preview installation
* @param purge Fully delete all files (including those marked "PRESERVED")
* @throws IOException
*/
public void uninstallModule(String moduleId,String warFileLocation, boolean preview, boolean purge)
public void uninstallModule(String moduleId,String warFileLocation, boolean preview, boolean purge) throws IOException
{
InstalledFiles installedFiles = new InstalledFiles(warFileLocation, moduleId);
installedFiles.load();
@@ -491,10 +497,10 @@ public class ModuleManagementTool implements LogOutput
if (preview == false)
{
// Recover updated file and delete backups
File modified = new File(warFileLocation + update.getKey(), DETECTOR_AMP_AND_WAR);
File backup = new File(warFileLocation + update.getValue(), DETECTOR_AMP_AND_WAR);
modified.copyFrom(backup);
backup.delete();
TFile modified = new TFile(warFileLocation + update.getKey());
TFile backup = new TFile(warFileLocation + update.getValue());
backup.cp_rp(modified);
backup.deleteOnExit();
}
outputVerboseMessage("Recovering file '" + update.getKey() + "' from backup '" + update.getValue() + "'", true);
@@ -516,7 +522,7 @@ public class ModuleManagementTool implements LogOutput
*/
private void removeFile(String warLocation, String filePath, boolean preview)
{
File removeFile = new File(warLocation + filePath, DETECTOR_AMP_AND_WAR);
TFile removeFile = new TFile(warLocation + filePath);
if (removeFile.exists() == true)
{
outputVerboseMessage("Removing file '" + filePath + "' from war", true);
@@ -567,7 +573,7 @@ public class ModuleManagementTool implements LogOutput
}
String sourceLocation = ampFileLocation + sourceDir;
File ampConfig = new File(sourceLocation, DETECTOR_AMP_AND_WAR);
TFile ampConfig = new TFile(sourceLocation);
java.io.File[] files = ampConfig.listFiles();
if (files != null)
@@ -575,7 +581,7 @@ public class ModuleManagementTool implements LogOutput
for (java.io.File sourceChild : files)
{
String destinationFileLocation = warFileLocation + destinationDir + "/" + sourceChild.getName();
File destinationChild = new File(destinationFileLocation, DETECTOR_AMP_AND_WAR);
TFile destinationChild = new TFile(destinationFileLocation);
if (sourceChild.isFile() == true)
{
String backupLocation = null;
@@ -592,8 +598,8 @@ public class ModuleManagementTool implements LogOutput
backupLocation = BACKUP_DIR + "/" + generateGuid() + ".bin";
if (preview == false)
{
File backupFile = new File(warFileLocation + backupLocation, DETECTOR_AMP_AND_WAR);
backupFile.copyFrom(destinationChild);
TFile backupFile = new TFile(warFileLocation + backupLocation);
destinationChild.cp_rp(backupFile);
}
} else {
//Not a forced install, there is an existing file in the war, lets rollback the transaction,
@@ -666,7 +672,7 @@ public class ModuleManagementTool implements LogOutput
try
{
File moduleDir = new File(warLocation + WarHelper.MODULE_NAMESPACE_DIR, DETECTOR_AMP_AND_WAR);
TFile moduleDir = new TFile(warLocation + WarHelper.MODULE_NAMESPACE_DIR);
if (moduleDir.exists() == false)
{
outputVerboseMessage("No modules are installed in this WAR file");
@@ -679,20 +685,27 @@ public class ModuleManagementTool implements LogOutput
{
if (dir.isDirectory() == true)
{
File moduleProperties = new File(dir.getPath() + WarHelper.MODULE_CONFIG_IN_WAR, DETECTOR_AMP_AND_WAR);
TFile moduleProperties = new TFile(dir.getPath() + WarHelper.MODULE_CONFIG_IN_WAR);
if (moduleProperties.exists() == true)
{
InputStream is = null;
try
{
moduleFound = true;
InputStream is = new FileInputStream(moduleProperties);
is = new TFileInputStream(moduleProperties);
moduleDetails = ModuleDetailsHelper.createModuleDetailsFromPropertiesStream(is);
}
catch (IOException exception)
{
throw new ModuleManagementToolException("Unable to open module properties file '" + moduleProperties.getPath() + "'", exception);
}
finally
{
if (is != null)
{
try { is.close(); } catch (Throwable e ) {}
}
}
outputVerboseMessage("Module '" + moduleDetails.getId() + "' installed in '" + warLocation + "'");
outputVerboseMessage(" Title: " + moduleDetails.getTitle(), true);
outputVerboseMessage(" Version: " + moduleDetails.getVersion(), true);
@@ -848,15 +861,22 @@ public class ModuleManagementTool implements LogOutput
}
}
if (directory == false)
try
{
// Install the module
manager.installModule(aepFileLocation, warFileLocation, previewInstall, forceInstall, backup);
if (directory == false)
{
// Install the module
manager.installModule(aepFileLocation, warFileLocation, previewInstall, forceInstall, backup);
}
else
{
// Install the modules from the directory
manager.installModules(aepFileLocation, warFileLocation, previewInstall, forceInstall, backup);
}
}
else
catch (IOException error)
{
// Install the modules from the directory
manager.installModules(aepFileLocation, warFileLocation, previewInstall, forceInstall, backup);
throw new ModuleManagementToolException(error.getMessage());
}
System.exit(SUCCESS_EXIT_CODE);
@@ -921,6 +941,11 @@ public class ModuleManagementTool implements LogOutput
manager.outputErrorMessage(e.getMessage());
System.exit(ERROR_EXIT_CODE);
}
catch (IOException error)
{
manager.outputErrorMessage(error.getMessage());
System.exit(ERROR_EXIT_CODE);
}
}
/**
@@ -931,37 +956,6 @@ public class ModuleManagementTool implements LogOutput
return UUIDGenerator.getInstance().generateTimeBasedUUID().toString();
}
/**
* Code borrowed directly from the Springframework FileCopyUtils.
*/
private static void copyFile(java.io.File in, java.io.File out) throws IOException
{
InputStream is = new BufferedInputStream(new FileInputStream(in));
OutputStream os = new BufferedOutputStream(new FileOutputStream(out));
try
{
int byteCount = 0;
byte[] buffer = new byte[4096];
int bytesRead = -1;
while ((bytesRead = is.read(buffer)) != -1) {
os.write(buffer, 0, bytesRead);
byteCount += bytesRead;
}
os.flush();
}
finally
{
if (is != null)
{
try { is.close(); } catch (Throwable e) { e.printStackTrace(); }
}
if (os != null)
{
try { os.close(); } catch (Throwable e) { e.printStackTrace(); }
}
}
}
/**
* Outputs the module management tool usage
*/

View File

@@ -20,23 +20,22 @@ package org.alfresco.repo.module.tool;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import junit.framework.TestCase;
import org.alfresco.util.TempFileProvider;
import org.springframework.util.FileCopyUtils;
import de.schlichtherle.io.DefaultRaesZipDetector;
import de.schlichtherle.io.FileInputStream;
import de.schlichtherle.io.FileOutputStream;
import de.schlichtherle.io.ZipDetector;
import de.schlichtherle.truezip.file.TFile;
import de.schlichtherle.truezip.file.TFileInputStream;
import de.schlichtherle.truezip.file.TVFS;
/**
* @see org.alfresco.repo.module.tool.ModuleManagementTool
@@ -47,8 +46,7 @@ import de.schlichtherle.io.ZipDetector;
public class ModuleManagementToolTest extends TestCase
{
private ModuleManagementTool manager = new ModuleManagementTool();
ZipDetector defaultDetector = new DefaultRaesZipDetector("amp|war");
static final int BUFFER = 2048;
public void testBasicInstall()
throws Exception
@@ -59,6 +57,11 @@ public class ModuleManagementToolTest extends TestCase
String ampLocation = getFileLocation(".amp", "module/test_v1.amp");
String ampV2Location = getFileLocation(".amp", "module/test_v2.amp");
installerSharedTests(warLocation, ampLocation, ampV2Location);
}
private void installerSharedTests(String warLocation, String ampLocation, String ampV2Location)
{
// Initial install of module
this.manager.installModule(ampLocation, warLocation);
@@ -148,6 +151,20 @@ public class ModuleManagementToolTest extends TestCase
}
}
public void testBasicFolderInstall() throws Exception
{
manager.setVerbose(true);
String warDirectory = extractToDir(".war", "module/test.war");
String ampDirectory = extractToDir(".amp", "module/test_v1.amp");
String ampV2Directory = getFileLocation(".amp", "module/test_v2.amp");
assertNotNull(warDirectory);
assertNotNull(ampDirectory);
assertNotNull(ampV2Directory);
installerSharedTests(warDirectory, ampDirectory, ampV2Directory);
}
public void testDependencySuccess() throws Exception
{
manager.setVerbose(true);
@@ -323,6 +340,22 @@ public class ModuleManagementToolTest extends TestCase
return file.getPath();
}
private String extractToDir(String extension, String location)
{
File tmpDir = TempFileProvider.getTempDir();
try {
TFile zipFile = new TFile(this.getClass().getClassLoader().getResource(location).getPath());
TFile outDir = new TFile(tmpDir.getAbsolutePath()+"/moduleManagementToolTestDir"+System.currentTimeMillis());
outDir.mkdir();
zipFile.cp_rp(outDir);
TVFS.umount(zipFile);
return outDir.getPath();
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
public void testNoWar() throws Exception
{
String noWar = "noWar";
@@ -349,7 +382,7 @@ public class ModuleManagementToolTest extends TestCase
{
for (String file : files)
{
File file0 = new de.schlichtherle.io.File(warLocation + file, this.defaultDetector);
File file0 = new TFile(warLocation + file);
assertTrue("The file/dir " + file + " does not exist in the WAR.", file0.exists());
}
}
@@ -358,7 +391,7 @@ public class ModuleManagementToolTest extends TestCase
{
for (String file : files)
{
File file0 = new de.schlichtherle.io.File(warLocation + file, this.defaultDetector);
File file0 = new TFile(warLocation + file);
assertFalse("The file/dir " + file + " does exist in the WAR.", file0.exists());
}
}
@@ -366,11 +399,22 @@ public class ModuleManagementToolTest extends TestCase
private void checkContentsOfFile(String location, String expectedContents)
throws IOException
{
File file = new de.schlichtherle.io.File(location, this.defaultDetector);
File file = new TFile(location);
assertTrue(file.exists());
BufferedReader reader = new BufferedReader(new InputStreamReader(new FileInputStream(file)));
String line = reader.readLine();
assertNotNull(line);
assertEquals(expectedContents, line.trim());
BufferedReader reader = null;
try
{
reader = new BufferedReader(new InputStreamReader(new TFileInputStream(file)));
String line = reader.readLine();
assertNotNull(line);
assertEquals(expectedContents, line.trim());
}
finally
{
if (reader != null)
{
try { reader.close(); } catch (Throwable e ) {}
}
}
}
}

View File

@@ -1,9 +1,9 @@
package org.alfresco.repo.module.tool;
import java.io.File;
import org.alfresco.service.cmr.module.ModuleDetails;
import de.schlichtherle.truezip.file.TFile;
/**
* Performs various actions on a war file or exploded war directory
*
@@ -20,21 +20,21 @@ public interface WarHelper
* @param installingModuleDetails
* @return ModuleDetails
*/
public ModuleDetails getModuleDetailsOrAlias(File war, ModuleDetails installingModuleDetails);
public ModuleDetails getModuleDetailsOrAlias(TFile war, ModuleDetails installingModuleDetails);
/**
* Checks the dependencies of this module
* @param war
* @param installingModuleDetails
*/
public void checkModuleDependencies(File war, ModuleDetails installingModuleDetails);
public void checkModuleDependencies(TFile war, ModuleDetails installingModuleDetails);
/**
* Checks to see if the module is compatible with the version of Alfresco.
*
* @param war a valid war file or exploded directory from a war
*/
public void checkCompatibleVersion(File war, ModuleDetails installingModuleDetails);
public void checkCompatibleVersion(TFile war, ModuleDetails installingModuleDetails);
/**
* This checks to see if the module that is being installed is compatible with the war.
@@ -43,6 +43,6 @@ public interface WarHelper
* @param war a valid war file or exploded directory from a war
* @param installingModuleDetails
*/
public void checkCompatibleEdition(File war, ModuleDetails installingModuleDetails);
public void checkCompatibleEdition(TFile war, ModuleDetails installingModuleDetails);
}

View File

@@ -1,6 +1,5 @@
package org.alfresco.repo.module.tool;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
@@ -12,7 +11,9 @@ import org.alfresco.service.cmr.module.ModuleDependency;
import org.alfresco.service.cmr.module.ModuleDetails;
import org.alfresco.util.VersionNumber;
import de.schlichtherle.io.FileInputStream;
import de.schlichtherle.truezip.file.TFile;
import de.schlichtherle.truezip.file.TFileInputStream;
/**
* Performs logic for the Module Management Tool.
@@ -33,10 +34,10 @@ public class WarHelperImpl implements WarHelper
}
@Override
public void checkCompatibleVersion(File war, ModuleDetails installingModuleDetails)
public void checkCompatibleVersion(TFile war, ModuleDetails installingModuleDetails)
{
//Version check
File propsFile = getFile(war, VERSION_PROPERTIES);
TFile propsFile = new TFile(war+VERSION_PROPERTIES);
if (propsFile != null && propsFile.exists())
{
Properties warVers = loadProperties(propsFile);
@@ -55,14 +56,14 @@ public class WarHelperImpl implements WarHelper
}
@Override
public void checkCompatibleEdition(File war, ModuleDetails installingModuleDetails)
public void checkCompatibleEdition(TFile war, ModuleDetails installingModuleDetails)
{
List<String> installableEditions = installingModuleDetails.getEditions();
if (installableEditions != null && installableEditions.size() > 0) {
File propsFile = getFile(war, VERSION_PROPERTIES);
TFile propsFile = new TFile(war+VERSION_PROPERTIES);
if (propsFile != null && propsFile.exists())
{
Properties warVers = loadProperties(propsFile);
@@ -84,7 +85,7 @@ public class WarHelperImpl implements WarHelper
}
@Override
public void checkModuleDependencies(File war, ModuleDetails installingModuleDetails)
public void checkModuleDependencies(TFile war, ModuleDetails installingModuleDetails)
{
// Check that the target war has the necessary dependencies for this install
List<ModuleDependency> installingModuleDependencies = installingModuleDetails.getDependencies();
@@ -107,7 +108,7 @@ public class WarHelperImpl implements WarHelper
}
@Override
public ModuleDetails getModuleDetailsOrAlias(File war, ModuleDetails installingModuleDetails)
public ModuleDetails getModuleDetailsOrAlias(TFile war, ModuleDetails installingModuleDetails)
{
ModuleDetails installedModuleDetails = getModuleDetails(war, installingModuleDetails.getId());
if (installedModuleDetails == null)
@@ -137,10 +138,10 @@ public class WarHelperImpl implements WarHelper
* @param moduleId
* @return
*/
protected ModuleDetails getModuleDetails(File war, String moduleId)
protected ModuleDetails getModuleDetails(TFile war, String moduleId)
{
ModuleDetails moduleDets = null;
File theFile = getModuleDetailsFile(war, moduleId);
TFile theFile = getModuleDetailsFile(war, moduleId);
if (theFile != null && theFile.exists())
{
moduleDets = new ModuleDetailsImpl(loadProperties(theFile));
@@ -153,14 +154,15 @@ public class WarHelperImpl implements WarHelper
* @param propertiesPath Path to the properties file (including .properties)
* @return Properties object or null
*/
private Properties loadProperties(File propertiesFile)
private Properties loadProperties(TFile propertiesFile)
{
Properties result = null;
InputStream is = null;
try
{
if (propertiesFile.exists())
{
InputStream is = new FileInputStream(propertiesFile);
is = new TFileInputStream(propertiesFile);
result = new Properties();
result.load(is);
}
@@ -169,21 +171,21 @@ public class WarHelperImpl implements WarHelper
{
throw new ModuleManagementToolException("Unable to load properties from the war file; "+propertiesFile.getPath(), exception);
}
finally
{
if (is != null)
{
try { is.close(); } catch (Throwable e ) {}
}
}
return result;
}
private File getModuleDetailsFile(File war, String moduleId)
private TFile getModuleDetailsFile(TFile war, String moduleId)
{
return getFile(war,MODULE_NAMESPACE_DIR+ "/" + moduleId+MODULE_CONFIG_IN_WAR);
return new TFile(war.getAbsolutePath()+MODULE_NAMESPACE_DIR+ "/" + moduleId+MODULE_CONFIG_IN_WAR);
}
private File getFile(File war, String pathToFileIncludingExtension)
{
return new de.schlichtherle.io.File(war,pathToFileIncludingExtension, ModuleManagementTool.DETECTOR_AMP_AND_WAR);
}
}

View File

@@ -5,6 +5,7 @@ import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
@@ -14,11 +15,10 @@ import org.alfresco.repo.module.ModuleDetailsImpl;
import org.alfresco.service.cmr.module.ModuleDetails;
import org.alfresco.util.TempFileProvider;
import org.alfresco.util.VersionNumber;
import org.junit.Before;
import org.junit.Test;
import org.springframework.util.FileCopyUtils;
import de.schlichtherle.io.FileOutputStream;
import de.schlichtherle.truezip.file.TFile;
/**
* Tests the war helper.
@@ -43,7 +43,7 @@ public class WarHelperImplTest extends WarHelperImpl
@Test
public void testCheckCompatibleVersion()
{
File theWar = getFile(".war", "module/test.war"); //Version 4.1.0
TFile theWar = getFile(".war", "module/test.war"); //Version 4.1.0
ModuleDetails installingModuleDetails = new ModuleDetailsImpl("test_it", new VersionNumber("9999"), "Test Mod", "Testing module");
installingModuleDetails.setRepoVersionMin(new VersionNumber("10.1"));
@@ -104,7 +104,7 @@ public class WarHelperImplTest extends WarHelperImpl
props.setProperty(ModuleDetails.PROP_TITLE, "Test for Compatiblity");
props.setProperty(ModuleDetails.PROP_DESCRIPTION, "Test for Compatible Editions");
ModuleDetails installingModuleDetails = new ModuleDetailsImpl(props);
File theWar = getFile(".war", "module/test.war"); //Community Edition
TFile theWar = getFile(".war", "module/test.war"); //Community Edition
//Test for no edition specified
this.checkCompatibleEdition(theWar, installingModuleDetails); //does not throw exception
@@ -139,7 +139,7 @@ public class WarHelperImplTest extends WarHelperImpl
@Test
public void testNoVersionProperties()
{
File theWar = getFile(".war", "module/empty.war");
TFile theWar = getFile(".war", "module/empty.war");
ModuleDetails installingModuleDetails = new ModuleDetailsImpl("test_it", new VersionNumber("9999"), "Test Mod", "Testing module");
installingModuleDetails.setRepoVersionMin(new VersionNumber("10.1"));
@@ -147,7 +147,7 @@ public class WarHelperImplTest extends WarHelperImpl
this.checkCompatibleEdition(theWar, installingModuleDetails); //does not throw exception
}
private File getFile(String extension, String location)
private TFile getFile(String extension, String location)
{
File file = TempFileProvider.createTempFile("moduleManagementToolTest-", extension);
InputStream is = this.getClass().getClassLoader().getResourceAsStream(location);
@@ -162,6 +162,6 @@ public class WarHelperImplTest extends WarHelperImpl
{
error.printStackTrace();
}
return file;
return new TFile(file);
}
}