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 ?");
}
}
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));
}
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"));
}
}
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);
}
Aggregations