Bug 486562 - Migration of existing change package fails on client
Fix case in which local change package needs to be migrated, but is
an proxy, i.e. the operations.eoc file is empty
Change-Id: I5ce8f6745622383b75c836bceef7da058cf1ae21
diff --git a/bundles/org.eclipse.emf.emfstore.client/src/org/eclipse/emf/emfstore/internal/client/model/impl/ProjectSpaceBase.java b/bundles/org.eclipse.emf.emfstore.client/src/org/eclipse/emf/emfstore/internal/client/model/impl/ProjectSpaceBase.java
index 6743ae1..74d9d65 100644
--- a/bundles/org.eclipse.emf.emfstore.client/src/org/eclipse/emf/emfstore/internal/client/model/impl/ProjectSpaceBase.java
+++ b/bundles/org.eclipse.emf.emfstore.client/src/org/eclipse/emf/emfstore/internal/client/model/impl/ProjectSpaceBase.java
@@ -660,28 +660,12 @@
initPropertyMap();
final URI localChangePackageUri = ESClientURIUtil.createOperationsURI(this);
- AbstractChangePackage localChangePackage = getLocalChangePackage();
+ final AbstractChangePackage localChangePackage = getLocalChangePackage();
if (localChangePackage == null) {
- if (Configuration.getClientBehavior().useInMemoryChangePackage()) {
- localChangePackage = VersioningFactory.eINSTANCE.createChangePackage();
- final Resource resource = getResourceSet().createResource(localChangePackageUri);
- resource.getContents().add(localChangePackage);
- } else {
- final URI normalizedUri = getResourceSet().getURIConverter().normalize(localChangePackageUri);
- final String filePath = normalizedUri.toFileString();
- localChangePackage = VersioningFactory.eINSTANCE.createFileBasedChangePackage();
- ((FileBasedChangePackage) localChangePackage)
- .initialize(filePath + FileBasedChangePackageImpl.FILE_OP_INDEX);
- final Resource resource = getResourceSet().createResource(localChangePackageUri);
- resource.getContents().add(localChangePackage);
- try {
- resource.save(ModelUtil.getResourceSaveOptions());
- } catch (final IOException ex) {
- WorkspaceUtil.logException(ex.getMessage(), ex);
- }
- }
- setChangePackage(localChangePackage);
+ setChangePackage(createChangePackage(localChangePackageUri, true));
+ } else if (localChangePackage.eIsProxy()) {
+ setChangePackage(createChangePackage(localChangePackageUri, false));
} else {
if (!Configuration.getClientBehavior().useInMemoryChangePackage()) {
final FileBasedChangePackage changePackage = (FileBasedChangePackage) getLocalChangePackage();
@@ -719,13 +703,48 @@
cleanCutElements();
}
+ private AbstractChangePackage createChangePackage(URI localChangePackageUri, boolean initialize) {
+
+ AbstractChangePackage localChangePackage;
+
+ if (Configuration.getClientBehavior().useInMemoryChangePackage()) {
+ localChangePackage = VersioningFactory.eINSTANCE.createChangePackage();
+ final Resource resource = getResourceSet().createResource(localChangePackageUri);
+ resource.getContents().add(localChangePackage);
+ } else {
+ final URI normalizedUri = getResourceSet().getURIConverter().normalize(localChangePackageUri);
+ final String filePath = normalizedUri.toFileString();
+ localChangePackage = VersioningFactory.eINSTANCE.createFileBasedChangePackage();
+
+ if (initialize) {
+ ((FileBasedChangePackage) localChangePackage)
+ .initialize(filePath + FileBasedChangePackageImpl.FILE_OP_INDEX);
+ } else {
+ ((FileBasedChangePackage) localChangePackage).setFilePath(
+ filePath + FileBasedChangePackageImpl.FILE_OP_INDEX);
+ }
+
+ final Resource resource = getResourceSet().createResource(localChangePackageUri);
+ resource.getContents().add(localChangePackage);
+ try {
+ resource.save(ModelUtil.getResourceSaveOptions());
+ } catch (final IOException ex) {
+ WorkspaceUtil.logException(ex.getMessage(), ex);
+ }
+ }
+
+ return localChangePackage;
+ }
+
private void migrateFileBasedChangePackageIntoDedicatedResource(final URI localChangePackageUri,
final FileBasedChangePackage changePackage) {
final URI normalizedUri = getResourceSet().getURIConverter().normalize(localChangePackageUri);
final String filePath = normalizedUri.toFileString();
+
final String tempPath = changePackage.getTempFilePath();
final String path = changePackage.getFilePath();
+
RunESCommand.run(new ESVoidCallable() {
@Override
public void run() {
@@ -733,19 +752,27 @@
}
});
- try {
- FileUtils.moveFile(new File(tempPath), new File(changePackage.getTempFilePath()));
- FileUtils.moveFile(new File(path), new File(changePackage.getFilePath()));
- } catch (final IOException ex) {
- WorkspaceUtil.logException(ex.getMessage(), ex);
+ if (path != null) {
+ // temp file depends on path
+ try {
+ FileUtils.moveFile(new File(tempPath), new File(changePackage.getTempFilePath()));
+ FileUtils.moveFile(new File(path), new File(changePackage.getFilePath()));
+ } catch (final IOException ex) {
+ WorkspaceUtil.logException(ex.getMessage(), ex);
+ }
}
+ Resource resource = getResourceSet().getResource(localChangePackageUri, true);
+ if (resource == null) {
+ resource = getResourceSet().createResource(localChangePackageUri);
+ }
+
+ final Resource r = resource;
// move change package into its own resource
- final Resource resource = getResourceSet().createResource(localChangePackageUri);
RunESCommand.run(new ESVoidCallable() {
@Override
public void run() {
- resource.getContents().add(changePackage);
+ r.getContents().add(changePackage);
setChangePackage(changePackage);
}
});