mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-07-24 17:32:48 +00:00
Tighter control of file-mapping.properties values.
Fixed bug with file-mapping.properties 'include.default' option. Refactor of ModuleDetails properties serialization. git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@5518 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
@@ -270,7 +270,7 @@ public class ModuleComponentHelper
|
|||||||
private void startModule(ModuleDetails module, Set<ModuleComponent> executedComponents)
|
private void startModule(ModuleDetails module, Set<ModuleComponent> executedComponents)
|
||||||
{
|
{
|
||||||
String moduleId = module.getId();
|
String moduleId = module.getId();
|
||||||
VersionNumber moduleVersion = module.getVersionNumber();
|
VersionNumber moduleVersion = module.getVersion();
|
||||||
// Get the module details from the registry
|
// Get the module details from the registry
|
||||||
RegistryKey moduleKeyInstalledVersion = new RegistryKey(
|
RegistryKey moduleKeyInstalledVersion = new RegistryKey(
|
||||||
ModuleComponentHelper.URI_MODULES_1_0,
|
ModuleComponentHelper.URI_MODULES_1_0,
|
||||||
@@ -336,7 +336,7 @@ public class ModuleComponentHelper
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Check the version applicability
|
// Check the version applicability
|
||||||
VersionNumber moduleVersion = module.getVersionNumber();
|
VersionNumber moduleVersion = module.getVersion();
|
||||||
VersionNumber minVersion = component.getAppliesFromVersionNumber();
|
VersionNumber minVersion = component.getAppliesFromVersionNumber();
|
||||||
VersionNumber maxVersion = component.getAppliesToVersionNumber();
|
VersionNumber maxVersion = component.getAppliesToVersionNumber();
|
||||||
if (moduleVersion.compareTo(minVersion) < 0 || moduleVersion.compareTo(maxVersion) > 0)
|
if (moduleVersion.compareTo(minVersion) < 0 || moduleVersion.compareTo(maxVersion) > 0)
|
||||||
|
@@ -24,13 +24,15 @@
|
|||||||
*/
|
*/
|
||||||
package org.alfresco.repo.module;
|
package org.alfresco.repo.module;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.util.ArrayList;
|
||||||
import java.io.InputStream;
|
import java.util.Date;
|
||||||
|
import java.util.List;
|
||||||
import java.util.Properties;
|
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.ModuleDetails;
|
||||||
import org.alfresco.service.cmr.module.ModuleInstallState;
|
import org.alfresco.service.cmr.module.ModuleInstallState;
|
||||||
|
import org.alfresco.util.ISO8601DateFormat;
|
||||||
import org.alfresco.util.VersionNumber;
|
import org.alfresco.util.VersionNumber;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -42,42 +44,82 @@ import org.alfresco.util.VersionNumber;
|
|||||||
*/
|
*/
|
||||||
public class ModuleDetailsImpl implements ModuleDetails
|
public class ModuleDetailsImpl implements ModuleDetails
|
||||||
{
|
{
|
||||||
/** Property names */
|
private String id;
|
||||||
protected static final String PROP_ID = "module.id";
|
private VersionNumber version;
|
||||||
protected static final String PROP_TITLE = "module.title";
|
private String title;
|
||||||
protected static final String PROP_DESCRIPTION = "module.description";
|
private String description;
|
||||||
protected static final String PROP_VERSION = "module.version";
|
private VersionNumber repoVersionMin;
|
||||||
protected static final String PROP_INSTALL_DATE = "module.installDate";
|
private VersionNumber repoVersionMax;
|
||||||
protected static final String PROP_INSTALL_STATE = "module.installState";
|
private Date installDate;
|
||||||
|
private ModuleInstallState installState;
|
||||||
/** Properties object */
|
|
||||||
protected Properties properties;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor
|
* @param properties the set of properties
|
||||||
*
|
|
||||||
* @param is input stream, which will be closed
|
|
||||||
*/
|
*/
|
||||||
public ModuleDetailsImpl(InputStream is)
|
public ModuleDetailsImpl(Properties properties)
|
||||||
{
|
{
|
||||||
|
// Check that the required properties are present
|
||||||
|
List<String> missingProperties = new ArrayList<String>(1);
|
||||||
|
// ID
|
||||||
|
id = properties.getProperty(PROP_ID);
|
||||||
|
if (id == null) { missingProperties.add(PROP_ID); }
|
||||||
|
// VERSION
|
||||||
|
if (properties.getProperty(PROP_VERSION) == null)
|
||||||
|
{
|
||||||
|
missingProperties.add(PROP_VERSION);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
version = new VersionNumber(properties.getProperty(PROP_VERSION));
|
||||||
|
}
|
||||||
|
// 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)
|
||||||
|
{
|
||||||
|
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
|
try
|
||||||
{
|
{
|
||||||
this.properties = new Properties();
|
installDate = ISO8601DateFormat.parse(installDateStr);
|
||||||
this.properties.load(is);
|
|
||||||
}
|
}
|
||||||
catch (IOException exception)
|
catch (Throwable e)
|
||||||
{
|
{
|
||||||
throw new ModuleManagementToolException("Unable to load module details from property file.", exception);
|
throw new AlfrescoRuntimeException("Unable to parse install date: " + installDateStr, e);
|
||||||
}
|
}
|
||||||
finally
|
}
|
||||||
|
// Check
|
||||||
|
if (missingProperties.size() > 0)
|
||||||
{
|
{
|
||||||
try { is.close(); } catch (IOException e) { e.printStackTrace(); }
|
throw new AlfrescoRuntimeException("The following module properties need to be defined: " + missingProperties);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Set other defaults
|
||||||
|
installState = ModuleInstallState.INSTALLED;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor
|
|
||||||
*
|
|
||||||
* @param id module id
|
* @param id module id
|
||||||
* @param versionNumber version number
|
* @param versionNumber version number
|
||||||
* @param title title
|
* @param title title
|
||||||
@@ -85,81 +127,96 @@ public class ModuleDetailsImpl implements ModuleDetails
|
|||||||
*/
|
*/
|
||||||
public ModuleDetailsImpl(String id, VersionNumber versionNumber, String title, String description)
|
public ModuleDetailsImpl(String id, VersionNumber versionNumber, String title, String description)
|
||||||
{
|
{
|
||||||
this.properties = new Properties();
|
this.id = id;
|
||||||
this.properties.setProperty(PROP_ID, id);
|
this.version = versionNumber;
|
||||||
this.properties.setProperty(PROP_VERSION, versionNumber.toString());
|
this.title = title;
|
||||||
this.properties.setProperty(PROP_TITLE, title);
|
this.description = description;
|
||||||
this.properties.setProperty(PROP_DESCRIPTION, description);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
public Properties getProperties()
|
||||||
* @see org.alfresco.service.cmr.module.ModuleDetails#exists()
|
|
||||||
*/
|
|
||||||
public boolean exists()
|
|
||||||
{
|
{
|
||||||
return (this.properties != null);
|
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)
|
||||||
|
{
|
||||||
|
properties.setProperty(PROP_REPO_VERSION_MIN, repoVersionMin.toString());
|
||||||
|
}
|
||||||
|
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 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)
|
|
||||||
{
|
|
||||||
result = ModuleInstallState.valueOf(value);
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @see java.lang.Object#toString()
|
|
||||||
*/
|
|
||||||
@Override
|
@Override
|
||||||
public String toString()
|
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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -32,6 +32,7 @@ import java.util.Collection;
|
|||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.Properties;
|
||||||
|
|
||||||
import org.alfresco.error.AlfrescoRuntimeException;
|
import org.alfresco.error.AlfrescoRuntimeException;
|
||||||
import org.alfresco.repo.admin.registry.RegistryService;
|
import org.alfresco.repo.admin.registry.RegistryService;
|
||||||
@@ -176,7 +177,9 @@ public class ModuleServiceImpl implements ModuleService
|
|||||||
try
|
try
|
||||||
{
|
{
|
||||||
InputStream is = new BufferedInputStream(resource.getInputStream());
|
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);
|
moduleDetailsById.put(details.getId(), details);
|
||||||
}
|
}
|
||||||
catch (Throwable e)
|
catch (Throwable e)
|
||||||
|
@@ -27,10 +27,10 @@ package org.alfresco.repo.module.tool;
|
|||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.io.OutputStream;
|
import java.io.OutputStream;
|
||||||
import java.util.Date;
|
import java.util.Properties;
|
||||||
|
|
||||||
import org.alfresco.repo.module.ModuleDetailsImpl;
|
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.File;
|
||||||
import de.schlichtherle.io.FileInputStream;
|
import de.schlichtherle.io.FileInputStream;
|
||||||
@@ -40,34 +40,45 @@ import de.schlichtherle.io.FileOutputStream;
|
|||||||
* Module details helper used by the module mangement tool
|
* Module details helper used by the module mangement tool
|
||||||
*
|
*
|
||||||
* @author Roy Wetherall
|
* @author Roy Wetherall
|
||||||
|
* @author Derek Hulley
|
||||||
*/
|
*/
|
||||||
public class ModuleDetailsHelper extends ModuleDetailsImpl
|
public class ModuleDetailsHelper
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* Constructor
|
* 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
|
||||||
* @param is input stream
|
* @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.
|
* Creates a module details helper object based on a file location.
|
||||||
*
|
*
|
||||||
* @param location 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
|
try
|
||||||
{
|
{
|
||||||
File file = new File(location, ModuleManagementTool.DETECTOR_AMP_AND_WAR);
|
File file = new File(location, ModuleManagementTool.DETECTOR_AMP_AND_WAR);
|
||||||
if (file.exists() == true)
|
if (file.exists() == true)
|
||||||
{
|
{
|
||||||
result = new ModuleDetailsHelper(new FileInputStream(file));
|
InputStream is = new FileInputStream(file);
|
||||||
|
result = createModuleDetailsFromPropertiesStream(is);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (IOException exception)
|
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 warLocation the war location
|
||||||
* @param moduleId the module id
|
* @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 <tt>null</tt>
|
||||||
|
* 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 warLocation the war location
|
||||||
* @param moduleId the module id
|
* @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
|
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)
|
if (file.exists() == false)
|
||||||
{
|
{
|
||||||
file.createNewFile();
|
file.createNewFile();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Get all the module properties
|
||||||
|
Properties moduleProperties = moduleDetails.getProperties();
|
||||||
OutputStream os = new FileOutputStream(file);
|
OutputStream os = new FileOutputStream(file);
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
Date now = new Date();
|
moduleProperties.store(os, null);
|
||||||
this.properties.setProperty(PROP_INSTALL_DATE, now.toString());
|
|
||||||
this.properties.store(os, null);
|
|
||||||
}
|
}
|
||||||
finally
|
finally
|
||||||
{
|
{
|
||||||
@@ -131,18 +147,11 @@ public class ModuleDetailsHelper extends ModuleDetailsImpl
|
|||||||
}
|
}
|
||||||
catch (IOException exception)
|
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());
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@@ -26,15 +26,18 @@ package org.alfresco.repo.module.tool;
|
|||||||
|
|
||||||
import java.io.BufferedInputStream;
|
import java.io.BufferedInputStream;
|
||||||
import java.io.BufferedOutputStream;
|
import java.io.BufferedOutputStream;
|
||||||
import java.io.FileNotFoundException;
|
|
||||||
import java.io.FileOutputStream;
|
import java.io.FileOutputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.io.OutputStream;
|
import java.io.OutputStream;
|
||||||
|
import java.util.Date;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Properties;
|
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.service.cmr.module.ModuleInstallState;
|
||||||
|
import org.alfresco.util.VersionNumber;
|
||||||
import org.doomdark.uuid.UUIDGenerator;
|
import org.doomdark.uuid.UUIDGenerator;
|
||||||
|
|
||||||
import de.schlichtherle.io.DefaultRaesZipDetector;
|
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 property to add to a custom {@link #FILE_MAPPING_PROPERTIES file-mapping.properties} to inherit the default values.
|
||||||
* The default is <code>true</code>.
|
* The default is <code>true</code>.
|
||||||
*/
|
*/
|
||||||
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 */
|
/** Standard directories found in the alfresco war */
|
||||||
public static final String MODULE_DIR = "/WEB-INF/classes/alfresco/module";
|
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
|
// Get the details of the installing module
|
||||||
ModuleDetailsHelper installingModuleDetails = ModuleDetailsHelper.create(ampFileLocation + "/module.properties");
|
String propertiesLocation = ampFileLocation + "/module.properties";
|
||||||
if (installingModuleDetails.exists() == false)
|
ModuleDetails installingModuleDetails = ModuleDetailsHelper.createModuleDetailsFromPropertyLocation(propertiesLocation);
|
||||||
|
if (installingModuleDetails == null)
|
||||||
{
|
{
|
||||||
throw new ModuleManagementToolException("No module.properties file has been found in the installing .amp file '" + ampFileLocation + "'");
|
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
|
// Get the detail of the installed module
|
||||||
ModuleDetailsHelper installedModuleDetails = ModuleDetailsHelper.create(warFileLocation, installingModuleDetails.getId());
|
ModuleDetails installedModuleDetails = ModuleDetailsHelper.createModuleDetailsFromWarAndId(warFileLocation, installingModuleDetails.getId());
|
||||||
if (installedModuleDetails != null)
|
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 || compareValue == -1)
|
||||||
{
|
{
|
||||||
if (forceInstall == true)
|
if (forceInstall == true)
|
||||||
@@ -263,8 +272,8 @@ public class ModuleManagementTool
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Trying to update the extension, old files need to cleaned before we proceed
|
// 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() + "'");
|
outputMessage("Clearing out files relating to version '" + installedVersion + "' of module '" + installedId + "'");
|
||||||
cleanWAR(warFileLocation, installedModuleDetails.getId(), preview);
|
cleanWAR(warFileLocation, installedId, preview);
|
||||||
}
|
}
|
||||||
else if (compareValue == 0)
|
else if (compareValue == 0)
|
||||||
{
|
{
|
||||||
@@ -276,7 +285,7 @@ public class ModuleManagementTool
|
|||||||
{
|
{
|
||||||
// Trying to install an earlier version of the extension
|
// Trying to install an earlier version of the extension
|
||||||
outputMessage("WARNING: A later version of this module is already installed in the WAR");
|
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,24 +311,36 @@ public class ModuleManagementTool
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Copy the files from the AEP file into the WAR file
|
// Copy the files from the AEP file into the WAR file
|
||||||
outputMessage("Adding files relating to version '" + installingModuleDetails.getVersionNumber() + "' of module '" + installingModuleDetails.getId() + "'");
|
outputMessage("Adding files relating to version '" + installingVersion + "' of module '" + installingId + "'");
|
||||||
InstalledFiles installedFiles = new InstalledFiles(warFileLocation, installingModuleDetails.getId());
|
InstalledFiles installedFiles = new InstalledFiles(warFileLocation, installingId);
|
||||||
for (Map.Entry<Object, Object> entry : fileMappingProperties.entrySet())
|
for (Map.Entry<Object, Object> 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
|
// 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)
|
if (preview == false)
|
||||||
{
|
{
|
||||||
// Get a reference to the source folder (if it isn't present don't do anything)
|
// 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)
|
if (source != null && source.list() != null)
|
||||||
{
|
{
|
||||||
// Get a reference to the destination folder
|
// 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)
|
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
|
// 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
|
// Update the installed module details
|
||||||
installingModuleDetails.setInstallState(ModuleInstallState.INSTALLED);
|
installingModuleDetails.setInstallState(ModuleInstallState.INSTALLED);
|
||||||
installingModuleDetails.save(warFileLocation, installingModuleDetails.getId());
|
installingModuleDetails.setInstallDate(new Date());
|
||||||
|
ModuleDetailsHelper.saveModuleDetails(warFileLocation, installingModuleDetails);
|
||||||
|
|
||||||
// Update the zip files
|
// Update the zip files
|
||||||
File.update();
|
File.update();
|
||||||
@@ -462,8 +484,8 @@ public class ModuleManagementTool
|
|||||||
*
|
*
|
||||||
* @param ampFileLocation the AMP file location
|
* @param ampFileLocation the AMP file location
|
||||||
* @param warFileLocation the WAR file location
|
* @param warFileLocation the WAR file location
|
||||||
* @param sourceDir the directory in the AMP to copy from
|
* @param sourceDir the directory in the AMP to copy from. It must start with "/".
|
||||||
* @param destinationDir the directory in the WAR to copy to
|
* @param destinationDir the directory in the WAR to copy to. It must start with "/".
|
||||||
* @param installedFiles a list of the currently installed files
|
* @param installedFiles a list of the currently installed files
|
||||||
* @param preview indicates whether this is a preview install or not
|
* @param preview indicates whether this is a preview install or not
|
||||||
* @throws IOException throws any IOExpceptions thar are raised
|
* @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)
|
private void copyToWar(String ampFileLocation, String warFileLocation, String sourceDir, String destinationDir, InstalledFiles installedFiles, boolean preview)
|
||||||
throws IOException
|
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;
|
String sourceLocation = ampFileLocation + sourceDir;
|
||||||
File ampConfig = new File(sourceLocation, DETECTOR_AMP_AND_WAR);
|
File ampConfig = new File(sourceLocation, DETECTOR_AMP_AND_WAR);
|
||||||
|
|
||||||
@@ -562,7 +603,7 @@ public class ModuleManagementTool
|
|||||||
*/
|
*/
|
||||||
public void listModules(String warLocation)
|
public void listModules(String warLocation)
|
||||||
{
|
{
|
||||||
ModuleDetailsHelper moduleDetails = null;
|
ModuleDetails moduleDetails = null;
|
||||||
boolean previous = this.verbose;
|
boolean previous = this.verbose;
|
||||||
this.verbose = true;
|
this.verbose = true;
|
||||||
try
|
try
|
||||||
@@ -585,18 +626,19 @@ public class ModuleManagementTool
|
|||||||
{
|
{
|
||||||
try
|
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("Module '" + moduleDetails.getId() + "' installed in '" + warLocation + "'");
|
||||||
outputMessage("Title: " + moduleDetails.getTitle(), true);
|
outputMessage(" Title: " + moduleDetails.getTitle(), true);
|
||||||
outputMessage("Version: " + moduleDetails.getVersionNumber(), true);
|
outputMessage(" Version: " + moduleDetails.getVersion(), true);
|
||||||
outputMessage("Install Date: " + moduleDetails.getInstalledDate(), true);
|
outputMessage(" Install Date: " + moduleDetails.getInstallDate(), true);
|
||||||
outputMessage("Desription: " + moduleDetails.getDescription(), true);
|
outputMessage(" Desription: " + moduleDetails.getDescription(), true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -36,6 +36,7 @@ import java.util.Map;
|
|||||||
|
|
||||||
import junit.framework.TestCase;
|
import junit.framework.TestCase;
|
||||||
|
|
||||||
|
import org.alfresco.util.TempFileProvider;
|
||||||
import org.springframework.util.FileCopyUtils;
|
import org.springframework.util.FileCopyUtils;
|
||||||
|
|
||||||
import de.schlichtherle.io.DefaultRaesZipDetector;
|
import de.schlichtherle.io.DefaultRaesZipDetector;
|
||||||
@@ -212,7 +213,8 @@ public class ModuleManagementToolTest extends TestCase
|
|||||||
}
|
}
|
||||||
catch (ModuleManagementToolException exception)
|
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)
|
private String getFileLocation(String extension, String location)
|
||||||
throws IOException
|
throws IOException
|
||||||
{
|
{
|
||||||
File file = File.createTempFile("moduleManagementToolTest-", extension);
|
File file = TempFileProvider.createTempFile("moduleManagementToolTest-", extension);
|
||||||
InputStream is = this.getClass().getClassLoader().getResourceAsStream(location);
|
InputStream is = this.getClass().getClassLoader().getResourceAsStream(location);
|
||||||
assertNotNull(is);
|
assertNotNull(is);
|
||||||
OutputStream os = new FileOutputStream(file);
|
OutputStream os = new FileOutputStream(file);
|
||||||
|
@@ -24,6 +24,9 @@
|
|||||||
*/
|
*/
|
||||||
package org.alfresco.service.cmr.module;
|
package org.alfresco.service.cmr.module;
|
||||||
|
|
||||||
|
import java.util.Date;
|
||||||
|
import java.util.Properties;
|
||||||
|
|
||||||
import org.alfresco.util.VersionNumber;
|
import org.alfresco.util.VersionNumber;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -34,12 +37,21 @@ import org.alfresco.util.VersionNumber;
|
|||||||
*/
|
*/
|
||||||
public interface ModuleDetails
|
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
|
* Get the id of the module
|
||||||
@@ -53,7 +65,7 @@ public interface ModuleDetails
|
|||||||
*
|
*
|
||||||
* @return module version number
|
* @return module version number
|
||||||
*/
|
*/
|
||||||
VersionNumber getVersionNumber();
|
VersionNumber getVersion();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the title of the module
|
* Get the title of the module
|
||||||
@@ -72,9 +84,16 @@ public interface ModuleDetails
|
|||||||
/**
|
/**
|
||||||
* Get the modules install date
|
* Get the modules install date
|
||||||
*
|
*
|
||||||
* @return module install date
|
* @return module install date or <tt>null</tt> 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
|
* Get the modules install state
|
||||||
@@ -82,4 +101,11 @@ public interface ModuleDetails
|
|||||||
* @return the modules install state
|
* @return the modules install state
|
||||||
*/
|
*/
|
||||||
ModuleInstallState getInstallState();
|
ModuleInstallState getInstallState();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set the module install state.
|
||||||
|
*
|
||||||
|
* @param installState the module install state
|
||||||
|
*/
|
||||||
|
void setInstallState(ModuleInstallState installState);
|
||||||
}
|
}
|
||||||
|
Binary file not shown.
Reference in New Issue
Block a user