Search in sources :

Example 11 with InstallRequest

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

the class ExtensionInstallerTest method installExtension.

@Test
public void installExtension() throws Exception {
    // Mocks
    InstallJob installJob = mock(InstallJob.class);
    mocker.registerComponent(Job.class, InstallJob.JOBTYPE, installJob);
    final InstallRequest[] installRequest = { null };
    doAnswer(new Answer() {

        @Override
        public Object answer(InvocationOnMock invocation) throws Throwable {
            installRequest[0] = (InstallRequest) invocation.getArguments()[0];
            return null;
        }
    }).when(installJob).initialize(any(Request.class));
    // Test
    mocker.getComponentUnderTest().installExtension("wikiId", new ExtensionId("extensionId", "version"));
    // Verify
    assertNotNull(installRequest[0]);
    assertEquals(Arrays.asList("wiki:wikiId"), installRequest[0].getNamespaces());
    assertEquals(Arrays.asList("wikicreation", "install", "wikiId"), installRequest[0].getId());
    assertEquals(Arrays.asList(new ExtensionId("extensionId", "version")), installRequest[0].getExtensions());
    assertEquals(new DocumentReference("xwiki", "XWiki", "superadmin"), installRequest[0].getProperty("user.reference"));
    verify(installJob).run();
}
Also used : Answer(org.mockito.stubbing.Answer) Mockito.doAnswer(org.mockito.Mockito.doAnswer) InstallRequest(org.xwiki.extension.job.InstallRequest) InvocationOnMock(org.mockito.invocation.InvocationOnMock) Request(org.xwiki.job.Request) InstallRequest(org.xwiki.extension.job.InstallRequest) ExtensionId(org.xwiki.extension.ExtensionId) DocumentReference(org.xwiki.model.reference.DocumentReference) InstallJob(org.xwiki.extension.job.internal.InstallJob) Test(org.junit.Test)

Example 12 with InstallRequest

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

the class DataMojo method executeInternal.

@Override
public void executeInternal() throws MojoExecutionException {
    InstallRequest installRequest = new InstallRequest();
    // Allow modifying root namespace
    installRequest.setRootModificationsAllowed(true);
    // 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);
    // Use superadmin as pages author
    installRequest.setProperty(AbstractExtensionValidator.PROPERTY_USERREFERENCE, new DocumentReference("xwiki", "XWiki", XWikiRightService.SUPERADMIN_USER));
    this.extensionHelper.install(this.includes, installRequest, "wiki:xwiki", null);
}
Also used : ScriptExtensionRewriter(org.xwiki.extension.script.ScriptExtensionRewriter) InstallRequest(org.xwiki.extension.job.InstallRequest) DocumentReference(org.xwiki.model.reference.DocumentReference)

Example 13 with InstallRequest

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

the class ExtensionInstaller method installExtension.

/**
 * Install an extension on a wiki.
 *
 * @param wikiId id of the wiki
 * @param extensionId id of the extension to install
 * @throws org.xwiki.platform.wiki.creationjob.WikiCreationException if problem occurs
 */
public void installExtension(String wikiId, ExtensionId extensionId) throws WikiCreationException {
    try {
        // Create the install request
        InstallRequest installRequest = new InstallRequest();
        installRequest.setId(Arrays.asList(WikiCreationJob.JOB_ID_PREFIX, "install", wikiId));
        installRequest.addExtension(extensionId);
        installRequest.addNamespace("wiki:" + wikiId);
        // To avoid problem with Programming Rights, we install everything with superadmin
        installRequest.setProperty(PROPERTY_USERREFERENCE, SUPERADMIN_REFERENCE);
        InstallJob job = componentManager.getInstance(Job.class, InstallJob.JOBTYPE);
        job.initialize(installRequest);
        job.run();
    } catch (ComponentLookupException e) {
        throw new WikiCreationException(String.format("Failed to install the extension [%s] on the wiki [%s].", extensionId.toString(), wikiId), e);
    }
}
Also used : WikiCreationException(org.xwiki.platform.wiki.creationjob.WikiCreationException) InstallRequest(org.xwiki.extension.job.InstallRequest) ComponentLookupException(org.xwiki.component.manager.ComponentLookupException) InstallJob(org.xwiki.extension.job.internal.InstallJob)

Example 14 with InstallRequest

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

the class XarExtensionHandlerTest method installOnNamespace.

private XarInstalledExtension installOnNamespace(ExtensionId extensionId, String namespace, DocumentReference user) throws Throwable {
    InstallRequest installRequest = new InstallRequest();
    if (user != null) {
        installRequest.setProperty("user.reference", getXWikiContext().getUserReference());
        installRequest.setProperty("checkrights", true);
    }
    installRequest.addExtension(extensionId);
    if (namespace != null) {
        installRequest.addNamespace(namespace);
    }
    Job installJob = this.jobExecutor.execute(InstallJob.JOBTYPE, installRequest);
    installJob.join();
    List<LogEvent> errors = installJob.getStatus().getLog().getLogsFrom(LogLevel.WARN);
    if (!errors.isEmpty()) {
        if (errors.get(0).getThrowable() != null) {
            throw errors.get(0).getThrowable();
        } else {
            throw new Exception(errors.get(0).getFormattedMessage());
        }
    }
    return (XarInstalledExtension) this.xarExtensionRepository.resolve(extensionId);
}
Also used : LogEvent(org.xwiki.logging.event.LogEvent) XarInstalledExtension(org.xwiki.extension.xar.internal.repository.XarInstalledExtension) InstallRequest(org.xwiki.extension.job.InstallRequest) UninstallJob(org.xwiki.extension.job.internal.UninstallJob) InstallJob(org.xwiki.extension.job.internal.InstallJob) Job(org.xwiki.job.Job) UninstallException(org.xwiki.extension.UninstallException) AccessDeniedException(org.xwiki.security.authorization.AccessDeniedException) InstallException(org.xwiki.extension.InstallException)

Example 15 with InstallRequest

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

the class DiffXarJob method runInternal.

@Override
protected void runInternal() throws Exception {
    InstallRequest request = getRequest();
    // There must be only one namespace specified because we compute the differences for only one wiki.
    if (!request.hasNamespaces() || request.getNamespaces().size() != 1) {
        return;
    }
    String namespace = request.getNamespaces().iterator().next();
    Collection<ExtensionId> extensionIds = request.getExtensions();
    this.progressManager.pushLevelProgress(extensionIds.size(), this);
    try {
        for (ExtensionId extensionId : extensionIds) {
            this.progressManager.startStep(this);
            InstalledExtension installedExtension = getInstalledExtension(extensionId, namespace);
            // Make sure the specified extension is installed on the specified namespace.
            if (installedExtension != null && installedExtension.isInstalled(namespace)) {
                diff(extensionId.getId(), namespace, new HashSet<>());
            }
            this.progressManager.endStep(this);
        }
    } finally {
        this.progressManager.popLevelProgress(this);
    }
}
Also used : InstalledExtension(org.xwiki.extension.InstalledExtension) InstallRequest(org.xwiki.extension.job.InstallRequest) 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