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);
}
}
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();
}
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;
}
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);
}
}
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);
}
}
}
Aggregations