use of org.xwiki.extension.LocalExtension in project xwiki-platform by xwiki.
the class DocumentsModifiedDuringDistributionListener method checkXARHandler.
private void checkXARHandler(Event event, XWikiDocument document, XWikiContext xcontext) {
ExecutionContext context = this.execution.getContext();
if (context != null) {
XarExtensionPlan xarExtensionPlan = (XarExtensionPlan) context.getProperty(XarExtensionPlan.CONTEXTKEY_XARINSTALLPLAN);
if (xarExtensionPlan != null) {
Request request = this.jobContext.getCurrentJob().getRequest();
// It's a job started by the Distribution Wizard
if (StringUtils.equals(request.<String>getProperty("context.action"), "distribution")) {
String distributionWiki = request.getProperty("context.wiki");
if (distributionWiki != null) {
DocumentReference reference = document.getDocumentReferenceWithLocale();
DocumentStatus.Action action = toAction(event);
LocalExtension previousExtension = xarExtensionPlan.getPreviousXarExtension(reference);
LocalExtension nextExtension = xarExtensionPlan.getNextXarExtension(reference);
addDocument(distributionWiki, document, action, previousExtension, nextExtension);
}
}
}
}
}
use of org.xwiki.extension.LocalExtension in project xwiki-platform by xwiki.
the class RepairXarJob method getLocalXARExtension.
/**
* @param extensionId the extension unique identifier
* @return the stored local extension
* @throws InstallException failed to store extension
*/
private LocalExtension getLocalXARExtension(ExtensionId extensionId) throws InstallException {
LocalExtension localExtension = this.localRepository.getLocalExtension(extensionId);
if (localExtension == null) {
this.progressManager.pushLevelProgress(2, this);
try {
this.progressManager.startStep(this);
Extension extension = this.repositoryManager.resolve(extensionId);
this.progressManager.endStep(this);
this.progressManager.startStep(this);
if (extension.getType().equals(XarExtensionHandler.TYPE)) {
localExtension = this.localExtensionRepository.storeExtension(extension);
}
this.progressManager.endStep(this);
} catch (ResolveException e) {
throw new InstallException("Failed to find extension", e);
} catch (LocalExtensionRepositoryException e) {
throw new InstallException("Failed save extension in local repository", e);
} finally {
this.progressManager.popLevelProgress(this);
}
} else if (!localExtension.getType().equals(XarExtensionHandler.TYPE)) {
localExtension = null;
}
return localExtension;
}
use of org.xwiki.extension.LocalExtension 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.LocalExtension in project xwiki-platform by xwiki.
the class RepairXarJob method repairExtension.
/**
* @param extensionId the unique extension identifier
* @param namespace the namespace where to install extension
* @param dependency indicate of the extension is installed as a dependency of another
* @param managedDependencies the managed dependencies
* @throws InstallException failed to repair extension
*/
private void repairExtension(ExtensionId extensionId, String namespace, boolean dependency, Map<String, ExtensionDependency> managedDependencies) throws InstallException {
if (this.installedRepository.getInstalledExtension(extensionId.getId(), namespace) != null) {
this.logger.debug("Extension [{}] already installed on namespace [{}]", extensionId.getId(), namespace);
return;
}
if (getRequest().isVerbose()) {
if (namespace != null) {
this.logger.info(LOG_REPAIR_NAMESPACE_BEGIN, "Repairing XAR extension [{}] on namespace [{}]", extensionId, namespace);
} else {
this.logger.info(LOG_REPAIR_BEGIN, "Repairing XAR extension [{}] on all namespaces", extensionId, namespace);
}
}
this.progressManager.pushLevelProgress(2, this);
try {
this.progressManager.startStep(this);
LocalExtension localExtension = getLocalXARExtension(extensionId);
this.progressManager.endStep(this);
this.progressManager.startStep(this);
if (localExtension != null) {
repairExtension(localExtension, namespace, dependency, managedDependencies);
}
} finally {
if (getRequest().isVerbose()) {
if (namespace != null) {
this.logger.info(LOG_REPAIR_END_NAMESPACE, "Done repairing XAR extension [{}] on namespace [{}]", extensionId, namespace);
} else {
this.logger.info(LOG_REPAIR_END, "Done repairing XAR extension [{}] on all namespaces", extensionId, namespace);
}
}
this.progressManager.popLevelProgress(this);
}
}
use of org.xwiki.extension.LocalExtension in project xwiki-platform by xwiki.
the class XarExtensionHandler method createPackageConfiguration.
private PackageConfiguration createPackageConfiguration(LocalExtension extension, Request request, String wiki) {
PackageConfiguration configuration;
// Search job configuration in the context
ExecutionContext context = this.execution.getContext();
if (context != null) {
configuration = (PackageConfiguration) context.getProperty(CONTEXTKEY_PACKAGECONFIGURATION);
} else {
configuration = null;
}
// Create a configuration for this extension
if (configuration != null) {
configuration = configuration.clone();
} else {
configuration = new PackageConfiguration();
DocumentReference userReference = getRequestUserReference(AbstractExtensionValidator.PROPERTY_USERREFERENCE, request);
configuration.setInteractive(request.isInteractive());
configuration.setUser(userReference);
configuration.setVerbose(request.isVerbose());
configuration.setSkipMandatorytDocuments(true);
}
configuration.setWiki(wiki);
// Filter entries to import if there is a plan
if (extension != null && configuration.getXarExtensionPlan() != null) {
Map<String, Map<XarEntry, LocalExtension>> nextXAREntries = configuration.getXarExtensionPlan().nextXAREntries;
Set<String> entriesToImport = new HashSet<>();
Map<XarEntry, LocalExtension> nextXAREntriesOnRoot = nextXAREntries.get(null);
if (nextXAREntriesOnRoot != null) {
for (Map.Entry<XarEntry, LocalExtension> entry : nextXAREntriesOnRoot.entrySet()) {
if (entry.getValue() == extension) {
entriesToImport.add(entry.getKey().getEntryName());
}
}
}
Map<XarEntry, LocalExtension> nextXAREntriesOnWiki = nextXAREntries.get(wiki);
if (nextXAREntriesOnWiki != null) {
for (Map.Entry<XarEntry, LocalExtension> entry : nextXAREntriesOnWiki.entrySet()) {
if (entry.getValue() == extension) {
entriesToImport.add(entry.getKey().getEntryName());
}
}
}
configuration.setEntriesToImport(entriesToImport);
}
return configuration;
}
Aggregations