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 0000000000..dde86182ea Binary files /dev/null and b/source/test-resources/module/empty.war differ