Search in sources :

Example 46 with ExtensionId

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

the class DiffXarJob method diff.

private void diff(InstalledExtension installedExtension, String namespace, Set<LocalDocumentReference> alreadydone) {
    Collection<ExtensionId> excludedExtensions = getRequest().getExcludedExtensions();
    if (XarExtensionHandler.TYPE.equals(installedExtension.getType()) && (excludedExtensions == null || !excludedExtensions.contains(installedExtension.getId()))) {
        if (getRequest().isVerbose()) {
            this.logger.info("Computing differences for [{}] on namespace [{}]", installedExtension.getId(), namespace);
        }
        try {
            WikiReference wikiReference = new WikiReference(XarHandlerUtils.getWikiFromNamespace(namespace));
            diff(new XarFile(new File(installedExtension.getFile().getAbsolutePath())), wikiReference, installedExtension.getId(), alreadydone);
        } catch (UnsupportedNamespaceException e) {
            this.logger.error("Failed to extract the wiki id from the namespace [{}].", namespace, e);
        } catch (IOException e) {
            this.logger.error("Failed to read the XAR file of the extension [{}].", installedExtension.getId(), e);
        } catch (XarException e) {
            this.logger.error("Failed to parse the XAR file of the extension [{}].", installedExtension.getId(), e);
        }
    }
}
Also used : UnsupportedNamespaceException(org.xwiki.extension.xar.internal.handler.UnsupportedNamespaceException) XarFile(org.xwiki.xar.XarFile) XarException(org.xwiki.xar.XarException) ExtensionId(org.xwiki.extension.ExtensionId) IOException(java.io.IOException) WikiReference(org.xwiki.model.reference.WikiReference) XarFile(org.xwiki.xar.XarFile) File(java.io.File)

Example 47 with ExtensionId

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

Example 48 with ExtensionId

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

the class XarExtensionScriptService method diff.

/**
 * Computes the differences, in unified format, between the documents of an installed XAR extension and the document
 * from the wiki.
 *
 * @param feature the identifier of a XAR extension (or one of its features)
 * @param wiki the wiki where the XAR extension is installed
 * @return the {@link Job} object which can be used to monitor the progress while the differences are being
 *         computed, or {@code null} in case of failure
 * @since 7.0RC1
 */
public Job diff(String feature, String wiki) {
    setError(null);
    String namespace = getWikiNamespace(wiki);
    InstallRequest installRequest = new InstallRequest();
    installRequest.addExtension(new ExtensionId(feature, (Version) null));
    if (namespace != null) {
        installRequest.addNamespace(namespace);
    }
    installRequest.setId(getDiffJobId(feature, namespace));
    try {
        return this.jobExecutor.execute(DiffXarJob.JOB_TYPE, installRequest);
    } catch (Exception e) {
        setError(e);
        return null;
    }
}
Also used : Version(org.xwiki.extension.version.Version) InstallRequest(org.xwiki.extension.job.InstallRequest) ExtensionId(org.xwiki.extension.ExtensionId) IOException(java.io.IOException) JobException(org.xwiki.job.JobException) XarException(org.xwiki.xar.XarException)

Example 49 with ExtensionId

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

the class XarExtensionScriptService method repairInstalledExtension.

/**
 * Make sure the provided XAR extension properly is registered in the installed extensions index.
 * <p>
 * Start an asynchronous Job.
 *
 * @param id the extension identifier
 * @param version the extension version
 * @param wiki the wiki where the extension is installed
 * @return the {@link Job} object which can be used to monitor the progress of the installation process, or
 *         {@code null} in case of failure
 */
public Job repairInstalledExtension(String id, String version, String wiki) {
    setError(null);
    if (!this.authorization.hasAccess(Right.PROGRAM)) {
        setError(new JobException("Need programming right to repair a XAR"));
        return null;
    }
    String namespace = getWikiNamespace(wiki);
    InstallRequest installRequest = new InstallRequest();
    installRequest.setId(ExtensionRequest.getJobId(ExtensionRequest.JOBID_ACTION_PREFIX, id, namespace));
    DocumentReference currentUserReference = this.documentAccessBridge.getCurrentUserReference();
    if (currentUserReference != null) {
        installRequest.setProperty(PROPERTY_USER_REFERENCE, currentUserReference);
        // 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, currentUserReference.toString());
    }
    installRequest.addExtension(new ExtensionId(id, version));
    if (StringUtils.isNotBlank(namespace)) {
        installRequest.addNamespace(namespace);
    }
    Job job = null;
    try {
        job = this.jobExecutor.execute(RepairXarJob.JOBTYPE, installRequest);
    } catch (Exception e) {
        setError(e);
    }
    return job;
}
Also used : JobException(org.xwiki.job.JobException) InstallRequest(org.xwiki.extension.job.InstallRequest) ExtensionId(org.xwiki.extension.ExtensionId) DiffXarJob(org.xwiki.extension.xar.internal.job.DiffXarJob) Job(org.xwiki.job.Job) RepairXarJob(org.xwiki.extension.xar.internal.job.RepairXarJob) DocumentReference(org.xwiki.model.reference.DocumentReference) IOException(java.io.IOException) JobException(org.xwiki.job.JobException) XarException(org.xwiki.xar.XarException)

Example 50 with ExtensionId

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

the class DocumentsDeletingListenerTest method test.

@Test
public void test() 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");
    DocumentReference doc2 = new DocumentReference("a", "b", "c2");
    DocumentReference doc3 = new DocumentReference("a", "b", "c3");
    concernedEntities.put(doc1, new EntitySelection(doc1));
    concernedEntities.put(doc2, new EntitySelection(doc2));
    concernedEntities.put(doc3, new EntitySelection(doc3));
    XarInstalledExtension ext1 = mock(XarInstalledExtension.class);
    XarInstalledExtension ext2 = mock(XarInstalledExtension.class);
    when(ext1.getId()).thenReturn(new ExtensionId("ext1"));
    when(ext2.getId()).thenReturn(new ExtensionId("ext2"));
    when(repository.getXarInstalledExtensions(doc1)).thenReturn(Arrays.asList(ext1, ext2));
    when(repository.getXarInstalledExtensions(doc2)).thenReturn(Collections.emptyList());
    when(repository.getXarInstalledExtensions(doc3)).thenReturn(Arrays.asList(ext2));
    doAnswer(invocationOnMock -> {
        ExtensionBreakingQuestion question = invocationOnMock.getArgument(0);
        assertEquals(concernedEntities, question.getConcernedEntities());
        // Ext 1
        assertEquals(1, question.getExtension("ext1").getPages().size());
        assertTrue(question.getExtension("ext1").getPages().contains(concernedEntities.get(doc1)));
        // Ext 2
        assertEquals(2, question.getExtension("ext2").getPages().size());
        assertTrue(question.getExtension("ext2").getPages().contains(concernedEntities.get(doc1)));
        assertTrue(question.getExtension("ext2").getPages().contains(concernedEntities.get(doc3)));
        // Free pages
        assertEquals(1, question.getFreePages().size());
        assertTrue(question.getFreePages().contains(concernedEntities.get(doc2)));
        // Assert nothing is select by default
        for (EntitySelection selection : question.getConcernedEntities().values()) {
            assertFalse(selection.isSelected());
        }
        return null;
    }).when(status).ask(any(), anyLong(), any());
    // Test
    DocumentsDeletingEvent event = new DocumentsDeletingEvent();
    mocker.getComponentUnderTest().onEvent(event, job, concernedEntities);
    // Check
    verify(status, times(1)).ask(any(), eq(5L), eq(TimeUnit.MINUTES));
}
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) ExtensionBreakingQuestion(org.xwiki.extension.xar.internal.delete.question.ExtensionBreakingQuestion) 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)

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