Search in sources :

Example 1 with InstallRequest

use of org.xwiki.extension.job.InstallRequest 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 InstallRequest

use of org.xwiki.extension.job.InstallRequest in project xwiki-platform by xwiki.

the class AbstractExtensionDistributionStep method install.

protected void install(ExtensionId extensionId, String namespace, boolean jarOnRoot) throws JobException, InterruptedException {
    // Install the default UI
    InstallRequest installRequest = new InstallRequest();
    installRequest.setId(ExtensionRequest.getJobId(ExtensionRequest.JOBID_ACTION_PREFIX, extensionId.getId(), namespace));
    installRequest.addExtension(extensionId);
    installRequest.addNamespace(namespace);
    // Indicate it's allowed to do modification on root namespace
    installRequest.setRootModificationsAllowed(true);
    // Make sure the job is no interactive
    installRequest.setInteractive(false);
    if (jarOnRoot) {
        // Make sure jars are installed on root
        // TODO: use a less script oriented class
        ScriptExtensionRewriter rewriter = new ScriptExtensionRewriter();
        rewriter.installExtensionTypeOnRootNamespace("jar");
        rewriter.installExtensionTypeOnRootNamespace("webjar");
        installRequest.setRewriter(rewriter);
    }
    // Set the author to use
    installRequest.setProperty(AbstractExtensionValidator.PROPERTY_USERREFERENCE, new DocumentReference("xwiki", "XWiki", XWikiRightService.SUPERADMIN_USER));
    installRequest.setExtensionProperty(AbstractExtensionValidator.PROPERTY_USERREFERENCE, XWikiRightService.SUPERADMIN_USER_FULLNAME);
    this.jobExecutor.execute(InstallJob.JOBTYPE, installRequest).join();
}
Also used : ScriptExtensionRewriter(org.xwiki.extension.script.ScriptExtensionRewriter) InstallRequest(org.xwiki.extension.job.InstallRequest) DocumentReference(org.xwiki.model.reference.DocumentReference)

Example 3 with InstallRequest

use of org.xwiki.extension.job.InstallRequest in project xwiki-platform by xwiki.

the class ExtensionManagerScriptService method createUpgradePlanRequest.

/**
 * Create a request used when asking for the upgrade plan on the whole farm.
 *
 * @return the request to pass t the job
 */
private InstallRequest createUpgradePlanRequest() {
    InstallRequest installRequest = new InstallRequest();
    installRequest.setId(ExtensionRequest.getJobId(ExtensionRequest.JOBID_PLAN_PREFIX, null, null));
    contextualize(installRequest);
    return installRequest;
}
Also used : InstallRequest(org.xwiki.extension.job.InstallRequest)

Example 4 with InstallRequest

use of org.xwiki.extension.job.InstallRequest in project xwiki-platform by xwiki.

the class ExtensionManagerScriptService method createUpgradePlanRequest.

/**
 * Create a request used when asking for the upgrade plan of an extension on a namespace.
 *
 * @param extensionId the id of the extension
 * @param namespace the namespace to upgrade
 * @return the request to pass t the job
 * @since 9.5
 */
public InstallRequest createUpgradePlanRequest(ExtensionId extensionId, String namespace) {
    InstallRequest installRequest = new InstallRequest();
    installRequest.addNamespace(namespace);
    List<String> jobId;
    if (extensionId != null) {
        installRequest.addExtension(extensionId);
        jobId = ExtensionRequest.getJobId(ExtensionRequest.JOBID_PLAN_PREFIX, extensionId.getId(), namespace);
    } else {
        jobId = ExtensionRequest.getJobId(ExtensionRequest.JOBID_PLAN_PREFIX, null, namespace);
    }
    installRequest.setId(jobId);
    contextualize(installRequest);
    return installRequest;
}
Also used : InstallRequest(org.xwiki.extension.job.InstallRequest)

Example 5 with InstallRequest

use of org.xwiki.extension.job.InstallRequest in project xwiki-platform by xwiki.

the class ExtensionManagerScriptService method createInstallPlanRequest.

/**
 * Create an {@link InstallRequest} instance based on given parameters, to be used to create the install plan.
 *
 * @param id the identifier of the extension to install
 * @param version the version to install
 * @param namespace the (optional) namespace where to install the extension; if {@code null} or empty, the extension
 *            will be installed in root namespace (globally)
 * @return the {@link InstallRequest}
 */
public InstallRequest createInstallPlanRequest(String id, String version, String namespace) {
    InstallRequest installRequest = new InstallRequest();
    installRequest.setId(ExtensionRequest.getJobId(ExtensionRequest.JOBID_PLAN_PREFIX, id, namespace));
    installRequest.setInteractive(true);
    installRequest.addExtension(new ExtensionId(id, version));
    if (StringUtils.isNotBlank(namespace)) {
        installRequest.addNamespace(namespace);
    }
    XWikiContext xcontext = this.xcontextProvider.get();
    // Indicate if it's allowed to do modification on root namespace
    installRequest.setRootModificationsAllowed(namespace == null || xcontext.isMainWiki(toWikiId(namespace)));
    // Allow overwritting a few things in extensions descriptors
    installRequest.setRewriter(new ScriptExtensionRewriter());
    contextualize(installRequest);
    setRightsProperties(installRequest);
    return installRequest;
}
Also used : InstallRequest(org.xwiki.extension.job.InstallRequest) XWikiContext(com.xpn.xwiki.XWikiContext) ExtensionId(org.xwiki.extension.ExtensionId)

Aggregations

InstallRequest (org.xwiki.extension.job.InstallRequest)21 DocumentReference (org.xwiki.model.reference.DocumentReference)8 Test (org.junit.Test)7 Job (org.xwiki.job.Job)7 ExtensionId (org.xwiki.extension.ExtensionId)6 ExtensionJobHistoryRecord (org.xwiki.extension.job.history.ExtensionJobHistoryRecord)4 ReplayRequest (org.xwiki.extension.job.history.ReplayRequest)3 ReplayJob (org.xwiki.extension.job.history.internal.ReplayJob)3 InstallJob (org.xwiki.extension.job.internal.InstallJob)3 WikiReference (org.xwiki.model.reference.WikiReference)3 IOException (java.io.IOException)2 InstallException (org.xwiki.extension.InstallException)2 InstalledExtension (org.xwiki.extension.InstalledExtension)2 UninstallRequest (org.xwiki.extension.job.UninstallRequest)2 ScriptExtensionRewriter (org.xwiki.extension.script.ScriptExtensionRewriter)2 JobException (org.xwiki.job.JobException)2 LogEvent (org.xwiki.logging.event.LogEvent)2 XarException (org.xwiki.xar.XarException)2 XWikiContext (com.xpn.xwiki.XWikiContext)1 Predicate (org.apache.commons.collections4.Predicate)1