Bug 469728 - Possible loss/modification of UUIDs during migration
* Added test case based on attachments on bug
https://bugs.eclipse.org/bugs/show_bug.cgi?id=469728
Signed-off-by: Johannes Faltermeier <jfaltermeier@eclipsesource.com>
diff --git a/plugins/org.eclipse.emf.edapt.migration.test/src/org/eclipse/emf/edapt/migration/test/MigrationTestSuite.java b/plugins/org.eclipse.emf.edapt.migration.test/src/org/eclipse/emf/edapt/migration/test/MigrationTestSuite.java
index 27d1995..283dc08 100644
--- a/plugins/org.eclipse.emf.edapt.migration.test/src/org/eclipse/emf/edapt/migration/test/MigrationTestSuite.java
+++ b/plugins/org.eclipse.emf.edapt.migration.test/src/org/eclipse/emf/edapt/migration/test/MigrationTestSuite.java
@@ -72,7 +72,7 @@
/**
* Creates a {@link Test} which will be passed to {@link #addTest(Test)}.
- *
+ *
* @param caseDefinition the {@link TestCaseDefinition}
* @return the test to add
*/
@@ -112,7 +112,7 @@
}
/** Load the migrator from the history model. */
- private Migrator loadMigrator() throws IOException {
+ protected Migrator loadMigrator() throws IOException {
final History history = loadHistory();
final Migrator migrator = new Migrator(history, loader);
return migrator;
diff --git a/plugins/org.eclipse.emf.edapt.migration.ui/src/org/eclipse/emf/edapt/migration/ui/MigrationLaunchConfigurationDelegate.java b/plugins/org.eclipse.emf.edapt.migration.ui/src/org/eclipse/emf/edapt/migration/ui/MigrationLaunchConfigurationDelegate.java
index 92131bd..159c6af 100644
--- a/plugins/org.eclipse.emf.edapt.migration.ui/src/org/eclipse/emf/edapt/migration/ui/MigrationLaunchConfigurationDelegate.java
+++ b/plugins/org.eclipse.emf.edapt.migration.ui/src/org/eclipse/emf/edapt/migration/ui/MigrationLaunchConfigurationDelegate.java
@@ -93,12 +93,11 @@
}
/** Get the model files from the launch configuration. */
- @SuppressWarnings("unchecked")
private List<IFile> getModelFiles(ILaunchConfiguration configuration)
throws CoreException {
final List<IFile> files = new ArrayList<IFile>();
final List<String> modelURIs = configuration.getAttribute(MODELS.id(),
- Collections.emptyList());
+ Collections.<String> emptyList());
for (final String modelURI : modelURIs) {
final IFile file = FileUtils.getFile(modelURI);
files.add(file);
@@ -110,7 +109,7 @@
@Override
public void launch(final ILaunchConfiguration configuration, String mode,
final ILaunch launch, final IProgressMonitor monitor)
- throws CoreException {
+ throws CoreException {
final ILaunchManager launchManager = DebugPlugin.getDefault()
.getLaunchManager();
launchManager.addLaunchListener(new LaunchTerminationListener(
diff --git a/tests/org.eclipse.emf.edapt.tests/data/uuid/My.uuidbug b/tests/org.eclipse.emf.edapt.tests/data/uuid/My.uuidbug
new file mode 100644
index 0000000..b13e6e7
--- /dev/null
+++ b/tests/org.eclipse.emf.edapt.tests/data/uuid/My.uuidbug
@@ -0,0 +1,7 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<uuidBug:X xmi:version="2.0" xmlns:xmi="http://www.omg.org/XMI" xmlns:uuidBug="http://uuidBug.org/1.0" xmi:id="_PpP9sA6KEeWf8PYBnrK7MA">
+ <a xmi:id="_PpQkwA6KEeWf8PYBnrK7MA" name="a1"/>
+ <b xmi:id="_PpQkwQ6KEeWf8PYBnrK7MA" name="b1">
+ <a xmi:id="_PpQkwg6KEeWf8PYBnrK7MA" name="a2"/>
+ </b>
+</uuidBug:X>
diff --git a/tests/org.eclipse.emf.edapt.tests/data/uuid/_My.uuidbug b/tests/org.eclipse.emf.edapt.tests/data/uuid/_My.uuidbug
new file mode 100644
index 0000000..bc1126d
--- /dev/null
+++ b/tests/org.eclipse.emf.edapt.tests/data/uuid/_My.uuidbug
@@ -0,0 +1,7 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<uuidBug:X xmi:version="2.0" xmlns:xmi="http://www.omg.org/XMI" xmlns:uuidBug="http://uuidBug.org/2.0" xmi:id="_PpP9sA6KEeWf8PYBnrK7MA">
+ <a xmi:id="_PpQkwA6KEeWf8PYBnrK7MA" name="a1"/>
+ <b xmi:id="_PpQkwQ6KEeWf8PYBnrK7MA" name="b1">
+ <a xmi:id="_PpQkwg6KEeWf8PYBnrK7MA" name="a2"/>
+ </b>
+</uuidBug:X>
diff --git a/tests/org.eclipse.emf.edapt.tests/data/uuid/uuidBug.ecore b/tests/org.eclipse.emf.edapt.tests/data/uuid/uuidBug.ecore
new file mode 100644
index 0000000..8843bd1
--- /dev/null
+++ b/tests/org.eclipse.emf.edapt.tests/data/uuid/uuidBug.ecore
@@ -0,0 +1,15 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<ecore:EPackage xmi:version="2.0" xmlns:xmi="http://www.omg.org/XMI" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xmlns:ecore="http://www.eclipse.org/emf/2002/Ecore" name="uuidBug" nsURI="http://uuidBug.org/2.0" nsPrefix="uuidBug">
+ <eClassifiers xsi:type="ecore:EClass" name="X">
+ <eStructuralFeatures xsi:type="ecore:EReference" name="a" eType="#//A" containment="true"/>
+ <eStructuralFeatures xsi:type="ecore:EReference" name="b" eType="#//B" containment="true"/>
+ </eClassifiers>
+ <eClassifiers xsi:type="ecore:EClass" name="A">
+ <eStructuralFeatures xsi:type="ecore:EAttribute" name="name" eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EString"/>
+ </eClassifiers>
+ <eClassifiers xsi:type="ecore:EClass" name="B">
+ <eStructuralFeatures xsi:type="ecore:EAttribute" name="name" eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EString"/>
+ <eStructuralFeatures xsi:type="ecore:EReference" name="a" eType="#//A" containment="true"/>
+ </eClassifiers>
+</ecore:EPackage>
diff --git a/tests/org.eclipse.emf.edapt.tests/data/uuid/uuidBug.history b/tests/org.eclipse.emf.edapt.tests/data/uuid/uuidBug.history
new file mode 100644
index 0000000..be0ce24
--- /dev/null
+++ b/tests/org.eclipse.emf.edapt.tests/data/uuid/uuidBug.history
@@ -0,0 +1,77 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<history:History xmi:version="2.0" xmlns:xmi="http://www.omg.org/XMI" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xmlns:history="http://www.eclipse.org/emf/edapt/history/0.3">
+ <releases date="2015-06-09T11:32:42.587+0200">
+ <changes xsi:type="history:CompositeChange">
+ <changes xsi:type="history:Create" element="uuidBug.ecore#/">
+ <changes xsi:type="history:Set" element="uuidBug.ecore#/" featureName="name"
+ dataValue="uuidBug"/>
+ <changes xsi:type="history:Set" element="uuidBug.ecore#/" featureName="nsURI"
+ dataValue="http://uuidBug.org/1.0"/>
+ <changes xsi:type="history:Set" element="uuidBug.ecore#/" featureName="nsPrefix"
+ dataValue="uuidBug"/>
+ </changes>
+ <changes xsi:type="history:Create" target="uuidBug.ecore#/" referenceName="eClassifiers"
+ element="uuidBug.ecore#//X">
+ <changes xsi:type="history:Set" element="uuidBug.ecore#//X" featureName="name"
+ dataValue="X"/>
+ </changes>
+ <changes xsi:type="history:Create" target="uuidBug.ecore#/" referenceName="eClassifiers"
+ element="uuidBug.ecore#//A">
+ <changes xsi:type="history:Set" element="uuidBug.ecore#//A" featureName="name"
+ dataValue="A"/>
+ </changes>
+ <changes xsi:type="history:Create" target="uuidBug.ecore#//X" referenceName="eStructuralFeatures"
+ element="uuidBug.ecore#//X/a">
+ <changes xsi:type="history:Set" element="uuidBug.ecore#//X/a" featureName="name"
+ dataValue="a"/>
+ <changes xsi:type="history:Set" element="uuidBug.ecore#//X/a" featureName="containment"
+ dataValue="true" oldDataValue="false"/>
+ <changes xsi:type="history:Set" element="uuidBug.ecore#//X/a" featureName="eType"
+ referenceValue="uuidBug.ecore#//A"/>
+ </changes>
+ <changes xsi:type="history:Create" target="uuidBug.ecore#//A" referenceName="eStructuralFeatures"
+ element="uuidBug.ecore#//A/name">
+ <changes xsi:type="history:Set" element="uuidBug.ecore#//A/name" featureName="name"
+ dataValue="name"/>
+ <changes xsi:type="history:Set" element="uuidBug.ecore#//A/name" featureName="eType"
+ referenceValue="http://www.eclipse.org/emf/2002/Ecore#//EString"/>
+ </changes>
+ <changes xsi:type="history:Create" target="uuidBug.ecore#/" referenceName="eClassifiers"
+ element="uuidBug.ecore#//B">
+ <changes xsi:type="history:Set" element="uuidBug.ecore#//B" featureName="name"
+ dataValue="B"/>
+ </changes>
+ <changes xsi:type="history:Create" target="uuidBug.ecore#//X" referenceName="eStructuralFeatures"
+ element="uuidBug.ecore#//X/b">
+ <changes xsi:type="history:Set" element="uuidBug.ecore#//X/b" featureName="name"
+ dataValue="b"/>
+ <changes xsi:type="history:Set" element="uuidBug.ecore#//X/b" featureName="containment"
+ dataValue="true" oldDataValue="false"/>
+ <changes xsi:type="history:Set" element="uuidBug.ecore#//X/b" featureName="eType"
+ referenceValue="uuidBug.ecore#//B"/>
+ </changes>
+ <changes xsi:type="history:Create" target="uuidBug.ecore#//B" referenceName="eStructuralFeatures"
+ element="uuidBug.ecore#//B/name">
+ <changes xsi:type="history:Set" element="uuidBug.ecore#//B/name" featureName="name"
+ dataValue="name"/>
+ <changes xsi:type="history:Set" element="uuidBug.ecore#//B/name" featureName="eType"
+ referenceValue="http://www.eclipse.org/emf/2002/Ecore#//EString"/>
+ </changes>
+ <changes xsi:type="history:Create" target="uuidBug.ecore#//B" referenceName="eStructuralFeatures"
+ element="uuidBug.ecore#//B/a">
+ <changes xsi:type="history:Set" element="uuidBug.ecore#//B/a" featureName="name"
+ dataValue="a"/>
+ <changes xsi:type="history:Set" element="uuidBug.ecore#//B/a" featureName="containment"
+ dataValue="true" oldDataValue="false"/>
+ <changes xsi:type="history:Set" element="uuidBug.ecore#//B/a" featureName="eType"
+ referenceValue="uuidBug.ecore#//A"/>
+ </changes>
+ </changes>
+ </releases>
+ <releases date="2015-06-09T11:32:48.575+0200" label="2.0">
+ <changes xsi:type="history:Set" element="uuidBug.ecore#/" featureName="nsURI"
+ dataValue="http://uuidBug.org/2.0" oldDataValue="http://uuidBug.org/1.0"/>
+ </releases>
+ <releases/>
+</history:History>
diff --git a/tests/org.eclipse.emf.edapt.tests/data/uuid/uuidBug.test b/tests/org.eclipse.emf.edapt.tests/data/uuid/uuidBug.test
new file mode 100644
index 0000000..13fbe90
--- /dev/null
+++ b/tests/org.eclipse.emf.edapt.tests/data/uuid/uuidBug.test
@@ -0,0 +1,11 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<test:TestSuiteDefinition
+ xmi:version="2.0"
+ xmlns:xmi="http://www.omg.org/XMI"
+ xmlns:test="http://www.eclipse.org/emf/edapt/migration/test/0.3"
+ name="UUID Migration"
+ history="uuidBug.history">
+ <cases name="Test UUIDs are same after migration"
+ model="My.uuidbug"
+ expectedModel="_My.uuidbug"/>
+</test:TestSuiteDefinition>
diff --git a/tests/org.eclipse.emf.edapt.tests/src/org/eclipse/emf/edapt/tests/migration/MigrationTest.java b/tests/org.eclipse.emf.edapt.tests/src/org/eclipse/emf/edapt/tests/migration/MigrationTest.java
index 77c2754..f9fd063 100644
--- a/tests/org.eclipse.emf.edapt.tests/src/org/eclipse/emf/edapt/tests/migration/MigrationTest.java
+++ b/tests/org.eclipse.emf.edapt.tests/src/org/eclipse/emf/edapt/tests/migration/MigrationTest.java
@@ -14,15 +14,23 @@
import java.io.File;
import java.io.IOException;
-import junit.framework.Test;
-import junit.framework.TestSuite;
-
import org.eclipse.emf.common.util.URI;
+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.xmi.impl.XMIResourceFactoryImpl;
+import org.eclipse.emf.ecore.xmi.impl.XMIResourceImpl;
+import org.eclipse.emf.edapt.common.IResourceSetFactory;
import org.eclipse.emf.edapt.internal.common.FileUtils;
import org.eclipse.emf.edapt.internal.common.URIUtils;
+import org.eclipse.emf.edapt.internal.migration.execution.IClassLoader;
import org.eclipse.emf.edapt.internal.migration.execution.internal.ClassLoaderFacade;
+import org.eclipse.emf.edapt.migration.execution.Migrator;
import org.eclipse.emf.edapt.migration.test.MigrationTestSuite;
+import junit.framework.Test;
+import junit.framework.TestSuite;
+
/**
* Test of model migrations defined by test models.
*
@@ -53,9 +61,9 @@
if (extension != null && "test".equals(extension)) { //$NON-NLS-1$
final URI uri = URIUtils.getURI(file);
try {
- suite.addTest(new MigrationTestSuite(uri,
- new ClassLoaderFacade(MigrationTest.class
- .getClassLoader())));
+ final MigrationTestSuite migrationTestSuite = new UUIDMigrationTestSuite(
+ uri, new ClassLoaderFacade(MigrationTest.class.getClassLoader()));
+ suite.addTest(migrationTestSuite);
} catch (final IOException e) {
e.printStackTrace();
}
@@ -63,4 +71,39 @@
}
}
}
+
+ private static final class UUIDMigrationTestSuite extends MigrationTestSuite {
+ private UUIDMigrationTestSuite(URI definitionURI, IClassLoader loader) throws IOException {
+ super(definitionURI, loader);
+ }
+
+ @Override
+ protected org.eclipse.emf.edapt.migration.execution.Migrator loadMigrator()
+ throws IOException {
+ final Migrator loadedMigrator = super.loadMigrator();
+ loadedMigrator.setResourceSetFactory(new IResourceSetFactory() {
+ @Override
+ public ResourceSet createResourceSet() {
+ final ResourceSetImpl resourceSet = new ResourceSetImpl();
+ resourceSet.getResourceFactoryRegistry().getExtensionToFactoryMap().put(
+ Resource.Factory.Registry.DEFAULT_EXTENSION, new UuidResourceFactory());
+ return resourceSet;
+ }
+ });
+ return loadedMigrator;
+ }
+
+ private static class UuidResourceFactory extends XMIResourceFactoryImpl {
+ @Override
+ public Resource createResource(URI uri) {
+ return new XMIResourceImpl(uri) {
+ @Override
+ protected boolean useUUIDs() {
+ return true;
+ }
+ };
+ }
+ }
+ }
+
}