Home » Modeling » EMF "Technology" (Ecore Tools, EMFatic, etc) » Is EMF Compare right for this use-case?
Is EMF Compare right for this use-case? [message #138669] |
Wed, 15 July 2009 17:57 |
No real name Messages: 61 Registered: July 2009 |
Member |
|
|
Hi,
I am not sure if EMF Compare is right for my task. I want JUnit-test
T2M-transformations. For this reason, the test creates a model from some
text. Then I need to compare it with a reference-model.
I already implemented it like this:
MatchModel match = MatchService.doMatch(referenceModel,
createdModel, Collections.<String, Object> emptyMap());
DiffModel diff = DiffService.doDiff(match, false);
List<DiffElement> differences = diff.getOwnedElements();
if( differences.size() > 0 ){
Assert.assertTrue("the created model is different from the
reference-model", false);
}
Unfortunatly, there are differences, even though the model are equal,
except for ID's. But I want to ignore ID's and I just want to know if the
models are "logically" equal.
My simple (UML2-)test-models are:
model 1
<?xml version="1.0" encoding="UTF-8"?>
<uml:Model xmi:version="2.1"
xmlns:xmi="http://schema.omg.org/spec/XMI/2.1"
xmlns:uml="http://www.eclipse.org/uml2/3.0.0/UML"
xmi:id="_Wb9ysXFoEd6xJohxLdzz5Q">
<packagedElement xmi:type="uml:Package" xmi:id="_Wb9ysnFoEd6xJohxLdzz5Q"
name="foo">
<packagedElement xmi:type="uml:Class" xmi:id="_Wb9ys3FoEd6xJohxLdzz5Q"
name="SimpleClass"/>
</packagedElement>
</uml:Model>
model 2
<?xml version="1.0" encoding="UTF-8"?>
<uml:Model xmi:version="2.1"
xmlns:xmi="http://schema.omg.org/spec/XMI/2.1"
xmlns:uml="http://www.eclipse.org/uml2/3.0.0/UML"
xmi:id="_WcG8oHFoEd6xJohxLdzz5Q">
<packagedElement xmi:type="uml:Package" xmi:id="_WcG8oXFoEd6xJohxLdzz5Q"
name="foo">
<packagedElement xmi:type="uml:Class" xmi:id="_WcG8onFoEd6xJohxLdzz5Q"
name="SimpleClass"/>
</packagedElement>
</uml:Model>
If I compare these models with the GUI, it says:
"2 change(s) in <Model>"
- "<Package> foo has been added"
- "<Package> foo has been removed"
Is there maybe some kind of mode that I can use, or is EMF Compare the
wrong choice for this task?
thank you
|
|
|
Re: Is EMF Compare right for this use-case? [message #138683 is a reply to message #138669] |
Wed, 15 July 2009 20:51 |
Eclipse User |
|
|
|
Originally posted by: stephenmccants.yahoo.com
Hi Usul,
You might like at the MatchOptions.OPTION_IGNORE_XMI_ID. I'm not sure if that does what you need
or only part of what you need.
Hope that helps.
Sincerely,
Stephen
Usul wrote:
> Hi,
>
> I am not sure if EMF Compare is right for my task. I want JUnit-test
> T2M-transformations. For this reason, the test creates a model from some
> text. Then I need to compare it with a reference-model.
>
> I already implemented it like this:
> MatchModel match = MatchService.doMatch(referenceModel,
> createdModel, Collections.<String, Object> emptyMap());
> DiffModel diff = DiffService.doDiff(match, false);
> List<DiffElement> differences = diff.getOwnedElements();
>
> if( differences.size() > 0 ){
> Assert.assertTrue("the created model is different from
> the reference-model", false);
> }
>
> Unfortunatly, there are differences, even though the model are equal,
> except for ID's. But I want to ignore ID's and I just want to know if
> the models are "logically" equal.
>
> My simple (UML2-)test-models are:
> model 1
> <?xml version="1.0" encoding="UTF-8"?>
> <uml:Model xmi:version="2.1"
> xmlns:xmi="http://schema.omg.org/spec/XMI/2.1"
> xmlns:uml="http://www.eclipse.org/uml2/3.0.0/UML"
> xmi:id="_Wb9ysXFoEd6xJohxLdzz5Q">
> <packagedElement xmi:type="uml:Package"
> xmi:id="_Wb9ysnFoEd6xJohxLdzz5Q" name="foo">
> <packagedElement xmi:type="uml:Class"
> xmi:id="_Wb9ys3FoEd6xJohxLdzz5Q" name="SimpleClass"/>
> </packagedElement>
> </uml:Model>
>
> model 2
> <?xml version="1.0" encoding="UTF-8"?>
> <uml:Model xmi:version="2.1"
> xmlns:xmi="http://schema.omg.org/spec/XMI/2.1"
> xmlns:uml="http://www.eclipse.org/uml2/3.0.0/UML"
> xmi:id="_WcG8oHFoEd6xJohxLdzz5Q">
> <packagedElement xmi:type="uml:Package"
> xmi:id="_WcG8oXFoEd6xJohxLdzz5Q" name="foo">
> <packagedElement xmi:type="uml:Class"
> xmi:id="_WcG8onFoEd6xJohxLdzz5Q" name="SimpleClass"/>
> </packagedElement>
> </uml:Model>
>
> If I compare these models with the GUI, it says:
> "2 change(s) in <Model>"
> - "<Package> foo has been added"
> - "<Package> foo has been removed"
>
> Is there maybe some kind of mode that I can use, or is EMF Compare the
> wrong choice for this task?
>
>
>
> thank you
>
>
|
|
|
Re: Is EMF Compare right for this use-case? [message #138721 is a reply to message #138683] |
Thu, 16 July 2009 07:36 |
|
This is a multi-part message in MIME format.
--------------050002040801030109070507
Content-Type: text/plain; charset=ISO-8859-15; format=flowed
Content-Transfer-Encoding: 8bit
Hi,
Yup, MatchOptions.OPTION_IGNORE_XMI_ID is indeed the option Usul needs
.... but it defaults to false so the matching should already work as
intended.
Usul, these IDs can only be accessed when the model is contained within
XMIResources. If you created Resources to contain your models, they need
to be "new XMIResourceImpl()".
From the GUI, you will have two differences if the option discussed
above is true. This can be checked from "Window => Preferences => EMF
Compare". On this page, the option is labeled "Ignore XMI IDs for model
comparison". If it isn't ticked, you shouldn't have any difference detected.
Laurent Goubet
Obeo
Stephen McCants a
|
|
|
Re: Is EMF Compare right for this use-case? [message #138756 is a reply to message #138721] |
Thu, 16 July 2009 14:04 |
No real name Messages: 61 Registered: July 2009 |
Member |
|
|
Thank you. It works on the GUI, but I cant manage to get it done
programmaticly.
Here is what I have:
// saving models
ResourceSet resourceSet = new ResourceSetImpl();
IFile file = srcFolder.getFile("createdModel.uml");
String path = file.getLocation().toFile().getAbsolutePath();
URI fileURI = URI.createFileURI(path);
Resource resource = new XMIResourceImpl(fileURI);
resource.getContents().add(createdModel);
resource.save(Collections.EMPTY_MAP);
resourceSet.getResources().add(resource);
file = srcFolder.getFile("referenceModel.uml");
path = file.getLocation().toFile().getAbsolutePath();
fileURI = URI.createFileURI(path);
resource = new XMIResourceImpl(fileURI);
resourceSet.getResources().add(resource);
resource.save(Collections.EMPTY_MAP);
resource.getContents().add(createdModel);
// refresh workspace
IWorkspaceRoot wRoot = ResourcesPlugin.getWorkspace().getRoot();
IResource resc = wRoot.findMember(new Path(project.getName()));
resc.refreshLocal(IResource.DEPTH_INFINITE, null);
// compare the generated model with the reference-model
Map<String, Object> options = new HashMap<String, Object>();
options.put(MatchOptions.OPTION_IGNORE_XMI_ID, new Boolean(true));
MatchModel match = MatchService.doMatch(referenceModel,
createdModel, options);
DiffModel diff = DiffService.doDiff(match, false);
List<DiffElement> differences = diff.getOwnedElements();
if( differences.size() > 0 ){
Assert.assertTrue("the created model is different from the
reference-model", false);
}
And its back to the NullPointerException:
java.lang.NullPointerException
at
org.eclipse.emf.compare.match.engine.GenericMatchEngine.mode lMatch(GenericMatchEngine.java:356)
at
org.eclipse.emf.compare.match.service.MatchService.doMatch(M atchService.java:160)
at
alltests.ParentT2MAndM2TTestCase.testT2M(ParentT2MAndM2TTest Case.java:374)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at
org.junit.runners.model.FrameworkMethod$1.runReflectiveCall( FrameworkMethod.java:44)
at
org.junit.internal.runners.model.ReflectiveCallable.run(Refl ectiveCallable.java:15)
at
org.junit.runners.model.FrameworkMethod.invokeExplosively(Fr ameworkMethod.java:41)
at
org.junit.internal.runners.statements.InvokeMethod.evaluate( InvokeMethod.java:20)
at
org.junit.internal.runners.statements.RunBefores.evaluate(Ru nBefores.java:28)
at
org.junit.internal.runners.statements.RunAfters.evaluate(Run Afters.java:31)
at
org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit 4ClassRunner.java:73)
at
org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit 4ClassRunner.java:46)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java :180)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java: 41)
at org.junit.runners.ParentRunner$1.evaluate(ParentRunner.java: 173)
at
org.junit.internal.runners.statements.RunBefores.evaluate(Ru nBefores.java:28)
at
org.junit.internal.runners.statements.RunAfters.evaluate(Run Afters.java:31)
at org.junit.runners.ParentRunner.run(ParentRunner.java:220)
at org.junit.runners.Suite.runChild(Suite.java:115)
at org.junit.runners.Suite.runChild(Suite.java:23)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java :180)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java: 41)
at org.junit.runners.ParentRunner$1.evaluate(ParentRunner.java: 173)
at
org.junit.internal.runners.statements.RunBefores.evaluate(Ru nBefores.java:28)
at
org.junit.internal.runners.statements.RunAfters.evaluate(Run Afters.java:31)
at org.junit.runners.ParentRunner.run(ParentRunner.java:220)
at
org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.r un(JUnit4TestReference.java:46)
at
org.eclipse.jdt.internal.junit.runner.TestExecution.run(Test Execution.java:38)
at
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTe sts(RemoteTestRunner.java:467)
at
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTe sts(RemoteTestRunner.java:683)
at
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(R emoteTestRunner.java:390)
at
org.eclipse.pde.internal.junit.runtime.RemotePluginTestRunne r.main(RemotePluginTestRunner.java:62)
at
org.eclipse.pde.internal.junit.runtime.CoreTestApplication.r un(CoreTestApplication.java:23)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at
org.eclipse.equinox.internal.app.EclipseAppContainer.callMet hodWithException(EclipseAppContainer.java:574)
at
org.eclipse.equinox.internal.app.EclipseAppHandle.run(Eclips eAppHandle.java:196)
at
org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher .runApplication(EclipseAppLauncher.java:110)
at
org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher .start(EclipseAppLauncher.java:79)
at
org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseS tarter.java:368)
at
org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseS tarter.java:179)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.eclipse.equinox.launcher.Main.invokeFramework(Main.java: 559)
at org.eclipse.equinox.launcher.Main.basicRun(Main.java:514)
at org.eclipse.equinox.launcher.Main.run(Main.java:1311)
at org.eclipse.equinox.launcher.Main.main(Main.java:1287)
I think I'm not saving the ressources right. I tried using
XMIResourceImpl as you can see (and they are being saved), but I suspect
I'm not correctly adding them to the ResourseSet. Any hints?
thank you
> Hi,
> Yup, MatchOptions.OPTION_IGNORE_XMI_ID is indeed the option Usul needs
> .... but it defaults to false so the matching should already work as
> intended.
> Usul, these IDs can only be accessed when the model is contained within
> XMIResources. If you created Resources to contain your models, they need
> to be "new XMIResourceImpl()".
> From the GUI, you will have two differences if the option discussed
> above is true. This can be checked from "Window => Preferences => EMF
> Compare". On this page, the option is labeled "Ignore XMI IDs for model
> comparison". If it isn't ticked, you shouldn't have any difference detected.
> Laurent Goubet
> Obeo
> Stephen McCants a écrit :
>> Hi Usul,
>> You might like at the MatchOptions.OPTION_IGNORE_XMI_ID. I'm not
>> sure if that does what you need or only part of what you need.
>> Hope that helps.
>>
>> Sincerely,
>> Stephen
>>
>> Usul wrote:
>>> Hi,
>>>
>>> I am not sure if EMF Compare is right for my task. I want JUnit-test
>>> T2M-transformations. For this reason, the test creates a model from
>>> some text. Then I need to compare it with a reference-model.
>>>
>>> I already implemented it like this:
>>> MatchModel match = MatchService.doMatch(referenceModel,
>>> createdModel, Collections.<String, Object>
>>> emptyMap());
>>> DiffModel diff = DiffService.doDiff(match, false);
>>> List<DiffElement> differences = diff.getOwnedElements();
>>>
>>> if( differences.size() > 0 ){
>>> Assert.assertTrue("the created model is different from
>>> the reference-model", false);
>>> }
>>>
>>> Unfortunatly, there are differences, even though the model are equal,
>>> except for ID's. But I want to ignore ID's and I just want to know if
>>> the models are "logically" equal.
>>>
>>> My simple (UML2-)test-models are:
>>> model 1
>>> <?xml version="1.0" encoding="UTF-8"?>
>>> <uml:Model xmi:version="2.1"
>>> xmlns:xmi="http://schema.omg.org/spec/XMI/2.1"
>>> xmlns:uml="http://www.eclipse.org/uml2/3.0.0/UML"
>>> xmi:id="_Wb9ysXFoEd6xJohxLdzz5Q">
>>> <packagedElement xmi:type="uml:Package"
>>> xmi:id="_Wb9ysnFoEd6xJohxLdzz5Q" name="foo">
>>> <packagedElement xmi:type="uml:Class"
>>> xmi:id="_Wb9ys3FoEd6xJohxLdzz5Q" name="SimpleClass"/>
>>> </packagedElement>
>>> </uml:Model>
>>>
>>> model 2
>>> <?xml version="1.0" encoding="UTF-8"?>
>>> <uml:Model xmi:version="2.1"
>>> xmlns:xmi="http://schema.omg.org/spec/XMI/2.1"
>>> xmlns:uml="http://www.eclipse.org/uml2/3.0.0/UML"
>>> xmi:id="_WcG8oHFoEd6xJohxLdzz5Q">
>>> <packagedElement xmi:type="uml:Package"
>>> xmi:id="_WcG8oXFoEd6xJohxLdzz5Q" name="foo">
>>> <packagedElement xmi:type="uml:Class"
>>> xmi:id="_WcG8onFoEd6xJohxLdzz5Q" name="SimpleClass"/>
>>> </packagedElement>
>>> </uml:Model>
>>>
>>> If I compare these models with the GUI, it says:
>>> "2 change(s) in <Model>"
>>> - "<Package> foo has been added"
>>> - "<Package> foo has been removed"
>>>
>>> Is there maybe some kind of mode that I can use, or is EMF Compare the
>>> wrong choice for this task?
>>>
>>>
>>>
>>> thank you
>>>
>>>
|
|
|
Re: Is EMF Compare right for this use-case? [message #138769 is a reply to message #138756] |
Thu, 16 July 2009 14:22 |
|
This is a multi-part message in MIME format.
--------------020802010701010205030808
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 8bit
Hi Usul,
I didn't understand that you were loading already existing models from
disk. This means you don't have to create the resources yourself. Yet
what you're loading are UML models; those can't be contained in
"XMIResource", they have their own. If you are loading your models in
standalone mode, you'll need to follow what's explained on
http://wiki.eclipse.org/MDT/UML2/FAQ#What.27s_required_to_lo ad_a_UML_.28.uml.29_resource_from_a_standalone_application.3 F
.. If you're loading them from within eclipse (your code is run from an
action or it is within unit tests run as "JUnit plugin test"), you only
need to load them. The easy way for this would be to use
org.eclipse.emf.compare.util.ModelUtils as it contains utility methods
to load models from File, URIs ... (EclipseModelUtils contain utility to
load from IFiles ... but is not standalone).
If you cannot use these utilities ... look at their code to see the
steps needed to load models from Files ^^.
When your models are loaded within their resources, the NPE you get here
should fix itself. Don't hesitate to come back here if it does not.
Laurent Goubet
Obeo
Usul a
|
|
|
Re: Is EMF Compare right for this use-case? [message #138781 is a reply to message #138756] |
Thu, 16 July 2009 15:07 |
Eclipse User |
|
|
|
Originally posted by: stephenmccants.yahoo.com
Hi Usul,
In your code you have this line twice:
resource.getContents().add(createdModel);
Should one of those lines be:
resource.getContents().add(referenceModel);
Just a thought...
--Stephen
Usul wrote:
> Thank you. It works on the GUI, but I cant manage to get it done
> programmaticly.
>
> Here is what I have:
>
> // saving models
>
> ResourceSet resourceSet = new ResourceSetImpl();
>
> IFile file = srcFolder.getFile("createdModel.uml");
> String path = file.getLocation().toFile().getAbsolutePath();
> URI fileURI = URI.createFileURI(path);
> Resource resource = new XMIResourceImpl(fileURI);
> resource.getContents().add(createdModel);
> resource.save(Collections.EMPTY_MAP);
> resourceSet.getResources().add(resource);
>
> file = srcFolder.getFile("referenceModel.uml");
> path = file.getLocation().toFile().getAbsolutePath();
> fileURI = URI.createFileURI(path);
> resource = new XMIResourceImpl(fileURI);
> resourceSet.getResources().add(resource);
> resource.save(Collections.EMPTY_MAP);
> resource.getContents().add(createdModel);
>
> // refresh workspace
>
> IWorkspaceRoot wRoot =
> ResourcesPlugin.getWorkspace().getRoot();
> IResource resc = wRoot.findMember(new Path(project.getName()));
> resc.refreshLocal(IResource.DEPTH_INFINITE, null);
>
>
> // compare the generated model with the reference-model
>
> Map<String, Object> options = new HashMap<String, Object>();
> options.put(MatchOptions.OPTION_IGNORE_XMI_ID, new
> Boolean(true));
> MatchModel match = MatchService.doMatch(referenceModel,
> createdModel, options);
> DiffModel diff = DiffService.doDiff(match, false);
> List<DiffElement> differences = diff.getOwnedElements();
>
> if( differences.size() > 0 ){
> Assert.assertTrue("the created model is different from
> the reference-model", false);
> }
>
> And its back to the NullPointerException:
>
> java.lang.NullPointerException
> at
> org.eclipse.emf.compare.match.engine.GenericMatchEngine.mode lMatch(GenericMatchEngine.java:356)
>
> at
> org.eclipse.emf.compare.match.service.MatchService.doMatch(M atchService.java:160)
>
> at
> alltests.ParentT2MAndM2TTestCase.testT2M(ParentT2MAndM2TTest Case.java:374)
> at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
> at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
> at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
> at java.lang.reflect.Method.invoke(Unknown Source)
> at
> org.junit.runners.model.FrameworkMethod$1.runReflectiveCall( FrameworkMethod.java:44)
>
> at
> org.junit.internal.runners.model.ReflectiveCallable.run(Refl ectiveCallable.java:15)
>
> at
> org.junit.runners.model.FrameworkMethod.invokeExplosively(Fr ameworkMethod.java:41)
>
> at
> org.junit.internal.runners.statements.InvokeMethod.evaluate( InvokeMethod.java:20)
>
> at
> org.junit.internal.runners.statements.RunBefores.evaluate(Ru nBefores.java:28)
>
> at
> org.junit.internal.runners.statements.RunAfters.evaluate(Run Afters.java:31)
> at
> org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit 4ClassRunner.java:73)
>
> at
> org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit 4ClassRunner.java:46)
>
> at org.junit.runners.ParentRunner.runChildren(ParentRunner.java :180)
> at org.junit.runners.ParentRunner.access$000(ParentRunner.java: 41)
> at org.junit.runners.ParentRunner$1.evaluate(ParentRunner.java: 173)
> at
> org.junit.internal.runners.statements.RunBefores.evaluate(Ru nBefores.java:28)
>
> at
> org.junit.internal.runners.statements.RunAfters.evaluate(Run Afters.java:31)
> at org.junit.runners.ParentRunner.run(ParentRunner.java:220)
> at org.junit.runners.Suite.runChild(Suite.java:115)
> at org.junit.runners.Suite.runChild(Suite.java:23)
> at org.junit.runners.ParentRunner.runChildren(ParentRunner.java :180)
> at org.junit.runners.ParentRunner.access$000(ParentRunner.java: 41)
> at org.junit.runners.ParentRunner$1.evaluate(ParentRunner.java: 173)
> at
> org.junit.internal.runners.statements.RunBefores.evaluate(Ru nBefores.java:28)
>
> at
> org.junit.internal.runners.statements.RunAfters.evaluate(Run Afters.java:31)
> at org.junit.runners.ParentRunner.run(ParentRunner.java:220)
> at
> org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.r un(JUnit4TestReference.java:46)
>
> at
> org.eclipse.jdt.internal.junit.runner.TestExecution.run(Test Execution.java:38)
>
> at
> org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTe sts(RemoteTestRunner.java:467)
>
> at
> org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTe sts(RemoteTestRunner.java:683)
>
> at
> org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(R emoteTestRunner.java:390)
>
> at
> org.eclipse.pde.internal.junit.runtime.RemotePluginTestRunne r.main(RemotePluginTestRunner.java:62)
>
> at
> org.eclipse.pde.internal.junit.runtime.CoreTestApplication.r un(CoreTestApplication.java:23)
>
> at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
> at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
> at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
> at java.lang.reflect.Method.invoke(Unknown Source)
> at
> org.eclipse.equinox.internal.app.EclipseAppContainer.callMet hodWithException(EclipseAppContainer.java:574)
>
> at
> org.eclipse.equinox.internal.app.EclipseAppHandle.run(Eclips eAppHandle.java:196)
>
> at
> org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher .runApplication(EclipseAppLauncher.java:110)
>
> at
> org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher .start(EclipseAppLauncher.java:79)
>
> at
> org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseS tarter.java:368)
>
> at
> org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseS tarter.java:179)
>
> at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
> at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
> at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
> at java.lang.reflect.Method.invoke(Unknown Source)
> at org.eclipse.equinox.launcher.Main.invokeFramework(Main.java: 559)
> at org.eclipse.equinox.launcher.Main.basicRun(Main.java:514)
> at org.eclipse.equinox.launcher.Main.run(Main.java:1311)
> at org.eclipse.equinox.launcher.Main.main(Main.java:1287)
>
>
> I think I'm not saving the ressources right. I tried using
> XMIResourceImpl as you can see (and they are being saved), but I suspect
> I'm not correctly adding them to the ResourseSet. Any hints?
>
>
> thank you
>
>> Hi,
>
>> Yup, MatchOptions.OPTION_IGNORE_XMI_ID is indeed the option Usul needs
>> .... but it defaults to false so the matching should already work as
>> intended.
>
>> Usul, these IDs can only be accessed when the model is contained
>> within XMIResources. If you created Resources to contain your models,
>> they need to be "new XMIResourceImpl()".
>
>> From the GUI, you will have two differences if the option discussed
>> above is true. This can be checked from "Window => Preferences => EMF
>> Compare". On this page, the option is labeled "Ignore XMI IDs for
>> model comparison". If it isn't ticked, you shouldn't have any
>> difference detected.
>
>> Laurent Goubet
>> Obeo
>
>> Stephen McCants a écrit :
>>> Hi Usul,
>>> You might like at the MatchOptions.OPTION_IGNORE_XMI_ID. I'm not
>>> sure if that does what you need or only part of what you need.
>>> Hope that helps.
>>>
>>> Sincerely,
>>> Stephen
>>>
>>> Usul wrote:
>>>> Hi,
>>>>
>>>> I am not sure if EMF Compare is right for my task. I want JUnit-test
>>>> T2M-transformations. For this reason, the test creates a model from
>>>> some text. Then I need to compare it with a reference-model.
>>>>
>>>> I already implemented it like this:
>>>> MatchModel match = MatchService.doMatch(referenceModel,
>>>> createdModel, Collections.<String, Object>
>>>> emptyMap());
>>>> DiffModel diff = DiffService.doDiff(match, false);
>>>> List<DiffElement> differences = diff.getOwnedElements();
>>>>
>>>> if( differences.size() > 0 ){
>>>> Assert.assertTrue("the created model is different
>>>> from the reference-model", false);
>>>> }
>>>>
>>>> Unfortunatly, there are differences, even though the model are
>>>> equal, except for ID's. But I want to ignore ID's and I just want to
>>>> know if the models are "logically" equal.
>>>>
>>>> My simple (UML2-)test-models are:
>>>> model 1
>>>> <?xml version="1.0" encoding="UTF-8"?>
>>>> <uml:Model xmi:version="2.1"
>>>> xmlns:xmi="http://schema.omg.org/spec/XMI/2.1"
>>>> xmlns:uml="http://www.eclipse.org/uml2/3.0.0/UML"
>>>> xmi:id="_Wb9ysXFoEd6xJohxLdzz5Q">
>>>> <packagedElement xmi:type="uml:Package"
>>>> xmi:id="_Wb9ysnFoEd6xJohxLdzz5Q" name="foo">
>>>> <packagedElement xmi:type="uml:Class"
>>>> xmi:id="_Wb9ys3FoEd6xJohxLdzz5Q" name="SimpleClass"/>
>>>> </packagedElement>
>>>> </uml:Model>
>>>>
>>>> model 2
>>>> <?xml version="1.0" encoding="UTF-8"?>
>>>> <uml:Model xmi:version="2.1"
>>>> xmlns:xmi="http://schema.omg.org/spec/XMI/2.1"
>>>> xmlns:uml="http://www.eclipse.org/uml2/3.0.0/UML"
>>>> xmi:id="_WcG8oHFoEd6xJohxLdzz5Q">
>>>> <packagedElement xmi:type="uml:Package"
>>>> xmi:id="_WcG8oXFoEd6xJohxLdzz5Q" name="foo">
>>>> <packagedElement xmi:type="uml:Class"
>>>> xmi:id="_WcG8onFoEd6xJohxLdzz5Q" name="SimpleClass"/>
>>>> </packagedElement>
>>>> </uml:Model>
>>>>
>>>> If I compare these models with the GUI, it says:
>>>> "2 change(s) in <Model>"
>>>> - "<Package> foo has been added"
>>>> - "<Package> foo has been removed"
>>>>
>>>> Is there maybe some kind of mode that I can use, or is EMF Compare
>>>> the wrong choice for this task?
>>>>
>>>>
>>>>
>>>> thank you
>>>>
>>>>
>
>
|
|
|
Re: Is EMF Compare right for this use-case? [message #138806 is a reply to message #138781] |
Thu, 16 July 2009 15:56 |
No real name Messages: 61 Registered: July 2009 |
Member |
|
|
Hi,
@Stephen:
Uh right, stupid me. Changing that got rid of the NPE, but still the
models are not considered equal.
@Laurent:
Yes, I'm starting the tests as "JUnit Plugin-Test" (headless mode). But
I'm not loading existing models. I create both of the models using the
EMF-Framework (i.e. using UMLFactory.eINSTANCE). Then I'm saving them,
just because I want to be able to use EMF Compare.
So right now there is no NPE, the models are being saved,
butdiff.getOwnedElements().size() still equals one. Did I use the options
wrong?
thank you
> Hi Usul,
> In your code you have this line twice:
> resource.getContents().add(createdModel);
> Should one of those lines be:
> resource.getContents().add(referenceModel);
> Just a thought...
> --Stephen
> Usul wrote:
>> Thank you. It works on the GUI, but I cant manage to get it done
>> programmaticly.
>>
>> Here is what I have:
>>
>> // saving models
>>
>> ResourceSet resourceSet = new ResourceSetImpl();
>>
>> IFile file = srcFolder.getFile("createdModel.uml");
>> String path = file.getLocation().toFile().getAbsolutePath();
>> URI fileURI = URI.createFileURI(path);
>> Resource resource = new XMIResourceImpl(fileURI);
>> resource.getContents().add(createdModel);
>> resource.save(Collections.EMPTY_MAP);
>> resourceSet.getResources().add(resource);
>>
>> file = srcFolder.getFile("referenceModel.uml");
>> path = file.getLocation().toFile().getAbsolutePath();
>> fileURI = URI.createFileURI(path);
>> resource = new XMIResourceImpl(fileURI);
>> resourceSet.getResources().add(resource);
>> resource.save(Collections.EMPTY_MAP);
>> resource.getContents().add(createdModel);
>>
>> // refresh workspace
>>
>> IWorkspaceRoot wRoot =
>> ResourcesPlugin.getWorkspace().getRoot();
>> IResource resc = wRoot.findMember(new Path(project.getName()));
>> resc.refreshLocal(IResource.DEPTH_INFINITE, null);
>>
>>
>> // compare the generated model with the reference-model
>>
>> Map<String, Object> options = new HashMap<String, Object>();
>> options.put(MatchOptions.OPTION_IGNORE_XMI_ID, new
>> Boolean(true));
>> MatchModel match = MatchService.doMatch(referenceModel,
>> createdModel, options);
>> DiffModel diff = DiffService.doDiff(match, false);
>> List<DiffElement> differences = diff.getOwnedElements();
>>
>> if( differences.size() > 0 ){
>> Assert.assertTrue("the created model is different from
>> the reference-model", false);
>> }
>>
>> And its back to the NullPointerException:
>>
>> java.lang.NullPointerException
>> at
>>
org.eclipse.emf.compare.match.engine.GenericMatchEngine.mode lMatch(GenericMatchEngine.java:356)
>>
>> at
>>
org.eclipse.emf.compare.match.service.MatchService.doMatch(M atchService.java:160)
>>
>> at
>> alltests.ParentT2MAndM2TTestCase.testT2M(ParentT2MAndM2TTest Case.java:374)
>> at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
>> at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
>> at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
>> at java.lang.reflect.Method.invoke(Unknown Source)
>> at
>>
org.junit.runners.model.FrameworkMethod$1.runReflectiveCall( FrameworkMethod.java:44)
>>
>> at
>>
org.junit.internal.runners.model.ReflectiveCallable.run(Refl ectiveCallable.java:15)
>>
>> at
>>
org.junit.runners.model.FrameworkMethod.invokeExplosively(Fr ameworkMethod.java:41)
>>
>> at
>>
org.junit.internal.runners.statements.InvokeMethod.evaluate( InvokeMethod.java:20)
>>
>> at
>>
org.junit.internal.runners.statements.RunBefores.evaluate(Ru nBefores.java:28)
>>
>> at
>> org.junit.internal.runners.statements.RunAfters.evaluate(Run Afters.java:31)
>> at
>>
org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit 4ClassRunner.java:73)
>>
>> at
>>
org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit 4ClassRunner.java:46)
>>
>> at org.junit.runners.ParentRunner.runChildren(ParentRunner.java :180)
>> at org.junit.runners.ParentRunner.access$000(ParentRunner.java: 41)
>> at org.junit.runners.ParentRunner$1.evaluate(ParentRunner.java: 173)
>> at
>>
org.junit.internal.runners.statements.RunBefores.evaluate(Ru nBefores.java:28)
>>
>> at
>> org.junit.internal.runners.statements.RunAfters.evaluate(Run Afters.java:31)
>> at org.junit.runners.ParentRunner.run(ParentRunner.java:220)
>> at org.junit.runners.Suite.runChild(Suite.java:115)
>> at org.junit.runners.Suite.runChild(Suite.java:23)
>> at org.junit.runners.ParentRunner.runChildren(ParentRunner.java :180)
>> at org.junit.runners.ParentRunner.access$000(ParentRunner.java: 41)
>> at org.junit.runners.ParentRunner$1.evaluate(ParentRunner.java: 173)
>> at
>>
org.junit.internal.runners.statements.RunBefores.evaluate(Ru nBefores.java:28)
>>
>> at
>> org.junit.internal.runners.statements.RunAfters.evaluate(Run Afters.java:31)
>> at org.junit.runners.ParentRunner.run(ParentRunner.java:220)
>> at
>>
org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.r un(JUnit4TestReference.java:46)
>>
>> at
>>
org.eclipse.jdt.internal.junit.runner.TestExecution.run(Test Execution.java:38)
>>
>> at
>>
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTe sts(RemoteTestRunner.java:467)
>>
>> at
>>
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTe sts(RemoteTestRunner.java:683)
>>
>> at
>>
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(R emoteTestRunner.java:390)
>>
>> at
>>
org.eclipse.pde.internal.junit.runtime.RemotePluginTestRunne r.main(RemotePluginTestRunner.java:62)
>>
>> at
>>
org.eclipse.pde.internal.junit.runtime.CoreTestApplication.r un(CoreTestApplication.java:23)
>>
>> at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
>> at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
>> at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
>> at java.lang.reflect.Method.invoke(Unknown Source)
>> at
>>
org.eclipse.equinox.internal.app.EclipseAppContainer.callMet hodWithException(EclipseAppContainer.java:574)
>>
>> at
>>
org.eclipse.equinox.internal.app.EclipseAppHandle.run(Eclips eAppHandle.java:196)
>>
>> at
>>
org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher .runApplication(EclipseAppLauncher.java:110)
>>
>> at
>>
org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher .start(EclipseAppLauncher.java:79)
>>
>> at
>>
org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseS tarter.java:368)
>>
>> at
>>
org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseS tarter.java:179)
>>
>> at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
>> at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
>> at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
>> at java.lang.reflect.Method.invoke(Unknown Source)
>> at org.eclipse.equinox.launcher.Main.invokeFramework(Main.java: 559)
>> at org.eclipse.equinox.launcher.Main.basicRun(Main.java:514)
>> at org.eclipse.equinox.launcher.Main.run(Main.java:1311)
>> at org.eclipse.equinox.launcher.Main.main(Main.java:1287)
>>
>>
>> I think I'm not saving the ressources right. I tried using
>> XMIResourceImpl as you can see (and they are being saved), but I suspect
>> I'm not correctly adding them to the ResourseSet. Any hints?
>>
>>
>> thank you
>>
>>> Hi,
>>
>>> Yup, MatchOptions.OPTION_IGNORE_XMI_ID is indeed the option Usul needs
>>> .... but it defaults to false so the matching should already work as
>>> intended.
>>
>>> Usul, these IDs can only be accessed when the model is contained
>>> within XMIResources. If you created Resources to contain your models,
>>> they need to be "new XMIResourceImpl()".
>>
>>> From the GUI, you will have two differences if the option discussed
>>> above is true. This can be checked from "Window => Preferences => EMF
>>> Compare". On this page, the option is labeled "Ignore XMI IDs for
>>> model comparison". If it isn't ticked, you shouldn't have any
>>> difference detected.
>>
>>> Laurent Goubet
>>> Obeo
>>
>>> Stephen McCants a écrit :
>>>> Hi Usul,
>>>> You might like at the MatchOptions.OPTION_IGNORE_XMI_ID. I'm not
>>>> sure if that does what you need or only part of what you need.
>>>> Hope that helps.
>>>>
>>>> Sincerely,
>>>> Stephen
>>>>
>>>> Usul wrote:
>>>>> Hi,
>>>>>
>>>>> I am not sure if EMF Compare is right for my task. I want JUnit-test
>>>>> T2M-transformations. For this reason, the test creates a model from
>>>>> some text. Then I need to compare it with a reference-model.
>>>>>
>>>>> I already implemented it like this:
>>>>> MatchModel match = MatchService.doMatch(referenceModel,
>>>>> createdModel, Collections.<String, Object>
>>>>> emptyMap());
>>>>> DiffModel diff = DiffService.doDiff(match, false);
>>>>> List<DiffElement> differences = diff.getOwnedElements();
>>>>>
>>>>> if( differences.size() > 0 ){
>>>>> Assert.assertTrue("the created model is different
>>>>> from the reference-model", false);
>>>>> }
>>>>>
>>>>> Unfortunatly, there are differences, even though the model are
>>>>> equal, except for ID's. But I want to ignore ID's and I just want to
>>>>> know if the models are "logically" equal.
>>>>>
>>>>> My simple (UML2-)test-models are:
>>>>> model 1
>>>>> <?xml version="1.0" encoding="UTF-8"?>
>>>>> <uml:Model xmi:version="2.1"
>>>>> xmlns:xmi="http://schema.omg.org/spec/XMI/2.1"
>>>>> xmlns:uml="http://www.eclipse.org/uml2/3.0.0/UML"
>>>>> xmi:id="_Wb9ysXFoEd6xJohxLdzz5Q">
>>>>> <packagedElement xmi:type="uml:Package"
>>>>> xmi:id="_Wb9ysnFoEd6xJohxLdzz5Q" name="foo">
>>>>> <packagedElement xmi:type="uml:Class"
>>>>> xmi:id="_Wb9ys3FoEd6xJohxLdzz5Q" name="SimpleClass"/>
>>>>> </packagedElement>
>>>>> </uml:Model>
>>>>>
>>>>> model 2
>>>>> <?xml version="1.0" encoding="UTF-8"?>
>>>>> <uml:Model xmi:version="2.1"
>>>>> xmlns:xmi="http://schema.omg.org/spec/XMI/2.1"
>>>>> xmlns:uml="http://www.eclipse.org/uml2/3.0.0/UML"
>>>>> xmi:id="_WcG8oHFoEd6xJohxLdzz5Q">
>>>>> <packagedElement xmi:type="uml:Package"
>>>>> xmi:id="_WcG8oXFoEd6xJohxLdzz5Q" name="foo">
>>>>> <packagedElement xmi:type="uml:Class"
>>>>> xmi:id="_WcG8onFoEd6xJohxLdzz5Q" name="SimpleClass"/>
>>>>> </packagedElement>
>>>>> </uml:Model>
>>>>>
>>>>> If I compare these models with the GUI, it says:
>>>>> "2 change(s) in <Model>"
>>>>> - "<Package> foo has been added"
>>>>> - "<Package> foo has been removed"
>>>>>
>>>>> Is there maybe some kind of mode that I can use, or is EMF Compare
>>>>> the wrong choice for this task?
>>>>>
>>>>>
>>>>>
>>>>> thank you
>>>>>
>>>>>
>>
>>
|
|
|
Re: Is EMF Compare right for this use-case? [message #138859 is a reply to message #138806] |
Fri, 17 July 2009 08:31 |
|
This is a multi-part message in MIME format.
--------------060905010306020903000502
Content-Type: text/plain; charset=ISO-8859-15; format=flowed
Content-Transfer-Encoding: 8bit
Hi Usul,
You don't need to save your models in order to compare them with EMF
Compare. As long as they're created and live in a Resource, they can be
compared. As for the option, you're using it right. What I didn't pay
enough attention to in your code are the last few lines.
"diff.getOwnedElements()" will always have a size greater than 0 as it
will always contain the root of all differences for the compared models;
be there differences or not. What should be equal to 0 though is the
result of "getSubChanges" on this root.
----------8<----------
[...]
DiffGroup diffRoot = diff.getOwnedElements().get(0);
if( diffRoot.getSubChanges() > 0 ){
fail("the created model is different from the reference-model");
}
---------->8----------
Laurent Goubet
Obeo
Usul a
|
|
|
Re: Is EMF Compare right for this use-case? [message #138883 is a reply to message #138859] |
Fri, 17 July 2009 14:39 |
No real name Messages: 61 Registered: July 2009 |
Member |
|
|
Hi Laurent,
thank you very much! Solved. Thanks again!
> Hi Usul,
> You don't need to save your models in order to compare them with EMF
> Compare. As long as they're created and live in a Resource, they can be
> compared. As for the option, you're using it right. What I didn't pay
> enough attention to in your code are the last few lines.
> "diff.getOwnedElements()" will always have a size greater than 0 as it
> will always contain the root of all differences for the compared models;
> be there differences or not. What should be equal to 0 though is the
> result of "getSubChanges" on this root.
> ----------8<----------
> [...]
> DiffGroup diffRoot = diff.getOwnedElements().get(0);
> if( diffRoot.getSubChanges() > 0 ){
> fail("the created model is different from the reference-model");
> }
> ---------->8----------
> Laurent Goubet
> Obeo
> Usul a écrit :
>> Hi,
>>
>> @Stephen:
>> Uh right, stupid me. Changing that got rid of the NPE, but still the
>> models are not considered equal.
>>
>> @Laurent:
>> Yes, I'm starting the tests as "JUnit Plugin-Test" (headless mode). But
>> I'm not loading existing models. I create both of the models using the
>> EMF-Framework (i.e. using UMLFactory.eINSTANCE). Then I'm saving them,
>> just because I want to be able to use EMF Compare.
>> So right now there is no NPE, the models are being saved,
>> butdiff.getOwnedElements().size() still equals one. Did I use the
>> options wrong?
>>
>>
>> thank you
>>
>>
>>> Hi Usul,
>>> In your code you have this line twice:
>>
>>> resource.getContents().add(createdModel);
>>
>>> Should one of those lines be:
>>
>>> resource.getContents().add(referenceModel);
>>
>>> Just a thought...
>>
>>> --Stephen
>>
>>> Usul wrote:
>>>> Thank you. It works on the GUI, but I cant manage to get it done
>>>> programmaticly.
>>>>
>>>> Here is what I have:
>>>>
>>>> // saving models
>>>>
>>>> ResourceSet resourceSet = new ResourceSetImpl();
>>>> IFile file =
>>>> srcFolder.getFile("createdModel.uml");
>>>> String path = file.getLocation().toFile().getAbsolutePath();
>>>> URI fileURI = URI.createFileURI(path);
>>>> Resource resource = new XMIResourceImpl(fileURI);
>>>> resource.getContents().add(createdModel);
>>>> resource.save(Collections.EMPTY_MAP);
>>>> resourceSet.getResources().add(resource);
>>>>
>>>> file = srcFolder.getFile("referenceModel.uml");
>>>> path = file.getLocation().toFile().getAbsolutePath();
>>>> fileURI = URI.createFileURI(path);
>>>> resource = new XMIResourceImpl(fileURI);
>>>> resourceSet.getResources().add(resource);
>>>> resource.save(Collections.EMPTY_MAP);
>>>> resource.getContents().add(createdModel);
>>>>
>>>> // refresh workspace
>>>>
>>>> IWorkspaceRoot wRoot =
>>>> ResourcesPlugin.getWorkspace().getRoot();
>>>> IResource resc = wRoot.findMember(new
>>>> Path(project.getName()));
>>>> resc.refreshLocal(IResource.DEPTH_INFINITE, null);
>>>>
>>>> // compare the generated model with the reference-model
>>>> Map<String, Object> options = new HashMap<String,
>>>> Object>();
>>>> options.put(MatchOptions.OPTION_IGNORE_XMI_ID, new
>>>> Boolean(true));
>>>> MatchModel match = MatchService.doMatch(referenceModel,
>>>> createdModel, options);
>>>> DiffModel diff = DiffService.doDiff(match, false);
>>>> List<DiffElement> differences = diff.getOwnedElements();
>>>>
>>>> if( differences.size() > 0 ){
>>>> Assert.assertTrue("the created model is different
>>>> from the reference-model", false);
>>>> }
>>>>
>>>> And its back to the NullPointerException:
>>>>
>>>> java.lang.NullPointerException
>>>> at
>>
org.eclipse.emf.compare.match.engine.GenericMatchEngine.mode lMatch(GenericMatchEngine.java:356)
>>
>>>>
>>>> at
>>
org.eclipse.emf.compare.match.service.MatchService.doMatch(M atchService.java:160)
>>
>>>>
>>>> at
>>>>
alltests.ParentT2MAndM2TTestCase.testT2M(ParentT2MAndM2TTest Case.java:374)
>>>>
>>>> at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
>>>> at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
>>>> at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
>>>> at java.lang.reflect.Method.invoke(Unknown Source)
>>>> at
>>
org.junit.runners.model.FrameworkMethod$1.runReflectiveCall( FrameworkMethod.java:44)
>>
>>>>
>>>> at
>>
org.junit.internal.runners.model.ReflectiveCallable.run(Refl ectiveCallable.java:15)
>>
>>>>
>>>> at
>>
org.junit.runners.model.FrameworkMethod.invokeExplosively(Fr ameworkMethod.java:41)
>>
>>>>
>>>> at
>>
org.junit.internal.runners.statements.InvokeMethod.evaluate( InvokeMethod.java:20)
>>
>>>>
>>>> at
>>
org.junit.internal.runners.statements.RunBefores.evaluate(Ru nBefores.java:28)
>>
>>>>
>>>> at
>>>>
org.junit.internal.runners.statements.RunAfters.evaluate(Run Afters.java:31)
>>>>
>>>> at
>>
org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit 4ClassRunner.java:73)
>>
>>>>
>>>> at
>>
org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit 4ClassRunner.java:46)
>>
>>>>
>>>> at org.junit.runners.ParentRunner.runChildren(ParentRunner.java :180)
>>>> at org.junit.runners.ParentRunner.access$000(ParentRunner.java: 41)
>>>> at org.junit.runners.ParentRunner$1.evaluate(ParentRunner.java: 173)
>>>> at
>>
org.junit.internal.runners.statements.RunBefores.evaluate(Ru nBefores.java:28)
>>
>>>>
>>>> at
>>>>
org.junit.internal.runners.statements.RunAfters.evaluate(Run Afters.java:31)
>>>>
>>>> at org.junit.runners.ParentRunner.run(ParentRunner.java:220)
>>>> at org.junit.runners.Suite.runChild(Suite.java:115)
>>>> at org.junit.runners.Suite.runChild(Suite.java:23)
>>>> at org.junit.runners.ParentRunner.runChildren(ParentRunner.java :180)
>>>> at org.junit.runners.ParentRunner.access$000(ParentRunner.java: 41)
>>>> at org.junit.runners.ParentRunner$1.evaluate(ParentRunner.java: 173)
>>>> at
>>
org.junit.internal.runners.statements.RunBefores.evaluate(Ru nBefores.java:28)
>>
>>>>
>>>> at
>>>>
org.junit.internal.runners.statements.RunAfters.evaluate(Run Afters.java:31)
>>>>
>>>> at org.junit.runners.ParentRunner.run(ParentRunner.java:220)
>>>> at
>>
org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.r un(JUnit4TestReference.java:46)
>>
>>>>
>>>> at
>>
org.eclipse.jdt.internal.junit.runner.TestExecution.run(Test Execution.java:38)
>>
>>>>
>>>> at
>>
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTe sts(RemoteTestRunner.java:467)
>>
>>>>
>>>> at
>>
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTe sts(RemoteTestRunner.java:683)
>>
>>>>
>>>> at
>>
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(R emoteTestRunner.java:390)
>>
>>>>
>>>> at
>>
org.eclipse.pde.internal.junit.runtime.RemotePluginTestRunne r.main(RemotePluginTestRunner.java:62)
>>
>>>>
>>>> at
>>
org.eclipse.pde.internal.junit.runtime.CoreTestApplication.r un(CoreTestApplication.java:23)
>>
>>>>
>>>> at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
>>>> at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
>>>> at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
>>>> at java.lang.reflect.Method.invoke(Unknown Source)
>>>> at
>>
org.eclipse.equinox.internal.app.EclipseAppContainer.callMet hodWithException(EclipseAppContainer.java:574)
>>
>>>>
>>>> at
>>
org.eclipse.equinox.internal.app.EclipseAppHandle.run(Eclips eAppHandle.java:196)
>>
>>>>
>>>> at
>>
org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher .runApplication(EclipseAppLauncher.java:110)
>>
>>>>
>>>> at
>>
org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher .start(EclipseAppLauncher.java:79)
>>
>>>>
>>>> at
>>
org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseS tarter.java:368)
>>
>>>>
>>>> at
>>
org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseS tarter.java:179)
>>
>>>>
>>>> at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
>>>> at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
>>>> at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
>>>> at java.lang.reflect.Method.invoke(Unknown Source)
>>>> at org.eclipse.equinox.launcher.Main.invokeFramework(Main.java: 559)
>>>> at org.eclipse.equinox.launcher.Main.basicRun(Main.java:514)
>>>> at org.eclipse.equinox.launcher.Main.run(Main.java:1311)
>>>> at org.eclipse.equinox.launcher.Main.main(Main.java:1287)
>>>>
>>>>
>>>> I think I'm not saving the ressources right. I tried using
>>>> XMIResourceImpl as you can see (and they are being saved), but I
>>>> suspect I'm not correctly adding them to the ResourseSet. Any hints?
>>>>
>>>>
>>>> thank you
>>>>
>>>>> Hi,
>>>>
>>>>> Yup, MatchOptions.OPTION_IGNORE_XMI_ID is indeed the option Usul
>>>>> needs .... but it defaults to false so the matching should already
>>>>> work as intended.
>>>>
>>>>> Usul, these IDs can only be accessed when the model is contained
>>>>> within XMIResources. If you created Resources to contain your
>>>>> models, they need to be "new XMIResourceImpl()".
>>>>
>>>>> From the GUI, you will have two differences if the option discussed
>>>>> above is true. This can be checked from "Window => Preferences =>
>>>>> EMF Compare". On this page, the option is labeled "Ignore XMI IDs
>>>>> for model comparison". If it isn't ticked, you shouldn't have any
>>>>> difference detected.
>>>>
>>>>> Laurent Goubet
>>>>> Obeo
>>>>
>>>>> Stephen McCants a écrit :
>>>>>> Hi Usul,
>>>>>> You might like at the MatchOptions.OPTION_IGNORE_XMI_ID. I'm
>>>>>> not sure if that does what you need or only part of what you need.
>>>>>> Hope that helps.
>>>>>>
>>>>>> Sincerely,
>>>>>> Stephen
>>>>>>
>>>>>> Usul wrote:
>>>>>>> Hi,
>>>>>>>
>>>>>>> I am not sure if EMF Compare is right for my task. I want
>>>>>>> JUnit-test T2M-transformations. For this reason, the test creates
>>>>>>> a model from some text. Then I need to compare it with a
>>>>>>> reference-model.
>>>>>>>
>>>>>>> I already implemented it like this:
>>>>>>> MatchModel match = MatchService.doMatch(referenceModel,
>>>>>>> createdModel, Collections.<String, Object>
>>>>>>> emptyMap());
>>>>>>> DiffModel diff = DiffService.doDiff(match, false);
>>>>>>> List<DiffElement> differences = diff.getOwnedElements();
>>>>>>>
>>>>>>> if( differences.size() > 0 ){
>>>>>>> Assert.assertTrue("the created model is different
>>>>>>> from the reference-model", false);
>>>>>>> }
>>>>>>>
>>>>>>> Unfortunatly, there are differences, even though the model are
>>>>>>> equal, except for ID's. But I want to ignore ID's and I just want
>>>>>>> to know if the models are "logically" equal.
>>>>>>>
>>>>>>> My simple (UML2-)test-models are:
>>>>>>> model 1
>>>>>>> <?xml version="1.0" encoding="UTF-8"?>
>>>>>>> <uml:Model xmi:version="2.1"
>>>>>>> xmlns:xmi="http://schema.omg.org/spec/XMI/2.1"
>>>>>>> xmlns:uml="http://www.eclipse.org/uml2/3.0.0/UML"
>>>>>>> xmi:id="_Wb9ysXFoEd6xJohxLdzz5Q">
>>>>>>> <packagedElement xmi:type="uml:Package"
>>>>>>> xmi:id="_Wb9ysnFoEd6xJohxLdzz5Q" name="foo">
>>>>>>> <packagedElement xmi:type="uml:Class"
>>>>>>> xmi:id="_Wb9ys3FoEd6xJohxLdzz5Q" name="SimpleClass"/>
>>>>>>> </packagedElement>
>>>>>>> </uml:Model>
>>>>>>>
>>>>>>> model 2
>>>>>>> <?xml version="1.0" encoding="UTF-8"?>
>>>>>>> <uml:Model xmi:version="2.1"
>>>>>>> xmlns:xmi="http://schema.omg.org/spec/XMI/2.1"
>>>>>>> xmlns:uml="http://www.eclipse.org/uml2/3.0.0/UML"
>>>>>>> xmi:id="_WcG8oHFoEd6xJohxLdzz5Q">
>>>>>>> <packagedElement xmi:type="uml:Package"
>>>>>>> xmi:id="_WcG8oXFoEd6xJohxLdzz5Q" name="foo">
>>>>>>> <packagedElement xmi:type="uml:Class"
>>>>>>> xmi:id="_WcG8onFoEd6xJohxLdzz5Q" name="SimpleClass"/>
>>>>>>> </packagedElement>
>>>>>>> </uml:Model>
>>>>>>>
>>>>>>> If I compare these models with the GUI, it says:
>>>>>>> "2 change(s) in <Model>"
>>>>>>> - "<Package> foo has been added"
>>>>>>> - "<Package> foo has been removed"
>>>>>>>
>>>>>>> Is there maybe some kind of mode that I can use, or is EMF Compare
>>>>>>> the wrong choice for this task?
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>> thank you
>>>>>>>
>>>>>>>
>>>>
>>>>
>>
>>
|
|
|
Re: Is EMF Compare right for this use-case? [message #621139 is a reply to message #138669] |
Wed, 15 July 2009 20:51 |
Stephen McCants Messages: 92 Registered: July 2009 |
Member |
|
|
Hi Usul,
You might like at the MatchOptions.OPTION_IGNORE_XMI_ID. I'm not sure if that does what you need
or only part of what you need.
Hope that helps.
Sincerely,
Stephen
Usul wrote:
> Hi,
>
> I am not sure if EMF Compare is right for my task. I want JUnit-test
> T2M-transformations. For this reason, the test creates a model from some
> text. Then I need to compare it with a reference-model.
>
> I already implemented it like this:
> MatchModel match = MatchService.doMatch(referenceModel,
> createdModel, Collections.<String, Object> emptyMap());
> DiffModel diff = DiffService.doDiff(match, false);
> List<DiffElement> differences = diff.getOwnedElements();
>
> if( differences.size() > 0 ){
> Assert.assertTrue("the created model is different from
> the reference-model", false);
> }
>
> Unfortunatly, there are differences, even though the model are equal,
> except for ID's. But I want to ignore ID's and I just want to know if
> the models are "logically" equal.
>
> My simple (UML2-)test-models are:
> model 1
> <?xml version="1.0" encoding="UTF-8"?>
> <uml:Model xmi:version="2.1"
> xmlns:xmi="http://schema.omg.org/spec/XMI/2.1"
> xmlns:uml="http://www.eclipse.org/uml2/3.0.0/UML"
> xmi:id="_Wb9ysXFoEd6xJohxLdzz5Q">
> <packagedElement xmi:type="uml:Package"
> xmi:id="_Wb9ysnFoEd6xJohxLdzz5Q" name="foo">
> <packagedElement xmi:type="uml:Class"
> xmi:id="_Wb9ys3FoEd6xJohxLdzz5Q" name="SimpleClass"/>
> </packagedElement>
> </uml:Model>
>
> model 2
> <?xml version="1.0" encoding="UTF-8"?>
> <uml:Model xmi:version="2.1"
> xmlns:xmi="http://schema.omg.org/spec/XMI/2.1"
> xmlns:uml="http://www.eclipse.org/uml2/3.0.0/UML"
> xmi:id="_WcG8oHFoEd6xJohxLdzz5Q">
> <packagedElement xmi:type="uml:Package"
> xmi:id="_WcG8oXFoEd6xJohxLdzz5Q" name="foo">
> <packagedElement xmi:type="uml:Class"
> xmi:id="_WcG8onFoEd6xJohxLdzz5Q" name="SimpleClass"/>
> </packagedElement>
> </uml:Model>
>
> If I compare these models with the GUI, it says:
> "2 change(s) in <Model>"
> - "<Package> foo has been added"
> - "<Package> foo has been removed"
>
> Is there maybe some kind of mode that I can use, or is EMF Compare the
> wrong choice for this task?
>
>
>
> thank you
>
>
|
|
|
Re: Is EMF Compare right for this use-case? [message #621142 is a reply to message #138683] |
Thu, 16 July 2009 07:36 |
|
This is a multi-part message in MIME format.
--------------050002040801030109070507
Content-Type: text/plain; charset=ISO-8859-15; format=flowed
Content-Transfer-Encoding: 8bit
Hi,
Yup, MatchOptions.OPTION_IGNORE_XMI_ID is indeed the option Usul needs
.... but it defaults to false so the matching should already work as
intended.
Usul, these IDs can only be accessed when the model is contained within
XMIResources. If you created Resources to contain your models, they need
to be "new XMIResourceImpl()".
From the GUI, you will have two differences if the option discussed
above is true. This can be checked from "Window => Preferences => EMF
Compare". On this page, the option is labeled "Ignore XMI IDs for model
comparison". If it isn't ticked, you shouldn't have any difference detected.
Laurent Goubet
Obeo
Stephen McCants a
|
|
|
Re: Is EMF Compare right for this use-case? [message #621145 is a reply to message #138721] |
Thu, 16 July 2009 14:04 |
No real name Messages: 61 Registered: July 2009 |
Member |
|
|
Thank you. It works on the GUI, but I cant manage to get it done
programmaticly.
Here is what I have:
// saving models
ResourceSet resourceSet = new ResourceSetImpl();
IFile file = srcFolder.getFile("createdModel.uml");
String path = file.getLocation().toFile().getAbsolutePath();
URI fileURI = URI.createFileURI(path);
Resource resource = new XMIResourceImpl(fileURI);
resource.getContents().add(createdModel);
resource.save(Collections.EMPTY_MAP);
resourceSet.getResources().add(resource);
file = srcFolder.getFile("referenceModel.uml");
path = file.getLocation().toFile().getAbsolutePath();
fileURI = URI.createFileURI(path);
resource = new XMIResourceImpl(fileURI);
resourceSet.getResources().add(resource);
resource.save(Collections.EMPTY_MAP);
resource.getContents().add(createdModel);
// refresh workspace
IWorkspaceRoot wRoot = ResourcesPlugin.getWorkspace().getRoot();
IResource resc = wRoot.findMember(new Path(project.getName()));
resc.refreshLocal(IResource.DEPTH_INFINITE, null);
// compare the generated model with the reference-model
Map<String, Object> options = new HashMap<String, Object>();
options.put(MatchOptions.OPTION_IGNORE_XMI_ID, new Boolean(true));
MatchModel match = MatchService.doMatch(referenceModel,
createdModel, options);
DiffModel diff = DiffService.doDiff(match, false);
List<DiffElement> differences = diff.getOwnedElements();
if( differences.size() > 0 ){
Assert.assertTrue("the created model is different from the
reference-model", false);
}
And its back to the NullPointerException:
java.lang.NullPointerException
at
org.eclipse.emf.compare.match.engine.GenericMatchEngine.mode lMatch(GenericMatchEngine.java:356)
at
org.eclipse.emf.compare.match.service.MatchService.doMatch(M atchService.java:160)
at
alltests.ParentT2MAndM2TTestCase.testT2M(ParentT2MAndM2TTest Case.java:374)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at
org.junit.runners.model.FrameworkMethod$1.runReflectiveCall( FrameworkMethod.java:44)
at
org.junit.internal.runners.model.ReflectiveCallable.run(Refl ectiveCallable.java:15)
at
org.junit.runners.model.FrameworkMethod.invokeExplosively(Fr ameworkMethod.java:41)
at
org.junit.internal.runners.statements.InvokeMethod.evaluate( InvokeMethod.java:20)
at
org.junit.internal.runners.statements.RunBefores.evaluate(Ru nBefores.java:28)
at
org.junit.internal.runners.statements.RunAfters.evaluate(Run Afters.java:31)
at
org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit 4ClassRunner.java:73)
at
org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit 4ClassRunner.java:46)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java :180)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java: 41)
at org.junit.runners.ParentRunner$1.evaluate(ParentRunner.java: 173)
at
org.junit.internal.runners.statements.RunBefores.evaluate(Ru nBefores.java:28)
at
org.junit.internal.runners.statements.RunAfters.evaluate(Run Afters.java:31)
at org.junit.runners.ParentRunner.run(ParentRunner.java:220)
at org.junit.runners.Suite.runChild(Suite.java:115)
at org.junit.runners.Suite.runChild(Suite.java:23)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java :180)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java: 41)
at org.junit.runners.ParentRunner$1.evaluate(ParentRunner.java: 173)
at
org.junit.internal.runners.statements.RunBefores.evaluate(Ru nBefores.java:28)
at
org.junit.internal.runners.statements.RunAfters.evaluate(Run Afters.java:31)
at org.junit.runners.ParentRunner.run(ParentRunner.java:220)
at
org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.r un(JUnit4TestReference.java:46)
at
org.eclipse.jdt.internal.junit.runner.TestExecution.run(Test Execution.java:38)
at
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTe sts(RemoteTestRunner.java:467)
at
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTe sts(RemoteTestRunner.java:683)
at
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(R emoteTestRunner.java:390)
at
org.eclipse.pde.internal.junit.runtime.RemotePluginTestRunne r.main(RemotePluginTestRunner.java:62)
at
org.eclipse.pde.internal.junit.runtime.CoreTestApplication.r un(CoreTestApplication.java:23)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at
org.eclipse.equinox.internal.app.EclipseAppContainer.callMet hodWithException(EclipseAppContainer.java:574)
at
org.eclipse.equinox.internal.app.EclipseAppHandle.run(Eclips eAppHandle.java:196)
at
org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher .runApplication(EclipseAppLauncher.java:110)
at
org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher .start(EclipseAppLauncher.java:79)
at
org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseS tarter.java:368)
at
org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseS tarter.java:179)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.eclipse.equinox.launcher.Main.invokeFramework(Main.java: 559)
at org.eclipse.equinox.launcher.Main.basicRun(Main.java:514)
at org.eclipse.equinox.launcher.Main.run(Main.java:1311)
at org.eclipse.equinox.launcher.Main.main(Main.java:1287)
I think I'm not saving the ressources right. I tried using
XMIResourceImpl as you can see (and they are being saved), but I suspect
I'm not correctly adding them to the ResourseSet. Any hints?
thank you
> Hi,
> Yup, MatchOptions.OPTION_IGNORE_XMI_ID is indeed the option Usul needs
> .... but it defaults to false so the matching should already work as
> intended.
> Usul, these IDs can only be accessed when the model is contained within
> XMIResources. If you created Resources to contain your models, they need
> to be "new XMIResourceImpl()".
> From the GUI, you will have two differences if the option discussed
> above is true. This can be checked from "Window => Preferences => EMF
> Compare". On this page, the option is labeled "Ignore XMI IDs for model
> comparison". If it isn't ticked, you shouldn't have any difference detected.
> Laurent Goubet
> Obeo
> Stephen McCants a écrit :
>> Hi Usul,
>> You might like at the MatchOptions.OPTION_IGNORE_XMI_ID. I'm not
>> sure if that does what you need or only part of what you need.
>> Hope that helps.
>>
>> Sincerely,
>> Stephen
>>
>> Usul wrote:
>>> Hi,
>>>
>>> I am not sure if EMF Compare is right for my task. I want JUnit-test
>>> T2M-transformations. For this reason, the test creates a model from
>>> some text. Then I need to compare it with a reference-model.
>>>
>>> I already implemented it like this:
>>> MatchModel match = MatchService.doMatch(referenceModel,
>>> createdModel, Collections.<String, Object>
>>> emptyMap());
>>> DiffModel diff = DiffService.doDiff(match, false);
>>> List<DiffElement> differences = diff.getOwnedElements();
>>>
>>> if( differences.size() > 0 ){
>>> Assert.assertTrue("the created model is different from
>>> the reference-model", false);
>>> }
>>>
>>> Unfortunatly, there are differences, even though the model are equal,
>>> except for ID's. But I want to ignore ID's and I just want to know if
>>> the models are "logically" equal.
>>>
>>> My simple (UML2-)test-models are:
>>> model 1
>>> <?xml version="1.0" encoding="UTF-8"?>
>>> <uml:Model xmi:version="2.1"
>>> xmlns:xmi="http://schema.omg.org/spec/XMI/2.1"
>>> xmlns:uml="http://www.eclipse.org/uml2/3.0.0/UML"
>>> xmi:id="_Wb9ysXFoEd6xJohxLdzz5Q">
>>> <packagedElement xmi:type="uml:Package"
>>> xmi:id="_Wb9ysnFoEd6xJohxLdzz5Q" name="foo">
>>> <packagedElement xmi:type="uml:Class"
>>> xmi:id="_Wb9ys3FoEd6xJohxLdzz5Q" name="SimpleClass"/>
>>> </packagedElement>
>>> </uml:Model>
>>>
>>> model 2
>>> <?xml version="1.0" encoding="UTF-8"?>
>>> <uml:Model xmi:version="2.1"
>>> xmlns:xmi="http://schema.omg.org/spec/XMI/2.1"
>>> xmlns:uml="http://www.eclipse.org/uml2/3.0.0/UML"
>>> xmi:id="_WcG8oHFoEd6xJohxLdzz5Q">
>>> <packagedElement xmi:type="uml:Package"
>>> xmi:id="_WcG8oXFoEd6xJohxLdzz5Q" name="foo">
>>> <packagedElement xmi:type="uml:Class"
>>> xmi:id="_WcG8onFoEd6xJohxLdzz5Q" name="SimpleClass"/>
>>> </packagedElement>
>>> </uml:Model>
>>>
>>> If I compare these models with the GUI, it says:
>>> "2 change(s) in <Model>"
>>> - "<Package> foo has been added"
>>> - "<Package> foo has been removed"
>>>
>>> Is there maybe some kind of mode that I can use, or is EMF Compare the
>>> wrong choice for this task?
>>>
>>>
>>>
>>> thank you
>>>
>>>
|
|
|
Re: Is EMF Compare right for this use-case? [message #621146 is a reply to message #138756] |
Thu, 16 July 2009 14:22 |
|
This is a multi-part message in MIME format.
--------------020802010701010205030808
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 8bit
Hi Usul,
I didn't understand that you were loading already existing models from
disk. This means you don't have to create the resources yourself. Yet
what you're loading are UML models; those can't be contained in
"XMIResource", they have their own. If you are loading your models in
standalone mode, you'll need to follow what's explained on
http://wiki.eclipse.org/MDT/UML2/FAQ#What.27s_required_to_lo ad_a_UML_.28.uml.29_resource_from_a_standalone_application.3 F
.. If you're loading them from within eclipse (your code is run from an
action or it is within unit tests run as "JUnit plugin test"), you only
need to load them. The easy way for this would be to use
org.eclipse.emf.compare.util.ModelUtils as it contains utility methods
to load models from File, URIs ... (EclipseModelUtils contain utility to
load from IFiles ... but is not standalone).
If you cannot use these utilities ... look at their code to see the
steps needed to load models from Files ^^.
When your models are loaded within their resources, the NPE you get here
should fix itself. Don't hesitate to come back here if it does not.
Laurent Goubet
Obeo
Usul a
|
|
|
Re: Is EMF Compare right for this use-case? [message #621147 is a reply to message #138756] |
Thu, 16 July 2009 15:07 |
Stephen McCants Messages: 92 Registered: July 2009 |
Member |
|
|
Hi Usul,
In your code you have this line twice:
resource.getContents().add(createdModel);
Should one of those lines be:
resource.getContents().add(referenceModel);
Just a thought...
--Stephen
Usul wrote:
> Thank you. It works on the GUI, but I cant manage to get it done
> programmaticly.
>
> Here is what I have:
>
> // saving models
>
> ResourceSet resourceSet = new ResourceSetImpl();
>
> IFile file = srcFolder.getFile("createdModel.uml");
> String path = file.getLocation().toFile().getAbsolutePath();
> URI fileURI = URI.createFileURI(path);
> Resource resource = new XMIResourceImpl(fileURI);
> resource.getContents().add(createdModel);
> resource.save(Collections.EMPTY_MAP);
> resourceSet.getResources().add(resource);
>
> file = srcFolder.getFile("referenceModel.uml");
> path = file.getLocation().toFile().getAbsolutePath();
> fileURI = URI.createFileURI(path);
> resource = new XMIResourceImpl(fileURI);
> resourceSet.getResources().add(resource);
> resource.save(Collections.EMPTY_MAP);
> resource.getContents().add(createdModel);
>
> // refresh workspace
>
> IWorkspaceRoot wRoot =
> ResourcesPlugin.getWorkspace().getRoot();
> IResource resc = wRoot.findMember(new Path(project.getName()));
> resc.refreshLocal(IResource.DEPTH_INFINITE, null);
>
>
> // compare the generated model with the reference-model
>
> Map<String, Object> options = new HashMap<String, Object>();
> options.put(MatchOptions.OPTION_IGNORE_XMI_ID, new
> Boolean(true));
> MatchModel match = MatchService.doMatch(referenceModel,
> createdModel, options);
> DiffModel diff = DiffService.doDiff(match, false);
> List<DiffElement> differences = diff.getOwnedElements();
>
> if( differences.size() > 0 ){
> Assert.assertTrue("the created model is different from
> the reference-model", false);
> }
>
> And its back to the NullPointerException:
>
> java.lang.NullPointerException
> at
> org.eclipse.emf.compare.match.engine.GenericMatchEngine.mode lMatch(GenericMatchEngine.java:356)
>
> at
> org.eclipse.emf.compare.match.service.MatchService.doMatch(M atchService.java:160)
>
> at
> alltests.ParentT2MAndM2TTestCase.testT2M(ParentT2MAndM2TTest Case.java:374)
> at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
> at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
> at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
> at java.lang.reflect.Method.invoke(Unknown Source)
> at
> org.junit.runners.model.FrameworkMethod$1.runReflectiveCall( FrameworkMethod.java:44)
>
> at
> org.junit.internal.runners.model.ReflectiveCallable.run(Refl ectiveCallable.java:15)
>
> at
> org.junit.runners.model.FrameworkMethod.invokeExplosively(Fr ameworkMethod.java:41)
>
> at
> org.junit.internal.runners.statements.InvokeMethod.evaluate( InvokeMethod.java:20)
>
> at
> org.junit.internal.runners.statements.RunBefores.evaluate(Ru nBefores.java:28)
>
> at
> org.junit.internal.runners.statements.RunAfters.evaluate(Run Afters.java:31)
> at
> org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit 4ClassRunner.java:73)
>
> at
> org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit 4ClassRunner.java:46)
>
> at org.junit.runners.ParentRunner.runChildren(ParentRunner.java :180)
> at org.junit.runners.ParentRunner.access$000(ParentRunner.java: 41)
> at org.junit.runners.ParentRunner$1.evaluate(ParentRunner.java: 173)
> at
> org.junit.internal.runners.statements.RunBefores.evaluate(Ru nBefores.java:28)
>
> at
> org.junit.internal.runners.statements.RunAfters.evaluate(Run Afters.java:31)
> at org.junit.runners.ParentRunner.run(ParentRunner.java:220)
> at org.junit.runners.Suite.runChild(Suite.java:115)
> at org.junit.runners.Suite.runChild(Suite.java:23)
> at org.junit.runners.ParentRunner.runChildren(ParentRunner.java :180)
> at org.junit.runners.ParentRunner.access$000(ParentRunner.java: 41)
> at org.junit.runners.ParentRunner$1.evaluate(ParentRunner.java: 173)
> at
> org.junit.internal.runners.statements.RunBefores.evaluate(Ru nBefores.java:28)
>
> at
> org.junit.internal.runners.statements.RunAfters.evaluate(Run Afters.java:31)
> at org.junit.runners.ParentRunner.run(ParentRunner.java:220)
> at
> org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.r un(JUnit4TestReference.java:46)
>
> at
> org.eclipse.jdt.internal.junit.runner.TestExecution.run(Test Execution.java:38)
>
> at
> org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTe sts(RemoteTestRunner.java:467)
>
> at
> org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTe sts(RemoteTestRunner.java:683)
>
> at
> org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(R emoteTestRunner.java:390)
>
> at
> org.eclipse.pde.internal.junit.runtime.RemotePluginTestRunne r.main(RemotePluginTestRunner.java:62)
>
> at
> org.eclipse.pde.internal.junit.runtime.CoreTestApplication.r un(CoreTestApplication.java:23)
>
> at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
> at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
> at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
> at java.lang.reflect.Method.invoke(Unknown Source)
> at
> org.eclipse.equinox.internal.app.EclipseAppContainer.callMet hodWithException(EclipseAppContainer.java:574)
>
> at
> org.eclipse.equinox.internal.app.EclipseAppHandle.run(Eclips eAppHandle.java:196)
>
> at
> org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher .runApplication(EclipseAppLauncher.java:110)
>
> at
> org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher .start(EclipseAppLauncher.java:79)
>
> at
> org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseS tarter.java:368)
>
> at
> org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseS tarter.java:179)
>
> at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
> at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
> at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
> at java.lang.reflect.Method.invoke(Unknown Source)
> at org.eclipse.equinox.launcher.Main.invokeFramework(Main.java: 559)
> at org.eclipse.equinox.launcher.Main.basicRun(Main.java:514)
> at org.eclipse.equinox.launcher.Main.run(Main.java:1311)
> at org.eclipse.equinox.launcher.Main.main(Main.java:1287)
>
>
> I think I'm not saving the ressources right. I tried using
> XMIResourceImpl as you can see (and they are being saved), but I suspect
> I'm not correctly adding them to the ResourseSet. Any hints?
>
>
> thank you
>
>> Hi,
>
>> Yup, MatchOptions.OPTION_IGNORE_XMI_ID is indeed the option Usul needs
>> .... but it defaults to false so the matching should already work as
>> intended.
>
>> Usul, these IDs can only be accessed when the model is contained
>> within XMIResources. If you created Resources to contain your models,
>> they need to be "new XMIResourceImpl()".
>
>> From the GUI, you will have two differences if the option discussed
>> above is true. This can be checked from "Window => Preferences => EMF
>> Compare". On this page, the option is labeled "Ignore XMI IDs for
>> model comparison". If it isn't ticked, you shouldn't have any
>> difference detected.
>
>> Laurent Goubet
>> Obeo
>
>> Stephen McCants a écrit :
>>> Hi Usul,
>>> You might like at the MatchOptions.OPTION_IGNORE_XMI_ID. I'm not
>>> sure if that does what you need or only part of what you need.
>>> Hope that helps.
>>>
>>> Sincerely,
>>> Stephen
>>>
>>> Usul wrote:
>>>> Hi,
>>>>
>>>> I am not sure if EMF Compare is right for my task. I want JUnit-test
>>>> T2M-transformations. For this reason, the test creates a model from
>>>> some text. Then I need to compare it with a reference-model.
>>>>
>>>> I already implemented it like this:
>>>> MatchModel match = MatchService.doMatch(referenceModel,
>>>> createdModel, Collections.<String, Object>
>>>> emptyMap());
>>>> DiffModel diff = DiffService.doDiff(match, false);
>>>> List<DiffElement> differences = diff.getOwnedElements();
>>>>
>>>> if( differences.size() > 0 ){
>>>> Assert.assertTrue("the created model is different
>>>> from the reference-model", false);
>>>> }
>>>>
>>>> Unfortunatly, there are differences, even though the model are
>>>> equal, except for ID's. But I want to ignore ID's and I just want to
>>>> know if the models are "logically" equal.
>>>>
>>>> My simple (UML2-)test-models are:
>>>> model 1
>>>> <?xml version="1.0" encoding="UTF-8"?>
>>>> <uml:Model xmi:version="2.1"
>>>> xmlns:xmi="http://schema.omg.org/spec/XMI/2.1"
>>>> xmlns:uml="http://www.eclipse.org/uml2/3.0.0/UML"
>>>> xmi:id="_Wb9ysXFoEd6xJohxLdzz5Q">
>>>> <packagedElement xmi:type="uml:Package"
>>>> xmi:id="_Wb9ysnFoEd6xJohxLdzz5Q" name="foo">
>>>> <packagedElement xmi:type="uml:Class"
>>>> xmi:id="_Wb9ys3FoEd6xJohxLdzz5Q" name="SimpleClass"/>
>>>> </packagedElement>
>>>> </uml:Model>
>>>>
>>>> model 2
>>>> <?xml version="1.0" encoding="UTF-8"?>
>>>> <uml:Model xmi:version="2.1"
>>>> xmlns:xmi="http://schema.omg.org/spec/XMI/2.1"
>>>> xmlns:uml="http://www.eclipse.org/uml2/3.0.0/UML"
>>>> xmi:id="_WcG8oHFoEd6xJohxLdzz5Q">
>>>> <packagedElement xmi:type="uml:Package"
>>>> xmi:id="_WcG8oXFoEd6xJohxLdzz5Q" name="foo">
>>>> <packagedElement xmi:type="uml:Class"
>>>> xmi:id="_WcG8onFoEd6xJohxLdzz5Q" name="SimpleClass"/>
>>>> </packagedElement>
>>>> </uml:Model>
>>>>
>>>> If I compare these models with the GUI, it says:
>>>> "2 change(s) in <Model>"
>>>> - "<Package> foo has been added"
>>>> - "<Package> foo has been removed"
>>>>
>>>> Is there maybe some kind of mode that I can use, or is EMF Compare
>>>> the wrong choice for this task?
>>>>
>>>>
>>>>
>>>> thank you
>>>>
>>>>
>
>
|
|
|
Re: Is EMF Compare right for this use-case? [message #621149 is a reply to message #138781] |
Thu, 16 July 2009 15:56 |
No real name Messages: 61 Registered: July 2009 |
Member |
|
|
Hi,
@Stephen:
Uh right, stupid me. Changing that got rid of the NPE, but still the
models are not considered equal.
@Laurent:
Yes, I'm starting the tests as "JUnit Plugin-Test" (headless mode). But
I'm not loading existing models. I create both of the models using the
EMF-Framework (i.e. using UMLFactory.eINSTANCE). Then I'm saving them,
just because I want to be able to use EMF Compare.
So right now there is no NPE, the models are being saved,
butdiff.getOwnedElements().size() still equals one. Did I use the options
wrong?
thank you
> Hi Usul,
> In your code you have this line twice:
> resource.getContents().add(createdModel);
> Should one of those lines be:
> resource.getContents().add(referenceModel);
> Just a thought...
> --Stephen
> Usul wrote:
>> Thank you. It works on the GUI, but I cant manage to get it done
>> programmaticly.
>>
>> Here is what I have:
>>
>> // saving models
>>
>> ResourceSet resourceSet = new ResourceSetImpl();
>>
>> IFile file = srcFolder.getFile("createdModel.uml");
>> String path = file.getLocation().toFile().getAbsolutePath();
>> URI fileURI = URI.createFileURI(path);
>> Resource resource = new XMIResourceImpl(fileURI);
>> resource.getContents().add(createdModel);
>> resource.save(Collections.EMPTY_MAP);
>> resourceSet.getResources().add(resource);
>>
>> file = srcFolder.getFile("referenceModel.uml");
>> path = file.getLocation().toFile().getAbsolutePath();
>> fileURI = URI.createFileURI(path);
>> resource = new XMIResourceImpl(fileURI);
>> resourceSet.getResources().add(resource);
>> resource.save(Collections.EMPTY_MAP);
>> resource.getContents().add(createdModel);
>>
>> // refresh workspace
>>
>> IWorkspaceRoot wRoot =
>> ResourcesPlugin.getWorkspace().getRoot();
>> IResource resc = wRoot.findMember(new Path(project.getName()));
>> resc.refreshLocal(IResource.DEPTH_INFINITE, null);
>>
>>
>> // compare the generated model with the reference-model
>>
>> Map<String, Object> options = new HashMap<String, Object>();
>> options.put(MatchOptions.OPTION_IGNORE_XMI_ID, new
>> Boolean(true));
>> MatchModel match = MatchService.doMatch(referenceModel,
>> createdModel, options);
>> DiffModel diff = DiffService.doDiff(match, false);
>> List<DiffElement> differences = diff.getOwnedElements();
>>
>> if( differences.size() > 0 ){
>> Assert.assertTrue("the created model is different from
>> the reference-model", false);
>> }
>>
>> And its back to the NullPointerException:
>>
>> java.lang.NullPointerException
>> at
>>
org.eclipse.emf.compare.match.engine.GenericMatchEngine.mode lMatch(GenericMatchEngine.java:356)
>>
>> at
>>
org.eclipse.emf.compare.match.service.MatchService.doMatch(M atchService.java:160)
>>
>> at
>> alltests.ParentT2MAndM2TTestCase.testT2M(ParentT2MAndM2TTest Case.java:374)
>> at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
>> at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
>> at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
>> at java.lang.reflect.Method.invoke(Unknown Source)
>> at
>>
org.junit.runners.model.FrameworkMethod$1.runReflectiveCall( FrameworkMethod.java:44)
>>
>> at
>>
org.junit.internal.runners.model.ReflectiveCallable.run(Refl ectiveCallable.java:15)
>>
>> at
>>
org.junit.runners.model.FrameworkMethod.invokeExplosively(Fr ameworkMethod.java:41)
>>
>> at
>>
org.junit.internal.runners.statements.InvokeMethod.evaluate( InvokeMethod.java:20)
>>
>> at
>>
org.junit.internal.runners.statements.RunBefores.evaluate(Ru nBefores.java:28)
>>
>> at
>> org.junit.internal.runners.statements.RunAfters.evaluate(Run Afters.java:31)
>> at
>>
org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit 4ClassRunner.java:73)
>>
>> at
>>
org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit 4ClassRunner.java:46)
>>
>> at org.junit.runners.ParentRunner.runChildren(ParentRunner.java :180)
>> at org.junit.runners.ParentRunner.access$000(ParentRunner.java: 41)
>> at org.junit.runners.ParentRunner$1.evaluate(ParentRunner.java: 173)
>> at
>>
org.junit.internal.runners.statements.RunBefores.evaluate(Ru nBefores.java:28)
>>
>> at
>> org.junit.internal.runners.statements.RunAfters.evaluate(Run Afters.java:31)
>> at org.junit.runners.ParentRunner.run(ParentRunner.java:220)
>> at org.junit.runners.Suite.runChild(Suite.java:115)
>> at org.junit.runners.Suite.runChild(Suite.java:23)
>> at org.junit.runners.ParentRunner.runChildren(ParentRunner.java :180)
>> at org.junit.runners.ParentRunner.access$000(ParentRunner.java: 41)
>> at org.junit.runners.ParentRunner$1.evaluate(ParentRunner.java: 173)
>> at
>>
org.junit.internal.runners.statements.RunBefores.evaluate(Ru nBefores.java:28)
>>
>> at
>> org.junit.internal.runners.statements.RunAfters.evaluate(Run Afters.java:31)
>> at org.junit.runners.ParentRunner.run(ParentRunner.java:220)
>> at
>>
org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.r un(JUnit4TestReference.java:46)
>>
>> at
>>
org.eclipse.jdt.internal.junit.runner.TestExecution.run(Test Execution.java:38)
>>
>> at
>>
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTe sts(RemoteTestRunner.java:467)
>>
>> at
>>
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTe sts(RemoteTestRunner.java:683)
>>
>> at
>>
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(R emoteTestRunner.java:390)
>>
>> at
>>
org.eclipse.pde.internal.junit.runtime.RemotePluginTestRunne r.main(RemotePluginTestRunner.java:62)
>>
>> at
>>
org.eclipse.pde.internal.junit.runtime.CoreTestApplication.r un(CoreTestApplication.java:23)
>>
>> at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
>> at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
>> at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
>> at java.lang.reflect.Method.invoke(Unknown Source)
>> at
>>
org.eclipse.equinox.internal.app.EclipseAppContainer.callMet hodWithException(EclipseAppContainer.java:574)
>>
>> at
>>
org.eclipse.equinox.internal.app.EclipseAppHandle.run(Eclips eAppHandle.java:196)
>>
>> at
>>
org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher .runApplication(EclipseAppLauncher.java:110)
>>
>> at
>>
org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher .start(EclipseAppLauncher.java:79)
>>
>> at
>>
org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseS tarter.java:368)
>>
>> at
>>
org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseS tarter.java:179)
>>
>> at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
>> at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
>> at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
>> at java.lang.reflect.Method.invoke(Unknown Source)
>> at org.eclipse.equinox.launcher.Main.invokeFramework(Main.java: 559)
>> at org.eclipse.equinox.launcher.Main.basicRun(Main.java:514)
>> at org.eclipse.equinox.launcher.Main.run(Main.java:1311)
>> at org.eclipse.equinox.launcher.Main.main(Main.java:1287)
>>
>>
>> I think I'm not saving the ressources right. I tried using
>> XMIResourceImpl as you can see (and they are being saved), but I suspect
>> I'm not correctly adding them to the ResourseSet. Any hints?
>>
>>
>> thank you
>>
>>> Hi,
>>
>>> Yup, MatchOptions.OPTION_IGNORE_XMI_ID is indeed the option Usul needs
>>> .... but it defaults to false so the matching should already work as
>>> intended.
>>
>>> Usul, these IDs can only be accessed when the model is contained
>>> within XMIResources. If you created Resources to contain your models,
>>> they need to be "new XMIResourceImpl()".
>>
>>> From the GUI, you will have two differences if the option discussed
>>> above is true. This can be checked from "Window => Preferences => EMF
>>> Compare". On this page, the option is labeled "Ignore XMI IDs for
>>> model comparison". If it isn't ticked, you shouldn't have any
>>> difference detected.
>>
>>> Laurent Goubet
>>> Obeo
>>
>>> Stephen McCants a écrit :
>>>> Hi Usul,
>>>> You might like at the MatchOptions.OPTION_IGNORE_XMI_ID. I'm not
>>>> sure if that does what you need or only part of what you need.
>>>> Hope that helps.
>>>>
>>>> Sincerely,
>>>> Stephen
>>>>
>>>> Usul wrote:
>>>>> Hi,
>>>>>
>>>>> I am not sure if EMF Compare is right for my task. I want JUnit-test
>>>>> T2M-transformations. For this reason, the test creates a model from
>>>>> some text. Then I need to compare it with a reference-model.
>>>>>
>>>>> I already implemented it like this:
>>>>> MatchModel match = MatchService.doMatch(referenceModel,
>>>>> createdModel, Collections.<String, Object>
>>>>> emptyMap());
>>>>> DiffModel diff = DiffService.doDiff(match, false);
>>>>> List<DiffElement> differences = diff.getOwnedElements();
>>>>>
>>>>> if( differences.size() > 0 ){
>>>>> Assert.assertTrue("the created model is different
>>>>> from the reference-model", false);
>>>>> }
>>>>>
>>>>> Unfortunatly, there are differences, even though the model are
>>>>> equal, except for ID's. But I want to ignore ID's and I just want to
>>>>> know if the models are "logically" equal.
>>>>>
>>>>> My simple (UML2-)test-models are:
>>>>> model 1
>>>>> <?xml version="1.0" encoding="UTF-8"?>
>>>>> <uml:Model xmi:version="2.1"
>>>>> xmlns:xmi="http://schema.omg.org/spec/XMI/2.1"
>>>>> xmlns:uml="http://www.eclipse.org/uml2/3.0.0/UML"
>>>>> xmi:id="_Wb9ysXFoEd6xJohxLdzz5Q">
>>>>> <packagedElement xmi:type="uml:Package"
>>>>> xmi:id="_Wb9ysnFoEd6xJohxLdzz5Q" name="foo">
>>>>> <packagedElement xmi:type="uml:Class"
>>>>> xmi:id="_Wb9ys3FoEd6xJohxLdzz5Q" name="SimpleClass"/>
>>>>> </packagedElement>
>>>>> </uml:Model>
>>>>>
>>>>> model 2
>>>>> <?xml version="1.0" encoding="UTF-8"?>
>>>>> <uml:Model xmi:version="2.1"
>>>>> xmlns:xmi="http://schema.omg.org/spec/XMI/2.1"
>>>>> xmlns:uml="http://www.eclipse.org/uml2/3.0.0/UML"
>>>>> xmi:id="_WcG8oHFoEd6xJohxLdzz5Q">
>>>>> <packagedElement xmi:type="uml:Package"
>>>>> xmi:id="_WcG8oXFoEd6xJohxLdzz5Q" name="foo">
>>>>> <packagedElement xmi:type="uml:Class"
>>>>> xmi:id="_WcG8onFoEd6xJohxLdzz5Q" name="SimpleClass"/>
>>>>> </packagedElement>
>>>>> </uml:Model>
>>>>>
>>>>> If I compare these models with the GUI, it says:
>>>>> "2 change(s) in <Model>"
>>>>> - "<Package> foo has been added"
>>>>> - "<Package> foo has been removed"
>>>>>
>>>>> Is there maybe some kind of mode that I can use, or is EMF Compare
>>>>> the wrong choice for this task?
>>>>>
>>>>>
>>>>>
>>>>> thank you
>>>>>
>>>>>
>>
>>
|
|
|
Re: Is EMF Compare right for this use-case? [message #621153 is a reply to message #138806] |
Fri, 17 July 2009 08:31 |
|
This is a multi-part message in MIME format.
--------------060905010306020903000502
Content-Type: text/plain; charset=ISO-8859-15; format=flowed
Content-Transfer-Encoding: 8bit
Hi Usul,
You don't need to save your models in order to compare them with EMF
Compare. As long as they're created and live in a Resource, they can be
compared. As for the option, you're using it right. What I didn't pay
enough attention to in your code are the last few lines.
"diff.getOwnedElements()" will always have a size greater than 0 as it
will always contain the root of all differences for the compared models;
be there differences or not. What should be equal to 0 though is the
result of "getSubChanges" on this root.
----------8<----------
[...]
DiffGroup diffRoot = diff.getOwnedElements().get(0);
if( diffRoot.getSubChanges() > 0 ){
fail("the created model is different from the reference-model");
}
---------->8----------
Laurent Goubet
Obeo
Usul a
|
|
|
Re: Is EMF Compare right for this use-case? [message #621155 is a reply to message #138859] |
Fri, 17 July 2009 14:39 |
No real name Messages: 61 Registered: July 2009 |
Member |
|
|
Hi Laurent,
thank you very much! Solved. Thanks again!
> Hi Usul,
> You don't need to save your models in order to compare them with EMF
> Compare. As long as they're created and live in a Resource, they can be
> compared. As for the option, you're using it right. What I didn't pay
> enough attention to in your code are the last few lines.
> "diff.getOwnedElements()" will always have a size greater than 0 as it
> will always contain the root of all differences for the compared models;
> be there differences or not. What should be equal to 0 though is the
> result of "getSubChanges" on this root.
> ----------8<----------
> [...]
> DiffGroup diffRoot = diff.getOwnedElements().get(0);
> if( diffRoot.getSubChanges() > 0 ){
> fail("the created model is different from the reference-model");
> }
> ---------->8----------
> Laurent Goubet
> Obeo
> Usul a écrit :
>> Hi,
>>
>> @Stephen:
>> Uh right, stupid me. Changing that got rid of the NPE, but still the
>> models are not considered equal.
>>
>> @Laurent:
>> Yes, I'm starting the tests as "JUnit Plugin-Test" (headless mode). But
>> I'm not loading existing models. I create both of the models using the
>> EMF-Framework (i.e. using UMLFactory.eINSTANCE). Then I'm saving them,
>> just because I want to be able to use EMF Compare.
>> So right now there is no NPE, the models are being saved,
>> butdiff.getOwnedElements().size() still equals one. Did I use the
>> options wrong?
>>
>>
>> thank you
>>
>>
>>> Hi Usul,
>>> In your code you have this line twice:
>>
>>> resource.getContents().add(createdModel);
>>
>>> Should one of those lines be:
>>
>>> resource.getContents().add(referenceModel);
>>
>>> Just a thought...
>>
>>> --Stephen
>>
>>> Usul wrote:
>>>> Thank you. It works on the GUI, but I cant manage to get it done
>>>> programmaticly.
>>>>
>>>> Here is what I have:
>>>>
>>>> // saving models
>>>>
>>>> ResourceSet resourceSet = new ResourceSetImpl();
>>>> IFile file =
>>>> srcFolder.getFile("createdModel.uml");
>>>> String path = file.getLocation().toFile().getAbsolutePath();
>>>> URI fileURI = URI.createFileURI(path);
>>>> Resource resource = new XMIResourceImpl(fileURI);
>>>> resource.getContents().add(createdModel);
>>>> resource.save(Collections.EMPTY_MAP);
>>>> resourceSet.getResources().add(resource);
>>>>
>>>> file = srcFolder.getFile("referenceModel.uml");
>>>> path = file.getLocation().toFile().getAbsolutePath();
>>>> fileURI = URI.createFileURI(path);
>>>> resource = new XMIResourceImpl(fileURI);
>>>> resourceSet.getResources().add(resource);
>>>> resource.save(Collections.EMPTY_MAP);
>>>> resource.getContents().add(createdModel);
>>>>
>>>> // refresh workspace
>>>>
>>>> IWorkspaceRoot wRoot =
>>>> ResourcesPlugin.getWorkspace().getRoot();
>>>> IResource resc = wRoot.findMember(new
>>>> Path(project.getName()));
>>>> resc.refreshLocal(IResource.DEPTH_INFINITE, null);
>>>>
>>>> // compare the generated model with the reference-model
>>>> Map<String, Object> options = new HashMap<String,
>>>> Object>();
>>>> options.put(MatchOptions.OPTION_IGNORE_XMI_ID, new
>>>> Boolean(true));
>>>> MatchModel match = MatchService.doMatch(referenceModel,
>>>> createdModel, options);
>>>> DiffModel diff = DiffService.doDiff(match, false);
>>>> List<DiffElement> differences = diff.getOwnedElements();
>>>>
>>>> if( differences.size() > 0 ){
>>>> Assert.assertTrue("the created model is different
>>>> from the reference-model", false);
>>>> }
>>>>
>>>> And its back to the NullPointerException:
>>>>
>>>> java.lang.NullPointerException
>>>> at
>>
org.eclipse.emf.compare.match.engine.GenericMatchEngine.mode lMatch(GenericMatchEngine.java:356)
>>
>>>>
>>>> at
>>
org.eclipse.emf.compare.match.service.MatchService.doMatch(M atchService.java:160)
>>
>>>>
>>>> at
>>>>
alltests.ParentT2MAndM2TTestCase.testT2M(ParentT2MAndM2TTest Case.java:374)
>>>>
>>>> at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
>>>> at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
>>>> at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
>>>> at java.lang.reflect.Method.invoke(Unknown Source)
>>>> at
>>
org.junit.runners.model.FrameworkMethod$1.runReflectiveCall( FrameworkMethod.java:44)
>>
>>>>
>>>> at
>>
org.junit.internal.runners.model.ReflectiveCallable.run(Refl ectiveCallable.java:15)
>>
>>>>
>>>> at
>>
org.junit.runners.model.FrameworkMethod.invokeExplosively(Fr ameworkMethod.java:41)
>>
>>>>
>>>> at
>>
org.junit.internal.runners.statements.InvokeMethod.evaluate( InvokeMethod.java:20)
>>
>>>>
>>>> at
>>
org.junit.internal.runners.statements.RunBefores.evaluate(Ru nBefores.java:28)
>>
>>>>
>>>> at
>>>>
org.junit.internal.runners.statements.RunAfters.evaluate(Run Afters.java:31)
>>>>
>>>> at
>>
org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit 4ClassRunner.java:73)
>>
>>>>
>>>> at
>>
org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit 4ClassRunner.java:46)
>>
>>>>
>>>> at org.junit.runners.ParentRunner.runChildren(ParentRunner.java :180)
>>>> at org.junit.runners.ParentRunner.access$000(ParentRunner.java: 41)
>>>> at org.junit.runners.ParentRunner$1.evaluate(ParentRunner.java: 173)
>>>> at
>>
org.junit.internal.runners.statements.RunBefores.evaluate(Ru nBefores.java:28)
>>
>>>>
>>>> at
>>>>
org.junit.internal.runners.statements.RunAfters.evaluate(Run Afters.java:31)
>>>>
>>>> at org.junit.runners.ParentRunner.run(ParentRunner.java:220)
>>>> at org.junit.runners.Suite.runChild(Suite.java:115)
>>>> at org.junit.runners.Suite.runChild(Suite.java:23)
>>>> at org.junit.runners.ParentRunner.runChildren(ParentRunner.java :180)
>>>> at org.junit.runners.ParentRunner.access$000(ParentRunner.java: 41)
>>>> at org.junit.runners.ParentRunner$1.evaluate(ParentRunner.java: 173)
>>>> at
>>
org.junit.internal.runners.statements.RunBefores.evaluate(Ru nBefores.java:28)
>>
>>>>
>>>> at
>>>>
org.junit.internal.runners.statements.RunAfters.evaluate(Run Afters.java:31)
>>>>
>>>> at org.junit.runners.ParentRunner.run(ParentRunner.java:220)
>>>> at
>>
org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.r un(JUnit4TestReference.java:46)
>>
>>>>
>>>> at
>>
org.eclipse.jdt.internal.junit.runner.TestExecution.run(Test Execution.java:38)
>>
>>>>
>>>> at
>>
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTe sts(RemoteTestRunner.java:467)
>>
>>>>
>>>> at
>>
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTe sts(RemoteTestRunner.java:683)
>>
>>>>
>>>> at
>>
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(R emoteTestRunner.java:390)
>>
>>>>
>>>> at
>>
org.eclipse.pde.internal.junit.runtime.RemotePluginTestRunne r.main(RemotePluginTestRunner.java:62)
>>
>>>>
>>>> at
>>
org.eclipse.pde.internal.junit.runtime.CoreTestApplication.r un(CoreTestApplication.java:23)
>>
>>>>
>>>> at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
>>>> at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
>>>> at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
>>>> at java.lang.reflect.Method.invoke(Unknown Source)
>>>> at
>>
org.eclipse.equinox.internal.app.EclipseAppContainer.callMet hodWithException(EclipseAppContainer.java:574)
>>
>>>>
>>>> at
>>
org.eclipse.equinox.internal.app.EclipseAppHandle.run(Eclips eAppHandle.java:196)
>>
>>>>
>>>> at
>>
org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher .runApplication(EclipseAppLauncher.java:110)
>>
>>>>
>>>> at
>>
org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher .start(EclipseAppLauncher.java:79)
>>
>>>>
>>>> at
>>
org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseS tarter.java:368)
>>
>>>>
>>>> at
>>
org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseS tarter.java:179)
>>
>>>>
>>>> at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
>>>> at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
>>>> at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
>>>> at java.lang.reflect.Method.invoke(Unknown Source)
>>>> at org.eclipse.equinox.launcher.Main.invokeFramework(Main.java: 559)
>>>> at org.eclipse.equinox.launcher.Main.basicRun(Main.java:514)
>>>> at org.eclipse.equinox.launcher.Main.run(Main.java:1311)
>>>> at org.eclipse.equinox.launcher.Main.main(Main.java:1287)
>>>>
>>>>
>>>> I think I'm not saving the ressources right. I tried using
>>>> XMIResourceImpl as you can see (and they are being saved), but I
>>>> suspect I'm not correctly adding them to the ResourseSet. Any hints?
>>>>
>>>>
>>>> thank you
>>>>
>>>>> Hi,
>>>>
>>>>> Yup, MatchOptions.OPTION_IGNORE_XMI_ID is indeed the option Usul
>>>>> needs .... but it defaults to false so the matching should already
>>>>> work as intended.
>>>>
>>>>> Usul, these IDs can only be accessed when the model is contained
>>>>> within XMIResources. If you created Resources to contain your
>>>>> models, they need to be "new XMIResourceImpl()".
>>>>
>>>>> From the GUI, you will have two differences if the option discussed
>>>>> above is true. This can be checked from "Window => Preferences =>
>>>>> EMF Compare". On this page, the option is labeled "Ignore XMI IDs
>>>>> for model comparison". If it isn't ticked, you shouldn't have any
>>>>> difference detected.
>>>>
>>>>> Laurent Goubet
>>>>> Obeo
>>>>
>>>>> Stephen McCants a écrit :
>>>>>> Hi Usul,
>>>>>> You might like at the MatchOptions.OPTION_IGNORE_XMI_ID. I'm
>>>>>> not sure if that does what you need or only part of what you need.
>>>>>> Hope that helps.
>>>>>>
>>>>>> Sincerely,
>>>>>> Stephen
>>>>>>
>>>>>> Usul wrote:
>>>>>>> Hi,
>>>>>>>
>>>>>>> I am not sure if EMF Compare is right for my task. I want
>>>>>>> JUnit-test T2M-transformations. For this reason, the test creates
>>>>>>> a model from some text. Then I need to compare it with a
>>>>>>> reference-model.
>>>>>>>
>>>>>>> I already implemented it like this:
>>>>>>> MatchModel match = MatchService.doMatch(referenceModel,
>>>>>>> createdModel, Collections.<String, Object>
>>>>>>> emptyMap());
>>>>>>> DiffModel diff = DiffService.doDiff(match, false);
>>>>>>> List<DiffElement> differences = diff.getOwnedElements();
>>>>>>>
>>>>>>> if( differences.size() > 0 ){
>>>>>>> Assert.assertTrue("the created model is different
>>>>>>> from the reference-model", false);
>>>>>>> }
>>>>>>>
>>>>>>> Unfortunatly, there are differences, even though the model are
>>>>>>> equal, except for ID's. But I want to ignore ID's and I just want
>>>>>>> to know if the models are "logically" equal.
>>>>>>>
>>>>>>> My simple (UML2-)test-models are:
>>>>>>> model 1
>>>>>>> <?xml version="1.0" encoding="UTF-8"?>
>>>>>>> <uml:Model xmi:version="2.1"
>>>>>>> xmlns:xmi="http://schema.omg.org/spec/XMI/2.1"
>>>>>>> xmlns:uml="http://www.eclipse.org/uml2/3.0.0/UML"
>>>>>>> xmi:id="_Wb9ysXFoEd6xJohxLdzz5Q">
>>>>>>> <packagedElement xmi:type="uml:Package"
>>>>>>> xmi:id="_Wb9ysnFoEd6xJohxLdzz5Q" name="foo">
>>>>>>> <packagedElement xmi:type="uml:Class"
>>>>>>> xmi:id="_Wb9ys3FoEd6xJohxLdzz5Q" name="SimpleClass"/>
>>>>>>> </packagedElement>
>>>>>>> </uml:Model>
>>>>>>>
>>>>>>> model 2
>>>>>>> <?xml version="1.0" encoding="UTF-8"?>
>>>>>>> <uml:Model xmi:version="2.1"
>>>>>>> xmlns:xmi="http://schema.omg.org/spec/XMI/2.1"
>>>>>>> xmlns:uml="http://www.eclipse.org/uml2/3.0.0/UML"
>>>>>>> xmi:id="_WcG8oHFoEd6xJohxLdzz5Q">
>>>>>>> <packagedElement xmi:type="uml:Package"
>>>>>>> xmi:id="_WcG8oXFoEd6xJohxLdzz5Q" name="foo">
>>>>>>> <packagedElement xmi:type="uml:Class"
>>>>>>> xmi:id="_WcG8onFoEd6xJohxLdzz5Q" name="SimpleClass"/>
>>>>>>> </packagedElement>
>>>>>>> </uml:Model>
>>>>>>>
>>>>>>> If I compare these models with the GUI, it says:
>>>>>>> "2 change(s) in <Model>"
>>>>>>> - "<Package> foo has been added"
>>>>>>> - "<Package> foo has been removed"
>>>>>>>
>>>>>>> Is there maybe some kind of mode that I can use, or is EMF Compare
>>>>>>> the wrong choice for this task?
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>> thank you
>>>>>>>
>>>>>>>
>>>>
>>>>
>>
>>
|
|
|
Goto Forum:
Current Time: Tue Dec 03 11:19:21 GMT 2024
Powered by FUDForum. Page generated in 0.05355 seconds
|