From 5c6e93521c4d0ede16d3c9fa22eb27286ba3305d Mon Sep 17 00:00:00 2001 From: Gethin James Date: Wed, 17 Oct 2012 11:47:02 +0000 Subject: [PATCH] Removed dependency on commons StringUtils and cleaned up the warning message git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@42716 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261 --- .../repo/module/tool/WarHelperImpl.java | 20 +++++++++++------- .../repo/module/tool/WarHelperImplTest.java | 21 +++++++++++++++++++ 2 files changed, 33 insertions(+), 8 deletions(-) diff --git a/source/java/org/alfresco/repo/module/tool/WarHelperImpl.java b/source/java/org/alfresco/repo/module/tool/WarHelperImpl.java index fca44f013b..60ffd9f05e 100644 --- a/source/java/org/alfresco/repo/module/tool/WarHelperImpl.java +++ b/source/java/org/alfresco/repo/module/tool/WarHelperImpl.java @@ -13,7 +13,6 @@ import org.alfresco.repo.module.ModuleDetailsImpl; import org.alfresco.service.cmr.module.ModuleDependency; import org.alfresco.service.cmr.module.ModuleDetails; import org.alfresco.util.VersionNumber; -import org.apache.commons.lang.StringUtils; import de.schlichtherle.truezip.file.TFile; import de.schlichtherle.truezip.file.TFileInputStream; @@ -36,6 +35,7 @@ public class WarHelperImpl implements WarHelper public static final String MANIFEST_SHARE = "Alfresco Share"; public static final String MANIFEST_COMMUNITY = "Community"; + protected static final String REGEX_NUMBER_OR_DOT = "[0-9\\.]*"; private LogOutput log = null; @@ -72,9 +72,9 @@ public class WarHelperImpl implements WarHelper protected void checkCompatibleVersionUsingManifest(TFile war, ModuleDetails installingModuleDetails) { String version = findManifestArtibute(war, MANIFEST_SPECIFICATION_VERSION); - if (StringUtils.isNotBlank(version)) - { - if (StringUtils.containsOnly(version, "0123456789.")) { + if (version != null && version.length() > 0) + { + if (version.matches(REGEX_NUMBER_OR_DOT)) { VersionNumber warVersion = new VersionNumber(version); checkVersions(warVersion, installingModuleDetails); } @@ -93,7 +93,11 @@ public class WarHelperImpl implements WarHelper } } - } + } + 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 ?"); + } } /** @@ -158,7 +162,7 @@ public class WarHelperImpl implements WarHelper throw new ModuleManagementToolException("The module ("+installingModuleDetails.getTitle() +") can only be installed in one of the following editions"+installableEditions); } else { - log.info("No valid editions found, is this a share war?"); + checkCompatibleEditionUsingManifest(war,installingModuleDetails); } } } @@ -177,7 +181,7 @@ public class WarHelperImpl implements WarHelper if (installableEditions != null && installableEditions.size() > 0) { String warEdition = findManifestArtibute(war, MANIFEST_IMPLEMENTATION_TITLE); - if (StringUtils.isNotBlank(warEdition)) + if (warEdition != null && warEdition.length() > 0) { warEdition = warEdition.toLowerCase(); for (String edition : installableEditions) @@ -190,7 +194,7 @@ public class WarHelperImpl implements WarHelper throw new ModuleManagementToolException("The module ("+installingModuleDetails.getTitle() +") can only be installed in one of the following editions"+installableEditions); } else { - log.info("No valid editions found in the manifest. Is this war prior to 3.4.11, 4.1.1 and Community 4.2 ?"); + log.info("WARNING: No edition information detected in war, edition validation is disabled, continuing anyway. Is this war prior to 3.4.11, 4.1.1 and Community 4.2 ?"); } } } diff --git a/source/java/org/alfresco/repo/module/tool/WarHelperImplTest.java b/source/java/org/alfresco/repo/module/tool/WarHelperImplTest.java index 40c345f8d9..0a7cc1321d 100644 --- a/source/java/org/alfresco/repo/module/tool/WarHelperImplTest.java +++ b/source/java/org/alfresco/repo/module/tool/WarHelperImplTest.java @@ -37,6 +37,27 @@ public class WarHelperImplTest extends WarHelperImpl }); } + @Test + public void testRegEx() + { + String x = "1"; + assertTrue(x.matches(REGEX_NUMBER_OR_DOT)); + x = "king"; + assertFalse(x.matches(REGEX_NUMBER_OR_DOT)); + x = "2.5.a"; + assertFalse(x.matches(REGEX_NUMBER_OR_DOT)); + x = "1.2.5"; + assertTrue(x.matches(REGEX_NUMBER_OR_DOT)); + x = "123"; + assertTrue(x.matches(REGEX_NUMBER_OR_DOT)); + x = "3.4.11"; + assertTrue(x.matches(REGEX_NUMBER_OR_DOT)); + x = "4.1.1"; + assertTrue(x.matches(REGEX_NUMBER_OR_DOT)); + x = "4.2.b"; + assertFalse(x.matches(REGEX_NUMBER_OR_DOT)); + + } @Test public void testCheckCompatibleVersion() {