Search in sources :

Example 21 with ExtensionId

use of org.xwiki.extension.ExtensionId 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)

Example 22 with ExtensionId

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

the class XarInstalledExtensionRepository method getXarInstalledExtensions.

/**
 * @param reference the reference of the document
 * @return the extension owners of the passed document
 * @since 8.1M2
 */
public Collection<XarInstalledExtension> getXarInstalledExtensions(DocumentReference reference) {
    if (reference instanceof DocumentVersionReference) {
        DocumentVersionReference versionReference = (DocumentVersionReference) reference;
        if (versionReference.getVersion() instanceof ExtensionId) {
            ExtensionId extensionId = (ExtensionId) versionReference.getVersion();
            if (extensionId != null) {
                return Arrays.asList((XarInstalledExtension) getInstalledExtension(extensionId));
            }
        }
    }
    Collection<XarInstalledExtension> wikiExtensions = this.documents.get(reference.getLocale() == null ? new DocumentReference(reference, Locale.ROOT) : reference);
    Collection<XarInstalledExtension> rootExtensions = this.rootDocuments.get(reference.getLocalDocumentReference().getLocale() == null ? new LocalDocumentReference(reference.getLocalDocumentReference(), Locale.ROOT) : reference.getLocalDocumentReference());
    List<XarInstalledExtension> allExtensions = new ArrayList<>();
    if (wikiExtensions != null) {
        allExtensions.addAll(wikiExtensions);
    }
    if (rootExtensions != null) {
        allExtensions.addAll(rootExtensions);
    }
    return allExtensions;
}
Also used : LocalDocumentReference(org.xwiki.model.reference.LocalDocumentReference) DocumentVersionReference(org.xwiki.extension.xar.job.diff.DocumentVersionReference) ArrayList(java.util.ArrayList) ExtensionId(org.xwiki.extension.ExtensionId) LocalDocumentReference(org.xwiki.model.reference.LocalDocumentReference) DocumentReference(org.xwiki.model.reference.DocumentReference)

Example 23 with ExtensionId

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

the class DocumentsDeletingListenerTest method testCancel.

@Test
public void testCancel() throws Exception {
    Request request = mock(Request.class);
    Job job = mock(Job.class);
    JobStatus status = mock(JobStatus.class);
    when(job.getRequest()).thenReturn(request);
    when(request.isInteractive()).thenReturn(true);
    when(job.getStatus()).thenReturn(status);
    Map<EntityReference, EntitySelection> concernedEntities = new HashMap<>();
    DocumentReference doc1 = new DocumentReference("a", "b", "c1");
    concernedEntities.put(doc1, new EntitySelection(doc1));
    XarInstalledExtension ext1 = mock(XarInstalledExtension.class);
    when(ext1.getId()).thenReturn(new ExtensionId("ext1"));
    when(repository.getXarInstalledExtensions(doc1)).thenReturn(Arrays.asList(ext1));
    InterruptedException e = new InterruptedException();
    doThrow(e).when(status).ask(any(), anyLong(), any());
    // Test
    DocumentsDeletingEvent event = mock(DocumentsDeletingEvent.class);
    mocker.getComponentUnderTest().onEvent(event, job, concernedEntities);
    // Check
    verify(status, times(1)).ask(any(), eq(5L), eq(TimeUnit.MINUTES));
    verify(event).cancel(eq("Question has been interrupted."));
    verify(mocker.getMockedLogger()).warn("Confirm question has been interrupted.");
}
Also used : JobStatus(org.xwiki.job.event.status.JobStatus) HashMap(java.util.HashMap) XarInstalledExtension(org.xwiki.extension.xar.internal.repository.XarInstalledExtension) EntitySelection(org.xwiki.refactoring.job.question.EntitySelection) Request(org.xwiki.job.Request) EntityReference(org.xwiki.model.reference.EntityReference) ExtensionId(org.xwiki.extension.ExtensionId) Job(org.xwiki.job.Job) DocumentReference(org.xwiki.model.reference.DocumentReference) DocumentsDeletingEvent(org.xwiki.bridge.event.DocumentsDeletingEvent) Test(org.junit.Test)

Example 24 with ExtensionId

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

the class FlavorSearchJob method findValidVersion.

private Extension findValidVersion(String flavorId, String namespace, List<Version> versionList) {
    this.progressManager.pushLevelProgress(versionList.size(), flavorId);
    try {
        for (ListIterator<Version> it = versionList.listIterator(versionList.size()); it.hasPrevious(); ) {
            this.progressManager.startStep(flavorId);
            Version version = it.previous();
            Extension extension = tryInstallExtension(new ExtensionId(flavorId, version), namespace);
            this.progressManager.endStep(flavorId);
            if (extension != null) {
                return extension;
            }
        }
    } finally {
        this.progressManager.popLevelProgress(flavorId);
    }
    return null;
}
Also used : Extension(org.xwiki.extension.Extension) Version(org.xwiki.extension.version.Version) ExtensionId(org.xwiki.extension.ExtensionId)

Example 25 with ExtensionId

use of org.xwiki.extension.ExtensionId 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)

Aggregations

ExtensionId (org.xwiki.extension.ExtensionId)67 Test (org.junit.Test)37 InstalledExtension (org.xwiki.extension.InstalledExtension)13 ExtensionAdministrationPage (org.xwiki.extension.test.po.ExtensionAdministrationPage)11 TestExtension (org.xwiki.repository.test.TestExtension)11 ExtensionPane (org.xwiki.extension.test.po.ExtensionPane)9 DocumentReference (org.xwiki.model.reference.DocumentReference)9 InstalledExtensionRepository (org.xwiki.extension.repository.InstalledExtensionRepository)8 Extension (org.xwiki.extension.Extension)7 InstallRequest (org.xwiki.extension.job.InstallRequest)6 DefaultVersionConstraint (org.xwiki.extension.version.internal.DefaultVersionConstraint)6 WikiDescriptorManager (org.xwiki.wiki.descriptor.WikiDescriptorManager)6 IOException (java.io.IOException)5 DefaultExtensionDependency (org.xwiki.extension.DefaultExtensionDependency)5 SearchResultsPane (org.xwiki.extension.test.po.SearchResultsPane)5 ViewPage (org.xwiki.test.ui.po.ViewPage)5 XWikiContext (com.xpn.xwiki.XWikiContext)4 ResolveException (org.xwiki.extension.ResolveException)4 DependencyPane (org.xwiki.extension.test.po.DependencyPane)4 LogItemPane (org.xwiki.extension.test.po.LogItemPane)4