Skip to content

Commit

Permalink
#88 Copy images to the target project
Browse files Browse the repository at this point in the history
Add a new Activity triggered after diff/merge to copy images contained
in the source project to the target project.

Change-Id: I0000000000000000000000000000000000000000
Signed-off-by: Arnaud Dieumegard <arnaud.dieumegard@obeo.fr>
  • Loading branch information
arnauddieumegard authored and pdulth committed Jun 10, 2022
1 parent 879d495 commit 50e2b60
Show file tree
Hide file tree
Showing 8 changed files with 171 additions and 45 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import org.polarsys.capella.core.transition.common.activities.DifferencesMergingActivity;
import org.polarsys.capella.core.transition.common.activities.InitializeScopeActivity;
import org.polarsys.capella.core.transition.common.activities.PostTransformationActivity;
import org.polarsys.capella.transition.system2subsystem.activities.CopyImagesActivity;
import org.polarsys.capella.transition.system2subsystem.activities.FinalizeSubsystemTransitionActivity;
import org.polarsys.capella.transition.system2subsystem.activities.RootComponentNameUpdater;
import org.polarsys.capella.transition.system2subsystem.crossphases.activities.InitializeCrossPhasesTransformationActivity;
Expand Down Expand Up @@ -102,6 +103,10 @@ protected WorkflowActivityParameter buildDiffMergeActivities() {
@Override
protected WorkflowActivityParameter buildFinalizationActivities() {
WorkflowActivityParameter parameter = super.buildFinalizationActivities();

// Copy images to the target project
parameter.addActivity(CopyImagesActivity.ID);

parameter.addActivity(FinalizeSubsystemTransitionActivity.ID);
return parameter;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import org.polarsys.capella.core.transition.common.activities.DifferencesMergingActivity;
import org.polarsys.capella.core.transition.common.activities.InitializeScopeActivity;
import org.polarsys.capella.core.transition.common.activities.PostTransformationActivity;
import org.polarsys.capella.transition.system2subsystem.activities.CopyImagesActivity;
import org.polarsys.capella.transition.system2subsystem.activities.FinalizeSubsystemTransitionActivity;
import org.polarsys.capella.transition.system2subsystem.activities.InitializeTransformationActivity;
import org.polarsys.capella.transition.system2subsystem.interphases.activities.InitializeDiffMergeActivity;
Expand Down Expand Up @@ -75,7 +76,7 @@ protected WorkflowActivityParameter buildDiffMergeActivities() {
WorkflowActivityParameter parameter = new WorkflowActivityParameter();

if (getTransposer() != null) {

// PostTransformationActivity
parameter.addActivity(getActivity(PostTransformationActivity.ID));

Expand All @@ -99,6 +100,10 @@ protected WorkflowActivityParameter buildDiffMergeActivities() {
@Override
protected WorkflowActivityParameter buildFinalizationActivities() {
WorkflowActivityParameter parameter = super.buildFinalizationActivities();

// Copy images to the target project
parameter.addActivity(CopyImagesActivity.ID);

parameter.addActivity(FinalizeSubsystemTransitionActivity.ID);
return parameter;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import org.polarsys.capella.core.transition.common.constants.ITransitionConstants;
import org.polarsys.capella.core.transition.common.transposer.ExtendedRulesHandler;
import org.polarsys.capella.core.transition.common.transposer.SharedWorkflowActivityParameter;
import org.polarsys.capella.transition.system2subsystem.activities.CopyImagesActivity;
import org.polarsys.capella.transition.system2subsystem.activities.FinalizeSubsystemTransitionActivity;
import org.polarsys.capella.transition.system2subsystem.activities.RootComponentNameUpdater;
import org.polarsys.capella.transition.system2subsystem.crossphases.handlers.attachment.CrossPhasesAttachmentHelper;
Expand Down Expand Up @@ -86,6 +87,8 @@ public void launch(Collection<?> selection, IProgressMonitor monitor) {
new InitializeMultiphasesDiffMergeActivity().run(createActivityParameters(InitializeMultiphasesDiffMergeActivity.ID, context));
new MultiphasesDifferencesComputingActivity().run(createActivityParameters(MultiphasesDifferencesComputingActivity.ID, context));
new DifferencesMergingActivity().run(createActivityParameters(DifferencesMergingActivity.ID, context));
// Copy images to the target project
new CopyImagesActivity().run(createActivityParameters(CopyImagesActivity.ID, context));
new FinalizeTransitionActivity().run(createActivityParameters(FinalizeTransitionActivity.ID, context));
} finally {
try {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,43 +1,45 @@
Manifest-Version: 1.0
Export-Package: org.polarsys.capella.transition.system2subsystem,
org.polarsys.capella.transition.system2subsystem.activities,
org.polarsys.capella.transition.system2subsystem.commands,
org.polarsys.capella.transition.system2subsystem.constants,
org.polarsys.capella.transition.system2subsystem.context,
org.polarsys.capella.transition.system2subsystem.handlers.attachment,
org.polarsys.capella.transition.system2subsystem.handlers.filter,
org.polarsys.capella.transition.system2subsystem.handlers.scope,
org.polarsys.capella.transition.system2subsystem.handlers.selection,
org.polarsys.capella.transition.system2subsystem.handlers.session,
org.polarsys.capella.transition.system2subsystem.handlers.traceability,
org.polarsys.capella.transition.system2subsystem.handlers.traceability.config,
org.polarsys.capella.transition.system2subsystem.launcher,
org.polarsys.capella.transition.system2subsystem.policies.match,
org.polarsys.capella.transition.system2subsystem.preferences,
org.polarsys.capella.transition.system2subsystem.rules,
org.polarsys.capella.transition.system2subsystem.rules.core,
org.polarsys.capella.transition.system2subsystem.rules.cs,
org.polarsys.capella.transition.system2subsystem.rules.fa,
org.polarsys.capella.transition.system2subsystem.rules.information,
org.polarsys.capella.transition.system2subsystem.rules.information.communication,
org.polarsys.capella.transition.system2subsystem.rules.interaction,
org.polarsys.capella.transition.system2subsystem.rules.pa,
org.polarsys.capella.transition.system2subsystem.transposer
Require-Bundle: org.eclipse.core.runtime,
org.polarsys.capella.core.data.gen,
org.polarsys.capella.core.model.helpers,
org.polarsys.capella.core.transition.system;visibility:=reexport,
org.polarsys.capella.core.transition.system.topdown,
org.polarsys.capella.core.model.handler,
org.polarsys.capella.common.libraries,
org.polarsys.capella.common.transition
Bundle-Vendor: %providerName
Bundle-ActivationPolicy: lazy
Bundle-Version: 1.6.0.qualifier
Bundle-Localization: plugin
Bundle-Name: %pluginName
Bundle-Activator: org.polarsys.capella.transition.system2subsystem.Activator
Bundle-ManifestVersion: 2
Bundle-SymbolicName: org.polarsys.capella.transition.system2subsystem;singleton:=true
Bundle-RequiredExecutionEnvironment: JavaSE-1.8

Manifest-Version: 1.0
Export-Package: org.polarsys.capella.transition.system2subsystem,
org.polarsys.capella.transition.system2subsystem.activities,
org.polarsys.capella.transition.system2subsystem.commands,
org.polarsys.capella.transition.system2subsystem.constants,
org.polarsys.capella.transition.system2subsystem.context,
org.polarsys.capella.transition.system2subsystem.handlers.attachment,
org.polarsys.capella.transition.system2subsystem.handlers.filter,
org.polarsys.capella.transition.system2subsystem.handlers.scope,
org.polarsys.capella.transition.system2subsystem.handlers.selection,
org.polarsys.capella.transition.system2subsystem.handlers.session,
org.polarsys.capella.transition.system2subsystem.handlers.traceability,
org.polarsys.capella.transition.system2subsystem.handlers.traceability.config,
org.polarsys.capella.transition.system2subsystem.launcher,
org.polarsys.capella.transition.system2subsystem.policies.match,
org.polarsys.capella.transition.system2subsystem.preferences,
org.polarsys.capella.transition.system2subsystem.rules,
org.polarsys.capella.transition.system2subsystem.rules.core,
org.polarsys.capella.transition.system2subsystem.rules.cs,
org.polarsys.capella.transition.system2subsystem.rules.fa,
org.polarsys.capella.transition.system2subsystem.rules.information,
org.polarsys.capella.transition.system2subsystem.rules.information.communication,
org.polarsys.capella.transition.system2subsystem.rules.interaction,
org.polarsys.capella.transition.system2subsystem.rules.pa,
org.polarsys.capella.transition.system2subsystem.transposer
Require-Bundle: org.eclipse.core.runtime,
org.polarsys.capella.core.data.gen,
org.polarsys.capella.core.model.helpers,
org.polarsys.capella.core.transition.system;visibility:=reexport,
org.polarsys.capella.core.transition.system.topdown,
org.polarsys.capella.core.model.handler,
org.polarsys.capella.common.libraries,
org.polarsys.capella.common.transition,
org.polarsys.kitalpha.ad.metadata,
org.polarsys.capella.core.sirius.ui
Bundle-Vendor: %providerName
Bundle-ActivationPolicy: lazy
Bundle-Version: 1.6.0.qualifier
Bundle-Localization: plugin
Bundle-Name: %pluginName
Bundle-Activator: org.polarsys.capella.transition.system2subsystem.Activator
Bundle-ManifestVersion: 2
Bundle-SymbolicName: org.polarsys.capella.transition.system2subsystem;singleton:=true
Bundle-RequiredExecutionEnvironment: JavaSE-1.8

Original file line number Diff line number Diff line change
Expand Up @@ -689,6 +689,22 @@
</ActivityDeclaration>
</extension>


<extension
point="org.polarsys.kitalpha.cadence.core.activity.declaration">
<ActivityDeclaration
ActivityClass="org.polarsys.capella.transition.system2subsystem.activities.CopyImagesActivity"
Identifier="org.polarsys.capella.transition.system2subsystem.activities.CopyImagesActivity"
Multiple="false"
Name="CopyImagesActivity"
WorkflowElementIdentifier="transition.workflow.finalization"
WorkflowIdentifier="org.polarsys.kitalpha.transposer.workflow">
<Description>
Copy images to the target project
</Description>
</ActivityDeclaration>
</extension>

<extension
point="org.polarsys.kitalpha.cadence.core.activity.declaration">
<ActivityDeclaration
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
/*******************************************************************************
* Copyright (c) 2022 THALES GLOBAL SERVICES.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* Thales - initial API and implementation
*******************************************************************************/
package org.polarsys.capella.transition.system2subsystem.activities;

import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.core.runtime.Status;
import org.polarsys.capella.core.data.capellamodeller.Project;
import org.polarsys.capella.core.sirius.ui.helper.ResourceHelper;
import org.polarsys.capella.core.transition.common.activities.AbstractActivity;
import org.polarsys.capella.core.transition.common.handlers.log.LogHelper;
import org.polarsys.capella.core.transition.system.helpers.ContextHelper;
import org.polarsys.capella.transition.system2subsystem.constants.Messages;
import org.polarsys.kitalpha.cadence.core.api.parameter.ActivityParameters;
import org.polarsys.kitalpha.transposer.rules.handler.rules.api.IContext;

/**
* This activity copies all images from the Transition Context Source Project into the Transition Context Target
* Project.
*
* @author <a href="mailto:arnaud.dieumegard@obeo.fr">Arnaud Dieumegard</a>
*/
public class CopyImagesActivity extends AbstractActivity {

public static final String ID = "org.polarsys.capella.transition.system2subsystem.activities.CopyImagesActivity"; //$NON-NLS-1$

/**
* {@inheritDoc}
*/
@Override
protected IStatus _run(ActivityParameters activityParams_p) {

IContext transformationContext = getContext(activityParams_p);
Project sourceProject = ContextHelper.getSourceProject(transformationContext);
Project targetProject = ContextHelper.getTargetProject(transformationContext);

IProject sourceEclipseProject = ResourcesPlugin.getWorkspace().getRoot().getProject(sourceProject.getName());
IProject targetEclipseProject = ResourcesPlugin.getWorkspace().getRoot().getProject(targetProject.getName());

copyImagesToTargetProject(sourceEclipseProject, targetEclipseProject);

return Status.OK_STATUS;
}

private void copyImagesToTargetProject(IProject sourceEclipseProject, IProject targetEclipseProject) {
// Copy image
try {
for (IResource resource : ResourceHelper.collectImageFiles(sourceEclipseProject)) {
// Prevent the copy of already existing resources
if (!targetEclipseProject.exists(resource.getProjectRelativePath())) {
// Calculate newPath with the same file name
IPath newPath = targetEclipseProject.getFullPath();
newPath = newPath.addTrailingSeparator();
newPath = newPath.append(resource.getProjectRelativePath());
// Create folder hierarchy
boolean mkdirs = targetEclipseProject.getLocation().addTrailingSeparator().append(resource.getProjectRelativePath()).removeLastSegments(1).toFile().mkdirs();
if (mkdirs) {
targetEclipseProject.refreshLocal(newPath.segmentCount() - 1, null);
}
// Copy the file
resource.copy(newPath, true, new NullProgressMonitor());
}
}
} catch (CoreException e) {
LogHelper.getInstance().log(e.getMessage(), new Status(IStatus.ERROR, org.polarsys.capella.transition.system2subsystem.Activator.PLUGIN_ID, e.getMessage(), e),
Messages.Activity_CopyImages);
}
}

/**
* {@inheritDoc}
*/
@Override
public String getActivityIdentifier() {
return ID;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ public class Messages extends NLS {
public static String Rule_InteractionState_FailMsg;
public static String Rule_StateFragment_FailMsg;
public static String Rule_InteractionFunctionState_FailMsg;
public static String Activity_CopyImages;

static {
// initialize resource bundle
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,6 @@ ScenarioSuffix_OES=\ (OES)
Rule_Event_FunctionalExchangeNotAllocated=Functional Exchange ''{0}'' is not allocated to any Component Exchange. Sequence Message ''{1}'' will not convey any operation.
Rule_InteractionState_FailMsg=An interaction state is never transitioned between two different phases.
Rule_InteractionFunctionState_FailMsg=An interaction state with a function cannot be transitioned while exchange scenario to interface scenario.
Rule_StateFragment_FailMsg=A state fragment is never transitioned between two different phases.
Rule_StateFragment_FailMsg=A state fragment is never transitioned between two different phases.

Activity_CopyImages=CopyImages

0 comments on commit 50e2b60

Please sign in to comment.