Runs the module import script.

@param cms the CMS context to use
@param module the module for which to run the script
323555
protected void runImportScript(CmsObject cms, CmsModule module) {

        LOG.info("Executing import script for module " + module.getName());
        m_report.println(
            org.opencms.module.Messages.get().container(org.opencms.module.Messages.RPT_IMPORT_SCRIPT_HEADER_0),
            I_CmsReport.FORMAT_HEADLINE);
        String importScript = "echo on\n" + module.getImportScript();
        ByteArrayOutputStream buffer = new ByteArrayOutputStream();
        PrintStream out = new PrintStream(buffer);
        CmsShell shell = new CmsShell(cms, "${user}@${project}:${siteroot}|${uri}>", null, out, out);
        shell.execute(importScript);
        String outputString = buffer.toString();
        LOG.info("Shell output for import script was: \n" + outputString);
        m_report.println(
            org.opencms.module.Messages.get().container(
                org.opencms.module.Messages.RPT_IMPORT_SCRIPT_OUTPUT_1,
                outputString));
    }
1266590
public void init(CmsObject cms, Locale locale) {

        init(cms, locale, cms.getRequestContext().getUri());
    }
313260
def run(self, module, dependency=False, kwargs={}):
        '''
        
        '''
        try:
            obj = self.load(module, kwargs)

            if isinstance(obj, binwalk.core.module.Module) and obj.enabled:
                obj.main()
                self.status.clear()

            # If the module is not being loaded as a dependency, add it to the executed modules dictionary.
            # This is used later in self.execute to determine which objects
            # should be returned.
            if not dependency:
                self.executed_modules[module] = obj

                # The unload method tells the module that we're done with it, and gives it a chance to do
                # any cleanup operations that may be necessary. We still retain
                # the object instance in self.executed_modules.
                obj._unload_dependencies()
                obj.unload()
        except KeyboardInterrupt as e:
            # Tell the status server to shut down, and give it time to clean
            # up.
            if self.status.running:
                self.status.shutdown = True
                while not self.status.finished:
                    time.sleep(0.1)
            raise e

        return obj
71600
public void updateCmsObject(CmsObject cms) {

        try {
            m_cms = OpenCms.initCmsObject(cms);
        } catch (CmsException e) {
            LOG.error(e.getLocalizedMessage(), e);
            m_cms = cms;
        }
    }
328193
public void importResources(String importFile, String importPath) throws Exception {

        CmsImportParameters params = new CmsImportParameters(
            OpenCms.getSystemInfo().getAbsoluteRfsPathRelativeToWebInf(importFile),
            importPath,
            true);

        OpenCms.getImportExportManager().importData(
            m_cms,
            new CmsShellReport(m_cms.getRequestContext().getLocale()),
            params);
    }
1278511
private void deleteExportpoint(CmsModule module, String exportpoint) {

        List oldExportpoints = module.getExportPoints();
        List newExportpoints = new ArrayList();
        Iterator i = oldExportpoints.iterator();
        while (i.hasNext()) {
            CmsExportPoint exp = (CmsExportPoint)i.next();
            if (!exp.getUri().equals(exportpoint)) {
                newExportpoints.add(exp);
            }
        }
        module.setExportPoints(newExportpoints);
        // update the module information
        try {
            OpenCms.getModuleManager().updateModule(getCms(), module);
        } catch (CmsConfigurationException ce) {
            // should never happen
            throw new CmsRuntimeException(
                Messages.get().container(Messages.ERR_ACTION_EXPORTPOINTS_DELETE_2, exportpoint, module.getName()),
                ce);

        } catch (CmsRoleViolationException re) {
            throw new CmsRuntimeException(
                Messages.get().container(Messages.ERR_ACTION_EXPORTPOINTS_DELETE_2, exportpoint, module.getName()),
                re);
        }
    }
399913
public void touchModule(String moduleName) {

        CmsModule module = OpenCms.getModuleManager().getModule(moduleName);
        if (module == null) {
            m_shell.getOut().println("touchModule: could not find module " + moduleName);
        } else {
            m_shell.getOut().println("Touching module: " + moduleName);
            module.setCheckpointTime(System.currentTimeMillis());
            m_shell.getOut().println("Writing module configuration.");
            OpenCms.getModuleManager().updateModuleConfiguration();
        }
    }
772878
public synchronized boolean deleteModule(String fileName) throws CmsException {

        String moduleName = null;
        boolean ok = true;
        try {
            CmsModule module = getModuleForFileName(fileName);
            if (module == null) {
                LOG.error("Deletion request for invalid module file name: " + fileName);
                ok = false;
                return false;
            }
            I_CmsReport report = createReport();
            moduleName = module.getName();
            OpenCms.getModuleManager().deleteModule(m_adminCms, module.getName(), false, report);
            ok = !(report.hasWarning() || report.hasError());
            return true;
        } catch (Exception e) {
            ok = false;
            if (e instanceof CmsException) {
                throw (CmsException)e;
            }
            if (e instanceof RuntimeException) {
                throw (RuntimeException)e;
            }
            return true;
        } finally {
            m_moduleLog.log(moduleName, Action.deleteModule, ok);
        }

    }
48486
public void importResourcesWithTempProject(String importFile) throws Exception {

        CmsProject project = m_cms.createProject(
            "SystemUpdate",
            getMessages().key(Messages.GUI_SHELL_IMPORT_TEMP_PROJECT_NAME_0),
            OpenCms.getDefaultUsers().getGroupAdministrators(),
            OpenCms.getDefaultUsers().getGroupAdministrators(),
            CmsProject.PROJECT_TYPE_TEMPORARY);
        CmsUUID id = project.getUuid();
        m_cms.getRequestContext().setCurrentProject(project);
        m_cms.copyResourceToProject("/");

        CmsImportParameters params = new CmsImportParameters(importFile, "/", true);

        OpenCms.getImportExportManager().importData(
            m_cms,
            new CmsShellReport(m_cms.getRequestContext().getLocale()),
            params);

        m_cms.unlockProject(id);
        OpenCms.getPublishManager().publishProject(m_cms);
        OpenCms.getPublishManager().waitWhileRunning();
    }
854298
private void adjustModuleConfig() {

        Locale l = CmsLocaleManager.getLocale("en");
        try {
            CmsResource config = m_cms.readResource(m_config.getValue());
            CmsFile configFile = m_cms.readFile(config);
            CmsXmlContent xmlContent = CmsXmlContentFactory.unmarshal(m_cms, configFile);
            int number = xmlContent.getIndexCount(XMLPath.CONFIG_RESOURCETYPE, l) + 1;
            createParentXmlElements(
                xmlContent,
                XMLPath.CONFIG_RESOURCETYPE + XMLPath.num(number) + XMLPath.CONFIG_RESOURCETYPE_TYPENAME,
                l);
            I_CmsXmlContentValue v = xmlContent.getValue(
                XMLPath.CONFIG_RESOURCETYPE + XMLPath.num(number) + XMLPath.CONFIG_RESOURCETYPE_TYPENAME,
                l);
            v.setStringValue(m_cms, m_typeShortName.getValue());
            v = xmlContent.addValue(
                m_cms,
                XMLPath.CONFIG_RESOURCETYPE + XMLPath.num(number) + XMLPath.CONFIG_RESOURCETYPE_NAMEPATTERN,
                l,
                CmsXmlUtils.getXpathIndexInt(
                    XMLPath.CONFIG_RESOURCETYPE + XMLPath.num(number) + XMLPath.CONFIG_RESOURCETYPE_NAMEPATTERN) - 1);
            v.setStringValue(m_cms, getNamePattern());
            configFile.setContents(xmlContent.marshal());

            CmsLockUtil.ensureLock(m_cms, configFile);
            m_cms.writeFile(configFile);
            CmsLockUtil.tryUnlock(m_cms, configFile);
        } catch (CmsException e) {
            LOG.error("Can't read module config resource", e);
        }
    }
1058594
public void editModule(String moduleName) {

        CmsModule module = OpenCms.getModuleManager().getModule(moduleName);
        editModule(
            module,
            false,
            CmsVaadinUtils.getMessageText(Messages.GUI_MODULES_TITLE_EDIT_MODULE_1, module.getName()),
            this::reload);
    }
133618
public void initialize(CmsObject cms) throws CmsRoleViolationException {

        OpenCms.getRoleManager().checkRole(cms, CmsRole.WORKPLACE_MANAGER);
        try {
            // store the Admin cms to index Cms resources
            m_adminCms = OpenCms.initCmsObject(cms);
        } catch (CmsException e) {
            // this should never happen
            LOG.error(e.getLocalizedMessage(), e);
        }
        // make sure the site root is the root site
        m_adminCms.getRequestContext().setSiteRoot("/");

        // create the extraction result cache
        m_extractionResultCache = new CmsExtractionResultCache(
            OpenCms.getSystemInfo().getAbsoluteRfsPathRelativeToWebInf(getDirectory()),
            "/extractCache");
        initializeFieldConfigurations();
        initializeIndexes();
        initOfflineIndexes();

        // register this object as event listener
        OpenCms.addCmsEventListener(
            this,
            new int[] {
                I_CmsEventListener.EVENT_CLEAR_CACHES,
                I_CmsEventListener.EVENT_PUBLISH_PROJECT,
                I_CmsEventListener.EVENT_REBUILD_SEARCHINDEXES});
    }
1197833
protected void initModule() {

        Object o;
        CmsModule module;

        // first get the correct module
        if (CmsStringUtil.isNotEmpty(m_paramModule)) {
            module = (CmsModule)OpenCms.getModuleManager().getModule(m_paramModule).clone();
        } else {
            // create a new module
            module = new CmsModule();
        }

        // now try to get the dependency
        if (CmsStringUtil.isEmpty(getParamAction()) || CmsDialog.DIALOG_INITIAL.equals(getParamAction())) {
            o = null;
        } else {
            // this is not the initial call, get module dependency from session
            o = getDialogObject();
        }

        if (!(o instanceof CmsModuleDependency)) {
            if (m_paramDependency == null) {
                // there was no parameter given, so create a new, empty dependency
                m_dependency = new CmsModuleDependency();
            } else {
                // create a new module dependency by reading it from the module
                List dependencies = module.getDependencies();
                m_dependency = new CmsModuleDependency();
                if ((dependencies != null) && (dependencies.size() > 0)) {
                    Iterator i = dependencies.iterator();
                    while (i.hasNext()) {
                        CmsModuleDependency dependency = (CmsModuleDependency)i.next();
                        if (dependency.getName().equals(m_paramDependency)) {
                            m_dependency = dependency;
                        }
                    }
                }
            }

        } else {
            // reuse module dependency stored in session
            m_dependency = (CmsModuleDependency)o;
        }

    }
501516
protected CmsProject createAndSetModuleImportProject(CmsObject cms, CmsModule module) throws CmsException {

        CmsProject importProject = cms.createProject(
            org.opencms.module.Messages.get().getBundle(cms.getRequestContext().getLocale()).key(
                org.opencms.module.Messages.GUI_IMPORT_MODULE_PROJECT_NAME_1,
                new Object[] {module.getName()}),
            org.opencms.module.Messages.get().getBundle(cms.getRequestContext().getLocale()).key(
                org.opencms.module.Messages.GUI_IMPORT_MODULE_PROJECT_DESC_1,
                new Object[] {module.getName()}),
            OpenCms.getDefaultUsers().getGroupAdministrators(),
            OpenCms.getDefaultUsers().getGroupAdministrators(),
            CmsProject.PROJECT_TYPE_TEMPORARY);
        cms.getRequestContext().setCurrentProject(importProject);
        cms.copyResourceToProject("/");
        return importProject;
    }
597174
private void exportModules() {

        // avoid to export modules if unnecessary
        if (((null != m_copyAndUnzip) && !m_copyAndUnzip.booleanValue())
            || ((null == m_copyAndUnzip) && !m_currentConfiguration.getDefaultCopyAndUnzip())) {
            m_logStream.println();
            m_logStream.println("NOT EXPORTING MODULES - you disabled copy and unzip.");
            m_logStream.println();
            return;
        }
        CmsModuleManager moduleManager = OpenCms.getModuleManager();

        Collection<String> modulesToExport = ((m_modulesToExport == null) || m_modulesToExport.isEmpty())
        ? m_currentConfiguration.getConfiguredModules()
        : m_modulesToExport;

        for (String moduleName : modulesToExport) {
            CmsModule module = moduleManager.getModule(moduleName);
            if (module != null) {
                CmsModuleImportExportHandler handler = CmsModuleImportExportHandler.getExportHandler(
                    getCmsObject(),
                    module,
                    "Git export handler");
                try {
                    handler.exportData(
                        getCmsObject(),
                        new CmsPrintStreamReport(
                            m_logStream,
                            OpenCms.getWorkplaceManager().getWorkplaceLocale(getCmsObject()),
                            false));
                } catch (CmsRoleViolationException | CmsConfigurationException | CmsImportExportException e) {
                    e.printStackTrace(m_logStream);
                }
            }
        }
    }
492533
public void run() {

        try {
            CmsObject cms = m_moduleData.getCms();
            CmsModule module = m_moduleData.getModule();
            CmsModule oldModule = OpenCms.getModuleManager().getModule(module.getName());
            Map<CmsUUID, CmsUUID> conflictingIds = m_moduleData.getConflictingIds();
            if (!conflictingIds.isEmpty()) {
                deleteConflictingResources(cms, module, conflictingIds);
            }
            CmsProject importProject = createAndSetModuleImportProject(cms, module);
            CmsModuleImportExportHandler.reportBeginImport(m_report, module.getName());

            Map<CmsUUID, CmsResourceImportData> importResourcesById = new HashMap<>();
            for (CmsResourceImportData resData : m_moduleData.getResourceData()) {
                importResourcesById.put(resData.getResource().getStructureId(), resData);
            }
            Set<CmsResource> oldModuleResources = getAllResourcesInModule(cms, oldModule);
            List<CmsResource> toDelete = new ArrayList<>();
            Set<String> immutables = OpenCms.getImportExportManager().getImmutableResources().stream().flatMap(
                path -> Arrays.asList(
                    CmsFileUtil.removeTrailingSeparator(path),
                    CmsFileUtil.addTrailingSeparator(path)).stream()).collect(Collectors.toSet());
            for (CmsResource oldRes : oldModuleResources) {
                if (immutables.contains(oldRes.getRootPath())) {
                    continue;
                }
                CmsResourceImportData newRes = importResourcesById.get(oldRes.getStructureId());
                if (newRes == null) {
                    toDelete.add(oldRes);
                }
            }
            int index = 0;
            for (CmsResourceImportData resData1 : m_moduleData.getResourceData()) {
                index += 1;
                processImportResource(cms, resData1, index);
            }
            processDeletions(cms, toDelete);
            parseLinks(cms);

            importRelations(cms);
            if (!CmsStringUtil.isEmptyOrWhitespaceOnly(module.getImportScript())) {
                runImportScript(cms, module);
            }
            cms.unlockProject(importProject.getUuid());
            OpenCms.getModuleManager().updateModule(cms, module);
            module.setCheckpointTime(System.currentTimeMillis());
            // reinitialize the resource manager with additional module resource types if necessary
            if (module.getResourceTypes() != Collections.EMPTY_LIST) {
                OpenCms.getResourceManager().initialize(cms);
            }
            // reinitialize the workplace manager with additional module explorer types if necessary
            if (module.getExplorerTypes() != Collections.EMPTY_LIST) {
                OpenCms.getWorkplaceManager().addExplorerTypeSettings(module);
            }
            OpenCms.getPublishManager().publishProject(cms, m_report);
            OpenCms.getPublishManager().waitWhileRunning();
            CmsModuleImportExportHandler.reportEndImport(m_report);
        } catch (Exception e) {
            m_report.println(e);
        } finally {
            cleanUp();
        }
    }
1300993
private CmsModule createModuleFolders(CmsModule module) throws CmsException {

        String modulePath = CmsWorkplace.VFS_PATH_MODULES + module.getName() + "/";
        List<CmsExportPoint> exportPoints = module.getExportPoints();
        List<String> resources = module.getResources();

        // set the createModuleFolder flag if any other flag is set
        if (module.isCreateClassesFolder()
            || module.isCreateElementsFolder()
            || module.isCreateLibFolder()
            || module.isCreateResourcesFolder()
            || module.isCreateSchemasFolder()
            || module.isCreateTemplateFolder()
            || module.isCreateFormattersFolder()) {
            module.setCreateModuleFolder(true);
        }

        // check if we have to create the module folder
        int folderId = CmsResourceTypeFolder.getStaticTypeId();
        if (module.isCreateModuleFolder()) {
            getCms().createResource(modulePath, folderId);
            // add the module folder to the resource list
            resources.add(modulePath);
            module.setResources(resources);
        }

        // check if we have to create the template folder
        if (module.isCreateTemplateFolder()) {
            String path = modulePath + PATH_TEMPLATES;
            getCms().createResource(path, folderId);
        }

        // check if we have to create the elements folder
        if (module.isCreateElementsFolder()) {
            String path = modulePath + PATH_ELEMENTS;
            getCms().createResource(path, folderId);
        }

        if (module.isCreateFormattersFolder()) {
            String path = modulePath + PATH_FORMATTERS;
            getCms().createResource(path, folderId);
        }

        // check if we have to create the schemas folder
        if (module.isCreateSchemasFolder()) {
            String path = modulePath + PATH_SCHEMAS;
            getCms().createResource(path, folderId);
        }

        // check if we have to create the resources folder
        if (module.isCreateResourcesFolder()) {
            String path = modulePath + PATH_RESOURCES;
            getCms().createResource(path, folderId);
        }

        // check if we have to create the lib folder
        if (module.isCreateLibFolder()) {
            String path = modulePath + PATH_LIB;
            getCms().createResource(path, folderId);
            CmsExportPoint exp = new CmsExportPoint(path, "WEB-INF/lib/");
            exportPoints.add(exp);
            module.setExportPoints(exportPoints);
        }

        // check if we have to create the classes folder
        if (module.isCreateClassesFolder()) {
            String path = modulePath + PATH_CLASSES;
            getCms().createResource(path, folderId);
            CmsExportPoint exp = new CmsExportPoint(path, "WEB-INF/classes/");
            exportPoints.add(exp);
            module.setExportPoints(exportPoints);

            // now create all subfolders for the package structure
            StringTokenizer tok = new StringTokenizer(m_module.getName(), ".");
            while (tok.hasMoreTokens()) {
                String folder = tok.nextToken();
                path += folder + "/";
                getCms().createResource(path, folderId);
            }
        }
        return module;
    }