Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAnsgar Radermacher2015-02-06 06:44:55 -0500
committerAnsgar Radermacher2015-02-06 10:04:31 -0500
commitca450e641d4e7839f3ca6be932beab1d50be87f1 (patch)
treef124d750319461ec2f8e45a72477ab357cc67d0c
parentb3c987478d78eb87a023ce621daccca33065d454 (diff)
downloadorg.eclipse.papyrus-ca450e641d4e7839f3ca6be932beab1d50be87f1.tar.gz
org.eclipse.papyrus-ca450e641d4e7839f3ca6be932beab1d50be87f1.tar.xz
org.eclipse.papyrus-ca450e641d4e7839f3ca6be932beab1d50be87f1.zip
458433 - [Papyrus DSML Validation] org.eclipse.papyrus.dsml.validation should be part of the core papyrus
-rw-r--r--extraplugins/dsml.validation/org.eclipse.papyrus.dsml.validation.model.ui/src/org/eclipse/papyrus/dsml/validation/generation/ui/CreateJavaValidationPluginHandler.java19
-rw-r--r--extraplugins/dsml.validation/org.eclipse.papyrus.dsml.validation.model.ui/src/org/eclipse/papyrus/dsml/validation/generation/ui/Messages.java2
-rw-r--r--extraplugins/dsml.validation/org.eclipse.papyrus.dsml.validation.model.ui/src/org/eclipse/papyrus/dsml/validation/generation/ui/messages.properties2
-rw-r--r--extraplugins/dsml.validation/org.eclipse.papyrus.dsml.validation.wizard/src/org/eclipse/papyrus/dsml/validation/wizard/ValidationPluginGenerator.java46
-rw-r--r--plugins/customization/org.eclipse.papyrus.customization/src/org/eclipse/papyrus/customization/plugin/PluginEditor.java10
-rw-r--r--plugins/infra/org.eclipse.papyrus.eclipse.project.editors/src/org/eclipse/papyrus/eclipse/project/editors/file/ManifestEditor.java12
-rw-r--r--plugins/infra/org.eclipse.papyrus.eclipse.project.editors/src/org/eclipse/papyrus/eclipse/project/editors/interfaces/IManifestEditor.java10
7 files changed, 92 insertions, 9 deletions
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 7e7c9103f2a..035c06912b5 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
@@ -12,6 +12,8 @@
*****************************************************************************/
package org.eclipse.papyrus.dsml.validation.generation.ui;
+import java.io.IOException;
+
import org.eclipse.core.commands.AbstractHandler;
import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.core.commands.ExecutionException;
@@ -19,6 +21,7 @@ import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.resources.IWorkspaceRoot;
import org.eclipse.core.resources.ResourcesPlugin;
+import org.eclipse.core.runtime.CoreException;
import org.eclipse.emf.common.util.URI;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecore.EPackage;
@@ -126,6 +129,8 @@ public class CreateJavaValidationPluginHandler extends AbstractHandler {
if (uri.segmentCount() >= 2) {
existingProject = root.getProject(uri.segment(1));
}
+ IProject hostingProject = existingProject;
+
int question = 0;
Shell shell = Display.getDefault().getActiveShell();
if ((existingProject != null) && existingProject.exists()) {
@@ -166,6 +171,7 @@ public class CreateJavaValidationPluginHandler extends AbstractHandler {
// 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);
@@ -174,6 +180,12 @@ public class CreateJavaValidationPluginHandler extends AbstractHandler {
}
else if (question == 0) {
+ try {
+ addDependencyToHostingProject(shell, hostingProject);
+ } 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();
}
@@ -181,6 +193,13 @@ public class CreateJavaValidationPluginHandler extends AbstractHandler {
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()));
+ }
+ }
+
@Override
public boolean isEnabled() {
EObject eObject = getSelectedElement();
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 7893bc039e4..eb9fa457e06 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
@@ -24,6 +24,8 @@ public class Messages extends NLS {
public static String CreateJavaValidationPluginHandler_CheckErrorLog;
public static String CreateJavaValidationPluginHandler_ChoosePluginGeneration;
public static String CreateJavaValidationPluginHandler_CreateNewPlugin;
+ public static String CreateJavaValidationPluginHandler_DependencyAdded;
+ public static String CreateJavaValidationPluginHandler_DependencyAddedMsg;
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 28c8a85b6e5..e4a290ae752 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
@@ -1,6 +1,8 @@
CreateJavaValidationPluginHandler_CheckErrorLog=An exception occured during plugin generation. Please check the error log.
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_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.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 925168e65dd..780ec9f136a 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
@@ -32,6 +32,7 @@ import org.eclipse.papyrus.dsml.validation.model.elements.interfaces.IConstraint
import org.eclipse.papyrus.dsml.validation.model.elements.interfaces.IConstraintsManager;
import org.eclipse.papyrus.dsml.validation.model.elements.interfaces.IValidationRule;
import org.eclipse.papyrus.dsml.validation.model.profilenames.Utils;
+import org.eclipse.papyrus.eclipse.project.editors.file.ManifestEditor;
import org.eclipse.papyrus.eclipse.project.editors.interfaces.IPluginProjectEditor;
import org.eclipse.uml2.uml.Constraint;
import org.eclipse.uml2.uml.Stereotype;
@@ -88,9 +89,13 @@ public class ValidationPluginGenerator {
private static final String UML_PLUGIN = "org.eclipse.uml2.uml"; //$NON-NLS-1$
private static final String EMF_VALIDATION_PLUGIN = "org.eclipse.emf.validation"; //$NON-NLS-1$
-
+
private static final String UML_VALIDATION_PLUGIN = "org.eclipse.papyrus.uml.service.validation"; //$NON-NLS-1$
+ // 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$
+
private static final String UML_URL = "http://www.eclipse.org/uml2/5.0.0/UML"; //$NON-NLS-1$
@@ -104,21 +109,45 @@ public class ValidationPluginGenerator {
private IConstraintsManager constraintsManager;
/**
- * generate the java code form constraints contained in the profile
+ * Add a dependency to the plugin hosting the DSML profile.
+ *
+ * @param project
+ * The Eclipse project
+ * @return true, if dependency has been added
+ * @throws CoreException
+ * @throws IOException
+ */
+ public boolean addDSMLdependency(IProject project) throws
+ CoreException, IOException {
+
+ if ((project != null) && project.exists()) {
+ ManifestEditor manifest = new ManifestEditor(project);
+ manifest.init();
+ if (manifest.initOk() && !manifest.hasDependency(UML_VALIDATION_PROFILE_PLUGIN)) {
+ manifest.addDependency(UML_VALIDATION_PROFILE_PLUGIN);
+ manifest.save();
+ return true;
+ }
+ }
+ return false;
+ }
+
+ /**
+ * Generate the java code form constraints contained in the profile
*
* @param project
- * the project eclipse
- * @param wizard
- * the ref to to wizard
+ * the Eclipse project
* @param constraintsManager
* the class in charge to collect all information from the model
+ * @param definition
+ * The definition of the profile for which a plugin is generated
* @throws CoreException
* @throws IOException
* @throws SAXException
* @throws ParserConfigurationException
*/
- public void generate(IProject project, IConstraintsManager constraintsManager, EPackage definition) throws CoreException,
- IOException, SAXException, ParserConfigurationException {
+ public void generate(IProject project, IConstraintsManager constraintsManager, EPackage definition) throws
+ CoreException, IOException, SAXException, ParserConfigurationException {
PluginEditor editor;
this.constraintsManager = constraintsManager;
@@ -141,7 +170,7 @@ public class ValidationPluginGenerator {
editor.getManifestEditor().addDependency(EMF_VALIDATION_PLUGIN);
editor.getManifestEditor().addDependency(UML_VALIDATION_PLUGIN);
editor.getManifestEditor().addDependency(UML_PLUGIN);
-
+
Element constraintProviderExtension =
createOrCleanExtension(editor, EMF_VALIDATION_CONSTRAINT_PROVIDERS_EXTENSIONPOINT);
@@ -309,6 +338,7 @@ public class ValidationPluginGenerator {
* @param constraintProvider
* @param parentElement
* @param editor
+ * @param definition
* @return the extension point
*/
@SuppressWarnings("nls")
diff --git a/plugins/customization/org.eclipse.papyrus.customization/src/org/eclipse/papyrus/customization/plugin/PluginEditor.java b/plugins/customization/org.eclipse.papyrus.customization/src/org/eclipse/papyrus/customization/plugin/PluginEditor.java
index 028a0e3073b..d35c703017c 100644
--- a/plugins/customization/org.eclipse.papyrus.customization/src/org/eclipse/papyrus/customization/plugin/PluginEditor.java
+++ b/plugins/customization/org.eclipse.papyrus.customization/src/org/eclipse/papyrus/customization/plugin/PluginEditor.java
@@ -76,6 +76,16 @@ public class PluginEditor extends PluginProjectEditor implements IPluginProjectE
manifest.addDependency(dependency, version);
}
+ /**
+ * @see org.eclipse.papyrus.eclipse.project.editors.interfaces.IManifestEditor#hasDependency(java.lang.String)
+ *
+ * @param dependency
+ * @return
+ */
+ public boolean hasDependency(String dependency) {
+ return manifest.hasDependency(dependency);
+ }
+
public void setValue(String key, String value) {
manifest.setValue(key, value);
}
diff --git a/plugins/infra/org.eclipse.papyrus.eclipse.project.editors/src/org/eclipse/papyrus/eclipse/project/editors/file/ManifestEditor.java b/plugins/infra/org.eclipse.papyrus.eclipse.project.editors/src/org/eclipse/papyrus/eclipse/project/editors/file/ManifestEditor.java
index 0f921bbf5e9..1c67da07c9f 100644
--- a/plugins/infra/org.eclipse.papyrus.eclipse.project.editors/src/org/eclipse/papyrus/eclipse/project/editors/file/ManifestEditor.java
+++ b/plugins/infra/org.eclipse.papyrus.eclipse.project.editors/src/org/eclipse/papyrus/eclipse/project/editors/file/ManifestEditor.java
@@ -147,6 +147,18 @@ public class ManifestEditor extends ProjectEditor implements IManifestEditor {
this.manifest.getMainAttributes().put(rqBundle, requireBundle);
}
+ /**
+ *
+ * @see org.eclipse.papyrus.eclipse.project.editors.interfaces.IManifestEditor#hasDependency(java.lang.String)
+ *
+ * {@inheritDoc}
+ */
+ public boolean hasDependency(final String dependency) {
+ final Name rqBundle = new Name(REQUIRED_BUNDLE);
+ String requireBundle = this.manifest.getMainAttributes().getValue(rqBundle);
+ return (requireBundle != null) && requireBundle.contains(dependency);
+ }
+
public void setDependenciesVersion(final String dependencyPattern, final String newVersion) {
final Name rqBundle = new Name(REQUIRED_BUNDLE);
final String requireBundles = this.manifest.getMainAttributes().getValue(rqBundle);
diff --git a/plugins/infra/org.eclipse.papyrus.eclipse.project.editors/src/org/eclipse/papyrus/eclipse/project/editors/interfaces/IManifestEditor.java b/plugins/infra/org.eclipse.papyrus.eclipse.project.editors/src/org/eclipse/papyrus/eclipse/project/editors/interfaces/IManifestEditor.java
index 0d05b57b7c0..a471b67f5c6 100644
--- a/plugins/infra/org.eclipse.papyrus.eclipse.project.editors/src/org/eclipse/papyrus/eclipse/project/editors/interfaces/IManifestEditor.java
+++ b/plugins/infra/org.eclipse.papyrus.eclipse.project.editors/src/org/eclipse/papyrus/eclipse/project/editors/interfaces/IManifestEditor.java
@@ -51,13 +51,14 @@ public interface IManifestEditor extends IProjectEditor, IFileEditor {
public static final String BUNDLE_LOCALIZATION = "Bundle-Localization"; //$NON-NLS-1$
/**
- *
+ * Add a dependency to the MANIFEST
* @param dependency
* the dependency to add
*/
public void addDependency(final String dependency);
/**
+ * Add a specific version of a dependency to the MANIFEST
*
* @param dependency
* the dependency to add
@@ -66,6 +67,13 @@ public interface IManifestEditor extends IProjectEditor, IFileEditor {
*/
public void addDependency(final String dependency, final String version);
+ /**
+ * Check whether a dependency is already present in the MANIFEST
+ *
+ * @param dependency
+ * the dependency to check
+ */
+ public boolean hasDependency(final String dependency);
/**
*

Back to the top