Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--plugins/org.eclipse.emf.edapt.history.cdo/.classpath7
-rw-r--r--plugins/org.eclipse.emf.edapt.history.cdo/.project28
-rw-r--r--plugins/org.eclipse.emf.edapt.history.cdo/META-INF/MANIFEST.MF14
-rw-r--r--plugins/org.eclipse.emf.edapt.history.cdo/OSGI-INF/l10n/bundle.properties3
-rw-r--r--plugins/org.eclipse.emf.edapt.history.cdo/build.properties7
-rw-r--r--plugins/org.eclipse.emf.edapt.history.cdo/plugin.xml13
-rw-r--r--plugins/org.eclipse.emf.edapt.history.cdo/src/org/eclipse/emf/edapt/cdo/migration/StrategyBackwardConverter.java129
-rw-r--r--plugins/org.eclipse.emf.edapt.history.cdo/src/org/eclipse/emf/edapt/cdo/migration/StrategyForwardConverter.java141
-rw-r--r--plugins/org.eclipse.emf.edapt.history.cdo/src/org/eclipse/emf/edapt/cdo/migration/execution/CDOMigrationReconstructor.java61
-rw-r--r--plugins/org.eclipse.emf.edapt.history.cdo/src/org/eclipse/emf/edapt/cdo/migration/execution/CDOMigrator.java391
-rw-r--r--plugins/org.eclipse.emf.edapt.history.cdo/src/org/eclipse/emf/edapt/cdo/migration/execution/CDOPersistency.java64
-rw-r--r--plugins/org.eclipse.emf.edapt.history.cdo/src/org/eclipse/emf/edapt/cdo/migration/execution/EdaptCDOViewProvider.java50
12 files changed, 908 insertions, 0 deletions
diff --git a/plugins/org.eclipse.emf.edapt.history.cdo/.classpath b/plugins/org.eclipse.emf.edapt.history.cdo/.classpath
new file mode 100644
index 0000000..64c5e31
--- /dev/null
+++ b/plugins/org.eclipse.emf.edapt.history.cdo/.classpath
@@ -0,0 +1,7 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<classpath>
+ <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/J2SE-1.5"/>
+ <classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
+ <classpathentry kind="src" path="src"/>
+ <classpathentry kind="output" path="bin"/>
+</classpath>
diff --git a/plugins/org.eclipse.emf.edapt.history.cdo/.project b/plugins/org.eclipse.emf.edapt.history.cdo/.project
new file mode 100644
index 0000000..c34de77
--- /dev/null
+++ b/plugins/org.eclipse.emf.edapt.history.cdo/.project
@@ -0,0 +1,28 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+ <name>org.eclipse.emf.edapt.history.cdo</name>
+ <comment></comment>
+ <projects>
+ </projects>
+ <buildSpec>
+ <buildCommand>
+ <name>org.eclipse.jdt.core.javabuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ <buildCommand>
+ <name>org.eclipse.pde.ManifestBuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ <buildCommand>
+ <name>org.eclipse.pde.SchemaBuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ </buildSpec>
+ <natures>
+ <nature>org.eclipse.pde.PluginNature</nature>
+ <nature>org.eclipse.jdt.core.javanature</nature>
+ </natures>
+</projectDescription>
diff --git a/plugins/org.eclipse.emf.edapt.history.cdo/META-INF/MANIFEST.MF b/plugins/org.eclipse.emf.edapt.history.cdo/META-INF/MANIFEST.MF
new file mode 100644
index 0000000..4474681
--- /dev/null
+++ b/plugins/org.eclipse.emf.edapt.history.cdo/META-INF/MANIFEST.MF
@@ -0,0 +1,14 @@
+Manifest-Version: 1.0
+Bundle-ManifestVersion: 2
+Bundle-Name: %Bundle-Name
+Bundle-SymbolicName: org.eclipse.emf.edapt.history.cdo;singleton:=true
+Bundle-Version: 1.0.0.qualifier
+Bundle-Vendor: %Bundle-Vendor
+Bundle-RequiredExecutionEnvironment: J2SE-1.5
+Require-Bundle: org.eclipse.emf.ecore,
+ org.eclipse.emf.edapt.history,
+ org.eclipse.emf.cdo;bundle-version="4.2.1",
+ org.eclipse.emf.cdo.net4j;bundle-version="4.1.101",
+ org.eclipse.net4j.tcp;bundle-version="4.1.100"
+Export-Package: org.eclipse.emf.edapt.cdo.migration,
+ org.eclipse.emf.edapt.cdo.migration.execution
diff --git a/plugins/org.eclipse.emf.edapt.history.cdo/OSGI-INF/l10n/bundle.properties b/plugins/org.eclipse.emf.edapt.history.cdo/OSGI-INF/l10n/bundle.properties
new file mode 100644
index 0000000..293ead7
--- /dev/null
+++ b/plugins/org.eclipse.emf.edapt.history.cdo/OSGI-INF/l10n/bundle.properties
@@ -0,0 +1,3 @@
+#Properties file for org.eclipse.emf.edapt.history.cdo
+Bundle-Vendor = Eclipse
+Bundle-Name = CDO History \ No newline at end of file
diff --git a/plugins/org.eclipse.emf.edapt.history.cdo/build.properties b/plugins/org.eclipse.emf.edapt.history.cdo/build.properties
new file mode 100644
index 0000000..da1e9aa
--- /dev/null
+++ b/plugins/org.eclipse.emf.edapt.history.cdo/build.properties
@@ -0,0 +1,7 @@
+source.. = src/
+output.. = bin/
+bin.includes = META-INF/,\
+ .,\
+ OSGI-INF/l10n/bundle.properties,\
+ OSGI-INF/,\
+ plugin.xml
diff --git a/plugins/org.eclipse.emf.edapt.history.cdo/plugin.xml b/plugins/org.eclipse.emf.edapt.history.cdo/plugin.xml
new file mode 100644
index 0000000..c123a5c
--- /dev/null
+++ b/plugins/org.eclipse.emf.edapt.history.cdo/plugin.xml
@@ -0,0 +1,13 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<?eclipse version="3.4"?>
+<plugin>
+ <extension
+ point="org.eclipse.emf.cdo.viewProviders">
+ <viewProvider
+ class="org.eclipse.emf.edapt.cdo.migration.execution.EdaptCDOViewProvider"
+ priority="500"
+ regex="cdo">
+ </viewProvider>
+ </extension>
+
+</plugin>
diff --git a/plugins/org.eclipse.emf.edapt.history.cdo/src/org/eclipse/emf/edapt/cdo/migration/StrategyBackwardConverter.java b/plugins/org.eclipse.emf.edapt.history.cdo/src/org/eclipse/emf/edapt/cdo/migration/StrategyBackwardConverter.java
new file mode 100644
index 0000000..34c012d
--- /dev/null
+++ b/plugins/org.eclipse.emf.edapt.history.cdo/src/org/eclipse/emf/edapt/cdo/migration/StrategyBackwardConverter.java
@@ -0,0 +1,129 @@
+package org.eclipse.emf.edapt.cdo.migration;
+
+import java.util.Collection;
+import java.util.List;
+
+import org.eclipse.emf.cdo.util.CDOFactory;
+import org.eclipse.emf.common.util.URI;
+import org.eclipse.emf.ecore.EClass;
+import org.eclipse.emf.ecore.EFactory;
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.ecore.EPackage;
+import org.eclipse.emf.ecore.InternalEObject;
+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 org.eclipse.emf.ecore.xmi.XMLResource;
+import org.eclipse.emf.edapt.common.MetamodelExtent;
+import org.eclipse.emf.edapt.common.ResourceUtils;
+import org.eclipse.emf.edapt.migration.BackwardConverter;
+import org.eclipse.emf.edapt.migration.Instance;
+import org.eclipse.emf.edapt.migration.Model;
+import org.eclipse.emf.edapt.migration.ModelResource;
+import org.eclipse.emf.edapt.migration.Type;
+
+/**
+ *
+ * A {@link BackwardConverter} which defines a Strategy for converting a Model
+ * to a {@link Resource}.
+ *
+ *
+ * @author Christophe Bouhier
+ *
+ */
+public class StrategyBackwardConverter extends BackwardConverter {
+
+ private EFactory eFactory;
+
+ /**
+ * We need to override the creation of Objects. In the base version, the
+ * creation is delegated to the ECoreFactory set on the EPackage. (By using
+ * ECoreUtil). However CDO will use a CDOFactoryImpl which creates CDO
+ * Dynamic Objects. This is not compatible with Edapt as a DynamicCDOObject
+ * will have a CDOClassInfo based on a previous EPackage. Here we create
+ * regular EMF Objects which are added to a resource.
+ *
+ */
+ @Override
+ protected void createObjects(Type type) {
+ EClass sourceClass = type.getEClass();
+ EClass targetClass = resolveEClass(sourceClass);
+ for (Instance element : type.getInstances()) {
+
+ EFactory eFactoryInstance = targetClass.getEPackage()
+ .getEFactoryInstance();
+ EObject eObject = null;
+ if (eFactoryInstance instanceof CDOFactory) {
+ // We are a CDO Factory auch... we can't create
+ // migrated model objects with a CDOFactory.
+
+ if (eFactory == null) {
+ Collection<EPackage> rootPackages = extent
+ .getRootPackages();
+ for (EPackage ePack : rootPackages) {
+ eFactory = ePack.getEFactoryInstance();
+ }
+ }
+ if (eFactory != null) {
+ eObject = eFactory.create(targetClass);
+ }
+ }
+
+ if (eObject == null) {
+ eObject = EcoreUtil.create(targetClass);
+ }
+
+ if (element.isProxy()) {
+ ((InternalEObject) eObject).eSetProxyURI(element.getUri());
+ }
+ mapping.put(element, eObject);
+ }
+ }
+
+ /**
+ * The target {@link URI} which represents a path.
+ */
+ private List<URI> targetURI;
+
+ /**
+ * The original metamodel extent needed to obtain a {@link EFactory factory}
+ */
+ private MetamodelExtent extent;
+
+ public StrategyBackwardConverter(MetamodelExtent extent, List<URI> list) {
+ this.targetURI = list;
+ this.extent = extent;
+ }
+
+ @Override
+ protected ResourceSet initResources(Model model) {
+ ResourceSet resourceSet = new ResourceSetImpl();
+
+ ResourceUtils.register(model.getMetamodel().getEPackages(),
+ resourceSet.getPackageRegistry());
+
+ for (ModelResource modelResource : model.getResources()) {
+
+ // FIXME How to map source/target URI's, should be a map right?
+ URI target = targetURI.get(0);
+
+ Resource resource = resourceSet.createResource(target);
+
+ if (resource instanceof XMLResource) {
+ XMLResource xmlResource = (XMLResource) resource;
+ if (modelResource.getEncoding() != null) {
+ xmlResource.setEncoding(modelResource.getEncoding());
+ }
+ }
+
+ // We can only add to the resource when a conforming EPackage.
+ for (Instance element : modelResource.getRootInstances()) {
+ EObject resolve = resolve(element);
+ resource.getContents().add(resolve);
+ }
+ }
+ return resourceSet;
+ }
+
+}
diff --git a/plugins/org.eclipse.emf.edapt.history.cdo/src/org/eclipse/emf/edapt/cdo/migration/StrategyForwardConverter.java b/plugins/org.eclipse.emf.edapt.history.cdo/src/org/eclipse/emf/edapt/cdo/migration/StrategyForwardConverter.java
new file mode 100644
index 0000000..9221f1b
--- /dev/null
+++ b/plugins/org.eclipse.emf.edapt.history.cdo/src/org/eclipse/emf/edapt/cdo/migration/StrategyForwardConverter.java
@@ -0,0 +1,141 @@
+package org.eclipse.emf.edapt.cdo.migration;
+
+import java.util.Collection;
+import java.util.List;
+
+import org.eclipse.emf.ecore.EAttribute;
+import org.eclipse.emf.ecore.EClass;
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.ecore.EPackage;
+import org.eclipse.emf.ecore.EReference;
+import org.eclipse.emf.ecore.EStructuralFeature;
+import org.eclipse.emf.ecore.EcorePackage;
+import org.eclipse.emf.ecore.util.EcoreUtil;
+import org.eclipse.emf.edapt.migration.ForwardConverter;
+import org.eclipse.emf.edapt.migration.Instance;
+import org.eclipse.emf.edapt.migration.ReferenceSlot;
+
+public class StrategyForwardConverter extends ForwardConverter {
+
+ Collection<EPackage> rootPackages;
+
+ public StrategyForwardConverter(Collection<EPackage> ePackages) {
+ this.rootPackages = ePackages;
+ }
+
+ @Override
+ protected Instance newInstance(EObject eObject, boolean proxy) {
+
+ EObject find = find(eObject.eClass());
+
+ if (find instanceof EClass) {
+ // EClass eClass = eObject.eClass();
+ Instance element = model.newInstance((EClass) find);
+ mapping.put(eObject, element);
+ if (proxy) {
+ element.setUri(EcoreUtil.getURI(eObject));
+ }
+ return element;
+ }
+ return null;
+ }
+
+ @SuppressWarnings({ "rawtypes", "unchecked" })
+ protected void initInstance(EObject eObject) {
+ Instance element = resolve(eObject);
+ EClass c = eObject.eClass();
+ for (EAttribute attribute : c.getEAllAttributes()) {
+ if (ignore(attribute)) {
+ continue;
+ }
+ EObject lookupAttribute = find(attribute);
+ if (lookupAttribute instanceof EAttribute) {
+ // Get the lookup attribute and set it.
+ if (eObject.eIsSet(attribute)) {
+ Object value = eObject.eGet(attribute);
+ element.set((EStructuralFeature) lookupAttribute, value);
+ }
+ }
+ }
+
+ for (EReference reference : c.getEAllReferences()) {
+ if (ignore(reference)) {
+ continue;
+ }
+
+ // Get the lookup attribute and set it.
+ EObject lookupReference = find(reference);
+
+ if (lookupReference instanceof EReference) {
+ Object value = eObject.eGet(reference);
+ if (reference.isMany()) {
+ List<EObject> valueEObjects = (List<EObject>) value;
+ int index = 0;
+ for (EObject valueEObject : valueEObjects) {
+ Instance valueInstance = resolve(valueEObject);
+ if (reference.isUnique()
+ && ((List) element
+ .get((EStructuralFeature) lookupReference))
+ .contains(valueInstance)) {
+ ReferenceSlot referenceSlot = (ReferenceSlot) element
+ .getSlot((EStructuralFeature) lookupReference);
+ try {
+ referenceSlot.getValues().move(index,
+ valueInstance);
+ index++;
+ } catch (IndexOutOfBoundsException e) {
+ // ignore missing inverse link
+ }
+ } else {
+ element.add((EStructuralFeature) lookupReference,
+ index, valueInstance);
+ index++;
+ }
+ }
+ } else {
+ if (value != null) {
+ EObject valueEObject = (EObject) value;
+ Instance valueInstance = resolve(valueEObject);
+ element.set((EStructuralFeature) lookupReference,
+ valueInstance);
+ }
+ }
+ }
+ }
+ }
+
+ /** Find an element in the metamodel created for migration. */
+ @SuppressWarnings("unchecked")
+ private EObject find(EObject sourceElement) {
+ if (sourceElement == EcorePackage.eINSTANCE) {
+ return sourceElement;
+ }
+ EObject sourceParent = sourceElement.eContainer();
+ if (sourceParent == null) {
+ EPackage sourcePackage = (EPackage) sourceElement;
+ for (EPackage targetPackage : rootPackages) {
+ if (targetPackage.getNsURI().equals(sourcePackage.getNsURI())) {
+ return targetPackage;
+ }
+ }
+ return sourcePackage;
+ }
+ EObject targetParent = find(sourceParent);
+ if (targetParent == sourceParent) {
+ return sourceElement;
+ }
+ EReference reference = sourceElement.eContainmentFeature();
+ if (reference.isMany()) {
+ List<EObject> targetChildren = (List<EObject>) targetParent
+ .eGet(reference);
+ List<EObject> sourceChildren = (List<EObject>) sourceParent
+ .eGet(reference);
+ int index = sourceChildren.indexOf(sourceElement);
+ EObject targetElement = targetChildren.get(index);
+ return targetElement;
+ }
+ EObject targetElement = (EObject) targetParent.eGet(reference);
+ return targetElement;
+ }
+
+}
diff --git a/plugins/org.eclipse.emf.edapt.history.cdo/src/org/eclipse/emf/edapt/cdo/migration/execution/CDOMigrationReconstructor.java b/plugins/org.eclipse.emf.edapt.history.cdo/src/org/eclipse/emf/edapt/cdo/migration/execution/CDOMigrationReconstructor.java
new file mode 100644
index 0000000..8c24b70
--- /dev/null
+++ b/plugins/org.eclipse.emf.edapt.history.cdo/src/org/eclipse/emf/edapt/cdo/migration/execution/CDOMigrationReconstructor.java
@@ -0,0 +1,61 @@
+package org.eclipse.emf.edapt.cdo.migration.execution;
+
+import java.io.IOException;
+import java.util.List;
+
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.emf.common.util.URI;
+import org.eclipse.emf.ecore.resource.ResourceSet;
+import org.eclipse.emf.edapt.common.IResourceSetFactory;
+import org.eclipse.emf.edapt.history.Release;
+import org.eclipse.emf.edapt.history.reconstruction.FinishedException;
+import org.eclipse.emf.edapt.migration.Metamodel;
+import org.eclipse.emf.edapt.migration.MigrationFactory;
+import org.eclipse.emf.edapt.migration.Model;
+import org.eclipse.emf.edapt.migration.execution.IClassLoader;
+import org.eclipse.emf.edapt.migration.execution.MigrationReconstructor;
+import org.eclipse.emf.edapt.migration.execution.ValidationLevel;
+
+public class CDOMigrationReconstructor extends MigrationReconstructor {
+
+ public CDOMigrationReconstructor(List<URI> modelURIs,
+ Release sourceRelease, Release targetRelease,
+ IProgressMonitor monitor, IClassLoader classLoader,
+ ValidationLevel level, IResourceSetFactory resourceSetFactory) {
+ super(modelURIs, sourceRelease, targetRelease, monitor, classLoader,
+ level, resourceSetFactory);
+ }
+
+ /** Load the model before migration. */
+ protected void loadRepository() {
+ Metamodel metamodel = loadMetamodel();
+ metamodel.refreshCaches();
+ try {
+ ResourceSet set = resourceSetFactory.createResourceSet();
+ Model model = CDOPersistency.loadModel(modelURIs, metamodel, set);
+ repository = MigrationFactory.eINSTANCE.createRepository();
+ repository.setMetamodel(metamodel);
+ repository.setModel(model);
+ checkConformanceIfMoreThan(ValidationLevel.HISTORY);
+ } catch (IOException e) {
+ throwWrappedMigrationException("Model could not be loaded", e);
+ }
+ }
+
+ /** {@inheritDoc} */
+ @Override
+ public void endRelease(Release originalRelease) {
+ if (originalRelease == targetRelease) {
+ disable();
+ checkConformanceIfMoreThan(ValidationLevel.HISTORY);
+ throw new FinishedException();
+ } else if (originalRelease == sourceRelease) {
+ enable();
+ start();
+ loadRepository();
+ } else if (isEnabled()) {
+ checkConformanceIfMoreThan(ValidationLevel.RELEASE);
+ }
+ }
+
+}
diff --git a/plugins/org.eclipse.emf.edapt.history.cdo/src/org/eclipse/emf/edapt/cdo/migration/execution/CDOMigrator.java b/plugins/org.eclipse.emf.edapt.history.cdo/src/org/eclipse/emf/edapt/cdo/migration/execution/CDOMigrator.java
new file mode 100644
index 0000000..b02849d
--- /dev/null
+++ b/plugins/org.eclipse.emf.edapt.history.cdo/src/org/eclipse/emf/edapt/cdo/migration/execution/CDOMigrator.java
@@ -0,0 +1,391 @@
+package org.eclipse.emf.edapt.cdo.migration.execution;
+
+import java.io.File;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.Map.Entry;
+import java.util.Set;
+
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.emf.common.util.URI;
+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.MetamodelExtent;
+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;
+import org.eclipse.emf.edapt.declaration.OperationRegistry;
+import org.eclipse.emf.edapt.history.Delete;
+import org.eclipse.emf.edapt.history.History;
+import org.eclipse.emf.edapt.history.HistoryPackage;
+import org.eclipse.emf.edapt.history.Release;
+import org.eclipse.emf.edapt.history.reconstruction.EcoreForwardReconstructor;
+import org.eclipse.emf.edapt.history.util.HistoryUtils;
+import org.eclipse.emf.edapt.migration.BackupUtils;
+import org.eclipse.emf.edapt.migration.CustomMigration;
+import org.eclipse.emf.edapt.migration.MaterializingBackwardConverter;
+import org.eclipse.emf.edapt.migration.Metamodel;
+import org.eclipse.emf.edapt.migration.MigrationException;
+import org.eclipse.emf.edapt.migration.Model;
+import org.eclipse.emf.edapt.migration.PrintStreamProgressMonitor;
+import org.eclipse.emf.edapt.migration.ReleaseUtils;
+import org.eclipse.emf.edapt.migration.execution.ClassLoaderFacade;
+import org.eclipse.emf.edapt.migration.execution.IClassLoader;
+import org.eclipse.emf.edapt.migration.execution.MigratorCommandLine;
+import org.eclipse.emf.edapt.migration.execution.ValidationLevel;
+import org.eclipse.emf.edapt.migration.execution.WrappedMigrationException;
+
+/**
+ * Migrator to migrate a model from a previous to the current release.
+ *
+ * @author Christophe Bouhier
+ */
+public class CDOMigrator {
+
+ /** Metamodel history no which this migrator is based. */
+ private History history;
+
+ /** Mapping of namespace URIs to releases. */
+ private HashMap<String, Set<Release>> releaseMap;
+
+ /** 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;
+
+ private MetamodelExtent extent;
+
+ /** Constructor. */
+ public CDOMigrator(URI historyURI, IClassLoader classLoader)
+ throws MigrationException {
+ HistoryPackage.eINSTANCE.getHistory();
+ try {
+ history = ResourceUtils.loadElement(historyURI);
+ } catch (IOException e) {
+ throw new MigrationException("History could not be loaded", e);
+ }
+ this.classLoader = classLoader;
+ init();
+ }
+
+ /** Constructor. */
+ public CDOMigrator(History history, IClassLoader classLoader) {
+ this.history = history;
+ this.classLoader = classLoader;
+ init();
+ }
+
+ /** Initialize release map for the migrator. */
+ private void init() {
+ releaseMap = new HashMap<String, Set<Release>>();
+ Map<EPackage, String> packageMap = new HashMap<EPackage, String>();
+
+ for (Release release : history.getReleases()) {
+ if (!release.isLastRelease()) {
+ updatePackages(release, packageMap);
+ registerRelease(release, packageMap);
+ }
+ }
+ }
+
+ /** Register a package for a certain release. */
+ private void registerRelease(Release release,
+ Map<EPackage, String> packageMap) {
+ for (Entry<EPackage, String> entry : packageMap.entrySet()) {
+ String nsURI = entry.getValue();
+ Set<Release> releases = releaseMap.get(nsURI);
+ if (releases == null) {
+ releases = new HashSet<Release>();
+ releaseMap.put(nsURI, releases);
+ }
+ releases.add(release);
+ }
+ }
+
+ /** Update the namespace URIs based on the changes during a release. */
+ private void updatePackages(Release release,
+ Map<EPackage, String> packageMap) {
+ for (Iterator<EObject> i = release.eAllContents(); i.hasNext();) {
+ EObject element = i.next();
+ if (element instanceof org.eclipse.emf.edapt.history.Set) {
+ org.eclipse.emf.edapt.history.Set set = (org.eclipse.emf.edapt.history.Set) element;
+ if (set.getFeature() == EcorePackage.eINSTANCE
+ .getEPackage_NsURI()) {
+ EPackage ePackage = (EPackage) set.getElement();
+ String nsURI = (String) set.getValue();
+ packageMap.put(ePackage, nsURI);
+ }
+ } else if (element instanceof Delete) {
+ Delete delete = (Delete) element;
+ packageMap.remove(delete.getElement());
+ }
+ }
+ }
+
+ /**
+ * Migrate a model based on a set of {@link URI} and save to it's own URI
+ * location.
+ *
+ * @param modelURIs
+ * @param sourceRelease
+ * @param targetRelease
+ * @param monitor
+ * @throws MigrationException
+ */
+ public void migrateAndSave(List<URI> modelURIs, Release sourceRelease,
+ Release targetRelease, IProgressMonitor monitor)
+ throws MigrationException {
+ migrateAndSave(modelURIs, sourceRelease, targetRelease, monitor, null);
+ }
+
+ /**
+ * Migrate a model based on a set of {@link URI} and save it to a
+ * destination {@link URI}. The destination {@link URI} is the path URI in
+ * case multiple modelURIs are provided.
+ *
+ * @param modelURIs
+ * @param sourceRelease
+ * Release to which the model conforms
+ * @param targetRelease
+ * Release to which the model should be migrated (use null for
+ * the newest release)
+ * @param monitor
+ * Progress monitor
+ * @param destnationURI
+ */
+ public void migrateAndSave(List<URI> modelURIs, Release sourceRelease,
+ Release targetRelease, IProgressMonitor monitor, List<URI> list)
+ throws MigrationException {
+ Model model = migrate(modelURIs, sourceRelease, targetRelease, monitor);
+ if (model == null) {
+ throw new MigrationException("Model is up-to-date", null);
+ }
+ // Get the original extend, as we need a factory...
+ try {
+ CDOPersistency.saveModel(model, extent, list);
+ } catch (IOException e) {
+ throw new MigrationException("Model could not be saved", e);
+ }
+ }
+
+ /**
+ * Migrate a model based on a set of {@link URI}s and load it afterwards.
+ *
+ * @param modelURIs
+ * The set of {@link URI}
+ * @param sourceRelease
+ * Release to which the model conforms
+ * @param targetRelease
+ * Release to which the model should be migrated (use null for
+ * the newest release)
+ * @param monitor
+ * Progress monitor
+ * @return The model in a {@link ResourceSet}
+ */
+ public ResourceSet migrateAndLoad(List<URI> modelURIs,
+ Release sourceRelease, Release targetRelease,
+ IProgressMonitor monitor) throws MigrationException {
+ Model model = migrate(modelURIs, sourceRelease, targetRelease, monitor);
+ if (model == null) {
+ return null;
+ }
+ MaterializingBackwardConverter converter = new MaterializingBackwardConverter();
+ return converter.convert(model);
+ }
+
+ /** Get the latest release. */
+ private Release getLatestRelease() {
+ List<Release> releases = history.getReleases();
+ return releases.get(releases.size() - 2);
+ }
+
+ /**
+ * Migrate a model based on a set of {@link URI}s.
+ *
+ * @param modelURIs
+ * The set of {@link URI}
+ * @param sourceRelease
+ * Release to which the model conforms
+ * @param targetRelease
+ * Release to which the model should be migrated (use null for
+ * the newest release)
+ * @param monitor
+ * Progress monitor
+ * @return The model in the generic structure
+ */
+ private Model migrate(List<URI> modelURIs, Release sourceRelease,
+ Release targetRelease, IProgressMonitor monitor)
+ throws MigrationException {
+ try {
+ if (targetRelease == null) {
+ targetRelease = getLatestRelease();
+ }
+ if (sourceRelease == targetRelease) {
+ return null;
+ }
+
+ monitor.beginTask("Migrate",
+ numberOfSteps(sourceRelease, targetRelease));
+ EcoreForwardReconstructor reconstructor = new EcoreForwardReconstructor(
+ URI.createFileURI("test"));
+ CDOMigrationReconstructor migrationReconstructor = new CDOMigrationReconstructor(
+ modelURIs, sourceRelease, targetRelease, monitor,
+ classLoader, level, resourceSetFactory);
+ reconstructor.addReconstructor(migrationReconstructor);
+
+ reconstructor.reconstruct(targetRelease, false);
+
+ extent = reconstructor.getExtent();
+
+ Model model = migrationReconstructor.getModel();
+ return model;
+ } catch (WrappedMigrationException e) {
+ throw e.getCause();
+ } finally {
+ monitor.done();
+ }
+ }
+
+ /** Returns the length of the migration in terms of the steps. */
+ private int numberOfSteps(Release sourceRelease, Release targetRelease) {
+ int size = 0;
+ boolean inRelease = false;
+ for (Release release : history.getReleases()) {
+ if (inRelease) {
+ size += release.getChanges().size();
+ }
+ if (release == sourceRelease) {
+ inRelease = true;
+ }
+ if (release == targetRelease) {
+ break;
+ }
+ }
+ return size;
+ }
+
+ /** Get the release of a model based on {@link URI}. */
+ public Set<Release> getRelease(URI modelURI) {
+ String nsURI = ReleaseUtils.getNamespaceURI(modelURI);
+ return releaseMap.containsKey(nsURI) ? releaseMap.get(nsURI)
+ : Collections.<Release> emptySet();
+ }
+
+ /** Get the release with a certain number. */
+ public Release getRelease(int number) {
+ if (number < 0 || number >= history.getReleases().size()) {
+ return null;
+ }
+ return history.getReleases().get(number);
+ }
+
+ /** Get all releases. */
+ public List<Release> getReleases() {
+ List<Release> releases = new ArrayList<Release>();
+ releases.addAll(history.getReleases());
+ releases.remove(history.getLastRelease());
+ return releases;
+ }
+
+ /** Get set of namespace URIs. */
+ public Set<String> getNsURIs() {
+ return releaseMap.keySet();
+ }
+
+ /** Returns the metamodel for a release. */
+ public Metamodel getMetamodel(Release release) {
+ EcoreForwardReconstructor reconstructor = new EcoreForwardReconstructor(
+ URI.createFileURI("test"));
+ reconstructor.reconstruct(release, false);
+ URI metamodelURI = URI.createFileURI(new File("metamodel."
+ + ResourceUtils.ECORE_FILE_EXTENSION).getAbsolutePath());
+ List<EPackage> rootPackages = ResourceUtils.getRootElements(
+ reconstructor.getResourceSet(), EPackage.class);
+ ResourceSet resourceSet = MetamodelUtils
+ .createIndependentMetamodelCopy(rootPackages, metamodelURI);
+ return CDOPersistency.loadMetamodel(resourceSet);
+ }
+
+ /** Set the validation level. */
+ public void setLevel(ValidationLevel level) {
+ this.level = level;
+ }
+
+ /** Main method to perform migrations. */
+ public static void main(String[] args) {
+
+ MigratorCommandLine commandLine = new MigratorCommandLine(args);
+ List<URI> modelURIs = commandLine.getModelURIs();
+ int sourceReleaseNumber = commandLine.getSourceReleaseNumber();
+ int targetReleaseNumber = commandLine.getTargetReleaseNumber();
+
+ try {
+ for (Class<? extends LibraryImplementation> library : commandLine
+ .getLibraries()) {
+ OperationRegistry.getInstance().registerLibrary(library);
+ }
+ for (Class<? extends OperationImplementation> operation : commandLine
+ .getOperations()) {
+ OperationRegistry.getInstance().registerOperation(operation);
+ }
+
+ CDOMigrator migrator = new CDOMigrator(commandLine.getHistoryURI(),
+ new ClassLoaderFacade(Thread.currentThread()
+ .getContextClassLoader()));
+ migrator.setLevel(commandLine.getLevel());
+
+ Set<Release> releases = migrator.getRelease(modelURIs.get(0));
+ Release sourceRelease = null;
+ if (sourceReleaseNumber != -1) {
+ sourceRelease = HistoryUtils.getRelease(releases,
+ sourceReleaseNumber);
+ } else {
+ sourceRelease = releases.iterator().next();
+ }
+
+ if (commandLine.isBackup()) {
+ Metamodel metamodel = migrator.getMetamodel(sourceRelease);
+ try {
+ BackupUtils.backup(modelURIs, metamodel);
+ } catch (IOException e) {
+ System.err.println(e.getMessage());
+ }
+ }
+
+ Release targetRelease = migrator.getRelease(targetReleaseNumber);
+
+ migrator.migrateAndSave(modelURIs, sourceRelease, targetRelease,
+ new PrintStreamProgressMonitor(System.out));
+ } catch (MigrationException e) {
+ System.err.println(e.getMessage());
+ 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.history.cdo/src/org/eclipse/emf/edapt/cdo/migration/execution/CDOPersistency.java b/plugins/org.eclipse.emf.edapt.history.cdo/src/org/eclipse/emf/edapt/cdo/migration/execution/CDOPersistency.java
new file mode 100644
index 0000000..cfbb028
--- /dev/null
+++ b/plugins/org.eclipse.emf.edapt.history.cdo/src/org/eclipse/emf/edapt/cdo/migration/execution/CDOPersistency.java
@@ -0,0 +1,64 @@
+/*******************************************************************************
+ * Copyright (c) 2007, 2010 BMW Car IT, Technische Universitaet Muenchen, and others.
+ * 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:
+ * BMW Car IT - Initial API and implementation
+ * Technische Universitaet Muenchen - Major refactoring and extension
+ *******************************************************************************/
+package org.eclipse.emf.edapt.cdo.migration.execution;
+
+import java.io.IOException;
+import java.util.List;
+
+import org.eclipse.emf.common.util.URI;
+import org.eclipse.emf.ecore.resource.ResourceSet;
+import org.eclipse.emf.edapt.cdo.migration.StrategyBackwardConverter;
+import org.eclipse.emf.edapt.cdo.migration.StrategyForwardConverter;
+import org.eclipse.emf.edapt.common.MetamodelExtent;
+import org.eclipse.emf.edapt.common.ResourceUtils;
+import org.eclipse.emf.edapt.migration.Metamodel;
+import org.eclipse.emf.edapt.migration.Model;
+import org.eclipse.emf.edapt.migration.Persistency;
+
+/**
+ * Helper class for loading and saving models.
+ *
+ * @author herrmama
+ * @author Christophe Bouhier
+ * @version $Rev$
+ * @levd.rating YELLOW Hash: 7340771F1DE173BDAA2534B8901681B1
+ */
+public class CDOPersistency extends Persistency {
+
+ /**
+ * Save model to an explity URI.
+ *
+ * @param model
+ * @param extent
+ * @param list
+ * @throws IOException
+ */
+ public static void saveModel(Model model, MetamodelExtent extent,
+ List<URI> list) throws IOException {
+
+ StrategyBackwardConverter bConverter = new StrategyBackwardConverter(
+ extent, list);
+ ResourceSet resourceSet = bConverter.convert(model);
+ ResourceUtils.saveResourceSet(resourceSet);
+ }
+
+ public static Model loadModel(List<URI> modelURIs, Metamodel metamodel,
+ ResourceSet set) throws IOException {
+ ResourceUtils.loadResourceSet(modelURIs, set);
+ StrategyForwardConverter fConverter = new StrategyForwardConverter(
+ metamodel.getEPackages());
+ Model model = fConverter.convert(set);
+ model.setMetamodel(metamodel);
+ return model;
+ }
+
+}
diff --git a/plugins/org.eclipse.emf.edapt.history.cdo/src/org/eclipse/emf/edapt/cdo/migration/execution/EdaptCDOViewProvider.java b/plugins/org.eclipse.emf.edapt.history.cdo/src/org/eclipse/emf/edapt/cdo/migration/execution/EdaptCDOViewProvider.java
new file mode 100644
index 0000000..32ccde0
--- /dev/null
+++ b/plugins/org.eclipse.emf.edapt.history.cdo/src/org/eclipse/emf/edapt/cdo/migration/execution/EdaptCDOViewProvider.java
@@ -0,0 +1,50 @@
+// TODO HEADER FOR EDAPT
+package org.eclipse.emf.edapt.cdo.migration.execution;
+
+import org.eclipse.emf.cdo.net4j.CDONet4jSessionConfiguration;
+import org.eclipse.emf.cdo.net4j.CDONet4jUtil;
+import org.eclipse.emf.cdo.session.CDOSession;
+import org.eclipse.emf.cdo.view.AbstractCDOViewProvider;
+import org.eclipse.emf.cdo.view.CDOView;
+import org.eclipse.emf.common.util.URI;
+import org.eclipse.emf.ecore.resource.ResourceSet;
+import org.eclipse.net4j.Net4jUtil;
+import org.eclipse.net4j.connector.IConnector;
+import org.eclipse.net4j.tcp.TCPUtil;
+import org.eclipse.net4j.util.container.IManagedContainer;
+import org.eclipse.net4j.util.container.ManagedContainer;
+
+public class EdaptCDOViewProvider extends AbstractCDOViewProvider {
+ private IManagedContainer container;
+
+
+ public EdaptCDOViewProvider(String regex, int priority) {
+ super("cdo\\.local:.*", priority);
+ }
+
+
+ @Override
+ public CDOView getView(URI uri, ResourceSet resourceSet) {
+ if (container == null) {
+ container = new ManagedContainer();
+ Net4jUtil.prepareContainer(container);
+ TCPUtil.prepareContainer(container);
+ container.activate();
+ }
+
+ int startIndex = uri.toString().indexOf(':');
+ String repoName = uri.toString().substring(startIndex);
+
+ IConnector connector = (IConnector) container.getElement(
+ "org.eclipse.net4j.connectors", "tcp", "localhost");
+
+ CDONet4jSessionConfiguration config = CDONet4jUtil
+ .createNet4jSessionConfiguration();
+ config.setConnector(connector);
+ config.setRepositoryName(repoName);
+
+ CDOSession session = config.openNet4jSession();
+ return session.openTransaction();
+ }
+
+}

Back to the top