Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorashatalin2009-01-13 13:35:37 -0500
committerashatalin2009-01-13 13:35:37 -0500
commitaa44c270a6c36b1992a59518a9173a132b2818fd (patch)
tree7c5406539f6993bdb29fb1feb918a4ad96383b62
parent1223dcd80be5c1b7364bb60d309e409d8eb011b8 (diff)
downloadorg.eclipse.gmf-tooling-aa44c270a6c36b1992a59518a9173a132b2818fd.tar.gz
org.eclipse.gmf-tooling-aa44c270a6c36b1992a59518a9173a132b2818fd.tar.xz
org.eclipse.gmf-tooling-aa44c270a6c36b1992a59518a9173a132b2818fd.zip
Common ResourceSet added for QVT and Xpand meta-model resolutions.v20090113-13-40
-rw-r--r--plugins/org.eclipse.gmf.xpand/src/org/eclipse/gmf/internal/xpand/Activator.java30
-rw-r--r--plugins/org.eclipse.gmf.xpand/src/org/eclipse/gmf/internal/xpand/build/WorkspaceModelRegistry.java12
-rw-r--r--plugins/org.eclipse.gmf.xpand/src/org/eclipse/gmf/internal/xpand/build/WorkspaceResourceManager.java14
-rw-r--r--plugins/org.eclipse.gmf.xpand/src/org/eclipse/gmf/internal/xpand/build/XpandBuilder.java2
-rw-r--r--plugins/org.eclipse.gmf.xpand/src/org/eclipse/gmf/internal/xpand/util/BundleResourceManager.java13
-rw-r--r--plugins/org.eclipse.gmf.xpand/src/org/eclipse/gmf/internal/xpand/util/ResourceManagerImpl.java9
6 files changed, 70 insertions, 10 deletions
diff --git a/plugins/org.eclipse.gmf.xpand/src/org/eclipse/gmf/internal/xpand/Activator.java b/plugins/org.eclipse.gmf.xpand/src/org/eclipse/gmf/internal/xpand/Activator.java
index c20c5d3b9..f2c09a367 100644
--- a/plugins/org.eclipse.gmf.xpand/src/org/eclipse/gmf/internal/xpand/Activator.java
+++ b/plugins/org.eclipse.gmf.xpand/src/org/eclipse/gmf/internal/xpand/Activator.java
@@ -26,6 +26,8 @@ import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Plugin;
import org.eclipse.core.runtime.Status;
import org.eclipse.emf.ecore.EPackage;
+import org.eclipse.emf.ecore.resource.ResourceSet;
+import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl;
import org.eclipse.gmf.internal.xpand.build.MetaModelSource;
import org.osgi.framework.BundleContext;
@@ -156,6 +158,7 @@ public class Activator extends Plugin {
};
private final Set<MetaModelSource> modelSources = new LinkedHashSet<MetaModelSource>();
+ private static ResourceSet workspaceMetamodelRS;
public static void registerModelSource(MetaModelSource modelSource) {
assert modelSource != null;
anInstance.modelSources.add(modelSource);
@@ -174,4 +177,31 @@ public class Activator extends Plugin {
}
return EPackage.Registry.INSTANCE.getEPackage(nsURI);
}
+
+ public static ResourceSet getWorkspaceMetamodelsResourceSet() {
+ if (workspaceMetamodelRS == null) {
+ ResourceSetImpl resourceSetImpl = new ResourceSetImpl();
+// if (resourceSetImpl.getURIResourceMap() == null) {
+// resourceSetImpl.setURIResourceMap(new HashMap<URI, Resource>());
+// }
+// for (Map.Entry<String, URI> entry : EcorePlugin.getEPackageNsURIToGenModelLocationMap().entrySet()) {
+// EPackage ePackage = EPackage.Registry.INSTANCE.getEPackage(entry.getKey());
+// if (ePackage != null && ePackage.eResource() != null) {
+// // TODO: optimize!
+// ResourceSet tmpResourceSet = new ResourceSetImpl();
+// Resource tmpResource = tmpResourceSet.getResource(entry.getValue(), true);
+// if (tmpResource.getContents().size() > 0 && tmpResource.getContents().get(0) instanceof GenModel) {
+// GenModel genModel = (GenModel) tmpResource.getContents().get(0);
+// if (genModel.getGenPackages().size() > 0) {
+// URI ecoreResourceURI = genModel.getGenPackages().get(0).getEcorePackage().eResource().getURI();
+// resourceSetImpl.getURIResourceMap().put(ecoreResourceURI, ePackage.eResource());
+// }
+// }
+// }
+// }
+ workspaceMetamodelRS = resourceSetImpl;
+ }
+ return workspaceMetamodelRS;
+ }
+
}
diff --git a/plugins/org.eclipse.gmf.xpand/src/org/eclipse/gmf/internal/xpand/build/WorkspaceModelRegistry.java b/plugins/org.eclipse.gmf.xpand/src/org/eclipse/gmf/internal/xpand/build/WorkspaceModelRegistry.java
index 82bf50cbd..3e633c5d7 100644
--- a/plugins/org.eclipse.gmf.xpand/src/org/eclipse/gmf/internal/xpand/build/WorkspaceModelRegistry.java
+++ b/plugins/org.eclipse.gmf.xpand/src/org/eclipse/gmf/internal/xpand/build/WorkspaceModelRegistry.java
@@ -32,7 +32,7 @@ class WorkspaceModelRegistry implements MetaModelSource {
this.resource = res;
}
}
-
+
private final Map<String, Descriptor> pathToDescriptor = new TreeMap<String, Descriptor>();
private final Map<String, Descriptor> uriToDescriptor = new TreeMap<String, Descriptor>();
@@ -45,9 +45,13 @@ class WorkspaceModelRegistry implements MetaModelSource {
// System.err.println("<<< " + WorkspaceModelRegistry.class.getSimpleName());
// }
- public WorkspaceModelRegistry() {
+ public WorkspaceModelRegistry(ResourceSet resolutionResourceSet) {
+ resourceSet = resolutionResourceSet;
resourceSet.getURIConverter().getURIMap().putAll(EcorePlugin.computePlatformURIMap());
-
+ }
+
+ public WorkspaceModelRegistry() {
+ this(new ResourceSetImpl());
}
public EPackage find(String nsURI) {
@@ -104,7 +108,7 @@ class WorkspaceModelRegistry implements MetaModelSource {
}
// TODO per-project?
- private final ResourceSet resourceSet = new ResourceSetImpl();
+ private final ResourceSet resourceSet;
private Resource attemptLoad(IFile file) throws IOException {
URI uri = URI.createPlatformResourceURI(file.getFullPath().toString(), false);
diff --git a/plugins/org.eclipse.gmf.xpand/src/org/eclipse/gmf/internal/xpand/build/WorkspaceResourceManager.java b/plugins/org.eclipse.gmf.xpand/src/org/eclipse/gmf/internal/xpand/build/WorkspaceResourceManager.java
index 982881f81..59cf50a64 100644
--- a/plugins/org.eclipse.gmf.xpand/src/org/eclipse/gmf/internal/xpand/build/WorkspaceResourceManager.java
+++ b/plugins/org.eclipse.gmf.xpand/src/org/eclipse/gmf/internal/xpand/build/WorkspaceResourceManager.java
@@ -155,4 +155,18 @@ public class WorkspaceResourceManager extends ResourceManagerImpl {
private static String toFullyQualifiedName(IPath filePath) {
return filePath.removeFileExtension().toString().replace("/", TypeNameUtil.NS_DELIM);
}
+
+ @Override
+ protected String resolveCFileFullPath(String fullyQualifiedName, String fileExtension) {
+ IPath fp = new Path(fullyQualifiedName.replaceAll(TypeNameUtil.NS_DELIM, "/")).addFileExtension(fileExtension);
+ IPath[] resolutions = getResolutions(fp);
+ for (IPath resolvedPath : resolutions) {
+ IFile file = resolvedPath.isAbsolute() ? ResourcesPlugin.getWorkspace().getRoot().getFile(resolvedPath) : contextProject.getFile(resolvedPath);
+ if (file.exists()) {
+ return file.getLocation().toOSString();
+ }
+ }
+ // TODO: use file located in main Path in this case?
+ return fullyQualifiedName + "." + fileExtension;
+ }
} \ No newline at end of file
diff --git a/plugins/org.eclipse.gmf.xpand/src/org/eclipse/gmf/internal/xpand/build/XpandBuilder.java b/plugins/org.eclipse.gmf.xpand/src/org/eclipse/gmf/internal/xpand/build/XpandBuilder.java
index c32d00706..76ef63457 100644
--- a/plugins/org.eclipse.gmf.xpand/src/org/eclipse/gmf/internal/xpand/build/XpandBuilder.java
+++ b/plugins/org.eclipse.gmf.xpand/src/org/eclipse/gmf/internal/xpand/build/XpandBuilder.java
@@ -58,7 +58,7 @@ public class XpandBuilder extends IncrementalProjectBuilder implements RootManag
super.startupOnInitialize();
myRootManager = Activator.getRootManager(getProject());
myRootManager.addRootChangeListener(this);
- modelRegistry = new WorkspaceModelRegistry();
+ modelRegistry = new WorkspaceModelRegistry(Activator.getWorkspaceMetamodelsResourceSet());
Activator.registerModelSource(modelRegistry);
}
diff --git a/plugins/org.eclipse.gmf.xpand/src/org/eclipse/gmf/internal/xpand/util/BundleResourceManager.java b/plugins/org.eclipse.gmf.xpand/src/org/eclipse/gmf/internal/xpand/util/BundleResourceManager.java
index 13b076088..91f5f223a 100644
--- a/plugins/org.eclipse.gmf.xpand/src/org/eclipse/gmf/internal/xpand/util/BundleResourceManager.java
+++ b/plugins/org.eclipse.gmf.xpand/src/org/eclipse/gmf/internal/xpand/util/BundleResourceManager.java
@@ -98,4 +98,17 @@ public class BundleResourceManager extends ResourceManagerImpl {
}
return result.toArray(new Reader[result.size()]);
}
+
+ @Override
+ protected String resolveCFileFullPath(String fullyQualifiedName, String extension) {
+ final String urlPath = fullyQualifiedName.replaceAll(TypeNameUtil.NS_DELIM, "/") + '.' + extension;
+ if (paths.length > 0) {
+ try {
+ return new URL(paths[0], urlPath).toString();
+ } catch (MalformedURLException e) {
+ /* IGNORE */
+ }
+ }
+ return fullyQualifiedName + "." + extension;
+ }
}
diff --git a/plugins/org.eclipse.gmf.xpand/src/org/eclipse/gmf/internal/xpand/util/ResourceManagerImpl.java b/plugins/org.eclipse.gmf.xpand/src/org/eclipse/gmf/internal/xpand/util/ResourceManagerImpl.java
index 72043052c..280e4187a 100644
--- a/plugins/org.eclipse.gmf.xpand/src/org/eclipse/gmf/internal/xpand/util/ResourceManagerImpl.java
+++ b/plugins/org.eclipse.gmf.xpand/src/org/eclipse/gmf/internal/xpand/util/ResourceManagerImpl.java
@@ -25,7 +25,6 @@ import java.util.StringTokenizer;
import java.util.TreeMap;
import org.eclipse.core.filesystem.IFileStore;
-import org.eclipse.emf.ecore.impl.EPackageRegistryImpl;
import org.eclipse.gmf.internal.xpand.Activator;
import org.eclipse.gmf.internal.xpand.ResourceManager;
import org.eclipse.gmf.internal.xpand.model.XpandResource;
@@ -40,8 +39,6 @@ import org.eclipse.m2m.internal.qvt.oml.compiler.QvtCompiler;
import org.eclipse.m2m.internal.qvt.oml.compiler.QvtCompilerOptions;
import org.eclipse.m2m.internal.qvt.oml.evaluator.ImportToNonTransformCtxHelper;
import org.eclipse.m2m.internal.qvt.oml.expressions.Module;
-import org.eclipse.m2m.qvt.oml.blackbox.LoadContext;
-import org.eclipse.m2m.qvt.oml.blackbox.ResolutionContextImpl;
// FIXME it's not a good idea to parse file on every proposal computation
public abstract class ResourceManagerImpl implements ResourceManager {
@@ -215,7 +212,7 @@ public abstract class ResourceManagerImpl implements ResourceManager {
Reader[] readers = resolveMultiple(fullyQualifiedName, QvtResource.FILE_EXTENSION);
// TODO: provide user with more detailed error message in this case?
assert readers.length == 1;
- CFile cFile = new InputStreamCFile(readers[0], fullyQualifiedName);
+ CFile cFile = new InputStreamCFile(readers[0], resolveCFileFullPath(fullyQualifiedName, QvtResource.FILE_EXTENSION));
try {
CompiledModule module = getQvtCompiler().compile(cFile, getQvtCompilerOptions(), null).getModule();
// assert module.getModule() instanceof Library;
@@ -237,6 +234,8 @@ public abstract class ResourceManagerImpl implements ResourceManager {
}
}
+ abstract protected String resolveCFileFullPath(String fullyQualifiedName, String fileExtension);
+
/**
* Using singleton QvtCompiler instance with "history". To prevent same
* (native) libraries from being loaded twice into if (indirectly)
@@ -246,7 +245,7 @@ public abstract class ResourceManagerImpl implements ResourceManager {
if (qvtCompiler == null) {
// TODO: use different kind of ImportResolver being able to
// construct referenced CFiles using ResourceManagerImpl
- qvtCompiler = QvtCompiler.createCompilerWithHistory(new ImportResolverImpl());
+ qvtCompiler = QvtCompiler.createCompilerWithHistory(new ImportResolverImpl(), Activator.getWorkspaceMetamodelsResourceSet());
}
return qvtCompiler;
}

Back to the top