From e05d519880a8b1eda4601c4cbf975eedaedcac80 Mon Sep 17 00:00:00 2001 From: jcadavid Date: Tue, 15 Apr 2014 15:41:09 +0200 Subject: Plug-in containing customized MWE2 components for common use. Initially: -QvtoTransformationWorkflowComponent -RegisterUmlProfileComponent Change-Id: I3d986a25a2e53682b7cb0fda0a2a1ef279749029 Signed-off-by: jcadavid --- .../org.eclipse.papyrus.mwe2.utils/.classpath | 7 + .../org.eclipse.papyrus.mwe2.utils/.project | 34 +++++ .../.settings/org.eclipse.core.resources.prefs | 2 + .../.settings/org.eclipse.jdt.core.prefs | 7 + .../META-INF/MANIFEST.MF | 17 +++ .../OSGI-INF/l10n/bundle.properties | 3 + .../org.eclipse.papyrus.mwe2.utils/about.html | 28 ++++ .../build.properties | 7 + .../org/eclipse/papyrus/mwe2/utils/Activator.java | 40 ++++++ .../QvtoTransformationWorkflowComponent.java | 146 +++++++++++++++++++++ .../components/RegisterUmlProfileComponent.java | 73 +++++++++++ .../papyrus/mwe2/utils/messages/Messages.java | 27 ++++ .../mwe2/utils/messages/messages.properties | 6 + 13 files changed, 397 insertions(+) create mode 100644 plugins/developer/org.eclipse.papyrus.mwe2.utils/.classpath create mode 100644 plugins/developer/org.eclipse.papyrus.mwe2.utils/.project create mode 100644 plugins/developer/org.eclipse.papyrus.mwe2.utils/.settings/org.eclipse.core.resources.prefs create mode 100644 plugins/developer/org.eclipse.papyrus.mwe2.utils/.settings/org.eclipse.jdt.core.prefs create mode 100644 plugins/developer/org.eclipse.papyrus.mwe2.utils/META-INF/MANIFEST.MF create mode 100644 plugins/developer/org.eclipse.papyrus.mwe2.utils/OSGI-INF/l10n/bundle.properties create mode 100644 plugins/developer/org.eclipse.papyrus.mwe2.utils/about.html create mode 100644 plugins/developer/org.eclipse.papyrus.mwe2.utils/build.properties create mode 100644 plugins/developer/org.eclipse.papyrus.mwe2.utils/src/org/eclipse/papyrus/mwe2/utils/Activator.java create mode 100644 plugins/developer/org.eclipse.papyrus.mwe2.utils/src/org/eclipse/papyrus/mwe2/utils/components/QvtoTransformationWorkflowComponent.java create mode 100644 plugins/developer/org.eclipse.papyrus.mwe2.utils/src/org/eclipse/papyrus/mwe2/utils/components/RegisterUmlProfileComponent.java create mode 100644 plugins/developer/org.eclipse.papyrus.mwe2.utils/src/org/eclipse/papyrus/mwe2/utils/messages/Messages.java create mode 100644 plugins/developer/org.eclipse.papyrus.mwe2.utils/src/org/eclipse/papyrus/mwe2/utils/messages/messages.properties diff --git a/plugins/developer/org.eclipse.papyrus.mwe2.utils/.classpath b/plugins/developer/org.eclipse.papyrus.mwe2.utils/.classpath new file mode 100644 index 00000000000..8a8f1668cdc --- /dev/null +++ b/plugins/developer/org.eclipse.papyrus.mwe2.utils/.classpath @@ -0,0 +1,7 @@ + + + + + + + diff --git a/plugins/developer/org.eclipse.papyrus.mwe2.utils/.project b/plugins/developer/org.eclipse.papyrus.mwe2.utils/.project new file mode 100644 index 00000000000..020a0c5a318 --- /dev/null +++ b/plugins/developer/org.eclipse.papyrus.mwe2.utils/.project @@ -0,0 +1,34 @@ + + + org.eclipse.papyrus.mwe2.utils + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.pde.ManifestBuilder + + + + + org.eclipse.pde.SchemaBuilder + + + + + org.eclipse.pde.api.tools.apiAnalysisBuilder + + + + + + org.eclipse.pde.PluginNature + org.eclipse.jdt.core.javanature + org.eclipse.pde.api.tools.apiAnalysisNature + + diff --git a/plugins/developer/org.eclipse.papyrus.mwe2.utils/.settings/org.eclipse.core.resources.prefs b/plugins/developer/org.eclipse.papyrus.mwe2.utils/.settings/org.eclipse.core.resources.prefs new file mode 100644 index 00000000000..daf82ed330d --- /dev/null +++ b/plugins/developer/org.eclipse.papyrus.mwe2.utils/.settings/org.eclipse.core.resources.prefs @@ -0,0 +1,2 @@ +eclipse.preferences.version=1 +encoding//src/org/eclipse/papyrus/mwe2/utils/messages/messages.properties=ISO-8859-1 diff --git a/plugins/developer/org.eclipse.papyrus.mwe2.utils/.settings/org.eclipse.jdt.core.prefs b/plugins/developer/org.eclipse.papyrus.mwe2.utils/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 00000000000..f287d53cf45 --- /dev/null +++ b/plugins/developer/org.eclipse.papyrus.mwe2.utils/.settings/org.eclipse.jdt.core.prefs @@ -0,0 +1,7 @@ +eclipse.preferences.version=1 +org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled +org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6 +org.eclipse.jdt.core.compiler.compliance=1.6 +org.eclipse.jdt.core.compiler.problem.assertIdentifier=error +org.eclipse.jdt.core.compiler.problem.enumIdentifier=error +org.eclipse.jdt.core.compiler.source=1.6 diff --git a/plugins/developer/org.eclipse.papyrus.mwe2.utils/META-INF/MANIFEST.MF b/plugins/developer/org.eclipse.papyrus.mwe2.utils/META-INF/MANIFEST.MF new file mode 100644 index 00000000000..39d8ad7bf12 --- /dev/null +++ b/plugins/developer/org.eclipse.papyrus.mwe2.utils/META-INF/MANIFEST.MF @@ -0,0 +1,17 @@ +Manifest-Version: 1.0 +Bundle-ManifestVersion: 2 +Bundle-Name: %Bundle-Name +Bundle-SymbolicName: org.eclipse.papyrus.mwe2.utils +Bundle-Version: 1.0.0.qualifier +Bundle-Activator: org.eclipse.papyrus.mwe2.utils.Activator +Require-Bundle: org.eclipse.core.runtime, + org.eclipse.emf.mwe.core, + org.eclipse.uml2.uml, + org.apache.commons.logging, + org.eclipse.m2m.qvt.oml +Bundle-RequiredExecutionEnvironment: JavaSE-1.6 +Bundle-ActivationPolicy: lazy +Export-Package: org.eclipse.papyrus.mwe2.utils, + org.eclipse.papyrus.mwe2.utils.components, + org.eclipse.papyrus.mwe2.utils.messages +Bundle-Vendor: %Bundle-Vendor diff --git a/plugins/developer/org.eclipse.papyrus.mwe2.utils/OSGI-INF/l10n/bundle.properties b/plugins/developer/org.eclipse.papyrus.mwe2.utils/OSGI-INF/l10n/bundle.properties new file mode 100644 index 00000000000..7ef28ac1e98 --- /dev/null +++ b/plugins/developer/org.eclipse.papyrus.mwe2.utils/OSGI-INF/l10n/bundle.properties @@ -0,0 +1,3 @@ +#Properties file for org.eclipse.papyrus.mwe2.utils +Bundle-Name = MWE2 custom components for modeling workflows +Bundle-Vendor = Eclipse Modeling Project \ No newline at end of file diff --git a/plugins/developer/org.eclipse.papyrus.mwe2.utils/about.html b/plugins/developer/org.eclipse.papyrus.mwe2.utils/about.html new file mode 100644 index 00000000000..82d49bf5f81 --- /dev/null +++ b/plugins/developer/org.eclipse.papyrus.mwe2.utils/about.html @@ -0,0 +1,28 @@ + + + + +About + + +

About This Content

+ +

June 5, 2007

+

License

+ +

The Eclipse Foundation makes available all content in this plug-in ("Content"). Unless otherwise +indicated below, the Content is provided to you under the terms and conditions of the +Eclipse Public License Version 1.0 ("EPL"). A copy of the EPL is available +at http://www.eclipse.org/legal/epl-v10.html. +For purposes of the EPL, "Program" will mean the Content.

+ +

If you did not receive this Content directly from the Eclipse Foundation, the Content is +being redistributed by another party ("Redistributor") and different terms and conditions may +apply to your use of any object code in the Content. Check the Redistributor's license that was +provided with the Content. If no such license exists, contact the Redistributor. Unless otherwise +indicated below, the terms and conditions of the EPL still apply to any source code in the Content +and such source code may be obtained at http://www.eclipse.org.

+ + + diff --git a/plugins/developer/org.eclipse.papyrus.mwe2.utils/build.properties b/plugins/developer/org.eclipse.papyrus.mwe2.utils/build.properties new file mode 100644 index 00000000000..804b2d39ad6 --- /dev/null +++ b/plugins/developer/org.eclipse.papyrus.mwe2.utils/build.properties @@ -0,0 +1,7 @@ +source.. = src/ +output.. = bin/ +bin.includes = META-INF/,\ + .,\ + OSGI-INF/l10n/bundle.properties,\ + about.html +src.includes = about.html diff --git a/plugins/developer/org.eclipse.papyrus.mwe2.utils/src/org/eclipse/papyrus/mwe2/utils/Activator.java b/plugins/developer/org.eclipse.papyrus.mwe2.utils/src/org/eclipse/papyrus/mwe2/utils/Activator.java new file mode 100644 index 00000000000..e4a37634fd7 --- /dev/null +++ b/plugins/developer/org.eclipse.papyrus.mwe2.utils/src/org/eclipse/papyrus/mwe2/utils/Activator.java @@ -0,0 +1,40 @@ +/******************************************************************************* + * Copyright (c) 2014 CEA LIST. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Juan Cadavid implementation + ******************************************************************************/ +package org.eclipse.papyrus.mwe2.utils; + +import org.osgi.framework.BundleActivator; +import org.osgi.framework.BundleContext; + +public class Activator implements BundleActivator { + + private static BundleContext context; + + static BundleContext getContext() { + return context; + } + + /* + * (non-Javadoc) + * @see org.osgi.framework.BundleActivator#start(org.osgi.framework.BundleContext) + */ + public void start(BundleContext bundleContext) throws Exception { + Activator.context = bundleContext; + } + + /* + * (non-Javadoc) + * @see org.osgi.framework.BundleActivator#stop(org.osgi.framework.BundleContext) + */ + public void stop(BundleContext bundleContext) throws Exception { + Activator.context = null; + } + +} diff --git a/plugins/developer/org.eclipse.papyrus.mwe2.utils/src/org/eclipse/papyrus/mwe2/utils/components/QvtoTransformationWorkflowComponent.java b/plugins/developer/org.eclipse.papyrus.mwe2.utils/src/org/eclipse/papyrus/mwe2/utils/components/QvtoTransformationWorkflowComponent.java new file mode 100644 index 00000000000..a88492f94cc --- /dev/null +++ b/plugins/developer/org.eclipse.papyrus.mwe2.utils/src/org/eclipse/papyrus/mwe2/utils/components/QvtoTransformationWorkflowComponent.java @@ -0,0 +1,146 @@ +/******************************************************************************* + * Copyright (c) 2014 CEA LIST. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Juan Cadavid implementation + ******************************************************************************/ +package org.eclipse.papyrus.mwe2.utils.components; + +import java.io.File; +import java.io.IOException; +import java.util.ArrayList; +import java.util.List; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.eclipse.emf.common.util.Diagnostic; +import org.eclipse.emf.common.util.URI; +import org.eclipse.emf.ecore.EObject; +import org.eclipse.emf.mwe.core.WorkflowContext; +import org.eclipse.emf.mwe.core.issues.Issues; +import org.eclipse.emf.mwe.core.lib.AbstractWorkflowComponent; +import org.eclipse.emf.mwe.core.monitor.ProgressMonitor; +import org.eclipse.m2m.qvt.oml.BasicModelExtent; +import org.eclipse.m2m.qvt.oml.ExecutionContextImpl; +import org.eclipse.m2m.qvt.oml.ExecutionDiagnostic; +import org.eclipse.m2m.qvt.oml.ModelExtent; +import org.eclipse.m2m.qvt.oml.TransformationExecutor; +import org.eclipse.papyrus.mwe2.utils.messages.Messages; + +/** + * MWE Component to execute QVTO transformations. An example of use is: + *
+ * component = org.eclipse.papyrus.mwe.utils.components.QvtoTransformationWorkflowComponent { + inputSlots = 'inputGmfgen' + inputSlots = 'gmfgenUmlMetamodel' + transformationURI = 'platform:/resource/org.eclipse.papyrus.tests.framework/qvto/gmfgen2uml.qvto' + outputSlot = 'inputGmfgenUml' + } +
+ * where the multi-valued input slots are the input parameters for the transformation; + * there should be as many as there are declared in the qvto file; + * transformationURI is the location of the .qvto file and outputSlot the slot where + * the list of resulting eObjects of the transformation will be placed. + * + */ +public class QvtoTransformationWorkflowComponent extends + AbstractWorkflowComponent { + + private String transformationURI; + private String outputSlot; + private ArrayList inputSlots = new ArrayList(); + private Log log = LogFactory.getLog(getClass()); + + public String getTransformationURI() { + return transformationURI; + } + + public void setTransformationURI(String transformationURI) { + this.transformationURI = transformationURI; + } + + public String getOutputSlot() { + return outputSlot; + } + + public void setOutputSlot(String outputSlot) { + this.outputSlot = outputSlot; + } + + public boolean addInputSlots(String c) { + return inputSlots.add(c); + } + + public ExecutionDiagnostic generate(List inObjects, + URI transformationURI, WorkflowContext ctx, Issues issues) + throws IOException { + //resolveProxies(inObjects); + TransformationExecutor executor = new TransformationExecutor( + transformationURI); + Diagnostic loadTransformationDiagnostic = executor.loadTransformation(); + if (!loadTransformationDiagnostic.getMessage().equals("OK")) { //$NON-NLS-1$ + log.error(Messages.QvtoTransformationWorkflowComponent_1 + + loadTransformationDiagnostic); + return null; + } + ExecutionContextImpl context = new ExecutionContextImpl(); + ArrayList input = new ArrayList(); + for (EObject eObject : inObjects) { + BasicModelExtent basicModelExtent = new BasicModelExtent(); + basicModelExtent.add(eObject); + input.add(basicModelExtent); + } + issues.addInfo(new File("..").getAbsolutePath()); //$NON-NLS-1$ + ModelExtent output = new BasicModelExtent(); + input.add(output); + ModelExtent[] modelParameters = input.toArray(new ModelExtent[] {}); + context = new ExecutionContextImpl(); + context.setConfigProperty("keepModeling", true); //$NON-NLS-1$ + ExecutionDiagnostic result = executor.execute(context, modelParameters); + if (result.getSeverity() == Diagnostic.OK) { + List outObjects = output.getContents(); + ctx.set(getOutputSlot(), outObjects); + log.info(Messages.QvtoTransformationWorkflowComponent_4 + getTransformationURI()); + } else { + issues.addError(result.toString()); + } + return result; + } + + @Override + protected void invokeInternal(WorkflowContext ctx, ProgressMonitor monitor, + Issues issues) { + List inObjects = new ArrayList(); + for (String inputSlot : inputSlots) { + + Object inputObject = ctx.get(inputSlot); + if(inputObject instanceof EObject){ + inObjects.add((EObject) inputObject); + }else if(inputObject instanceof List){ + List list = (List) inputObject; + inObjects.add((EObject) list.get(0)); + } + } + try { + generate(inObjects, URI.createURI(transformationURI), + ctx, issues); + } catch (IOException e) { + log.error(e.getLocalizedMessage()); + } + + } + + @Override + public void checkConfiguration(Issues issues) { + if (inputSlots.isEmpty()) { + issues.addError(Messages.QvtoTransformationWorkflowComponent_5); + } + } + + + +} diff --git a/plugins/developer/org.eclipse.papyrus.mwe2.utils/src/org/eclipse/papyrus/mwe2/utils/components/RegisterUmlProfileComponent.java b/plugins/developer/org.eclipse.papyrus.mwe2.utils/src/org/eclipse/papyrus/mwe2/utils/components/RegisterUmlProfileComponent.java new file mode 100644 index 00000000000..26c2f305ee8 --- /dev/null +++ b/plugins/developer/org.eclipse.papyrus.mwe2.utils/src/org/eclipse/papyrus/mwe2/utils/components/RegisterUmlProfileComponent.java @@ -0,0 +1,73 @@ +/******************************************************************************* + * Copyright (c) 2014 CEA LIST. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Juan Cadavid implementation + ******************************************************************************/ +package org.eclipse.papyrus.mwe2.utils.components; + + +import org.apache.commons.logging.LogFactory; +import org.eclipse.emf.ecore.EObject; +import org.eclipse.emf.ecore.EPackage; +import org.eclipse.emf.mwe.core.WorkflowContext; +import org.eclipse.emf.mwe.core.issues.Issues; +import org.eclipse.emf.mwe.core.lib.AbstractWorkflowComponent; +import org.eclipse.emf.mwe.core.monitor.ProgressMonitor; +import org.eclipse.papyrus.mwe2.utils.messages.Messages; +import org.eclipse.uml2.uml.Profile; + +/** + * This MWE component registers the EPackage definition of a UML profile in the global EPackage registry. + * An example of its usage is: + *
+ * component = org.eclipse.papyrus.mwe.utils.components.RegisterUmlProfile { + profileSlot = 'ecoreprofile' + } +
+ * where profileSlot is a slot that contains the uml Profile object to register. + */ +public class RegisterUmlProfileComponent extends AbstractWorkflowComponent { + private org.apache.commons.logging.Log log = LogFactory.getLog(getClass()); + + + private String profileSlot; + + public String getProfileSlot() { + return profileSlot; + } + + public void setProfileSlot(String profileSlot) { + this.profileSlot = profileSlot; + } + + public void checkConfiguration(Issues issues) { + if(profileSlot == null || profileSlot.equals("")){ //$NON-NLS-1$ + issues.addError(Messages.RegisterUmlProfile_1); + } + } + + @Override + protected void invokeInternal(WorkflowContext ctx, ProgressMonitor monitor, + Issues issues) { + EObject eObject = (EObject) ctx.get(profileSlot); + if(!(eObject instanceof Profile)){ + log.error(Messages.RegisterUmlProfile_2); + return; + } + Profile profile = (Profile) eObject; + EPackage definition = profile.getDefinition(); + if(definition == null){ + log.error(Messages.RegisterUmlProfile_3); + return; + } + EPackage.Registry.INSTANCE.put(definition.getNsURI(), definition); + } + + + +} diff --git a/plugins/developer/org.eclipse.papyrus.mwe2.utils/src/org/eclipse/papyrus/mwe2/utils/messages/Messages.java b/plugins/developer/org.eclipse.papyrus.mwe2.utils/src/org/eclipse/papyrus/mwe2/utils/messages/Messages.java new file mode 100644 index 00000000000..99713cd0275 --- /dev/null +++ b/plugins/developer/org.eclipse.papyrus.mwe2.utils/src/org/eclipse/papyrus/mwe2/utils/messages/Messages.java @@ -0,0 +1,27 @@ +package org.eclipse.papyrus.mwe2.utils.messages; + +import org.eclipse.osgi.util.NLS; + +public class Messages extends NLS { + + private static final String BUNDLE_NAME = "org.eclipse.papyrus.mwe.utils.messages.messages"; //$NON-NLS-1$ + + public static String QvtoTransformationWorkflowComponent_1; + + public static String QvtoTransformationWorkflowComponent_4; + + public static String QvtoTransformationWorkflowComponent_5; + + public static String RegisterUmlProfile_1; + + public static String RegisterUmlProfile_2; + + public static String RegisterUmlProfile_3; + static { + // initialize resource bundle + NLS.initializeMessages(BUNDLE_NAME, Messages.class); + } + + private Messages() { + } +} diff --git a/plugins/developer/org.eclipse.papyrus.mwe2.utils/src/org/eclipse/papyrus/mwe2/utils/messages/messages.properties b/plugins/developer/org.eclipse.papyrus.mwe2.utils/src/org/eclipse/papyrus/mwe2/utils/messages/messages.properties new file mode 100644 index 00000000000..4b99391e951 --- /dev/null +++ b/plugins/developer/org.eclipse.papyrus.mwe2.utils/src/org/eclipse/papyrus/mwe2/utils/messages/messages.properties @@ -0,0 +1,6 @@ +QvtoTransformationWorkflowComponent_1=Error loading the model transformation: +QvtoTransformationWorkflowComponent_4=Successful QVTO transformation +QvtoTransformationWorkflowComponent_5=No input slots given for the QVTO transformation +RegisterUmlProfile_1=Profile URI not provided +RegisterUmlProfile_2=The profile URI does not contain a Profile object +RegisterUmlProfile_3=The profile has not been defined -- cgit v1.2.3