mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-08-07 17:49:17 +00:00
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:
15
source/java/org/alfresco/repo/module/tool/LogOutput.java
Normal file
15
source/java/org/alfresco/repo/module/tool/LogOutput.java
Normal 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);
|
||||||
|
}
|
@@ -52,7 +52,7 @@ import de.schlichtherle.io.ZipWarningException;
|
|||||||
* @author Roy Wetherall
|
* @author Roy Wetherall
|
||||||
* @author Derek Hulley
|
* @author Derek Hulley
|
||||||
*/
|
*/
|
||||||
public class ModuleManagementTool
|
public class ModuleManagementTool implements LogOutput
|
||||||
{
|
{
|
||||||
/** Location of the default mapping properties file */
|
/** Location of the default mapping properties file */
|
||||||
private static final String DEFAULT_FILE_MAPPING_PROPERTIES = "org/alfresco/repo/module/tool/default-file-mapping.properties";
|
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 */
|
/** Indicates the current verbose setting */
|
||||||
private boolean verbose = false;
|
private boolean verbose = false;
|
||||||
|
|
||||||
WarHelper warHelper = new WarHelperImpl();
|
WarHelper warHelper = new WarHelperImpl(this);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor
|
* Constructor
|
||||||
@@ -885,5 +885,11 @@ public class ModuleManagementTool
|
|||||||
System.out.println("uninstall: Uninstalls a module from the Alfresco WAR file.");
|
System.out.println("uninstall: Uninstalls a module from the Alfresco WAR file.");
|
||||||
System.out.println("usage: uninstall <ModuleId> <WARFileLocation>\n");
|
System.out.println("usage: uninstall <ModuleId> <WARFileLocation>\n");
|
||||||
System.out.println("-----------------------------------------------------------\n");
|
System.out.println("-----------------------------------------------------------\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void info(Object message)
|
||||||
|
{
|
||||||
|
outputMessage(String.valueOf(message));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -23,20 +23,34 @@ public class WarHelperImpl implements WarHelper
|
|||||||
{
|
{
|
||||||
|
|
||||||
public static final String VERSION_PROPERTIES = "/WEB-INF/classes/alfresco/version.properties";
|
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
|
@Override
|
||||||
public void checkCompatibleVersion(File war, ModuleDetails installingModuleDetails)
|
public void checkCompatibleVersion(File war, ModuleDetails installingModuleDetails)
|
||||||
{
|
{
|
||||||
//Version check
|
//Version check
|
||||||
File propsFile = getFile(war, VERSION_PROPERTIES);
|
File propsFile = getFile(war, VERSION_PROPERTIES);
|
||||||
Properties warVers = loadProperties(propsFile);
|
if (propsFile != null && propsFile.exists())
|
||||||
VersionNumber warVersion = new VersionNumber(warVers.getProperty("version.major")+"."+warVers.getProperty("version.revision")+"."+warVers.getProperty("version.minor"));
|
{
|
||||||
if(warVersion.compareTo(installingModuleDetails.getRepoVersionMin())==-1) {
|
Properties warVers = loadProperties(propsFile);
|
||||||
throw new ModuleManagementToolException("The module ("+installingModuleDetails.getTitle()+") must be installed on a repo version greater than "+installingModuleDetails.getRepoVersionMin());
|
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) {
|
else
|
||||||
throw new ModuleManagementToolException("The module ("+installingModuleDetails.getTitle()+") cannot be installed on a repo version greater than "+installingModuleDetails.getRepoVersionMax());
|
{
|
||||||
|
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) {
|
if (installableEditions != null && installableEditions.size() > 0) {
|
||||||
|
|
||||||
File propsFile = getFile(war, VERSION_PROPERTIES);
|
File propsFile = getFile(war, VERSION_PROPERTIES);
|
||||||
Properties warVers = loadProperties(propsFile);
|
if (propsFile != null && propsFile.exists())
|
||||||
String warEdition = warVers.getProperty("version.edition");
|
|
||||||
|
|
||||||
for (String edition : installableEditions)
|
|
||||||
{
|
{
|
||||||
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);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -14,6 +14,7 @@ import org.alfresco.repo.module.ModuleDetailsImpl;
|
|||||||
import org.alfresco.service.cmr.module.ModuleDetails;
|
import org.alfresco.service.cmr.module.ModuleDetails;
|
||||||
import org.alfresco.util.TempFileProvider;
|
import org.alfresco.util.TempFileProvider;
|
||||||
import org.alfresco.util.VersionNumber;
|
import org.alfresco.util.VersionNumber;
|
||||||
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.springframework.util.FileCopyUtils;
|
import org.springframework.util.FileCopyUtils;
|
||||||
|
|
||||||
@@ -27,13 +28,18 @@ import de.schlichtherle.io.FileOutputStream;
|
|||||||
public class WarHelperImplTest extends WarHelperImpl
|
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
|
@Test
|
||||||
public void testCheckCompatibleVersion()
|
public void testCheckCompatibleVersion()
|
||||||
{
|
{
|
||||||
@@ -43,7 +49,7 @@ public class WarHelperImplTest extends WarHelperImpl
|
|||||||
installingModuleDetails.setRepoVersionMin(new VersionNumber("10.1"));
|
installingModuleDetails.setRepoVersionMin(new VersionNumber("10.1"));
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
this.warhelper.checkCompatibleVersion(theWar, installingModuleDetails);
|
this.checkCompatibleVersion(theWar, installingModuleDetails);
|
||||||
fail(); //should never get here
|
fail(); //should never get here
|
||||||
}
|
}
|
||||||
catch (ModuleManagementToolException exception)
|
catch (ModuleManagementToolException exception)
|
||||||
@@ -52,12 +58,12 @@ public class WarHelperImplTest extends WarHelperImpl
|
|||||||
}
|
}
|
||||||
|
|
||||||
installingModuleDetails.setRepoVersionMin(new VersionNumber("1.1"));
|
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"));
|
installingModuleDetails.setRepoVersionMax(new VersionNumber("3.0"));
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
this.warhelper.checkCompatibleVersion(theWar, installingModuleDetails);
|
this.checkCompatibleVersion(theWar, installingModuleDetails);
|
||||||
fail(); //should never get here
|
fail(); //should never get here
|
||||||
}
|
}
|
||||||
catch (ModuleManagementToolException exception)
|
catch (ModuleManagementToolException exception)
|
||||||
@@ -66,11 +72,11 @@ public class WarHelperImplTest extends WarHelperImpl
|
|||||||
}
|
}
|
||||||
|
|
||||||
installingModuleDetails.setRepoVersionMax(new VersionNumber("99"));
|
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.setRepoVersionMin(new VersionNumber("4.0.1")); //current war version
|
||||||
installingModuleDetails.setRepoVersionMax(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
|
@Test
|
||||||
@@ -85,7 +91,7 @@ public class WarHelperImplTest extends WarHelperImpl
|
|||||||
File theWar = getFile(".war", "module/test.war"); //Community Edition
|
File theWar = getFile(".war", "module/test.war"); //Community Edition
|
||||||
|
|
||||||
//Test for no edition specified
|
//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
|
//Test for invalid edition
|
||||||
props.setProperty(ModuleDetails.PROP_EDITIONS, "CommuniT");
|
props.setProperty(ModuleDetails.PROP_EDITIONS, "CommuniT");
|
||||||
@@ -93,7 +99,7 @@ public class WarHelperImplTest extends WarHelperImpl
|
|||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
this.warhelper.checkCompatibleEdition(theWar, installingModuleDetails);
|
this.checkCompatibleEdition(theWar, installingModuleDetails);
|
||||||
fail(); //should never get here
|
fail(); //should never get here
|
||||||
}
|
}
|
||||||
catch (ModuleManagementToolException exception)
|
catch (ModuleManagementToolException exception)
|
||||||
@@ -103,17 +109,28 @@ public class WarHelperImplTest extends WarHelperImpl
|
|||||||
|
|
||||||
props.setProperty(ModuleDetails.PROP_EDITIONS, ("CoMMunity")); //should ignore case
|
props.setProperty(ModuleDetails.PROP_EDITIONS, ("CoMMunity")); //should ignore case
|
||||||
installingModuleDetails = new ModuleDetailsImpl(props);
|
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
|
props.setProperty(ModuleDetails.PROP_EDITIONS, ("enterprise,community,bob")); //should ignore case
|
||||||
installingModuleDetails = new ModuleDetailsImpl(props);
|
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
|
props.setProperty(ModuleDetails.PROP_EDITIONS, ("enterprise,Community")); //should ignore case
|
||||||
installingModuleDetails = new ModuleDetailsImpl(props);
|
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)
|
private File getFile(String extension, String location)
|
||||||
{
|
{
|
||||||
File file = TempFileProvider.createTempFile("moduleManagementToolTest-", extension);
|
File file = TempFileProvider.createTempFile("moduleManagementToolTest-", extension);
|
||||||
|
BIN
source/test-resources/module/empty.war
Normal file
BIN
source/test-resources/module/empty.war
Normal file
Binary file not shown.
Reference in New Issue
Block a user