Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAnsgar Radermacher2015-12-14 10:34:09 +0000
committerGerrit Code Review @ Eclipse.org2015-12-14 14:23:52 +0000
commit5056e895d4a5efc0e7ad2981ac1c635f21d91ff7 (patch)
treed5fe5efc2945b5d5612856bcf0db7ffc91132e22 /extraplugins
parent84d9e14baaef64fe0b462a7f28270fb21fb4b081 (diff)
downloadorg.eclipse.papyrus-5056e895d4a5efc0e7ad2981ac1c635f21d91ff7.tar.gz
org.eclipse.papyrus-5056e895d4a5efc0e7ad2981ac1c635f21d91ff7.tar.xz
org.eclipse.papyrus-5056e895d4a5efc0e7ad2981ac1c635f21d91ff7.zip
Bug 484011 - [Papyrus DSML Validation] The code generator for Java constraints does not produce a suitable operation signature for static profiles
Diffstat (limited to 'extraplugins')
-rw-r--r--extraplugins/dsml.validation/org.eclipse.papyrus.dsml.validation.generator/src/org/eclipse/papyrus/dsml/validation/generator/xtend/ConstraintGen.xtend61
-rw-r--r--extraplugins/dsml.validation/org.eclipse.papyrus.dsml.validation.generator/src/org/eclipse/papyrus/dsml/validation/generator/xtend/Generate.java4
-rw-r--r--extraplugins/dsml.validation/org.eclipse.papyrus.dsml.validation.model.ui/src/org/eclipse/papyrus/dsml/validation/generation/ui/CreateJavaValidationPluginHandler.java74
-rw-r--r--extraplugins/dsml.validation/org.eclipse.papyrus.dsml.validation.model.ui/src/org/eclipse/papyrus/dsml/validation/generation/ui/Messages.java1
-rw-r--r--extraplugins/dsml.validation/org.eclipse.papyrus.dsml.validation.model.ui/src/org/eclipse/papyrus/dsml/validation/generation/ui/messages.properties3
-rw-r--r--extraplugins/dsml.validation/org.eclipse.papyrus.dsml.validation.model/META-INF/MANIFEST.MF3
-rw-r--r--extraplugins/dsml.validation/org.eclipse.papyrus.dsml.validation.model/src/org/eclipse/papyrus/dsml/validation/model/elements/impl/ValidationRuleImpl.java19
-rw-r--r--extraplugins/dsml.validation/org.eclipse.papyrus.dsml.validation.model/src/org/eclipse/papyrus/dsml/validation/model/profilenames/Utils.java44
-rw-r--r--extraplugins/dsml.validation/org.eclipse.papyrus.dsml.validation.wizard/src/org/eclipse/papyrus/dsml/validation/wizard/CreateEMFValidationProject.java36
-rw-r--r--extraplugins/dsml.validation/org.eclipse.papyrus.dsml.validation.wizard/src/org/eclipse/papyrus/dsml/validation/wizard/JavaContentGenerator.java51
-rw-r--r--extraplugins/dsml.validation/org.eclipse.papyrus.dsml.validation.wizard/src/org/eclipse/papyrus/dsml/validation/wizard/ValidationPluginGenerator.java13
11 files changed, 206 insertions, 103 deletions
diff --git a/extraplugins/dsml.validation/org.eclipse.papyrus.dsml.validation.generator/src/org/eclipse/papyrus/dsml/validation/generator/xtend/ConstraintGen.xtend b/extraplugins/dsml.validation/org.eclipse.papyrus.dsml.validation.generator/src/org/eclipse/papyrus/dsml/validation/generator/xtend/ConstraintGen.xtend
index 68dd151bb40..90e4240669d 100644
--- a/extraplugins/dsml.validation/org.eclipse.papyrus.dsml.validation.generator/src/org/eclipse/papyrus/dsml/validation/generator/xtend/ConstraintGen.xtend
+++ b/extraplugins/dsml.validation/org.eclipse.papyrus.dsml.validation.generator/src/org/eclipse/papyrus/dsml/validation/generator/xtend/ConstraintGen.xtend
@@ -20,39 +20,55 @@ class ConstraintGen {
import org.eclipse.core.runtime.IStatus;
import org.eclipse.emf.validation.AbstractModelConstraint;
import org.eclipse.emf.validation.IValidationContext;
- import org.eclipse.uml2.uml.Element;
- import org.eclipse.uml2.uml.Stereotype;
+ import org.eclipse.emf.ecore.EObject;
+ «IF !Utils.staticProfile»
+ import org.eclipse.uml2.uml.Element;
+ import org.eclipse.uml2.uml.Stereotype;
+ import org.eclipse.uml2.uml.util.UMLUtil;
+ «ENDIF»
public class «constraint.name»Constraint extends AbstractModelConstraint {
public IStatus validate(IValidationContext ctx) {
- if (ctx.getTarget() instanceof Element) {
- Element element = (Element) ctx.getTarget();
+ EObject target = ctx.getTarget();
- «IF Utils.isConstraintForStereotype(constraint)»
- Stereotype appliedStereotype = element.getAppliedStereotype("«Utils.getConstraintForStereotype(constraint)»"); //$NON-NLS-1$
- if (appliedStereotype != null) {
- if (evaluateConstraint(element, appliedStereotype)) {
- return ctx.createSuccessStatus();
- }
- else {
- return ctx.createFailureStatus("Constraint not validated"); //$NON-NLS-1$
- }
- }
+ «IF Utils.isConstraintForStereotype(constraint)»
+ «val qStereotypeName = Utils.getConstraintForStereotype(constraint)»
+ «IF Utils.staticProfile»
+ «val qStereotypeNameJava = qStereotypeName.replace("::", ".")»
+ if (target instanceof «qStereotypeNameJava») {
+ if (evaluateConstraint((«qStereotypeNameJava») target)) {
«ELSE»
- if (evaluateConstraint(element)) {
+ Stereotype stereotype = UMLUtil.getStereotype(target);
+ if (stereotype.getQualifiedName().equals("«qStereotypeName»")) { //$NON-NLS-1$
+ Element element = UMLUtil.getBaseElement(target);
+ if (evaluateConstraint(element, stereotype)) {
+ «ENDIF»
return ctx.createSuccessStatus();
}
else {
- return ctx.createFailureStatus("Constraint not validated");
+ return ctx.createFailureStatus(""); //$NON-NLS-1$ failure message is in plugin.xml
}
- «ENDIF»
- }
- return ctx.createSuccessStatus();
+ }
+ return ctx.createSuccessStatus();
+ «ELSE»
+ if (evaluateConstraint(target)) {
+ return ctx.createSuccessStatus();
+ }
+ else {
+ return ctx.createFailureStatus(""); //$NON-NLS-1$ failure message is in plugin.xml
+ }
+ «ENDIF»
}
«IF Utils.isConstraintForStereotype(constraint)»
- private boolean evaluateConstraint(Element self, Stereotype appliedStereotype) {
+ «IF Utils.staticProfile»
+ «val qStereotypeName = Utils.getConstraintForStereotype(constraint)»
+ «val qStereotypeNameJava = qStereotypeName.replace("::", ".")»
+ private boolean evaluateConstraint(«qStereotypeNameJava» self) {
+ «ELSE»
+ private boolean evaluateConstraint(Element self, Stereotype appliedStereotype) {
+ «ENDIF»
«IF Utils.getJavaConstraintBody(constraint.specification) != null»
«Utils.getJavaConstraintBody(constraint.specification)»
«ELSE»
@@ -62,7 +78,7 @@ class ConstraintGen {
«ENDIF»
«IF !Utils.isConstraintForStereotype(constraint)»
- private boolean evaluateConstraint(Element self) {
+ private boolean evaluateConstraint(EObject self) {
«IF Utils.getJavaConstraintBody(constraint.specification) != null»
«Utils.getJavaConstraintBody(constraint.specification)»
«ELSE»
@@ -84,6 +100,9 @@ class ConstraintGen {
while (contentIterator.hasNext) {
val constraint = contentIterator.next
if (Utils.hasSpecificationForJava(constraint)) {
+ if (constraint.name == null) {
+ throw new RuntimeException("Constraint has no name, context: " + constraint.context.qualifiedName);
+ }
val fileName = Utils.getTopPkg().replaceAll('\\.', '/') + '/constraints/' + constraint.getName() +
'Constraint.java';
fsa.generateFile(fileName, constraint.generateConstraint.toString)
diff --git a/extraplugins/dsml.validation/org.eclipse.papyrus.dsml.validation.generator/src/org/eclipse/papyrus/dsml/validation/generator/xtend/Generate.java b/extraplugins/dsml.validation/org.eclipse.papyrus.dsml.validation.generator/src/org/eclipse/papyrus/dsml/validation/generator/xtend/Generate.java
index b863cef975a..3600bc23f7c 100644
--- a/extraplugins/dsml.validation/org.eclipse.papyrus.dsml.validation.generator/src/org/eclipse/papyrus/dsml/validation/generator/xtend/Generate.java
+++ b/extraplugins/dsml.validation/org.eclipse.papyrus.dsml.validation.generator/src/org/eclipse/papyrus/dsml/validation/generator/xtend/Generate.java
@@ -35,9 +35,9 @@ import org.eclipse.papyrus.codegen.base.ProjectBasedFileAccess;
public class Generate {
/**
- *
+ * The source folder for the generated file.
*/
- private static final String SRC = "src-gen"; //$NON-NLS-1$
+ public static final String SRC = "src-gen"; //$NON-NLS-1$
/**
* This method is used to launch the generation from a standalone application.
diff --git a/extraplugins/dsml.validation/org.eclipse.papyrus.dsml.validation.model.ui/src/org/eclipse/papyrus/dsml/validation/generation/ui/CreateJavaValidationPluginHandler.java b/extraplugins/dsml.validation/org.eclipse.papyrus.dsml.validation.model.ui/src/org/eclipse/papyrus/dsml/validation/generation/ui/CreateJavaValidationPluginHandler.java
index 13336cd8a6f..9133d5ae1ba 100644
--- a/extraplugins/dsml.validation/org.eclipse.papyrus.dsml.validation.model.ui/src/org/eclipse/papyrus/dsml/validation/generation/ui/CreateJavaValidationPluginHandler.java
+++ b/extraplugins/dsml.validation/org.eclipse.papyrus.dsml.validation.model.ui/src/org/eclipse/papyrus/dsml/validation/generation/ui/CreateJavaValidationPluginHandler.java
@@ -30,6 +30,7 @@ import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.jface.window.Window;
import org.eclipse.papyrus.dsml.validation.model.elements.impl.ConstraintManagerImpl;
import org.eclipse.papyrus.dsml.validation.model.elements.interfaces.IConstraintsManager;
+import org.eclipse.papyrus.dsml.validation.model.profilenames.Utils;
import org.eclipse.papyrus.dsml.validation.wizard.CreateEMFValidationProject;
import org.eclipse.papyrus.dsml.validation.wizard.JavaContentGenerator;
import org.eclipse.papyrus.dsml.validation.wizard.ValidationPluginGenerator;
@@ -98,14 +99,14 @@ public class CreateJavaValidationPluginHandler extends AbstractHandler {
constraintsManager = new ConstraintManagerImpl(profileSelection);
EPackage definition = null;
- IProject existingProject = null;
+ IProject hostingProject = null; // project that is hosting the profile
URI uri = profileSelection.eResource().getURI();
IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
if (uri.segmentCount() >= 2) {
- existingProject = root.getProject(uri.segment(1));
+ hostingProject = root.getProject(uri.segment(1));
}
- IProject hostingProject = existingProject;
+ IProject targetProject = null;
Shell shell = Display.getDefault().getActiveShell();
boolean isPlugin = false;
@@ -121,7 +122,7 @@ public class CreateJavaValidationPluginHandler extends AbstractHandler {
}
int question = 0;
- if ((existingProject != null) && existingProject.exists() && isPlugin) {
+ if ((hostingProject != null) && hostingProject.exists() && isPlugin) {
MessageDialog dialog = new MessageDialog(shell,
Messages.CreateJavaValidationPluginHandler_ChoosePluginGeneration, null,
Messages.CreateJavaValidationPluginHandler_HowtoGeneratePlugin, MessageDialog.QUESTION,
@@ -136,6 +137,8 @@ public class CreateJavaValidationPluginHandler extends AbstractHandler {
question = dialog.open();
}
+ boolean verboseDependency = true;
+
if ((question == 1) || (question == 2)) {
if (question == 1) {
// get object which represents the workspace
@@ -145,46 +148,61 @@ public class CreateJavaValidationPluginHandler extends AbstractHandler {
dialog.setTitle(Messages.CreateJavaValidationPluginHandler_SelectExisting);
if (dialog.open() == Window.OK) {
- existingProject = (IProject) dialog.getResult()[0];
- }
- else {
- existingProject = null;
+ targetProject = (IProject) dialog.getResult()[0];
}
}
-
- if (existingProject != null) {
- // generate java code
- JavaContentGenerator generateAllJava = new JavaContentGenerator(existingProject, profileSelection);
- generateAllJava.run();
- // generate plugin + extension point
- try {
- ValidationPluginGenerator.instance.generate(existingProject, constraintsManager, definition);
- addDependencyToHostingProject(shell, hostingProject);
- } catch (Exception e) {
- Activator.log.error(e);
- MessageDialog.openInformation(shell, Messages.CreateJavaValidationPluginHandler_ExceptionDuringPluginGeneration, Messages.CreateJavaValidationPluginHandler_CheckErrorLog);
- }
+ else {
+ targetProject = hostingProject;
}
}
else if (question == 0) {
+ CreateEMFValidationProject wizard = new CreateEMFValidationProject(profileSelection, constraintsManager, definition);
+ if (wizard.openDialog() == Window.OK) {
+ targetProject = wizard.getProject();
+ }
+ // don't create a dialog for added dependency (since the project is new, this information is not useful)
+ verboseDependency = false;
+ }
+ if (targetProject != null) {
+ // generate java code
+ JavaContentGenerator generateAllJava = new JavaContentGenerator(targetProject, profileSelection);
try {
- addDependencyToHostingProject(shell, hostingProject);
+ generateAllJava.run();
+ // generate plugin + extension point
+ ValidationPluginGenerator.instance.generate(targetProject, constraintsManager, definition);
+ addDependencyToProject(shell, hostingProject, ValidationPluginGenerator.UML_DSML_VALIDATION_PROFILE_PLUGIN, true);
+ if (Utils.isStaticProfile()) {
+ // add dependency to existing project (project hosting the static profile)
+ addDependencyToProject(shell, targetProject, hostingProject.getName(), verboseDependency);
+ }
} catch (Exception e) {
Activator.log.error(e);
MessageDialog.openInformation(shell, Messages.CreateJavaValidationPluginHandler_ExceptionDuringPluginGeneration, Messages.CreateJavaValidationPluginHandler_CheckErrorLog);
}
- CreateEMFValidationProject wizard = new CreateEMFValidationProject(profileSelection, constraintsManager, definition);
- wizard.openDialog();
}
}
return null;
}
- public void addDependencyToHostingProject(Shell shell, IProject hostingProject) throws CoreException, IOException {
- if (ValidationPluginGenerator.instance.addDSMLdependency(hostingProject)) {
- MessageDialog.openInformation(shell, Messages.CreateJavaValidationPluginHandler_DependencyAdded,
- String.format(Messages.CreateJavaValidationPluginHandler_DependencyAddedMsg, hostingProject.getName()));
+ /**
+ * @param shell An active shell
+ * @param dependingProject the project that will host the validation constraints
+ * @param dependsOnPlugin the name of the plugin on which it depends
+ * @param verbose if true, create a shell message
+ * @throws CoreException
+ * @throws IOException
+ */
+ public void addDependencyToProject(Shell shell, IProject dependingProject, String dependsOnPlugin, boolean verbose) throws CoreException, IOException {
+ if (ValidationPluginGenerator.instance.addDependency(dependingProject, dependsOnPlugin)) {
+ if (verbose) {
+ String message = Messages.CreateJavaValidationPluginHandler_DependencyAddedMsg;
+ if (dependsOnPlugin.equals(ValidationPluginGenerator.UML_DSML_VALIDATION_PROFILE_PLUGIN)) {
+ message += " " + Messages.CreateJavaValidationPluginHandler_DSMLDependencyAddedMsg; //$NON-NLS-1$
+ }
+ MessageDialog.openInformation(shell, Messages.CreateJavaValidationPluginHandler_DependencyAdded,
+ String.format(message, dependsOnPlugin, dependingProject.getName()));
+ }
}
}
diff --git a/extraplugins/dsml.validation/org.eclipse.papyrus.dsml.validation.model.ui/src/org/eclipse/papyrus/dsml/validation/generation/ui/Messages.java b/extraplugins/dsml.validation/org.eclipse.papyrus.dsml.validation.model.ui/src/org/eclipse/papyrus/dsml/validation/generation/ui/Messages.java
index 832c1904397..71673548155 100644
--- a/extraplugins/dsml.validation/org.eclipse.papyrus.dsml.validation.model.ui/src/org/eclipse/papyrus/dsml/validation/generation/ui/Messages.java
+++ b/extraplugins/dsml.validation/org.eclipse.papyrus.dsml.validation.model.ui/src/org/eclipse/papyrus/dsml/validation/generation/ui/Messages.java
@@ -26,6 +26,7 @@ public class Messages extends NLS {
public static String CreateJavaValidationPluginHandler_CreateNewPlugin;
public static String CreateJavaValidationPluginHandler_DependencyAdded;
public static String CreateJavaValidationPluginHandler_DependencyAddedMsg;
+ public static String CreateJavaValidationPluginHandler_DSMLDependencyAddedMsg;
public static String CreateJavaValidationPluginHandler_ExceptionDuringPluginGeneration;
public static String CreateJavaValidationPluginHandler_GenerateIntoExisting;
public static String CreateJavaValidationPluginHandler_SelectExisting;
diff --git a/extraplugins/dsml.validation/org.eclipse.papyrus.dsml.validation.model.ui/src/org/eclipse/papyrus/dsml/validation/generation/ui/messages.properties b/extraplugins/dsml.validation/org.eclipse.papyrus.dsml.validation.model.ui/src/org/eclipse/papyrus/dsml/validation/generation/ui/messages.properties
index 29f4102dd56..2eba8a7b069 100644
--- a/extraplugins/dsml.validation/org.eclipse.papyrus.dsml.validation.model.ui/src/org/eclipse/papyrus/dsml/validation/generation/ui/messages.properties
+++ b/extraplugins/dsml.validation/org.eclipse.papyrus.dsml.validation.model.ui/src/org/eclipse/papyrus/dsml/validation/generation/ui/messages.properties
@@ -2,7 +2,8 @@ CreateJavaValidationPluginHandler_CheckErrorLog=An exception occured during plug
CreateJavaValidationPluginHandler_ChoosePluginGeneration=Choose plugin generation
CreateJavaValidationPluginHandler_CreateNewPlugin=Create a new plugin
CreateJavaValidationPluginHandler_DependencyAdded=Dependency has been added
-CreateJavaValidationPluginHandler_DependencyAddedMsg=A dependency to the DSML profile plugin has been added to project "%s". This assures that the validation profile will be automatically installed during deployment.
+CreateJavaValidationPluginHandler_DependencyAddedMsg=A dependency to the "%s" plugin has been added to project "%s".
+CreateJavaValidationPluginHandler_DSMLDependencyAddedMsg=It assures that the DSML validation profile will be automatically installed during deployment. This is required if your profile applies the DSML profile, unless you externalize the profile application (remove the dependency manually in this case).
CreateJavaValidationPluginHandler_ExceptionDuringPluginGeneration=Exception occured during plugin generation
CreateJavaValidationPluginHandler_GenerateIntoExisting=Generate DSML code into existing plugin\nCAVEAT: this operation will modify the plugin.xml
CreateJavaValidationPluginHandler_HostCurrent=Host in current plugin
diff --git a/extraplugins/dsml.validation/org.eclipse.papyrus.dsml.validation.model/META-INF/MANIFEST.MF b/extraplugins/dsml.validation/org.eclipse.papyrus.dsml.validation.model/META-INF/MANIFEST.MF
index a0b82946e50..84ea39c24a6 100644
--- a/extraplugins/dsml.validation/org.eclipse.papyrus.dsml.validation.model/META-INF/MANIFEST.MF
+++ b/extraplugins/dsml.validation/org.eclipse.papyrus.dsml.validation.model/META-INF/MANIFEST.MF
@@ -9,7 +9,8 @@ Require-Bundle: org.eclipse.ui,
org.eclipse.emf.transaction;bundle-version="1.4.0",
org.eclipse.gmf.runtime.emf.commands.core;bundle-version="1.4.0",
org.eclipse.papyrus.infra.core;bundle-version="1.2.0",
- org.eclipse.papyrus.dsml.validation;bundle-version="1.2.0"
+ org.eclipse.papyrus.dsml.validation;bundle-version="1.2.0",
+ org.eclipse.papyrus.uml.tools.utils;bundle-version="1.2.0"
Bundle-Vendor: %pluginProvider
Bundle-ActivationPolicy: lazy
Bundle-Version: 1.2.0.qualifier
diff --git a/extraplugins/dsml.validation/org.eclipse.papyrus.dsml.validation.model/src/org/eclipse/papyrus/dsml/validation/model/elements/impl/ValidationRuleImpl.java b/extraplugins/dsml.validation/org.eclipse.papyrus.dsml.validation.model/src/org/eclipse/papyrus/dsml/validation/model/elements/impl/ValidationRuleImpl.java
index e2c72d25a7f..0fb87c1252a 100644
--- a/extraplugins/dsml.validation/org.eclipse.papyrus.dsml.validation.model/src/org/eclipse/papyrus/dsml/validation/model/elements/impl/ValidationRuleImpl.java
+++ b/extraplugins/dsml.validation/org.eclipse.papyrus.dsml.validation.model/src/org/eclipse/papyrus/dsml/validation/model/elements/impl/ValidationRuleImpl.java
@@ -33,6 +33,21 @@ import org.eclipse.uml2.uml.Stereotype;
public class ValidationRuleImpl implements IValidationRule {
/**
+ *
+ */
+ private static final String CONSTRAINT_POSTFIX = "Constraint";
+
+ /**
+ *
+ */
+ private static final String DPT = ".";
+
+ /**
+ *
+ */
+ private static final String CONSTRAINT_PKG = "constraints";
+
+ /**
* Attributes of stereotype ValidationRule
*/
private static final String SA_TARGET = "target"; //$NON-NLS-1$
@@ -103,11 +118,11 @@ public class ValidationRuleImpl implements IValidationRule {
id = (String) getStereoAttribValue(SA_ID);
}
else {
- String qname = constraint.getQualifiedName().replace("::", ".");
+ String qname = constraint.getQualifiedName().replace("::", DPT);
id = qname;
}
- implementingClass = parentCategory.getID() + "." + this.getName() + "Constraint";
+ implementingClass = CONSTRAINT_PKG + DPT + this.getName() + CONSTRAINT_POSTFIX;
// unused
// this.contextID = parentCategory.getID();
diff --git a/extraplugins/dsml.validation/org.eclipse.papyrus.dsml.validation.model/src/org/eclipse/papyrus/dsml/validation/model/profilenames/Utils.java b/extraplugins/dsml.validation/org.eclipse.papyrus.dsml.validation.model/src/org/eclipse/papyrus/dsml/validation/model/profilenames/Utils.java
index 8ae1570fecc..88d2047ac68 100644
--- a/extraplugins/dsml.validation/org.eclipse.papyrus.dsml.validation.model/src/org/eclipse/papyrus/dsml/validation/model/profilenames/Utils.java
+++ b/extraplugins/dsml.validation/org.eclipse.papyrus.dsml.validation.model/src/org/eclipse/papyrus/dsml/validation/model/profilenames/Utils.java
@@ -15,9 +15,12 @@ package org.eclipse.papyrus.dsml.validation.model.profilenames;
import java.util.HashMap;
import java.util.Map;
+import org.eclipse.papyrus.uml.tools.utils.PackageUtil;
import org.eclipse.uml2.uml.Constraint;
import org.eclipse.uml2.uml.Namespace;
import org.eclipse.uml2.uml.OpaqueExpression;
+import org.eclipse.uml2.uml.Package;
+import org.eclipse.uml2.uml.Profile;
import org.eclipse.uml2.uml.Stereotype;
import org.eclipse.uml2.uml.ValueSpecification;
@@ -28,8 +31,21 @@ import org.eclipse.uml2.uml.ValueSpecification;
*/
public class Utils {
+ private static final String DOT = "."; //$NON-NLS-1$
private static final String JAVA_LANGUAGE = "JAVA"; //$NON-NLS-1$
private static final String OCL_LANGUAGE = "OCL"; //$NON-NLS-1$
+
+ /**
+ * qualified name of EPackage stereotype (used for static profile detection)
+ */
+ public static final String EPackage_QNAME = "Ecore::EPackage"; //$NON-NLS-1$
+ /**
+ * Attributes of EPackage stereotype
+ */
+ private static final String EPKG_BASE_PACKAGE = "basePackage"; //$NON-NLS-1$
+ private static final String EPKG_PACKAGE_NAME = "packageName"; //$NON-NLS-1$
+
+
/*
* Map holding relations between String representing the qualified name of a
* constraint and name of a package to which it belongs. Package name in
@@ -104,7 +120,23 @@ public class Utils {
Namespace nameSpace = constraint.getContext();
if (nameSpace instanceof Stereotype) {
- return ((Stereotype) constraint.getContext()).getQualifiedName();
+ Package profilePkg = PackageUtil.getRootPackage(constraint.getContext());
+ if (profilePkg instanceof Profile) {
+ Profile profile = (Profile) profilePkg;
+ Stereotype ePkg = profile.getAppliedStereotype(EPackage_QNAME);
+ String base = (String) profile.getValue(ePkg, EPKG_BASE_PACKAGE);
+ if (base != null) {
+ String pkgName = (String) profile.getValue(ePkg, EPKG_PACKAGE_NAME);
+ if (pkgName != null) {
+ return base + DOT + pkgName + DOT + nameSpace.getName();
+ }
+ else {
+ return base + DOT + nameSpace.getQualifiedName();
+ }
+ }
+ }
+ // Stereotype ePackage = umlProfile.getAppliedStereotype(EPackage_QNAME);
+ return nameSpace.getQualifiedName();
}
return ""; //$NON-NLS-1$
}
@@ -227,5 +259,15 @@ public class Utils {
pluginID = ID;
}
+ public static boolean isStaticProfile() {
+ return staticProfile;
+ }
+
+ public static void setStaticProfile(boolean staticProfile) {
+ Utils.staticProfile = staticProfile;
+ }
+
private static String pluginID;
+
+ private static boolean staticProfile;
}
diff --git a/extraplugins/dsml.validation/org.eclipse.papyrus.dsml.validation.wizard/src/org/eclipse/papyrus/dsml/validation/wizard/CreateEMFValidationProject.java b/extraplugins/dsml.validation/org.eclipse.papyrus.dsml.validation.wizard/src/org/eclipse/papyrus/dsml/validation/wizard/CreateEMFValidationProject.java
index 25846075c06..09d3f0e6d59 100644
--- a/extraplugins/dsml.validation/org.eclipse.papyrus.dsml.validation.wizard/src/org/eclipse/papyrus/dsml/validation/wizard/CreateEMFValidationProject.java
+++ b/extraplugins/dsml.validation/org.eclipse.papyrus.dsml.validation.wizard/src/org/eclipse/papyrus/dsml/validation/wizard/CreateEMFValidationProject.java
@@ -13,7 +13,6 @@
package org.eclipse.papyrus.dsml.validation.wizard;
import org.eclipse.core.resources.IProject;
-import org.eclipse.core.resources.IResource;
import org.eclipse.emf.ecore.EPackage;
import org.eclipse.jface.wizard.IWizardPage;
import org.eclipse.jface.wizard.WizardDialog;
@@ -39,10 +38,12 @@ public class CreateEMFValidationProject extends NewPluginProjectWizard {
private JavaContentGenerator generateAllJava;
- private Profile selectedProfile;
+ protected Profile selectedProfile;
- private EPackage definition = null;
+ protected EPackage definition = null;
+ protected IProject createdProject;
+
/**
*
* Constructor.
@@ -56,6 +57,7 @@ public class CreateEMFValidationProject extends NewPluginProjectWizard {
this.constraintsManager = constraintsExtractor;
this.selectedProfile = selectedProfile;
this.definition = definition;
+ createdProject = null;
}
@Override
@@ -72,34 +74,26 @@ public class CreateEMFValidationProject extends NewPluginProjectWizard {
}
/**
+ * @return The project created by this wizard
+ */
+ public IProject getProject() {
+ return createdProject;
+ }
+
+ /**
* run the dialog
*/
- public void openDialog() {
+ public int openDialog() {
WizardDialog dialog = new WizardDialog(Display.getDefault().getActiveShell(), this);
- dialog.open();
+ return dialog.open();
}
@Override
public boolean performFinish() {
boolean result = super.performFinish();
if (result) {
- IProject project = this.fMainPage.getProjectHandle();
- try {
-
- // generate java code
- generateAllJava = new JavaContentGenerator(project, selectedProfile);
- generateAllJava.run();
- // generate plugin + extension point
- ValidationPluginGenerator.instance.generate(project, constraintsManager, definition);
-
-
- project.refreshLocal(IResource.DEPTH_INFINITE, null);
- } catch (Exception e) {
- e.printStackTrace();
- }
+ createdProject = this.fMainPage.getProjectHandle();
}
-
return result;
}
-
}
diff --git a/extraplugins/dsml.validation/org.eclipse.papyrus.dsml.validation.wizard/src/org/eclipse/papyrus/dsml/validation/wizard/JavaContentGenerator.java b/extraplugins/dsml.validation/org.eclipse.papyrus.dsml.validation.wizard/src/org/eclipse/papyrus/dsml/validation/wizard/JavaContentGenerator.java
index 948cd380adf..fc492ea21f4 100644
--- a/extraplugins/dsml.validation/org.eclipse.papyrus.dsml.validation.wizard/src/org/eclipse/papyrus/dsml/validation/wizard/JavaContentGenerator.java
+++ b/extraplugins/dsml.validation/org.eclipse.papyrus.dsml.validation.wizard/src/org/eclipse/papyrus/dsml/validation/wizard/JavaContentGenerator.java
@@ -25,6 +25,7 @@ import org.eclipse.jface.operation.IRunnableWithProgress;
import org.eclipse.papyrus.dsml.validation.model.profilenames.Utils;
import org.eclipse.ui.PlatformUI;
import org.eclipse.uml2.uml.Profile;
+import org.eclipse.uml2.uml.Stereotype;
/**
* this class generate java classes in the project
@@ -40,13 +41,6 @@ public class JavaContentGenerator {
protected Profile umlProfile;
private IProject project;
-
- /**
- * The source folder for the generated file. Ideally, it should be changed from "src" to "src-gen", but the
- * PluginGenerator currently does not support setting up the class path within the generated plugin
- * appropriately.
- */
- public static final String srcFolder = "src"; //$NON-NLS-1$
/**
*
@@ -62,25 +56,42 @@ public class JavaContentGenerator {
this.umlProfile = umlProfile;
}
+ class RunClassGenerator implements IRunnableWithProgress {
+
+ private RuntimeException storedException = null;
+
+ public RuntimeException getException() {
+ return storedException;
+ }
+
+ public void run(IProgressMonitor monitor) {
+ try {
+ // static profile apply the EPackage stereotype
+ Stereotype ePackage = umlProfile.getAppliedStereotype(Utils.EPackage_QNAME);
+ Utils.setStaticProfile(ePackage != null);
+ Utils.setPluginID(project.getName());
+ ClassesGenerator generator = new ClassesGenerator(umlProfile.eResource(), project);
+ generator.doGenerate(monitor);
+ } catch (IOException e) {
+ IStatus status = new Status(IStatus.ERROR, Activator.PLUGIN_ID, e.getMessage(), e);
+ Activator.getDefault().getLog().log(status);
+ } catch (RuntimeException e) {
+ storedException = e;
+ }
+ }
+ }
+
/**
* launch the generation of the content
*/
public void run() {
- IRunnableWithProgress operation = new IRunnableWithProgress() {
- public void run(IProgressMonitor monitor) {
- try {
- Utils.setPluginID(project.getName());
- ClassesGenerator generator = new ClassesGenerator(umlProfile.eResource(), project);
- generator.doGenerate(monitor);
- } catch (IOException e) {
- IStatus status = new Status(IStatus.ERROR, Activator.PLUGIN_ID, e.getMessage(), e);
- Activator.getDefault().getLog().log(status);
- }
- }
- };
+ RunClassGenerator operation = new RunClassGenerator();
try {
- // don't fork (avoid dirty state of MANIFEST which is automatically openend by NewWizard)
+ // don't fork (avoid dirty state of MANIFEST which is automatically opened by NewWizard)
PlatformUI.getWorkbench().getProgressService().run(false, true, operation);
+ if (operation.getException() != null) {
+ throw operation.getException();
+ }
} catch (InvocationTargetException e) {
IStatus status = new Status(IStatus.ERROR, Activator.PLUGIN_ID, e.getMessage(), e);
Activator.getDefault().getLog().log(status);
diff --git a/extraplugins/dsml.validation/org.eclipse.papyrus.dsml.validation.wizard/src/org/eclipse/papyrus/dsml/validation/wizard/ValidationPluginGenerator.java b/extraplugins/dsml.validation/org.eclipse.papyrus.dsml.validation.wizard/src/org/eclipse/papyrus/dsml/validation/wizard/ValidationPluginGenerator.java
index 0ffaedb1b67..8ad7691dbc6 100644
--- a/extraplugins/dsml.validation/org.eclipse.papyrus.dsml.validation.wizard/src/org/eclipse/papyrus/dsml/validation/wizard/ValidationPluginGenerator.java
+++ b/extraplugins/dsml.validation/org.eclipse.papyrus.dsml.validation.wizard/src/org/eclipse/papyrus/dsml/validation/wizard/ValidationPluginGenerator.java
@@ -28,6 +28,7 @@ import org.eclipse.emf.ecore.EPackage;
import org.eclipse.papyrus.customization.plugin.PluginEditor;
import org.eclipse.papyrus.dsml.validation.PapyrusDSMLValidationRule.MessageHandling;
import org.eclipse.papyrus.dsml.validation.PapyrusDSMLValidationRule.NameBasedMsgMode;
+import org.eclipse.papyrus.dsml.validation.generator.xtend.Generate;
import org.eclipse.papyrus.dsml.validation.model.elements.interfaces.Category;
import org.eclipse.papyrus.dsml.validation.model.elements.interfaces.IConstraintProvider;
import org.eclipse.papyrus.dsml.validation.model.elements.interfaces.IConstraintsCategory;
@@ -106,7 +107,7 @@ public class ValidationPluginGenerator {
// A generated plugin will depend on the validation profile, since it typically contains the profile as well.
// [well, that's not always the case]
- private static final String UML_VALIDATION_PROFILE_PLUGIN = "org.eclipse.papyrus.dsml.validation"; //$NON-NLS-1$
+ public static final String UML_DSML_VALIDATION_PROFILE_PLUGIN = "org.eclipse.papyrus.dsml.validation"; //$NON-NLS-1$
/**
* singleton
@@ -126,13 +127,13 @@ public class ValidationPluginGenerator {
* @throws CoreException
* @throws IOException
*/
- public boolean addDSMLdependency(IProject project) throws CoreException, IOException {
+ public boolean addDependency(IProject project, String pluginName) throws CoreException, IOException {
- if ((project != null) && project.exists()) {
+ if ((project != null) && project.exists() && !pluginName.equals(project.getName())) {
ManifestEditor manifest = new ManifestEditor(project);
manifest.init();
- if (manifest.initOk() && !manifest.hasDependency(UML_VALIDATION_PROFILE_PLUGIN)) {
- manifest.addDependency(UML_VALIDATION_PROFILE_PLUGIN);
+ if (manifest.initOk() && !manifest.hasDependency(pluginName)) {
+ manifest.addDependency(pluginName);
manifest.save();
return true;
}
@@ -161,7 +162,7 @@ public class ValidationPluginGenerator {
// prepare the plugin
editor = new PluginEditor(project);
- editor.registerSourceFolder(JavaContentGenerator.srcFolder);
+ editor.registerSourceFolder(Generate.SRC);
// it's possible that editor.getManifestEditor() logs an exception due to resource out of sync.
String pluginID = editor.getSymbolicBundleName();
if (editor.getBundleName() == null) {

Back to the top