summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMoritz Eysholdt2011-04-20 10:05:13 (EDT)
committer Sebastian Zarnekow2011-04-20 10:25:43 (EDT)
commit07190dfc5a0de74876bd881a749dc545108f863d (patch)
treeb07d10ac413a835fa771db2a8468492e4b05632c
parent3fb76c839674cd3702e3250475b1eccc92d372c6 (diff)
downloadorg.eclipse.mwe-07190dfc5a0de74876bd881a749dc545108f863d.zip
org.eclipse.mwe-07190dfc5a0de74876bd881a749dc545108f863d.tar.gz
org.eclipse.mwe-07190dfc5a0de74876bd881a749dc545108f863d.tar.bz2
Implemented support to register EMF GenModels v0.2
Signed-off-by: Sebastian Zarnekow <Sebastian.Zarnekow@itemis.de>
-rw-r--r--plugins/org.eclipse.emf.mwe.utils/META-INF/MANIFEST.MF3
-rw-r--r--plugins/org.eclipse.emf.mwe.utils/src/org/eclipse/emf/mwe/utils/GenModelHelper.java81
-rw-r--r--plugins/org.eclipse.emf.mwe.utils/src/org/eclipse/emf/mwe/utils/StandaloneSetup.java8
-rw-r--r--plugins/org.eclipse.emf.mwe2.lib/META-INF/MANIFEST.MF1
-rw-r--r--plugins/org.eclipse.emf.mwe2.lib/src/org/eclipse/emf/mwe2/ecore/EcoreGenerator.java10
-rw-r--r--tests/org.eclipse.emf.mwe.tests/resources/test/res/referee.genmodel10
-rw-r--r--tests/org.eclipse.emf.mwe.tests/resources/test/res/test.ecore2
-rw-r--r--tests/org.eclipse.emf.mwe.tests/resources/test/res/test.genmodel30
-rw-r--r--tests/org.eclipse.emf.mwe.tests/src/org/eclipse/emf/mwe/tests/util/StandaloneSetupTest.java13
9 files changed, 154 insertions, 4 deletions
diff --git a/plugins/org.eclipse.emf.mwe.utils/META-INF/MANIFEST.MF b/plugins/org.eclipse.emf.mwe.utils/META-INF/MANIFEST.MF
index 846101f..e9279c2 100644
--- a/plugins/org.eclipse.emf.mwe.utils/META-INF/MANIFEST.MF
+++ b/plugins/org.eclipse.emf.mwe.utils/META-INF/MANIFEST.MF
@@ -5,7 +5,8 @@ Bundle-Localization: plugin
Bundle-SymbolicName: org.eclipse.emf.mwe.utils
Bundle-Version: 1.1.0.qualifier
Require-Bundle: org.eclipse.emf.mwe.core,
- org.eclipse.emf.ecore.xmi
+ org.eclipse.emf.ecore.xmi,
+ org.eclipse.emf.codegen.ecore;resolution:=optional
Export-Package: org.eclipse.emf.mwe.utils
Bundle-Vendor: %providerName
Bundle-RequiredExecutionEnvironment: J2SE-1.5
diff --git a/plugins/org.eclipse.emf.mwe.utils/src/org/eclipse/emf/mwe/utils/GenModelHelper.java b/plugins/org.eclipse.emf.mwe.utils/src/org/eclipse/emf/mwe/utils/GenModelHelper.java
new file mode 100644
index 0000000..bf226de
--- /dev/null
+++ b/plugins/org.eclipse.emf.mwe.utils/src/org/eclipse/emf/mwe/utils/GenModelHelper.java
@@ -0,0 +1,81 @@
+package org.eclipse.emf.mwe.utils;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.eclipse.emf.codegen.ecore.genmodel.GenModel;
+import org.eclipse.emf.codegen.ecore.genmodel.GenModelPackage;
+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.EcorePackage;
+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.mwe.core.ConfigurationException;
+
+/**
+ * @author Moritz Eysholdt
+ */
+public class GenModelHelper {
+
+ private Log log = LogFactory.getLog(getClass());
+
+ static {
+ EcorePackage.eINSTANCE.getEFactoryInstance();
+ GenModelPackage.eINSTANCE.getEFactoryInstance();
+ }
+
+ public void registerGenModel(ResourceSet rs, URI genmodelURI) throws ConfigurationException {
+ Resource res = rs.getResource(genmodelURI, true);
+ if (res == null)
+ throw new ConfigurationException("Couldn't find resource under " + genmodelURI);
+ for (EObject object : res.getContents())
+ if (object instanceof GenModel)
+ registerGenModel((GenModel) object);
+ }
+
+ protected Collection<GenPackage> collectGenPackages(GenModel genModel) {
+ List<GenPackage> pkgs = new ArrayList<GenPackage>();
+ for (GenPackage pkg : genModel.getGenPackages()) {
+ pkgs.add(pkg);
+ pkgs.addAll(collectGenPackages(pkg));
+ }
+ pkgs.addAll(genModel.getUsedGenPackages());
+ return pkgs;
+ }
+
+ protected Collection<GenPackage> collectGenPackages(GenPackage genPackage) {
+ List<GenPackage> pkgs = new ArrayList<GenPackage>();
+ for (GenPackage pkg : genPackage.getNestedGenPackages()) {
+ pkgs.add(pkg);
+ pkgs.addAll(collectGenPackages(pkg));
+ }
+ return pkgs;
+ }
+
+ public void registerGenModel(GenModel genModel) {
+ Map<String, URI> registry = EcorePlugin.getEPackageNsURIToGenModelLocationMap();
+ for (GenPackage pkg : collectGenPackages(genModel)) {
+ String nsURI = pkg.getEcorePackage().getNsURI();
+ if (nsURI != null) {
+ URI newUri = pkg.eResource().getURI();
+ if (registry.containsKey(nsURI)) {
+ URI oldURI = registry.get(nsURI);
+ if (!oldURI.equals(newUri))
+ log.warn("There is already a GenModel registered for NamespaceURI '" + nsURI
+ + "'. It will be overwritten from '" + oldURI + "' to '" + newUri + "'");
+ else
+ continue;
+ }
+ registry.put(nsURI, newUri);
+ if (log.isInfoEnabled())
+ log.info("Registered GenModel '" + nsURI + "' from '" + newUri + "'");
+ }
+ }
+ }
+}
diff --git a/plugins/org.eclipse.emf.mwe.utils/src/org/eclipse/emf/mwe/utils/StandaloneSetup.java b/plugins/org.eclipse.emf.mwe.utils/src/org/eclipse/emf/mwe/utils/StandaloneSetup.java
index f94a2d3..fd976b8 100644
--- a/plugins/org.eclipse.emf.mwe.utils/src/org/eclipse/emf/mwe/utils/StandaloneSetup.java
+++ b/plugins/org.eclipse.emf.mwe.utils/src/org/eclipse/emf/mwe/utils/StandaloneSetup.java
@@ -289,6 +289,14 @@ public class StandaloneSetup {
public void setResourceSetImpl(ResourceSetImpl resourceSet) {
setResourceSet(resourceSet);
}
+
+ protected GenModelHelper createGenModelHelper() {
+ return new GenModelHelper();
+ }
+
+ public void addRegisterGenModelFile(String fileName) {
+ createGenModelHelper().registerGenModel(resourceSet, createURI(fileName));
+ }
public void addRegisterEcoreFile(String fileName) throws IllegalArgumentException, SecurityException {
Resource res = resourceSet.getResource(createURI(fileName), true);
diff --git a/plugins/org.eclipse.emf.mwe2.lib/META-INF/MANIFEST.MF b/plugins/org.eclipse.emf.mwe2.lib/META-INF/MANIFEST.MF
index f3c35f9..686ada0 100644
--- a/plugins/org.eclipse.emf.mwe2.lib/META-INF/MANIFEST.MF
+++ b/plugins/org.eclipse.emf.mwe2.lib/META-INF/MANIFEST.MF
@@ -6,6 +6,7 @@ Bundle-Version: 2.0.0.qualifier
Bundle-Vendor: Eclipse Modeling Project
Bundle-RequiredExecutionEnvironment: J2SE-1.5
Require-Bundle: org.eclipse.emf.mwe2.runtime;bundle-version="2.0.0",
+ org.eclipse.emf.mwe.utils;bundle-version="1.1.0",
org.apache.log4j;bundle-version="1.2.15";resolution:=optional,
org.eclipse.emf.codegen.ecore;bundle-version="2.5.0";resolution:=optional;visibility:=reexport,
com.google.collect;bundle-version="1.0.0"
diff --git a/plugins/org.eclipse.emf.mwe2.lib/src/org/eclipse/emf/mwe2/ecore/EcoreGenerator.java b/plugins/org.eclipse.emf.mwe2.lib/src/org/eclipse/emf/mwe2/ecore/EcoreGenerator.java
index da16d56..10b4d01 100644
--- a/plugins/org.eclipse.emf.mwe2.lib/src/org/eclipse/emf/mwe2/ecore/EcoreGenerator.java
+++ b/plugins/org.eclipse.emf.mwe2.lib/src/org/eclipse/emf/mwe2/ecore/EcoreGenerator.java
@@ -1,5 +1,7 @@
package org.eclipse.emf.mwe2.ecore;
+import static com.google.common.collect.Lists.newArrayList;
+
import java.io.IOException;
import java.io.OutputStream;
import java.util.List;
@@ -24,14 +26,13 @@ import org.eclipse.emf.ecore.resource.Resource;
import org.eclipse.emf.ecore.resource.ResourceSet;
import org.eclipse.emf.ecore.resource.URIConverter;
import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl;
+import org.eclipse.emf.mwe.utils.GenModelHelper;
import org.eclipse.emf.mwe2.runtime.Mandatory;
import org.eclipse.emf.mwe2.runtime.workflow.IWorkflowComponent;
import org.eclipse.emf.mwe2.runtime.workflow.IWorkflowContext;
import com.google.common.base.Function;
-import static com.google.common.collect.Lists.newArrayList;
-
public class EcoreGenerator implements IWorkflowComponent {
private static Logger log = Logger.getLogger(EcoreGenerator.class);
@@ -75,6 +76,10 @@ public class EcoreGenerator implements IWorkflowComponent {
public void postInvoke() {
}
+
+ protected GenModelHelper createGenModelSetup() {
+ return new GenModelHelper();
+ }
public void invoke(IWorkflowContext ctx) {
ResourceSet resSet = new ResourceSetImpl();
@@ -82,6 +87,7 @@ public class EcoreGenerator implements IWorkflowComponent {
final GenModel genModel = (GenModel) resource.getContents().get(0);
genModel.setCanGenerate(true);
genModel.reconcile();
+ createGenModelSetup().registerGenModel(genModel);
Generator generator = new Generator() {
@Override
diff --git a/tests/org.eclipse.emf.mwe.tests/resources/test/res/referee.genmodel b/tests/org.eclipse.emf.mwe.tests/resources/test/res/referee.genmodel
new file mode 100644
index 0000000..e902021
--- /dev/null
+++ b/tests/org.eclipse.emf.mwe.tests/resources/test/res/referee.genmodel
@@ -0,0 +1,10 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<genmodel:GenModel xmi:version="2.0"
+ xmlns:xmi="http://www.omg.org/XMI" xmlns:genmodel="http://www.eclipse.org/emf/2002/GenModel" modelDirectory="/org.eclipse.emf.mwe.tests/src"
+ modelPluginID="org.eclipse.emf.mwe.tests" modelName="Referee" importerID="org.eclipse.emf.importer.ecore"
+ complianceLevel="5.0" copyrightFields="false">
+ <foreignModel>referee.ecore</foreignModel>
+ <genPackages prefix="Referee" disposableProviderFactory="true" ecorePackage="referee.ecore#/">
+ <genClasses ecoreClass="referee.ecore#//Stuff"/>
+ </genPackages>
+</genmodel:GenModel>
diff --git a/tests/org.eclipse.emf.mwe.tests/resources/test/res/test.ecore b/tests/org.eclipse.emf.mwe.tests/resources/test/res/test.ecore
index 6842be4..bac5aac 100644
--- a/tests/org.eclipse.emf.mwe.tests/resources/test/res/test.ecore
+++ b/tests/org.eclipse.emf.mwe.tests/resources/test/res/test.ecore
@@ -21,7 +21,7 @@
eOpposite="#//nested/BaseType/children"/>
<eStructuralFeatures xsi:type="ecore:EReference" name="children" upperBound="-1"
eType="#//nested/BaseType" containment="true" eOpposite="#//nested/BaseType/container"/>
- <eStructuralFeatures xsi:type="ecore:EReference" name="stuff" eType="ecore:EClass platform:/plugin/org.eclipse.emf.mwe.tests/resources/test/res/referee.ecore#//Stuff"/>
+ <eStructuralFeatures xsi:type="ecore:EReference" name="stuff" eType="ecore:EClass referee.ecore#//Stuff"/>
</eClassifiers>
</eSubpackages>
</ecore:EPackage>
diff --git a/tests/org.eclipse.emf.mwe.tests/resources/test/res/test.genmodel b/tests/org.eclipse.emf.mwe.tests/resources/test/res/test.genmodel
new file mode 100644
index 0000000..6d01f7c
--- /dev/null
+++ b/tests/org.eclipse.emf.mwe.tests/resources/test/res/test.genmodel
@@ -0,0 +1,30 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<genmodel:GenModel xmi:version="2.0"
+ xmlns:xmi="http://www.omg.org/XMI" xmlns:ecore="http://www.eclipse.org/emf/2002/Ecore"
+ xmlns:genmodel="http://www.eclipse.org/emf/2002/GenModel" modelDirectory="/org.eclipse.emf.mwe.tests/src"
+ modelPluginID="org.eclipse.emf.mwe.tests" modelName="Test" importerID="org.eclipse.emf.importer.ecore"
+ complianceLevel="5.0" copyrightFields="false" usedGenPackages="referee.genmodel#//referee">
+ <foreignModel>test.ecore</foreignModel>
+ <genPackages prefix="Test" disposableProviderFactory="true" ecorePackage="test.ecore#/">
+ <genEnums typeSafeEnumCompatible="false" ecoreEnum="test.ecore#//MyEnum">
+ <genEnumLiterals ecoreEnumLiteral="test.ecore#//MyEnum/ONE"/>
+ <genEnumLiterals ecoreEnumLiteral="test.ecore#//MyEnum/TWO"/>
+ </genEnums>
+ <genClasses ecoreClass="test.ecore#//AClass">
+ <genFeatures createChild="false" ecoreFeature="ecore:EAttribute test.ecore#//AClass/enum"/>
+ <genFeatures createChild="false" ecoreFeature="ecore:EAttribute test.ecore#//AClass/name"/>
+ <genFeatures notify="false" createChild="false" propertySortChoices="true" ecoreFeature="ecore:EReference test.ecore#//AClass/refToGenModel"/>
+ <genFeatures createChild="false" ecoreFeature="ecore:EAttribute test.ecore#//AClass/Action"/>
+ <genFeatures createChild="false" ecoreFeature="ecore:EAttribute test.ecore#//AClass/anOtherAction"/>
+ </genClasses>
+ <nestedGenPackages prefix="Nested" basePackage="test" disposableProviderFactory="true"
+ ecorePackage="test.ecore#//nested">
+ <genClasses ecoreClass="test.ecore#//nested/BaseType">
+ <genFeatures property="None" notify="false" createChild="false" ecoreFeature="ecore:EReference test.ecore#//nested/BaseType/container"/>
+ <genFeatures property="None" children="true" createChild="true" ecoreFeature="ecore:EReference test.ecore#//nested/BaseType/children"/>
+ <genFeatures notify="false" createChild="false" propertySortChoices="true"
+ ecoreFeature="ecore:EReference test.ecore#//nested/BaseType/stuff"/>
+ </genClasses>
+ </nestedGenPackages>
+ </genPackages>
+</genmodel:GenModel>
diff --git a/tests/org.eclipse.emf.mwe.tests/src/org/eclipse/emf/mwe/tests/util/StandaloneSetupTest.java b/tests/org.eclipse.emf.mwe.tests/src/org/eclipse/emf/mwe/tests/util/StandaloneSetupTest.java
index 809603c..77572e7 100644
--- a/tests/org.eclipse.emf.mwe.tests/src/org/eclipse/emf/mwe/tests/util/StandaloneSetupTest.java
+++ b/tests/org.eclipse.emf.mwe.tests/src/org/eclipse/emf/mwe/tests/util/StandaloneSetupTest.java
@@ -14,10 +14,14 @@
*/
package org.eclipse.emf.mwe.tests.util;
+import java.util.Map;
+
import junit.framework.TestCase;
+import org.eclipse.emf.common.util.URI;
import org.eclipse.emf.ecore.EPackage;
import org.eclipse.emf.ecore.EPackage.Registry;
+import org.eclipse.emf.ecore.plugin.EcorePlugin;
import org.eclipse.emf.mwe.utils.StandaloneSetup;
@@ -31,6 +35,15 @@ public class StandaloneSetupTest extends TestCase {
assertTrue(registry.containsKey("http://www.openarchitectureware.org/mm/test/nested"));
}
+ public void testRegisterGenModels() {
+ Map<String, URI> registry = EcorePlugin.getEPackageNsURIToGenModelLocationMap();
+ StandaloneSetup setup = new StandaloneSetup();
+ setup.addRegisterGenModelFile("platform:/plugin/org.eclipse.emf.mwe.tests/resources/test/res/test.genmodel");
+ assertTrue(registry.containsKey("http://www.openarchitectureware.org/mm/test"));
+ assertTrue(registry.containsKey("http://www.openarchitectureware.org/mm/test/nested"));
+ assertTrue(registry.containsKey("http://www.eclipse.org/oaw/test"));
+ }
+
// does not run in OSGi context.
// public void testSearchJars() throws Exception {
// StandaloneSetup setup = new StandaloneSetup();