Search in sources :

Example 21 with InstalledExtension

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

the class RepairXarJobTest method testRepairOnRoot.

@Test
public void testRepairOnRoot() throws Throwable {
    ExtensionId extensionId = new ExtensionId("test", "1.0");
    repair(extensionId, null, LogLevel.WARN);
    InstalledExtension installedExtension = this.xarExtensionRepository.resolve(extensionId);
    assertTrue(installedExtension.isValid(null));
    installedExtension = this.xarExtensionRepository.resolve(new ExtensionId("dependency", "1.0"));
    assertTrue(installedExtension.isValid(null));
}
Also used : InstalledExtension(org.xwiki.extension.InstalledExtension) ExtensionId(org.xwiki.extension.ExtensionId) Test(org.junit.Test) AbstractExtensionHandlerTest(org.xwiki.extension.test.AbstractExtensionHandlerTest)

Example 22 with InstalledExtension

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

the class RepairXarJobTest method testRepairOnWiki.

@Test
public void testRepairOnWiki() throws Throwable {
    ExtensionId extensionId = new ExtensionId("test", "1.0");
    repair(extensionId, new String[] { "wiki:wiki1" }, LogLevel.WARN);
    InstalledExtension installedExtension = this.xarExtensionRepository.resolve(extensionId);
    assertTrue(installedExtension.isValid(null));
    installedExtension = this.xarExtensionRepository.resolve(new ExtensionId("dependency", "1.0"));
    assertTrue(installedExtension.isValid(null));
}
Also used : InstalledExtension(org.xwiki.extension.InstalledExtension) ExtensionId(org.xwiki.extension.ExtensionId) Test(org.junit.Test) AbstractExtensionHandlerTest(org.xwiki.extension.test.AbstractExtensionHandlerTest)

Example 23 with InstalledExtension

use of org.xwiki.extension.InstalledExtension 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 24 with InstalledExtension

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

the class RepairXarJob method repairExtension.

/**
 * @param localExtension the local extension to install
 * @param namespace the namespace where to install extension
 * @param dependency indicate of the extension is installed as a dependency of another
 * @param managedDependencies the managed dependencies
 * @throws InstallException failed to repair extension
 */
private void repairExtension(LocalExtension localExtension, String namespace, boolean dependency, Map<String, ExtensionDependency> managedDependencies) throws InstallException {
    this.progressManager.pushLevelProgress(2, this);
    this.observationManager.notify(new ExtensionInstallingEvent(localExtension.getId(), namespace), localExtension);
    InstalledExtension installedExtension = null;
    try {
        this.progressManager.startStep(this);
        Collection<? extends ExtensionDependency> dependencies = localExtension.getDependencies();
        if (!dependencies.isEmpty()) {
            this.progressManager.pushLevelProgress(dependencies.size(), dependencies);
            try {
                for (ExtensionDependency extensionDependency : dependencies) {
                    this.progressManager.startStep(dependencies);
                    // Replace with managed dependency if any
                    ExtensionDependency resolvedDependency = ExtensionUtils.getDependency(extensionDependency, managedDependencies, localExtension);
                    repairDependency(resolvedDependency, namespace, ExtensionUtils.append(managedDependencies, localExtension));
                    this.progressManager.endStep(dependencies);
                }
            } finally {
                this.progressManager.popLevelProgress(dependencies);
            }
        }
        this.progressManager.endStep(this);
        this.progressManager.startStep(this);
        installedExtension = this.installedRepository.installExtension(localExtension, namespace, dependency);
    } finally {
        if (installedExtension != null) {
            this.observationManager.notify(new ExtensionInstalledEvent(installedExtension.getId(), namespace), installedExtension);
        } else {
            this.observationManager.notify(new ExtensionInstallFailedEvent(localExtension.getId(), namespace), localExtension);
        }
        this.progressManager.popLevelProgress(this);
    }
}
Also used : InstalledExtension(org.xwiki.extension.InstalledExtension) ExtensionInstallingEvent(org.xwiki.extension.event.ExtensionInstallingEvent) ExtensionInstallFailedEvent(org.xwiki.extension.event.ExtensionInstallFailedEvent) ExtensionDependency(org.xwiki.extension.ExtensionDependency) ExtensionInstalledEvent(org.xwiki.extension.event.ExtensionInstalledEvent)

Example 25 with InstalledExtension

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

the class WikiEventListener method copyInstalledExtension.

private void copyInstalledExtension(InstalledExtension installedExtension, String sourceNamespace, String targetNamespace) {
    if (!installedExtension.isInstalled(targetNamespace) && !installedExtension.isInstalled(null)) {
        // Copy dependencies first
        for (ExtensionDependency dependency : installedExtension.getDependencies()) {
            InstalledExtension installedDependency = this.installedRepository.getInstalledExtension(dependency.getId(), sourceNamespace);
            if (installedDependency != null) {
                copyInstalledExtension(installedDependency, sourceNamespace, targetNamespace);
            }
        }
        // Copy extension
        try {
            // Installed extension
            this.extensionHandlerManager.initialize(installedExtension, targetNamespace);
            // Register extension as installed
            this.installedRepository.installExtension(installedExtension, targetNamespace, installedExtension.isDependency(sourceNamespace));
        } catch (ExtensionException e) {
            this.logger.error("Failed to copy extension [{}] from namespace [{}] to namespace [{}]", installedExtension, sourceNamespace, targetNamespace, e);
        }
    }
}
Also used : InstalledExtension(org.xwiki.extension.InstalledExtension) ExtensionException(org.xwiki.extension.ExtensionException) 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