Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMarkus Herrmannsdoerfer2012-06-03 16:02:10 +0000
committerMarkus Herrmannsdoerfer2012-06-03 16:02:10 +0000
commit15a8491b2f333546892a89249e02c22efd21fb91 (patch)
treeaf49787b808d524672f69ee4659b04a38464bc1a
parenta613658799e0d32b0cbb3c34b2b4c62a2851a9f7 (diff)
downloadorg.eclipse.emf.edapt-15a8491b2f333546892a89249e02c22efd21fb91.tar.gz
org.eclipse.emf.edapt-15a8491b2f333546892a89249e02c22efd21fb91.tar.xz
org.eclipse.emf.edapt-15a8491b2f333546892a89249e02c22efd21fb91.zip
[377037]
support for configuring serialization during migration
-rw-r--r--plugins/org.eclipse.emf.edapt.common/src/org/eclipse/emf/edapt/common/IResourceSetFactory.java17
-rw-r--r--plugins/org.eclipse.emf.edapt.common/src/org/eclipse/emf/edapt/common/ResourceSetFactoryImpl.java22
-rw-r--r--plugins/org.eclipse.emf.edapt.common/src/org/eclipse/emf/edapt/common/ResourceUtils.java28
-rw-r--r--plugins/org.eclipse.emf.edapt.declaration/src/org/eclipse/emf/edapt/declaration/OperationRegistry.java450
-rw-r--r--plugins/org.eclipse.emf.edapt.history/src/org/eclipse/emf/edapt/migration/execution/MigrationReconstructor.java11
-rw-r--r--plugins/org.eclipse.emf.edapt.history/src/org/eclipse/emf/edapt/migration/execution/Migrator.java19
-rw-r--r--plugins/org.eclipse.emf.edapt.migration.ui/src/org/eclipse/emf/edapt/migration/ui/MigratorHandlerBase.java13
-rw-r--r--plugins/org.eclipse.emf.edapt.migration/src/org/eclipse/emf/edapt/migration/Persistency.java61
-rw-r--r--tests/org.eclipse.emf.edapt.tests/data/node/Graph1.xmi6
-rw-r--r--tests/org.eclipse.emf.edapt.tests/data/node/Graph2.xmi4
-rw-r--r--tests/org.eclipse.emf.edapt.tests/data/node/node2.ecore15
-rw-r--r--tests/org.eclipse.emf.edapt.tests/data/node/node2.history71
-rw-r--r--tests/org.eclipse.emf.edapt.tests/src/org/eclipse/emf/edapt/tests/migration/ConverterTest.java109
-rw-r--r--tests/org.eclipse.emf.edapt.tests/src/org/eclipse/emf/edapt/tests/migration/CustomSerializationTest.java76
14 files changed, 586 insertions, 316 deletions
diff --git a/plugins/org.eclipse.emf.edapt.common/src/org/eclipse/emf/edapt/common/IResourceSetFactory.java b/plugins/org.eclipse.emf.edapt.common/src/org/eclipse/emf/edapt/common/IResourceSetFactory.java
new file mode 100644
index 0000000..0999e33
--- /dev/null
+++ b/plugins/org.eclipse.emf.edapt.common/src/org/eclipse/emf/edapt/common/IResourceSetFactory.java
@@ -0,0 +1,17 @@
+package org.eclipse.emf.edapt.common;
+
+import org.eclipse.emf.ecore.resource.ResourceSet;
+
+/**
+ * Factory to create {@link ResourceSet}s for customizing serialization.
+ *
+ * @author herrmi
+ * @author $Author: hummelb $
+ * @version $Rev: 18709 $
+ * @levd.rating RED Rev:
+ */
+public interface IResourceSetFactory {
+
+ /** Create an instance of an implementation of {@link ResourceSet}. */
+ ResourceSet createResourceSet();
+}
diff --git a/plugins/org.eclipse.emf.edapt.common/src/org/eclipse/emf/edapt/common/ResourceSetFactoryImpl.java b/plugins/org.eclipse.emf.edapt.common/src/org/eclipse/emf/edapt/common/ResourceSetFactoryImpl.java
new file mode 100644
index 0000000..bd10360
--- /dev/null
+++ b/plugins/org.eclipse.emf.edapt.common/src/org/eclipse/emf/edapt/common/ResourceSetFactoryImpl.java
@@ -0,0 +1,22 @@
+package org.eclipse.emf.edapt.common;
+
+import org.eclipse.emf.ecore.resource.ResourceSet;
+import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl;
+
+/**
+ * Default implementation of {@link IResourceSetFactory} returning an instance
+ * of {@link ResourceSetImpl}.
+ *
+ * @author herrmi
+ * @author $Author: hummelb $
+ * @version $Rev: 18709 $
+ * @levd.rating RED Rev:
+ */
+public class ResourceSetFactoryImpl implements IResourceSetFactory {
+
+ /** {@inheritDoc} */
+ public ResourceSet createResourceSet() {
+ return new ResourceSetImpl();
+ }
+
+}
diff --git a/plugins/org.eclipse.emf.edapt.common/src/org/eclipse/emf/edapt/common/ResourceUtils.java b/plugins/org.eclipse.emf.edapt.common/src/org/eclipse/emf/edapt/common/ResourceUtils.java
index 85c32da..00fd504 100644
--- a/plugins/org.eclipse.emf.edapt.common/src/org/eclipse/emf/edapt/common/ResourceUtils.java
+++ b/plugins/org.eclipse.emf.edapt.common/src/org/eclipse/emf/edapt/common/ResourceUtils.java
@@ -71,7 +71,17 @@ public final class ResourceUtils {
*/
public static ResourceSet loadResourceSet(List<URI> modelURIs,
List<EPackage> ePackages) throws IOException {
- ResourceSet resourceSet = new ResourceSetImpl();
+ return loadResourceSet(modelURIs, ePackages,
+ new ResourceSetFactoryImpl());
+ }
+
+ /**
+ * Load EMF model based on a set of {@link URI} and root packages.
+ */
+ public static ResourceSet loadResourceSet(List<URI> modelURIs,
+ List<EPackage> ePackages, IResourceSetFactory resourceSetFactory)
+ throws IOException {
+ ResourceSet resourceSet = resourceSetFactory.createResourceSet();
register(ePackages, resourceSet.getPackageRegistry());
Map<String, Object> options = new HashMap<String, Object>();
@@ -133,12 +143,14 @@ public final class ResourceUtils {
* Load EMF model based on file name (use the packages already added to the
* registry).
*/
- public static ResourceSet loadResourceSet(String fileName) throws IOException {
+ public static ResourceSet loadResourceSet(String fileName)
+ throws IOException {
return loadResourceSet(fileName, new ArrayList<EPackage>());
}
/** Save model based on {@link ResourceSet}. */
- public static void saveResourceSet(ResourceSet resourceSet) throws IOException {
+ public static void saveResourceSet(ResourceSet resourceSet)
+ throws IOException {
Map<String, Object> options = new HashMap<String, Object>();
options.put(XMLResource.OPTION_SCHEMA_LOCATION, Boolean.FALSE);
for (Resource resource : resourceSet.getResources()) {
@@ -220,17 +232,19 @@ public final class ResourceUtils {
/** Decide whether a resource is a platform resource. */
public static boolean isPlatformResource(Resource resource) {
- return resource != null && PLATFORM_SCHEME.equals(resource.getURI().scheme());
+ return resource != null
+ && PLATFORM_SCHEME.equals(resource.getURI().scheme());
}
/** Resolve all referenced resources within a {@link ResourceSet}. */
public static void resolveAll(ResourceSet resourceSet) {
Set<Resource> resolved = new HashSet<Resource>();
boolean newFound = true;
- while(newFound) {
+ while (newFound) {
newFound = false;
- for(Resource r : new ArrayList<Resource>(resourceSet.getResources())) {
- if(!resolved.contains(r)) {
+ for (Resource r : new ArrayList<Resource>(
+ resourceSet.getResources())) {
+ if (!resolved.contains(r)) {
newFound = true;
org.eclipse.emf.ecore.util.EcoreUtil.resolveAll(r);
resolved.add(r);
diff --git a/plugins/org.eclipse.emf.edapt.declaration/src/org/eclipse/emf/edapt/declaration/OperationRegistry.java b/plugins/org.eclipse.emf.edapt.declaration/src/org/eclipse/emf/edapt/declaration/OperationRegistry.java
index a0e8101..b7c756a 100644
--- a/plugins/org.eclipse.emf.edapt.declaration/src/org/eclipse/emf/edapt/declaration/OperationRegistry.java
+++ b/plugins/org.eclipse.emf.edapt.declaration/src/org/eclipse/emf/edapt/declaration/OperationRegistry.java
@@ -1,224 +1,226 @@
-/*******************************************************************************
- * Copyright (c) 2006, 2009 Markus Herrmannsdoerfer.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * Markus Herrmannsdoerfer - initial API and implementation
- *******************************************************************************/
-package org.eclipse.emf.edapt.declaration;
-
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-
-import org.eclipse.core.runtime.CoreException;
-import org.eclipse.core.runtime.IConfigurationElement;
-import org.eclipse.core.runtime.IExtensionRegistry;
-import org.eclipse.core.runtime.Platform;
-import org.eclipse.emf.edapt.common.LoggingUtils;
-import org.eclipse.emf.edapt.migration.MigrationPlugin;
-
-/**
- * Registry for all operations (singleton). A set of operations is registered as
- * a Eclipse extension.
- *
- * @author herrmama
- * @author $Author: mherrmannsd $
- * @version $Rev: 117 $
- * @levd.rating YELLOW Hash: 5D6B6EEEA0BB217D3762F008E642AA6F
- */
-public class OperationRegistry {
-
- /** Singleton instance. */
- private static OperationRegistry instance;
-
- /** All registered operations identified by name. */
- private Map<String, Operation> operations;
-
- /** Operations that need to be performed before an operation. */
- private Map<Operation, List<Operation>> beforeOperations;
-
- /** Operations that need to be performed after an operation. */
- private Map<Operation, List<Operation>> afterOperations;
-
- /** List of registered operation containers. */
- private Library rootLibrary;
-
- /** Private default constructor. */
- private OperationRegistry() {
- registerLibrary();
- initDependencies();
- }
-
- /** Initialize the dependencies between the operations. */
- private void initDependencies() {
- for (Operation operation : getOperations()) {
- if (operation.getBefore() != null) {
- Operation before = getOperation(operation.getBefore());
- addBefore(operation, before);
- }
- if (operation.getAfter() != null) {
- Operation after = getOperation(operation.getAfter());
- addAfter(operation, after);
- }
- }
- }
-
- /** Get the operations that need to be performed before an operation. */
- public List<Operation> getBefore(Operation operation) {
- List<Operation> operations = beforeOperations.get(operation);
- if (operations == null) {
- return Collections.emptyList();
- }
- return operations;
- }
-
- /**
- * Add a dependency saying that an operation needs to be performed before an
- * operation.
- */
- private void addBefore(Operation operation, Operation before) {
- List<Operation> operations = beforeOperations.get(before);
- if (operations == null) {
- operations = new ArrayList<Operation>();
- beforeOperations.put(before, operations);
- }
- operations.add(operation);
- }
-
- /** Get the operations that need to be performed after an operation. */
- public List<Operation> getAfter(Operation operation) {
- List<Operation> operations = afterOperations.get(operation);
- if (operations == null) {
- return Collections.emptyList();
- }
- return operations;
- }
-
- /**
- * Add a dependency saying that an operation needs to be performed after an
- * operation.
- */
- private void addAfter(Operation operation, Operation after) {
- List<Operation> operations = afterOperations.get(after);
- if (operations == null) {
- operations = new ArrayList<Operation>();
- afterOperations.put(after, operations);
- }
- operations.add(operation);
- }
-
- /** Register the operations defined by extensions. */
- private void registerLibrary() {
- operations = new HashMap<String, Operation>();
- beforeOperations = new HashMap<Operation, List<Operation>>();
- afterOperations = new HashMap<Operation, List<Operation>>();
- rootLibrary = DeclarationFactory.eINSTANCE.createLibrary();
- rootLibrary.setName("root");
- rootLibrary.setLabel("Root library");
- rootLibrary.setDescription("Root library of the operation registry");
-
- if (Platform.isRunning()) {
- IExtensionRegistry extensionRegistry = Platform
- .getExtensionRegistry();
- IConfigurationElement[] configurationElements = extensionRegistry
- .getConfigurationElementsFor("org.eclipse.emf.edapt.operations");
-
- for (int i = 0, n = configurationElements.length; i < n; i++) {
- IConfigurationElement configurationElement = configurationElements[i];
- register(configurationElement);
- }
- }
- }
-
- /** Register a configuration element. */
- @SuppressWarnings("unchecked")
- private void register(IConfigurationElement configurationElement) {
- try {
- Class c = configurationElement.createExecutableExtension(
- "class").getClass();
- if ("operation".equals(configurationElement.getName())) {
- registerOperation(c);
- } else if ("library".equals(configurationElement.getName())) {
- registerLibrary(c);
- }
- } catch (CoreException e) {
- // do not register operations that are declared erroneously.
- }
- }
-
- /** Register the implementation of an operation. */
- public void registerOperation(Class<? extends OperationImplementation> c) {
- Operation operation = new OperationExtractor().extractOperation(c);
- if (operation != null) {
- initOperation(operation);
- rootLibrary.getOperations().add(operation);
- }
- }
-
- /**
- * Register one operation (if the name is not already occupied by another
- * operation).
- */
- private void initOperation(Operation operation) {
- String name = operation.getName();
- if (operations.get(name) != null) {
- LoggingUtils.logError(MigrationPlugin.getPlugin(),
- "Duplicate operation name: " + name);
- }
- operations.put(name, operation);
- }
-
- /** Register the implementation of a library. */
- public void registerLibrary(Class<? extends LibraryImplementation> c) {
- Library library = new LibraryExtractor().extractLibrary(c);
- if (library != null) {
- initLibrary(library);
- rootLibrary.getLibraries().add(library);
- }
- }
-
- /** Register the operations provided by a library. */
- private void initLibrary(Library library) {
- for (Operation operation : library.getOperations()) {
- initOperation(operation);
- }
- for (Library subLibrary : library.getLibraries()) {
- initLibrary(subLibrary);
- }
- }
-
- /** Getter for instance. */
- public static OperationRegistry getInstance() {
- if (instance == null) {
- instance = new OperationRegistry();
- }
- return instance;
- }
-
- /** Get a list of all operations. */
- public Collection<Operation> getOperations() {
- return operations.values();
- }
-
- /** Get an operation by name. */
- public Operation getOperation(String name) {
- return operations.get(name);
- }
-
- /** Get the root libraries. */
- public List<Library> getRootLibraries() {
- return new ArrayList<Library>(rootLibrary.getLibraries());
- }
-
- /** Get the root operations. */
- public List<Operation> getRootOperations() {
- return new ArrayList<Operation>(rootLibrary.getOperations());
- }
-}
+/*******************************************************************************
+ * Copyright (c) 2006, 2009 Markus Herrmannsdoerfer.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Markus Herrmannsdoerfer - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.emf.edapt.declaration;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IConfigurationElement;
+import org.eclipse.core.runtime.IExtensionRegistry;
+import org.eclipse.core.runtime.Platform;
+import org.eclipse.emf.edapt.common.LoggingUtils;
+import org.eclipse.emf.edapt.migration.MigrationPlugin;
+
+/**
+ * Registry for all operations (singleton). A set of operations is registered as
+ * a Eclipse extension.
+ *
+ * @author herrmama
+ * @author $Author$
+ * @version $Rev$
+ * @levd.rating YELLOW Hash: 5D6B6EEEA0BB217D3762F008E642AA6F
+ */
+public class OperationRegistry {
+
+ /** Singleton instance. */
+ private static OperationRegistry instance;
+
+ /** All registered operations identified by name. */
+ private Map<String, Operation> operations;
+
+ /** Operations that need to be performed before an operation. */
+ private Map<Operation, List<Operation>> beforeOperations;
+
+ /** Operations that need to be performed after an operation. */
+ private Map<Operation, List<Operation>> afterOperations;
+
+ /** List of registered operation containers. */
+ private Library rootLibrary;
+
+ /** Private default constructor. */
+ private OperationRegistry() {
+ registerLibrary();
+ initDependencies();
+ }
+
+ /** Initialize the dependencies between the operations. */
+ private void initDependencies() {
+ for (Operation operation : getOperations()) {
+ if (operation.getBefore() != null) {
+ Operation before = getOperation(operation.getBefore());
+ addBefore(operation, before);
+ }
+ if (operation.getAfter() != null) {
+ Operation after = getOperation(operation.getAfter());
+ addAfter(operation, after);
+ }
+ }
+ }
+
+ /** Get the operations that need to be performed before an operation. */
+ public List<Operation> getBefore(Operation operation) {
+ List<Operation> operations = beforeOperations.get(operation);
+ if (operations == null) {
+ return Collections.emptyList();
+ }
+ return operations;
+ }
+
+ /**
+ * Add a dependency saying that an operation needs to be performed before an
+ * operation.
+ */
+ private void addBefore(Operation operation, Operation before) {
+ List<Operation> operations = beforeOperations.get(before);
+ if (operations == null) {
+ operations = new ArrayList<Operation>();
+ beforeOperations.put(before, operations);
+ }
+ operations.add(operation);
+ }
+
+ /** Get the operations that need to be performed after an operation. */
+ public List<Operation> getAfter(Operation operation) {
+ List<Operation> operations = afterOperations.get(operation);
+ if (operations == null) {
+ return Collections.emptyList();
+ }
+ return operations;
+ }
+
+ /**
+ * Add a dependency saying that an operation needs to be performed after an
+ * operation.
+ */
+ private void addAfter(Operation operation, Operation after) {
+ List<Operation> operations = afterOperations.get(after);
+ if (operations == null) {
+ operations = new ArrayList<Operation>();
+ afterOperations.put(after, operations);
+ }
+ operations.add(operation);
+ }
+
+ /** Register the operations defined by extensions. */
+ private void registerLibrary() {
+ operations = new HashMap<String, Operation>();
+ beforeOperations = new HashMap<Operation, List<Operation>>();
+ afterOperations = new HashMap<Operation, List<Operation>>();
+ rootLibrary = DeclarationFactory.eINSTANCE.createLibrary();
+ rootLibrary.setName("root");
+ rootLibrary.setLabel("Root library");
+ rootLibrary.setDescription("Root library of the operation registry");
+
+ if (Platform.isRunning()) {
+ IExtensionRegistry extensionRegistry = Platform
+ .getExtensionRegistry();
+ IConfigurationElement[] configurationElements = extensionRegistry
+ .getConfigurationElementsFor("org.eclipse.emf.edapt.operations");
+
+ for (int i = 0, n = configurationElements.length; i < n; i++) {
+ IConfigurationElement configurationElement = configurationElements[i];
+ register(configurationElement);
+ }
+ } else {
+ registerLibrary(BaseLibrary.class);
+ }
+ }
+
+ /** Register a configuration element. */
+ @SuppressWarnings("unchecked")
+ private void register(IConfigurationElement configurationElement) {
+ try {
+ Class c = configurationElement.createExecutableExtension("class")
+ .getClass();
+ if ("operation".equals(configurationElement.getName())) {
+ registerOperation(c);
+ } else if ("library".equals(configurationElement.getName())) {
+ registerLibrary(c);
+ }
+ } catch (CoreException e) {
+ // do not register operations that are declared erroneously.
+ }
+ }
+
+ /** Register the implementation of an operation. */
+ public void registerOperation(Class<? extends OperationImplementation> c) {
+ Operation operation = new OperationExtractor().extractOperation(c);
+ if (operation != null) {
+ initOperation(operation);
+ rootLibrary.getOperations().add(operation);
+ }
+ }
+
+ /**
+ * Register one operation (if the name is not already occupied by another
+ * operation).
+ */
+ private void initOperation(Operation operation) {
+ String name = operation.getName();
+ if (operations.get(name) != null) {
+ LoggingUtils.logError(MigrationPlugin.getPlugin(),
+ "Duplicate operation name: " + name);
+ }
+ operations.put(name, operation);
+ }
+
+ /** Register the implementation of a library. */
+ public void registerLibrary(Class<? extends LibraryImplementation> c) {
+ Library library = new LibraryExtractor().extractLibrary(c);
+ if (library != null) {
+ initLibrary(library);
+ rootLibrary.getLibraries().add(library);
+ }
+ }
+
+ /** Register the operations provided by a library. */
+ private void initLibrary(Library library) {
+ for (Operation operation : library.getOperations()) {
+ initOperation(operation);
+ }
+ for (Library subLibrary : library.getLibraries()) {
+ initLibrary(subLibrary);
+ }
+ }
+
+ /** Getter for instance. */
+ public static OperationRegistry getInstance() {
+ if (instance == null) {
+ instance = new OperationRegistry();
+ }
+ return instance;
+ }
+
+ /** Get a list of all operations. */
+ public Collection<Operation> getOperations() {
+ return operations.values();
+ }
+
+ /** Get an operation by name. */
+ public Operation getOperation(String name) {
+ return operations.get(name);
+ }
+
+ /** Get the root libraries. */
+ public List<Library> getRootLibraries() {
+ return new ArrayList<Library>(rootLibrary.getLibraries());
+ }
+
+ /** Get the root operations. */
+ public List<Operation> getRootOperations() {
+ return new ArrayList<Operation>(rootLibrary.getOperations());
+ }
+}
diff --git a/plugins/org.eclipse.emf.edapt.history/src/org/eclipse/emf/edapt/migration/execution/MigrationReconstructor.java b/plugins/org.eclipse.emf.edapt.history/src/org/eclipse/emf/edapt/migration/execution/MigrationReconstructor.java
index d6b2f19..bac6426 100644
--- a/plugins/org.eclipse.emf.edapt.history/src/org/eclipse/emf/edapt/migration/execution/MigrationReconstructor.java
+++ b/plugins/org.eclipse.emf.edapt.history/src/org/eclipse/emf/edapt/migration/execution/MigrationReconstructor.java
@@ -25,6 +25,7 @@ import org.eclipse.emf.ecore.EReference;
import org.eclipse.emf.ecore.EStructuralFeature;
import org.eclipse.emf.ecore.EcorePackage;
import org.eclipse.emf.ecore.resource.ResourceSet;
+import org.eclipse.emf.edapt.common.IResourceSetFactory;
import org.eclipse.emf.edapt.common.MetamodelExtent;
import org.eclipse.emf.edapt.common.MetamodelUtils;
import org.eclipse.emf.edapt.common.ResourceUtils;
@@ -106,16 +107,21 @@ public class MigrationReconstructor extends ReconstructorBase {
/** Validation level. */
private final ValidationLevel level;
+ /** Factory to create {@link ResourceSet}s for custom serialization. */
+ private IResourceSetFactory resourceSetFactory;
+
/** Constructor. */
public MigrationReconstructor(List<URI> modelURIs, Release sourceRelease,
Release targetRelease, IProgressMonitor monitor,
- IClassLoader classLoader, ValidationLevel level) {
+ IClassLoader classLoader, ValidationLevel level,
+ IResourceSetFactory resourceSetFactory) {
this.modelURIs = modelURIs;
this.sourceRelease = sourceRelease;
this.targetRelease = targetRelease;
this.monitor = monitor;
this.classLoader = classLoader;
this.level = level;
+ this.resourceSetFactory = resourceSetFactory;
}
/** {@inheritDoc} */
@@ -174,7 +180,8 @@ public class MigrationReconstructor extends ReconstructorBase {
Metamodel metamodel = loadMetamodel();
metamodel.refreshCaches();
try {
- Model model = Persistency.loadModel(modelURIs, metamodel);
+ Model model = Persistency.loadModel(modelURIs, metamodel,
+ resourceSetFactory);
repository = MigrationFactory.eINSTANCE.createRepository();
repository.setMetamodel(metamodel);
repository.setModel(model);
diff --git a/plugins/org.eclipse.emf.edapt.history/src/org/eclipse/emf/edapt/migration/execution/Migrator.java b/plugins/org.eclipse.emf.edapt.history/src/org/eclipse/emf/edapt/migration/execution/Migrator.java
index c95df63..713444b 100644
--- a/plugins/org.eclipse.emf.edapt.history/src/org/eclipse/emf/edapt/migration/execution/Migrator.java
+++ b/plugins/org.eclipse.emf.edapt.history/src/org/eclipse/emf/edapt/migration/execution/Migrator.java
@@ -29,7 +29,9 @@ import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecore.EPackage;
import org.eclipse.emf.ecore.EcorePackage;
import org.eclipse.emf.ecore.resource.ResourceSet;
+import org.eclipse.emf.edapt.common.IResourceSetFactory;
import org.eclipse.emf.edapt.common.MetamodelUtils;
+import org.eclipse.emf.edapt.common.ResourceSetFactoryImpl;
import org.eclipse.emf.edapt.common.ResourceUtils;
import org.eclipse.emf.edapt.declaration.LibraryImplementation;
import org.eclipse.emf.edapt.declaration.OperationImplementation;
@@ -69,6 +71,9 @@ public class Migrator {
/** Classloader to load {@link CustomMigration}s. */
private final IClassLoader classLoader;
+ /** Factory to create {@link ResourceSet}s for custom serialization. */
+ private IResourceSetFactory resourceSetFactory = new ResourceSetFactoryImpl();
+
/** Validation level. */
private ValidationLevel level = ValidationLevel.CUSTOM_MIGRATION;
@@ -227,7 +232,7 @@ public class Migrator {
URI.createFileURI("test"));
MigrationReconstructor migrationReconstructor = new MigrationReconstructor(
modelURIs, sourceRelease, targetRelease, monitor,
- classLoader, level);
+ classLoader, level, resourceSetFactory);
reconstructor.addReconstructor(migrationReconstructor);
reconstructor.reconstruct(targetRelease, false);
@@ -356,4 +361,16 @@ public class Migrator {
System.err.println(e.getCause().getMessage());
}
}
+
+ /** Set the factory to create {@link ResourceSet}s for custom serialization. */
+ public void setResourceSetFactory(IResourceSetFactory resourceSetFactory) {
+ if (resourceSetFactory != null) {
+ this.resourceSetFactory = resourceSetFactory;
+ }
+ }
+
+ /** Get the factory to create {@link ResourceSet}s for custom serialization. */
+ public IResourceSetFactory getResourceSetFactory() {
+ return resourceSetFactory;
+ }
}
diff --git a/plugins/org.eclipse.emf.edapt.migration.ui/src/org/eclipse/emf/edapt/migration/ui/MigratorHandlerBase.java b/plugins/org.eclipse.emf.edapt.migration.ui/src/org/eclipse/emf/edapt/migration/ui/MigratorHandlerBase.java
index 4314411..23da5b3 100644
--- a/plugins/org.eclipse.emf.edapt.migration.ui/src/org/eclipse/emf/edapt/migration/ui/MigratorHandlerBase.java
+++ b/plugins/org.eclipse.emf.edapt.migration.ui/src/org/eclipse/emf/edapt/migration/ui/MigratorHandlerBase.java
@@ -109,16 +109,18 @@ public abstract class MigratorHandlerBase extends AbstractHandler {
}
/** Infer the release of a model. */
- protected Release getRelease(final List<URI> modelURIs, final Migrator migrator) {
- Set<Release> releases = new HashSet<Release>(migrator
- .getRelease(modelURIs.get(0)));
+ protected Release getRelease(final List<URI> modelURIs,
+ final Migrator migrator) {
+ Set<Release> releases = new HashSet<Release>(
+ migrator.getRelease(modelURIs.get(0)));
Release release = null;
if (releases.size() > 1) {
for (Iterator<Release> i = releases.iterator(); i.hasNext();) {
Release r = i.next();
Metamodel metamodel = migrator.getMetamodel(r);
try {
- Model model = Persistency.loadModel(modelURIs, metamodel);
+ Model model = Persistency.loadModel(modelURIs, metamodel,
+ migrator.getResourceSetFactory());
model.checkConformance();
} catch (Exception e) {
i.remove();
@@ -149,8 +151,7 @@ public abstract class MigratorHandlerBase extends AbstractHandler {
/** Update the selection. */
private void updateSelection(ISelection selection) {
- selectedFiles = SelectionUtils
- .getSelectedElements(selection);
+ selectedFiles = SelectionUtils.getSelectedElements(selection);
}
/** Get the selected files. */
diff --git a/plugins/org.eclipse.emf.edapt.migration/src/org/eclipse/emf/edapt/migration/Persistency.java b/plugins/org.eclipse.emf.edapt.migration/src/org/eclipse/emf/edapt/migration/Persistency.java
index ca599bd..1d3283b 100644
--- a/plugins/org.eclipse.emf.edapt.migration/src/org/eclipse/emf/edapt/migration/Persistency.java
+++ b/plugins/org.eclipse.emf.edapt.migration/src/org/eclipse/emf/edapt/migration/Persistency.java
@@ -21,9 +21,9 @@ import org.eclipse.emf.ecore.EPackage;
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.edapt.common.IResourceSetFactory;
import org.eclipse.emf.edapt.common.ResourceUtils;
-
/**
* Helper class for loading and saving models.
*
@@ -33,9 +33,9 @@ import org.eclipse.emf.edapt.common.ResourceUtils;
* @levd.rating YELLOW Hash: 7340771F1DE173BDAA2534B8901681B1
*/
public class Persistency {
-
+
/** Load metamodel based on {@link URI}. */
- public static Metamodel loadMetamodel(URI metamodelURI) throws IOException {
+ public static Metamodel loadMetamodel(URI metamodelURI) throws IOException {
ResourceSet resourceSet = ResourceUtils.loadResourceSet(metamodelURI);
return loadMetamodel(resourceSet);
@@ -45,12 +45,13 @@ public class Persistency {
public static Metamodel loadMetamodel(ResourceSet resourceSet) {
ResourceUtils.resolveAll(resourceSet);
Metamodel metamodel = MigrationFactory.eINSTANCE.createMetamodel();
- for(Resource resource : resourceSet.getResources()) {
- MetamodelResource metamodelResource = MigrationFactory.eINSTANCE.createMetamodelResource();
+ for (Resource resource : resourceSet.getResources()) {
+ MetamodelResource metamodelResource = MigrationFactory.eINSTANCE
+ .createMetamodelResource();
metamodelResource.setUri(resource.getURI());
metamodel.getResources().add(metamodelResource);
- for(EObject element : resource.getContents()) {
- if(element instanceof EPackage) {
+ for (EObject element : resource.getContents()) {
+ if (element instanceof EPackage) {
EPackage ePackage = (EPackage) element;
metamodelResource.getRootPackages().add(ePackage);
}
@@ -64,43 +65,51 @@ public class Persistency {
public static Metamodel loadMetamodel(String fileName) throws IOException {
return loadMetamodel(URI.createFileURI(fileName));
}
-
+
/** Save metamodel based on {@link URI}. */
public static void saveMetamodel(Metamodel metamodel) throws IOException {
ResourceSet resourceSet = new ResourceSetImpl();
-
- for(MetamodelResource metamodelResource : metamodel.getResources()) {
- Resource resource = resourceSet.createResource(metamodelResource.getUri());
- resource.getContents().addAll(metamodelResource.getRootPackages());
+
+ for (MetamodelResource metamodelResource : metamodel.getResources()) {
+ Resource resource = resourceSet.createResource(metamodelResource
+ .getUri());
+ resource.getContents().addAll(metamodelResource.getRootPackages());
}
-
+
ResourceUtils.saveResourceSet(resourceSet);
}
-
+
/** Load model based on {@link URI} for model and metamodel. */
- public static Model loadModel(URI modelURI, URI metamodelURI) throws IOException {
+ public static Model loadModel(URI modelURI, URI metamodelURI,
+ IResourceSetFactory resourceSetFactory) throws IOException {
Metamodel metamodel = loadMetamodel(metamodelURI);
- Model model = loadModel(modelURI, metamodel);
+ Model model = loadModel(modelURI, metamodel, resourceSetFactory);
return model;
}
-
+
/** Load model based on {@link URI} and metamodel. */
- public static Model loadModel(URI modelURI, Metamodel metamodel) throws IOException {
- return loadModel(Collections.singletonList(modelURI), metamodel);
+ public static Model loadModel(URI modelURI, Metamodel metamodel,
+ IResourceSetFactory resourceSetFactory) throws IOException {
+ return loadModel(Collections.singletonList(modelURI), metamodel,
+ resourceSetFactory);
}
-
+
/** Load model based on a set of {@link URI} and metamodel. */
- public static Model loadModel(List<URI> modelURIs, Metamodel metamodel) throws IOException {
- ResourceSet resourceSet = ResourceUtils.loadResourceSet(modelURIs, metamodel.getEPackages());
+ public static Model loadModel(List<URI> modelURIs, Metamodel metamodel,
+ IResourceSetFactory resourceSetFactory) throws IOException {
+ ResourceSet resourceSet = ResourceUtils.loadResourceSet(modelURIs,
+ metamodel.getEPackages(), resourceSetFactory);
ForwardConverter fConverter = new ForwardConverter();
Model model = fConverter.convert(resourceSet);
model.setMetamodel(metamodel);
return model;
- }
-
+ }
+
/** Load model based on file name and metamodel. */
- public static Model loadModel(String fileName, Metamodel metamodel) throws IOException {
- return loadModel(URI.createFileURI(fileName), metamodel);
+ public static Model loadModel(String fileName, Metamodel metamodel,
+ IResourceSetFactory resourceSetFactory) throws IOException {
+ return loadModel(URI.createFileURI(fileName), metamodel,
+ resourceSetFactory);
}
/** Save model based on {@link URI}. */
diff --git a/tests/org.eclipse.emf.edapt.tests/data/node/Graph1.xmi b/tests/org.eclipse.emf.edapt.tests/data/node/Graph1.xmi
new file mode 100644
index 0000000..c3ad7a4
--- /dev/null
+++ b/tests/org.eclipse.emf.edapt.tests/data/node/Graph1.xmi
@@ -0,0 +1,6 @@
+<?xml version="1.0" encoding="ASCII"?>
+<node:Graph xmi:version="2.0" xmlns:xmi="http://www.omg.org/XMI" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:node="node/v1" xsi:schemaLocation="node/v1 node2.ecore">
+ <children name="Node1">
+ <refs href="urn:app:com.emc.xcp.application:Graph2#//@children.0"/>
+ </children>
+</node:Graph>
diff --git a/tests/org.eclipse.emf.edapt.tests/data/node/Graph2.xmi b/tests/org.eclipse.emf.edapt.tests/data/node/Graph2.xmi
new file mode 100644
index 0000000..f8c9056
--- /dev/null
+++ b/tests/org.eclipse.emf.edapt.tests/data/node/Graph2.xmi
@@ -0,0 +1,4 @@
+<?xml version="1.0" encoding="ASCII"?>
+<node:Graph xmi:version="2.0" xmlns:xmi="http://www.omg.org/XMI" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:node="node/v1" xsi:schemaLocation="node/v1 node2.ecore">
+ <children name="Node2"/>
+</node:Graph>
diff --git a/tests/org.eclipse.emf.edapt.tests/data/node/node2.ecore b/tests/org.eclipse.emf.edapt.tests/data/node/node2.ecore
new file mode 100644
index 0000000..f210b6e
--- /dev/null
+++ b/tests/org.eclipse.emf.edapt.tests/data/node/node2.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="node"
+ nsURI="node/v2" nsPrefix="node">
+ <eClassifiers xsi:type="ecore:EClass" name="Graph">
+ <eStructuralFeatures xsi:type="ecore:EReference" name="children" upperBound="-1"
+ eType="#//Node" containment="true"/>
+ </eClassifiers>
+ <eClassifiers xsi:type="ecore:EClass" name="Node">
+ <eStructuralFeatures xsi:type="ecore:EAttribute" name="name" eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EString"/>
+ <eStructuralFeatures xsi:type="ecore:EReference" name="links" upperBound="-1"
+ eType="#//Node"/>
+ </eClassifiers>
+</ecore:EPackage>
diff --git a/tests/org.eclipse.emf.edapt.tests/data/node/node2.history b/tests/org.eclipse.emf.edapt.tests/data/node/node2.history
new file mode 100644
index 0000000..5576d72
--- /dev/null
+++ b/tests/org.eclipse.emf.edapt.tests/data/node/node2.history
@@ -0,0 +1,71 @@
+<?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="2012-06-02T17:57:34.857+0200" label="v1">
+ <changes xsi:type="history:CompositeChange">
+ <changes xsi:type="history:Create" element="node2.ecore#/">
+ <changes xsi:type="history:Set" element="node2.ecore#/" featureName="name"
+ dataValue="node"/>
+ <changes xsi:type="history:Set" element="node2.ecore#/" featureName="nsURI"
+ dataValue="node/v1"/>
+ <changes xsi:type="history:Set" element="node2.ecore#/" featureName="nsPrefix"
+ dataValue="node"/>
+ </changes>
+ <changes xsi:type="history:Create" target="node2.ecore#/" referenceName="eClassifiers"
+ element="node2.ecore#//Graph">
+ <changes xsi:type="history:Set" element="node2.ecore#//Graph" featureName="name"
+ dataValue="Graph"/>
+ </changes>
+ <changes xsi:type="history:Create" target="node2.ecore#/" referenceName="eClassifiers"
+ element="node2.ecore#//Node">
+ <changes xsi:type="history:Set" element="node2.ecore#//Node" featureName="name"
+ dataValue="Node"/>
+ </changes>
+ <changes xsi:type="history:Create" target="node2.ecore#//Graph" referenceName="eStructuralFeatures"
+ element="node2.ecore#//Graph/children">
+ <changes xsi:type="history:Set" element="node2.ecore#//Graph/children" featureName="name"
+ dataValue="children"/>
+ <changes xsi:type="history:Set" element="node2.ecore#//Graph/children" featureName="upperBound"
+ dataValue="-1" oldDataValue="1"/>
+ <changes xsi:type="history:Set" element="node2.ecore#//Graph/children" featureName="containment"
+ dataValue="true" oldDataValue="false"/>
+ <changes xsi:type="history:Set" element="node2.ecore#//Graph/children" featureName="eType"
+ referenceValue="node2.ecore#//Node"/>
+ </changes>
+ <changes xsi:type="history:Create" target="node2.ecore#//Node" referenceName="eStructuralFeatures"
+ element="node2.ecore#//Node/name">
+ <changes xsi:type="history:Set" element="node2.ecore#//Node/name" featureName="name"
+ dataValue="name"/>
+ <changes xsi:type="history:Set" element="node2.ecore#//Node/name" featureName="eType"
+ referenceValue="http://www.eclipse.org/emf/2002/Ecore#//EString"/>
+ </changes>
+ <changes xsi:type="history:Create" target="node2.ecore#//Node" referenceName="eStructuralFeatures"
+ element="node2.ecore#//Node/links">
+ <changes xsi:type="history:Set" element="node2.ecore#//Node/links" featureName="name"
+ dataValue="refs"/>
+ <changes xsi:type="history:Set" element="node2.ecore#//Node/links" featureName="upperBound"
+ dataValue="-1" oldDataValue="1"/>
+ <changes xsi:type="history:Set" element="node2.ecore#//Node/links" featureName="eType"
+ referenceValue="node2.ecore#//Node"/>
+ </changes>
+ </changes>
+ </releases>
+ <releases date="2012-06-02T17:57:54.660+0200" label="v2">
+ <changes xsi:type="history:OperationChange">
+ <changes xsi:type="history:Set" element="node2.ecore#//Node/links" featureName="name"
+ dataValue="links" oldDataValue="refs"/>
+ <operation name="rename">
+ <parameters name="element">
+ <referenceValue element="node2.ecore#//Node/links"/>
+ </parameters>
+ <parameters name="name">
+ <dataValue>links</dataValue>
+ </parameters>
+ </operation>
+ </changes>
+ <changes xsi:type="history:Set" element="node2.ecore#/" featureName="nsURI" dataValue="node/v2"
+ oldDataValue="node/v1"/>
+ </releases>
+ <releases/>
+</history:History>
diff --git a/tests/org.eclipse.emf.edapt.tests/src/org/eclipse/emf/edapt/tests/migration/ConverterTest.java b/tests/org.eclipse.emf.edapt.tests/src/org/eclipse/emf/edapt/tests/migration/ConverterTest.java
index 6634976..6b0bc2a 100644
--- a/tests/org.eclipse.emf.edapt.tests/src/org/eclipse/emf/edapt/tests/migration/ConverterTest.java
+++ b/tests/org.eclipse.emf.edapt.tests/src/org/eclipse/emf/edapt/tests/migration/ConverterTest.java
@@ -25,6 +25,7 @@ import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecore.EReference;
import org.eclipse.emf.ecore.EStructuralFeature;
import org.eclipse.emf.ecore.resource.Resource;
+import org.eclipse.emf.edapt.common.ResourceSetFactoryImpl;
import org.eclipse.emf.edapt.common.ResourceUtils;
import org.eclipse.emf.edapt.common.URIUtils;
import org.eclipse.emf.edapt.migration.BackwardConverter;
@@ -45,24 +46,26 @@ import org.eclipse.emf.edapt.migration.BackupUtils.URIMapper;
* @levd.rating RED Rev:
*/
public class ConverterTest extends TestCase {
-
+
/**
* Mapping between two models
*/
private Map<EObject, EObject> mapping;
/**
- * Test whether both converters maintain the order of multi-valued references
+ * Test whether both converters maintain the order of multi-valued
+ * references
*/
public void testOrder() throws IOException, MigrationException {
-
+
URI contextURI = URIUtils.getURI("data/node");
URI metamodelURI = contextURI.appendSegment("node.ecore");
URI model1URI = contextURI.appendSegment("split.xmi");
URI model2URI = contextURI.appendSegment("split_2.xmi");
-
+
Metamodel metamodel = Persistency.loadMetamodel(metamodelURI);
- Model model = Persistency.loadModel(model1URI, metamodel);
+ Model model = Persistency.loadModel(model1URI, metamodel,
+ new ResourceSetFactoryImpl());
model.validate();
URIMapper mapper = new URIMapper() {
@@ -70,23 +73,28 @@ public class ConverterTest extends TestCase {
public URI map(URI uri) {
String name = uri.trimFileExtension().lastSegment() + "_2";
String extension = uri.fileExtension();
- return uri.trimSegments(1).appendSegment(name).appendFileExtension(extension);
+ return uri.trimSegments(1).appendSegment(name)
+ .appendFileExtension(extension);
}
-
+
};
- for(ModelResource resource : model.getResources()) {
+ for (ModelResource resource : model.getResources()) {
resource.setUri(mapper.map(resource.getUri()));
}
-
- Persistency.saveModel(model);
-
- Resource model1 = ResourceUtils.loadResourceSet(model1URI, metamodel.getEPackages()).getResources().get(0);
- Resource model2 = ResourceUtils.loadResourceSet(model2URI, metamodel.getEPackages()).getResources().get(0);
-
+
+ Persistency.saveModel(model);
+
+ Resource model1 = ResourceUtils
+ .loadResourceSet(model1URI, metamodel.getEPackages())
+ .getResources().get(0);
+ Resource model2 = ResourceUtils
+ .loadResourceSet(model2URI, metamodel.getEPackages())
+ .getResources().get(0);
+
EObject root1 = model1.getContents().get(0);
EObject root2 = model2.getContents().get(0);
-
+
checkOrder(root1, root2);
}
@@ -94,7 +102,7 @@ public class ConverterTest extends TestCase {
* Check whether the order is maintained
*/
private void checkOrder(EObject root1, EObject root2) {
- mapping = new IdentityHashMap<EObject, EObject>();
+ mapping = new IdentityHashMap<EObject, EObject>();
checkContainment(root1, root2);
checkCrossReference(root1);
}
@@ -104,36 +112,38 @@ public class ConverterTest extends TestCase {
*/
@SuppressWarnings("unchecked")
private void checkContainment(EObject element1, EObject element2) {
-
+
Assert.assertNotSame(element1, element2);
-
+
EClass type = element1.eClass();
-
+
EStructuralFeature feature = type.getEStructuralFeature("name");
Assert.assertEquals(element1.eGet(feature), element2.eGet(feature));
-
+
Assert.assertNull(mapping.put(element1, element2));
-
- for(EReference containment : type.getEAllContainments()) {
- if(containment.isMany()) {
- List<EObject> list1 = ((List<EObject>) element1.eGet(containment));
- List<EObject> list2 = ((List<EObject>) element2.eGet(containment));
-
+
+ for (EReference containment : type.getEAllContainments()) {
+ if (containment.isMany()) {
+ List<EObject> list1 = ((List<EObject>) element1
+ .eGet(containment));
+ List<EObject> list2 = ((List<EObject>) element2
+ .eGet(containment));
+
Assert.assertEquals(list1.size(), list2.size());
-
- for(int i = 0, n = list1.size(); i < n; i++) {
+
+ for (int i = 0, n = list1.size(); i < n; i++) {
EObject child1 = list1.get(i);
- EObject child2 = list2.get(i);
+ EObject child2 = list2.get(i);
checkContainment(child1, child2);
}
- }
- else {
+ } else {
EObject child1 = (EObject) element1.eGet(containment);
EObject child2 = (EObject) element2.eGet(containment);
-
- Assert.assertTrue(child1 != null && child2 != null || child1 == null && child2 == null);
-
- if(child1 != null) {
+
+ Assert.assertTrue(child1 != null && child2 != null
+ || child1 == null && child2 == null);
+
+ if (child1 != null) {
checkContainment(child1, child2);
}
}
@@ -146,37 +156,36 @@ public class ConverterTest extends TestCase {
@SuppressWarnings("unchecked")
private void checkCrossReference(EObject element1) {
EObject element2 = mapping.get(element1);
-
+
EClass type = element1.eClass();
EStructuralFeature feature = type.getEStructuralFeature("name");
Assert.assertEquals(element1.eGet(feature), element2.eGet(feature));
-
- for(EReference reference : type.getEAllReferences()) {
- if(reference.isContainment()) {
+
+ for (EReference reference : type.getEAllReferences()) {
+ if (reference.isContainment()) {
continue;
}
-
- if(reference.isMany()) {
+
+ if (reference.isMany()) {
List<EObject> list1 = ((List<EObject>) element1.eGet(reference));
List<EObject> list2 = ((List<EObject>) element2.eGet(reference));
-
+
Assert.assertEquals(list1.size(), list2.size());
-
- for(int i = 0, n = list1.size(); i < n; i++) {
+
+ for (int i = 0, n = list1.size(); i < n; i++) {
EObject target1 = list1.get(i);
- EObject target2 = list2.get(i);
+ EObject target2 = list2.get(i);
Assert.assertSame(mapping.get(target1), target2);
}
- }
- else {
+ } else {
EObject target1 = (EObject) element1.eGet(reference);
EObject target2 = (EObject) element2.eGet(reference);
-
+
Assert.assertSame(mapping.get(target1), target2);
}
}
-
- for(EObject child1 : element1.eContents()) {
+
+ for (EObject child1 : element1.eContents()) {
checkCrossReference(child1);
}
}
diff --git a/tests/org.eclipse.emf.edapt.tests/src/org/eclipse/emf/edapt/tests/migration/CustomSerializationTest.java b/tests/org.eclipse.emf.edapt.tests/src/org/eclipse/emf/edapt/tests/migration/CustomSerializationTest.java
new file mode 100644
index 0000000..739ab30
--- /dev/null
+++ b/tests/org.eclipse.emf.edapt.tests/src/org/eclipse/emf/edapt/tests/migration/CustomSerializationTest.java
@@ -0,0 +1,76 @@
+package org.eclipse.emf.edapt.tests.migration;
+
+import java.util.Arrays;
+import java.util.List;
+import java.util.Map;
+
+import junit.framework.Assert;
+import junit.framework.TestCase;
+
+import org.eclipse.emf.common.util.URI;
+import org.eclipse.emf.ecore.EPackage;
+import org.eclipse.emf.ecore.EPackage.Registry;
+import org.eclipse.emf.ecore.resource.ResourceSet;
+import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl;
+import org.eclipse.emf.edapt.common.IResourceSetFactory;
+import org.eclipse.emf.edapt.common.URIUtils;
+import org.eclipse.emf.edapt.history.Release;
+import org.eclipse.emf.edapt.migration.MigrationException;
+import org.eclipse.emf.edapt.migration.PrintStreamProgressMonitor;
+import org.eclipse.emf.edapt.migration.execution.Migrator;
+
+/**
+ * Test for ensuring that the configuration of the custom serialization has
+ * effect on the migration.
+ *
+ * @author herrmi
+ * @author $Author: hummelb $
+ * @version $Rev: 18709 $
+ * @levd.rating RED Rev:
+ */
+public class CustomSerializationTest extends TestCase {
+
+ /** Test that the custom serialization works as configured. */
+ public void testCustomSerialization() throws MigrationException {
+
+ Migrator migrator = new Migrator(
+ URIUtils.getURI("data/node/node2.history"), null);
+
+ List<URI> modelURIs = Arrays.asList(URIUtils
+ .getURI("data/node/Graph1.xmi"));
+ Release sourceRelease = migrator.getRelease(0);
+ Release targetRelease = migrator.getRelease(1);
+ PrintStreamProgressMonitor monitor = new PrintStreamProgressMonitor(
+ System.out);
+
+ EPackage metamodel = migrator.getMetamodel(targetRelease)
+ .getEPackages().get(0);
+
+ Registry.INSTANCE.put(metamodel.getNsURI(), metamodel);
+
+ // without custom serialization
+ ResourceSet resourceSet = migrator.migrateAndLoad(modelURIs,
+ sourceRelease, targetRelease, monitor);
+
+ Assert.assertEquals(1, resourceSet.getResources().size());
+
+ // with custom serialization
+ migrator.setResourceSetFactory(new IResourceSetFactory() {
+
+ public ResourceSet createResourceSet() {
+ ResourceSet resourceSet = new ResourceSetImpl();
+ Map<URI, URI> uriMap = resourceSet.getURIConverter()
+ .getURIMap();
+ uriMap.put(
+ URI.createURI("urn:app:com.emc.xcp.application:Graph2"),
+ URIUtils.getURI("data/node/Graph2.xmi"));
+ return resourceSet;
+ }
+ });
+
+ resourceSet = migrator.migrateAndLoad(modelURIs, sourceRelease,
+ targetRelease, monitor);
+
+ Assert.assertEquals(2, resourceSet.getResources().size());
+ }
+}

Back to the top