Commit 06a7e2c3 authored by Erwan Bousse's avatar Erwan Bousse
Browse files

Versionning everything

parent cf54973e
package main;
import java.util.Map;
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 somemetamodel.A;
import somemetamodel.B;
import somemetamodel.C;
import somemetamodel.SomemetamodelFactory;
public class MainTestChangeResource {
public static void main(String[] args) {
// Creating some objects from our metamodel
SomemetamodelFactory factory = SomemetamodelFactory.eINSTANCE;
A a = factory.createA();
B b1 = factory.createB();
B b2 = factory.createB();
C c = factory.createC();
// Preparing serialization
Resource.Factory.Registry reg = Resource.Factory.Registry.INSTANCE;
Map<String, Object> m = reg.getExtensionToFactoryMap();
m.put("xmi", new XMIResourceFactoryImpl());
// Creating the resource sets (= models)
ResourceSet model1 = new ResourceSetImpl();
ResourceSet model2 = new ResourceSetImpl();
// Creating the first model
Resource submodel1 = model1.createResource(URI.createURI("models/submodel1.xmi"));
submodel1.getContents().add(a);
submodel1.getContents().add(b1);
// Creating the second model
Resource submodel2 = model2.createResource(URI.createURI("models/submodel2.xmi"));
submodel2.getContents().add(b2);
submodel2.getContents().add(c);
a.setB(b1);
a.setB(b2);
a.setC(c);
}
}
package main;
import java.io.File;
import java.io.IOException;
import java.util.Collections;
import java.util.Map;
import org.eclipse.emf.common.util.URI;
import org.eclipse.emf.ecore.impl.EPackageRegistryImpl;
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 someMMMutClassOnly.SomeMMMutClassOnlyTags;
import somemetamodel.A;
import somemetamodel.B;
import somemetamodel.C;
import somemetamodel.SomemetamodelFactory;
import somemetamodelextension.SomemetamodelextensionFactory;
import somemetamodelextension.X;
import util.HeapDump;
import fancyemfcloning.cloner.Cloner;
import fancyemfcloning.cloner.impl.ClonerImpl;
import fancyemfcloning.emfextension.LooseCopier;
public class MainTestCloning {
public static void main(String[] args) {
// Preparing factories
SomemetamodelFactory factory = SomemetamodelFactory.eINSTANCE;
SomemetamodelextensionFactory factory2 = SomemetamodelextensionFactory.eINSTANCE;
// Creating some objects from our metamodel
A a = factory.createA();
B b = factory.createB();
C c = factory.createC();
X x = factory2.createX();
a.setC(c);
a.setX(x);
// Preparing serialization
Resource.Factory.Registry reg = Resource.Factory.Registry.INSTANCE;
Map<String, Object> m = reg.getExtensionToFactoryMap();
m.put("xmi", new XMIResourceFactoryImpl());
// Creating the model
ResourceSet model = new ResourceSetImpl();
model.setPackageRegistry(new EPackageRegistryImpl());
// Creating submodels
Resource submodel1 = model.createResource(URI.createURI("file://home/ebousse/Dev/modelCloning/emf/SomeManipulations/models/submodel1.xmi"));
submodel1.getContents().add(a);
submodel1.getContents().add(b);
Resource submodel2 = model.createResource(URI.createURI("file://home/ebousse/Dev/modelCloning/emf/SomeManipulations/models/submodel2.xmi"));
submodel2.getContents().add(c);
submodel2.getContents().add(x);
// Deep cloning the model
/*
Cloner dc = new ClonerImpl(new SomeMMDeepTags(), new LooseCopier());
ResourceSet deepClone = dc.clone(model, "deepClone");
Cloner lightdc = new ClonerImpl(new SomeMMDeepTags(), new SomeMMDeepLightCopier());
ResourceSet lightDeepClone = lightdc.clone(model, "lightDeepClone");
*/
Cloner mc = new ClonerImpl(new SomeMMMutClassOnlyTags(), new LooseCopier());
@SuppressWarnings("unused")
ResourceSet mcClone = mc.clone(model, "mutableOnlyClone");
/*
Cloner lightmc = new ClonerImpl(new SomeMMMutClassOnlyTags(), new SomeMMMutClassOnlyLightCopier());
ResourceSet lightmcClone = lightmc.clone(model, "lightMutableOnlyClone");
try {
Thread.sleep(60000);
} catch (InterruptedException e1) {
// TODO Bloc catch généré automatiquement
e1.printStackTrace();
}*/
File outputDump = new File("/tmp/yay.bin");
if (outputDump.exists())
outputDump.delete();
HeapDump.dumpHeap(outputDump.getAbsolutePath(), true);
// MutClassesOnly cloning the model
//ResourceSet mutableClassesOnlyClone = new MutClassesOnlyCloner().clone(model, "mutableClassesOnlyClone");
/*
// WeakMutClassesOnly cloning the model
Set<Resource> metamodel = new HashSet<Resource>();
for (Object o : EPackage.Registry.INSTANCE.values()) {
EPackage p = (EPackage) o;
if (p.getNsURI() != "http://www.eclipse.org/emf/2002/Ecore")
metamodel.add(p.eResource());
}
//ResourceSet weakMutableClassesOnlyClone = new WeakMutClassesOnlyCloner(metamodel).clone(model, "mutableClassesOnlyClone");
*/
// Saving the models into files
try {
//mutableClassesOnlyClone.getResources().get(0).save(Collections.EMPTY_MAP);
//mutableClassesOnlyClone.getResources().get(1).save(Collections.EMPTY_MAP);
submodel1.save(Collections.EMPTY_MAP);
submodel2.save(Collections.EMPTY_MAP);
/*deepClone.getResources().get(0).save(Collections.EMPTY_MAP);
deepClone.getResources().get(1).save(Collections.EMPTY_MAP);
lightDeepClone.getResources().get(0).save(Collections.EMPTY_MAP);
lightDeepClone.getResources().get(1).save(Collections.EMPTY_MAP);
mcClone.getResources().get(0).save(Collections.EMPTY_MAP);
mcClone.getResources().get(1).save(Collections.EMPTY_MAP);
lightmcClone.getResources().get(0).save(Collections.EMPTY_MAP);
lightmcClone.getResources().get(1).save(Collections.EMPTY_MAP);*/
} catch (IOException e) {
// TODO Auto-generated catch block
System.err.println("An error occured during the saving:");
e.printStackTrace();
}
}
}
package main;
import somemetamodel.A;
import somemetamodel.B;
import somemetamodel.SomemetamodelFactory;
public class MainTestCompositions {
public static void main(String[] args) {
// Creating some objects from our metamodel
SomemetamodelFactory factory = SomemetamodelFactory.eINSTANCE;
A a1 = factory.createA();
A a2 = factory.createA();
B b = factory.createB();
a1.setB(b);
a2.setB(b);
System.out.println(a1);
}
}
package main;
import java.io.IOException;
import java.util.Collections;
import java.util.Map;
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 someMMDeep.SomeMMDeepTags;
import somemetamodel.A;
import somemetamodel.E;
import somemetamodel.SomemetamodelFactory;
import fancyemfcloning.emfextension.LooseResource;
public class MainTestLooseResource {
public static void main(String[] args) {
// Creating some objects from our metamodel
SomemetamodelFactory factory = SomemetamodelFactory.eINSTANCE;
A a = factory.createA();
E e = factory.createE();
// Preparing serialization
Resource.Factory.Registry reg = Resource.Factory.Registry.INSTANCE;
Map<String, Object> m = reg.getExtensionToFactoryMap();
m.put("xmi", new XMIResourceFactoryImpl());
// Creating the resource sets (= models)
ResourceSet model1 = new ResourceSetImpl();
ResourceSet model2 = new ResourceSetImpl();
// Creating the first submodel, with a
Resource submodel1 = model1.createResource(URI.createURI("models/submodel1.xmi"));
submodel1.getContents().add(a);
submodel1.getContents().add(e);
// Creating the second submodel, with e
Resource submodel2 = new LooseResource(new SomeMMDeepTags());
submodel2.setURI(URI.createURI("models/submodel2.xmi"));
model2.getResources().add(submodel2);
submodel2.getContents().add(a);
// Trying to put e in a
//a.setE(e);
// Saving the models into files
try {
submodel1.save(Collections.EMPTY_MAP);
submodel2.save(Collections.EMPTY_MAP);
} catch (IOException e2) {
// TODO Auto-generated catch block
e2.printStackTrace();
}
}
}
package main;
import java.util.Map;
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 somemetamodel.A;
import somemetamodel.B;
import somemetamodel.SomemetamodelFactory;
public class MainTestMultipleCompositions {
public static void main(String[] args) {
// Creating some objects from our metamodel
SomemetamodelFactory factory = SomemetamodelFactory.eINSTANCE;
A a11 = factory.createA();
A a12 = factory.createA();
A a21 = factory.createA();
A a22 = factory.createA();
B bShared = factory.createB();//new BReadonlyImpl();
// Preparing serialization
Resource.Factory.Registry reg = Resource.Factory.Registry.INSTANCE;
Map<String, Object> m = reg.getExtensionToFactoryMap();
m.put("xmi", new XMIResourceFactoryImpl());
// Creating the resource sets (= models)
ResourceSet model1 = new ResourceSetImpl();
ResourceSet model2 = new ResourceSetImpl();
// Creating the first model
Resource submodel1 = model1.createResource(URI.createURI("models/submodel1.xmi"));
submodel1.getContents().add(a11);
submodel1.getContents().add(a12);
submodel1.getContents().add(bShared);
// Creating the second model
//Resource submodel2 = new LooseResource();//
Resource submodel2 = model2.createResource(URI.createURI("models/submodel1.xmi"));
model2.getResources().add(submodel2);
submodel2.getContents().add(a21);
submodel2.getContents().add(a22);
// Putting bshared into a11
a11.setB(bShared);
// Then putting it into a21
a21.setB(bShared);
// Then putting it into a12
a12.setB(bShared);
// Then putting it into a22
a22.setB(bShared);
System.out.println(a11);
}
}
package main;
import java.util.Map;
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 someMMDeep.SomeMMDeepTags;
import somemetamodel.A;
import somemetamodel.B;
import somemetamodel.C;
import somemetamodel.SomemetamodelFactory;
import fancyemfcloning.emfextension.LooseResource;
public class MainTestMultipleCompositionsOnlyLoose {
public static void main(String[] args) {
// Creating some objects from our metamodel
SomemetamodelFactory factory = SomemetamodelFactory.eINSTANCE;
A a11 = factory.createA();
A a12 = factory.createA();
A a21 = factory.createA();
A a22 = factory.createA();
B bShared = factory.createB();//new BReadonlyImpl();
C cShared = factory.createC();//new BReadonlyImpl();
// Preparing serialization
Resource.Factory.Registry reg = Resource.Factory.Registry.INSTANCE;
Map<String, Object> m = reg.getExtensionToFactoryMap();
m.put("xmi", new XMIResourceFactoryImpl());
// Creating the resource sets (= models)
ResourceSet model1 = new ResourceSetImpl();
ResourceSet model2 = new ResourceSetImpl();
// Creating the first model
Resource submodel1 = new LooseResource(new SomeMMDeepTags());
model1.getResources().add(submodel1);
submodel1.getContents().add(a11);
submodel1.getContents().add(a12);
submodel1.getContents().add(bShared);
submodel1.getContents().add(cShared);
// Creating the second model
Resource submodel2 = new LooseResource(new SomeMMDeepTags());
model2.getResources().add(submodel2);
submodel2.getContents().add(a21);
submodel2.getContents().add(a22);
submodel2.getContents().add(cShared);
// Setting links to c
a11.setC(cShared);
a21.setC(cShared);
// Putting bshared into a11
a11.setB(bShared);
// Then putting it into a21
a21.setB(bShared);
// Then putting it into a12
a12.setB(bShared);
// Then putting it into a22
a22.setB(bShared);
System.out.println(a11);
}
}
package main;
import java.util.Map;
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 somemetamodel.A;
import somemetamodel.E;
import somemetamodel.SomemetamodelFactory;
public class MainTestNullResource {
public static void main(String[] args) {
// Creating some objects from our metamodel
SomemetamodelFactory factory = SomemetamodelFactory.eINSTANCE;
A a = factory.createA();
E e = factory.createE();
// Preparing serialization
Resource.Factory.Registry reg = Resource.Factory.Registry.INSTANCE;
Map<String, Object> m = reg.getExtensionToFactoryMap();
m.put("xmi", new XMIResourceFactoryImpl());
// Creating the resource set (= model)
ResourceSet model = new ResourceSetImpl();
Resource submodel1 = model.createResource(URI.createURI("models/submodel1.xmi"));
Resource submodel2 = model.createResource(URI.createURI("models/submodel2.xmi"));
a.getE().add(e);
submodel1.getContents().add(e);
submodel2.getContents().add(a);
submodel1.getContents().add(a);
}
}
package main;
import java.util.Map;
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 somemetamodel.A;
import somemetamodel.B;
import somemetamodel.C;
import somemetamodel.E;
import somemetamodel.SomemetamodelFactory;
public class MainTestResources {
public static void main(String[] args) {
// Creating some objects from our metamodel
SomemetamodelFactory factory = SomemetamodelFactory.eINSTANCE;
A a = factory.createA();
B b = factory.createB();
C c = factory.createC();
E e = factory.createE();
// Preparing serialization
Resource.Factory.Registry reg = Resource.Factory.Registry.INSTANCE;
Map<String, Object> m = reg.getExtensionToFactoryMap();
m.put("xmi", new XMIResourceFactoryImpl());
// Creating the resource set (= model)
ResourceSet model = new ResourceSetImpl();
// Creating the first submodel, with a
Resource submodel1 = model.createResource(URI.createURI("models/submodel1.xmi"));
submodel1.getContents().add(a);
System.out.println(e.eResource());
a.getE().add(e);
System.out.println(e.eResource());
// Creating the second submodel, with b and c
Resource submodel2 = model.createResource(URI.createURI("models/submodel2.xmi"));
submodel2.getContents().add(c);
// Trying to put b in a
a.setB(b); // b will leave the resource submodel2
System.out.println(b.eResource());
// Trying to put c in a
a.setC(c); //
System.out.println(a);
}
}
package main;
public class MainTruc {
public static void main(String[] args) {
Object o = new Truc2();
((Truc)o).doStuff();
}
}
package main;
public class Truc {
public void doStuff() {
System.out.println("Truc do stuff");
}
}
package main;
public class Truc2 extends Truc {
public void doStuff() {
System.out.println("Truc2 do stuff");
}
}
package util;
import javax.management.MBeanServer;
import java.lang.management.ManagementFactory;
import java.lang.reflect.Method;
//@SuppressWarnings("restriction")
public class HeapDump {
// This is the name of the HotSpot Diagnostic MBean
private static final String HOTSPOT_BEAN_NAME =
"com.sun.management:type=HotSpotDiagnostic";
// field to store the hotspot diagnostic MBean
private static volatile Object hotspotMBean;
/**
* Call this method from your application whenever you
* want to dump the heap snapshot into a file.
*
* @param fileName name of the heap dump file
* @param live flag that tells whether to dump
* only the live objects
*/
public static void dumpHeap(String fileName, boolean live) {
// initialize hotspot diagnostic MBean
initHotspotMBean();
try {
Class<?> clazz = Class.forName("com.sun.management.HotSpotDiagnosticMXBean");