Search in sources :

Example 26 with InstalledExtension

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

the class Package method registerExtension.

private void registerExtension(XWikiContext context) {
    // Register the package as extension if it's one
    if (isInstallExtension() && StringUtils.isNotEmpty(getExtensionId()) && StringUtils.isNotEmpty(getVersion())) {
        ExtensionId extensionId = new ExtensionId(getExtensionId(), getVersion());
        try {
            LocalExtensionRepository localRepository = Utils.getComponent(LocalExtensionRepository.class);
            LocalExtension localExtension = localRepository.getLocalExtension(extensionId);
            if (localExtension == null) {
                Extension extension;
                try {
                    // Try to find and download the extension from a repository
                    extension = Utils.getComponent(ExtensionRepositoryManager.class).resolve(extensionId);
                } catch (ResolveException e) {
                    LOGGER.debug("Can't find extension [{}]", extensionId, e);
                    // FIXME: Create a dummy extension. Need support for partial/lazy extension.
                    return;
                }
                localExtension = localRepository.storeExtension(extension);
            }
            InstalledExtensionRepository installedRepository = Utils.getComponent(InstalledExtensionRepository.class);
            String namespace = "wiki:" + context.getWikiId();
            // Make sure it's not already there
            if (installedRepository.getInstalledExtension(localExtension.getId().getId(), namespace) == null) {
                for (ExtensionId feature : localExtension.getExtensionFeatures()) {
                    if (installedRepository.getInstalledExtension(feature.getId(), namespace) != null) {
                        // Already exist so don't register it or it could create a mess
                        return;
                    }
                }
            } else {
                return;
            }
            // Register the extension as installed
            InstalledExtension installedExtension = installedRepository.installExtension(localExtension, namespace, false);
            // Tell the world about it
            Utils.getComponent(ObservationManager.class).notify(new ExtensionInstalledEvent(installedExtension.getId(), namespace), installedExtension);
        } catch (Exception e) {
            LOGGER.error("Failed to register extenion [{}] from the XAR", extensionId, e);
        }
    }
}
Also used : InstalledExtension(org.xwiki.extension.InstalledExtension) Extension(org.xwiki.extension.Extension) LocalExtension(org.xwiki.extension.LocalExtension) ResolveException(org.xwiki.extension.ResolveException) InstalledExtension(org.xwiki.extension.InstalledExtension) LocalExtensionRepository(org.xwiki.extension.repository.LocalExtensionRepository) LocalExtension(org.xwiki.extension.LocalExtension) ExtensionId(org.xwiki.extension.ExtensionId) ObservationManager(org.xwiki.observation.ObservationManager) InstalledExtensionRepository(org.xwiki.extension.repository.InstalledExtensionRepository) XWikiException(com.xpn.xwiki.XWikiException) QueryException(org.xwiki.query.QueryException) DocumentException(org.dom4j.DocumentException) IOException(java.io.IOException) ResolveException(org.xwiki.extension.ResolveException) ExtensionInstalledEvent(org.xwiki.extension.event.ExtensionInstalledEvent)

Example 27 with InstalledExtension

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

the class JARTranslationBundleFactoryListener method onEvent.

@Override
public void onEvent(Event event, Object source, Object data) {
    ExtensionEvent extensionEvent = (ExtensionEvent) event;
    InstalledExtension extension = (InstalledExtension) source;
    if (extension.getType().equals(EXTENSION_TYPE)) {
        if (event instanceof ExtensionInstalledEvent) {
            extensionAdded(extension, extensionEvent.getNamespace());
        } else if (event instanceof ExtensionUninstalledEvent) {
            extensionDeleted(extension, extensionEvent.getNamespace());
        } else {
            extensionUpgraded(extension, (Collection<InstalledExtension>) data, extensionEvent.getNamespace());
        }
    }
}
Also used : InstalledExtension(org.xwiki.extension.InstalledExtension) ExtensionUninstalledEvent(org.xwiki.extension.event.ExtensionUninstalledEvent) Collection(java.util.Collection) ExtensionEvent(org.xwiki.extension.event.ExtensionEvent) ExtensionInstalledEvent(org.xwiki.extension.event.ExtensionInstalledEvent)

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