use of org.xwiki.extension.InstalledExtension in project xwiki-platform by xwiki.
the class RepairXarJobTest method testRepairOnRoot.
@Test
public void testRepairOnRoot() throws Throwable {
ExtensionId extensionId = new ExtensionId("test", "1.0");
repair(extensionId, null, LogLevel.WARN);
InstalledExtension installedExtension = this.xarExtensionRepository.resolve(extensionId);
assertTrue(installedExtension.isValid(null));
installedExtension = this.xarExtensionRepository.resolve(new ExtensionId("dependency", "1.0"));
assertTrue(installedExtension.isValid(null));
}
use of org.xwiki.extension.InstalledExtension in project xwiki-platform by xwiki.
the class RepairXarJobTest method testRepairOnWiki.
@Test
public void testRepairOnWiki() throws Throwable {
ExtensionId extensionId = new ExtensionId("test", "1.0");
repair(extensionId, new String[] { "wiki:wiki1" }, LogLevel.WARN);
InstalledExtension installedExtension = this.xarExtensionRepository.resolve(extensionId);
assertTrue(installedExtension.isValid(null));
installedExtension = this.xarExtensionRepository.resolve(new ExtensionId("dependency", "1.0"));
assertTrue(installedExtension.isValid(null));
}
use of org.xwiki.extension.InstalledExtension in project xwiki-platform by xwiki.
the class DiffXarJob method runInternal.
@Override
protected void runInternal() throws Exception {
InstallRequest request = getRequest();
// There must be only one namespace specified because we compute the differences for only one wiki.
if (!request.hasNamespaces() || request.getNamespaces().size() != 1) {
return;
}
String namespace = request.getNamespaces().iterator().next();
Collection<ExtensionId> extensionIds = request.getExtensions();
this.progressManager.pushLevelProgress(extensionIds.size(), this);
try {
for (ExtensionId extensionId : extensionIds) {
this.progressManager.startStep(this);
InstalledExtension installedExtension = getInstalledExtension(extensionId, namespace);
// Make sure the specified extension is installed on the specified namespace.
if (installedExtension != null && installedExtension.isInstalled(namespace)) {
diff(extensionId.getId(), namespace, new HashSet<>());
}
this.progressManager.endStep(this);
}
} finally {
this.progressManager.popLevelProgress(this);
}
}
use of org.xwiki.extension.InstalledExtension in project xwiki-platform by xwiki.
the class RepairXarJob method repairExtension.
/**
* @param localExtension the local extension to install
* @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(LocalExtension localExtension, String namespace, boolean dependency, Map<String, ExtensionDependency> managedDependencies) throws InstallException {
this.progressManager.pushLevelProgress(2, this);
this.observationManager.notify(new ExtensionInstallingEvent(localExtension.getId(), namespace), localExtension);
InstalledExtension installedExtension = null;
try {
this.progressManager.startStep(this);
Collection<? extends ExtensionDependency> dependencies = localExtension.getDependencies();
if (!dependencies.isEmpty()) {
this.progressManager.pushLevelProgress(dependencies.size(), dependencies);
try {
for (ExtensionDependency extensionDependency : dependencies) {
this.progressManager.startStep(dependencies);
// Replace with managed dependency if any
ExtensionDependency resolvedDependency = ExtensionUtils.getDependency(extensionDependency, managedDependencies, localExtension);
repairDependency(resolvedDependency, namespace, ExtensionUtils.append(managedDependencies, localExtension));
this.progressManager.endStep(dependencies);
}
} finally {
this.progressManager.popLevelProgress(dependencies);
}
}
this.progressManager.endStep(this);
this.progressManager.startStep(this);
installedExtension = this.installedRepository.installExtension(localExtension, namespace, dependency);
} finally {
if (installedExtension != null) {
this.observationManager.notify(new ExtensionInstalledEvent(installedExtension.getId(), namespace), installedExtension);
} else {
this.observationManager.notify(new ExtensionInstallFailedEvent(localExtension.getId(), namespace), localExtension);
}
this.progressManager.popLevelProgress(this);
}
}
use of org.xwiki.extension.InstalledExtension in project xwiki-platform by xwiki.
the class WikiEventListener method copyInstalledExtension.
private void copyInstalledExtension(InstalledExtension installedExtension, String sourceNamespace, String targetNamespace) {
if (!installedExtension.isInstalled(targetNamespace) && !installedExtension.isInstalled(null)) {
// Copy dependencies first
for (ExtensionDependency dependency : installedExtension.getDependencies()) {
InstalledExtension installedDependency = this.installedRepository.getInstalledExtension(dependency.getId(), sourceNamespace);
if (installedDependency != null) {
copyInstalledExtension(installedDependency, sourceNamespace, targetNamespace);
}
}
// Copy extension
try {
// Installed extension
this.extensionHandlerManager.initialize(installedExtension, targetNamespace);
// Register extension as installed
this.installedRepository.installExtension(installedExtension, targetNamespace, installedExtension.isDependency(sourceNamespace));
} catch (ExtensionException e) {
this.logger.error("Failed to copy extension [{}] from namespace [{}] to namespace [{}]", installedExtension, sourceNamespace, targetNamespace, e);
}
}
}
Aggregations