use of org.xwiki.extension.ResolveException 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.ResolveException in project xwiki-platform by xwiki.
the class FlavorSearchJob method findValidVersion.
private Extension findValidVersion(String flavorId, String namespace) {
IterableResult<Version> versions;
try {
versions = this.repositoryManager.resolveVersions(flavorId, 0, -1);
if (versions.getSize() == 0) {
this.logger.debug("Could not find any version for the flavor extension [{}]", flavorId);
return null;
}
List<Version> versionList = new ArrayList<Version>(versions.getSize());
for (Version version : versions) {
versionList.add(version);
}
return findValidVersion(flavorId, namespace, versionList);
} catch (ResolveException e) {
this.logger.debug("Failed to resolve versions for extension id [{}]", flavorId, e);
}
return null;
}
use of org.xwiki.extension.ResolveException 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);
}
}
}
use of org.xwiki.extension.ResolveException in project xwiki-platform by xwiki.
the class RepositoryManager method isVersionValid.
private boolean isVersionValid(XWikiDocument document, BaseObject extensionVersionObject, XWikiContext context) {
// Has a version
String extensionVersion = getValue(extensionVersionObject, XWikiRepositoryModel.PROP_VERSION_VERSION);
if (StringUtils.isBlank(extensionVersion)) {
this.logger.debug("No actual version provided for object [{}({})]", XWikiRepositoryModel.EXTENSIONVERSION_CLASSREFERENCE, extensionVersionObject.getNumber());
return false;
}
boolean valid;
ResourceReference resourceReference = null;
try {
resourceReference = getDownloadReference(document, extensionVersion);
} catch (ResolveException e) {
logger.debug("Cannot obtain download source reference for object [{}({})]", XWikiRepositoryModel.EXTENSIONVERSION_CLASSREFERENCE, extensionVersionObject.getNumber());
return false;
}
if (resourceReference != null) {
if (ResourceType.ATTACHMENT.equals(resourceReference.getType())) {
AttachmentReference attachmentReference = this.attachmentResolver.resolve(resourceReference.getReference(), document.getDocumentReference());
XWikiDocument attachmentDocument;
try {
attachmentDocument = context.getWiki().getDocument(attachmentReference.getDocumentReference(), context);
valid = attachmentDocument.getAttachment(attachmentReference.getName()) != null;
} catch (XWikiException e) {
this.logger.error("Failed to get document [{}]", attachmentReference.getDocumentReference(), e);
valid = false;
}
if (!valid) {
this.logger.debug("Attachment [{}] does not exists", attachmentReference);
}
} else if (ResourceType.URL.equals(resourceReference.getType()) || ExtensionResourceReference.TYPE.equals(resourceReference.getType())) {
valid = true;
} else {
valid = false;
this.logger.debug("Unknown resource type [{}]", resourceReference.getType());
}
} else {
valid = false;
this.logger.debug("No actual download provided for object [{}({})]", XWikiRepositoryModel.EXTENSIONVERSION_CLASSREFERENCE, extensionVersionObject.getNumber());
}
return valid;
}
use of org.xwiki.extension.ResolveException in project xwiki-platform by xwiki.
the class ExtensionVersionFileRESTResource method downloadRemoteExtension.
private ResponseBuilder downloadRemoteExtension(ExtensionResourceReference extensionResource) throws ResolveException, IOException {
ExtensionRepository repository = null;
if (extensionResource.getRepositoryId() != null) {
repository = this.extensionRepositoryManager.getRepository(extensionResource.getRepositoryId());
}
if (repository == null && extensionResource.getRepositoryType() != null && extensionResource.getRepositoryURI() != null) {
ExtensionRepositoryDescriptor repositoryDescriptor = new DefaultExtensionRepositoryDescriptor("tmp", extensionResource.getRepositoryType(), extensionResource.getRepositoryURI());
try {
ExtensionRepositoryFactory repositoryFactory = this.componentManager.getInstance(ExtensionRepositoryFactory.class, repositoryDescriptor.getType());
repository = repositoryFactory.createRepository(repositoryDescriptor);
} catch (Exception e) {
// Ignore invalid repository
getLogger().warn("Invalid repository in download link [{}]", extensionResource);
}
}
// Resolve extension
Extension downloadExtension;
if (repository == null) {
downloadExtension = this.extensionRepositoryManager.resolve(new ExtensionId(extensionResource.getExtensionId(), extensionResource.getExtensionVersion()));
} else {
downloadExtension = repository.resolve(new ExtensionId(extensionResource.getExtensionId(), extensionResource.getExtensionVersion()));
}
// Get file
// TODO: find media type
ExtensionFile extensionFile = downloadExtension.getFile();
long length = extensionFile.getLength();
// TODO: find a proper way to do a perfect proxy of the URL without directly using Restlet classes.
// Should probably use javax.ws.rs.ext.MessageBodyWriter
InputRepresentation content = new InputRepresentation(extensionFile.openStream(), MediaType.ALL, length);
Disposition disposition = new Disposition(Disposition.TYPE_ATTACHMENT);
disposition.setFilename(downloadExtension.getId().toString() + '.' + downloadExtension.getType());
content.setDisposition(disposition);
ResponseBuilder response = Response.ok();
response.entity(content);
return response;
}
Aggregations