@Override public boolean isValid(String namespace) { return getWrapped().isValid(namespace); }
@Override public boolean isValid(String namespace) { return getWrapped().isValid(namespace); }
/** * Initialize an extension in the given namespace. * * @param installedExtension the extension to initialize * @param namespace the namespace in which the extention is initialized, null for global * @param initializedExtensions the currently initialized extensions set (to avoid initializing twice a dependency) * @throws ExtensionException when an initialization error occurs */ private void initializeExtensionInNamespace(InstalledExtension installedExtension, String namespace, Map<String, Set<InstalledExtension>> initializedExtensions) throws ExtensionException { // Check if the extension can be available from this namespace if (!installedExtension.isValid(namespace)) { return; } Set<InstalledExtension> initializedExtensionsInNamespace = initializedExtensions.get(namespace); if (initializedExtensionsInNamespace == null) { initializedExtensionsInNamespace = new HashSet<>(); initializedExtensions.put(namespace, initializedExtensionsInNamespace); } if (!initializedExtensionsInNamespace.contains(installedExtension)) { initializeExtensionInNamespace(installedExtension, namespace, initializedExtensions, initializedExtensionsInNamespace); } }
@Override public void uninstall(InstalledExtension installedExtension, String namespace, Request request) throws UninstallException { if (installedExtension.isValid(namespace)) { NamespaceURLClassLoader classLoader = this.jarExtensionClassLoader.getURLClassLoader(namespace, false); // There might be no classloading matching the passed namespace when installing a new JAR at the same time // than an upgrade on root if (classLoader != null && StringUtils.equals(namespace, classLoader.getNamespace())) { // unregister components try { unloadComponents(installedExtension.getFile(), classLoader, namespace); } catch (Throwable e) { // We failed to unregister some components, we probably failed to register them in the first // place too so let's just ignore it. Better than making impossible to uninstall the extension. // We catch Throwable because most of the time we end up with a LinkageError this.logger.warn("Failed to unregister some components of the JAR extension [{}]", installedExtension.getId(), e); } // The ClassLoader(s) will be replaced and reloaded at the end of the job // @see org.xwiki.extension.jar.internal.handler.JarExtensionJobFinishedListener } } }
private NavigableSet<Version> getVersions(InstalledExtension extension, String namespace) { NavigableSet<Version> versionList = new TreeSet<>(); // Search local versions try { IterableResult<Version> versions = this.localExtensionRepository.resolveVersions(extension.getId().getId(), 0, -1); for (Version version : versions) { versionList.add(version); } } catch (ResolveException e) { this.logger.debug("Failed to resolve local versions for extension id [{}]", extension.getId().getId(), e); } // Search remote versions try { IterableResult<Version> versions = this.repositoryManager.resolveVersions(extension.getId().getId(), 0, -1); for (Version version : versions) { versionList.add(version); } } catch (ResolveException e) { this.logger.debug("Failed to resolve remote versions for extension id [{}]", extension.getId().getId(), e); } // Make sure the current version is included if the extension is invalid (it's possible this version does // not exist on any repository) if (!extension.isValid(namespace)) { versionList.add(extension.getId().getVersion()); } return versionList; }
private Extension checkInstalledExtension(Extension extension, String namespace) throws InstallException { // Check if the extension conflict with an extension installed on root namespace if (namespace != null) { checkRootExtension(extension); } // Check if the exact same valid extension is already installed on target namespace InstalledExtension installedExtension = this.installedExtensionRepository.getInstalledExtension(extension.getId()); if (installedExtension != null && installedExtension.isInstalled(namespace)) { if (installedExtension.isValid(namespace)) { throw new InstallException(String.format("Extension [%s] is already installed on namespace [%s]", extension.getId(), namespace)); } // In case the extension is already installed on the namespace but is invalid continue with it to make clear // to following code we are actually repairing it return installedExtension; } return extension; }
protected void upgradeExtension(InstalledExtension extension, String namespace, Collection<Version> versionList) { for (Version version : versionList) { // Don't try to upgrade for lower versions but try to repair same version of the extension is invalid int compare = extension.getId().getVersion().compareTo(version); if (compare > 0 || (compare == 0 && extension.isValid(namespace))) { break; } // Only upgrade beta if the current is beta etc. if (extension.getId().getVersion().getType().ordinal() <= version.getType().ordinal()) { if (tryInstallExtension(new ExtensionId(extension.getId().getId(), version), namespace)) { break; } } } }
if (installedExtension.isValid(namespace)) { ExtensionId feature = installedExtension.getExtensionFeature(extensionDependency.getId());