Search in sources :

Example 6 with Extension

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

the class ExtensionInstanceOutputFilterStream method endExtension.

@Override
public void endExtension(String id, String version, FilterEventParameters parameters) throws FilterException {
    // TODO: add support for complete extension
    ExtensionId extensionId = new ExtensionId(id, factory.getVersion(version));
    try {
        LocalExtension localExtension = this.localRepository.getLocalExtension(extensionId);
        if (localExtension == null) {
            Extension extension;
            try {
                // Try to find and download the extension from a repository
                extension = this.extensionRepository.resolve(extensionId);
            } catch (ResolveException e) {
                this.logger.debug("Can't find extension [{}]", extensionId, e);
                // FIXME: Create a dummy extension. Need support for partial/lazy extension.
                return;
            }
            localExtension = this.localRepository.storeExtension(extension);
        }
        String namespace = getCurrentNamespace();
        // TODO: should probably make it configurable
        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
        installedRepository.installExtension(localExtension, namespace, false);
    } catch (Exception e) {
        this.logger.error("Failed to register extenion [{}] from the XAR", extensionId, e);
    }
}
Also used : Extension(org.xwiki.extension.Extension) LocalExtension(org.xwiki.extension.LocalExtension) ResolveException(org.xwiki.extension.ResolveException) LocalExtension(org.xwiki.extension.LocalExtension) ExtensionId(org.xwiki.extension.ExtensionId) IOException(java.io.IOException) ResolveException(org.xwiki.extension.ResolveException) FilterException(org.xwiki.filter.FilterException)

Example 7 with Extension

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

the class WebJarsScriptService method getVersion.

private String getVersion(String extensionId, String namespace) {
    // Look for WebJars that are core extensions.
    Extension extension = this.coreExtensionRepository.getCoreExtension(extensionId);
    if (extension == null) {
        // Look for WebJars that are installed on the passed namespace (if defined), the current wiki or the main
        // wiki.
        String selectedNamespace = resolveNamespace(namespace);
        extension = this.installedExtensionRepository.getInstalledExtension(extensionId, selectedNamespace);
        if (extension == null) {
            // Fallback by looking in the main wiki
            selectedNamespace = constructNamespace(this.wikiDescriptorManager.getMainWikiId());
            extension = this.installedExtensionRepository.getInstalledExtension(extensionId, selectedNamespace);
            if (extension == null) {
                return null;
            }
        }
    }
    return extension.getId().getVersion().getValue();
}
Also used : Extension(org.xwiki.extension.Extension)

Example 8 with Extension

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

the class ExtensionManagerScriptService method resolve.

/**
 * Get the extension handler corresponding to the given extension ID and version. The returned handler can be used
 * to get more information about the extension, such as the authors, an extension description, its license...
 *
 * @param extensionDependency the extension dependency to resolve
 * @return the read-only handler corresponding to the requested extension, or {@code null} if the extension couldn't
 *         be resolved, in which case {@link #getLastError()} contains the failure reason
 * @since 3.4M1
 * @deprecated since 5.3M1, use {@link #resolve(ExtensionDependency, String)} instead
 */
@Deprecated
public Extension resolve(ExtensionDependency extensionDependency) {
    setError(null);
    Extension extension = null;
    try {
        extension = safe(this.extensionManager.resolveExtension(extensionDependency));
    } catch (Exception e) {
        setError(e);
    }
    return extension;
}
Also used : CoreExtension(org.xwiki.extension.CoreExtension) Extension(org.xwiki.extension.Extension) InstalledExtension(org.xwiki.extension.InstalledExtension) LocalExtension(org.xwiki.extension.LocalExtension) SearchException(org.xwiki.extension.repository.search.SearchException) JobException(org.xwiki.job.JobException)

Example 9 with Extension

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

the class FlavorSearchJob method runInternal.

@Override
protected void runInternal() throws Exception {
    // Get known flavors
    Collection<ExtensionId> knownFlavors = this.flavorManager.getKnownFlavors();
    Collection<String> knownInvalidFlavors = this.flavorManager.getKnownInvalidFlavors();
    // Get remote flavors
    IterableResult<Extension> flavors = this.flavorManager.searchFlavors(new FlavorQuery());
    this.progressManager.pushLevelProgress(knownFlavors.size() + flavors.getSize(), this);
    try {
        // Remember which flavors already been (in)validated
        Set<String> doneFlavors = new HashSet<>();
        // Add the know invalid flavors to the list of already done flavors
        doneFlavors.addAll(knownInvalidFlavors);
        String namespace = getRequest().getNamespaces().iterator().next();
        // Add known flavors
        for (ExtensionId flavorId : knownFlavors) {
            this.progressManager.startStep(this);
            // Validate and add the flavor
            validateKnownFlavor(flavorId, namespace);
            // Remember we took care of this flavor
            doneFlavors.add(flavorId.getId());
            this.progressManager.endStep(this);
        }
        // Add remote flavors
        for (Extension flavor : flavors) {
            this.progressManager.startStep(this);
            // Search only unknown flavors
            if (!doneFlavors.contains(flavor.getId().getId())) {
                Extension validExtension = findValidVersion(flavor.getId().getId(), namespace);
                if (validExtension != null) {
                    this.foundFlavors.add(validExtension);
                }
            }
            this.progressManager.endStep(this);
        }
    } finally {
        this.progressManager.popLevelProgress(this);
    }
}
Also used : Extension(org.xwiki.extension.Extension) ExtensionId(org.xwiki.extension.ExtensionId) FlavorQuery(org.xwiki.platform.flavor.FlavorQuery) HashSet(java.util.HashSet)

Example 10 with Extension

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

Aggregations

Extension (org.xwiki.extension.Extension)12 ExtensionId (org.xwiki.extension.ExtensionId)7 LocalExtension (org.xwiki.extension.LocalExtension)6 InstalledExtension (org.xwiki.extension.InstalledExtension)5 ResolveException (org.xwiki.extension.ResolveException)5 XWikiException (com.xpn.xwiki.XWikiException)3 IOException (java.io.IOException)3 CoreExtension (org.xwiki.extension.CoreExtension)3 SearchException (org.xwiki.extension.repository.search.SearchException)3 JobException (org.xwiki.job.JobException)3 QueryException (org.xwiki.query.QueryException)3 HashSet (java.util.HashSet)2 WebApplicationException (javax.ws.rs.WebApplicationException)2 Version (org.xwiki.extension.version.Version)2 XWikiContext (com.xpn.xwiki.XWikiContext)1 XWikiDocument (com.xpn.xwiki.doc.XWikiDocument)1 BaseObject (com.xpn.xwiki.objects.BaseObject)1 URISyntaxException (java.net.URISyntaxException)1 Map (java.util.Map)1 TreeMap (java.util.TreeMap)1