Search in sources :

Example 6 with InstalledExtension

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

the class WikisDefaultUIDistributionStep method prepare.

@Override
public void prepare() {
    if (getState() == null) {
        setState(State.COMPLETED);
        WikiDescriptorManager wikiDescriptorManager = this.wikiDescriptorManagerProvider.get();
        Collection<String> wikiIds;
        try {
            wikiIds = wikiDescriptorManager.getAllIds();
        } catch (WikiManagerException e) {
            this.logger.error("Failed to get the list of wikis", e);
            setState(null);
            return;
        }
        ExtensionId wikiExtensionUI = this.distributionManager.getWikiUIExtensionId();
        if (wikiExtensionUI != null) {
            for (String wikiId : wikiIds) {
                if (!wikiDescriptorManager.getMainWikiId().equals(wikiId)) {
                    String namespace = "wiki:" + wikiId;
                    // Only if the UI is not already installed
                    InstalledExtension installedExtension = this.installedRepository.getInstalledExtension(wikiExtensionUI.getId(), namespace);
                    if (installedExtension == null || !installedExtension.getId().getVersion().equals(wikiExtensionUI.getVersion())) {
                        setState(null);
                        return;
                    }
                }
            }
        }
    }
}
Also used : InstalledExtension(org.xwiki.extension.InstalledExtension) WikiManagerException(org.xwiki.wiki.manager.WikiManagerException) WikiDescriptorManager(org.xwiki.wiki.descriptor.WikiDescriptorManager) ExtensionId(org.xwiki.extension.ExtensionId)

Example 7 with InstalledExtension

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

the class WikisDefaultUIDistributionStep method executeNonInteractive.

@Override
public void executeNonInteractive() throws Exception {
    WikiDescriptorManager wikiDescriptorManager = this.wikiDescriptorManagerProvider.get();
    Collection<String> wikiIds;
    try {
        wikiIds = wikiDescriptorManager.getAllIds();
    } catch (WikiManagerException e) {
        this.logger.error("Failed to get the list of wikis", e);
        setState(null);
        return;
    }
    ExtensionId wikiExtensionUI = this.distributionManager.getWikiUIExtensionId();
    for (String wikiId : wikiIds) {
        if (!wikiDescriptorManager.getMainWikiId().equals(wikiId)) {
            String namespace = new Namespace("wiki", wikiId).toString();
            // Only if the UI is not already installed
            if (wikiExtensionUI != null) {
                InstalledExtension installedExtension = this.installedRepository.getInstalledExtension(wikiExtensionUI.getId(), namespace);
                if (installedExtension == null || !installedExtension.getId().getVersion().equals(wikiExtensionUI.getVersion())) {
                    install(wikiExtensionUI, namespace, false);
                }
            }
        }
    }
    // Complete task
    setState(State.COMPLETED);
}
Also used : InstalledExtension(org.xwiki.extension.InstalledExtension) WikiManagerException(org.xwiki.wiki.manager.WikiManagerException) WikiDescriptorManager(org.xwiki.wiki.descriptor.WikiDescriptorManager) ExtensionId(org.xwiki.extension.ExtensionId) Namespace(org.xwiki.component.namespace.Namespace)

Example 8 with InstalledExtension

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

the class DefaultUIDistributionStep method prepare.

@Override
public void prepare() {
    if (getState() == null) {
        setState(State.COMPLETED);
        Namespace namespace = getNamespace();
        ExtensionId extensionUI = this.distributionJob.getStatus().getDistributionExtensionUI();
        // Only if the UI is not already installed
        if (extensionUI != null) {
            InstalledExtension installedExtension = this.installedRepository.getInstalledExtension(extensionUI.getId(), namespace.toString());
            if (installedExtension == null || !installedExtension.getId().getVersion().equals(extensionUI.getVersion())) {
                setState(null);
            }
        }
    }
}
Also used : InstalledExtension(org.xwiki.extension.InstalledExtension) ExtensionId(org.xwiki.extension.ExtensionId) Namespace(org.xwiki.component.namespace.Namespace)

Example 9 with InstalledExtension

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

the class WikiCopiedEventListenerTest method testCopyOneExtension.

@Test
public void testCopyOneExtension() throws InstallException {
    InstalledExtension extensionDependency1 = this.installedExtensionRepository.installExtension(this.localExtensionDependency1, "wiki:source", false);
    InstalledExtension extension1 = this.installedExtensionRepository.installExtension(this.localExtension1, "wiki:source", false);
    Assert.assertFalse(extension1.isInstalled("wiki:target"));
    Assert.assertFalse(extensionDependency1.isInstalled("wiki:target"));
    this.observation.notify(new WikiCopiedEvent("source", "target"), null, null);
    Assert.assertTrue(extension1.isInstalled("wiki:target"));
    Assert.assertTrue(extensionDependency1.isInstalled("wiki:target"));
}
Also used : InstalledExtension(org.xwiki.extension.InstalledExtension) WikiCopiedEvent(org.xwiki.bridge.event.WikiCopiedEvent) Test(org.junit.Test)

Example 10 with InstalledExtension

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

the class DiffXarJob method diff.

private void diff(String feature, String namespace, Set<LocalDocumentReference> alreadydone) {
    if (this.comparedFeatures.contains(feature)) {
        // We already looked at this feature.
        return;
    }
    this.comparedFeatures.add(feature);
    InstalledExtension installedExtension = this.installedExtensionRepository.getInstalledExtension(feature, namespace);
    if (installedExtension != null) {
        diff(installedExtension, namespace, alreadydone);
        Collection<? extends ExtensionDependency> dependencies = installedExtension.getDependencies();
        this.progressManager.pushLevelProgress(dependencies.size(), this);
        try {
            for (ExtensionDependency dependency : dependencies) {
                this.progressManager.startStep(this);
                diff(dependency.getId(), namespace, new HashSet<>(alreadydone));
            }
        } finally {
            this.progressManager.popLevelProgress(this);
        }
    }
}
Also used : InstalledExtension(org.xwiki.extension.InstalledExtension) ExtensionDependency(org.xwiki.extension.ExtensionDependency)

Aggregations

InstalledExtension (org.xwiki.extension.InstalledExtension)27 ExtensionId (org.xwiki.extension.ExtensionId)12 Test (org.junit.Test)8 InstalledExtensionRepository (org.xwiki.extension.repository.InstalledExtensionRepository)5 Namespace (org.xwiki.component.namespace.Namespace)4 WikiDescriptorManager (org.xwiki.wiki.descriptor.WikiDescriptorManager)4 Collection (java.util.Collection)3 ExtensionDependency (org.xwiki.extension.ExtensionDependency)3 ExtensionInstalledEvent (org.xwiki.extension.event.ExtensionInstalledEvent)3 AbstractExtensionHandlerTest (org.xwiki.extension.test.AbstractExtensionHandlerTest)3 ExtendedURL (org.xwiki.url.ExtendedURL)3 WebJarsResourceReference (org.xwiki.webjars.internal.WebJarsResourceReference)3 JSONObject (net.sf.json.JSONObject)2 ExtensionEvent (org.xwiki.extension.event.ExtensionEvent)2 ExtensionUninstalledEvent (org.xwiki.extension.event.ExtensionUninstalledEvent)2 InstallRequest (org.xwiki.extension.job.InstallRequest)2 WikiManagerException (org.xwiki.wiki.manager.WikiManagerException)2 XWikiException (com.xpn.xwiki.XWikiException)1 IOException (java.io.IOException)1 HashMap (java.util.HashMap)1