Permalink
Browse files

added check for unresolved proxies to avoid NPE while generator EMF code

  • Loading branch information...
mirkoseifert committed Apr 3, 2013
1 parent 9735544 commit 4312fbc0cab5af8c84b41a3057e69a0bc11f81e0
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2006-2012
+ * Copyright (c) 2006-2013
* Software Technology Group, Dresden University of Technology
* DevBoost GmbH, Berlin, Amtsgericht Charlottenburg, HRB 140026
*
@@ -27,14 +27,18 @@
import org.eclipse.emf.codegen.ecore.genmodel.GenModelPackage;
import org.eclipse.emf.codegen.ecore.genmodel.generator.GenBaseGeneratorAdapter;
import org.eclipse.emf.codegen.ecore.genmodel.generator.GenModelGeneratorAdapterFactory;
+import org.eclipse.emf.common.notify.Notifier;
import org.eclipse.emf.common.util.BasicMonitor;
import org.eclipse.emf.common.util.Diagnostic;
+import org.eclipse.emf.common.util.TreeIterator;
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.ecore.resource.impl.ResourceSetImpl;
+import org.eclipse.emf.ecore.util.EcoreUtil;
import org.eclipse.emf.ecore.xmi.impl.EcoreResourceFactoryImpl;
import de.devboost.buildboost.artifacts.Plugin;
@@ -45,7 +49,8 @@
* The {@link HeadlessCodeGenerator} is executed by build scripts that are
* generated by the {@link GenerateEMFCodeStage} or the
* {@link GenerateGenModelCodeStep}. It uses the EMF code generators to obtain
- * Java code for given generator models.
+ * Java code a given generator model. To allow access to referenced generator
+ * models a list of all available plug-ins can also be passed to this class.
*/
public class HeadlessCodeGenerator {
@@ -75,6 +80,10 @@ private void run(String pathToGenModel, String projectName, String projectPath,
);
GenModel genModel = loadGenModel(pathToGenModel, rs);
+ if (genModel == null) {
+ return;
+ }
+
registerCodeGenAdapter();
generateCode(genModel, projectPath);
}
@@ -149,6 +158,25 @@ private GenModel loadGenModel(String pathToGenModel, ResourceSet rs) {
// do not generate manifest, this may override an existing manifest
genModel.setBundleManifest(false);
+ EcoreUtil.resolveAll(rs);
+
+ boolean foundProxy = false;
+ TreeIterator<Notifier> allContents = rs.getAllContents();
+ while (allContents.hasNext()) {
+ Notifier notifier = (Notifier) allContents.next();
+ if (notifier instanceof EObject) {
+ EObject eObject = (EObject) notifier;
+ if (eObject.eIsProxy()) {
+ foundProxy = true;
+ System.out.println("ERROR: Found unresolved proxy in generator model " + eObject);
+ }
+ }
+ }
+
+ if (foundProxy) {
+ return null;
+ }
+
return genModel;
}

0 comments on commit 4312fbc

Please sign in to comment.