use of org.alfresco.service.cmr.module.ModuleDetails in project alfresco-repository by Alfresco.
the class WarHelperImpl method listModules.
/**
* Lists all the currently installed modules in the WAR
*
* @param war the war
* @throws ModuleManagementToolException
*/
@Override
public List<ModuleDetails> listModules(TFile war) {
List<ModuleDetails> moduleDetails = new ArrayList<>();
boolean moduleFound = false;
TFile moduleDir = new TFile(war, WarHelper.MODULE_NAMESPACE_DIR);
if (moduleDir.exists() == false) {
// empty
return moduleDetails;
}
java.io.File[] dirs = moduleDir.listFiles();
if (dirs != null && dirs.length != 0) {
for (java.io.File dir : dirs) {
if (dir.isDirectory() == true) {
TFile moduleProperties = new TFile(dir.getPath() + WarHelper.MODULE_CONFIG_IN_WAR);
if (moduleProperties.exists() == true) {
InputStream is = null;
try {
moduleFound = true;
is = new TFileInputStream(moduleProperties);
moduleDetails.add(ModuleDetailsHelper.createModuleDetailsFromPropertiesStream(is));
} catch (AlfrescoRuntimeException exception) {
throw new ModuleManagementToolException("Unable to open module properties file '" + moduleProperties.getPath() + "' " + exception.getMessage(), exception);
} catch (IOException exception) {
throw new ModuleManagementToolException("Unable to open module properties file '" + moduleProperties.getPath() + "'", exception);
} finally {
if (is != null) {
try {
is.close();
} catch (Throwable e) {
}
}
}
}
}
}
}
return moduleDetails;
}
use of org.alfresco.service.cmr.module.ModuleDetails in project alfresco-repository by Alfresco.
the class ModuleServiceImpl method getModule.
/**
* {@inheritDoc}
*/
public ModuleDetails getModule(String moduleId) {
cacheModuleDetails();
// Get the details of the specific module
ModuleDetails details = moduleDetailsById.get(moduleId);
// Done
return details;
}
use of org.alfresco.service.cmr.module.ModuleDetails in project alfresco-repository by Alfresco.
the class ModuleServiceImpl method cacheModuleDetails.
/**
* Ensure that the {@link #moduleDetailsById module details} are populated.
* <p/>
* TODO: We will have to avoid caching or add context listening if we support reloading
* of beans one day.
*/
private synchronized void cacheModuleDetails() {
if (moduleDetailsById != null) {
// There is nothing to do
return;
}
try {
moduleDetailsById = new HashMap<String, ModuleDetails>(13);
Resource[] resources = resolver.getResources(MODULE_CONFIG_SEARCH_ALL);
// Read each resource
for (Resource resource : resources) {
try {
InputStream is = new BufferedInputStream(resource.getInputStream());
Properties properties = new Properties();
properties.load(is);
ModuleDetails details = new ModuleDetailsImpl(properties);
moduleDetailsById.put(details.getId(), details);
} catch (Throwable e) {
logger.error("Unable to use module information.", e);
throw AlfrescoRuntimeException.create(e, ERR_UNABLE_TO_OPEN_MODULE_PROPETIES, resource);
}
}
} catch (IOException e) {
throw new AlfrescoRuntimeException("Failed to retrieve module information", e);
}
// Done
if (logger.isDebugEnabled()) {
logger.debug("Found " + moduleDetailsById.size() + " modules: \n" + " Modules: " + moduleDetailsById);
}
}
use of org.alfresco.service.cmr.module.ModuleDetails in project alfresco-repository by Alfresco.
the class ModuleServiceImpl method getMissingModules.
/**
* {@inheritDoc}
*/
public List<ModuleDetails> getMissingModules() {
cacheModuleDetails();
// Get the IDs of all modules from the registry
Collection<String> moduleIds = moduleComponentHelper.getRegistryModuleIDs();
List<ModuleDetails> result = new ArrayList<ModuleDetails>();
// Check for missing modules
for (String moduleId : moduleIds) {
ModuleDetails moduleDetails = getModule(moduleId);
if (moduleDetails == null) {
// Get the specifics of the missing module and add them to the list.
ModuleVersionNumber currentVersion = moduleComponentHelper.getVersion(moduleId);
ModuleDetails newModuleDetails = new ModuleDetailsImpl(moduleId, currentVersion, "", "");
result.add(newModuleDetails);
}
}
return result;
}
use of org.alfresco.service.cmr.module.ModuleDetails in project alfresco-repository by Alfresco.
the class ModuleManagementTool method installModule.
/**
* Installs a given AMP file into a given WAR file.
*
* @param ampFileLocation the location of the AMP file to be installed
* @param warFileLocation the location of the WAR file into which the AMP file is to be installed.
* @param preview indicates whether this should be a preview install. This means that the process of
* installation will be followed and reported, but the WAR file will not be modified.
* @param forceInstall indicates whether the installed files will be replaced regardless of the currently installed
* version of the AMP. Generally used during development of the AMP.
* @param backupWAR indicates whether we should backup the war we are modifying or not
*/
public void installModule(String ampFileLocation, String warFileLocation, boolean preview, boolean forceInstall, boolean backupWAR) {
TFile warFile = new TFile(warFileLocation);
try {
outputVerboseMessage("Installing AMP '" + ampFileLocation + "' into WAR '" + warFileLocation + "'");
if (!warFile.exists()) {
throw new ModuleManagementToolException("The war file '" + warFile + "' does not exist.");
}
if (preview == false) {
// Make sure the module and backup directory exisits in the WAR file
TFile moduleDir = new TFile(warFileLocation + WarHelper.MODULE_NAMESPACE_DIR);
if (moduleDir.exists() == false) {
moduleDir.mkdir();
}
backupWar(warFile, backupWAR);
}
// Get the details of the installing module
String propertiesLocation = ampFileLocation + "/module.properties";
ModuleDetails installingModuleDetails = ModuleDetailsHelper.createModuleDetailsFromPropertyLocation(propertiesLocation, this);
if (installingModuleDetails == null) {
throw new ModuleManagementToolException("No module.properties file has been found in the installing .amp file '" + ampFileLocation + "'");
}
String installingId = installingModuleDetails.getId();
ModuleVersionNumber installingVersion = installingModuleDetails.getModuleVersionNumber();
// A series of checks
warHelper.checkCompatibleVersion(warFile, installingModuleDetails);
warHelper.checkCompatibleEdition(warFile, installingModuleDetails);
warHelper.checkModuleDependencies(warFile, installingModuleDetails);
// Try to find an installed module by the ID
ModuleDetails installedModuleDetails = warHelper.getModuleDetailsOrAlias(warFile, installingModuleDetails);
// Check module directory exists
TFile moduleInstallDirectory = new TFile(warFileLocation + WarHelper.MODULE_NAMESPACE_DIR + "/" + installingId);
if (preview == false && moduleInstallDirectory.exists() == false) {
moduleInstallDirectory.mkdir();
}
uninstallIfNecessary(warFileLocation, installedModuleDetails, preview, forceInstall, installingVersion);
outputVerboseMessage("Adding files relating to version '" + installingVersion + "' of module '" + installingId + "'");
InstalledFiles installedFiles = new InstalledFiles(warFileLocation, installingId);
Properties directoryChanges = calculateChanges(ampFileLocation, warFileLocation, preview, forceInstall, installedFiles);
if (preview == false) {
// Now actually do the changes
if (directoryChanges != null && directoryChanges.size() > 0) {
for (Entry<Object, Object> entry : directoryChanges.entrySet()) {
TFile source = new TFile((String) entry.getKey());
TFile destination = new TFile((String) entry.getValue());
source.cp_rp(destination);
}
}
// Save the installed file list
installedFiles.save();
// Update the installed module details
installingModuleDetails.setInstallState(ModuleInstallState.INSTALLED);
installingModuleDetails.setInstallDate(new Date());
ModuleDetailsHelper.saveModuleDetails(warFileLocation, installingModuleDetails);
// Set the modified date
if (warFile.exists()) {
warFile.setLastModified(System.currentTimeMillis());
}
}
} catch (AlfrescoRuntimeException exception) {
throw new ModuleManagementToolException("An error was encountered during deployment of the AMP into the WAR: " + exception.getMessage(), exception);
} catch (IOException exception) {
throw new ModuleManagementToolException("An IO error was encountered during deployment of the AMP into the WAR", exception);
} finally {
try {
TVFS.umount(warFile);
} catch (FsSyncException e) {
throw new ModuleManagementToolException("Error when attempting to unmount WAR file: " + warFile.getPath(), e);
}
}
}
Aggregations