Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authoravera2011-01-06 03:00:51 +0000
committeravera2011-01-06 03:00:51 +0000
commitb83324d7eff02e4a502cff47941c9d868c8eb81e (patch)
tree6c9f56bdb68460ca6fa28dfc894906f2f096c9ac /plugins/org.eclipse.wst.server.core/servercore/org/eclipse
parent1f4d77b3b840a13a241519a066129d190c12b2b1 (diff)
downloadwebtools.servertools-b83324d7eff02e4a502cff47941c9d868c8eb81e.tar.gz
webtools.servertools-b83324d7eff02e4a502cff47941c9d868c8eb81e.tar.xz
webtools.servertools-b83324d7eff02e4a502cff47941c9d868c8eb81e.zip
[333617] ModuleFactory extension point should contain enablement expression
Diffstat (limited to 'plugins/org.eclipse.wst.server.core/servercore/org/eclipse')
-rw-r--r--plugins/org.eclipse.wst.server.core/servercore/org/eclipse/wst/server/core/ServerUtil.java15
-rw-r--r--plugins/org.eclipse.wst.server.core/servercore/org/eclipse/wst/server/core/internal/ModuleFactory.java55
2 files changed, 62 insertions, 8 deletions
diff --git a/plugins/org.eclipse.wst.server.core/servercore/org/eclipse/wst/server/core/ServerUtil.java b/plugins/org.eclipse.wst.server.core/servercore/org/eclipse/wst/server/core/ServerUtil.java
index 51b30c85e..d01415b52 100644
--- a/plugins/org.eclipse.wst.server.core/servercore/org/eclipse/wst/server/core/ServerUtil.java
+++ b/plugins/org.eclipse.wst.server.core/servercore/org/eclipse/wst/server/core/ServerUtil.java
@@ -1,5 +1,5 @@
/**********************************************************************
- * Copyright (c) 2003, 2010 IBM Corporation and others.
+ * Copyright (c) 2003, 2011 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -91,13 +91,16 @@ public class ServerUtil {
List<IModule> list = new ArrayList<IModule>();
ModuleFactory[] factories = ServerPlugin.getModuleFactories();
+
if (factories != null) {
for (ModuleFactory factory : factories) {
- IModule[] modules = factory.getModules(project, null);
- if (modules != null) {
- for (IModule module : modules) {
- if (!list.contains(module))
- list.add(module);
+ if (factory.isEnabled(project, null)){
+ IModule[] modules = factory.getModules(project, null);
+ if (modules != null) {
+ for (IModule module : modules) {
+ if (!list.contains(module))
+ list.add(module);
+ }
}
}
}
diff --git a/plugins/org.eclipse.wst.server.core/servercore/org/eclipse/wst/server/core/internal/ModuleFactory.java b/plugins/org.eclipse.wst.server.core/servercore/org/eclipse/wst/server/core/internal/ModuleFactory.java
index 0e07791fb..9b9790429 100644
--- a/plugins/org.eclipse.wst.server.core/servercore/org/eclipse/wst/server/core/internal/ModuleFactory.java
+++ b/plugins/org.eclipse.wst.server.core/servercore/org/eclipse/wst/server/core/internal/ModuleFactory.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2003, 2007 IBM Corporation and others.
+ * Copyright (c) 2003, 2011 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -13,10 +13,11 @@ package org.eclipse.wst.server.core.internal;
import java.util.ArrayList;
import java.util.List;
+import org.eclipse.core.expressions.*;
import org.eclipse.core.resources.IProject;
+import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IConfigurationElement;
import org.eclipse.core.runtime.IProgressMonitor;
-
import org.eclipse.wst.server.core.IModule;
import org.eclipse.wst.server.core.IModuleType;
import org.eclipse.wst.server.core.model.InternalInitializer;
@@ -28,6 +29,7 @@ public class ModuleFactory implements IOrdered {
private IConfigurationElement element;
public ModuleFactoryDelegate delegate;
private List<IModuleType> moduleTypes;
+ private Expression fContextualLaunchExpr = null;
/**
* ModuleFactory constructor comment.
@@ -137,6 +139,55 @@ public class ModuleFactory implements IOrdered {
return new IModule[0];
}
}
+
+ /**
+ * Returns an expression that represents the enablement logic for the
+ * contextual project of this module factory <code>null</code> if none.
+ * @return an evaluatable expression or <code>null</code>
+ * @throws CoreException if the configuration element can't be
+ * converted. Reasons include: (a) no handler is available to
+ * cope with a certain configuration element or (b) the XML
+ * expression tree is malformed.
+ */
+ protected Expression getContextualLaunchEnablementExpression() throws CoreException {
+ if (fContextualLaunchExpr == null) {
+ IConfigurationElement[] elements = element.getChildren(ExpressionTagNames.ENABLEMENT);
+ IConfigurationElement enablement = (elements != null && elements.length > 0) ? elements[0] : null;
+
+ if (enablement != null)
+ fContextualLaunchExpr = ExpressionConverter.getDefault().perform(enablement);
+ }
+ return fContextualLaunchExpr;
+ }
+
+ /**
+ * Evaluate the given expression within the given context and return
+ * the result. Returns <code>true</code> if result is either TRUE or NOT_LOADED.
+ * This allows optimistic inclusion before plugins are loaded.
+ * Returns <code>true</code> if exp is <code>null</code>.
+ *
+ * @param exp the enablement expression to evaluate or <code>null</code>
+ * @param context the context of the evaluation.
+ * @return the result of evaluating the expression
+ * @throws CoreException
+ */
+ protected boolean evalEnablementExpression(IEvaluationContext context, Expression exp) throws CoreException {
+ // for compatibility with the current behaviour, if the exp == null we return true. Meaning that the factory doesn't
+ // implement an expression and should be enabled for all cases.
+ return (exp != null) ? ((exp.evaluate(context)) != EvaluationResult.FALSE) : true;
+ }
+
+ public boolean isEnabled(IProject project, IProgressMonitor monitor) {
+ try {
+ IEvaluationContext context = new EvaluationContext(null, project);
+ context.addVariable("project", project);
+
+ return evalEnablementExpression(context, getContextualLaunchEnablementExpression());
+ } catch (Throwable t) {
+ Trace.trace(Trace.SEVERE, "Error calling delegate " + toString(), t);
+ return false;
+ }
+ }
/*
* @see ModuleFactoryDelegate#findModule(String)

Back to the top