Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--plugins/org.eclipse.etrice.generator.c/src/org/eclipse/etrice/generator/c/Main.java9
-rw-r--r--plugins/org.eclipse.etrice.generator.config/src/org/eclipse/etrice/generator/config/DataConfiguration.xtend9
-rw-r--r--plugins/org.eclipse.etrice.generator.config/xtend-gen/org/eclipse/etrice/generator/config/DataConfiguration.java10
-rw-r--r--plugins/org.eclipse.etrice.generator.doc/src/org/eclipse/etrice/generator/doc/Main.java11
-rw-r--r--plugins/org.eclipse.etrice.generator.java/src/org/eclipse/etrice/generator/java/Main.java38
-rw-r--r--plugins/org.eclipse.etrice.generator/src/org/eclipse/etrice/generator/base/AbstractGenerator.java111
-rw-r--r--plugins/org.eclipse.etrice.generator/src/org/eclipse/etrice/generator/base/IDataConfiguration.java5
7 files changed, 111 insertions, 82 deletions
diff --git a/plugins/org.eclipse.etrice.generator.c/src/org/eclipse/etrice/generator/c/Main.java b/plugins/org.eclipse.etrice.generator.c/src/org/eclipse/etrice/generator/c/Main.java
index f28d21c40..78617013e 100644
--- a/plugins/org.eclipse.etrice.generator.c/src/org/eclipse/etrice/generator/c/Main.java
+++ b/plugins/org.eclipse.etrice.generator.c/src/org/eclipse/etrice/generator/c/Main.java
@@ -15,7 +15,6 @@ package org.eclipse.etrice.generator.c;
import java.util.ArrayList;
import java.util.List;
-import org.eclipse.emf.ecore.resource.ResourceSet;
import org.eclipse.etrice.core.genmodel.etricegen.Root;
import org.eclipse.etrice.generator.base.AbstractGenerator;
import org.eclipse.etrice.generator.c.gen.Validator;
@@ -100,14 +99,12 @@ public class Main extends AbstractGenerator {
}
protected boolean runGenerator(List<String> uriList, String genModelPath, boolean genInstDiag, boolean asLibrary) {
- ResourceSet rs = resourceSetProvider.get();
+ loadModels(uriList);
- loadModels(uriList, rs);
-
- if (!validateModels(rs))
+ if (!validateModels())
return false;
- Root genModel = createGeneratorModel(rs, asLibrary, genModelPath);
+ Root genModel = createGeneratorModel(asLibrary, genModelPath);
if (genModel==null)
return false;
diff --git a/plugins/org.eclipse.etrice.generator.config/src/org/eclipse/etrice/generator/config/DataConfiguration.xtend b/plugins/org.eclipse.etrice.generator.config/src/org/eclipse/etrice/generator/config/DataConfiguration.xtend
index e7b0e7588..bdad57177 100644
--- a/plugins/org.eclipse.etrice.generator.config/src/org/eclipse/etrice/generator/config/DataConfiguration.xtend
+++ b/plugins/org.eclipse.etrice.generator.config/src/org/eclipse/etrice/generator/config/DataConfiguration.xtend
@@ -31,10 +31,11 @@ import org.eclipse.etrice.core.config.StringLiteral
import org.eclipse.etrice.core.config.LiteralArray
import org.eclipse.etrice.core.config.Literal
import org.eclipse.etrice.core.room.InterfaceItem
-import org.eclipse.emf.ecore.resource.Resource
import org.eclipse.etrice.core.config.ConfigModel
import com.google.inject.Inject
import org.eclipse.xtext.scoping.impl.ImportUriResolver
+import org.eclipse.etrice.generator.base.IResourceURIAcceptor
+import org.eclipse.emf.ecore.EObject
class DataConfiguration implements IDataConfiguration {
@@ -166,13 +167,11 @@ class DataConfiguration implements IDataConfiguration {
return result
}
- override addReferencedModels(Resource resource, List<String> uriList) {
- val root = resource.contents.get(0)
+ override void addReferencedModels(IResourceURIAcceptor acceptor, EObject root) {
if (root instanceof ConfigModel) {
for (imp : (root as ConfigModel).imports) {
val importURI = uriResolver.resolve(imp)
- logger.logInfo("adding imported model "+importURI)
- uriList.add(importURI)
+ acceptor.addResourceURI(importURI);
}
}
}
diff --git a/plugins/org.eclipse.etrice.generator.config/xtend-gen/org/eclipse/etrice/generator/config/DataConfiguration.java b/plugins/org.eclipse.etrice.generator.config/xtend-gen/org/eclipse/etrice/generator/config/DataConfiguration.java
index 45e8f6405..38b98c3fb 100644
--- a/plugins/org.eclipse.etrice.generator.config/xtend-gen/org/eclipse/etrice/generator/config/DataConfiguration.java
+++ b/plugins/org.eclipse.etrice.generator.config/xtend-gen/org/eclipse/etrice/generator/config/DataConfiguration.java
@@ -6,7 +6,6 @@ import java.util.ArrayList;
import java.util.List;
import org.eclipse.emf.common.util.EList;
import org.eclipse.emf.ecore.EObject;
-import org.eclipse.emf.ecore.resource.Resource;
import org.eclipse.emf.ecore.resource.ResourceSet;
import org.eclipse.etrice.core.ConfigStandaloneSetup;
import org.eclipse.etrice.core.config.AttrClassConfig;
@@ -30,6 +29,7 @@ import org.eclipse.etrice.core.room.InterfaceItem;
import org.eclipse.etrice.core.room.ProtocolClass;
import org.eclipse.etrice.core.room.SubSystemClass;
import org.eclipse.etrice.generator.base.IDataConfiguration;
+import org.eclipse.etrice.generator.base.IResourceURIAcceptor;
import org.eclipse.etrice.generator.config.util.DataConfigurationHelper;
import org.eclipse.xtend2.lib.StringConcatenation;
import org.eclipse.xtext.scoping.impl.ImportUriResolver;
@@ -354,17 +354,13 @@ public class DataConfiguration implements IDataConfiguration {
return result;
}
- public void addReferencedModels(final Resource resource, final List<String> uriList) {
- EList<EObject> _contents = resource.getContents();
- final EObject root = _contents.get(0);
+ public void addReferencedModels(final IResourceURIAcceptor acceptor, final EObject root) {
if ((root instanceof ConfigModel)) {
EList<Import> _imports = ((ConfigModel) root).getImports();
for (final Import imp : _imports) {
{
final String importURI = this.uriResolver.resolve(imp);
- String _plus = ("adding imported model " + importURI);
- this.logger.logInfo(_plus);
- uriList.add(importURI);
+ acceptor.addResourceURI(importURI);
}
}
}
diff --git a/plugins/org.eclipse.etrice.generator.doc/src/org/eclipse/etrice/generator/doc/Main.java b/plugins/org.eclipse.etrice.generator.doc/src/org/eclipse/etrice/generator/doc/Main.java
index c49cd5ffa..5b88b5168 100644
--- a/plugins/org.eclipse.etrice.generator.doc/src/org/eclipse/etrice/generator/doc/Main.java
+++ b/plugins/org.eclipse.etrice.generator.doc/src/org/eclipse/etrice/generator/doc/Main.java
@@ -15,11 +15,10 @@ package org.eclipse.etrice.generator.doc;
import java.util.ArrayList;
import java.util.List;
-import org.eclipse.emf.ecore.resource.ResourceSet;
import org.eclipse.etrice.core.genmodel.etricegen.Root;
import org.eclipse.etrice.generator.base.AbstractGenerator;
-import org.eclipse.etrice.generator.doc.setup.GeneratorModule;
import org.eclipse.etrice.generator.doc.gen.InstanceDiagramGen;
+import org.eclipse.etrice.generator.doc.setup.GeneratorModule;
import org.eclipse.xtext.generator.IGenerator;
import com.google.inject.Inject;
@@ -93,14 +92,12 @@ public class Main extends AbstractGenerator {
}
protected boolean runGenerator(List<String> uriList, String genModelPath, boolean genInstDiag, boolean asLibrary) {
- ResourceSet rs = resourceSetProvider.get();
-
- loadModels(uriList, rs);
+ loadModels(uriList);
- if (!validateModels(rs))
+ if (!validateModels())
return false;
- Root genModel = createGeneratorModel(rs, asLibrary, genModelPath);
+ Root genModel = createGeneratorModel(asLibrary, genModelPath);
if (genModel==null)
return false;
diff --git a/plugins/org.eclipse.etrice.generator.java/src/org/eclipse/etrice/generator/java/Main.java b/plugins/org.eclipse.etrice.generator.java/src/org/eclipse/etrice/generator/java/Main.java
index fc117c70c..1dfdec064 100644
--- a/plugins/org.eclipse.etrice.generator.java/src/org/eclipse/etrice/generator/java/Main.java
+++ b/plugins/org.eclipse.etrice.generator.java/src/org/eclipse/etrice/generator/java/Main.java
@@ -16,15 +16,13 @@ import java.util.ArrayList;
import java.util.List;
import org.eclipse.emf.ecore.EObject;
-import org.eclipse.emf.ecore.resource.Resource;
-import org.eclipse.emf.ecore.resource.ResourceSet;
import org.eclipse.etrice.core.etmap.eTMap.MappingModel;
import org.eclipse.etrice.core.etmap.util.ETMapUtil;
import org.eclipse.etrice.core.etphys.eTPhys.PhysicalModel;
import org.eclipse.etrice.core.genmodel.etricegen.Root;
-import org.eclipse.etrice.core.room.RoomModel;
import org.eclipse.etrice.generator.base.AbstractGenerator;
import org.eclipse.etrice.generator.base.IDataConfiguration;
+import org.eclipse.etrice.generator.base.IResourceURIAcceptor;
import org.eclipse.etrice.generator.java.gen.Validator;
import org.eclipse.etrice.generator.java.setup.GeneratorModule;
import org.eclipse.xtext.generator.IGenerator;
@@ -121,24 +119,22 @@ public class Main extends AbstractGenerator {
}
protected boolean runGenerator(List<String> uriList, String genModelPath, boolean genDocumentation, boolean asLibrary, boolean debug) {
- ResourceSet rs = resourceSetProvider.get();
+ loadModels(uriList);
- loadModels(uriList, rs);
-
- if (!validateModels(rs))
+ if (!validateModels())
return false;
- if(!dataConfig.setResources(rs, logger))
+ if(!dataConfig.setResources(getResourceSet(), logger))
return false;
- Root genModel = createGeneratorModel(rs, asLibrary, genModelPath);
+ Root genModel = createGeneratorModel(asLibrary, genModelPath);
if (genModel==null)
return false;
if (!validator.validate(genModel))
return false;
- ETMapUtil.processModels(genModel, rs);
+ ETMapUtil.processModels(genModel, getResourceSet());
if (debug) {
logger.logInfo("-- begin dump of mappings");
logger.logInfo(ETMapUtil.dumpMappings());
@@ -167,31 +163,23 @@ public class Main extends AbstractGenerator {
* @see org.eclipse.etrice.generator.base.AbstractGenerator#addReferencedModels(org.eclipse.emf.ecore.resource.Resource, java.util.List)
*/
@Override
- protected void addReferencedModels(Resource resource, List<String> uriList) {
- EObject root = resource.getContents().get(0);
- if (root instanceof RoomModel) {
- for (org.eclipse.etrice.core.room.Import imp : ((RoomModel)root).getImports()) {
- String importURI = uriResolver.resolve(imp);
- logger.logInfo("adding imported model "+importURI);
- uriList.add(importURI);
- }
- }
- else if (root instanceof PhysicalModel) {
+ protected void addReferencedModels(EObject root, IResourceURIAcceptor acceptor) {
+ super.addReferencedModels(root, acceptor);
+
+ if (root instanceof PhysicalModel) {
for (org.eclipse.etrice.core.etphys.eTPhys.Import imp : ((PhysicalModel)root).getImports()) {
String importURI = uriResolver.resolve(imp);
- logger.logInfo("adding imported model "+importURI);
- uriList.add(importURI);
+ acceptor.addResourceURI(importURI);
}
}
else if (root instanceof MappingModel) {
for (org.eclipse.etrice.core.etmap.eTMap.Import imp : ((MappingModel)root).getImports()) {
String importURI = uriResolver.resolve(imp);
- logger.logInfo("adding imported model "+importURI);
- uriList.add(importURI);
+ acceptor.addResourceURI(importURI);
}
}
else {
- dataConfig.addReferencedModels(resource, uriList);
+ dataConfig.addReferencedModels(acceptor, root);
}
}
}
diff --git a/plugins/org.eclipse.etrice.generator/src/org/eclipse/etrice/generator/base/AbstractGenerator.java b/plugins/org.eclipse.etrice.generator/src/org/eclipse/etrice/generator/base/AbstractGenerator.java
index 72e696dc3..8a27bec09 100644
--- a/plugins/org.eclipse.etrice.generator/src/org/eclipse/etrice/generator/base/AbstractGenerator.java
+++ b/plugins/org.eclipse.etrice.generator/src/org/eclipse/etrice/generator/base/AbstractGenerator.java
@@ -17,6 +17,7 @@ import java.io.IOException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
+import java.util.HashSet;
import java.util.List;
import org.eclipse.emf.common.util.TreeIterator;
@@ -51,7 +52,7 @@ import com.google.inject.Provider;
* @author Henrik Rentz-Reichert
*
*/
-public abstract class AbstractGenerator {
+public abstract class AbstractGenerator implements IResourceURIAcceptor {
public static final int GENERATOR_OK = 0;
public static final int GENERATOR_ERROR = 1;
@@ -63,7 +64,10 @@ public abstract class AbstractGenerator {
private static Injector injector;
private HashMap<DetailCode, String> detailcode2string = new HashMap<DetailCode, String>();
-
+ private ResourceSet resourceSet;
+ private HashSet<URI> modelURIs = new HashSet<URI>();
+ private HashSet<URI> loadedModelURIs = new HashSet<URI>();
+
public static void setTerminateOnError(boolean terminateOnError) {
AbstractGenerator.terminateOnError = terminateOnError;
}
@@ -120,6 +124,10 @@ public abstract class AbstractGenerator {
protected IResourceValidator validator;
+ protected ResourceSet getResourceSet() {
+ return resourceSet;
+ }
+
/**
* setup the ROOM core model plug-in and create a validator using injection
*/
@@ -130,15 +138,14 @@ public abstract class AbstractGenerator {
}
/**
- * @param rs the {@link ResourceSet} to which the generator model should be added
* @param genModelPath path to store the generator model (not stored if {@code null})
*
* @return the {@link Root} object of the generator model (is added to a new Resource also)
*/
- protected Root createGeneratorModel(ResourceSet rs, boolean asLibrary, String genModelPath) {
+ protected Root createGeneratorModel(boolean asLibrary, String genModelPath) {
// create a list of ROOM models
List<RoomModel> rml = new ArrayList<RoomModel>();
- for (Resource resource : rs.getResources()) {
+ for (Resource resource : resourceSet.getResources()) {
List<EObject> contents = resource.getContents();
if (!contents.isEmpty() && contents.get(0) instanceof RoomModel) {
rml.add((RoomModel)contents.get(0));
@@ -162,7 +169,7 @@ public abstract class AbstractGenerator {
translateDetailCodes(gmRoot);
URI genModelURI = genModelPath!=null? URI.createFileURI(genModelPath) : URI.createFileURI("tmp.rim");
- Resource genResource = rs.createResource(genModelURI);
+ Resource genResource = resourceSet.createResource(genModelURI);
genResource.getContents().add(gmRoot);
if (genModelPath!=null) {
try {
@@ -182,14 +189,13 @@ public abstract class AbstractGenerator {
/**
* validate the models
*
- * @param rs
*/
- protected boolean validateModels(ResourceSet rs) {
+ protected boolean validateModels() {
logger.logInfo("-- validating models");
int errors = 0;
int warnings = 0;
- for (Resource resource : rs.getResources()) {
+ for (Resource resource : resourceSet.getResources()) {
List<Issue> list = validator.validate(resource, CheckMode.ALL, CancelIndicator.NullImpl);
if (!list.isEmpty()) {
for (Issue issue : list) {
@@ -213,58 +219,83 @@ public abstract class AbstractGenerator {
return true;
}
- protected boolean loadModel(String uriString, ResourceSet rs)
+ protected boolean loadModel(URI uri)
throws RuntimeException, IOException {
- URI uri = uriString.startsWith("file:/")? URI.createURI(uriString):URI.createFileURI(uriString);
- String can = uri.toFileString();
- File f = new File(can);
- can = f.getCanonicalPath(); // e.g. remove embedded ../
- if (rs.getResource(URI.createFileURI(can), false) != null)
+
+ if (loadedModelURIs.contains(uri))
+ return true;
+
+ if (resourceSet.getResource(uri, false) != null)
// already loaded
return false;
- logger.logInfo("Loading " + can);
- rs.getResource(URI.createFileURI(can), true); // Could throw an exception...
+ logger.logInfo("Loading " + uri);
+ resourceSet.getResource(uri, true); // Could throw an exception...
+ loadedModelURIs.add(uri);
return true;
+ }
+
+ private static URI getCanonicalFileURI(String uriString) throws IOException {
+ URI uri = uriString.startsWith("file:/")? URI.createURI(uriString):URI.createFileURI(uriString);
+ String can = uri.toFileString();
+ File f = new File(can);
+ can = f.getCanonicalPath(); // e.g. remove embedded ../
+ return URI.createFileURI(can);
}
/**
- * load all models into a {@link ResourceSet}
+ * load all models into a {@link ResourceSet} which is create by this method and
+ * maintained in this object
*
* @param uriList a list of {@link URI}s as Strings
- * @param rs the {@link ResourceSet}
*/
- protected boolean loadModels(List<String> uriList, ResourceSet rs) {
+ protected boolean loadModels(List<String> uriList) {
logger.logInfo("-- reading models");
+
+ resourceSet = resourceSetProvider.get();
+ modelURIs.clear();
+ loadedModelURIs.clear();
- ArrayList<String> uris = new ArrayList<String>(uriList);
+ for (String uri : uriList) {
+ addResourceURI(uri);
+ }
boolean ok = true;
- while (!uris.isEmpty()) {
- String uriString = uris.get(0);
+ while (!modelURIs.isEmpty()) {
+ URI uri = modelURIs.iterator().next();
//logger.logInfo("Loading " + uriString);
try {
- loadModel(uriString, rs);
- addReferencedModels(rs.getResources().get(rs.getResources().size()-1), uris);
+ loadModel(uri);
+ Resource resource = resourceSet.getResources().get(resourceSet.getResources().size()-1);
+ for (EObject root : resource.getContents()) {
+ addReferencedModels(root, this);
+ }
}
catch (Exception e) {
ok = false;
- logger.logError("couldn't load '"+uriString+"'", null);
+ logger.logError("couldn't load '"+uri+"'", null);
}
- uris.remove(0);
+ modelURIs.remove(uri);
}
- EcoreUtil.resolveAll(rs);
+ EcoreUtil.resolveAll(resourceSet);
return ok;
}
/**
* @param resource
- * @param uriList
+ * @param acceptor
*/
- protected void addReferencedModels(Resource resource, List<String> uriList) {}
+ protected void addReferencedModels(EObject root, IResourceURIAcceptor acceptor) {
+ if (root instanceof RoomModel) {
+ for (org.eclipse.etrice.core.room.Import imp : ((RoomModel)root).getImports()) {
+ String importURI = uriResolver.resolve(imp);
+ acceptor.addResourceURI(importURI);
+ }
+ }
+ }
/**
* create detail code translations once and for all
@@ -331,5 +362,25 @@ public abstract class AbstractGenerator {
* @return GENERATOR_OK or GENERATOR_ERROR
*/
protected abstract int runGenerator(String[] args);
+
+ public boolean addResourceURI(String uri) {
+ try {
+ URI can = getCanonicalFileURI(uri);
+ if (loadedModelURIs.contains(can))
+ return false;
+
+ boolean added = modelURIs.add(can);
+ if (added) {
+ if (loadedModelURIs.isEmpty())
+ logger.logInfo("added model "+uri);
+ else
+ logger.logInfo("added referenced model "+uri);
+ }
+ return added;
+ }
+ catch (IOException e) {
+ return false;
+ }
+ }
}
diff --git a/plugins/org.eclipse.etrice.generator/src/org/eclipse/etrice/generator/base/IDataConfiguration.java b/plugins/org.eclipse.etrice.generator/src/org/eclipse/etrice/generator/base/IDataConfiguration.java
index c64838310..a99dd8d8d 100644
--- a/plugins/org.eclipse.etrice.generator/src/org/eclipse/etrice/generator/base/IDataConfiguration.java
+++ b/plugins/org.eclipse.etrice.generator/src/org/eclipse/etrice/generator/base/IDataConfiguration.java
@@ -14,7 +14,7 @@ package org.eclipse.etrice.generator.base;
import java.util.List;
-import org.eclipse.emf.ecore.resource.Resource;
+import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecore.resource.ResourceSet;
import org.eclipse.etrice.core.genmodel.base.ILogger;
import org.eclipse.etrice.core.genmodel.etricegen.ActorInstance;
@@ -52,6 +52,7 @@ public interface IDataConfiguration {
public List<Attribute> getDynConfigReadAttributes(ActorClass actor);
public List<Attribute> getDynConfigWriteAttributes(ActorClass actor);
- public void addReferencedModels(Resource resource, List<String> uriList);
+ // for some reason overriding this method isn't accepted if the EObject parameter is in the first place
+ public void addReferencedModels(IResourceURIAcceptor acceptor, EObject root);
}

Back to the top