Search in sources :

Example 6 with ModuleVersionNumber

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);
        }
    }
}
Also used : FsSyncException(de.schlichtherle.truezip.fs.FsSyncException) ModuleDetails(org.alfresco.service.cmr.module.ModuleDetails) IOException(java.io.IOException) ModuleVersionNumber(org.alfresco.repo.module.ModuleVersionNumber) AlfrescoRuntimeException(org.alfresco.error.AlfrescoRuntimeException)

Example 7 with ModuleVersionNumber

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);
        }
    }
}
Also used : ModuleVersionNumber(org.alfresco.repo.module.ModuleVersionNumber)

Example 8 with ModuleVersionNumber

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"));
    }
}
Also used : TFile(de.schlichtherle.truezip.file.TFile) ModuleDetailsImpl(org.alfresco.repo.module.ModuleDetailsImpl) ModuleVersionNumber(org.alfresco.repo.module.ModuleVersionNumber) ModuleDetails(org.alfresco.service.cmr.module.ModuleDetails) VersionNumber(org.alfresco.util.VersionNumber) ModuleVersionNumber(org.alfresco.repo.module.ModuleVersionNumber) Test(org.junit.Test)

Example 9 with ModuleVersionNumber

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);
}
Also used : ModuleVersionNumber(org.alfresco.repo.module.ModuleVersionNumber)

Example 10 with ModuleVersionNumber

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);
}
Also used : ModuleVersionNumber(org.alfresco.repo.module.ModuleVersionNumber)

Aggregations

ModuleVersionNumber (org.alfresco.repo.module.ModuleVersionNumber)15 ModuleDetails (org.alfresco.service.cmr.module.ModuleDetails)4 VersionNumber (org.alfresco.util.VersionNumber)4 TFile (de.schlichtherle.truezip.file.TFile)3 ModuleDetailsImpl (org.alfresco.repo.module.ModuleDetailsImpl)3 Test (org.junit.Test)3 Serializable (java.io.Serializable)2 RegistryKey (org.alfresco.repo.admin.registry.RegistryKey)2 FsSyncException (de.schlichtherle.truezip.fs.FsSyncException)1 IOException (java.io.IOException)1 AlfrescoRuntimeException (org.alfresco.error.AlfrescoRuntimeException)1 RegistryService (org.alfresco.repo.admin.registry.RegistryService)1 ModuleServiceImpl (org.alfresco.repo.module.ModuleServiceImpl)1 ModuleManagementToolException (org.alfresco.repo.module.tool.ModuleManagementToolException)1 RetryingTransactionHelper (org.alfresco.repo.transaction.RetryingTransactionHelper)1 Before (org.junit.Before)1 InvocationOnMock (org.mockito.invocation.InvocationOnMock)1 ApplicationContext (org.springframework.context.ApplicationContext)1 Resource (org.springframework.core.io.Resource)1 PathMatchingResourcePatternResolver (org.springframework.core.io.support.PathMatchingResourcePatternResolver)1