Added support for module-specific 'file-mapping.properties' files to augment or override default file mappings when deploying a module to a war.

git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@5498 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Derek Hulley
2007-04-17 00:31:09 +00:00
parent d6e56b62a4
commit 292d2b5de7
4 changed files with 87 additions and 30 deletions

View File

@@ -56,7 +56,7 @@ public class InstalledFiles
*/ */
public void load() public void load()
{ {
File file = new File(getFileLocation(), ModuleManagementTool.defaultDetector); File file = new File(getFileLocation(), ModuleManagementTool.DETECTOR_AMP_AND_WAR);
if (file.exists() == true) if (file.exists() == true)
{ {
try try
@@ -108,7 +108,7 @@ public class InstalledFiles
{ {
try try
{ {
File file = new File(getFileLocation(), ModuleManagementTool.defaultDetector); File file = new File(getFileLocation(), ModuleManagementTool.DETECTOR_AMP_AND_WAR);
if (file.exists() == false) if (file.exists() == false)
{ {
file.createNewFile(); file.createNewFile();

View File

@@ -64,7 +64,7 @@ public class ModuleDetailsHelper extends ModuleDetailsImpl
ModuleDetailsHelper result = null; ModuleDetailsHelper result = null;
try try
{ {
File file = new File(location, ModuleManagementTool.defaultDetector); File file = new File(location, ModuleManagementTool.DETECTOR_AMP_AND_WAR);
if (file.exists() == true) if (file.exists() == true)
{ {
result = new ModuleDetailsHelper(new FileInputStream(file)); result = new ModuleDetailsHelper(new FileInputStream(file));
@@ -86,7 +86,7 @@ public class ModuleDetailsHelper extends ModuleDetailsImpl
*/ */
public static ModuleDetailsHelper create(String warLocation, String moduleId) public static ModuleDetailsHelper create(String warLocation, String moduleId)
{ {
return ModuleDetailsHelper.create(ModuleDetailsHelper.getFileLocation(warLocation, moduleId)); return ModuleDetailsHelper.create(ModuleDetailsHelper.getModulePropertiesFileLocation(warLocation, moduleId));
} }
/** /**
@@ -96,7 +96,7 @@ public class ModuleDetailsHelper extends ModuleDetailsImpl
* @param moduleId the module id * @param moduleId the module id
* @return the file location * @return the file location
*/ */
private static String getFileLocation(String warLocation, String moduleId) private static String getModulePropertiesFileLocation(String warLocation, String moduleId)
{ {
return warLocation + ModuleManagementTool.MODULE_DIR + "/" + moduleId + "/" + "module.properties"; return warLocation + ModuleManagementTool.MODULE_DIR + "/" + moduleId + "/" + "module.properties";
} }
@@ -111,7 +111,7 @@ public class ModuleDetailsHelper extends ModuleDetailsImpl
{ {
try try
{ {
File file = new File(getFileLocation(warLocation, moduleId), ModuleManagementTool.defaultDetector); File file = new File(getModulePropertiesFileLocation(warLocation, moduleId), ModuleManagementTool.DETECTOR_AMP_AND_WAR);
if (file.exists() == false) if (file.exists() == false)
{ {
file.createNewFile(); file.createNewFile();

View File

@@ -56,6 +56,13 @@ public class ModuleManagementTool
{ {
/** 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";
/** Location of the AMP-specific mappings file */
private static final String FILE_MAPPING_PROPERTIES = "file-mapping.properties";
/**
* 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>.
*/
private static final String PROP_INHERIT_DEFAULT = "inherit.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";
@@ -71,10 +78,10 @@ public class ModuleManagementTool
private static final String OPTION_DIRECTORY = "-directory"; private static final String OPTION_DIRECTORY = "-directory";
/** Default zip detector */ /** Default zip detector */
public static ZipDetector defaultDetector = new DefaultRaesZipDetector("amp|war"); public static final ZipDetector DETECTOR_AMP_AND_WAR = new DefaultRaesZipDetector("amp|war");
/** File mapping properties */ /** File mapping properties */
private Properties fileMappingProperties; private Properties defaultFileMappingProperties;
/** Indicates the current verbose setting */ /** Indicates the current verbose setting */
private boolean verbose = false; private boolean verbose = false;
@@ -85,11 +92,11 @@ public class ModuleManagementTool
public ModuleManagementTool() public ModuleManagementTool()
{ {
// Load the default file mapping properties // Load the default file mapping properties
this.fileMappingProperties = new Properties(); this.defaultFileMappingProperties = new Properties();
InputStream is = this.getClass().getClassLoader().getResourceAsStream(DEFAULT_FILE_MAPPING_PROPERTIES); InputStream is = this.getClass().getClassLoader().getResourceAsStream(DEFAULT_FILE_MAPPING_PROPERTIES);
try try
{ {
this.fileMappingProperties.load(is); this.defaultFileMappingProperties.load(is);
} }
catch (IOException exception) catch (IOException exception)
{ {
@@ -208,12 +215,12 @@ public class ModuleManagementTool
if (preview == false) if (preview == false)
{ {
// Make sure the module and backup directory exisits in the WAR file // Make sure the module and backup directory exisits in the WAR file
File moduleDir = new File(warFileLocation + MODULE_DIR, defaultDetector); File moduleDir = new File(warFileLocation + MODULE_DIR, DETECTOR_AMP_AND_WAR);
if (moduleDir.exists() == false) if (moduleDir.exists() == false)
{ {
moduleDir.mkdir(); moduleDir.mkdir();
} }
File backUpDir = new File(warFileLocation + BACKUP_DIR, defaultDetector); File backUpDir = new File(warFileLocation + BACKUP_DIR, DETECTOR_AMP_AND_WAR);
if (backUpDir.exists() == false) if (backUpDir.exists() == false)
{ {
backUpDir.mkdir(); backUpDir.mkdir();
@@ -252,11 +259,11 @@ public class ModuleManagementTool
if (forceInstall == true) if (forceInstall == true)
{ {
// Warn of forced install // Warn of forced install
outputMessage("WARNING: The installation of this module is being forced. All files will be removed and replaced reguarless of exiting versions present."); outputMessage("WARNING: The installation of this module is being forced. All files will be removed and replaced regardless of exiting versions present.");
} }
// 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().toString() + "' of module '" + installedModuleDetails.getId() + "'"); outputMessage("Clearing out files relating to version '" + installedModuleDetails.getVersionNumber() + "' of module '" + installedModuleDetails.getId() + "'");
cleanWAR(warFileLocation, installedModuleDetails.getId(), preview); cleanWAR(warFileLocation, installedModuleDetails.getId(), preview);
} }
else if (compareValue == 0) else if (compareValue == 0)
@@ -274,29 +281,47 @@ public class ModuleManagementTool
} }
// TODO check for any additional file mapping propeties supplied in the AEP file // Check if a custom mapping file has been defined
Properties fileMappingProperties = null;
Properties customFileMappingProperties = getCustomFileMappings(ampFileLocation);
if (customFileMappingProperties == null)
{
fileMappingProperties = defaultFileMappingProperties;
}
else
{
fileMappingProperties = new Properties();
// A custom mapping file was present. Check if it must inherit the default mappings.
String inheritDefaultStr = customFileMappingProperties.getProperty(PROP_INHERIT_DEFAULT, "true");
if (inheritDefaultStr.equalsIgnoreCase("true"))
{
fileMappingProperties.putAll(defaultFileMappingProperties);
}
fileMappingProperties.putAll(customFileMappingProperties);
fileMappingProperties.remove(PROP_INHERIT_DEFAULT);
}
// 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().toString() + "' of module '" + installingModuleDetails.getId() + "'"); outputMessage("Adding files relating to version '" + installingModuleDetails.getVersionNumber() + "' of module '" + installingModuleDetails.getId() + "'");
InstalledFiles installedFiles = new InstalledFiles(warFileLocation, installingModuleDetails.getId()); InstalledFiles installedFiles = new InstalledFiles(warFileLocation, installingModuleDetails.getId());
for (Map.Entry<Object, Object> entry : this.fileMappingProperties.entrySet()) for (Map.Entry<Object, Object> entry : fileMappingProperties.entrySet())
{ {
// 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, (String)entry.getKey(), (String)entry.getValue(), installedFiles, preview);
if (preview == false) if (preview == false)
{ {
// Get a reference to the source folder (if it isn't present dont 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(), defaultDetector); File source = new File(ampFileLocation + "/" + entry.getKey(), 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(), defaultDetector); File destination = new File(warFileLocation + "/" + entry.getValue(), 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 '" + entry.getValue() + "' as specified in mapping properties does not exist in the war");
} }
// Do the bulk copy since this is quicker than copying file's one by one // Do the bulk copy since this is quicker than copying files one by one
destination.copyAllFrom(source); destination.copyAllFrom(source);
} }
} }
@@ -311,7 +336,7 @@ public class ModuleManagementTool
installingModuleDetails.setInstallState(ModuleInstallState.INSTALLED); installingModuleDetails.setInstallState(ModuleInstallState.INSTALLED);
installingModuleDetails.save(warFileLocation, installingModuleDetails.getId()); installingModuleDetails.save(warFileLocation, installingModuleDetails.getId());
// Update the zip file's // Update the zip files
File.update(); File.update();
// Set the modified date // Set the modified date
@@ -339,6 +364,38 @@ public class ModuleManagementTool
} }
} }
/**
* @return Returns the custom file mapping properties or null if they weren't overwritten
*/
private Properties getCustomFileMappings(String ampFileLocation)
{
File file = new File(ampFileLocation + "/" + FILE_MAPPING_PROPERTIES, ModuleManagementTool.DETECTOR_AMP_AND_WAR);
if (!file.exists())
{
// Nothing there
return null;
}
Properties mappingProperties = new Properties();
InputStream is = null;
try
{
is = new BufferedInputStream(new FileInputStream(file));
mappingProperties.load(is);
}
catch (IOException exception)
{
throw new ModuleManagementToolException("Unable to load default extension file mapping properties.", exception);
}
finally
{
if (is != null)
{
try { is.close(); } catch (Throwable e ) {}
}
}
return mappingProperties;
}
/** /**
* Cleans the WAR file of all files relating to the currently installed version of the the AMP. * Cleans the WAR file of all files relating to the currently installed version of the the AMP.
* *
@@ -366,8 +423,8 @@ public class ModuleManagementTool
if (preview == false) if (preview == false)
{ {
// Recover updated file and delete backups // Recover updated file and delete backups
File modified = new File(warFileLocation + update.getKey(), defaultDetector); File modified = new File(warFileLocation + update.getKey(), DETECTOR_AMP_AND_WAR);
File backup = new File(warFileLocation + update.getValue(), defaultDetector); File backup = new File(warFileLocation + update.getValue(), DETECTOR_AMP_AND_WAR);
modified.copyFrom(backup); modified.copyFrom(backup);
backup.delete(); backup.delete();
} }
@@ -385,7 +442,7 @@ public class ModuleManagementTool
*/ */
private void removeFile(String warLocation, String filePath, boolean preview) private void removeFile(String warLocation, String filePath, boolean preview)
{ {
File removeFile = new File(warLocation + filePath, defaultDetector); File removeFile = new File(warLocation + filePath, DETECTOR_AMP_AND_WAR);
if (removeFile.exists() == true) if (removeFile.exists() == true)
{ {
outputMessage("Removing file '" + filePath + "' from war", true); outputMessage("Removing file '" + filePath + "' from war", true);
@@ -415,7 +472,7 @@ public class ModuleManagementTool
throws IOException throws IOException
{ {
String sourceLocation = ampFileLocation + sourceDir; String sourceLocation = ampFileLocation + sourceDir;
File ampConfig = new File(sourceLocation, defaultDetector); File ampConfig = new File(sourceLocation, DETECTOR_AMP_AND_WAR);
java.io.File[] files = ampConfig.listFiles(); java.io.File[] files = ampConfig.listFiles();
if (files != null) if (files != null)
@@ -423,7 +480,7 @@ public class ModuleManagementTool
for (java.io.File sourceChild : files) for (java.io.File sourceChild : files)
{ {
String destinationFileLocation = warFileLocation + destinationDir + "/" + sourceChild.getName(); String destinationFileLocation = warFileLocation + destinationDir + "/" + sourceChild.getName();
File destinationChild = new File(destinationFileLocation, defaultDetector); File destinationChild = new File(destinationFileLocation, DETECTOR_AMP_AND_WAR);
if (sourceChild.isFile() == true) if (sourceChild.isFile() == true)
{ {
String backupLocation = null; String backupLocation = null;
@@ -438,7 +495,7 @@ public class ModuleManagementTool
backupLocation = BACKUP_DIR + "/" + generateGuid() + ".bin"; backupLocation = BACKUP_DIR + "/" + generateGuid() + ".bin";
if (preview == false) if (preview == false)
{ {
File backupFile = new File(warFileLocation + backupLocation, defaultDetector); File backupFile = new File(warFileLocation + backupLocation, DETECTOR_AMP_AND_WAR);
backupFile.copyFrom(destinationChild); backupFile.copyFrom(destinationChild);
} }
} }
@@ -510,7 +567,7 @@ public class ModuleManagementTool
this.verbose = true; this.verbose = true;
try try
{ {
File moduleDir = new File(warLocation + MODULE_DIR, defaultDetector); File moduleDir = new File(warLocation + MODULE_DIR, DETECTOR_AMP_AND_WAR);
if (moduleDir.exists() == false) if (moduleDir.exists() == false)
{ {
outputMessage("No modules are installed in this WAR file"); outputMessage("No modules are installed in this WAR file");
@@ -523,7 +580,7 @@ public class ModuleManagementTool
{ {
if (dir.isDirectory() == true) if (dir.isDirectory() == true)
{ {
File moduleProperties = new File(dir.getPath() + "/module.properties", defaultDetector); File moduleProperties = new File(dir.getPath() + "/module.properties", DETECTOR_AMP_AND_WAR);
if (moduleProperties.exists() == true) if (moduleProperties.exists() == true)
{ {
try try