Search in sources :

Example 11 with InstalledExtension

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

the class InstalledExtensionScriptService method getBackwardDependencies.

/**
 * Get all the installed extensions that depend on the specified root extension. The results are grouped by
 * namespace.
 *
 * @param feature the extension id or provided feature (virtual extension) of the extension to resolve
 * @return a map namespace -> list of dependent extensions, or {@code null} if any error occurs while computing
 *         the result, in which case {@link #getLastError()} contains the failure reason
 */
public Map<String, Collection<InstalledExtension>> getBackwardDependencies(String feature) {
    InstalledExtension installedExtension = this.installedExtensionRepository.getInstalledExtension(feature, null);
    Map<String, Collection<InstalledExtension>> extensions;
    if (installedExtension != null) {
        extensions = getBackwardDependencies(installedExtension.getId());
    } else {
        extensions = null;
    }
    return extensions;
}
Also used : InstalledExtension(org.xwiki.extension.InstalledExtension) Collection(java.util.Collection)

Example 12 with InstalledExtension

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

the class InstalledExtensionSynchronizer method onEvent.

@Override
public void onEvent(Event event, Object source, Object data) {
    ExtensionEvent extensionEvent = (ExtensionEvent) event;
    try {
        if (extensionEvent instanceof ExtensionUninstalledEvent) {
            // Update documents index
            getXarRepository().pagesRemoved(extensionEvent.getExtensionId(), extensionEvent.getNamespace());
            // Update extension cache
            getXarRepository().updateCachedXarExtension(extensionEvent.getExtensionId());
        } else {
            if (data != null) {
                for (InstalledExtension installedExtension : (Collection<InstalledExtension>) data) {
                    // Update documents index
                    getXarRepository().pagesRemoved(installedExtension.getId(), extensionEvent.getNamespace());
                    // Update extension cache
                    getXarRepository().updateCachedXarExtension(installedExtension.getId());
                }
            }
            // New extension
            // Update extension cache
            getXarRepository().updateCachedXarExtension(extensionEvent.getExtensionId());
            // Update documents index
            getXarRepository().pagesAdded(extensionEvent.getExtensionId(), extensionEvent.getNamespace());
        }
    } catch (UnsupportedNamespaceException e) {
        logger.error("Failed to extract wiki from namespace [{}]", extensionEvent.getNamespace());
    }
}
Also used : InstalledExtension(org.xwiki.extension.InstalledExtension) UnsupportedNamespaceException(org.xwiki.extension.xar.internal.handler.UnsupportedNamespaceException) ExtensionUninstalledEvent(org.xwiki.extension.event.ExtensionUninstalledEvent) Collection(java.util.Collection) ExtensionEvent(org.xwiki.extension.event.ExtensionEvent)

Example 13 with InstalledExtension

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

the class DefaultFlavorManager method getFlavorOfWiki.

@Override
public ExtensionId getFlavorOfWiki(String wikiId) {
    Namespace namespace = new Namespace("wiki", wikiId);
    InstalledExtension flavor = getFlavorExtension(namespace);
    if (flavor != null) {
        return flavor.getId();
    }
    return null;
}
Also used : InstalledExtension(org.xwiki.extension.InstalledExtension) Namespace(org.xwiki.component.namespace.Namespace)

Example 14 with InstalledExtension

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

the class AbstractImportMojo method installExtension.

protected void installExtension(Artifact artifact, String namespace) throws MojoExecutionException {
    // We need to distinguish between extensions installed explicitly and their transitive dependencies.
    // We have to create our own Set because Maven changes the fields from the dependency Artifacts (e.g. resolves
    // their version) after they are added to the Set of dependencies and this causes the hash code to change. As a
    // result the #contains(Artifact) method doesn't work as expected because it uses the new hash code.
    Set<Artifact> directDependencies = new HashSet<>(this.project.getDependencyArtifacts());
    InstalledExtension installedExtension = this.extensionHelper.registerInstalledExtension(artifact, namespace, !directDependencies.contains(artifact), Collections.<String, Object>singletonMap("user.reference", this.installUser));
    getLog().info("  ... Registered extension [" + installedExtension + "]");
}
Also used : InstalledExtension(org.xwiki.extension.InstalledExtension) Artifact(org.apache.maven.artifact.Artifact) HashSet(java.util.HashSet)

Example 15 with InstalledExtension

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

the class WebJarsScriptServiceTest method computeURLWithoutVersion.

@Test
public void computeURLWithoutVersion() throws Exception {
    WikiDescriptorManager wikiDescriptorManager = this.mocker.getInstance(WikiDescriptorManager.class);
    when(wikiDescriptorManager.getCurrentWikiId()).thenReturn("math");
    InstalledExtensionRepository installedExtensionRepository = this.mocker.getInstance(InstalledExtensionRepository.class);
    InstalledExtension extension = mock(InstalledExtension.class);
    when(installedExtensionRepository.getInstalledExtension("org.webjars:angular", "wiki:math")).thenReturn(extension);
    when(extension.getId()).thenReturn(new ExtensionId("bar", "2.1.11"));
    WebJarsResourceReference resourceReference = new WebJarsResourceReference("wiki:math", Arrays.asList("angular", "2.1.11", "angular.css"));
    when(this.serializer.serialize(resourceReference)).thenReturn(new ExtendedURL(Arrays.asList("xwiki", "angular", "2.1.11", "angular.css")));
    assertEquals("/xwiki/angular/2.1.11/angular.css", this.mocker.getComponentUnderTest().url("angular", "angular.css"));
}
Also used : InstalledExtension(org.xwiki.extension.InstalledExtension) WebJarsResourceReference(org.xwiki.webjars.internal.WebJarsResourceReference) WikiDescriptorManager(org.xwiki.wiki.descriptor.WikiDescriptorManager) ExtensionId(org.xwiki.extension.ExtensionId) ExtendedURL(org.xwiki.url.ExtendedURL) InstalledExtensionRepository(org.xwiki.extension.repository.InstalledExtensionRepository) Test(org.junit.Test)

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