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

Fix usage of ResourceSet in DefaultStateBasedChangeResolutionStrategy & DeltaBasedResource #69

Merged
merged 1 commit into from
May 8, 2023
Merged
Show file tree
Hide file tree
Changes from all 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
@@ -1,5 +1,6 @@
package tools.vitruv.change.changederivation

import edu.kit.ipd.sdq.commons.util.org.eclipse.emf.ecore.resource.ResourceCopier
import org.eclipse.emf.common.notify.Notifier
import org.eclipse.emf.common.util.BasicMonitor
import org.eclipse.emf.compare.EMFCompare
Expand All @@ -19,11 +20,11 @@ import tools.vitruv.change.composite.description.VitruviusChange
import tools.vitruv.change.composite.recording.ChangeRecorder

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

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
import edu.kit.ipd.sdq.commons.util.org.eclipse.emf.ecore.resource.ResourceCopier

/**
* This default strategy for diff based state changes uses EMFCompare to resolve a
Expand Down Expand Up @@ -74,7 +75,7 @@ class DefaultStateBasedChangeResolutionStrategy implements StateBasedChangeResol
newState.checkNoProxies("new state")
// It is possible that root elements are automatically generated during resource creation (e.g., Java packages).
// Thus, we create the resource and then monitor the re-insertion of the elements
val monitoredResourceSet = new ResourceSetImpl()
val monitoredResourceSet = withGlobalFactories(new ResourceSetImpl());
val newResource = monitoredResourceSet.createResource(newState.URI)
newResource.contents.clear()
return newResource.record [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl
import tools.vitruv.change.atomic.EChange
import tools.vitruv.change.atomic.id.IdResolver
import tools.vitruv.change.composite.description.VitruviusChangeFactory
import static edu.kit.ipd.sdq.commons.util.org.eclipse.emf.ecore.resource.ResourceSetUtil.withGlobalFactories

class DeltaBasedResource extends ResourceImpl {

Expand All @@ -20,7 +21,7 @@ class DeltaBasedResource extends ResourceImpl {
}

private static def List<EChange> loadDeltas(URI modelUri) {
val resourceSet = new ResourceSetImpl();
val resourceSet = withGlobalFactories(new ResourceSetImpl());
val resource = resourceSet.getResource(modelUri, true);
return resource.getContents().map[it as EChange].toList
}
Expand All @@ -32,8 +33,8 @@ class DeltaBasedResource extends ResourceImpl {

override doSave(OutputStream outputStream, Map<?, ?> options) throws IOException {
val deltaChanges = new DefaultStateBasedChangeResolutionStrategy().getChangeSequenceForCreated(this).EChanges;
val resSet = new ResourceSetImpl();
val resource = resSet.createResource(this.URI);
val resourceSet = withGlobalFactories(new ResourceSetImpl());
val resource = resourceSet.createResource(this.URI);
resource.getContents().addAll(deltaChanges)
try (val out = outputStream){
resource.save(out, Collections.EMPTY_MAP)
Expand Down