Search in sources :

Example 1 with InstallException

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

the class WikiEventListener method onWikiCreated.

private void onWikiCreated(WikiCreatedEvent event, XWikiContext context) {
    String namespace = "wiki:" + event.getWikiId();
    Collection<InstalledExtension> installedExtensions = this.installedRepository.getInstalledExtensions(null);
    InstallRequest installRequest = new InstallRequest();
    DocumentReference userReference = context.getUserReference();
    if (userReference != null) {
        installRequest.setProperty(PROPERTY_USER_REFERENCE, userReference);
        // We set the string value because the extension repository doesn't know how to serialize/parse an extension
        // property whose value is a DocumentReference, and adding support for it requires considerable refactoring
        // because ExtensionPropertySerializers are not components (they are currently hard-coded).
        installRequest.setExtensionProperty(PROPERTY_USER_REFERENCE, userReference.toString());
    }
    installRequest.setVerbose(false);
    // TODO: make it interactive ? (require wiki creation to be job based)
    installRequest.setInteractive(false);
    ExtensionHandler xarHandler = this.xarHandlerProvider.get();
    for (InstalledExtension installedExtension : installedExtensions) {
        if (installedExtension.getType().equals(XarExtensionHandler.TYPE)) {
            installRequest.addExtension(installedExtension.getId());
            try {
                xarHandler.install(installedExtension, namespace, installRequest);
            } catch (InstallException e) {
                this.logger.error("Failed to import extension [{}] in wiki [{}]", installedExtension, event.getWikiId(), e);
            }
        }
    }
}
Also used : InstalledExtension(org.xwiki.extension.InstalledExtension) InstallRequest(org.xwiki.extension.job.InstallRequest) ExtensionHandler(org.xwiki.extension.handler.ExtensionHandler) InstallException(org.xwiki.extension.InstallException) DocumentReference(org.xwiki.model.reference.DocumentReference)

Example 2 with InstallException

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

the class XarExtensionHandler method install.

@Override
public void install(LocalExtension localExtension, String namespace, Request request) throws InstallException {
    // probably not be in an expected state)
    if (!request.isRemote()) {
        String wiki;
        try {
            wiki = XarHandlerUtils.getWikiFromNamespace(namespace);
        } catch (UnsupportedNamespaceException e) {
            throw new InstallException("Failed to extract wiki id from namespace", e);
        }
        installInternal(localExtension, wiki, request);
    }
}
Also used : InstallException(org.xwiki.extension.InstallException)

Example 3 with InstallException

use of org.xwiki.extension.InstallException 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 4 with InstallException

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

the class FlavorSearchJob method tryInstallExtension.

/**
 * Try to install the provided extension and update the plan if it's working.
 *
 * @param extensionId the extension version to install
 * @param namespace the namespace where to install the extension
 * @return true if the installation would succeed, false otherwise
 */
private Extension tryInstallExtension(ExtensionId extensionId, String namespace) {
    DefaultExtensionPlanTree currentTree = new DefaultExtensionPlanTree();
    try {
        installExtension(extensionId, namespace, currentTree);
        // Cleanup
        this.extensionsNodeCache.clear();
        return currentTree.get(0).getAction().getExtension();
    } catch (InstallException e) {
        this.logger.debug("Can't install extension [{}] on namespace [{}].", extensionId, namespace, e);
    }
    return null;
}
Also used : DefaultExtensionPlanTree(org.xwiki.extension.job.plan.internal.DefaultExtensionPlanTree) InstallException(org.xwiki.extension.InstallException)

Example 5 with InstallException

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

the class XarExtensionHandler method upgrade.

@Override
public void upgrade(Collection<InstalledExtension> previousLocalExtensions, LocalExtension newLocalExtension, String namespace, Request request) throws InstallException {
    // probably not be in an expected state)
    if (!request.isRemote()) {
        String wiki;
        try {
            wiki = XarHandlerUtils.getWikiFromNamespace(namespace);
        } catch (UnsupportedNamespaceException e) {
            throw new InstallException("Failed to extract wiki id from namespace", e);
        }
        // Install new pages
        installInternal(newLocalExtension, wiki, request);
    }
}
Also used : InstallException(org.xwiki.extension.InstallException)

Aggregations

InstallException (org.xwiki.extension.InstallException)6 InstalledExtension (org.xwiki.extension.InstalledExtension)2 File (java.io.File)1 IOException (java.io.IOException)1 ComponentLookupException (org.xwiki.component.manager.ComponentLookupException)1 Extension (org.xwiki.extension.Extension)1 ExtensionException (org.xwiki.extension.ExtensionException)1 LocalExtension (org.xwiki.extension.LocalExtension)1 ResolveException (org.xwiki.extension.ResolveException)1 UninstallException (org.xwiki.extension.UninstallException)1 ExtensionHandler (org.xwiki.extension.handler.ExtensionHandler)1 InstallRequest (org.xwiki.extension.job.InstallRequest)1 DefaultExtensionPlanTree (org.xwiki.extension.job.plan.internal.DefaultExtensionPlanTree)1 LocalExtensionRepositoryException (org.xwiki.extension.repository.LocalExtensionRepositoryException)1 PackageConfiguration (org.xwiki.extension.xar.internal.handler.packager.PackageConfiguration)1 DocumentReference (org.xwiki.model.reference.DocumentReference)1 XarException (org.xwiki.xar.XarException)1