Commit 3ea98786 authored by Thomas Mortagne's avatar Thomas Mortagne
Browse files

XCOMMONS-2450: Allow indicating to skip already installed extension in an install job

parent 56f826c1
......@@ -37,6 +37,11 @@ public class InstallRequest extends AbstractExtensionRequest
*/
public static final String PROPERTY_EXTENSION_PROPERTIES = "extension.properties";
/**
* @see #isFailOnExist()
*/
public static final String PROPERTY_EXTENSION_FAIL_ON_EXIST = "extension.failOnExist";
/**
* Serialization identifier.
*/
......@@ -57,6 +62,24 @@ public InstallRequest(Request request)
super(request);
}
/**
* @return whether or not the wiki creation should fail if the database already exists
* @since 14.5RC1
*/
public boolean isFailOnExist()
{
return getProperty(PROPERTY_EXTENSION_FAIL_ON_EXIST, true);
}
/**
* @param failOnExist whether or not the wiki creation should fail if the database already exists
* @since 14.5RC1
*/
public void setFailOnExist(boolean failOnExist)
{
setProperty(PROPERTY_EXTENSION_FAIL_ON_EXIST, failOnExist);
}
/**
* @return the custom extension properties to be set on each of the extensions that are going to be installed from
* this request
......
......@@ -48,7 +48,7 @@
import org.xwiki.extension.handler.ExtensionHandler;
import org.xwiki.extension.internal.ExtensionFactory;
import org.xwiki.extension.internal.ExtensionUtils;
import org.xwiki.extension.job.ExtensionRequest;
import org.xwiki.extension.job.InstallRequest;
import org.xwiki.extension.job.plan.ExtensionPlanAction;
import org.xwiki.extension.job.plan.ExtensionPlanAction.Action;
import org.xwiki.extension.job.plan.ExtensionPlanNode;
......@@ -66,7 +66,7 @@
* @version $Id$
* @since 4.1M1
*/
public abstract class AbstractInstallPlanJob<R extends ExtensionRequest> extends AbstractExtensionPlanJob<R>
public abstract class AbstractInstallPlanJob<R extends InstallRequest> extends AbstractExtensionPlanJob<R>
{
protected static class ModifableExtensionPlanNode extends DefaultExtensionPlanNode
{
......@@ -315,8 +315,10 @@ protected void installExtension(ExtensionId extensionId, boolean dependency, Str
ModifableExtensionPlanNode node = installExtension(extensionId, dependency, namespace);
addExtensionNode(node);
parentBranch.add(node);
if (node != null) {
addExtensionNode(node);
parentBranch.add(node);
}
}
private boolean checkCoreDependency(ExtensionDependency extensionDependency,
......@@ -716,10 +718,12 @@ && hasIncompatileRootDependency(extensionDependency)) {
ModifableExtensionPlanNode node =
installExtensionDependency(targetDependency, true, namespace, extensionContext, parents);
node.versionConstraint = versionConstraint;
if (node != null) {
node.versionConstraint = versionConstraint;
addExtensionNode(node);
parentBranch.add(node);
addExtensionNode(node);
parentBranch.add(node);
}
}
/**
......@@ -993,7 +997,9 @@ private ModifableExtensionPlanNode installExtension(Extension sourceExtension, E
// Check if the extension is already installed
Extension installedExtension = checkInstalledExtension(rewrittenExtension, namespace);
if (installedExtension != rewrittenExtension) {
if (installedExtension == null) {
return null;
} else if (installedExtension != rewrittenExtension) {
sourceExtension = installedExtension;
// Rewrite the extension
......@@ -1155,8 +1161,15 @@ private Extension checkInstalledExtension(Extension extension, String namespace)
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));
if (this.getRequest().isFailOnExist()) {
throw new InstallException(String.format("Extension [%s] is already installed on namespace [%s]",
extension.getId(), namespace));
} else {
this.logger.warn("Extension [{}] is already installed on namespace [{}]",
installedExtension.getId(), namespace);
return null;
}
}
// In case the extension is already installed on the namespace but is invalid continue with it to make clear
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment