Search in sources :

Example 1 with LocalExtension

use of org.xwiki.extension.LocalExtension in project xwiki-platform by xwiki.

the class DocumentsModifiedDuringDistributionListener method checkXARHandler.

private void checkXARHandler(Event event, XWikiDocument document, XWikiContext xcontext) {
    ExecutionContext context = this.execution.getContext();
    if (context != null) {
        XarExtensionPlan xarExtensionPlan = (XarExtensionPlan) context.getProperty(XarExtensionPlan.CONTEXTKEY_XARINSTALLPLAN);
        if (xarExtensionPlan != null) {
            Request request = this.jobContext.getCurrentJob().getRequest();
            // It's a job started by the Distribution Wizard
            if (StringUtils.equals(request.<String>getProperty("context.action"), "distribution")) {
                String distributionWiki = request.getProperty("context.wiki");
                if (distributionWiki != null) {
                    DocumentReference reference = document.getDocumentReferenceWithLocale();
                    DocumentStatus.Action action = toAction(event);
                    LocalExtension previousExtension = xarExtensionPlan.getPreviousXarExtension(reference);
                    LocalExtension nextExtension = xarExtensionPlan.getNextXarExtension(reference);
                    addDocument(distributionWiki, document, action, previousExtension, nextExtension);
                }
            }
        }
    }
}
Also used : ExecutionContext(org.xwiki.context.ExecutionContext) XarExtensionPlan(org.xwiki.extension.xar.internal.handler.XarExtensionPlan) Request(org.xwiki.job.Request) Action(org.xwiki.extension.distribution.internal.DocumentsModifiedDuringDistributionListener.DocumentStatus.Action) LocalExtension(org.xwiki.extension.LocalExtension) DocumentReference(org.xwiki.model.reference.DocumentReference)

Example 2 with LocalExtension

use of org.xwiki.extension.LocalExtension in project xwiki-platform by xwiki.

the class RepairXarJob method getLocalXARExtension.

/**
 * @param extensionId the extension unique identifier
 * @return the stored local extension
 * @throws InstallException failed to store extension
 */
private LocalExtension getLocalXARExtension(ExtensionId extensionId) throws InstallException {
    LocalExtension localExtension = this.localRepository.getLocalExtension(extensionId);
    if (localExtension == null) {
        this.progressManager.pushLevelProgress(2, this);
        try {
            this.progressManager.startStep(this);
            Extension extension = this.repositoryManager.resolve(extensionId);
            this.progressManager.endStep(this);
            this.progressManager.startStep(this);
            if (extension.getType().equals(XarExtensionHandler.TYPE)) {
                localExtension = this.localExtensionRepository.storeExtension(extension);
            }
            this.progressManager.endStep(this);
        } catch (ResolveException e) {
            throw new InstallException("Failed to find extension", e);
        } catch (LocalExtensionRepositoryException e) {
            throw new InstallException("Failed save extension in local repository", e);
        } finally {
            this.progressManager.popLevelProgress(this);
        }
    } else if (!localExtension.getType().equals(XarExtensionHandler.TYPE)) {
        localExtension = null;
    }
    return localExtension;
}
Also used : Extension(org.xwiki.extension.Extension) InstalledExtension(org.xwiki.extension.InstalledExtension) LocalExtension(org.xwiki.extension.LocalExtension) ResolveException(org.xwiki.extension.ResolveException) LocalExtensionRepositoryException(org.xwiki.extension.repository.LocalExtensionRepositoryException) LocalExtension(org.xwiki.extension.LocalExtension) InstallException(org.xwiki.extension.InstallException)

Example 3 with LocalExtension

use of org.xwiki.extension.LocalExtension in project xwiki-platform by xwiki.

the class ExtensionInstanceOutputFilterStream method endExtension.

@Override
public void endExtension(String id, String version, FilterEventParameters parameters) throws FilterException {
    // TODO: add support for complete extension
    ExtensionId extensionId = new ExtensionId(id, factory.getVersion(version));
    try {
        LocalExtension localExtension = this.localRepository.getLocalExtension(extensionId);
        if (localExtension == null) {
            Extension extension;
            try {
                // Try to find and download the extension from a repository
                extension = this.extensionRepository.resolve(extensionId);
            } catch (ResolveException e) {
                this.logger.debug("Can't find extension [{}]", extensionId, e);
                // FIXME: Create a dummy extension. Need support for partial/lazy extension.
                return;
            }
            localExtension = this.localRepository.storeExtension(extension);
        }
        String namespace = getCurrentNamespace();
        // TODO: should probably make it configurable
        if (installedRepository.getInstalledExtension(localExtension.getId().getId(), namespace) == null) {
            for (ExtensionId feature : localExtension.getExtensionFeatures()) {
                if (installedRepository.getInstalledExtension(feature.getId(), namespace) != null) {
                    // Already exist so don't register it or it could create a mess
                    return;
                }
            }
        } else {
            return;
        }
        // Register the extension as installed
        installedRepository.installExtension(localExtension, namespace, false);
    } catch (Exception e) {
        this.logger.error("Failed to register extenion [{}] from the XAR", extensionId, e);
    }
}
Also used : Extension(org.xwiki.extension.Extension) LocalExtension(org.xwiki.extension.LocalExtension) ResolveException(org.xwiki.extension.ResolveException) LocalExtension(org.xwiki.extension.LocalExtension) ExtensionId(org.xwiki.extension.ExtensionId) IOException(java.io.IOException) ResolveException(org.xwiki.extension.ResolveException) FilterException(org.xwiki.filter.FilterException)

Example 4 with LocalExtension

use of org.xwiki.extension.LocalExtension in project xwiki-platform by xwiki.

the class RepairXarJob method repairExtension.

/**
 * @param extensionId the unique extension identifier
 * @param namespace the namespace where to install extension
 * @param dependency indicate of the extension is installed as a dependency of another
 * @param managedDependencies the managed dependencies
 * @throws InstallException failed to repair extension
 */
private void repairExtension(ExtensionId extensionId, String namespace, boolean dependency, Map<String, ExtensionDependency> managedDependencies) throws InstallException {
    if (this.installedRepository.getInstalledExtension(extensionId.getId(), namespace) != null) {
        this.logger.debug("Extension [{}] already installed on namespace [{}]", extensionId.getId(), namespace);
        return;
    }
    if (getRequest().isVerbose()) {
        if (namespace != null) {
            this.logger.info(LOG_REPAIR_NAMESPACE_BEGIN, "Repairing XAR extension [{}] on namespace [{}]", extensionId, namespace);
        } else {
            this.logger.info(LOG_REPAIR_BEGIN, "Repairing XAR extension [{}] on all namespaces", extensionId, namespace);
        }
    }
    this.progressManager.pushLevelProgress(2, this);
    try {
        this.progressManager.startStep(this);
        LocalExtension localExtension = getLocalXARExtension(extensionId);
        this.progressManager.endStep(this);
        this.progressManager.startStep(this);
        if (localExtension != null) {
            repairExtension(localExtension, namespace, dependency, managedDependencies);
        }
    } finally {
        if (getRequest().isVerbose()) {
            if (namespace != null) {
                this.logger.info(LOG_REPAIR_END_NAMESPACE, "Done repairing XAR extension [{}] on namespace [{}]", extensionId, namespace);
            } else {
                this.logger.info(LOG_REPAIR_END, "Done repairing XAR extension [{}] on all namespaces", extensionId, namespace);
            }
        }
        this.progressManager.popLevelProgress(this);
    }
}
Also used : LocalExtension(org.xwiki.extension.LocalExtension)

Example 5 with LocalExtension

use of org.xwiki.extension.LocalExtension in project xwiki-platform by xwiki.

the class XarExtensionHandler method createPackageConfiguration.

private PackageConfiguration createPackageConfiguration(LocalExtension extension, Request request, String wiki) {
    PackageConfiguration configuration;
    // Search job configuration in the context
    ExecutionContext context = this.execution.getContext();
    if (context != null) {
        configuration = (PackageConfiguration) context.getProperty(CONTEXTKEY_PACKAGECONFIGURATION);
    } else {
        configuration = null;
    }
    // Create a configuration for this extension
    if (configuration != null) {
        configuration = configuration.clone();
    } else {
        configuration = new PackageConfiguration();
        DocumentReference userReference = getRequestUserReference(AbstractExtensionValidator.PROPERTY_USERREFERENCE, request);
        configuration.setInteractive(request.isInteractive());
        configuration.setUser(userReference);
        configuration.setVerbose(request.isVerbose());
        configuration.setSkipMandatorytDocuments(true);
    }
    configuration.setWiki(wiki);
    // Filter entries to import if there is a plan
    if (extension != null && configuration.getXarExtensionPlan() != null) {
        Map<String, Map<XarEntry, LocalExtension>> nextXAREntries = configuration.getXarExtensionPlan().nextXAREntries;
        Set<String> entriesToImport = new HashSet<>();
        Map<XarEntry, LocalExtension> nextXAREntriesOnRoot = nextXAREntries.get(null);
        if (nextXAREntriesOnRoot != null) {
            for (Map.Entry<XarEntry, LocalExtension> entry : nextXAREntriesOnRoot.entrySet()) {
                if (entry.getValue() == extension) {
                    entriesToImport.add(entry.getKey().getEntryName());
                }
            }
        }
        Map<XarEntry, LocalExtension> nextXAREntriesOnWiki = nextXAREntries.get(wiki);
        if (nextXAREntriesOnWiki != null) {
            for (Map.Entry<XarEntry, LocalExtension> entry : nextXAREntriesOnWiki.entrySet()) {
                if (entry.getValue() == extension) {
                    entriesToImport.add(entry.getKey().getEntryName());
                }
            }
        }
        configuration.setEntriesToImport(entriesToImport);
    }
    return configuration;
}
Also used : ExecutionContext(org.xwiki.context.ExecutionContext) XarEntry(org.xwiki.xar.XarEntry) LocalExtension(org.xwiki.extension.LocalExtension) PackageConfiguration(org.xwiki.extension.xar.internal.handler.packager.PackageConfiguration) Map(java.util.Map) DocumentReference(org.xwiki.model.reference.DocumentReference) HashSet(java.util.HashSet)

Aggregations

LocalExtension (org.xwiki.extension.LocalExtension)8 IOException (java.io.IOException)3 ExecutionContext (org.xwiki.context.ExecutionContext)3 Extension (org.xwiki.extension.Extension)3 ResolveException (org.xwiki.extension.ResolveException)3 DocumentReference (org.xwiki.model.reference.DocumentReference)3 XarEntry (org.xwiki.xar.XarEntry)3 HashSet (java.util.HashSet)2 Map (java.util.Map)2 ExtensionId (org.xwiki.extension.ExtensionId)2 InstalledExtension (org.xwiki.extension.InstalledExtension)2 PackageConfiguration (org.xwiki.extension.xar.internal.handler.packager.PackageConfiguration)2 XWikiContext (com.xpn.xwiki.XWikiContext)1 XWikiException (com.xpn.xwiki.XWikiException)1 XWikiDocument (com.xpn.xwiki.doc.XWikiDocument)1 DocumentException (org.dom4j.DocumentException)1 InstallException (org.xwiki.extension.InstallException)1 Action (org.xwiki.extension.distribution.internal.DocumentsModifiedDuringDistributionListener.DocumentStatus.Action)1 ExtensionInstalledEvent (org.xwiki.extension.event.ExtensionInstalledEvent)1 InstalledExtensionRepository (org.xwiki.extension.repository.InstalledExtensionRepository)1