Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migrate to UUIDs #572

Merged
merged 21 commits into from
Apr 5, 2023
Merged
Show file tree
Hide file tree
Changes from 18 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

import org.eclipse.emf.ecore.resource.Resource;

import tools.vitruv.change.atomic.uuid.UuidResolver;

/**
* A view source giving access to the underlying source models of the view.
*/
Expand All @@ -15,4 +17,12 @@ public interface ViewSource {
* @return {@link Resource}s as the sources of a view
*/
Collection<Resource> getViewSourceModels();

/**
* Returns the {@link UuidResolver} associated with the resources in this view
* source.
*
* @return the {@link UuidResolver} of this view source.
*/
public UuidResolver getUuidResolver();
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,24 @@ import org.eclipse.emf.compare.merge.IMerger
import org.eclipse.emf.compare.scope.DefaultComparisonScope
import org.eclipse.emf.compare.utils.UseIdentifiers
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 tools.vitruv.change.atomic.EChangeIdManager
import tools.vitruv.change.atomic.id.IdResolver
import tools.vitruv.change.composite.description.VitruviusChange
import tools.vitruv.change.composite.recording.ChangeRecorder
import tools.vitruv.framework.views.util.ResourceCopier

import static com.google.common.base.Preconditions.checkArgument

import static extension edu.kit.ipd.sdq.commons.util.org.eclipse.emf.ecore.resource.ResourceUtil.getReferencedProxies
import static extension tools.vitruv.change.atomic.resolve.EChangeIdResolverAndApplicator.applyBackward
import static extension tools.vitruv.change.atomic.resolve.EChangeIdResolverAndApplicator.applyForward

/**
* This default strategy for diff based state changes uses EMFCompare to resolve a
* diff to a sequence of individual changes.
* @author Timur Saglam
*/
class DefaultStateBasedChangeResolutionStrategy implements StateBasedChangeResolutionStrategy {
/** The identifier matching behavior used by this strategy */
Expand Down Expand Up @@ -93,9 +98,22 @@ class DefaultStateBasedChangeResolutionStrategy implements StateBasedChangeResol
changeRecorder.beginRecording
changeRecorder.addToRecording(resource)
function.apply()
return changeRecorder.endRecording.unresolve
val recordedChanges = changeRecorder.endRecording
assignIds(recordedChanges, resource.resourceSet)
return recordedChanges.unresolve
}
}

private def void assignIds(VitruviusChange recordedChange, ResourceSet resourceSet) {
val changes = recordedChange.EChanges
val idResolver = IdResolver.create(resourceSet)
val eChangeIdManager = new EChangeIdManager(idResolver)
changes.toList.reverseView.forEach[applyBackward]
changes.forEach[ change |
eChangeIdManager.setOrGenerateIds(change)
change.applyForward(idResolver)
]
}

/**
* Compares states using EMFCompare and replays the changes to the current state.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ 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.xtend.lib.annotations.Accessors
import tools.vitruv.change.composite.description.PropagatedChange
import tools.vitruv.change.composite.description.VitruviusChange
import tools.vitruv.change.composite.propagation.ChangePropagationListener
import tools.vitruv.framework.views.ChangeableViewSource
import tools.vitruv.framework.views.ViewSelection
Expand All @@ -19,8 +21,6 @@ import static com.google.common.base.Preconditions.checkArgument
import static com.google.common.base.Preconditions.checkState

import static extension edu.kit.ipd.sdq.commons.util.org.eclipse.emf.ecore.resource.ResourceSetUtil.withGlobalFactories
import tools.vitruv.change.composite.description.PropagatedChange
import tools.vitruv.change.composite.description.VitruviusChange

package class BasicView implements ModifiableView, ChangePropagationListener {
@Accessors(PUBLIC_GETTER, PROTECTED_SETTER)
Expand All @@ -29,7 +29,7 @@ package class BasicView implements ModifiableView, ChangePropagationListener {
var ViewCreatingViewType<? extends ViewSelector> viewType
@Accessors(PUBLIC_GETTER, PROTECTED_SETTER)
var ChangeableViewSource viewSource
@Accessors(PROTECTED_GETTER, PROTECTED_SETTER)
@Accessors(PROTECTED_GETTER)
var ResourceSet viewResourceSet
boolean modelChanged
@Accessors(PROTECTED_SETTER)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
package tools.vitruv.framework.views.impl

import java.util.List
import org.eclipse.xtend.lib.annotations.Delegate
import tools.vitruv.change.atomic.EChange
import tools.vitruv.change.atomic.EChangeIdManager
import tools.vitruv.change.atomic.id.IdResolver
import tools.vitruv.change.composite.recording.ChangeRecorder
import tools.vitruv.framework.views.CommittableView
import tools.vitruv.framework.views.View
Expand All @@ -9,6 +13,9 @@ import tools.vitruv.framework.views.changederivation.StateBasedChangeResolutionS
import static com.google.common.base.Preconditions.checkArgument
import static com.google.common.base.Preconditions.checkState

import static extension tools.vitruv.change.atomic.resolve.EChangeIdResolverAndApplicator.applyBackward
import static extension tools.vitruv.change.atomic.resolve.EChangeIdResolverAndApplicator.applyForward

/**
* A {@link View} that records changes to its resources and allows to propagate them
* back to the underlying models using the {@link #commitChanges} method.
Expand Down Expand Up @@ -36,11 +43,21 @@ class ChangeRecordingView implements ModifiableView, CommittableView {
changeRecorder.addToRecording(view.viewResourceSet)
changeRecorder.beginRecording()
}
def private void assignIds(List<EChange> changes) {
val idResolver = IdResolver.create(view.viewResourceSet)
val idManager = new EChangeIdManager(idResolver)
changes.toList.reverseView.forEach[applyBackward]
changes.forEach[
idManager.setOrGenerateIds(it)
it.applyForward(idResolver)
]
}

override commitChanges() {
view.checkNotClosed()
changeRecorder.endRecording()
view.viewType.commitViewChanges(this, changeRecorder.change)
val recordedChange = changeRecorder.endRecording()
assignIds(recordedChange.EChanges)
view.viewType.commitViewChanges(this, recordedChange)
view.viewChanged = false
changeRecorder.beginRecording()
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
package tools.vitruv.framework.views.impl;

import static com.google.common.base.Preconditions.checkArgument;
import static edu.kit.ipd.sdq.commons.util.org.eclipse.emf.ecore.resource.ResourceSetUtil.withGlobalFactories;

import java.util.Collection;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

import org.eclipse.emf.ecore.resource.Resource;
import org.eclipse.emf.ecore.resource.ResourceSet;
import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl;

import tools.vitruv.change.atomic.EChangeUuidManager;
import tools.vitruv.change.atomic.id.IdResolver;
import tools.vitruv.change.atomic.uuid.UuidResolver;
import tools.vitruv.change.composite.description.VitruviusChange;
import tools.vitruv.framework.views.ChangeableViewSource;
import tools.vitruv.framework.views.View;
import tools.vitruv.framework.views.ViewSelection;
import tools.vitruv.framework.views.ViewSource;
import tools.vitruv.framework.views.selectors.DirectViewElementSelector;
import tools.vitruv.framework.views.util.ResourceCopier;

/**
* A view type that allows creating views based on a basic element-wise
* selection mechanism and providing a one-to-one (identity) mapping of elements
* within the {@link ViewSource} to a created {@link View}.
*/
public class IdentityMappingViewType extends AbstractViewType<DirectViewElementSelector> {
public IdentityMappingViewType(String name) {
super(name);
}

@Override
public DirectViewElementSelector createSelector(ChangeableViewSource viewSource) {
return new DirectViewElementSelector(this, viewSource,
viewSource.getViewSourceModels().stream().map(resource -> {
if (!resource.getContents().isEmpty() && ResourceCopier.requiresFullCopy(resource)) {
// We can only copy writable UML resources as a whole, so no option to select
JanWittler marked this conversation as resolved.
Show resolved Hide resolved
// specific root elements
return List.of(resource.getContents().get(0));
}
return resource.getContents();
}).flatMap(List::stream).filter(it -> it != null).collect(Collectors.toList()));
JanWittler marked this conversation as resolved.
Show resolved Hide resolved
}

@Override
public ModifiableView createView(DirectViewElementSelector selector) {
checkArgument(selector.getViewType() == this, "cannot create view with selector for different view type");
return new BasicView(selector.getViewType(), selector.getViewSource(), selector.getSelection());
}

@Override
public void updateView(ModifiableView view) {
view.modifyContents((viewResourceSet) -> {
viewResourceSet.getResources().forEach(Resource::unload);
viewResourceSet.getResources().clear();
createViewResources(view, viewResourceSet);
});
}

@Override
public void commitViewChanges(ModifiableView view, VitruviusChange viewChange) {
ResourceSet viewSourceCopyResourceSet = withGlobalFactories(new ResourceSetImpl());
IdResolver viewSourceCopyIdResolver = IdResolver.create(viewSourceCopyResourceSet);
UuidResolver viewSourceCopyUuidResolver = UuidResolver.create(viewSourceCopyResourceSet);
Map<Resource, Resource> mapping = createViewResources(view, viewSourceCopyResourceSet);
view.getViewSource().getUuidResolver().resolveResources(mapping, viewSourceCopyUuidResolver);

VitruviusChange resolvedChange = viewChange.unresolve().resolveAndApply(viewSourceCopyIdResolver);
EChangeUuidManager.setOrGenerateIds(resolvedChange.getEChanges(), viewSourceCopyUuidResolver);
view.getViewSource().propagateChange(resolvedChange.unresolve());
}

private Map<Resource, Resource> createViewResources(ModifiableView view, ResourceSet viewResourceSet) {
Collection<Resource> viewSources = view.getViewSource().getViewSourceModels();
ViewSelection selection = view.getSelection();
List<Resource> resourcesWithSelectedElements = viewSources.stream()
.filter(resource -> resource.getContents().stream().anyMatch(selection::isViewObjectSelected))
.collect(Collectors.toList());
JanWittler marked this conversation as resolved.
Show resolved Hide resolved
return ResourceCopier.copyViewSourceResources(resourcesWithSelectedElements, viewResourceSet,
selection::isViewObjectSelected);
}
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import org.eclipse.emf.common.util.URI

class VsumFileSystemLayout {
static final String CORRESPONDENCES_FILE = "correspondences.correspondence";
static final String UUIDS_FILE = "Uuid.uuid";
JanWittler marked this conversation as resolved.
Show resolved Hide resolved
static final String MODELS_FILE = "models.models";
static final String VSUM_FOLDER_NAME = "vsum";
static final String CONSISTENCY_METADATA_FOLDER_NAME = "consistencymetadata";
Expand Down Expand Up @@ -69,6 +70,11 @@ class VsumFileSystemLayout {
checkPrepared()
return vsumFolder.resolve(CORRESPONDENCES_FILE).toFile.createFileURI()
}

def URI getUuidsURI() {
checkPrepared()
return vsumFolder.resolve(UUIDS_FILE).toFile.createFileURI()
}

def Path getModelsNamesFilesPath() {
checkPrepared()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package tools.vitruv.framework.vsum.internal

import org.eclipse.emf.common.util.URI
import tools.vitruv.framework.views.ChangeableViewSource
import tools.vitruv.framework.vsum.VirtualModel
import tools.vitruv.change.correspondence.Correspondence
import tools.vitruv.change.correspondence.view.EditableCorrespondenceModelView
import tools.vitruv.framework.views.ChangeableViewSource
import tools.vitruv.framework.vsum.VirtualModel

interface InternalVirtualModel extends VirtualModel, ChangeableViewSource {
def EditableCorrespondenceModelView<Correspondence> getCorrespondenceModel()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package tools.vitruv.framework.vsum.internal

import org.eclipse.emf.common.util.URI
import java.util.Collection
import org.eclipse.emf.common.util.URI
import org.eclipse.emf.ecore.resource.Resource
import tools.vitruv.change.propagation.ChangeRecordingModelRepository

Expand Down
Loading