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
This commit is contained in:
Gethin James
2012-02-09 10:56:44 +00:00
parent 18e406eaa8
commit c3b86192d6
5 changed files with 89 additions and 32 deletions

View File

@@ -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);
}

View File

@@ -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
@@ -886,4 +886,10 @@ public class ModuleManagementTool
System.out.println("usage: uninstall <ModuleId> <WARFileLocation>\n");
System.out.println("-----------------------------------------------------------\n");
}
@Override
public void info(Object message)
{
outputMessage(String.valueOf(message));
}
}

View File

@@ -23,13 +23,22 @@ 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);
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) {
@@ -39,6 +48,11 @@ public class WarHelperImpl implements WarHelper
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?");
}
}
@Override
public void checkCompatibleEdition(File war, ModuleDetails installingModuleDetails)
@@ -49,6 +63,8 @@ public class WarHelperImpl implements WarHelper
if (installableEditions != null && installableEditions.size() > 0) {
File propsFile = getFile(war, VERSION_PROPERTIES);
if (propsFile != null && propsFile.exists())
{
Properties warVers = loadProperties(propsFile);
String warEdition = warVers.getProperty("version.edition");
@@ -61,6 +77,9 @@ 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?");
}
}
}

View File

@@ -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,12 +28,17 @@ import de.schlichtherle.io.FileOutputStream;
public class WarHelperImplTest extends WarHelperImpl
{
private WarHelper warhelper = new WarHelperImpl();
// @Before
// public void setUp() throws Exception
// {
// }
public WarHelperImplTest()
{
super(new LogOutput()
{
@Override
public void info(Object message)
{
System.out.println(message);
}
});
}
@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);

Binary file not shown.