From c3b86192d64219d388c570626430968e069ce3d0 Mon Sep 17 00:00:00 2001 From: Gethin James Date: Thu, 9 Feb 2012 10:56:44 +0000 Subject: [PATCH] Better fix for ALF-12541 - AMP files need to be able to be pinned to specific "edition(s)" of Alfresco Share doesn't have a version.properties file so I need to cater for that scenario. I didn't want to create the LogOutput interface but its a stop-gap until the MMT gets re-worked. git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@33793 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261 --- .../alfresco/repo/module/tool/LogOutput.java | 15 ++++++ .../module/tool/ModuleManagementTool.java | 10 +++- .../repo/module/tool/WarHelperImpl.java | 47 ++++++++++++----- .../repo/module/tool/WarHelperImplTest.java | 49 ++++++++++++------ source/test-resources/module/empty.war | Bin 0 -> 1399 bytes 5 files changed, 89 insertions(+), 32 deletions(-) create mode 100644 source/java/org/alfresco/repo/module/tool/LogOutput.java create mode 100644 source/test-resources/module/empty.war diff --git a/source/java/org/alfresco/repo/module/tool/LogOutput.java b/source/java/org/alfresco/repo/module/tool/LogOutput.java new file mode 100644 index 0000000000..8077e4ea4a --- /dev/null +++ b/source/java/org/alfresco/repo/module/tool/LogOutput.java @@ -0,0 +1,15 @@ +package org.alfresco.repo.module.tool; + +/** + * I didn't want to create this. The module management tool has an outputMessage method. I needed an implentation-independent way of outputting + * a message from a helper class without relying on a Logging framework or a Module Management Tool Class. + * + * Hopefully this will be removed when the code is refactored. + * + * @author Gethin James + */ +public interface LogOutput +{ + + public void info(Object message); +} diff --git a/source/java/org/alfresco/repo/module/tool/ModuleManagementTool.java b/source/java/org/alfresco/repo/module/tool/ModuleManagementTool.java index 728ad01c4b..0526f88466 100644 --- a/source/java/org/alfresco/repo/module/tool/ModuleManagementTool.java +++ b/source/java/org/alfresco/repo/module/tool/ModuleManagementTool.java @@ -52,7 +52,7 @@ import de.schlichtherle.io.ZipWarningException; * @author Roy Wetherall * @author Derek Hulley */ -public class ModuleManagementTool +public class ModuleManagementTool implements LogOutput { /** Location of the default mapping properties file */ private static final String DEFAULT_FILE_MAPPING_PROPERTIES = "org/alfresco/repo/module/tool/default-file-mapping.properties"; @@ -90,7 +90,7 @@ public class ModuleManagementTool /** Indicates the current verbose setting */ private boolean verbose = false; - WarHelper warHelper = new WarHelperImpl(); + WarHelper warHelper = new WarHelperImpl(this); /** * Constructor @@ -885,5 +885,11 @@ public class ModuleManagementTool System.out.println("uninstall: Uninstalls a module from the Alfresco WAR file."); System.out.println("usage: uninstall \n"); System.out.println("-----------------------------------------------------------\n"); + } + + @Override + public void info(Object message) + { + outputMessage(String.valueOf(message)); } } diff --git a/source/java/org/alfresco/repo/module/tool/WarHelperImpl.java b/source/java/org/alfresco/repo/module/tool/WarHelperImpl.java index 889caf36fe..e16446b998 100644 --- a/source/java/org/alfresco/repo/module/tool/WarHelperImpl.java +++ b/source/java/org/alfresco/repo/module/tool/WarHelperImpl.java @@ -23,20 +23,34 @@ public class WarHelperImpl implements WarHelper { public static final String VERSION_PROPERTIES = "/WEB-INF/classes/alfresco/version.properties"; + private LogOutput log = null; + public WarHelperImpl(LogOutput log) + { + super(); + this.log = log; + } + @Override public void checkCompatibleVersion(File war, ModuleDetails installingModuleDetails) { //Version check File propsFile = getFile(war, VERSION_PROPERTIES); - Properties warVers = loadProperties(propsFile); - VersionNumber warVersion = new VersionNumber(warVers.getProperty("version.major")+"."+warVers.getProperty("version.revision")+"."+warVers.getProperty("version.minor")); - if(warVersion.compareTo(installingModuleDetails.getRepoVersionMin())==-1) { - throw new ModuleManagementToolException("The module ("+installingModuleDetails.getTitle()+") must be installed on a repo version greater than "+installingModuleDetails.getRepoVersionMin()); + if (propsFile != null && propsFile.exists()) + { + Properties warVers = loadProperties(propsFile); + VersionNumber warVersion = new VersionNumber(warVers.getProperty("version.major")+"."+warVers.getProperty("version.revision")+"."+warVers.getProperty("version.minor")); + if(warVersion.compareTo(installingModuleDetails.getRepoVersionMin())==-1) { + throw new ModuleManagementToolException("The module ("+installingModuleDetails.getTitle()+") must be installed on a repo version greater than "+installingModuleDetails.getRepoVersionMin()); + } + if(warVersion.compareTo(installingModuleDetails.getRepoVersionMax())==1) { + throw new ModuleManagementToolException("The module ("+installingModuleDetails.getTitle()+") cannot be installed on a repo version greater than "+installingModuleDetails.getRepoVersionMax()); + } } - if(warVersion.compareTo(installingModuleDetails.getRepoVersionMax())==1) { - throw new ModuleManagementToolException("The module ("+installingModuleDetails.getTitle()+") cannot be installed on a repo version greater than "+installingModuleDetails.getRepoVersionMax()); + else + { + log.info("No valid version found, is this a share war?"); } } @@ -49,18 +63,23 @@ public class WarHelperImpl implements WarHelper if (installableEditions != null && installableEditions.size() > 0) { File propsFile = getFile(war, VERSION_PROPERTIES); - Properties warVers = loadProperties(propsFile); - String warEdition = warVers.getProperty("version.edition"); - - for (String edition : installableEditions) + if (propsFile != null && propsFile.exists()) { - if (warEdition.equalsIgnoreCase(edition)) + Properties warVers = loadProperties(propsFile); + String warEdition = warVers.getProperty("version.edition"); + + for (String edition : installableEditions) { - return; //successful match. + if (warEdition.equalsIgnoreCase(edition)) + { + return; //successful match. + } } + 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?"); } - throw new ModuleManagementToolException("The module ("+installingModuleDetails.getTitle() - +") can only be installed in one of the following editions"+installableEditions); } } diff --git a/source/java/org/alfresco/repo/module/tool/WarHelperImplTest.java b/source/java/org/alfresco/repo/module/tool/WarHelperImplTest.java index 0ded4ca9b9..f48838e50b 100644 --- a/source/java/org/alfresco/repo/module/tool/WarHelperImplTest.java +++ b/source/java/org/alfresco/repo/module/tool/WarHelperImplTest.java @@ -14,6 +14,7 @@ import org.alfresco.repo.module.ModuleDetailsImpl; import org.alfresco.service.cmr.module.ModuleDetails; import org.alfresco.util.TempFileProvider; import org.alfresco.util.VersionNumber; +import org.junit.Before; import org.junit.Test; import org.springframework.util.FileCopyUtils; @@ -27,13 +28,18 @@ import de.schlichtherle.io.FileOutputStream; public class WarHelperImplTest extends WarHelperImpl { - private WarHelper warhelper = new WarHelperImpl(); + public WarHelperImplTest() + { + super(new LogOutput() + { + @Override + public void info(Object message) + { + System.out.println(message); + } + }); + } -// @Before -// public void setUp() throws Exception -// { -// } - @Test public void testCheckCompatibleVersion() { @@ -43,7 +49,7 @@ public class WarHelperImplTest extends WarHelperImpl installingModuleDetails.setRepoVersionMin(new VersionNumber("10.1")); try { - this.warhelper.checkCompatibleVersion(theWar, installingModuleDetails); + this.checkCompatibleVersion(theWar, installingModuleDetails); fail(); //should never get here } catch (ModuleManagementToolException exception) @@ -52,12 +58,12 @@ public class WarHelperImplTest extends WarHelperImpl } installingModuleDetails.setRepoVersionMin(new VersionNumber("1.1")); - this.warhelper.checkCompatibleVersion(theWar, installingModuleDetails); //does not throw exception + this.checkCompatibleVersion(theWar, installingModuleDetails); //does not throw exception installingModuleDetails.setRepoVersionMax(new VersionNumber("3.0")); try { - this.warhelper.checkCompatibleVersion(theWar, installingModuleDetails); + this.checkCompatibleVersion(theWar, installingModuleDetails); fail(); //should never get here } catch (ModuleManagementToolException exception) @@ -66,11 +72,11 @@ public class WarHelperImplTest extends WarHelperImpl } installingModuleDetails.setRepoVersionMax(new VersionNumber("99")); - this.warhelper.checkCompatibleVersion(theWar, installingModuleDetails); //does not throw exception + this.checkCompatibleVersion(theWar, installingModuleDetails); //does not throw exception installingModuleDetails.setRepoVersionMin(new VersionNumber("4.0.1")); //current war version installingModuleDetails.setRepoVersionMax(new VersionNumber("4.0.1")); //current war version - this.warhelper.checkCompatibleVersion(theWar, installingModuleDetails); //does not throw exception + this.checkCompatibleVersion(theWar, installingModuleDetails); //does not throw exception } @Test @@ -85,7 +91,7 @@ public class WarHelperImplTest extends WarHelperImpl File theWar = getFile(".war", "module/test.war"); //Community Edition //Test for no edition specified - this.warhelper.checkCompatibleEdition(theWar, installingModuleDetails); //does not throw exception + this.checkCompatibleEdition(theWar, installingModuleDetails); //does not throw exception //Test for invalid edition props.setProperty(ModuleDetails.PROP_EDITIONS, "CommuniT"); @@ -93,7 +99,7 @@ public class WarHelperImplTest extends WarHelperImpl try { - this.warhelper.checkCompatibleEdition(theWar, installingModuleDetails); + this.checkCompatibleEdition(theWar, installingModuleDetails); fail(); //should never get here } catch (ModuleManagementToolException exception) @@ -103,17 +109,28 @@ public class WarHelperImplTest extends WarHelperImpl props.setProperty(ModuleDetails.PROP_EDITIONS, ("CoMMunity")); //should ignore case installingModuleDetails = new ModuleDetailsImpl(props); - this.warhelper.checkCompatibleEdition(theWar, installingModuleDetails); //does not throw exception + this.checkCompatibleEdition(theWar, installingModuleDetails); //does not throw exception props.setProperty(ModuleDetails.PROP_EDITIONS, ("enterprise,community,bob")); //should ignore case installingModuleDetails = new ModuleDetailsImpl(props); - this.warhelper.checkCompatibleEdition(theWar, installingModuleDetails); //does not throw exception + this.checkCompatibleEdition(theWar, installingModuleDetails); //does not throw exception props.setProperty(ModuleDetails.PROP_EDITIONS, ("enterprise,Community")); //should ignore case installingModuleDetails = new ModuleDetailsImpl(props); - this.warhelper.checkCompatibleVersion(theWar, installingModuleDetails); //does not throw exception + this.checkCompatibleVersion(theWar, installingModuleDetails); //does not throw exception } + @Test + public void testNoVersionProperties() + { + File theWar = getFile(".war", "module/empty.war"); + + ModuleDetails installingModuleDetails = new ModuleDetailsImpl("test_it", new VersionNumber("9999"), "Test Mod", "Testing module"); + installingModuleDetails.setRepoVersionMin(new VersionNumber("10.1")); + this.checkCompatibleVersion(theWar, installingModuleDetails); //does not throw exception + this.checkCompatibleEdition(theWar, installingModuleDetails); //does not throw exception + + } private File getFile(String extension, String location) { File file = TempFileProvider.createTempFile("moduleManagementToolTest-", extension); diff --git a/source/test-resources/module/empty.war b/source/test-resources/module/empty.war new file mode 100644 index 0000000000000000000000000000000000000000..dde86182eae5f1fbd8c06a2577bf18d79b8114ec GIT binary patch literal 1399 zcmWIWW@h1HW&i@E77a5H4FjA&hOcXgqpqi)n|=ULnFvrB2ZJO~8O!bGmy?0gSwJj; ztjyQZ&(qB{I7H9a&G*zsK34;ghKGAS??3GM&X=nd*vvcmpvp$CtAesJmx7zOA5Z)H zZ-23f*pnq}Ju+olikIEGy6l2v&#mX^x7~OltV?Z?x5esTRrRaSW)zu9a_|4A@}jBV zI(|+;a>mKm`$dB8ARHwCbQD*z{kL;KC$8sUU;w#2GcP5zLNBYhU}^wxdpNq%1YF~MZjDz6h_OAO4UGtVrM6Xe?_`p-Le&pA^ob}{?u zr-D8`Vc4W`!b45U@ibQt>&(a{=J^dp;bE0i)3^V&P2aX}l33#680MdAe(+5#N@ok1 zdgk|DN0GxiatAJJ%saaM;oqFEMH}M|{?6Fh^KA7^leVKmYTZ9K-^|)Jb~y$uo{b^cD1`}u~;=W5u}zw@S5hMnS3G``X~rz`VD z`5h7W7iJ4YO`VIl@0{=I(_L1^-+o=*xW0d#ePdH{U|sUx3I`wV@CdG5TZ{UqZk+GZ z+Ueo@?qj$3I-MH+Yx|e_s33p7M{hTF z?5O-V*`pNx_qE2vv%^1ncLj2|K59%!)OVE&4sVK&3cVJ*m-+4-F<9! z*kEno*8VlA>T~n*cVC|Izu4BDUP%T%^H`fyd!)wYWCz~^ies-oGK1iejZT&4P(!Md_@Nvn#M&8Drg(+{_Q zXxX{quSCL!)vUr7tG*U_6 zebDX)T?HNDuQT`jI&e|^^vzdFEgvPerF13UcwcKhsU%1|F<g*$t{(0FdrQ-KI zW0MS4s8`-Fj4N-{w&=Wf?V^f(=2?H?Pe0@SZ+yOUTF3S7Y4gp+FTQ?$I@2byWNG=v zTe~ura$l-Zi9Bt7x-6FYpVgw((f9j4M87O|oqG7&a}yiyBm4p0j7%cTxQi@c&Iba4hPRF&8mRySX~SKF zffO?^C^Rf-R0q;