use of org.alfresco.repo.module.ModuleVersionNumber in project alfresco-repository by Alfresco.
the class ModuleManagementTool method installModule.
/**
* Installs a given AMP file into a given WAR file.
*
* @param ampFileLocation 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 preview indicates whether this should be a preview install. This means that the process of
* installation will be followed and reported, but the WAR file will not be modified.
* @param forceInstall indicates whether the installed files will be replaced regardless of the currently installed
* version of the AMP. Generally used during development of the AMP.
* @param backupWAR indicates whether we should backup the war we are modifying or not
*/
public void installModule(String ampFileLocation, String warFileLocation, boolean preview, boolean forceInstall, boolean backupWAR) {
TFile warFile = new TFile(warFileLocation);
try {
outputVerboseMessage("Installing AMP '" + ampFileLocation + "' into WAR '" + warFileLocation + "'");
if (!warFile.exists()) {
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
TFile moduleDir = new TFile(warFileLocation + WarHelper.MODULE_NAMESPACE_DIR);
if (moduleDir.exists() == false) {
moduleDir.mkdir();
}
backupWar(warFile, backupWAR);
}
// Get the details of the installing module
String propertiesLocation = ampFileLocation + "/module.properties";
ModuleDetails installingModuleDetails = ModuleDetailsHelper.createModuleDetailsFromPropertyLocation(propertiesLocation, this);
if (installingModuleDetails == null) {
throw new ModuleManagementToolException("No module.properties file has been found in the installing .amp file '" + ampFileLocation + "'");
}
String installingId = installingModuleDetails.getId();
ModuleVersionNumber installingVersion = installingModuleDetails.getModuleVersionNumber();
// A series of checks
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(warFile, installingModuleDetails);
// Check module directory exists
TFile moduleInstallDirectory = new TFile(warFileLocation + WarHelper.MODULE_NAMESPACE_DIR + "/" + installingId);
if (preview == false && moduleInstallDirectory.exists() == false) {
moduleInstallDirectory.mkdir();
}
uninstallIfNecessary(warFileLocation, installedModuleDetails, preview, forceInstall, installingVersion);
outputVerboseMessage("Adding files relating to version '" + installingVersion + "' of module '" + installingId + "'");
InstalledFiles installedFiles = new InstalledFiles(warFileLocation, installingId);
Properties directoryChanges = calculateChanges(ampFileLocation, warFileLocation, preview, forceInstall, installedFiles);
if (preview == false) {
// Now actually do the changes
if (directoryChanges != null && directoryChanges.size() > 0) {
for (Entry<Object, Object> entry : directoryChanges.entrySet()) {
TFile source = new TFile((String) entry.getKey());
TFile destination = new TFile((String) entry.getValue());
source.cp_rp(destination);
}
}
// Save the installed file list
installedFiles.save();
// Update the installed module details
installingModuleDetails.setInstallState(ModuleInstallState.INSTALLED);
installingModuleDetails.setInstallDate(new Date());
ModuleDetailsHelper.saveModuleDetails(warFileLocation, installingModuleDetails);
// Set the modified date
if (warFile.exists()) {
warFile.setLastModified(System.currentTimeMillis());
}
}
} catch (AlfrescoRuntimeException exception) {
throw new ModuleManagementToolException("An error was encountered during deployment of the AMP into the WAR: " + exception.getMessage(), exception);
} catch (IOException exception) {
throw new ModuleManagementToolException("An IO error was encountered during deployment of the AMP into the WAR", exception);
} finally {
try {
TVFS.umount(warFile);
} catch (FsSyncException e) {
throw new ModuleManagementToolException("Error when attempting to unmount WAR file: " + warFile.getPath(), e);
}
}
}
use of org.alfresco.repo.module.ModuleVersionNumber in project alfresco-repository by Alfresco.
the class ModuleManagementTool method uninstallIfNecessary.
private void uninstallIfNecessary(String warFileLocation, ModuleDetails installedModuleDetails, boolean preview, boolean forceInstall, ModuleVersionNumber installingVersion) throws IOException {
// Now clean up the old instance
if (installedModuleDetails != null) {
String installedId = installedModuleDetails.getId();
ModuleVersionNumber installedVersion = installedModuleDetails.getModuleVersionNumber();
int compareValue = installedVersion.compareTo(installingVersion);
if (compareValue > 0) {
// Trying to install an earlier version of the extension
outputVerboseMessage("WARNING: A later version of this module is already installed in the WAR. Installation skipped. " + "You could force the installation by passing the -force option.", false);
return;
}
if (forceInstall == true) {
// Warn of forced install
outputVerboseMessage("WARNING: The installation of this module is being forced. All files will be removed and replaced regardless of existing versions present.", false);
}
if (compareValue == 0) {
// Trying to install the same extension version again
outputVerboseMessage("WARNING: This version of this module is already installed in the WAR..upgrading.", false);
}
if (forceInstall == true || compareValue <= 0) {
// Trying to update the extension, old files need to cleaned before we proceed
outputVerboseMessage("Clearing out files relating to version '" + installedVersion + "' of module '" + installedId + "'", false);
uninstallModule(installedId, warFileLocation, preview, true);
}
}
}
use of org.alfresco.repo.module.ModuleVersionNumber in project alfresco-repository by Alfresco.
the class WarHelperImplTest method testCheckCompatibleVersion.
@Test
public void testCheckCompatibleVersion() {
// Version 4.1.0
TFile theWar = getFile(".war", "module/test.war");
ModuleDetails installingModuleDetails = new ModuleDetailsImpl("test_it", new ModuleVersionNumber("9999"), "Test Mod", "Testing module");
installingModuleDetails.setRepoVersionMin(new VersionNumber("10.1"));
try {
this.checkCompatibleVersion(theWar, installingModuleDetails);
// should never get here
fail();
} catch (ModuleManagementToolException exception) {
assertTrue(exception.getMessage().contains("must be installed on a war version equal to or greater than 10.1"));
}
installingModuleDetails.setRepoVersionMin(new VersionNumber("1.1"));
// does not throw exception
this.checkCompatibleVersion(theWar, installingModuleDetails);
installingModuleDetails.setRepoVersionMax(new VersionNumber("3.0"));
try {
this.checkCompatibleVersion(theWar, installingModuleDetails);
// should never get here
fail();
} catch (ModuleManagementToolException exception) {
assertTrue(exception.getMessage().contains("cannot be installed on a war version greater than 3.0"));
}
installingModuleDetails.setRepoVersionMax(new VersionNumber("99"));
// does not throw exception
this.checkCompatibleVersion(theWar, installingModuleDetails);
// current war version
installingModuleDetails.setRepoVersionMin(new VersionNumber("4.1.0"));
// current war version
installingModuleDetails.setRepoVersionMax(new VersionNumber("4.1.0"));
// does not throw exception
this.checkCompatibleVersion(theWar, installingModuleDetails);
// current war version
installingModuleDetails.setRepoVersionMin(new VersionNumber("3.4.0"));
// current war version
installingModuleDetails.setRepoVersionMax(new VersionNumber("4.1.0"));
// does not throw exception
this.checkCompatibleVersion(theWar, installingModuleDetails);
try {
// current war version
installingModuleDetails.setRepoVersionMin(new VersionNumber("3.4.0"));
// current war version
installingModuleDetails.setRepoVersionMax(new VersionNumber("4.0.999"));
// does not throw exception
this.checkCompatibleVersion(theWar, installingModuleDetails);
// should never get here
fail("Should not pass as current version is 4.1.0 and the max value is 4.0.999");
} catch (ModuleManagementToolException exception) {
assertTrue(exception.getMessage().contains("cannot be installed on a war version greater than 4.0.999"));
}
}
use of org.alfresco.repo.module.ModuleVersionNumber in project alfresco-repository by Alfresco.
the class ModuleComponentHelperTest method testStartComponentsV15.
public void testStartComponentsV15() {
ModuleVersionNumber moduleVersion = new ModuleVersionNumber("1.5");
startComponents(moduleVersion);
}
use of org.alfresco.repo.module.ModuleVersionNumber in project alfresco-repository by Alfresco.
the class ModuleComponentHelperTest method testStartComponentsV05.
public void testStartComponentsV05() {
ModuleVersionNumber moduleVersion = new ModuleVersionNumber("0.5");
startComponents(moduleVersion);
}
Aggregations