Search in sources :

Example 6 with VersionNumber

use of org.alfresco.util.VersionNumber in project alfresco-repository by Alfresco.

the class WarHelperImpl method checkCompatibleVersionUsingManifest.

/**
 * Checks if the module is compatible using the entry in the manifest. This is more accurate and works for both alfresco.war and share.war, however
 * valid manifest entries weren't added until 3.4.11, 4.1.1 and Community 4.2
 * @param war TFile
 * @param installingModuleDetails ModuleDetails
 */
protected void checkCompatibleVersionUsingManifest(TFile war, ModuleDetails installingModuleDetails) {
    String version = findManifestArtibute(war, MANIFEST_SPECIFICATION_VERSION);
    if (version != null && version.length() > 0) {
        if (version.matches(REGEX_NUMBER_OR_DOT)) {
            VersionNumber warVersion = new VersionNumber(version);
            checkVersions(warVersion, installingModuleDetails);
        } else {
            // A non-numeric version number.  Currently our VersionNumber class doesn't support Strings in the version
            String edition = findManifestArtibute(war, MANIFEST_IMPLEMENTATION_TITLE);
            if (edition.endsWith(MANIFEST_COMMUNITY)) {
                // If it's a community version, so don't worry about it
                log.info("WARNING: Community edition war detected, the version number is non-numeric so we will not validate it.");
            } else {
                throw new ModuleManagementToolException("Invalid version number specified: " + version);
            }
        }
    } else {
        log.info("WARNING: No version information detected in war, therefore version validation is disabled, continuing anyway.  Is this war prior to 3.4.11, 4.1.1 and Community 4.2 ?");
    }
}
Also used : VersionNumber(org.alfresco.util.VersionNumber)

Example 7 with VersionNumber

use of org.alfresco.util.VersionNumber in project alfresco-repository by Alfresco.

the class VersionLabelComparator method compare.

public int compare(Version version1, Version version2) {
    String labelV1 = version1.getVersionLabel();
    String labelV2 = version2.getVersionLabel();
    // sort the list descending (ie. most recent first)
    return new VersionNumber(labelV2).compareTo(new VersionNumber(labelV1));
}
Also used : VersionNumber(org.alfresco.util.VersionNumber)

Example 8 with VersionNumber

use of org.alfresco.util.VersionNumber 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 VersionNumber

use of org.alfresco.util.VersionNumber in project alfresco-repository by Alfresco.

the class WarHelperImplTest method testCheckCompatibleVersionUsingManifest.

@Test
public void testCheckCompatibleVersionUsingManifest() throws IOException {
    // Now check the compatible versions using the manifest
    TFile theWar = getFile(".war", "module/share-3.4.11.war");
    ModuleDetails installingModuleDetails = new ModuleDetailsImpl("test_it", new ModuleVersionNumber("9999"), "Test Mod", "Testing module");
    installingModuleDetails.setRepoVersionMin(new VersionNumber("10.1"));
    try {
        this.checkCompatibleVersionUsingManifest(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.checkCompatibleVersionUsingManifest(theWar, installingModuleDetails);
    installingModuleDetails.setRepoVersionMax(new VersionNumber("3.0"));
    try {
        this.checkCompatibleVersionUsingManifest(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.checkCompatibleVersionUsingManifest(theWar, installingModuleDetails);
    // current war version
    installingModuleDetails.setRepoVersionMin(new VersionNumber("3.4.11"));
    // current war version
    installingModuleDetails.setRepoVersionMax(new VersionNumber("3.4.11"));
    // does not throw exception
    this.checkCompatibleVersionUsingManifest(theWar, installingModuleDetails);
    // current war version
    installingModuleDetails.setRepoVersionMin(new VersionNumber("3.4.7"));
    // current war version
    installingModuleDetails.setRepoVersionMax(new VersionNumber("3.4.11"));
    // does not throw exception
    this.checkCompatibleVersionUsingManifest(theWar, installingModuleDetails);
    try {
        // current war version
        installingModuleDetails.setRepoVersionMin(new VersionNumber("3.4.0"));
        // current war version
        installingModuleDetails.setRepoVersionMax(new VersionNumber("3.4.10"));
        // does not throw exception
        this.checkCompatibleVersionUsingManifest(theWar, installingModuleDetails);
        // should never get here
        fail("Should not pass as current version is 3.4.11 and the max value is 3.4.10");
    } catch (ModuleManagementToolException exception) {
        assertTrue(exception.getMessage().contains("cannot be installed on a war version greater than 3.4.10"));
    }
    theWar = getFile(".war", "module/share-4.2.a.war");
    installingModuleDetails = new ModuleDetailsImpl("test_it", new ModuleVersionNumber("9999"), "Test Mod", "Testing module");
    installingModuleDetails.setRepoVersionMin(new VersionNumber("101.1"));
    // this should fail BUT we are using a non-numeric version number so instead it passes without validation
    this.checkCompatibleVersionUsingManifest(theWar, installingModuleDetails);
    theWar = getFile(".war", "module/alfresco-4.2.a.war");
    // this should fail BUT we are using a non-numeric version number so instead it passes without validation
    this.checkCompatibleVersionUsingManifest(theWar, installingModuleDetails);
}
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)

Aggregations

VersionNumber (org.alfresco.util.VersionNumber)9 TFile (de.schlichtherle.truezip.file.TFile)4 ModuleVersionNumber (org.alfresco.repo.module.ModuleVersionNumber)4 ModuleDetails (org.alfresco.service.cmr.module.ModuleDetails)4 ModuleDetailsImpl (org.alfresco.repo.module.ModuleDetailsImpl)3 Test (org.junit.Test)3 Serializable (java.io.Serializable)1 Properties (java.util.Properties)1 AlfrescoRuntimeException (org.alfresco.error.AlfrescoRuntimeException)1 RegistryKey (org.alfresco.repo.admin.registry.RegistryKey)1 ModuleManagementToolException (org.alfresco.repo.module.tool.ModuleManagementToolException)1 ModuleDependency (org.alfresco.service.cmr.module.ModuleDependency)1