diff --git a/source/java/org/alfresco/repo/module/ModuleComponentHelper.java b/source/java/org/alfresco/repo/module/ModuleComponentHelper.java index eeb0e68c66..ffad4e565e 100644 --- a/source/java/org/alfresco/repo/module/ModuleComponentHelper.java +++ b/source/java/org/alfresco/repo/module/ModuleComponentHelper.java @@ -270,7 +270,7 @@ public class ModuleComponentHelper private void startModule(ModuleDetails module, Set executedComponents) { String moduleId = module.getId(); - VersionNumber moduleVersion = module.getVersionNumber(); + VersionNumber moduleVersion = module.getVersion(); // Get the module details from the registry RegistryKey moduleKeyInstalledVersion = new RegistryKey( ModuleComponentHelper.URI_MODULES_1_0, @@ -336,7 +336,7 @@ public class ModuleComponentHelper } // Check the version applicability - VersionNumber moduleVersion = module.getVersionNumber(); + VersionNumber moduleVersion = module.getVersion(); VersionNumber minVersion = component.getAppliesFromVersionNumber(); VersionNumber maxVersion = component.getAppliesToVersionNumber(); if (moduleVersion.compareTo(minVersion) < 0 || moduleVersion.compareTo(maxVersion) > 0) diff --git a/source/java/org/alfresco/repo/module/ModuleDetailsImpl.java b/source/java/org/alfresco/repo/module/ModuleDetailsImpl.java index 7deee1582c..3aaa053ada 100644 --- a/source/java/org/alfresco/repo/module/ModuleDetailsImpl.java +++ b/source/java/org/alfresco/repo/module/ModuleDetailsImpl.java @@ -24,13 +24,15 @@ */ package org.alfresco.repo.module; -import java.io.IOException; -import java.io.InputStream; +import java.util.ArrayList; +import java.util.Date; +import java.util.List; import java.util.Properties; -import org.alfresco.repo.module.tool.ModuleManagementToolException; +import org.alfresco.error.AlfrescoRuntimeException; import org.alfresco.service.cmr.module.ModuleDetails; import org.alfresco.service.cmr.module.ModuleInstallState; +import org.alfresco.util.ISO8601DateFormat; import org.alfresco.util.VersionNumber; /** @@ -42,42 +44,82 @@ import org.alfresco.util.VersionNumber; */ public class ModuleDetailsImpl implements ModuleDetails { - /** Property names */ - protected static final String PROP_ID = "module.id"; - protected static final String PROP_TITLE = "module.title"; - protected static final String PROP_DESCRIPTION = "module.description"; - protected static final String PROP_VERSION = "module.version"; - protected static final String PROP_INSTALL_DATE = "module.installDate"; - protected static final String PROP_INSTALL_STATE = "module.installState"; - - /** Properties object */ - protected Properties properties; + private String id; + private VersionNumber version; + private String title; + private String description; + private VersionNumber repoVersionMin; + private VersionNumber repoVersionMax; + private Date installDate; + private ModuleInstallState installState; /** - * Constructor - * - * @param is input stream, which will be closed + * @param properties the set of properties */ - public ModuleDetailsImpl(InputStream is) + public ModuleDetailsImpl(Properties properties) { - try + // Check that the required properties are present + List missingProperties = new ArrayList(1); + // ID + id = properties.getProperty(PROP_ID); + if (id == null) { missingProperties.add(PROP_ID); } + // VERSION + if (properties.getProperty(PROP_VERSION) == null) { - this.properties = new Properties(); - this.properties.load(is); + missingProperties.add(PROP_VERSION); } - catch (IOException exception) + else { - throw new ModuleManagementToolException("Unable to load module details from property file.", exception); + version = new VersionNumber(properties.getProperty(PROP_VERSION)); } - finally + // TITLE + title = properties.getProperty(PROP_TITLE); + if (title == null) { missingProperties.add(PROP_TITLE); } + // DESCRIPTION + description = properties.getProperty(PROP_DESCRIPTION); + if (description == null) { missingProperties.add(PROP_DESCRIPTION); } + // REPO MIN + if (properties.getProperty(PROP_REPO_VERSION_MIN) == null) { - try { is.close(); } catch (IOException e) { e.printStackTrace(); } + repoVersionMin = new VersionNumber("0.0.0"); } + else + { + repoVersionMin = new VersionNumber(properties.getProperty(PROP_REPO_VERSION_MIN)); + } + // REPO MAX + if (properties.getProperty(PROP_REPO_VERSION_MAX) == null) + { + repoVersionMax = new VersionNumber("999.999.999"); + } + else + { + repoVersionMax = new VersionNumber(properties.getProperty(PROP_REPO_VERSION_MAX)); + } + // INSTALL DATE + if (properties.getProperty(PROP_INSTALL_DATE) != null) + { + String installDateStr = properties.getProperty(PROP_INSTALL_DATE); + try + { + installDate = ISO8601DateFormat.parse(installDateStr); + } + catch (Throwable e) + { + throw new AlfrescoRuntimeException("Unable to parse install date: " + installDateStr, e); + } + } + // Check + if (missingProperties.size() > 0) + { + throw new AlfrescoRuntimeException("The following module properties need to be defined: " + missingProperties); + } + + // Set other defaults + installState = ModuleInstallState.INSTALLED; } /** - * Constructor - * * @param id module id * @param versionNumber version number * @param title title @@ -85,81 +127,96 @@ public class ModuleDetailsImpl implements ModuleDetails */ public ModuleDetailsImpl(String id, VersionNumber versionNumber, String title, String description) { - this.properties = new Properties(); - this.properties.setProperty(PROP_ID, id); - this.properties.setProperty(PROP_VERSION, versionNumber.toString()); - this.properties.setProperty(PROP_TITLE, title); - this.properties.setProperty(PROP_DESCRIPTION, description); + this.id = id; + this.version = versionNumber; + this.title = title; + this.description = description; } - /** - * @see org.alfresco.service.cmr.module.ModuleDetails#exists() - */ - public boolean exists() + public Properties getProperties() { - return (this.properties != null); - } - - /** - * @see org.alfresco.service.cmr.module.ModuleDetails#getId() - */ - public String getId() - { - return this.properties.getProperty(PROP_ID); - } - - /** - * @see org.alfresco.service.cmr.module.ModuleDetails#getVersionNumber() - */ - public VersionNumber getVersionNumber() - { - return new VersionNumber(this.properties.getProperty(PROP_VERSION)); - } - - /** - * @see org.alfresco.service.cmr.module.ModuleDetails#getTitle() - */ - public String getTitle() - { - return this.properties.getProperty(PROP_TITLE); - } - - /** - * @see org.alfresco.service.cmr.module.ModuleDetails#getDescription() - */ - public String getDescription() - { - return this.properties.getProperty(PROP_DESCRIPTION); - } - - /** - * @see org.alfresco.service.cmr.module.ModuleDetails#getInstalledDate() - */ - public String getInstalledDate() - { - return this.properties.getProperty(PROP_INSTALL_DATE); - } - - /** - * @see org.alfresco.service.cmr.module.ModuleDetails#getInstallState() - */ - public ModuleInstallState getInstallState() - { - ModuleInstallState result = ModuleInstallState.INSTALLED; - String value = this.properties.getProperty(PROP_INSTALL_STATE); - if (value != null && value.length() != 0) + Properties properties = new Properties(); + // Mandatory properties + properties.setProperty(PROP_ID, id); + properties.setProperty(PROP_VERSION, version.toString()); + properties.setProperty(PROP_TITLE, title); + properties.setProperty(PROP_DESCRIPTION, description); + // Optional properites + if (repoVersionMin != null) { - result = ModuleInstallState.valueOf(value); + properties.setProperty(PROP_REPO_VERSION_MIN, repoVersionMin.toString()); } - return result; + if (repoVersionMax != null) + { + properties.setProperty(PROP_REPO_VERSION_MAX, repoVersionMax.toString()); + } + if (installDate != null) + { + String installDateStr = ISO8601DateFormat.format(installDate); + properties.setProperty(PROP_INSTALL_DATE, installDateStr); + } + if (installState != null) + { + String installStateStr = installState.toString(); + properties.setProperty(PROP_INSTALL_STATE, installStateStr); + } + // Done + return properties; } - /** - * @see java.lang.Object#toString() - */ @Override public String toString() { - return getId(); + return "ModuleDetails[" + getProperties() + "]"; + } + + public String getId() + { + return id; + } + + public VersionNumber getVersion() + { + return version; + } + + public String getTitle() + { + return title; + } + + public String getDescription() + { + return description; + } + + public VersionNumber getRepoVersionMin() + { + return repoVersionMin; + } + + public VersionNumber getRepoVersionMax() + { + return repoVersionMax; + } + + public Date getInstallDate() + { + return installDate; + } + + public void setInstallDate(Date installDate) + { + this.installDate = installDate; + } + + public ModuleInstallState getInstallState() + { + return installState; + } + + public void setInstallState(ModuleInstallState installState) + { + this.installState = installState; } } diff --git a/source/java/org/alfresco/repo/module/ModuleServiceImpl.java b/source/java/org/alfresco/repo/module/ModuleServiceImpl.java index 21a6efe958..de26ee50d5 100644 --- a/source/java/org/alfresco/repo/module/ModuleServiceImpl.java +++ b/source/java/org/alfresco/repo/module/ModuleServiceImpl.java @@ -32,6 +32,7 @@ import java.util.Collection; import java.util.HashMap; import java.util.List; import java.util.Map; +import java.util.Properties; import org.alfresco.error.AlfrescoRuntimeException; import org.alfresco.repo.admin.registry.RegistryService; @@ -176,7 +177,9 @@ public class ModuleServiceImpl implements ModuleService try { InputStream is = new BufferedInputStream(resource.getInputStream()); - ModuleDetails details = new ModuleDetailsImpl(is); + Properties properties = new Properties(); + properties.load(is); + ModuleDetails details = new ModuleDetailsImpl(properties); moduleDetailsById.put(details.getId(), details); } catch (Throwable e) diff --git a/source/java/org/alfresco/repo/module/tool/ModuleDetailsHelper.java b/source/java/org/alfresco/repo/module/tool/ModuleDetailsHelper.java index 1a6210a333..69229afdfb 100644 --- a/source/java/org/alfresco/repo/module/tool/ModuleDetailsHelper.java +++ b/source/java/org/alfresco/repo/module/tool/ModuleDetailsHelper.java @@ -27,10 +27,10 @@ package org.alfresco.repo.module.tool; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; -import java.util.Date; +import java.util.Properties; import org.alfresco.repo.module.ModuleDetailsImpl; -import org.alfresco.service.cmr.module.ModuleInstallState; +import org.alfresco.service.cmr.module.ModuleDetails; import de.schlichtherle.io.File; import de.schlichtherle.io.FileInputStream; @@ -40,34 +40,45 @@ import de.schlichtherle.io.FileOutputStream; * Module details helper used by the module mangement tool * * @author Roy Wetherall + * @author Derek Hulley */ -public class ModuleDetailsHelper extends ModuleDetailsImpl -{ +public class ModuleDetailsHelper +{ /** - * Constructor - * - * @param is input stream + * Factory method to create module details from a stream of a properties file + * @param is the properties input stream, which will be closed during the call + * @return Returns the initialized module details */ - public ModuleDetailsHelper(InputStream is) + public static ModuleDetails createModuleDetailsFromPropertiesStream(InputStream is) throws IOException { - super(is); + try + { + Properties properties = new Properties(); + properties.load(is); + return new ModuleDetailsImpl(properties); + } + finally + { + try { is.close(); } catch (Throwable e) {} + } } /** * Creates a module details helper object based on a file location. * * @param location file location - * @return module details helper object + * @return Returns the module details or null if the location points to nothing */ - public static ModuleDetailsHelper create(String location) + public static ModuleDetails createModuleDetailsFromPropertyLocation(String location) { - ModuleDetailsHelper result = null; + ModuleDetails result = null; try { File file = new File(location, ModuleManagementTool.DETECTOR_AMP_AND_WAR); if (file.exists() == true) { - result = new ModuleDetailsHelper(new FileInputStream(file)); + InputStream is = new FileInputStream(file); + result = createModuleDetailsFromPropertiesStream(is); } } catch (IOException exception) @@ -78,15 +89,17 @@ public class ModuleDetailsHelper extends ModuleDetailsImpl } /** - * Creates a module details helper object based on a war location and the module id + * Creates a module details instance based on a war location and the module id * * @param warLocation the war location * @param moduleId the module id - * @return the module details helper + * @return Returns the module details for the given module ID as it occurs in the WAR, or null + * if there are no module details available. */ - public static ModuleDetailsHelper create(String warLocation, String moduleId) + public static ModuleDetails createModuleDetailsFromWarAndId(String warLocation, String moduleId) { - return ModuleDetailsHelper.create(ModuleDetailsHelper.getModulePropertiesFileLocation(warLocation, moduleId)); + String modulePropertiesFileLocation = ModuleDetailsHelper.getModulePropertiesFileLocation(warLocation, moduleId); + return ModuleDetailsHelper.createModuleDetailsFromPropertyLocation(modulePropertiesFileLocation); } /** @@ -102,27 +115,30 @@ public class ModuleDetailsHelper extends ModuleDetailsImpl } /** - * Saves the module detailsin to the war in the correct location based on the module id + * Saves the module details to the war in the correct location based on the module id * * @param warLocation the war location * @param moduleId the module id */ - public void save(String warLocation, String moduleId) + public static void saveModuleDetails(String warLocation, ModuleDetails moduleDetails) { + // Ensure that it is a valid set of properties + String moduleId = moduleDetails.getId(); try { - File file = new File(getModulePropertiesFileLocation(warLocation, moduleId), ModuleManagementTool.DETECTOR_AMP_AND_WAR); + String modulePropertiesFileLocation = getModulePropertiesFileLocation(warLocation, moduleId); + File file = new File(modulePropertiesFileLocation, ModuleManagementTool.DETECTOR_AMP_AND_WAR); if (file.exists() == false) { - file.createNewFile(); + file.createNewFile(); } + // Get all the module properties + Properties moduleProperties = moduleDetails.getProperties(); OutputStream os = new FileOutputStream(file); try { - Date now = new Date(); - this.properties.setProperty(PROP_INSTALL_DATE, now.toString()); - this.properties.store(os, null); + moduleProperties.store(os, null); } finally { @@ -131,18 +147,11 @@ public class ModuleDetailsHelper extends ModuleDetailsImpl } catch (IOException exception) { - throw new ModuleManagementToolException("Unable to save module details into WAR file.", exception); + throw new ModuleManagementToolException( + "Unable to save module details into WAR file: \n" + + " Module: " + moduleDetails.getId() + "\n" + + " Properties: " + moduleDetails.getProperties(), + exception); } } - - /** - * Set the install state - * - * @param installState the install state - */ - public void setInstallState(ModuleInstallState installState) - { - this.properties.setProperty(PROP_INSTALL_STATE, installState.toString()); - } - } diff --git a/source/java/org/alfresco/repo/module/tool/ModuleManagementTool.java b/source/java/org/alfresco/repo/module/tool/ModuleManagementTool.java index 0cf1777468..603ae87d77 100644 --- a/source/java/org/alfresco/repo/module/tool/ModuleManagementTool.java +++ b/source/java/org/alfresco/repo/module/tool/ModuleManagementTool.java @@ -26,15 +26,18 @@ package org.alfresco.repo.module.tool; import java.io.BufferedInputStream; import java.io.BufferedOutputStream; -import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; +import java.util.Date; import java.util.Map; import java.util.Properties; +import org.alfresco.error.AlfrescoRuntimeException; +import org.alfresco.service.cmr.module.ModuleDetails; import org.alfresco.service.cmr.module.ModuleInstallState; +import org.alfresco.util.VersionNumber; import org.doomdark.uuid.UUIDGenerator; import de.schlichtherle.io.DefaultRaesZipDetector; @@ -62,7 +65,7 @@ public class ModuleManagementTool * The property to add to a custom {@link #FILE_MAPPING_PROPERTIES file-mapping.properties} to inherit the default values. * The default is true. */ - private static final String PROP_INHERIT_DEFAULT = "inherit.default"; + private static final String PROP_INHERIT_DEFAULT = "include.default"; /** Standard directories found in the alfresco war */ public static final String MODULE_DIR = "/WEB-INF/classes/alfresco/module"; @@ -243,17 +246,23 @@ public class ModuleManagementTool } // Get the details of the installing module - ModuleDetailsHelper installingModuleDetails = ModuleDetailsHelper.create(ampFileLocation + "/module.properties"); - if (installingModuleDetails.exists() == false) + String propertiesLocation = ampFileLocation + "/module.properties"; + ModuleDetails installingModuleDetails = ModuleDetailsHelper.createModuleDetailsFromPropertyLocation(propertiesLocation); + if (installingModuleDetails == null) { throw new ModuleManagementToolException("No module.properties file has been found in the installing .amp file '" + ampFileLocation + "'"); } + String installingId = installingModuleDetails.getId(); + VersionNumber installingVersion = installingModuleDetails.getVersion(); // Get the detail of the installed module - ModuleDetailsHelper installedModuleDetails = ModuleDetailsHelper.create(warFileLocation, installingModuleDetails.getId()); + ModuleDetails installedModuleDetails = ModuleDetailsHelper.createModuleDetailsFromWarAndId(warFileLocation, installingModuleDetails.getId()); if (installedModuleDetails != null) - { - int compareValue = installedModuleDetails.getVersionNumber().compareTo(installingModuleDetails.getVersionNumber()); + { + String installedId = installedModuleDetails.getId(); + VersionNumber installedVersion = installedModuleDetails.getVersion(); + + int compareValue = installedVersion.compareTo(installingVersion); if (forceInstall == true || compareValue == -1) { if (forceInstall == true) @@ -263,8 +272,8 @@ public class ModuleManagementTool } // Trying to update the extension, old files need to cleaned before we proceed - outputMessage("Clearing out files relating to version '" + installedModuleDetails.getVersionNumber() + "' of module '" + installedModuleDetails.getId() + "'"); - cleanWAR(warFileLocation, installedModuleDetails.getId(), preview); + outputMessage("Clearing out files relating to version '" + installedVersion + "' of module '" + installedId + "'"); + cleanWAR(warFileLocation, installedId, preview); } else if (compareValue == 0) { @@ -276,7 +285,7 @@ public class ModuleManagementTool { // Trying to install an earlier version of the extension outputMessage("WARNING: A later version of this module is already installed in the WAR"); - throw new ModuleManagementToolException("An earlier version of this module is already installed. You must first unistall the current version before installing this version of the module."); + throw new ModuleManagementToolException("A later version of this module is already installed. You must first unistall the current version before installing this version of the module."); } } @@ -302,27 +311,39 @@ public class ModuleManagementTool } // Copy the files from the AEP file into the WAR file - outputMessage("Adding files relating to version '" + installingModuleDetails.getVersionNumber() + "' of module '" + installingModuleDetails.getId() + "'"); - InstalledFiles installedFiles = new InstalledFiles(warFileLocation, installingModuleDetails.getId()); + outputMessage("Adding files relating to version '" + installingVersion + "' of module '" + installingId + "'"); + InstalledFiles installedFiles = new InstalledFiles(warFileLocation, installingId); for (Map.Entry entry : fileMappingProperties.entrySet()) { + // The file mappings are expected to start with "/" + String mappingSource = (String) entry.getKey(); + if (mappingSource.length() == 0 || !mappingSource.startsWith("/")) + { + throw new AlfrescoRuntimeException("File mapping sources must start with '/', but was: " + mappingSource); + } + String mappingTarget = (String) entry.getValue(); + if (mappingTarget.length() == 0 || !mappingTarget.startsWith("/")) + { + throw new AlfrescoRuntimeException("File mapping targets must start with '/' but was '" + mappingTarget + "'"); + } + // Run throught the files one by one figuring out what we are going to do during the copy - copyToWar(ampFileLocation, warFileLocation, (String)entry.getKey(), (String)entry.getValue(), installedFiles, preview); + copyToWar(ampFileLocation, warFileLocation, mappingSource, mappingTarget, installedFiles, preview); if (preview == false) { // Get a reference to the source folder (if it isn't present don't do anything) - File source = new File(ampFileLocation + "/" + entry.getKey(), DETECTOR_AMP_AND_WAR); + File source = new File(ampFileLocation + "/" + mappingSource, DETECTOR_AMP_AND_WAR); if (source != null && source.list() != null) { // Get a reference to the destination folder - File destination = new File(warFileLocation + "/" + entry.getValue(), DETECTOR_AMP_AND_WAR); + File destination = new File(warFileLocation + "/" + mappingTarget, DETECTOR_AMP_AND_WAR); if (destination == null) { - throw new ModuleManagementToolException("The destination folder '" + entry.getValue() + "' as specified in mapping properties does not exist in the war"); + throw new ModuleManagementToolException("The destination folder '" + mappingTarget + "' as specified in mapping properties does not exist in the war"); } // Do the bulk copy since this is quicker than copying files one by one - destination.copyAllFrom(source); + destination.copyAllFrom(source); } } } @@ -334,7 +355,8 @@ public class ModuleManagementTool // Update the installed module details installingModuleDetails.setInstallState(ModuleInstallState.INSTALLED); - installingModuleDetails.save(warFileLocation, installingModuleDetails.getId()); + installingModuleDetails.setInstallDate(new Date()); + ModuleDetailsHelper.saveModuleDetails(warFileLocation, installingModuleDetails); // Update the zip files File.update(); @@ -462,8 +484,8 @@ public class ModuleManagementTool * * @param ampFileLocation the AMP file location * @param warFileLocation the WAR file location - * @param sourceDir the directory in the AMP to copy from - * @param destinationDir the directory in the WAR to copy to + * @param sourceDir the directory in the AMP to copy from. It must start with "/". + * @param destinationDir the directory in the WAR to copy to. It must start with "/". * @param installedFiles a list of the currently installed files * @param preview indicates whether this is a preview install or not * @throws IOException throws any IOExpceptions thar are raised @@ -471,6 +493,25 @@ public class ModuleManagementTool private void copyToWar(String ampFileLocation, String warFileLocation, String sourceDir, String destinationDir, InstalledFiles installedFiles, boolean preview) throws IOException { + if (sourceDir.length() == 0 || !sourceDir.startsWith("/")) + { + throw new IllegalArgumentException("sourceDir must start with '/'"); + } + if (destinationDir.length() == 0 || !destinationDir.startsWith("/")) + { + throw new IllegalArgumentException("destinationDir must start with '/'"); + } + + // Handle source and destination if they are just the root '/' + if (sourceDir.equals("/")) + { + sourceDir = ""; + } + if (destinationDir.equals("/")) + { + destinationDir = ""; + } + String sourceLocation = ampFileLocation + sourceDir; File ampConfig = new File(sourceLocation, DETECTOR_AMP_AND_WAR); @@ -562,7 +603,7 @@ public class ModuleManagementTool */ public void listModules(String warLocation) { - ModuleDetailsHelper moduleDetails = null; + ModuleDetails moduleDetails = null; boolean previous = this.verbose; this.verbose = true; try @@ -585,18 +626,19 @@ public class ModuleManagementTool { try { - moduleDetails = new ModuleDetailsHelper(new FileInputStream(moduleProperties)); + InputStream is = new FileInputStream(moduleProperties); + moduleDetails = ModuleDetailsHelper.createModuleDetailsFromPropertiesStream(is); } - catch (FileNotFoundException exception) + catch (IOException exception) { - throw new ModuleManagementToolException("Unable to open module properties file '" + moduleProperties.getPath() + "'"); + throw new ModuleManagementToolException("Unable to open module properties file '" + moduleProperties.getPath() + "'", exception); } outputMessage("Module '" + moduleDetails.getId() + "' installed in '" + warLocation + "'"); - outputMessage("Title: " + moduleDetails.getTitle(), true); - outputMessage("Version: " + moduleDetails.getVersionNumber(), true); - outputMessage("Install Date: " + moduleDetails.getInstalledDate(), true); - outputMessage("Desription: " + moduleDetails.getDescription(), true); + outputMessage(" Title: " + moduleDetails.getTitle(), true); + outputMessage(" Version: " + moduleDetails.getVersion(), true); + outputMessage(" Install Date: " + moduleDetails.getInstallDate(), true); + outputMessage(" Desription: " + moduleDetails.getDescription(), true); } } } diff --git a/source/java/org/alfresco/repo/module/tool/ModuleManagementToolTest.java b/source/java/org/alfresco/repo/module/tool/ModuleManagementToolTest.java index e5f6d889d2..b28ae22538 100644 --- a/source/java/org/alfresco/repo/module/tool/ModuleManagementToolTest.java +++ b/source/java/org/alfresco/repo/module/tool/ModuleManagementToolTest.java @@ -36,6 +36,7 @@ import java.util.Map; import junit.framework.TestCase; +import org.alfresco.util.TempFileProvider; import org.springframework.util.FileCopyUtils; import de.schlichtherle.io.DefaultRaesZipDetector; @@ -212,7 +213,8 @@ public class ModuleManagementToolTest extends TestCase } catch (ModuleManagementToolException exception) { - // ignore since we are expecting this + exception.printStackTrace(); + System.out.println("Expected failure: " + exception.getMessage()); } } @@ -232,7 +234,7 @@ public class ModuleManagementToolTest extends TestCase private String getFileLocation(String extension, String location) throws IOException { - File file = File.createTempFile("moduleManagementToolTest-", extension); + File file = TempFileProvider.createTempFile("moduleManagementToolTest-", extension); InputStream is = this.getClass().getClassLoader().getResourceAsStream(location); assertNotNull(is); OutputStream os = new FileOutputStream(file); diff --git a/source/java/org/alfresco/service/cmr/module/ModuleDetails.java b/source/java/org/alfresco/service/cmr/module/ModuleDetails.java index 6c1e7824bc..6c085e9272 100644 --- a/source/java/org/alfresco/service/cmr/module/ModuleDetails.java +++ b/source/java/org/alfresco/service/cmr/module/ModuleDetails.java @@ -24,6 +24,9 @@ */ package org.alfresco.service.cmr.module; +import java.util.Date; +import java.util.Properties; + import org.alfresco.util.VersionNumber; /** @@ -34,12 +37,21 @@ import org.alfresco.util.VersionNumber; */ public interface ModuleDetails { + static final String PROP_ID = "module.id"; + static final String PROP_VERSION = "module.version"; + static final String PROP_TITLE = "module.title"; + static final String PROP_DESCRIPTION = "module.description"; + static final String PROP_REPO_VERSION_MIN = "module.repo.version.min"; + static final String PROP_REPO_VERSION_MAX = "module.repo.version.max"; + static final String PROP_INSTALL_DATE = "module.installDate"; + static final String PROP_INSTALL_STATE = "module.installState"; + /** - * Indicates whether the details exists or not + * Get all defined properties. * - * @return true if it exists, false otherwise + * @return Returns the properties defined by this set of details */ - boolean exists(); + Properties getProperties(); /** * Get the id of the module @@ -53,7 +65,7 @@ public interface ModuleDetails * * @return module version number */ - VersionNumber getVersionNumber(); + VersionNumber getVersion(); /** * Get the title of the module @@ -72,9 +84,16 @@ public interface ModuleDetails /** * Get the modules install date * - * @return module install date + * @return module install date or null if it has not been set */ - String getInstalledDate(); + Date getInstallDate(); + + /** + * Set the module installation date. + * + * @param installDate the module install date + */ + void setInstallDate(Date installDate); /** * Get the modules install state @@ -82,4 +101,11 @@ public interface ModuleDetails * @return the modules install state */ ModuleInstallState getInstallState(); + + /** + * Set the module install state. + * + * @param installState the module install state + */ + void setInstallState(ModuleInstallState installState); } diff --git a/source/test-resources/module/test.amp b/source/test-resources/module/test.amp index 4669992d6e..a3bf51a6bb 100644 Binary files a/source/test-resources/module/test.amp and b/source/test-resources/module/test.amp differ