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
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')
-rw-r--r--plugins/org.eclipse.wst.server.core/schema/moduleFactories.exsd37
-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
3 files changed, 80 insertions, 27 deletions
diff --git a/plugins/org.eclipse.wst.server.core/schema/moduleFactories.exsd b/plugins/org.eclipse.wst.server.core/schema/moduleFactories.exsd
index 4ee779e2b..4a7bc6215 100644
--- a/plugins/org.eclipse.wst.server.core/schema/moduleFactories.exsd
+++ b/plugins/org.eclipse.wst.server.core/schema/moduleFactories.exsd
@@ -1,6 +1,6 @@
<?xml version='1.0' encoding='UTF-8'?>
<!-- Schema file written by PDE -->
-<schema targetNamespace="org.eclipse.wst.server.core">
+<schema targetNamespace="org.eclipse.wst.server.core" xmlns="http://www.w3.org/2001/XMLSchema">
<annotation>
<appInfo>
<meta.schema plugin="org.eclipse.wst.server.core" id="moduleFactories" name="Module Factories"/>
@@ -10,7 +10,14 @@
</documentation>
</annotation>
+ <include schemaLocation="schema://org.eclipse.core.expressions/schema/expressionLanguage.exsd"/>
+
<element name="extension">
+ <annotation>
+ <appInfo>
+ <meta.element />
+ </appInfo>
+ </annotation>
<complexType>
<sequence>
<element ref="moduleFactory" minOccurs="1" maxOccurs="unbounded"/>
@@ -105,6 +112,15 @@ Module factory instances of this type will delegate to instances of this class
<annotation>
<appInfo>
+ <meta.section type="apiInfo"/>
+ </appInfo>
+ <documentation>
+ Value of the attribute &lt;b&gt;class&lt;/b&gt; must be a fully qualified name of a Java class that extends &lt;code&gt;org.eclipse.wst.server.core.model.ModuleFactoryDelegate&lt;/code&gt; and contains a public 0-arg constructor.
+ </documentation>
+ </annotation>
+
+ <annotation>
+ <appInfo>
<meta.section type="since"/>
</appInfo>
<documentation>
@@ -135,30 +151,13 @@ Module factory instances of this type will delegate to instances of this class
</documentation>
</annotation>
- <annotation>
- <appInfo>
- <meta.section type="apiInfo"/>
- </appInfo>
- <documentation>
- Value of the attribute &lt;b&gt;class&lt;/b&gt; must be a fully qualified name of a Java class that extends &lt;code&gt;org.eclipse.wst.server.core.model.ModuleFactoryDelegate&lt;/code&gt; and contains a public 0-arg constructor.
- </documentation>
- </annotation>
-
- <annotation>
- <appInfo>
- <meta.section type="implementation"/>
- </appInfo>
- <documentation>
-
- </documentation>
- </annotation>
<annotation>
<appInfo>
<meta.section type="copyright"/>
</appInfo>
<documentation>
- Copyright (c) 2000, 2005 IBM Corporation and others.&lt;br&gt;
+ Copyright (c) 2000, 2011 IBM Corporation and others.&lt;br&gt;
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
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