Commit f13d3fbb authored by Erwan Bousse's avatar Erwan Bousse

Fixed regression that appeared with the strategy reorganisation.

parent 1da19274
*.class
*.jar
*~
.metadata
......@@ -14,18 +14,24 @@ import java.io.File;
import java.io.IOException;
import java.io.PrintStream;
import org.eclipse.core.internal.runtime.InternalPlatform;
import org.osgi.framework.Bundle;
import org.osgi.framework.BundleContext;
import org.zeroturnaround.zip.ZipUtil;
import fr.inria.diverse.cloning.benchmark.common.BenchmarkMaterial;
import fr.inria.diverse.cloning.materialgenerator.util.CodeGeneration;
@SuppressWarnings("restriction")
public class OsgiBundleGenerator {
private static final String generatedBenchmarkMaterialPackageName = "cloningbenchmark";
private static final String generatedBenchmarkMaterialClassName = "BenchmarkMaterialImpl";
private static final String clonerPluginId = "fr.inria.diverse.cloning.runtime";
private static final String benchmarkCommonPluginId = "fr.inria.diverse.cloning.benchmark.common";
private static final String bundleName = "CloningBenchmark";
private static final String eclipseRuntimePluginId = "org.eclipse.core.runtime";
private static final String ecoreRuntimePluginId = "org.eclipse.emf.ecore";
public static void generateActivator(File outputFolder) {
......@@ -40,21 +46,18 @@ public class OsgiBundleGenerator {
outputFile.createNewFile();
PrintStream printer = new PrintStream(outputFile);
String content = "package "
+ packageFullName
+ ";"
String content = "package " + packageFullName + ";"
+ "import org.osgi.framework.BundleActivator;"
+ "import org.osgi.framework.BundleContext;"
+ "import "+BenchmarkMaterial.class.getCanonicalName()+";"
+ "public class "
+ className
+ " implements BundleActivator { "
+ "import org.osgi.framework.BundleContext;" + "import "
+ BenchmarkMaterial.class.getCanonicalName() + ";" + "public class "
+ className + " implements BundleActivator { "
+ "private static BundleContext context; "
+ "static BundleContext getContext() {return context;} "
+ "public void start(BundleContext bundleContext) throws Exception {"
+ " Activator.context = bundleContext;"
+ " context.registerService(\""+BenchmarkMaterial.class.getCanonicalName()+"\", new "+generatedBenchmarkMaterialClassName+"(), null);"
+ " } " + "public void stop(BundleContext bundleContext) throws Exception {"
+ " Activator.context = bundleContext;" + " context.registerService(\""
+ BenchmarkMaterial.class.getCanonicalName() + "\", new "
+ generatedBenchmarkMaterialClassName + "(), null);" + " } "
+ "public void stop(BundleContext bundleContext) throws Exception {"
+ " Activator.context = null;" + " }" + "}";
printer.print(CodeGeneration.formatJavaCode(content));
......@@ -76,10 +79,12 @@ public class OsgiBundleGenerator {
PrintStream printer = new PrintStream(outputFile);
String content = "<?xml version=\"1.0\" encoding=\"UTF-8\"?> "
+ "<scr:component xmlns:scr=\"http://www.osgi.org/xmlns/scr/v1.1.0\" name=\""+bundleName+"\"> "
+ "<implementation class=\""+generatedBenchmarkMaterialPackageName+"."+generatedBenchmarkMaterialClassName+"\"/> " + "<service>"
+ " <provide interface=\""+BenchmarkMaterial.class.getCanonicalName()+"\"/> "
+ "</service>" + " </scr:component>";
+ "<scr:component xmlns:scr=\"http://www.osgi.org/xmlns/scr/v1.1.0\" name=\""
+ bundleName + "\"> " + "<implementation class=\""
+ generatedBenchmarkMaterialPackageName + "."
+ generatedBenchmarkMaterialClassName + "\"/> " + "<service>"
+ " <provide interface=\"" + BenchmarkMaterial.class.getCanonicalName()
+ "\"/> " + "</service>" + " </scr:component>";
printer.print(content);
printer.close();
} catch (IOException e) {
......@@ -88,7 +93,21 @@ public class OsgiBundleGenerator {
}
}
@SuppressWarnings("restriction")
private static String findVersionOfBundle(String bundleName) {
BundleContext bundleContext = InternalPlatform.getDefault().getBundleContext();
for (Bundle b : bundleContext.getBundles()) {
if (b.getSymbolicName().equals(bundleName)) {
int major = b.getVersion().getMajor();
int minor = b.getVersion().getMinor();
// int micro = b.getVersion().getMicro();
return major + "." + minor;// + "." + micro;
// return b.getVersion().toString();
}
}
return "";
}
public static void generateManifest(File outputFolder) {
// Preparing the output file and the printer
......@@ -99,15 +118,34 @@ public class OsgiBundleGenerator {
outputFile.createNewFile();
PrintStream printer = new PrintStream(outputFile);
String content = "Manifest-Version: 1.0\n"
+ "Service-Component: component.xml\n"
+ "Require-Bundle: org.eclipse.core.runtime;bundle-version=\"3.9.0\", org.eclipse.emf.ecore;bundle-version=\"2.9.1\","+clonerPluginId+";bundle-version=\"0.1.0\","+benchmarkCommonPluginId+";bundle-version=\"1.0.0\",org.eclipse.emf.ecore.xmi\n"
String content = "Manifest-Version: 1.0\n" + "Service-Component: component.xml\n"
+ "Require-Bundle: "
+ eclipseRuntimePluginId
+ ";bundle-version=\""
+ findVersionOfBundle(eclipseRuntimePluginId)
+ "\", "
+ ecoreRuntimePluginId
+ ";bundle-version=\""
+ findVersionOfBundle(ecoreRuntimePluginId)
+ "\","
+ clonerPluginId
+ ";bundle-version=\""
+ findVersionOfBundle(clonerPluginId)
+ "\","
+ benchmarkCommonPluginId
+ ";bundle-version=\""
+ findVersionOfBundle(benchmarkCommonPluginId)
+ "\",org.eclipse.emf.ecore.xmi\n"
+ "Bundle-ActivationPolicy: lazy\n"
+ "Bundle-Version: 1\n"
+ "Bundle-Name: "+bundleName+"\n"
+ "Bundle-Activator: cloningbenchmark.Activator\n"
+ "Bundle-Version: 1\n"
+ "Bundle-Name: "
+ bundleName
+ "\n"
+ "Bundle-Activator: cloningbenchmark.Activator\n"
+ "Bundle-ManifestVersion: 2\n"
+ "Bundle-SymbolicName: "+bundleName+"\n"
+ "Bundle-SymbolicName: "
+ bundleName
+ "\n"
+ "Bundle-RequiredExecutionEnvironment: JavaSE-1.7\n";
printer.print(content);
printer.close();
......@@ -119,8 +157,9 @@ public class OsgiBundleGenerator {
}
public static void createJar(File inputFolder, File outputFile) {
//ZipHelper.zipDir(inputFolder.getAbsolutePath(), outputFile.getAbsolutePath());
ZipUtil.pack(inputFolder, outputFile);
// ZipHelper.zipDir(inputFolder.getAbsolutePath(),
// outputFile.getAbsolutePath());
ZipUtil.pack(inputFolder, outputFile);
}
......
......@@ -98,8 +98,10 @@ public class Benchmark {
Log.info("OriginalPerformance: " + originalModelPerformance);
}
// Echauffement
for (int i = 0; i < 1000; i++)
// Warmup
// NOTE : only works because our benchmark do not contain mutable containments
// If it did, the gc coudln't destroy the clones because of the additional containers of some objects
for (int i = 0; i < 1337; i++)
cloner.clone(model, tmpFolder);//, light);
// Cloning "numberOfClones" times and computing time
......
......@@ -3,6 +3,7 @@
<product name="Benchmark tool" uid="fr.inria.diverse.cloning.benchmark.tool.product" id="fr.inria.diverse.cloning.benchmark.tool.BenchmarkToolSuite" application="fr.inria.diverse.cloning.benchmark.tool.application" version="0.1.0.qualifier" useFeatures="false" includeLaunchers="true">
<configIni use="default">
</configIni>
......@@ -14,6 +15,7 @@
<windowImages/>
<launcher name="cloning-benchmark">
<solaris/>
<win useIco="false">
......@@ -21,9 +23,11 @@
</win>
</launcher>
<vm>
</vm>
<plugins>
<plugin id="fr.inria.diverse.cloning.benchmark.tool" version="0.1.0.qualifier"/>
<plugin id="org.eclipse.core.runtime"/>
......@@ -33,6 +37,7 @@
<configurations>
<plugin id="org.eclipse.core.runtime" autoStart="true" startLevel="0" />
<property name="osgi.instance.area.default" value="benchmarktool-workingdir" />
</configurations>
</product>
......@@ -15,7 +15,7 @@ import java.io.IOException;
import java.io.PrintStream;
import org.eclipse.emf.ecore.resource.ResourceSet;
import org.eclipse.emf.ecore.util.EcoreUtil.Copier;
import fr.inria.diverse.cloning.runtime.emfextension.impl.LooseCopier;
import fr.inria.diverse.cloning.materialgenerator.tagger.Tagger;
import fr.inria.diverse.cloning.materialgenerator.util.CodeGeneration;
......@@ -56,7 +56,7 @@ public class CloningMaterialClassGenerator {
imports += "import " + CloningMaterial.class.getCanonicalName() + ";\n";
//imports += "import " + LooseCopier.class.getCanonicalName() + ";\n";
imports += "import " + MetamodelTags.class.getCanonicalName() + ";\n";
imports += "import " + Copier.class.getCanonicalName() + ";\n";
imports += "import " + LooseCopier.class.getCanonicalName() + ";\n";
// Class declaration
String classdef = "public class " + className + " implements " + CloningMaterial.class.getSimpleName()
......@@ -80,17 +80,17 @@ public class CloningMaterialClassGenerator {
// getTags method declaration
classdef += "public " + MetamodelTags.class.getSimpleName() + " getTags() {\n";
classdef += "return tags;";
// end getTags method declaration
// end getTags method declarationCopier
classdef += "}\n";
// createLightCopier method declaration
String copierClassName = CodeGeneration.firstCharUp(tagger.getMetamodelName() + tagger.getCloningName()
+ Constants.COPIER_SUFFIX);
classdef += "public " + Copier.class.getSimpleName() + " createCopier() {\n";
classdef += "public " + LooseCopier.class.getSimpleName() + " createCopier() {\n";
if (tagger.mayTagClassesPartShareable())
classdef += "return new " + copierClassName + "();";
else
classdef += "return new Copier ();";
classdef += "return new LooseCopier ();";
// end createLightCopier method declaration
classdef += "}\n";
......
......@@ -23,6 +23,7 @@ import org.eclipse.emf.ecore.resource.ResourceSet;
import fr.inria.diverse.cloning.materialgenerator.tagger.Tagger;
import fr.inria.diverse.cloning.runtime.common.ClassTag;
import fr.inria.diverse.cloning.runtime.util.EcoreHelper;
import fr.inria.diverse.cloning.runtime.util.Log;
public abstract class AbstractTagger implements Tagger {
......@@ -69,7 +70,8 @@ public abstract class AbstractTagger implements Tagger {
}
protected static boolean isPropertyDesignedMutable(EStructuralFeature f) {
return f.getName().endsWith("_m");
//return f.getName().endsWith("_m");
return EcoreHelper.isPropertyDesignedMutable(f);
}
......
......@@ -18,13 +18,13 @@ import org.eclipse.emf.ecore.EObject;
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.Copier;
import org.eclipse.emf.ecore.xmi.impl.XMIResourceImpl;
import fr.inria.diverse.cloning.runtime.cloner.Cloner;
import fr.inria.diverse.cloning.runtime.common.ClassTag;
import fr.inria.diverse.cloning.runtime.common.CloningMaterial;
import fr.inria.diverse.cloning.runtime.common.MetamodelTags;
import fr.inria.diverse.cloning.runtime.emfextension.impl.LooseCopier;
import fr.inria.diverse.cloning.runtime.emfextension.impl.LooseResource;
/**
......@@ -54,7 +54,7 @@ public class ClonerImpl implements Cloner {
copier = cloningMaterial.createCopier();
else
copier = new LooseCopier();*/
Copier copier = cloningMaterial.createCopier();
LooseCopier copier = cloningMaterial.createCopier();
// Getting the tags of the metamodel
MetamodelTags tags = cloningMaterial.getTags();
......@@ -121,7 +121,7 @@ public class ClonerImpl implements Cloner {
}
}
// Resolving references (all of them, even between resources of the clone and between the clone and the origin)
copier.copyReferences();
......
......@@ -10,11 +10,11 @@
******************************************************************************/
package fr.inria.diverse.cloning.runtime.common;
import org.eclipse.emf.ecore.util.EcoreUtil.Copier;
import fr.inria.diverse.cloning.runtime.emfextension.impl.LooseCopier;
public interface CloningMaterial {
public MetamodelTags getTags();
public Copier createCopier();
public LooseCopier createCopier();
}
......@@ -22,17 +22,21 @@ import org.eclipse.emf.ecore.resource.ResourceSet;
import fr.inria.diverse.cloning.runtime.common.ClassTag;
import fr.inria.diverse.cloning.runtime.common.MetamodelTags;
import fr.inria.diverse.cloning.runtime.util.EcoreHelper;
// Default genmodel : org.eclipse.emf.ecore.impl.MinimalEObjectImpl$Container
/**
* Defines an EMF object that can be contained in multiple objects, as long as these objects are in different
* ResourceSets. Yet, it keeps a single "main" container, at all time (eContainer).
* Defines an EMF object that can be contained in multiple objects, as long as
* these objects are in different ResourceSets. Yet, it keeps a single "main"
* container, at all time (eContainer).
*
* @author ebousse
*
*
*/
public abstract class AbstractShareableEObject extends MinimalEObjectImpl.Container {// implements ShareableEObject {
public abstract class AbstractShareableEObject extends MinimalEObjectImpl.Container {// implements
// ShareableEObject
// {
/**
* Internal class to store the context temporarily
......@@ -66,7 +70,8 @@ public abstract class AbstractShareableEObject extends MinimalEObjectImpl.Contai
protected Map<ResourceSet, Object> additionnalContainersOrResources;
/**
* Maps are initialized only at first usage, in order to save some memory (despite)
* Maps are initialized only at first usage, in order to save some memory
* (despite)
*/
protected AbstractShareableEObject() {
super();
......@@ -107,10 +112,11 @@ public abstract class AbstractShareableEObject extends MinimalEObjectImpl.Contai
ResourceSet currentRS = findResourceSet(this);
Resource otherResource = findResource(otherEnd);
ResourceSet otherRS = findResourceSet(otherEnd);
// We must only change the context if the otherEnd is in a LooseResource
// in another ResourceSet
// AND if we are considered readonly by the cloning technique of the LooseResource
// AND if we are considered readonly by the cloning technique of the
// LooseResource
boolean toChange = (otherResource != null)
&& (otherResource instanceof LooseResource)
&& (((LooseResource) (otherResource)).getTags().getTagOf(this.eClass()) == ClassTag.COMPLETELY_SHAREABLE)
......@@ -127,13 +133,18 @@ public abstract class AbstractShareableEObject extends MinimalEObjectImpl.Contai
// We initialize the maps at the first usage
// if (this.additionnalContainersOrResources == null) {
// additionnalContainersOrResources = new HashMap<ResourceSet, Object>(1);
// additionnalContainersOrResources = new HashMap<ResourceSet,
// Object>(1);
// }
// If we don't have entries for the otherResourceSet,
// we create ones with 'null' (ie not contained in this resource yet)
// if (!this.additionnalContainersOrResources.containsKey(otherResourceSet)) {
// this.additionnalContainersOrResources.put(otherResourceSet, null);
// we create ones with 'null' (ie not contained in this resource
// yet)
// if
// (!this.additionnalContainersOrResources.containsKey(otherResourceSet))
// {
// this.additionnalContainersOrResources.put(otherResourceSet,
// null);
// }
// We remove ourselves from a resource
......@@ -166,9 +177,11 @@ public abstract class AbstractShareableEObject extends MinimalEObjectImpl.Contai
* this.additionnalContainersAndResources.get(otherResourceSet)[0];
*
*
* // We temporarily change the resource, if the container was null if (otherCont == null) { Resource
* otherResource = (Resource) this.additionnalContainersAndResources.get(otherResourceSet)[1]; if
* (otherResource != null) otherResource.getContents().add(this); }
* // We temporarily change the resource, if the container was null
* if (otherCont == null) { Resource otherResource = (Resource)
* this.additionnalContainersAndResources.get(otherResourceSet)[1];
* if (otherResource != null) otherResource.getContents().add(this);
* }
*/
// And we return the context for further restore
......@@ -201,10 +214,10 @@ public abstract class AbstractShareableEObject extends MinimalEObjectImpl.Contai
MetamodelTags tags = null;
if (otherResource != null && otherResource instanceof LooseResource)
tags = ((LooseResource) (otherResource)).getTags();
if (tags != null && tags.isPropertyShareable(this.eContainmentFeature())) {
// if (tags != null &&
// tags.isPropertyShareable(this.eContainmentFeature())) {
if (tags != null && !EcoreHelper.isPropertyDesignedMutable(this.eContainmentFeature())) {
storeContainer = false;
}
if (storeContainer) {
......@@ -233,13 +246,15 @@ public abstract class AbstractShareableEObject extends MinimalEObjectImpl.Contai
@Override
/*
* (non-Javadoc) Appelé lorsqu'un B (this) est ajouté à un A (otherEnd)
* (non-Javadoc) Appelé lorsque this est ajouté à otherEnd
*
* @see org.eclipse.emf.ecore.impl.BasicEObjectImpl#eInverseAdd(org.eclipse.emf .ecore.InternalEObject, int,
* java.lang.Class, org.eclipse.emf.common.notify.NotificationChain)
* @see
* org.eclipse.emf.ecore.impl.BasicEObjectImpl#eInverseAdd(org.eclipse.emf
* .ecore.InternalEObject, int, java.lang.Class,
* org.eclipse.emf.common.notify.NotificationChain)
*/
public NotificationChain eInverseAdd(InternalEObject otherEnd, int featureID, Class<?> baseClass,
NotificationChain msgs) {
public NotificationChain eInverseAdd(InternalEObject otherEnd, int featureID,
Class<?> baseClass, NotificationChain msgs) {
// Changing the context
ReadonlyContext context = changeContext(otherEnd);
......@@ -256,13 +271,15 @@ public abstract class AbstractShareableEObject extends MinimalEObjectImpl.Contai
@Override
/*
* (non-Javadoc) Appelé lorsqu'un B (this) est retiré d'un A (otherEnd)
* (non-Javadoc) Appelé lorsque this est retiré de otherEnd
*
* @see org.eclipse.emf.ecore.impl.BasicEObjectImpl#eInverseRemove(org.eclipse .emf.ecore.InternalEObject, int,
* java.lang.Class, org.eclipse.emf.common.notify.NotificationChain)
* @see
* org.eclipse.emf.ecore.impl.BasicEObjectImpl#eInverseRemove(org.eclipse
* .emf.ecore.InternalEObject, int, java.lang.Class,
* org.eclipse.emf.common.notify.NotificationChain)
*/
public NotificationChain eInverseRemove(InternalEObject otherEnd, int featureID, Class<?> baseClass,
NotificationChain msgs) {
public NotificationChain eInverseRemove(InternalEObject otherEnd, int featureID,
Class<?> baseClass, NotificationChain msgs) {
// Changing the context
ReadonlyContext context = changeContext(otherEnd);
......@@ -270,14 +287,16 @@ public abstract class AbstractShareableEObject extends MinimalEObjectImpl.Contai
// Actual call
NotificationChain result = super.eInverseRemove(otherEnd, featureID, baseClass, msgs);
// hack to destroy the map with containers if the containment is shareable
ResourceSet currentRS = findResourceSet(this);
// handling the removal from the hashmap, if required
Resource otherResource = findResource(otherEnd);
MetamodelTags tags = null;
if (otherResource != null && otherResource instanceof LooseResource)
tags = ((LooseResource) (otherResource)).getTags();
if (tags != null && tags.isPropertyShareable(this.eContainmentFeature())) {
this.additionnalContainersOrResources.remove(currentRS);
ResourceSet otherRS = findResourceSet(otherEnd);
//MetamodelTags tags = null;
if (otherResource != null && otherResource instanceof LooseResource) {
// tags = ((LooseResource) (otherResource)).getTags();
// if (tags != null &&
// !EcoreHelper.isPropertyDesignedMutable(this.eContainmentFeature()))
// {
this.additionnalContainersOrResources.remove(otherRS);
if (this.additionnalContainersOrResources.size() == 0)
this.additionnalContainersOrResources = null;
}
......@@ -290,12 +309,14 @@ public abstract class AbstractShareableEObject extends MinimalEObjectImpl.Contai
}
/**
* Added method that allow one to change the resource of the object without changing what resources think they
* contain. Created for the "save" method of LooseResource, that must briefly change the resources of the elements
* Added method that allow one to change the resource of the object without
* changing what resources think they contain. Created for the "save" method
* of LooseResource, that must briefly change the resources of the elements
* of a model for correct referencing between resources.
*
* @param resource
* The resource to set in the object. The resource won't be changed.
* The resource to set in the object. The resource won't be
* changed.
*/
public void setResourceNonInverse(Internal resource) {
eSetDirectResource(resource);
......
......@@ -18,6 +18,7 @@ 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.resource.Resource;
import org.eclipse.emf.ecore.resource.ResourceSet;
......@@ -41,6 +42,10 @@ public class EcoreHelper {
}
}
public static boolean isPropertyDesignedMutable(EStructuralFeature f) {
return f.getName().endsWith("_m");
}
public static Set<EClass> findRoots(Set<EClass> metamodel) {
......
#!/bin/bash
RARGS=""
for i in "$@"
do
RARGS="$RARGS $i"
done
R --no-save --args $RARGS < ~/Dev/modelCloning/emf/process-data.R
ls *.pdf | xargs -I '{}' pdfcrop '{}' '{}'
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment