Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authoraradermache2013-06-29 21:30:28 +0000
committeraradermache2013-06-29 21:30:28 +0000
commitab4a5ee51c77f82994232b3b217e324b83f1be4a (patch)
tree5a11944c5f2a17291788466d700c131fb64b37da /extraplugins/codegen
parent305fd1abb66a16818efaf4f04704cfc295ee122a (diff)
downloadorg.eclipse.papyrus-ab4a5ee51c77f82994232b3b217e324b83f1be4a.tar.gz
org.eclipse.papyrus-ab4a5ee51c77f82994232b3b217e324b83f1be4a.tar.xz
org.eclipse.papyrus-ab4a5ee51c77f82994232b3b217e324b83f1be4a.zip
- Fixed Acceleo problems:
- incomplete file instead of "null" in case of build errors (additional log entry instead of exception) - Deactivate use of absolute path
Diffstat (limited to 'extraplugins/codegen')
-rw-r--r--extraplugins/codegen/org.eclipse.papyrus.acceleo/src/org/eclipse/papyrus/acceleo/AcceleoDriver.java67
-rw-r--r--extraplugins/codegen/org.eclipse.papyrus.acceleo/src/org/eclipse/papyrus/acceleo/GenericGenUtils.java (renamed from extraplugins/codegen/org.eclipse.papyrus.acceleo/src/org/eclipse/papyrus/acceleo/GenUtils.java)2
-rw-r--r--extraplugins/codegen/org.eclipse.papyrus.cpp.codegen.ui/src/org/eclipse/papyrus/cpp/codegen/ui/handler/GenerateCodeHandler.java12
-rw-r--r--extraplugins/codegen/org.eclipse.papyrus.cpp.codegen/.classpath2
-rw-r--r--extraplugins/codegen/org.eclipse.papyrus.cpp.codegen/META-INF/MANIFEST.MF14
5 files changed, 65 insertions, 32 deletions
diff --git a/extraplugins/codegen/org.eclipse.papyrus.acceleo/src/org/eclipse/papyrus/acceleo/AcceleoDriver.java b/extraplugins/codegen/org.eclipse.papyrus.acceleo/src/org/eclipse/papyrus/acceleo/AcceleoDriver.java
index 3d8ca42d8e3..e669f023ec3 100644
--- a/extraplugins/codegen/org.eclipse.papyrus.acceleo/src/org/eclipse/papyrus/acceleo/AcceleoDriver.java
+++ b/extraplugins/codegen/org.eclipse.papyrus.acceleo/src/org/eclipse/papyrus/acceleo/AcceleoDriver.java
@@ -12,7 +12,6 @@
package org.eclipse.papyrus.acceleo;
import java.io.File;
-import java.lang.reflect.InvocationTargetException;
import java.util.ArrayList;
import java.util.List;
@@ -30,6 +29,7 @@ import org.eclipse.acceleo.parser.AcceleoSourceBuffer;
import org.eclipse.acceleo.parser.cst.ModuleImportsValue;
import org.eclipse.core.runtime.ILogListener;
import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Status;
import org.eclipse.emf.common.util.BasicEList;
import org.eclipse.emf.common.util.EList;
import org.eclipse.emf.common.util.URI;
@@ -50,13 +50,15 @@ public class AcceleoDriver {
public static void init() {
engine = new AcceleoEngine();
parser = new AcceleoParser();
+ hasErrors = false;
+ lastErrors = false;
// some errors are silently captured inside the evaluation query (@see AcceleoEvaluationVisiton.visitExpression). Yet they produce
// an event in the Acceleo log which is captured via this listener.
AcceleoEnginePlugin.getDefault().getLog().addLogListener(new ILogListener() {
public void logging(IStatus status, String plugin) {
- logEntries.add(status);
-
+ hasErrors = true;
+ lastErrors = true;
}
});
acceleoResourceSet = new AcceleoResourceSetImpl();
@@ -111,8 +113,12 @@ public class AcceleoDriver {
Resource r = acceleoResourceSet.getResource(uri, true);
if(r != null) {
// use absolute path, if possible, i.e. if file exists at absolute path
- // this is required, since Acceleo references dependent file using a relative
- // path
+ // this is required, since Acceleo references dependent files using a relative
+ // path.
+ // This workaround is no longer required. In the contrary, it is harmful for binary
+ // build
+
+ /*
String absoluteFileName = Utils.getAbsoluteFN(uri.toString());
if(absoluteFileName != null) {
File fileCandidate = new File(absoluteFileName);
@@ -122,6 +128,7 @@ public class AcceleoDriver {
return URI.createFileURI(fileCandidate.getAbsolutePath());
}
}
+ */
return uri;
}
} catch (Exception e) {
@@ -238,7 +245,7 @@ public class AcceleoDriver {
try {
EList<URI> depURIs = new BasicEList<URI>();
- logEntries.clear();
+ lastErrors = false;
// deps.add(outputURI);
// check, if imports are already in resource set
@@ -310,7 +317,12 @@ public class AcceleoDriver {
}
try {
// return evaluateURI(URI.createURI("org.eclipse.papyrus.cpp.codegen" + "/" + uriStr.replace(".", "/") + "." + IAcceleoConstants.EMTL_FILE_EXTENSION), element);
- return evaluateURI(findFileInPlugin(moduleName), templateName, element);
+ URI uri = findFileInPlugin(moduleName);
+ if (uri == null) {
+ throw new RuntimeException("Cannot find Acceleo module " + moduleName + //$NON-NLS-1$
+ ". Check whether the .emtl file exists and whether it is exported"); //$NON-NLS-1$
+ }
+ return evaluateURI(uri, templateName, element);
} catch (AcceleoException e) {
}
return null;
@@ -352,22 +364,20 @@ public class AcceleoDriver {
boolean dontCheck = (module.getOwnedModuleElement().size() == 1);
for(ModuleElement me : module.getOwnedModuleElement()) {
if((me instanceof Template) && (dontCheck || me.getName().equals(templateName))) {
- logEntries.clear();
+ lastErrors = false;
Object stringResult = engine.evaluate((Template)me, arguments, new PreviewStrategy(), null);
- if(logEntries.size() > 0) {
- IStatus e = logEntries.get(0);
- Throwable exception = e.getException();
- String message = exception.getMessage();
-
- if(exception.getCause() instanceof InvocationTargetException) {
- Throwable targetException = ((InvocationTargetException)exception.getCause()).getTargetException();
- if(targetException != null) {
- message = targetException.getMessage();
- }
+ if (lastErrors) {
+ // we do not throw an exception, since it would imply that the evaluation result is
+ // lost. For a users, the (partially) evaluated result might be more useful to locate
+ // the problem than the actual error message.
+ // log additional info about template, which are not present in the acceleo log
+ String message = "an acceleo error occurred during the evaluation of template <" + //$NON-NLS-1$
+ templateName + ">. Check previous errors in the log."; //$NON-NLS-1$
+ if (templateStr.length() > 0) {
+ message += "Template contents:\n" + templateStr; //$NON-NLS-1$
}
- throw new AcceleoException("Acceleo evaluation problems (showing only first): " + message +
- "\n\nTemplate: " + templateName + "\n" + templateStr);
-
+ AcceleoEnginePlugin.getDefault().getLog().log(
+ new Status(Status.INFO, AcceleoEnginePlugin.PLUGIN_ID, message));
}
if(stringResult instanceof String) {
return (String)stringResult;
@@ -379,8 +389,19 @@ public class AcceleoDriver {
throw new AcceleoEvaluationException("Template " + templateName + " not found");
}
- protected static EList<IStatus> logEntries = new BasicEList<IStatus>();
-
+ public static void clearErrors() {
+ hasErrors = false;
+ lastErrors = false;
+ }
+
+ public static boolean hasErrors() {
+ return hasErrors;
+ }
+
+ protected static boolean hasErrors;
+
+ protected static boolean lastErrors;
+
protected static AcceleoEngine engine = null;
protected static ResourceSet acceleoResourceSet;
diff --git a/extraplugins/codegen/org.eclipse.papyrus.acceleo/src/org/eclipse/papyrus/acceleo/GenUtils.java b/extraplugins/codegen/org.eclipse.papyrus.acceleo/src/org/eclipse/papyrus/acceleo/GenericGenUtils.java
index a8db150a582..5bf3d9df19a 100644
--- a/extraplugins/codegen/org.eclipse.papyrus.acceleo/src/org/eclipse/papyrus/acceleo/GenUtils.java
+++ b/extraplugins/codegen/org.eclipse.papyrus.acceleo/src/org/eclipse/papyrus/acceleo/GenericGenUtils.java
@@ -46,7 +46,7 @@ import org.eclipse.uml2.uml.Type;
* @author wassim
*
*/
-public class GenUtils {
+public class GenericGenUtils {
/**
* Retrieve template bindings for the class passed as a Parameter
diff --git a/extraplugins/codegen/org.eclipse.papyrus.cpp.codegen.ui/src/org/eclipse/papyrus/cpp/codegen/ui/handler/GenerateCodeHandler.java b/extraplugins/codegen/org.eclipse.papyrus.cpp.codegen.ui/src/org/eclipse/papyrus/cpp/codegen/ui/handler/GenerateCodeHandler.java
index 9232fe2c0f7..019afb0fc19 100644
--- a/extraplugins/codegen/org.eclipse.papyrus.cpp.codegen.ui/src/org/eclipse/papyrus/cpp/codegen/ui/handler/GenerateCodeHandler.java
+++ b/extraplugins/codegen/org.eclipse.papyrus.cpp.codegen.ui/src/org/eclipse/papyrus/cpp/codegen/ui/handler/GenerateCodeHandler.java
@@ -24,10 +24,13 @@ import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.Path;
import org.eclipse.emf.common.util.URI;
import org.eclipse.emf.ecore.EObject;
+import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.papyrus.acceleo.AcceleoDriver;
import org.eclipse.papyrus.cpp.codegen.preferences.CppCodeGenUtils;
import org.eclipse.papyrus.cpp.codegen.transformation.CppModelElementsCreator;
import org.eclipse.papyrus.infra.emf.utils.BusinessModelResolver;
+import org.eclipse.swt.widgets.Shell;
import org.eclipse.ui.PlatformUI;
import org.eclipse.uml2.uml.Classifier;
@@ -91,13 +94,18 @@ public class GenerateCodeHandler extends AbstractHandler {
// get the container for the current element
String headerSuffix = CppCodeGenUtils.getHeaderSuffix();
String bodySuffix = CppCodeGenUtils.getBodySuffix();
+ AcceleoDriver.clearErrors();
CppModelElementsCreator mec = new CppModelElementsCreator(modelProject);
IContainer srcPkg = mec.getContainer(classifier);
try {
mec.createPackageableElement(srcPkg, null, classifier);
- IFile cppFile = srcPkg.getFile(new Path(name + "." + bodySuffix));
- IFile hFile = srcPkg.getFile(new Path(name + "." + headerSuffix));
+ if (AcceleoDriver.hasErrors()) {
+ MessageDialog.openInformation(new Shell(), "Errors during code generation", //$NON-NLS-1$
+ "Errors occured during code generation. Please check the error log"); //$NON-NLS-1$
+ }
+ IFile cppFile = srcPkg.getFile(new Path(name + "." + bodySuffix)); //$NON-NLS-1$
+ IFile hFile = srcPkg.getFile(new Path(name + "." + headerSuffix)); //$NON-NLS-1$
if(!cppFile.exists()) {
return null;
}
diff --git a/extraplugins/codegen/org.eclipse.papyrus.cpp.codegen/.classpath b/extraplugins/codegen/org.eclipse.papyrus.cpp.codegen/.classpath
index 64c5e31b7a2..ad32c83a788 100644
--- a/extraplugins/codegen/org.eclipse.papyrus.cpp.codegen/.classpath
+++ b/extraplugins/codegen/org.eclipse.papyrus.cpp.codegen/.classpath
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
- <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/J2SE-1.5"/>
+ <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6"/>
<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
<classpathentry kind="src" path="src"/>
<classpathentry kind="output" path="bin"/>
diff --git a/extraplugins/codegen/org.eclipse.papyrus.cpp.codegen/META-INF/MANIFEST.MF b/extraplugins/codegen/org.eclipse.papyrus.cpp.codegen/META-INF/MANIFEST.MF
index 647ebebb0c1..98b2ab730e2 100644
--- a/extraplugins/codegen/org.eclipse.papyrus.cpp.codegen/META-INF/MANIFEST.MF
+++ b/extraplugins/codegen/org.eclipse.papyrus.cpp.codegen/META-INF/MANIFEST.MF
@@ -16,9 +16,13 @@ Require-Bundle: org.eclipse.ui,
org.eclipse.core.filesystem;bundle-version="1.3.200",
org.eclipse.papyrus.acceleo;bundle-version="0.10.0"
Eclipse-LazyStart: true
-Export-Package: org.eclipse.papyrus.cpp.codegen,
- org.eclipse.papyrus.cpp.codegen.preferences,
- org.eclipse.papyrus.cpp.codegen.transformation,
- org.eclipse.papyrus.cpp.codegen.utils
-Bundle-RequiredExecutionEnvironment: J2SE-1.5
+Export-Package: org.eclipse.papyrus.cpp.codegen;uses:="org.eclipse.ui.plugin,org.osgi.framework,org.eclipse.uml2.uml",
+ org.eclipse.papyrus.cpp.codegen.preferences;uses:="org.eclipse.jface.preference,org.eclipse.core.runtime.preferences",
+ org.eclipse.papyrus.cpp.codegen.transformation;
+ uses:="org.eclipse.core.runtime,
+ org.eclipse.papyrus.acceleo,
+ org.eclipse.core.resources,
+ org.eclipse.uml2.uml",
+ org.eclipse.papyrus.cpp.codegen.utils;uses:="org.eclipse.emf.ecore,org.eclipse.emf.common.util,org.eclipse.uml2.uml"
+Bundle-RequiredExecutionEnvironment: JavaSE-1.6
Bundle-ActivationPolicy: lazy

Back to the top