Search in sources :

Example 16 with ModuleDetails

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;
}
Also used : TFileInputStream(de.schlichtherle.truezip.file.TFileInputStream) InputStream(java.io.InputStream) TFileInputStream(de.schlichtherle.truezip.file.TFileInputStream) ArrayList(java.util.ArrayList) ModuleDetails(org.alfresco.service.cmr.module.ModuleDetails) IOException(java.io.IOException) TFile(de.schlichtherle.truezip.file.TFile) AlfrescoRuntimeException(org.alfresco.error.AlfrescoRuntimeException) TFile(de.schlichtherle.truezip.file.TFile)

Example 17 with 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;
}
Also used : ModuleDetails(org.alfresco.service.cmr.module.ModuleDetails)

Example 18 with ModuleDetails

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);
    }
}
Also used : BufferedInputStream(java.io.BufferedInputStream) BufferedInputStream(java.io.BufferedInputStream) InputStream(java.io.InputStream) Resource(org.springframework.core.io.Resource) AlfrescoRuntimeException(org.alfresco.error.AlfrescoRuntimeException) ModuleDetails(org.alfresco.service.cmr.module.ModuleDetails) IOException(java.io.IOException) Properties(java.util.Properties)

Example 19 with ModuleDetails

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;
}
Also used : ArrayList(java.util.ArrayList) ModuleDetails(org.alfresco.service.cmr.module.ModuleDetails)

Example 20 with ModuleDetails

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);
        }
    }
}
Also used : FsSyncException(de.schlichtherle.truezip.fs.FsSyncException) ModuleDetails(org.alfresco.service.cmr.module.ModuleDetails) IOException(java.io.IOException) ModuleVersionNumber(org.alfresco.repo.module.ModuleVersionNumber) AlfrescoRuntimeException(org.alfresco.error.AlfrescoRuntimeException)

Aggregations

ModuleDetails (org.alfresco.service.cmr.module.ModuleDetails)27 TFile (de.schlichtherle.truezip.file.TFile)9 Properties (java.util.Properties)7 ModuleDetailsImpl (org.alfresco.repo.module.ModuleDetailsImpl)7 Test (org.junit.Test)7 IOException (java.io.IOException)4 ArrayList (java.util.ArrayList)4 ModuleVersionNumber (org.alfresco.repo.module.ModuleVersionNumber)4 VersionNumber (org.alfresco.util.VersionNumber)4 AlfrescoRuntimeException (org.alfresco.error.AlfrescoRuntimeException)3 ModuleDependency (org.alfresco.service.cmr.module.ModuleDependency)3 TFileInputStream (de.schlichtherle.truezip.file.TFileInputStream)2 InputStream (java.io.InputStream)2 HashMap (java.util.HashMap)2 ModulePackage (org.alfresco.rest.api.model.ModulePackage)2 AuditService (org.alfresco.service.cmr.audit.AuditService)2 BasicDataSource (org.apache.commons.dbcp.BasicDataSource)2 FsSyncException (de.schlichtherle.truezip.fs.FsSyncException)1 BufferedInputStream (java.io.BufferedInputStream)1 FileNotFoundException (java.io.FileNotFoundException)1