Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChristian W. Damus2017-01-20 16:49:39 +0000
committerChristian W. Damus2017-01-20 18:09:37 +0000
commit0c4038453caa5eea9cdb0f6413bf17078088a93c (patch)
treeeae80a68bca2857f0cb1aa39559238a3df3e7a99 /extraplugins
parent052ffacc3929a90173a7016eb5656320c5a31aa2 (diff)
downloadorg.eclipse.papyrus-0c4038453caa5eea9cdb0f6413bf17078088a93c.tar.gz
org.eclipse.papyrus-0c4038453caa5eea9cdb0f6413bf17078088a93c.tar.xz
org.eclipse.papyrus-0c4038453caa5eea9cdb0f6413bf17078088a93c.zip
Bug 505330: Unable to post-process imported/migrated RSA-RTE model with proprietary profiles
Add an optional transformation extension interface for a new post-processing phase invoked on the final imported model after stereotype repair but before it is finally saved. Also persist the basic import configuration parameters from either the simple dialog or the wizard in the workspace metadata area so that they will be the defaults for the next import. https://bugs.eclipse.org/bugs/show_bug.cgi?id=505330 (🍒-picked from streams/2.0-maintenance) Change-Id: I364023b4529fb46197da0702b6b52bd21c223cfd
Diffstat (limited to 'extraplugins')
-rw-r--r--extraplugins/migration/org.eclipse.papyrus.migration.rsa/META-INF/MANIFEST.MF1
-rw-r--r--extraplugins/migration/org.eclipse.papyrus.migration.rsa/src/org/eclipse/papyrus/migration/rsa/handler/ImportHandler.java12
-rw-r--r--extraplugins/migration/org.eclipse.papyrus.migration.rsa/src/org/eclipse/papyrus/migration/rsa/internal/ConfigurationManager.java97
-rw-r--r--extraplugins/migration/org.eclipse.papyrus.migration.rsa/src/org/eclipse/papyrus/migration/rsa/internal/extension/PostProcessExtension.java64
-rw-r--r--extraplugins/migration/org.eclipse.papyrus.migration.rsa/src/org/eclipse/papyrus/migration/rsa/internal/extension/TransformationExtension.java10
-rw-r--r--extraplugins/migration/org.eclipse.papyrus.migration.rsa/src/org/eclipse/papyrus/migration/rsa/transformation/ImportTransformation.java71
-rw-r--r--extraplugins/migration/org.eclipse.papyrus.migration.rsa/src/org/eclipse/papyrus/migration/rsa/transformation/ImportTransformationLauncher.java91
-rw-r--r--extraplugins/migration/org.eclipse.papyrus.migration.rsa/src/org/eclipse/papyrus/migration/rsa/wizard/TransformationWizard.java21
8 files changed, 331 insertions, 36 deletions
diff --git a/extraplugins/migration/org.eclipse.papyrus.migration.rsa/META-INF/MANIFEST.MF b/extraplugins/migration/org.eclipse.papyrus.migration.rsa/META-INF/MANIFEST.MF
index ab0e1b412b3..d1a8baae7f3 100644
--- a/extraplugins/migration/org.eclipse.papyrus.migration.rsa/META-INF/MANIFEST.MF
+++ b/extraplugins/migration/org.eclipse.papyrus.migration.rsa/META-INF/MANIFEST.MF
@@ -47,6 +47,7 @@ Export-Package: org.eclipse.papyrus.migration.rsa,
org.eclipse.papyrus.migration.rsa.diagramholder.impl,
org.eclipse.papyrus.migration.rsa.diagramholder.util,
org.eclipse.papyrus.migration.rsa.handler,
+ org.eclipse.papyrus.migration.rsa.internal;x-internal:=true,
org.eclipse.papyrus.migration.rsa.internal.extension,
org.eclipse.papyrus.migration.rsa.transformation,
org.eclipse.papyrus.migration.rsa.umlnotation,
diff --git a/extraplugins/migration/org.eclipse.papyrus.migration.rsa/src/org/eclipse/papyrus/migration/rsa/handler/ImportHandler.java b/extraplugins/migration/org.eclipse.papyrus.migration.rsa/src/org/eclipse/papyrus/migration/rsa/handler/ImportHandler.java
index 8c6cb049847..c12a9cb02b0 100644
--- a/extraplugins/migration/org.eclipse.papyrus.migration.rsa/src/org/eclipse/papyrus/migration/rsa/handler/ImportHandler.java
+++ b/extraplugins/migration/org.eclipse.papyrus.migration.rsa/src/org/eclipse/papyrus/migration/rsa/handler/ImportHandler.java
@@ -1,5 +1,5 @@
/*****************************************************************************
- * Copyright (c) 2013, 2014 CEA LIST.
+ * Copyright (c) 2013, 2017 CEA LIST, Christian W. Damus, and others.
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
@@ -8,6 +8,7 @@
*
* Contributors:
* Camille Letavernier (CEA LIST) camille.letavernier@cea.fr - Initial API and implementation
+ * Christian W. Damus - bug 505330
*****************************************************************************/
package org.eclipse.papyrus.migration.rsa.handler;
@@ -30,6 +31,7 @@ import org.eclipse.papyrus.infra.properties.ui.creation.PropertyEditorFactory;
import org.eclipse.papyrus.migration.rsa.Activator;
import org.eclipse.papyrus.migration.rsa.RSAToPapyrusParameters.Config;
import org.eclipse.papyrus.migration.rsa.RSAToPapyrusParameters.RSAToPapyrusParametersFactory;
+import org.eclipse.papyrus.migration.rsa.internal.ConfigurationManager;
import org.eclipse.papyrus.migration.rsa.transformation.ImportTransformationLauncher;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Shell;
@@ -54,7 +56,7 @@ public class ImportHandler extends AbstractHandler {
while (selectionIterator.hasNext()) {
Object selectedElement = selectionIterator.next();
if (selectedElement instanceof IAdaptable) {
- IFile selectedFile = (IFile) ((IAdaptable) selectedElement).getAdapter(IFile.class);
+ IFile selectedFile = ((IAdaptable) selectedElement).getAdapter(IFile.class);
if (selectedFile == null) {
continue;
}
@@ -110,6 +112,8 @@ public class ImportHandler extends AbstractHandler {
public Config getTransformationParameters(ExecutionEvent event) {
Config config = RSAToPapyrusParametersFactory.eINSTANCE.createConfig();
+ ConfigurationManager configMan = new ConfigurationManager();
+ configMan.loadConfig(config);
Shell activeShell = HandlerUtil.getActiveShell(event);
@@ -130,6 +134,7 @@ public class ImportHandler extends AbstractHandler {
Object result = factory.edit(activeShell, config);
if (!okPressed.get()) {
+ configMan.dispose();
return null;
}
@@ -138,6 +143,9 @@ public class ImportHandler extends AbstractHandler {
config = (Config) result;
}
+ configMan.saveConfig(config);
+ configMan.dispose();
+
return config;
}
diff --git a/extraplugins/migration/org.eclipse.papyrus.migration.rsa/src/org/eclipse/papyrus/migration/rsa/internal/ConfigurationManager.java b/extraplugins/migration/org.eclipse.papyrus.migration.rsa/src/org/eclipse/papyrus/migration/rsa/internal/ConfigurationManager.java
new file mode 100644
index 00000000000..61190a70444
--- /dev/null
+++ b/extraplugins/migration/org.eclipse.papyrus.migration.rsa/src/org/eclipse/papyrus/migration/rsa/internal/ConfigurationManager.java
@@ -0,0 +1,97 @@
+/*****************************************************************************
+ * Copyright (c) 2017 Christian W. Damus and others.
+ *
+ * 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:
+ * Christian W. Damus - Initial API and implementation
+ *
+ *****************************************************************************/
+
+package org.eclipse.papyrus.migration.rsa.internal;
+
+import java.io.IOException;
+
+import org.eclipse.emf.common.util.EList;
+import org.eclipse.emf.common.util.URI;
+import org.eclipse.emf.ecore.EObject;
+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.papyrus.infra.emf.utils.EMFHelper;
+import org.eclipse.papyrus.migration.rsa.Activator;
+import org.eclipse.papyrus.migration.rsa.RSAToPapyrusParameters.Config;
+import org.eclipse.papyrus.migration.rsa.RSAToPapyrusParameters.RSAToPapyrusParametersFactory;
+
+/**
+ * Persistence manager for the basic import configuration properties.
+ */
+public class ConfigurationManager {
+
+ private ResourceSet rset = new ResourceSetImpl();
+ private Resource configResource;
+ private Config config;
+
+ public ConfigurationManager() {
+ super();
+
+ // Load or create the configuration resource in the workspace metadata
+ URI configURI = URI.createFileURI(Activator.getDefault().getStateLocation().toOSString())
+ .appendSegment("config.xmi"); //$NON-NLS-1$
+ try {
+ configResource = rset.getResource(configURI, true);
+ } catch (Exception e) {
+ // Doesn't exist. Fine. We insist
+ configResource = rset.getResource(configURI, false);
+ }
+
+ // Get or create the configuration in the configuration resource
+ EList<EObject> contents = configResource.getContents();
+ if (!contents.isEmpty() && (contents.get(0) instanceof Config)) {
+ config = (Config) contents.get(0);
+ } else {
+ config = RSAToPapyrusParametersFactory.eINSTANCE.createConfig();
+ contents.clear();
+ contents.add(config);
+ }
+ }
+
+ public void dispose() {
+ config = null;
+ configResource = null;
+ EMFHelper.unload(rset);
+ }
+
+ public void loadConfig(Config config) {
+ EcoreUtil.Copier copier = new EcoreUtil.Copier() {
+ private static final long serialVersionUID = 1L;
+
+ @Override
+ protected EObject createCopy(EObject eObject) {
+ return (eObject == ConfigurationManager.this.config)
+ ? config
+ : super.createCopy(eObject);
+ }
+ };
+
+ copier.copy(this.config);
+ }
+
+ public void saveConfig(Config newConfig) {
+ try {
+ if (newConfig == null) {
+ // Delete the saved configuration
+ configResource.delete(null);
+ } else if (!EcoreUtil.equals(config, newConfig)) {
+ EcoreUtil.replace(config, EcoreUtil.copy(newConfig));
+ configResource.save(null);
+ }
+ } catch (IOException e) {
+ Activator.log.error(e);
+ }
+ }
+}
diff --git a/extraplugins/migration/org.eclipse.papyrus.migration.rsa/src/org/eclipse/papyrus/migration/rsa/internal/extension/PostProcessExtension.java b/extraplugins/migration/org.eclipse.papyrus.migration.rsa/src/org/eclipse/papyrus/migration/rsa/internal/extension/PostProcessExtension.java
new file mode 100644
index 00000000000..5e8421eeed2
--- /dev/null
+++ b/extraplugins/migration/org.eclipse.papyrus.migration.rsa/src/org/eclipse/papyrus/migration/rsa/internal/extension/PostProcessExtension.java
@@ -0,0 +1,64 @@
+/*****************************************************************************
+ * Copyright (c) 2017 Christian W. Damus and others.
+ *
+ * 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:
+ * Christian W. Damus - Initial API and implementation
+ *
+ *****************************************************************************/
+
+package org.eclipse.papyrus.migration.rsa.internal.extension;
+
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.emf.ecore.resource.ResourceSet;
+import org.eclipse.m2m.qvt.oml.ExecutionContext;
+
+/**
+ * <p>
+ * Extension to the RSA-to-Papyrus transformation's post-processing phase
+ * for dependency migration and stereotype repair. {@link TransformationExtension}s
+ * may additionally implement this interface to be invoked after all other
+ * post-processing is done by the core import framework.
+ * </p>
+ * <p>
+ * This is provisional API.
+ * </p>
+ */
+public interface PostProcessExtension extends TransformationExtension {
+ /**
+ * <p>
+ * Post-processes the completed imported model. This method is invoked in the
+ * context of a write transaction, so the implementation is free to make any
+ * edits to the model directly, without the use of commands. Note that this
+ * does imply that the changes made to the model are not undoable and cannot
+ * be rolled back in case of any failure.
+ * </p>
+ * <p>
+ * <b>Note</b> also that this post-processing is performed in different resource
+ * set to the one in which the base transformation extensions are performed.
+ * Therefore, before this method is invoked, the receiver will have been
+ * assigned a new {@link #setResourceSet(ResourceSet) resourceSet}.
+ * </p>
+ *
+ * @param context
+ * the QVTo execution context
+ * @param monitor
+ * for optional reporting of progress if the post-processing is
+ * expected to be a long-running operation. This is a private
+ * monitor for the extension that should be started and finished
+ * as usual. So, the {@linkplain #getNumberOfSteps() number of steps}
+ * reported by the base transformation must not include this
+ * post-processing phase
+ *
+ * @return a status indicating success or problems
+ *
+ * @see #setResourceSet(ResourceSet)
+ * @see #getNumberOfSteps()
+ */
+ IStatus postProcess(ExecutionContext context, IProgressMonitor monitor);
+}
diff --git a/extraplugins/migration/org.eclipse.papyrus.migration.rsa/src/org/eclipse/papyrus/migration/rsa/internal/extension/TransformationExtension.java b/extraplugins/migration/org.eclipse.papyrus.migration.rsa/src/org/eclipse/papyrus/migration/rsa/internal/extension/TransformationExtension.java
index e7c468ba29b..545d28e2ad5 100644
--- a/extraplugins/migration/org.eclipse.papyrus.migration.rsa/src/org/eclipse/papyrus/migration/rsa/internal/extension/TransformationExtension.java
+++ b/extraplugins/migration/org.eclipse.papyrus.migration.rsa/src/org/eclipse/papyrus/migration/rsa/internal/extension/TransformationExtension.java
@@ -1,5 +1,5 @@
/*****************************************************************************
- * Copyright (c) 2015 CEA LIST and others.
+ * Copyright (c) 2015, 2017 CEA LIST, Christian W. Damus, and others.
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
@@ -8,6 +8,7 @@
*
* Contributors:
* Camille Letavernier (CEA LIST) camille.letavernier@cea.fr - Initial API and implementation
+ * Christian W. Damus - bug 505330
*
*****************************************************************************/
package org.eclipse.papyrus.migration.rsa.internal.extension;
@@ -82,9 +83,12 @@ public interface TransformationExtension {
public IStatus executeAfter(ExecutionContext context, IProgressMonitor monitor);
/**
- * The number of work steps required by this transformation. Corresponds to the total number of worked() you can invoke in executeBefore/executeAfter
+ * The number of work steps required by this transformation. Corresponds to the total number of worked() you can invoke in executeBefore/executeAfter.
+ * This does not include any work that is done in optional extensions such as {@link PostProcessExtension}.
*
- * @return
+ * @return the total number of steps consumed from the shared progress monitor in
+ * my {@link #executeBefore(ExecutionContext, IProgressMonitor) executeBefore} and
+ * {@link #executeAfter(ExecutionContext, IProgressMonitor) executeAfter}
*/
public int getNumberOfSteps();
}
diff --git a/extraplugins/migration/org.eclipse.papyrus.migration.rsa/src/org/eclipse/papyrus/migration/rsa/transformation/ImportTransformation.java b/extraplugins/migration/org.eclipse.papyrus.migration.rsa/src/org/eclipse/papyrus/migration/rsa/transformation/ImportTransformation.java
index 78592d38676..06c4b91ba3e 100644
--- a/extraplugins/migration/org.eclipse.papyrus.migration.rsa/src/org/eclipse/papyrus/migration/rsa/transformation/ImportTransformation.java
+++ b/extraplugins/migration/org.eclipse.papyrus.migration.rsa/src/org/eclipse/papyrus/migration/rsa/transformation/ImportTransformation.java
@@ -1,5 +1,5 @@
/*****************************************************************************
- * Copyright (c) 2013, 2016 CEA LIST, Christian W. Damus, and others.
+ * Copyright (c) 2013, 2017 CEA LIST, Christian W. Damus, and others.
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
@@ -9,6 +9,7 @@
* Contributors:
* Camille Letavernier (CEA LIST) camille.letavernier@cea.fr - Initial API and implementation
* Christian W. Damus - bugs 496439, 496299, 505330
+ *
*****************************************************************************/
package org.eclipse.papyrus.migration.rsa.transformation;
@@ -27,8 +28,10 @@ import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
+import java.util.Optional;
import java.util.Properties;
import java.util.Set;
+import java.util.stream.Collectors;
import org.eclipse.core.runtime.Assert;
import org.eclipse.core.runtime.IConfigurationElement;
@@ -37,6 +40,7 @@ import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.MultiStatus;
import org.eclipse.core.runtime.Platform;
import org.eclipse.core.runtime.Status;
+import org.eclipse.core.runtime.SubMonitor;
import org.eclipse.core.runtime.jobs.IJobChangeEvent;
import org.eclipse.core.runtime.jobs.Job;
import org.eclipse.core.runtime.jobs.JobChangeAdapter;
@@ -73,8 +77,10 @@ import org.eclipse.m2m.qvt.oml.util.ISessionData;
import org.eclipse.m2m.qvt.oml.util.Trace;
import org.eclipse.m2m.qvt.oml.util.WriterLog;
import org.eclipse.papyrus.dsml.validation.PapyrusDSMLValidationRule.PapyrusDSMLValidationRulePackage;
+import org.eclipse.papyrus.infra.core.resource.ModelSet;
import org.eclipse.papyrus.infra.emf.resource.ShardResourceHelper;
import org.eclipse.papyrus.infra.emf.utils.EMFHelper;
+import org.eclipse.papyrus.infra.gmfdiag.common.model.NotationModel;
import org.eclipse.papyrus.infra.tools.util.ClassLoaderHelper;
import org.eclipse.papyrus.infra.tools.util.ListHelper;
import org.eclipse.papyrus.m2m.qvto.TraceHelper;
@@ -86,6 +92,7 @@ import org.eclipse.papyrus.migration.rsa.blackbox.ProfileBaseHelper;
import org.eclipse.papyrus.migration.rsa.concurrent.ExecutorsPool;
import org.eclipse.papyrus.migration.rsa.concurrent.ResourceAccessHelper;
import org.eclipse.papyrus.migration.rsa.default_.DefaultPackage;
+import org.eclipse.papyrus.migration.rsa.internal.extension.PostProcessExtension;
import org.eclipse.papyrus.migration.rsa.internal.extension.TransformationExtension;
import org.eclipse.papyrus.migration.rsa.profilebase.ProfileBasePackage;
import org.eclipse.papyrus.uml.documentation.Documentation.DocumentationPackage;
@@ -113,7 +120,7 @@ public class ImportTransformation {
private static final boolean DEBUG = false;
// SourceURI is the input
- protected final URI sourceURI;
+ protected URI sourceURI;
// targetURI is computed during the transformation
protected URI targetURI;
@@ -376,6 +383,18 @@ public class ImportTransformation {
}
}
+ protected void initResourceSet(URI sourceURI, MigrationResourceSet resourceSet) {
+ this.sourceURI = sourceURI;
+ this.resourceSet = resourceSet;
+ this.umlResource = resourceSet.getResource(sourceURI, false);
+
+ // These are all new in the new resource set
+ outUML = null;
+ outNotation = null;
+ outSashModel = null;
+ inPapyrusProfiles = null;
+ }
+
/**
* Returns the number of elements to be migrated (i.e. diagrams to be migrated + specific non-trivial elements)
* Used to initialize the progress monitor
@@ -413,7 +432,7 @@ public class ImportTransformation {
i += getAllTransformationURIs().size();
// Add the number of steps required by each extension
- for (TransformationExtension extension : extensions) {
+ for (TransformationExtension extension : getExtensions()) {
int extraSteps = extension.getNumberOfSteps();
if (extraSteps > 0) {
i += extraSteps;
@@ -727,19 +746,37 @@ public class ImportTransformation {
public static IStatus executeAfter(TransformationExtension extension, ExecutionContext context, IProgressMonitor monitor) {
return extension.executeAfter(context, monitor);
}
+
+ /**
+ * Delegates to {@link PostProcessExtension#postProcess(ExecutionContext, IProgressMonitor)}.
+ */
+ public static IStatus postProcess(TransformationExtension extension, ExecutionContext context, IProgressMonitor monitor) {
+ return Optional.of(extension)
+ .filter(PostProcessExtension.class::isInstance)
+ .map(PostProcessExtension.class::cast)
+ .map(post -> post.postProcess(context, SubMonitor.convert(monitor, 1)))
+ .orElse(Status.OK_STATUS);
+ }
}
protected void prepareExtensions() {
- for (TransformationExtension extension : extensions) {
+ for (TransformationExtension extension : getExtensions()) {
extension.setResourceSet(resourceSet);
extension.setExecutorsPool(executorsPool);
extension.setTransformation(this);
}
}
+ /**
+ * @return the extensions
+ */
+ protected List<TransformationExtension> getExtensions() {
+ return extensions;
+ }
+
protected IStatus importExtensions(ExecutionContext context, IProgressMonitor monitor, ExtensionFunction function) {
- List<IStatus> allResults = new ArrayList<>(extensions.size());
- for (TransformationExtension extension : extensions) {
+ List<IStatus> allResults = new ArrayList<>(getExtensions().size());
+ for (TransformationExtension extension : getExtensions()) {
IStatus result = function.apply(extension, context, monitor);
allResults.add(result);
}
@@ -1234,6 +1271,7 @@ public class ImportTransformation {
context.getSessionData().setValue(TraceHelper.TRACE_HISTORY, trace);
+ this.context = context;
return context;
}
@@ -1340,7 +1378,26 @@ public class ImportTransformation {
/* Notation model is initially empty, but will be filled successively by each transformation */
public ModelExtent getInoutNotationModel() {
if (outNotation == null) {
- outNotation = new BasicModelExtent();
+ try {
+ if (resourceSet instanceof ModelSet) {
+ // This is the post-processing phase, so we already have the notations
+ NotationModel notation = (NotationModel) ((ModelSet) resourceSet).getModel(NotationModel.MODEL_ID);
+ if (notation != null) {
+ List<EObject> diagrams = notation.getResources().stream()
+ .flatMap(res -> res.getContents().stream())
+ .filter(Diagram.class::isInstance)
+ .collect(Collectors.toList());
+ outNotation = new BasicModelExtent(diagrams);
+ }
+ }
+ } catch (Exception e) {
+ Activator.log.error(e);
+ }
+
+ if (outNotation == null) {
+ // Guess it's not the post-processing phase
+ outNotation = new BasicModelExtent();
+ }
}
return outNotation;
diff --git a/extraplugins/migration/org.eclipse.papyrus.migration.rsa/src/org/eclipse/papyrus/migration/rsa/transformation/ImportTransformationLauncher.java b/extraplugins/migration/org.eclipse.papyrus.migration.rsa/src/org/eclipse/papyrus/migration/rsa/transformation/ImportTransformationLauncher.java
index 28d02c53116..1f3071109d6 100644
--- a/extraplugins/migration/org.eclipse.papyrus.migration.rsa/src/org/eclipse/papyrus/migration/rsa/transformation/ImportTransformationLauncher.java
+++ b/extraplugins/migration/org.eclipse.papyrus.migration.rsa/src/org/eclipse/papyrus/migration/rsa/transformation/ImportTransformationLauncher.java
@@ -1,5 +1,5 @@
/*****************************************************************************
- * Copyright (c) 2014, 2016 CEA LIST, Christian W. Damus, and others.
+ * Copyright (c) 2014, 2017 CEA LIST, Christian W. Damus, and others.
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
@@ -8,7 +8,8 @@
*
* Contributors:
* Camille Letavernier (CEA LIST) camille.letavernier@cea.fr - Initial API and implementation
- * Christian W. Damus - bug 496439
+ * Christian W. Damus - bugs 496439, 505330
+ *
*****************************************************************************/
package org.eclipse.papyrus.migration.rsa.transformation;
@@ -29,6 +30,7 @@ import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.MultiStatus;
import org.eclipse.core.runtime.Status;
+import org.eclipse.core.runtime.SubMonitor;
import org.eclipse.core.runtime.jobs.IJobChangeEvent;
import org.eclipse.core.runtime.jobs.Job;
import org.eclipse.core.runtime.jobs.JobChangeAdapter;
@@ -49,6 +51,8 @@ import org.eclipse.gmf.runtime.notation.NotationPackage;
import org.eclipse.gmf.runtime.notation.StringValueStyle;
import org.eclipse.gmf.runtime.notation.View;
import org.eclipse.jface.dialogs.MessageDialog;
+import org.eclipse.m2m.qvt.oml.ExecutionContext;
+import org.eclipse.m2m.qvt.oml.util.Trace;
import org.eclipse.papyrus.infra.core.resource.IEMFModel;
import org.eclipse.papyrus.infra.core.resource.IModel;
import org.eclipse.papyrus.infra.core.resource.ModelMultiException;
@@ -56,15 +60,18 @@ import org.eclipse.papyrus.infra.core.resource.ModelSet;
import org.eclipse.papyrus.infra.emf.resource.DependencyManagementHelper;
import org.eclipse.papyrus.infra.emf.utils.EMFHelper;
import org.eclipse.papyrus.infra.tools.util.StringHelper;
+import org.eclipse.papyrus.m2m.qvto.TraceHelper;
import org.eclipse.papyrus.migration.rsa.Activator;
import org.eclipse.papyrus.migration.rsa.RSAToPapyrusParameters.Config;
import org.eclipse.papyrus.migration.rsa.RSAToPapyrusParameters.MappingParameters;
import org.eclipse.papyrus.migration.rsa.RSAToPapyrusParameters.URIMapping;
import org.eclipse.papyrus.migration.rsa.concurrent.ResourceAccessHelper;
+import org.eclipse.papyrus.migration.rsa.internal.extension.PostProcessExtension;
import org.eclipse.papyrus.migration.rsa.internal.schedule.JobWrapper;
import org.eclipse.papyrus.migration.rsa.internal.schedule.Schedulable;
import org.eclipse.papyrus.migration.rsa.internal.schedule.Scheduler;
import org.eclipse.papyrus.migration.rsa.internal.schedule.TransformationWrapper;
+import org.eclipse.papyrus.migration.rsa.transformation.ImportTransformation.ExtensionFunction;
import org.eclipse.papyrus.migration.rsa.transformation.ui.URIMappingDialog;
import org.eclipse.papyrus.uml.tools.model.UmlModel;
import org.eclipse.swt.widgets.Control;
@@ -118,6 +125,11 @@ public class ImportTransformationLauncher {
protected long ownRepairStereotypesTime;
/**
+ * Own cumulated execution time for post-processing extensions
+ */
+ protected long ownPostProcessingTime;
+
+ /**
* Own cumulated execution time for repairing libraries
*/
protected long ownRepairLibrariesTime;
@@ -171,7 +183,7 @@ public class ImportTransformationLauncher {
protected ImportTransformation createTransformation(URI transformationURI) {
return new ImportTransformation(transformationURI, config, analysisHelper);
}
-
+
/**
* Start a Job and delegate to {@link #importModels(IProgressMonitor, List)}
*
@@ -209,12 +221,14 @@ public class ImportTransformationLauncher {
Long loadingTime = loadingTimeV2.get(transformation);
Long repairProxiesTime = proxiesTime.get(transformation);
Long repairStereoTime = stereoTime.get(transformation);
+ Long postTime = postProcessTime.get(transformation);
Long totalPhase2 = totalTimeV2.get(transformation);
log("Second phase (50-100%):");
log("\tTotal loading time: " + timeFormat(loadingTime));
log("\tTotal fix proxies time: " + timeFormat(repairProxiesTime));
log("\tTotal fix stereotypes time: " + timeFormat(repairStereoTime));
+ log("\tTotal post-processing time: " + timeFormat(postTime));
log("\tTotal execution time: " + timeFormat(totalPhase2));
log("Total");
@@ -235,6 +249,7 @@ public class ImportTransformationLauncher {
log("\tCumulated Loading Time: " + timeFormat(ownLoadingTime));
log("\tCumulated Fix Libraries Time: " + timeFormat(ownRepairLibrariesTime));
log("\tCumulated Fix Stereotypes Time: " + timeFormat(ownRepairStereotypesTime));
+ log("\tCumulated Post-processing Time: " + timeFormat(ownPostProcessingTime));
log("\tTotal Fix Dependencies Time: " + timeFormat(ownExecutionTime));
log("Total");
@@ -485,6 +500,8 @@ public class ImportTransformationLauncher {
final protected Map<ImportTransformation, Long> stereoTime = new HashMap<ImportTransformation, Long>();
+ final protected Map<ImportTransformation, Long> postProcessTime = new HashMap<ImportTransformation, Long>();
+
final protected Map<ImportTransformation, Long> totalTimeV2 = new HashMap<ImportTransformation, Long>();
protected IStatus fixDependencies(ImportTransformation transformation, IProgressMonitor monitor, Map<URI, URI> urisToReplace, Map<URI, URI> profileUrisToReplace) {
@@ -610,32 +627,64 @@ public class ImportTransformationLauncher {
return repairDisplayStatus;
}
- try {
-
- for (Resource resource : resourcesToRepair) {
- ResourceAccessHelper.INSTANCE.saveResource(resource, null);
- }
-
- monitor.worked(1);
+ IStatus result = Status.OK_STATUS;
+ // Post-processing extensions
+ long postProcessors = transformation.getExtensions().stream()
+ .filter(PostProcessExtension.class::isInstance)
+ .count();
+ if (postProcessors > 0L) {
final TransactionalEditingDomain domain = modelSet.getTransactionalEditingDomain();
- InternalTransactionalEditingDomain internalDomain = (InternalTransactionalEditingDomain) domain;
+ String statusMessage = String.format("Post-process %s", transformation.getModelName());
+ MultiStatus postProcessStatus = new MultiStatus(Activator.PLUGIN_ID, IStatus.OK, statusMessage, null);
- Map<String, Object> options = new HashMap<String, Object>();
- options.put(Transaction.OPTION_NO_UNDO, true);
- options.put(Transaction.OPTION_NO_VALIDATION, true);
- options.put(Transaction.OPTION_NO_TRIGGERS, true);
- options.put(Transaction.OPTION_UNPROTECTED, true);
+ long startPostProcessing = System.nanoTime();
- // We're in a batch environment, with no undo/redo support. Run a vanilla transaction to improve performances
- Transaction fastTransaction = internalDomain.startTransaction(false, options);
try {
- EMFHelper.unload(modelSet);
+ runFastTransaction(domain, () -> {
+ // Re-initialize the transformation for the new resource set
+ transformation.initResourceSet(transformation.getTargetURI(), modelSet);
+
+ ExecutionContext context = transformation.createExecutionContext(
+ SubMonitor.convert(monitor, 1),
+ postProcessStatus);
+
+ // Cannot increment on previous transformations because they were in a different resource set
+ context.getSessionData().setValue(TraceHelper.TRACE_HISTORY, Trace.createEmptyTrace());
+
+ postProcessStatus.merge(transformation.importExtensions(context, monitor, ExtensionFunction::postProcess));
+ });
+ } catch (RollbackException ex) {
+ Activator.log.error(ex);
+ } catch (InterruptedException ex) {
+ Activator.log.error(ex);
} finally {
- fastTransaction.commit();
+ long endPostProcessing = System.nanoTime();
+ synchronized (ImportTransformationLauncher.this) {
+ ownPostProcessingTime += endPostProcessing - startPostProcessing;
+ postProcessTime.put(transformation, endPostProcessing - startPostProcessing);
+ }
+ }
+
+ if (postProcessStatus.getSeverity() > IStatus.WARNING) {
+ return postProcessStatus;
}
+ result = postProcessStatus;
+ }
+
+ try {
+
+ for (Resource resource : resourcesToRepair) {
+ ResourceAccessHelper.INSTANCE.saveResource(resource, null);
+ }
+
+ monitor.worked(1);
+
+ TransactionalEditingDomain domain = modelSet.getTransactionalEditingDomain();
+ runFastTransaction(domain, () -> EMFHelper.unload(modelSet));
+
domain.dispose();
} catch (IOException ex) {
@@ -646,7 +695,7 @@ public class ImportTransformationLauncher {
Activator.log.error(ex);
}
- return Status.OK_STATUS;
+ return result;
}
protected IStatus repairStereotypeDisplay(ModelSet modelSet, Collection<Resource> resourcesToRepair) {
diff --git a/extraplugins/migration/org.eclipse.papyrus.migration.rsa/src/org/eclipse/papyrus/migration/rsa/wizard/TransformationWizard.java b/extraplugins/migration/org.eclipse.papyrus.migration.rsa/src/org/eclipse/papyrus/migration/rsa/wizard/TransformationWizard.java
index 476954d3d45..ec6466fc8c4 100644
--- a/extraplugins/migration/org.eclipse.papyrus.migration.rsa/src/org/eclipse/papyrus/migration/rsa/wizard/TransformationWizard.java
+++ b/extraplugins/migration/org.eclipse.papyrus.migration.rsa/src/org/eclipse/papyrus/migration/rsa/wizard/TransformationWizard.java
@@ -1,5 +1,5 @@
/*****************************************************************************
- * Copyright (c) 2014 CEA LIST.
+ * Copyright (c) 2014, 2017 CEA LIST, Christian W. Damus, and others.
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
@@ -8,6 +8,7 @@
*
* Contributors:
* Quentin Le Menez (CEA LIST) quentin.lemenez@cea.fr - Initial API and implementation
+ * Christian W. Damus - bug 505330
*****************************************************************************/
package org.eclipse.papyrus.migration.rsa.wizard;
@@ -23,11 +24,12 @@ import org.eclipse.jface.wizard.IWizardPage;
import org.eclipse.jface.wizard.Wizard;
import org.eclipse.papyrus.migration.rsa.Activator;
import org.eclipse.papyrus.migration.rsa.RSAToPapyrusParameters.Config;
+import org.eclipse.papyrus.migration.rsa.internal.ConfigurationManager;
import org.eclipse.papyrus.migration.rsa.messages.Messages;
import org.eclipse.papyrus.migration.rsa.transformation.ImportTransformationLauncher;
+import org.eclipse.papyrus.migration.rsa.wizard.pages.DialogData;
import org.eclipse.papyrus.migration.rsa.wizard.pages.TransformationConfigPage;
import org.eclipse.papyrus.migration.rsa.wizard.pages.TransformationSelectionPage;
-import org.eclipse.papyrus.migration.rsa.wizard.pages.DialogData;
import org.eclipse.ui.IImportWizard;
import org.eclipse.ui.IWorkbench;
@@ -48,16 +50,27 @@ public class TransformationWizard extends Wizard implements IImportWizard {
protected TransformationConfigPage configPage = new TransformationConfigPage(dialogData);
+ private ConfigurationManager configMan = new ConfigurationManager();
public TransformationWizard() {
setWindowTitle(Messages.TransformationWizard_Title);
+
+ configMan.loadConfig(dialogData.getConfig());
+ }
+
+ @Override
+ public void dispose() {
+ try {
+ configMan.dispose();
+ } finally {
+ super.dispose();
+ }
}
@Override
public void addPages() {
this.addPage(selectionPage);
this.addPage(configPage);
-
}
@Override
@@ -90,6 +103,8 @@ public class TransformationWizard extends Wizard implements IImportWizard {
@Override
public boolean performFinish() {
+ configMan.saveConfig(dialogData.getConfig());
+
// Set or update the unchecked elements for future executions of the plugin
dialogData.setSelectionMap();
importFiles();

Back to the top