Skip to content

Commit

Permalink
[569477] Add a migration contribution for trace resources (#15)
Browse files Browse the repository at this point in the history
- If the trace file is present in the capella project it is
automatically migrated during the project migration.
- If the trace file is present elsewhere in the workspace, a migration
menu is available.

- Add JUnit
-- Trace Helper JUnits
-- Migration procedure JUnit

- Add migration documentation

Change-Id: I8c94b2261bfdab00c55ae975099f1b3271e0c994
Signed-off-by: Sandu Postaru <sandu.postaru@thalesgroup.com>
  • Loading branch information
sandupostaru committed Dec 7, 2020
1 parent 9421088 commit f58eb56
Show file tree
Hide file tree
Showing 25 changed files with 1,952 additions and 12 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<link rel="stylesheet" type="text/css"
href="PLUGINS_ROOT/org.polarsys.capella.doc/html/styles.css"
media="all" />
<title>Migration</title>
</head>
<body>
<h1>Migration procedure</h1>
<p>As specified in the previous section, after a Reqif import a new
file .bridgetraces is created aside the .capella file which is used
for successive imports. Models that have been created in previous
versions of Capella need to be migrated for this version, including
the .bridgetraces file.</p>

<ul>
<li>If the .bridgetraces file is present in your Capella project,
it will be automatically migrated during the migration procedure. For
more details regarding the migration please of Capella projects
please consult <b>Capella Guide / User Manual / First steps with
Capella / How to Migrate Capella Project</b>
</li>
<li><img src="../../images/migration1.png"
style="max-width: 700px; height: auto;" /></li>
<li>If the .bridgetraces file is present in elsewhere in your
workspace, you can migrate them independently by doing <b>Right
Click / Migration / Migrate Trace resource to current version</b>
</li>
<li><img src="../../images/migration2.png"
style="max-width: 750px; height: auto;" /></li>
</ul>


</body>
</html>
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ <h2>Contents</h2>
<li><a href="31_reqifexport.html">ReqIF Export</a></li>
<li><a href="32_viewpointmanager.html">Viewpoint Manager</a></li>
<li><a href="33_reqifimport.html">ReqIF Import in Capella</a></li>
<li><a href="33_1_migration.html">Project migration</a></li>
<li><a href="34_preferences.html">Preferences</a></li>
<li><a href="35_propertiesview.html">Properties View</a></li>
<li><a href="311_diagrams.html">Requirements in Diagrams</a></li>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,3 +51,5 @@ These followings icons are made available under the terms of the Eclipse Public
/images/showrequirementsinsb.png - org.polarsys.capella.vp.requirements.doc
/images/type.png - org.polarsys.capella.vp.requirements.doc
/images/viewpointmanager.png - org.polarsys.capella.vp.requirements.doc
/images/migration1.png - org.polarsys.capella.vp.requirements.doc
/images/migration2.png - org.polarsys.capella.vp.requirements.doc
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
</topic>
<topic href="html/3_userguide/33_reqifimport.html" label="ReqIF Import in Capella">
</topic>
<topic href="html/3_userguide/33_1_migration.html" label="Project migration">
</topic>
<topic href="html/3_userguide/34_preferences.html" label="Preferences">
</topic>
<topic href="html/3_userguide/3a_edition.html" label="Edition of Requirements">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
import org.eclipse.emf.diffmerge.bridge.api.incremental.IIncrementalBridgeExecution;
import org.eclipse.emf.diffmerge.bridge.interactive.util.ResourceUtil;
import org.eclipse.emf.diffmerge.bridge.traces.gen.bridgetraces.BridgetracesFactory;
import org.eclipse.emf.diffmerge.bridge.traces.gen.bridgetraces.BridgetracesPackage;
import org.eclipse.emf.diffmerge.bridge.traces.gen.bridgetraces.Trace;
import org.eclipse.emf.diffmerge.diffdata.EComparison;
import org.eclipse.emf.diffmerge.generic.api.scopes.IEditableTreeDataScope;
Expand Down Expand Up @@ -62,6 +61,7 @@
import org.polarsys.capella.vp.requirements.importer.transposer.bridge.RequirementsVPBridge;
import org.polarsys.capella.vp.requirements.importer.transposer.policies.ReqIFImporterDiffPolicy;
import org.polarsys.capella.vp.requirements.importer.transposer.policies.ReqIFMergePolicy;
import org.polarsys.capella.vp.requirements.model.helpers.TraceHelper;
import org.polarsys.kitalpha.cadence.core.api.parameter.ActivityParameters;
import org.polarsys.kitalpha.transposer.api.ITransposerWorkflow;
import org.polarsys.kitalpha.transposer.rules.handler.rules.api.IContext;
Expand Down Expand Up @@ -114,7 +114,7 @@ protected IStatus initializeTransformation(final ActivityParameters activityPara
final RequirementsVPBridge bridge = createBridge(sourceScope, targetScope, mapping);

// Load traces
Resource traceResource = getCreateResource(getTraceURI(getTransformationURI(targetScope)),
Resource traceResource = getCreateResource(TraceHelper.getTraceURI(getTransformationURI(targetScope)),
getTransformationDomain(targetScope));
IBridgeTrace/* .Editable */ existingTrace = /* (IBridgeTrace.Editable) */getTrace(bridge, traceResource);

Expand Down Expand Up @@ -149,13 +149,6 @@ protected EMFDiffNode createDiffNode(EComparison comparison, EditingDomain domai
};
}

/**
* TODO COEV From org.eclipse.emf.diffmerge.bridge.interactive.BridgeJob
*/
protected URI getTraceURI(URI uri) {
return uri.appendFileExtension(BridgetracesPackage.eNAME);
}

/**
* @param context
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ Require-Bundle: org.eclipse.core.runtime,
org.polarsys.capella.vp.requirements.model,
org.polarsys.kitalpha.ad.services,
org.polarsys.capella.shared.id.handler,
org.polarsys.capella.core.diagram.helpers
org.polarsys.capella.core.diagram.helpers,
org.polarsys.capella.core.data.migration,
org.eclipse.ui
Bundle-ActivationPolicy: lazy
Export-Package: org.polarsys.capella.vp.requirements.model.helpers
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ bin.includes = .,\
META-INF/,\
plugin.properties,\
about.html,\
plugin.xml
plugin.xml,\
icons/
jars.compile.order = .
source.. = src/
output.. = bin/
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
These followings icons 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

<icon file path> - <original eclipse plug-in> - <original file path>

/icons/full/etools16/capella_migrate.gif - org.eclipse.debug.ui - org.eclipse.debug.ui/icons/full/obj16/debugt_obj.gif
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,50 @@
id="org.polarsys.capella.vp.requirements.id.handler.identifiableelement">
</IdHandler>
</extension>
<extension
point="org.polarsys.capella.core.data.migration.migrationContributors">
<migrationContributor
class="org.polarsys.capella.vp.requirements.model.migration.TraceMigrationContributor">
</migrationContributor>
</extension>
<extension
point="org.eclipse.ui.commands">
<command
categoryId="org.polarsys.capella.core.data.migration"
description="This action is available on Trace resources and migrates them to the current version"
id="org.polarsys.capella.vp.requirements.model.helpers.migration.trace"
name="Migrate Trace resource to current version">
</command>
</extension>
<extension
point="org.eclipse.ui.handlers">
<handler
class="org.polarsys.capella.vp.requirements.model.migration.TraceMigrationHandler"
commandId="org.polarsys.capella.vp.requirements.model.helpers.migration.trace">
</handler>
</extension>
<extension
point="org.eclipse.ui.commandImages">
<image
commandId="org.polarsys.capella.vp.requirements.model.helpers.migration.trace"
icon="icons/full/etools16/capella_migrate.gif">
</image>
</extension>
<extension
point="org.eclipse.ui.menus">
<menuContribution
locationURI="popup:capella.project.explorer#PopupMenu?after=group.migration">
<menu
id="org.polarsys.capella.core.data.migration"
label="Migration">
<command
commandId="org.polarsys.capella.vp.requirements.model.helpers.migration.trace"
style="push">
<visibleWhen
checkEnabled="true">
</visibleWhen>
</command>
</menu>
</menuContribution>
</extension>
</plugin>
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
/*******************************************************************************
* Copyright (c) 2020 THALES GLOBAL SERVICES.
* 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:
* Thales - initial API and implementation
*******************************************************************************/
package org.polarsys.capella.vp.requirements.model.helpers;

import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.emf.common.util.URI;
import org.polarsys.capella.core.model.handler.command.CapellaResourceHelper;

public class TraceHelper {
private static final String TRACE_FILE_EXTENSION = "bridgetraces";

public static URI getTraceURI(URI uri) {
return uri.appendFileExtension(TRACE_FILE_EXTENSION);
}

// Initial: model-with-manually-created-elements.melodymodeller.bridgetraces
// Expected: model-with-manually-created-elements.capella.bridgetraces

private static boolean hasTraceExtension(IResource resource) {
return resource != null && IResource.FILE == resource.getType()
&& TRACE_FILE_EXTENSION.equals(resource.getFileExtension());
}

private static boolean hasSecondaryExtension(IResource resource, String expectedExtension) {
if (expectedExtension != null && hasTraceExtension(resource)) {
IPath resourcePath = resource.getFullPath();
IPath capellaResourcePath = resourcePath.removeFileExtension();
String capellaResourceExtension = capellaResourcePath.getFileExtension();
return expectedExtension.equals(capellaResourceExtension);
}

return false;
}

public static boolean isLegacyTraceResource(IResource resource) {
return hasSecondaryExtension(resource, CapellaResourceHelper.LEGACY_CAPELLA_MODEL_FILE_EXTENSION);
}

public static boolean isTraceResource(IResource resource) {
return hasSecondaryExtension(resource, CapellaResourceHelper.CAPELLA_MODEL_FILE_EXTENSION);
}

public static IPath convertLegacyTracePathToModern(IPath tracePath) {
IPath legacyCapellaResourcePath = tracePath.removeFileExtension();
IPath modernCapellaResourcePath = CapellaResourceHelper
.convertLegacyResourcePathToModern(legacyCapellaResourcePath);

return modernCapellaResourcePath.addFileExtension(TRACE_FILE_EXTENSION);
}

public static void renameLegacyTraceFile(IFile traceFile) throws CoreException {
IPath legacyTracePath = traceFile.getFullPath();
IPath modernTracePath = convertLegacyTracePathToModern(legacyTracePath);

traceFile.move(modernTracePath, true, new NullProgressMonitor());
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/*******************************************************************************
* Copyright (c) 2020 THALES GLOBAL SERVICES.
* 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:
* Thales - initial API and implementation
*******************************************************************************/
package org.polarsys.capella.vp.requirements.model.migration;

import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IResource;
import org.polarsys.capella.core.data.migration.AbstractMigrationRunnable;
import org.polarsys.capella.core.data.migration.MigrationConstants;
import org.polarsys.capella.core.data.migration.contributor.AbstractMigrationContributor;
import org.polarsys.capella.vp.requirements.model.helpers.TraceHelper;

public class TraceMigrationContributor extends AbstractMigrationContributor {

/**
* @param member
* @return
*/
@Override
public boolean isValidResource(IResource resource) {
return TraceHelper.isLegacyTraceResource(resource);
}

@Override
public String getKind() {
return MigrationConstants.MIGRATION_KIND__SEMANTIC;
}

@Override
public AbstractMigrationRunnable getRunnable(IFile file) {
return new TraceMigrationRunnable(file);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
/*******************************************************************************
* Copyright (c) 2020 THALES GLOBAL SERVICES.
* 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:
* Thales - initial API and implementation
*******************************************************************************/
package org.polarsys.capella.vp.requirements.model.migration;

import java.util.LinkedList;
import java.util.List;

import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.core.commands.ExecutionException;
import org.eclipse.core.resources.IFile;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.osgi.util.NLS;
import org.eclipse.ui.handlers.HandlerUtil;
import org.polarsys.capella.core.data.migration.AbstractMigrationRunnable;
import org.polarsys.capella.core.data.migration.Messages;
import org.polarsys.capella.core.data.migration.MigrationJobScheduler;
import org.polarsys.capella.core.data.migration.context.MigrationContext;
import org.polarsys.capella.core.data.migration.handlers.AbstractMigrationHandler;
import org.polarsys.capella.vp.requirements.model.helpers.TraceHelper;

public class TraceMigrationHandler extends AbstractMigrationHandler {

@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
IStructuredSelection selection = (IStructuredSelection) HandlerUtil.getCurrentSelection(event);

for (Object element : selection.toArray()) {
if (element instanceof IFile) {
IFile traceFile = (IFile) element;

MigrationContext context = new MigrationContext();
context.setName(NLS.bind(Messages.MigrationAction_Title, traceFile.getName()));
context.setShell(HandlerUtil.getActiveShell(event));
context.setSkipConfirmation(false);
context.setBackupModel(false);

AbstractMigrationRunnable migrationRunnable = new TraceMigrationRunnable(traceFile);
LinkedList<AbstractMigrationRunnable> runnables = new LinkedList<>();
runnables.add(migrationRunnable);

new MigrationJobScheduler().run(runnables, context, true, false);
}
}

return event;

}

@Override
protected boolean isValidSelection(List<Object> selection) {
return selection.stream().allMatch(o -> o instanceof IFile && TraceHelper.isLegacyTraceResource((IFile) o));
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/*******************************************************************************
* Copyright (c) 2020 THALES GLOBAL SERVICES.
* 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:
* Thales - initial API and implementation
*******************************************************************************/
package org.polarsys.capella.vp.requirements.model.migration;

import org.eclipse.core.resources.IFile;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
import org.polarsys.capella.core.data.migration.AbstractMigrationRunnable;
import org.polarsys.capella.core.data.migration.context.MigrationContext;
import org.polarsys.capella.vp.requirements.model.helpers.TraceHelper;

public class TraceMigrationRunnable extends AbstractMigrationRunnable {

public TraceMigrationRunnable(IFile file) {
super(file);
}

@Override
public IStatus run(MigrationContext context, boolean checkVersion) {
IFile traceFile = getFile();

if (TraceHelper.isLegacyTraceResource(traceFile)) {
try {
TraceHelper.renameLegacyTraceFile(traceFile);
} catch (CoreException exception) {
return new Status(IStatus.ERROR, TraceMigrationRunnable.class, exception.getMessage(), exception);
}

}
return Status.OK_STATUS;
}
}

0 comments on commit f58eb56

Please sign in to comment.