summaryrefslogtreecommitdiffstatsabout
diff options
context:
space:
mode:
authorBalazs Grill2013-02-14 03:29:56 (EST)
committer Istvan Rath2013-02-14 03:29:56 (EST)
commit2e0407d22c82d7f99c3cd2bfcc96ff88dc482c2e (patch)
treecb1379352fc8f1ce6d9abb123454246d53538dbf
parent028a64043c6ce15826fd37973940472872c253c5 (diff)
downloadorg.eclipse.incquery-2e0407d22c82d7f99c3cd2bfcc96ff88dc482c2e.zip
org.eclipse.incquery-2e0407d22c82d7f99c3cd2bfcc96ff88dc482c2e.tar.gz
org.eclipse.incquery-2e0407d22c82d7f99c3cd2bfcc96ff88dc482c2e.tar.bz2
[398720] apply Balazs Grill's patch and append copyright headers
-rw-r--r--plugins/org.eclipse.incquery.tooling.core/src/org/eclipse/incquery/tooling/core/generator/GeneratorModule.java6
-rw-r--r--plugins/org.eclipse.incquery.tooling.core/src/org/eclipse/incquery/tooling/core/generator/genmodel/GenModelMetamodelProviderService.java4
-rw-r--r--plugins/org.eclipse.incquery.tooling.core/src/org/eclipse/incquery/tooling/core/targetplatform/ITargetPlatformMetamodelLoader.java46
-rw-r--r--plugins/org.eclipse.incquery.tooling.core/src/org/eclipse/incquery/tooling/core/targetplatform/TargetPlatformMetamodelProviderService.java88
-rw-r--r--plugins/org.eclipse.incquery.tooling.core/src/org/eclipse/incquery/tooling/core/targetplatform/TargetPlatformMetamodelsIndex.java219
5 files changed, 361 insertions, 2 deletions
diff --git a/plugins/org.eclipse.incquery.tooling.core/src/org/eclipse/incquery/tooling/core/generator/GeneratorModule.java b/plugins/org.eclipse.incquery.tooling.core/src/org/eclipse/incquery/tooling/core/generator/GeneratorModule.java
index c62d169..c8e0734 100644
--- a/plugins/org.eclipse.incquery.tooling.core/src/org/eclipse/incquery/tooling/core/generator/GeneratorModule.java
+++ b/plugins/org.eclipse.incquery.tooling.core/src/org/eclipse/incquery/tooling/core/generator/GeneratorModule.java
@@ -21,6 +21,8 @@ import org.eclipse.incquery.tooling.core.generator.genmodel.GenModelMetamodelPro
import org.eclipse.incquery.tooling.core.generator.genmodel.IEiqGenmodelProvider;
import org.eclipse.incquery.tooling.core.generator.jvmmodel.EMFPatternLanguageJvmModelInferrer;
import org.eclipse.incquery.tooling.core.generator.types.GenModelBasedTypeProvider;
+import org.eclipse.incquery.tooling.core.targetplatform.ITargetPlatformMetamodelLoader;
+import org.eclipse.incquery.tooling.core.targetplatform.TargetPlatformMetamodelsIndex;
import org.eclipse.xtext.common.types.access.IJvmTypeProvider;
import org.eclipse.xtext.common.types.access.jdt.JdtTypeProviderFactory;
import org.eclipse.xtext.xbase.jvmmodel.IJvmModelInferrer;
@@ -61,4 +63,8 @@ public class GeneratorModule extends EMFPatternLanguageRuntimeModule {
public Class<? extends ITypeProvider> bindITypeProvider() {
return GenModelBasedTypeProvider.class;
}
+
+ public Class<? extends ITargetPlatformMetamodelLoader> bindTargetPlatformMetamodelLoader(){
+ return TargetPlatformMetamodelsIndex.class;
+ }
}
diff --git a/plugins/org.eclipse.incquery.tooling.core/src/org/eclipse/incquery/tooling/core/generator/genmodel/GenModelMetamodelProviderService.java b/plugins/org.eclipse.incquery.tooling.core/src/org/eclipse/incquery/tooling/core/generator/genmodel/GenModelMetamodelProviderService.java
index cabad17..6d24065 100644
--- a/plugins/org.eclipse.incquery.tooling.core/src/org/eclipse/incquery/tooling/core/generator/genmodel/GenModelMetamodelProviderService.java
+++ b/plugins/org.eclipse.incquery.tooling.core/src/org/eclipse/incquery/tooling/core/generator/genmodel/GenModelMetamodelProviderService.java
@@ -31,8 +31,8 @@ import org.eclipse.emf.ecore.EPackage;
import org.eclipse.emf.ecore.resource.Resource;
import org.eclipse.emf.ecore.resource.ResourceSet;
import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl;
-import org.eclipse.incquery.patternlanguage.emf.scoping.MetamodelProviderService;
import org.eclipse.incquery.tooling.core.project.IncQueryNature;
+import org.eclipse.incquery.tooling.core.targetplatform.TargetPlatformMetamodelProviderService;
import org.eclipse.incquery.tooling.generator.model.generatorModel.GeneratorModelFactory;
import org.eclipse.incquery.tooling.generator.model.generatorModel.GeneratorModelReference;
import org.eclipse.incquery.tooling.generator.model.generatorModel.IncQueryGeneratorModel;
@@ -55,7 +55,7 @@ import com.google.common.collect.Maps;
import com.google.common.collect.Sets;
import com.google.inject.Inject;
-public class GenModelMetamodelProviderService extends MetamodelProviderService implements IEiqGenmodelProvider {
+public class GenModelMetamodelProviderService extends TargetPlatformMetamodelProviderService implements IEiqGenmodelProvider {
private static final class NameTransformerFunction implements Function<IEObjectDescription, QualifiedName> {
@Override
diff --git a/plugins/org.eclipse.incquery.tooling.core/src/org/eclipse/incquery/tooling/core/targetplatform/ITargetPlatformMetamodelLoader.java b/plugins/org.eclipse.incquery.tooling.core/src/org/eclipse/incquery/tooling/core/targetplatform/ITargetPlatformMetamodelLoader.java
new file mode 100644
index 0000000..f481165
--- /dev/null
+++ b/plugins/org.eclipse.incquery.tooling.core/src/org/eclipse/incquery/tooling/core/targetplatform/ITargetPlatformMetamodelLoader.java
@@ -0,0 +1,46 @@
+/*******************************************************************************
+ * Copyright (c) 2010-2013, Zoltan Ujhelyi, Balazs Grill, Istvan Rath and Daniel Varro
+ * 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
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Zoltan Ujhelyi, Balazs Grill - initial API and implementation
+ *******************************************************************************/
+
+package org.eclipse.incquery.tooling.core.targetplatform;
+
+import org.eclipse.emf.codegen.ecore.genmodel.GenPackage;
+import org.eclipse.emf.ecore.EPackage;
+import org.eclipse.emf.ecore.resource.ResourceSet;
+
+/**
+ * Interface for loading metamodels from the target platform
+ *
+ */
+public interface ITargetPlatformMetamodelLoader {
+
+ /**
+ * List the URIs of the available EPackages
+ * @return an iterable containing the ns URIs of the registered EPackages
+ */
+ public Iterable<String> listEPackages();
+
+ /**
+ * Load the EPackage with the given ns URI
+ * @param nsURI
+ * @param resourceSet
+ * @return The EPackage instance, or null if it could not be loaded
+ */
+ public EPackage loadPackage(ResourceSet resourceSet, String nsURI);
+
+ /**
+ * Load the GenPackage of the EPackage with the given ns URI
+ * @param resourceSet
+ * @param nsURI
+ * @return the registered GenPackage of the generated package
+ */
+ public GenPackage loadGenPackage(ResourceSet resourceSet, String nsURI);
+
+}
diff --git a/plugins/org.eclipse.incquery.tooling.core/src/org/eclipse/incquery/tooling/core/targetplatform/TargetPlatformMetamodelProviderService.java b/plugins/org.eclipse.incquery.tooling.core/src/org/eclipse/incquery/tooling/core/targetplatform/TargetPlatformMetamodelProviderService.java
new file mode 100644
index 0000000..f84e244
--- /dev/null
+++ b/plugins/org.eclipse.incquery.tooling.core/src/org/eclipse/incquery/tooling/core/targetplatform/TargetPlatformMetamodelProviderService.java
@@ -0,0 +1,88 @@
+/*******************************************************************************
+ * Copyright (c) 2010-2013, Zoltan Ujhelyi, Balazs Grill, Istvan Rath and Daniel Varro
+ * 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
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Zoltan Ujhelyi, Balazs Grill - initial API and implementation
+ *******************************************************************************/
+
+package org.eclipse.incquery.tooling.core.targetplatform;
+
+import java.util.Collections;
+
+import org.eclipse.emf.codegen.ecore.genmodel.GenPackage;
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.ecore.EPackage;
+import org.eclipse.emf.ecore.resource.ResourceSet;
+import org.eclipse.incquery.patternlanguage.emf.scoping.MetamodelProviderService;
+import org.eclipse.xtext.naming.IQualifiedNameConverter;
+import org.eclipse.xtext.naming.QualifiedName;
+import org.eclipse.xtext.resource.EObjectDescription;
+import org.eclipse.xtext.resource.IEObjectDescription;
+import org.eclipse.xtext.scoping.IScope;
+import org.eclipse.xtext.scoping.impl.SimpleScope;
+
+import com.google.common.base.Function;
+import com.google.common.base.Predicate;
+import com.google.common.collect.Iterables;
+import com.google.inject.Inject;
+
+/**
+ * Subclass implementation of MetamdelProviderService, which queires registered metamodel packages
+ * from the TargetPlatform instead of the PackageRegistry.
+ *
+ */
+public class TargetPlatformMetamodelProviderService extends
+ MetamodelProviderService {
+
+ @Inject
+ private ITargetPlatformMetamodelLoader metamodelLoader;
+
+ @Inject
+ private IQualifiedNameConverter qualifiedNameConverter;
+
+ /* (non-Javadoc)
+ * @see org.eclipse.incquery.patternlanguage.emf.scoping.MetamodelProviderService#getAllMetamodelObjects(org.eclipse.emf.ecore.EObject)
+ */
+ @Override
+ public IScope getAllMetamodelObjects(EObject context) {
+ final ResourceSet resourceSet = context.eResource().getResourceSet();
+ Iterable<String> tpmetamodels = metamodelLoader.listEPackages();
+ Iterable<IEObjectDescription> metamodels = Iterables.transform(tpmetamodels,
+ new Function<String, IEObjectDescription>() {
+ @Override
+ public IEObjectDescription apply(String from) {
+ EPackage ePackage = metamodelLoader.loadPackage(resourceSet, from);
+
+ QualifiedName qualifiedName = qualifiedNameConverter.toQualifiedName(from);
+
+ return EObjectDescription.create(qualifiedName, ePackage,
+ Collections.singletonMap("nsURI", "true"));
+ }
+ });
+ return new SimpleScope(IScope.NULLSCOPE, Iterables.filter(metamodels,
+ new Predicate<IEObjectDescription>() {
+ public boolean apply(IEObjectDescription desc){
+ return desc.getEObjectOrProxy() != null;
+ }
+ }));
+ }
+
+ protected GenPackage internalFindGenPackage(ResourceSet resourceSet, String packageUri){
+ return metamodelLoader.loadGenPackage(resourceSet, packageUri);
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.incquery.patternlanguage.emf.scoping.MetamodelProviderService#loadEPackage(java.lang.String, org.eclipse.emf.ecore.resource.ResourceSet)
+ */
+ @Override
+ public EPackage loadEPackage(String packageUri, ResourceSet resourceSet) {
+ EPackage pack = metamodelLoader.loadPackage(resourceSet, packageUri);
+ if (pack != null) return pack;
+ return super.loadEPackage(packageUri, resourceSet);
+ }
+
+}
diff --git a/plugins/org.eclipse.incquery.tooling.core/src/org/eclipse/incquery/tooling/core/targetplatform/TargetPlatformMetamodelsIndex.java b/plugins/org.eclipse.incquery.tooling.core/src/org/eclipse/incquery/tooling/core/targetplatform/TargetPlatformMetamodelsIndex.java
new file mode 100644
index 0000000..c58347d
--- /dev/null
+++ b/plugins/org.eclipse.incquery.tooling.core/src/org/eclipse/incquery/tooling/core/targetplatform/TargetPlatformMetamodelsIndex.java
@@ -0,0 +1,219 @@
+/*******************************************************************************
+ * Copyright (c) 2010-2013, Zoltan Ujhelyi, Balazs Grill, Istvan Rath and Daniel Varro
+ * 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
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Zoltan Ujhelyi, Balazs Grill - initial API and implementation
+ *******************************************************************************/
+
+package org.eclipse.incquery.tooling.core.targetplatform;
+
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+import org.eclipse.emf.codegen.ecore.genmodel.GenModel;
+import org.eclipse.emf.codegen.ecore.genmodel.GenPackage;
+import org.eclipse.emf.common.util.URI;
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.ecore.EPackage;
+import org.eclipse.emf.ecore.resource.Resource;
+import org.eclipse.emf.ecore.resource.ResourceSet;
+import org.eclipse.pde.core.plugin.IPluginAttribute;
+import org.eclipse.pde.core.plugin.IPluginBase;
+import org.eclipse.pde.core.plugin.IPluginElement;
+import org.eclipse.pde.core.plugin.IPluginExtension;
+import org.eclipse.pde.core.plugin.IPluginModelBase;
+import org.eclipse.pde.core.plugin.IPluginObject;
+import org.eclipse.pde.core.plugin.PluginRegistry;
+
+import com.google.common.collect.ArrayListMultimap;
+import com.google.common.collect.Multimap;
+
+/**
+ * This class is responsible for querying the active target platform data for registered GenModels
+ * and EPackages.
+ */
+public final class TargetPlatformMetamodelsIndex implements ITargetPlatformMetamodelLoader{
+
+ private static final String EP_GENPACKAGE = "org.eclipse.emf.ecore.generated_package";
+ private static final String PACKAGE = "package";
+ private static final String ATTR_URI = "uri";
+ private static final String ATTR_GENMODEL = "genModel";
+
+ private static final Multimap<String, TargetPlatformMetamodel> entries = ArrayListMultimap.create();
+
+ private void update(){
+ IPluginModelBase[] plugins = PluginRegistry.getActiveModels();
+ Set<String> workspacePlugins = new HashSet<String>();
+ Map<String, IPluginBase> pluginset = new HashMap<String, IPluginBase>();
+ for(IPluginModelBase mbase : plugins){
+ IPluginBase base = mbase.createPluginBase();
+ String ID = mbase.getInstallLocation();
+ pluginset.put(ID, base);
+ if (mbase.getUnderlyingResource() != null){
+ workspacePlugins.add(ID);
+ }
+ }
+
+ /* Remove entries that disappeared */
+ Set<String> remove = new HashSet<String>(entries.keySet());
+ remove.removeAll(pluginset.keySet());
+ for(String id : remove){
+ entries.removeAll(id);
+ }
+ /* Always reload workspace plugins */
+ for(String id : workspacePlugins){
+ entries.removeAll(id);
+ }
+
+ /* Add new entries */
+ Set<String> added = new HashSet<String>(pluginset.keySet());
+ added.removeAll(entries.keySet());
+ for(String id : added){
+ IPluginBase base = pluginset.get(id);
+ entries.putAll(id, load(base));
+ }
+ }
+
+ private List<TargetPlatformMetamodel> load(IPluginBase base){
+ List<TargetPlatformMetamodel> metamodels = new LinkedList<TargetPlatformMetamodelsIndex.TargetPlatformMetamodel>();
+ for(IPluginExtension extension : base.getExtensions()){
+ if (EP_GENPACKAGE.equals(extension.getPoint())){
+ for(IPluginObject po : extension.getChildren()){
+ if (po instanceof IPluginElement){
+ if (PACKAGE.equals(po.getName())){
+ IPluginAttribute uriAttrib = ((IPluginElement) po).getAttribute(ATTR_URI);
+ IPluginAttribute genAttrib = ((IPluginElement) po).getAttribute(ATTR_GENMODEL);
+ if (uriAttrib != null && genAttrib != null){
+ String uri = uriAttrib.getValue();
+ String genModel = genAttrib.getValue();
+ if (!genModel.startsWith("/")) genModel = "/"+genModel;
+ metamodels.add(new TargetPlatformMetamodel(URI.createURI(resolvePluginResource(base.getPluginModel(), genModel)), uri));
+ System.out.println(uri);
+ }
+ }
+ }
+ }
+ }
+ }
+ return metamodels;
+ }
+
+ public static class TargetPlatformMetamodel{
+
+ private final URI genModel;
+ private final String packageURI;
+
+ /**
+ *
+ */
+ private TargetPlatformMetamodel(URI genModel, String packageURI) {
+ this.genModel = genModel;
+ this.packageURI = packageURI;
+ }
+
+ /**
+ * @return the packageURI
+ */
+ public String getPackageURI() {
+ return packageURI;
+ }
+
+ public GenModel loadGenModel(ResourceSet resourceset){
+ try{
+ Resource genModel = resourceset.getResource(this.genModel, true);
+ for(EObject eo : genModel.getContents()){
+ if (eo instanceof GenModel){
+ return (GenModel)eo;
+ }
+ }
+ return null;
+ }catch(Exception e){
+ //Exception
+ return null;
+ }
+ }
+
+ public GenPackage loadGenPackage(ResourceSet resourceset){
+ GenModel genModel = loadGenModel(resourceset);
+ try{
+ for(GenPackage genpack : genModel.getAllGenPackagesWithClassifiers()){
+ EPackage epack = genpack.getEcorePackage();
+ if (this.packageURI.equals(epack.getNsURI())){
+ return genpack;
+ }
+ }
+ }catch(NullPointerException e){
+ // genModel.getAllGenPackagesWithClassifiers() can throw NullPointerException
+ }
+ return null;
+ }
+
+ public EPackage loadPackage(ResourceSet resourceset){
+ GenPackage genPack = loadGenPackage(resourceset);
+ if (genPack != null) return genPack.getEcorePackage();
+ return null;
+ }
+
+ }
+
+ private static String resolvePluginResource(IPluginModelBase modelbase, String path){
+ String location = modelbase.getInstallLocation();
+ if (location.endsWith(".jar")) {
+ return "jar:file:" + location + "!" + path;
+ } else {
+ return "file:" + modelbase.getInstallLocation() + path;
+ }
+ }
+
+ private Iterable<TargetPlatformMetamodel> load(){
+ update();
+ return entries.values();
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.incquery.tooling.core.targetPlatform.ITargetPlatformMetamodelLoader#listEPackages()
+ */
+ @Override
+ public Iterable<String> listEPackages() {
+ List<String> packageURIs = new LinkedList<String>();
+ for(TargetPlatformMetamodel entry: load()){
+ packageURIs.add(entry.getPackageURI());
+ }
+ return packageURIs;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.incquery.tooling.core.targetPlatform.ITargetPlatformMetamodelLoader#loadPackage(org.eclipse.emf.ecore.resource.ResourceSet, java.lang.String)
+ */
+ @Override
+ public EPackage loadPackage(ResourceSet resourceSet, String nsURI) {
+ for(TargetPlatformMetamodel mm : load()){
+ if (nsURI.equals(mm.packageURI)){
+ return mm.loadPackage(resourceSet);
+ }
+ }
+ return null;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.incquery.tooling.core.targetPlatform.ITargetPlatformMetamodelLoader#loadGenPackage(org.eclipse.emf.ecore.resource.ResourceSet, java.lang.String)
+ */
+ @Override
+ public GenPackage loadGenPackage(ResourceSet resourceSet, String nsURI) {
+ for(TargetPlatformMetamodel mm : load()){
+ if (nsURI.equals(mm.packageURI)){
+ return mm.loadGenPackage(resourceSet);
+ }
+ }
+ return null;
+ }
+
+}