Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorcbrun2015-03-02 16:30:51 +0000
committerMaxime Porhel2015-03-31 13:09:56 +0000
commit95c14db0004a14ac0b3d8d637fd35ab887433af3 (patch)
tree2353f4fe17707ac5196554d4c24a11288568af58
parent69539959f35957701e6c936541ecef9fff1885b4 (diff)
downloadorg.eclipse.sirius-95c14db0004a14ac0b3d8d637fd35ab887433af3.tar.gz
org.eclipse.sirius-95c14db0004a14ac0b3d8d637fd35ab887433af3.tar.xz
org.eclipse.sirius-95c14db0004a14ac0b3d8d637fd35ab887433af3.zip
[460947] Use JavaExtensionsManager in AQL
Bug: 460947 Change-Id: I5901cd3bca2d27cdcbf2582d515f0f5ef46c9ab8 Signed-off-by: Cedric Brun <cedric.brun@obeo.fr>
-rw-r--r--plugins/org.eclipse.sirius.common.acceleo.aql/src/org/eclipse/sirius/common/acceleo/aql/business/internal/AQLSiriusInterpreter.java128
-rw-r--r--plugins/org.eclipse.sirius.common.acceleo.aql/src/org/eclipse/sirius/common/acceleo/aql/business/internal/AcceleoAbstractInterpreter.java93
2 files changed, 62 insertions, 159 deletions
diff --git a/plugins/org.eclipse.sirius.common.acceleo.aql/src/org/eclipse/sirius/common/acceleo/aql/business/internal/AQLSiriusInterpreter.java b/plugins/org.eclipse.sirius.common.acceleo.aql/src/org/eclipse/sirius/common/acceleo/aql/business/internal/AQLSiriusInterpreter.java
index 7ff9215052..05e3bc78c2 100644
--- a/plugins/org.eclipse.sirius.common.acceleo.aql/src/org/eclipse/sirius/common/acceleo/aql/business/internal/AQLSiriusInterpreter.java
+++ b/plugins/org.eclipse.sirius.common.acceleo.aql/src/org/eclipse/sirius/common/acceleo/aql/business/internal/AQLSiriusInterpreter.java
@@ -20,8 +20,6 @@ import com.google.common.collect.Sets;
import java.util.Collection;
import java.util.Collections;
-import java.util.Iterator;
-import java.util.LinkedHashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
@@ -53,21 +51,19 @@ import org.eclipse.emf.ecore.EPackage;
import org.eclipse.emf.ecore.EPackage.Registry;
import org.eclipse.emf.ecore.EStructuralFeature.Setting;
import org.eclipse.emf.ecore.EcorePackage;
-import org.eclipse.emf.ecore.impl.EStringToStringMapEntryImpl;
import org.eclipse.emf.ecore.util.ECrossReferenceAdapter;
import org.eclipse.sirius.common.acceleo.aql.business.AQLSiriusPlugin;
import org.eclipse.sirius.common.acceleo.aql.business.api.AQLConstants;
import org.eclipse.sirius.common.acceleo.aql.business.api.ExpressionTrimmer;
import org.eclipse.sirius.common.acceleo.aql.business.api.TypesUtil;
+import org.eclipse.sirius.common.tools.api.interpreter.ClassLoadingCallback;
import org.eclipse.sirius.common.tools.api.interpreter.EvaluationException;
-import org.eclipse.sirius.common.tools.api.interpreter.IInterpreter;
import org.eclipse.sirius.common.tools.api.interpreter.IInterpreterContext;
import org.eclipse.sirius.common.tools.api.interpreter.IInterpreterStatus;
import org.eclipse.sirius.common.tools.api.interpreter.InterpreterStatusFactory;
import org.eclipse.sirius.ecore.extender.business.api.accessor.EcoreMetamodelDescriptor;
import org.eclipse.sirius.ecore.extender.business.api.accessor.MetamodelDescriptor;
import org.eclipse.sirius.ecore.extender.business.api.accessor.ModelAccessor;
-import org.osgi.framework.Bundle;
/**
* A Sirius interpreter using the Acceleo Query Language. It only supports
@@ -77,8 +73,6 @@ import org.osgi.framework.Bundle;
*/
public class AQLSiriusInterpreter extends AcceleoAbstractInterpreter {
- private final Collection<String> imports = new LinkedHashSet<String>();
-
private LoadingCache<String, AstResult> parsedExpressions;
private IQueryEnvironment queryEnvironment;
@@ -98,11 +92,39 @@ public class AQLSiriusInterpreter extends AcceleoAbstractInterpreter {
}
};
+ private final ClassLoadingCallback callback = new ClassLoadingCallback() {
+
+ @Override
+ public void loaded(String qualifiedName, Class<?> clazz) {
+ try {
+ queryEnvironment.registerServicePackage(clazz);
+ } catch (InvalidAcceleoPackageException e) {
+ AQLSiriusPlugin.INSTANCE.log(new Status(IStatus.WARNING, AQLSiriusPlugin.INSTANCE.getSymbolicName(), "Error loading Java extension class " + qualifiedName + " :" + e.getMessage(), e));
+ }
+
+ }
+
+ @Override
+ public void notFound(String qualifiedName) {
+ AQLSiriusPlugin.INSTANCE.log(new Status(IStatus.WARNING, AQLSiriusPlugin.INSTANCE.getSymbolicName(), "Could not find Java extension class " + qualifiedName));
+
+ }
+
+ @Override
+ public void unloaded(String qualifiedName, Class<?> clazz) {
+ // TODO implement the un-register once it is available in AQL.
+ // see Bug 461072
+
+ }
+ };
+
/**
* Create a new interpreter supporting the AQL evaluation engine.
*/
public AQLSiriusInterpreter() {
+ super();
this.queryEnvironment = new QueryEnvironment(xRef);
+ this.javaExtensions.addClassLoadingCallBack(callback);
final IQueryBuilderEngine builder = new QueryBuilderEngine(queryEnvironment);
this.parsedExpressions = CacheBuilder.newBuilder().maximumSize(500).build(new CacheLoader<String, AstResult>() {
@@ -113,7 +135,6 @@ public class AQLSiriusInterpreter extends AcceleoAbstractInterpreter {
});
this.queryEnvironment.registerEPackage(EcorePackage.eINSTANCE);
- this.queryEnvironment.registerCustomClassMapping(EcorePackage.eINSTANCE.getEStringToStringMapEntry(), EStringToStringMapEntryImpl.class);
registerEcoreModels(EPackage.Registry.INSTANCE);
}
@@ -135,71 +156,9 @@ public class AQLSiriusInterpreter extends AcceleoAbstractInterpreter {
}
@Override
- public void addImport(String dependency) {
- if (dependency != null && dependency.contains(".") && !imports.contains(dependency)) {
- imports.add(dependency);
- }
- updateServiceClasses();
- }
-
- private void updateServiceClasses() {
- List<Class> classesToLoad = Lists.newArrayList();
- for (String qualifiedName : this.imports) {
- Class found = null;
- Iterator<String> it = viewpointPlugins.iterator();
- while (found == null && it.hasNext()) {
- String bundleID = it.next();
- found = loadClassInBundle(bundleID, qualifiedName);
- }
- if (found != null) {
- classesToLoad.add(found);
-
- }
-
- }
- for (Class found : classesToLoad) {
- try {
- queryEnvironment.registerServicePackage(found);
- } catch (InvalidAcceleoPackageException e) {
- AQLSiriusPlugin.getPlugin().log(new Status(IStatus.WARNING, AQLSiriusPlugin.getPlugin().getSymbolicName(), e.getMessage(), e));
- }
- }
-
- }
-
- private Class loadClassInBundle(String bundleID, String qualifiedName) {
- Bundle requiredBundle = Platform.getBundle(bundleID);
- if (requiredBundle != null) {
- return loadClassInBundle(requiredBundle, qualifiedName);
- }
- return null;
-
- }
-
- private Class loadClassInBundle(Bundle bundle, String qualifiedName) {
- try {
- return bundle.loadClass(qualifiedName);
- } catch (ClassNotFoundException e) {
- /*
- * nothing to report, move along to the next bundle.
- */
- } catch (NoClassDefFoundError e) {
- /*
- * nothing to report, move along to the next bundle.
- */
- }
- return null;
- }
-
- @Override
- public void clearImports() {
- this.imports.clear();
- updateServiceClasses();
- }
-
- @Override
public void dispose() {
super.dispose();
+ this.javaExtensions.removeClassLoadingCallBack(callback);
}
@Override
@@ -292,11 +251,6 @@ public class AQLSiriusInterpreter extends AcceleoAbstractInterpreter {
}
@Override
- public Collection<String> getImports() {
- return Collections.<String> unmodifiableCollection(this.imports);
- }
-
- @Override
public String getVariablePrefix() {
/*
* no variable prefix for this interpreter.
@@ -305,14 +259,6 @@ public class AQLSiriusInterpreter extends AcceleoAbstractInterpreter {
}
@Override
- public void removeImport(String dependency) {
- if (this.imports.contains(dependency)) {
- this.imports.remove(dependency);
- }
- updateServiceClasses();
- }
-
- @Override
public void setCrossReferencer(ECrossReferenceAdapter crossReferencer) {
this.siriusXref = crossReferencer;
}
@@ -320,23 +266,11 @@ public class AQLSiriusInterpreter extends AcceleoAbstractInterpreter {
@Override
public void setModelAccessor(ModelAccessor modelAccessor) {
/*
- * nothing to do
+ * AQL does not support the ModelAccessor yet.
*/
}
@Override
- public void setProperty(Object key, Object value) {
- super.setProperty(key, value);
- if (IInterpreter.FILES.equals(key)) {
- /*
- * this.viewpointPlugins and/or this.viewpointProjects might have
- * been updated. We have to update the loaded classes.
- */
- updateServiceClasses();
- }
- }
-
- @Override
public boolean supportsValidation() {
return true;
}
diff --git a/plugins/org.eclipse.sirius.common.acceleo.aql/src/org/eclipse/sirius/common/acceleo/aql/business/internal/AcceleoAbstractInterpreter.java b/plugins/org.eclipse.sirius.common.acceleo.aql/src/org/eclipse/sirius/common/acceleo/aql/business/internal/AcceleoAbstractInterpreter.java
index c35529f7ce..44d5e8f540 100644
--- a/plugins/org.eclipse.sirius.common.acceleo.aql/src/org/eclipse/sirius/common/acceleo/aql/business/internal/AcceleoAbstractInterpreter.java
+++ b/plugins/org.eclipse.sirius.common.acceleo.aql/src/org/eclipse/sirius/common/acceleo/aql/business/internal/AcceleoAbstractInterpreter.java
@@ -11,26 +11,19 @@
package org.eclipse.sirius.common.acceleo.aql.business.internal;
import com.google.common.collect.ArrayListMultimap;
-import com.google.common.collect.Iterables;
import com.google.common.collect.ListMultimap;
import com.google.common.collect.Maps;
import com.google.common.collect.Sets;
-import java.net.MalformedURLException;
-import java.net.URL;
import java.util.Collection;
import java.util.List;
import java.util.ListIterator;
import java.util.Map;
import java.util.Set;
-import org.eclipse.core.resources.ResourcesPlugin;
-import org.eclipse.core.runtime.FileLocator;
-import org.eclipse.core.runtime.Path;
-import org.eclipse.emf.common.util.URI;
-import org.eclipse.emf.ecore.plugin.EcorePlugin;
import org.eclipse.sirius.common.tools.api.interpreter.IInterpreter;
import org.eclipse.sirius.common.tools.api.interpreter.IVariableStatusListener;
+import org.eclipse.sirius.common.tools.api.interpreter.JavaExtensionsManager;
/**
* An abstract class which handles the variables and classloading status.
@@ -38,18 +31,11 @@ import org.eclipse.sirius.common.tools.api.interpreter.IVariableStatusListener;
* @author cedric
*/
public abstract class AcceleoAbstractInterpreter implements IInterpreter {
-
- /**
- * This will be updated with the list of accessible viewpoint plugins, if
- * any.
- */
- protected final Set<String> viewpointPlugins = Sets.newLinkedHashSet();
-
/**
- * This will be updated with the list of accessible viewpoint projects
- * present in the workspace, if any.
+ * Instance responsible for managing the imports, dependencies and Java
+ * Services.
*/
- protected final Set<String> viewpointProjects = Sets.newLinkedHashSet();
+ protected JavaExtensionsManager javaExtensions;
/**
* This map will hold the values associated to given variable names. Note
@@ -64,35 +50,10 @@ public abstract class AcceleoAbstractInterpreter implements IInterpreter {
private final Set<IVariableStatusListener> variableStatusListeners = Sets.newHashSet();
/**
- * Checks whether the given path exists in the plugins.
- *
- * @param path
- * The path we need to check.
- * @return <code>true</code> if <em>path</em> denotes an existing plugin
- * resource, <code>false</code> otherwise.
- */
- private static boolean existsInPlugins(String path) {
- try {
- URL url = new URL(path);
- return FileLocator.find(url) != null;
- } catch (MalformedURLException e) {
- return false;
- }
- }
-
- /**
- * Checks whether the given path exists in the workspace.
- *
- * @param path
- * The path we need to check.
- * @return <code>true</code> if <em>path</em> denotes an existing workspace
- * resource, <code>false</code> otherwise.
+ * Create a new Interpreter.
*/
- private static boolean existsInWorkspace(String path) {
- if (path == null || path.length() == 0 || EcorePlugin.getWorkspaceRoot() == null) {
- return false;
- }
- return ResourcesPlugin.getWorkspace().getRoot().exists(new Path(path));
+ public AcceleoAbstractInterpreter() {
+ javaExtensions = JavaExtensionsManager.createManagerWithOverride();
}
/**
@@ -142,8 +103,7 @@ public abstract class AcceleoAbstractInterpreter implements IInterpreter {
public void dispose() {
variables.clear();
variableStatusListeners.clear();
- viewpointPlugins.clear();
- viewpointProjects.clear();
+ this.javaExtensions.dispose();
}
@@ -211,20 +171,7 @@ public abstract class AcceleoAbstractInterpreter implements IInterpreter {
* us all the VSM files as a Collection.
*/
if (IInterpreter.FILES.equals(key)) {
- if (value == null) {
- viewpointProjects.clear();
- viewpointPlugins.clear();
- } else if (value instanceof Collection<?>) {
- for (final String odesignPath : Iterables.filter((Collection<?>) value, String.class)) {
- final URI workspaceCandidate = URI.createPlatformResourceURI(odesignPath, true);
- final URI pluginCandidate = URI.createPlatformPluginURI(odesignPath, true);
- if (AcceleoAbstractInterpreter.existsInWorkspace(workspaceCandidate.toPlatformString(true))) {
- viewpointProjects.add(workspaceCandidate.segment(1));
- } else if (AcceleoAbstractInterpreter.existsInPlugins(URI.decode(pluginCandidate.toString()))) {
- viewpointPlugins.add(pluginCandidate.segment(1));
- }
- }
- }
+ javaExtensions.updateScope((Collection<String>) value);
}
}
@@ -257,4 +204,26 @@ public abstract class AcceleoAbstractInterpreter implements IInterpreter {
}
}
+ @Override
+ public void addImport(String dependency) {
+ javaExtensions.addImport(dependency);
+
+ }
+
+ @Override
+ public void removeImport(String dependency) {
+ javaExtensions.removeImport(dependency);
+ }
+
+ @Override
+ public Collection<String> getImports() {
+ return javaExtensions.getImports();
+
+ }
+
+ @Override
+ public void clearImports() {
+ javaExtensions.clearImports();
+ }
+
}

Back to the top