Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--plugins/org.eclipse.gmf.xpand/src/org/eclipse/gmf/internal/xpand/Activator.java51
-rw-r--r--plugins/org.eclipse.gmf.xpand/src/org/eclipse/gmf/internal/xpand/build/WorkspaceModelRegistry.java57
2 files changed, 92 insertions, 16 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 1658275f1..73d0d28f8 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
@@ -24,8 +24,11 @@ import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Plugin;
import org.eclipse.core.runtime.Status;
+import org.eclipse.emf.common.util.URI;
+import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecore.EPackage;
import org.eclipse.emf.ecore.plugin.EcorePlugin;
+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.gmf.internal.xpand.RootManager.RootDescription;
@@ -34,6 +37,7 @@ import org.eclipse.gmf.internal.xpand.build.WorkspaceResourceManager;
import org.osgi.framework.BundleContext;
public class Activator extends Plugin {
+
private static Activator anInstance;
public Activator() {
@@ -56,9 +60,11 @@ public class Activator extends Plugin {
public static String getId() {
return anInstance == null ? String.valueOf(anInstance) : anInstance.getBundle().getSymbolicName();
}
+
public static void logWarn(String message) {
log(new Status(IStatus.WARNING, getId(), 0, message, null));
}
+
public static void logError(Exception e) {
if (e instanceof CoreException) {
log(((CoreException) e).getStatus());
@@ -66,6 +72,7 @@ public class Activator extends Plugin {
log(new Status(IStatus.ERROR, getId(), 0, e.getMessage(), e));
}
}
+
public static void log(IStatus status) {
if (anInstance != null) {
anInstance.getLog().log(status);
@@ -77,7 +84,7 @@ public class Activator extends Plugin {
private final Map<IProject, RootManager> rootManagers = new HashMap<IProject, RootManager>();
public static RootManager getRootManager(IProject project) {
- synchronized(anInstance.myRootsTracker) {
+ synchronized (anInstance.myRootsTracker) {
RootManager result = anInstance.rootManagers.get(project);
if (result == null) {
result = new RootManager(project);
@@ -86,13 +93,14 @@ public class Activator extends Plugin {
return result;
}
}
-
+
public static WorkspaceResourceManager createWorkspaceResourceManager(IProject project, RootDescription rootDescription) {
return rootDescription != null ? new WorkspaceResourceManager(project, rootDescription.getRoots().toArray(new IPath[rootDescription.getRoots().size()]))
: new WorkspaceResourceManager(project);
}
private final IResourceChangeListener myRootsTracker = new IResourceChangeListener() {
+
public synchronized void resourceChanged(IResourceChangeEvent event) {
if (event == null || event.getDelta() == null) {
return;
@@ -145,6 +153,7 @@ public class Activator extends Plugin {
}
return false;
}
+
private boolean mayAffectOtherResourceManagers(IResourceDelta projectDelta) {
if ((projectDelta.getKind() & (IResourceDelta.REMOVED | IResourceDelta.ADDED)) > 0) {
return true;
@@ -176,7 +185,7 @@ public class Activator extends Plugin {
}
return EPackage.Registry.INSTANCE.getEPackage(nsURI);
}
-
+
/**
* {@link EcorePlugin#computePlatformURIMap()} analog for GMF Xpand templates.
* Fills supplied registry with metamodels available in the workspace, accessible both with platform:/resource/ and nsURI.
@@ -230,7 +239,40 @@ public class Activator extends Plugin {
if (anInstance != null && anInstance.workspaceMetamodelRS != null) {
return anInstance.workspaceMetamodelRS;
}
- final ResourceSetImpl resourceSetImpl = new ResourceSetImpl();
+ final ResourceSetImpl resourceSetImpl = new ResourceSetImpl() //
+// {
+//
+// @Override
+// public String toString() {
+// return "Activator.getWorkspaceMetamodelsResourceSet(): " + super.toString();
+// }
+//
+// @Override
+// public Resource getResource(URI uri, boolean loadOnDemand) {
+// int sizeBefore = getResources().size();
+// Resource result = super.getResource(uri, loadOnDemand);
+// if (sizeBefore < getResources().size()) {
+// logWarn("Activator.getWorkspaceMetamodelsResourceSet().: was: " + sizeBefore + //
+// ",\n now: " + getResources().size() + //
+// ",\n requested uri: " + uri + //
+// ",\n loaded: " + result + //
+// ",\n size: " + (result == null ? "null" : result.getContents().size()));
+// if (!result.getContents().isEmpty()) {
+// EObject first = result.getContents().get(0);
+// if (first instanceof EPackage) {
+// EPackage firstEPackage = (EPackage) first;
+// logWarn("loaded: package:" + first + //
+// ",\n nsUri: " + firstEPackage.getNsURI() + //
+// ",\n identityHashCode: " + System.identityHashCode(firstEPackage));
+// } else {
+// logWarn("loaded: NOT a package:" + first);
+// }
+// }
+// }
+// return result;
+// }
+// }
+ ;
resourceSetImpl.setURIResourceMap(new EPackageRegistryBasedURIResourceMap(resourceSetImpl.getURIConverter()));
// TODO: EcorePlugin.computePlatformURIMap() can return different maps
// if some of the project were opened/closed, so it is necessary to
@@ -244,5 +286,4 @@ public class Activator extends Plugin {
}
return resourceSetImpl;
}
-
}
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 7bc1561f8..3c5a95e70 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
@@ -13,6 +13,7 @@ package org.eclipse.gmf.internal.xpand.build;
import java.io.FileNotFoundException;
import java.io.IOException;
+import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
@@ -40,9 +41,27 @@ import org.eclipse.gmf.internal.xpand.Activator;
* @author artem
*/
class WorkspaceModelRegistry implements MetaModelSource {
+
+ /**
+ *
+ * It had been found that having gmfgraph.ecore / gmfgen.ecore from the workspace loaded tp this registry (by platform:resource URIs)
+ * leads to problems with binding QVTO utility calls, because the xPand code (from this class) supplies the EClass'es from workspace resources
+ * while QVTO compiler expects the same-named classes from typed GMFGraphPackageImpl/GmfGenPackageImpl.
+ *
+ * While we are investigating the problem, as a workaround, we will allow to block all metamodles from given workspace
+ * project to be loaded into this registry.
+ *
+ * That is, {@link WorkspaceModelRegistry} in 3.0 release will IGNORE all workspace metamodels from the projects that has the settings file with this name.
+ * @see #380069
+ */
+ private static final String SETTINGS_IGNORE_PROJECT_METAMODELS = ".settings/org.eclipse.gmf.xpand.build.ignore-all-local-metamodels.txt";
+
private static class Descriptor {
+
final String workspacePath;
+
final String nsURI;
+
final Resource resource;
public Descriptor(String workspacePath, String nsURI, Resource res) {
@@ -52,34 +71,39 @@ 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>();
private final IProject project;
+
private boolean isInFullBuild;
+
private boolean doneFullBuild;
-// void DEBUG_DUMP() {
-// System.err.println(">>> " + WorkspaceModelRegistry.class.getSimpleName());
-// for (Map.Entry<String, Descriptor> e : uriToDescriptor.entrySet()) {
-// assert e.getKey().equals(e.getValue().nsURI);
-// System.err.println(e.getKey() + " ==> " + e.getValue().workspacePath);
-// }
-// System.err.println("<<< " + WorkspaceModelRegistry.class.getSimpleName());
-// }
-
+ // void DEBUG_DUMP() {
+ // System.err.println(">>> " + WorkspaceModelRegistry.class.getSimpleName());
+ // for (Map.Entry<String, Descriptor> e : uriToDescriptor.entrySet()) {
+ // assert e.getKey().equals(e.getValue().nsURI);
+ // System.err.println(e.getKey() + " ==> " + e.getValue().workspacePath);
+ // }
+ // System.err.println("<<< " + WorkspaceModelRegistry.class.getSimpleName());
+ // }
+
public WorkspaceModelRegistry(IProject project, ResourceSet resolutionResourceSet) {
assert project != null;
this.project = project;
resourceSet = resolutionResourceSet;
}
-
+
public WorkspaceModelRegistry(IProject project) {
this(project, new ResourceSetImpl());
resourceSet.getURIConverter().getURIMap().putAll(EcorePlugin.computePlatformURIMap());
}
+ private Map<String, EPackage> myReturnedResults = new HashMap<String, EPackage>();
+
public EPackage find(String nsURI) {
Descriptor d = uriToDescriptor.get(nsURI);
return d == null ? null : (EPackage) d.resource.getContents().get(0);
@@ -148,6 +172,9 @@ class WorkspaceModelRegistry implements MetaModelSource {
filesToAdd.add(f);
}
for (IFile f : filesToAdd) {
+ if (shouldIgnoreWorkspaceMetamodel(f)) {
+ continue;
+ }
try {
Resource r = attemptLoad(f);
if (r != null && hasSuitableContent(r)) {
@@ -163,6 +190,14 @@ class WorkspaceModelRegistry implements MetaModelSource {
}
}
+ private boolean shouldIgnoreWorkspaceMetamodel(IFile metamodelFile) {
+ if (metamodelFile == null) {
+ return false;
+ }
+ IFile ignoreProjectMetamodelsSettings = metamodelFile.getProject().getFile(SETTINGS_IGNORE_PROJECT_METAMODELS);
+ return ignoreProjectMetamodelsSettings != null && ignoreProjectMetamodelsSettings.exists();
+ }
+
// TODO per-project?
private final ResourceSet resourceSet;

Back to the top