Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authordkolovos2013-02-03 05:50:17 -0500
committerdkolovos2013-02-03 05:50:17 -0500
commit3c31caebf46ae68be1ba0f692d7f24f2fb341a28 (patch)
treea0cdf1cd3dfaf5674a73ada697a4708c310e7323
parent030fd0e51180ec55da026bebd19f740f55506e18 (diff)
downloadorg.eclipse.emfatic-3c31caebf46ae68be1ba0f692d7f24f2fb341a28.tar.gz
org.eclipse.emfatic-3c31caebf46ae68be1ba0f692d7f24f2fb341a28.tar.xz
org.eclipse.emfatic-3c31caebf46ae68be1ba0f692d7f24f2fb341a28.zip
Added a version of EcoreGenerator.generate() that works with a File
instead of an IFile. In-Eclipse behaviour should remain unaffected.
-rw-r--r--doc/org.eclipse.emf.emfatic.doc.user/.classpath1
-rw-r--r--plugins/org.eclipse.emf.emfatic.core/META-INF/MANIFEST.MF3
-rw-r--r--plugins/org.eclipse.emf.emfatic.core/src/org/eclipse/emf/emfatic/core/generator/ecore/Builder.java4
-rw-r--r--plugins/org.eclipse.emf.emfatic.core/src/org/eclipse/emf/emfatic/core/generator/ecore/EcoreGenerator.java42
-rw-r--r--plugins/org.eclipse.emf.emfatic.core/src/org/eclipse/emf/emfatic/core/lang/gen/parser/EmfaticParserDriver.java5
-rw-r--r--updatesites/org.eclipse.emf.emfatic.updatesite/site.xml2
6 files changed, 50 insertions, 7 deletions
diff --git a/doc/org.eclipse.emf.emfatic.doc.user/.classpath b/doc/org.eclipse.emf.emfatic.doc.user/.classpath
index 3f74547..0215967 100644
--- a/doc/org.eclipse.emf.emfatic.doc.user/.classpath
+++ b/doc/org.eclipse.emf.emfatic.doc.user/.classpath
@@ -1,5 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
+ <classpathentry kind="src" path="src"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
<classpathentry kind="output" path="bin"/>
diff --git a/plugins/org.eclipse.emf.emfatic.core/META-INF/MANIFEST.MF b/plugins/org.eclipse.emf.emfatic.core/META-INF/MANIFEST.MF
index 472cfa5..efae3e3 100644
--- a/plugins/org.eclipse.emf.emfatic.core/META-INF/MANIFEST.MF
+++ b/plugins/org.eclipse.emf.emfatic.core/META-INF/MANIFEST.MF
@@ -21,6 +21,7 @@ Require-Bundle: org.eclipse.ui,
org.eclipse.emf.ecore,
org.eclipse.emf.ecore.edit,
org.eclipse.emf.edit.ui,
- org.eclipse.gymnast.runtime.core
+ org.eclipse.gymnast.runtime.core,
+ org.eclipse.emf.ecore.xmi
Bundle-ActivationPolicy: lazy
Bundle-RequiredExecutionEnvironment: J2SE-1.5
diff --git a/plugins/org.eclipse.emf.emfatic.core/src/org/eclipse/emf/emfatic/core/generator/ecore/Builder.java b/plugins/org.eclipse.emf.emfatic.core/src/org/eclipse/emf/emfatic/core/generator/ecore/Builder.java
index 07dab44..8786f10 100644
--- a/plugins/org.eclipse.emf.emfatic.core/src/org/eclipse/emf/emfatic/core/generator/ecore/Builder.java
+++ b/plugins/org.eclipse.emf.emfatic.core/src/org/eclipse/emf/emfatic/core/generator/ecore/Builder.java
@@ -78,7 +78,9 @@ public class Builder extends GenerationPhase {
initParseContext(parseContext);
_annotationMap = new EmfaticAnnotationMap();
CompUnit compUnit = (CompUnit) parseContext.getParseRoot();
- buildPackage(compUnit, resource);
+ if (compUnit != null) {
+ buildPackage(compUnit, resource);
+ }
}
private void buildPackage(CompUnit compUnit, Resource resource) {
diff --git a/plugins/org.eclipse.emf.emfatic.core/src/org/eclipse/emf/emfatic/core/generator/ecore/EcoreGenerator.java b/plugins/org.eclipse.emf.emfatic.core/src/org/eclipse/emf/emfatic/core/generator/ecore/EcoreGenerator.java
index 77f85d3..e2d3cd7 100644
--- a/plugins/org.eclipse.emf.emfatic.core/src/org/eclipse/emf/emfatic/core/generator/ecore/EcoreGenerator.java
+++ b/plugins/org.eclipse.emf.emfatic.core/src/org/eclipse/emf/emfatic/core/generator/ecore/EcoreGenerator.java
@@ -12,14 +12,18 @@
package org.eclipse.emf.emfatic.core.generator.ecore;
import java.io.BufferedReader;
+import java.io.File;
+import java.io.FileInputStream;
import java.io.InputStreamReader;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.emf.common.util.URI;
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.emf.ecore.xmi.impl.XMIResourceFactoryImpl;
import org.eclipse.emf.emfatic.core.lang.gen.parser.EmfaticParserDriver;
import org.eclipse.gymnast.runtime.core.parser.ParseContext;
import org.eclipse.gymnast.runtime.core.parser.ParseMessage;
@@ -30,7 +34,7 @@ import org.eclipse.gymnast.runtime.core.util.MarkerUtil;
* @author cjdaly@us.ibm.com
*/
public class EcoreGenerator {
-
+
public EcoreGenerator() {
}
@@ -44,7 +48,7 @@ public class EcoreGenerator {
EmfaticParserDriver parser = new EmfaticParserDriver();
ParseContext parseContext = parser.parse(reader);
String filePath = getEcoreFilePath(emfFile);
- Resource resource = createResource(filePath);
+ Resource resource = createResource(filePath, true);
Builder builder = new Builder();
builder.build(parseContext, resource, monitor);
if (!parseContext.hasErrors()) {
@@ -69,7 +73,30 @@ public class EcoreGenerator {
ex.printStackTrace();
}
}
+
+ public void generate(File emfFile, boolean writeEcore) throws Exception {
+ NullProgressMonitor monitor = new NullProgressMonitor();
+ BufferedReader reader = new BufferedReader(new InputStreamReader(new FileInputStream(emfFile)));
+ EmfaticParserDriver parser = new EmfaticParserDriver();
+ ParseContext parseContext = parser.parse(reader);
+ String filePath = emfFile.getAbsolutePath().replaceAll("\\.emf$", ".ecore");
+ Resource resource = createResource(filePath, false);
+ Builder builder = new Builder();
+ builder.build(parseContext, resource, monitor);
+ if (!parseContext.hasErrors() && writeEcore) {
+ Connector connector = new Connector(builder);
+ connector.connect(parseContext, resource, monitor);
+ resource.save(null);
+ }
+ else {
+ String message = parseContext.getMessages()[0].getMessage();
+ message = message.replaceAll("\\r|\\n", " ");
+ message = message.trim();
+ throw new Exception("Syntax error: " + message);
+ }
+ }
+
private String getEcoreFilePath(IFile emfFile) {
String emfFileExt = emfFile.getFileExtension();
int extLen = emfFileExt != null ? emfFileExt.length() + 1 : 0;
@@ -80,9 +107,16 @@ public class EcoreGenerator {
return filePath;
}
- private Resource createResource(String filePath) {
+ private Resource createResource(String filePath, boolean inWorkspace) {
ResourceSet resourceSet = new ResourceSetImpl();
- URI uri = URI.createPlatformResourceURI(filePath, false);
+ URI uri = null;
+ if (!inWorkspace) {
+ resourceSet.getResourceFactoryRegistry().getExtensionToFactoryMap().put("ecore", new XMIResourceFactoryImpl());
+ uri = URI.createFileURI(filePath);
+ }
+ else {
+ uri = URI.createPlatformResourceURI(filePath, false);
+ }
Resource resource = resourceSet.createResource(uri);
return resource;
}
diff --git a/plugins/org.eclipse.emf.emfatic.core/src/org/eclipse/emf/emfatic/core/lang/gen/parser/EmfaticParserDriver.java b/plugins/org.eclipse.emf.emfatic.core/src/org/eclipse/emf/emfatic/core/lang/gen/parser/EmfaticParserDriver.java
index 7163ecc..4dcb1f6 100644
--- a/plugins/org.eclipse.emf.emfatic.core/src/org/eclipse/emf/emfatic/core/lang/gen/parser/EmfaticParserDriver.java
+++ b/plugins/org.eclipse.emf.emfatic.core/src/org/eclipse/emf/emfatic/core/lang/gen/parser/EmfaticParserDriver.java
@@ -18,6 +18,7 @@ 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.emf.ecore.util.Diagnostician;
+import org.eclipse.emf.ecore.xmi.impl.XMIResourceFactoryImpl;
import org.eclipse.emf.emfatic.core.generator.ecore.Builder;
import org.eclipse.emf.emfatic.core.generator.ecore.Connector;
import org.eclipse.emf.emfatic.core.generator.ecore.EmfaticSemanticWarning;
@@ -53,6 +54,10 @@ public class EmfaticParserDriver implements IParser {
NullProgressMonitor npm = new NullProgressMonitor();
ResourceSet resourceSet = new ResourceSetImpl();
URI uri = URI.createPlatformResourceURI("dummy");
+
+ if (Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap().get("ecore") == null) {
+ resourceSet.getResourceFactoryRegistry().getExtensionToFactoryMap().put("*", new XMIResourceFactoryImpl());
+ }
Resource resource = resourceSet.createResource(uri);
try {
builder.build(parseContext, resource, npm);
diff --git a/updatesites/org.eclipse.emf.emfatic.updatesite/site.xml b/updatesites/org.eclipse.emf.emfatic.updatesite/site.xml
index df62e2a..b1a75d2 100644
--- a/updatesites/org.eclipse.emf.emfatic.updatesite/site.xml
+++ b/updatesites/org.eclipse.emf.emfatic.updatesite/site.xml
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<site
digestURL="http://download.eclipse.org/emfatic/update/">
- <feature url="features/org.eclipse.emf.emfatic_0.8.0.201301242224.jar" id="org.eclipse.emf.emfatic" version="0.8.0.201301242224">
+ <feature url="features/org.eclipse.emf.emfatic_0.8.0.201302031045.jar" id="org.eclipse.emf.emfatic" version="0.8.0.201302031045">
<category name="Emfatic (Incubation)"/>
</feature>
<category-def name="Emfatic (Incubation)" label="Emfatic (Incubation)"/>

Back to the top