Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Archived » M2M (model-to-model transformation) » [QVTo] Unit not found while executing qvto in own application
[QVTo] Unit not found while executing qvto in own application [message #769244] Wed, 21 December 2011 16:35 Go to next message
David Mising name is currently offline David Mising name
Messages: 9
Registered: December 2010
Location: Aachen
Junior Member

Hey,

I'm trying to execute my transformation basically via the code given here: http://wiki.eclipse.org/QVTOML/Examples/InvokeInJava


It has been changed a little to make it usabel from within an rcp application. All my files are stored within a plugin and can be loaded with the FileOperator. This works for my resources, but doesn't seem to work for the transformation itself.

		
		ResourceSet resourceSet = new ResourceSetImpl();

		URI transformationURI = FileOperator.getFileFromPlugin("transformations/ECORE2UML.qvto");
		TransformationExecutor executor = new TransformationExecutor(transformationURI);

		ExecutionContextImpl context = new ExecutionContextImpl();
		
		/*
		 * put UMLPackage into PackageRegistry
		 */
		resourceSet.getPackageRegistry().put(UMLPackage.eNS_URI, UMLPackage.eINSTANCE);	
		Resource inResource = resourceSet.getResource(FileOperator.getFileFromPlugin("models/model.uml") , true);
		EList<EObject> inObjects = inResource.getContents();

		ModelExtent input = new BasicModelExtent(inObjects);		
		// create an empty extent to catch the output
		ModelExtent output = new BasicModelExtent();

		context.setConfigProperty("keepModeling", true);

		ExecutionDiagnostic result = executor.execute(context, input, output);

		if(result.getSeverity() == Diagnostic.OK) {
			
			List<EObject> outObjects = output.getContents();
			Resource outResource = resourceSet.getResource(FileOperator.getFileFromPlugin("models/target.ecore"), true);
			outResource.getContents().addAll(outObjects);
			outResource.save(Collections.emptyMap());
			
		} else {
			IStatus status = BasicDiagnostic.toIStatus(result);
			Activator.getDefault().getLog().log(status);
		}
	}

This causes the following log-entry:
!ENTRY org.eclipse.m2m.qvt.oml.execution 4 200 2011-12-21 17:17:42.004
!MESSAGE Could not find unit 'file:/mypathtofile/transformations/ECORE2UML.qvto'

If I try to recieve my URI any other way e.g.
URI.createPlatformPluginURI( ... ) its working neither.

I've tried many suggestions dealing with similar problems, but none of them is working. I seem to miss something important. Do I have to put some plugins in my applications runconfig or manually register some Packages (like I did with the UMLPackage). I'm stuck ...

Thanks in advance for any hint.

Regards,
David
Re: [QVTo] Unit not found while executing qvto in own application [message #769522 is a reply to message #769244] Thu, 22 December 2011 08:40 Go to previous messageGo to next message
Ed Willink is currently offline Ed Willink
Messages: 4097
Registered: July 2009
Senior Member
Hi

Using EMF models standalone is not always easy since it becomes your
responsibility to activate all the registrations that Eclipse does
automatically via extensions points. If you are working standalone, you
are a programmer, and therefore expected to use programming/debugging
skills to help yourself a little. That said, a variety of projects could
provide more helpful initialization routines.

You say you have changed the example a little. Have you made sure that
it works unchanged?

Have you made sure that you can just load your model into a ResourceSet?
if not there is no point expecting QVTo to be able to use it.

For non-trivial model references, the use of platform: references is
essential and difficult to setup;
https://bugs.eclipse.org/bugs/show_bug.cgi?id=361063 is work in progress
towards making this much easier.
https://bugs.eclipse.org/bugs/show_bug.cgi?id=360926#c7 is my analysis
of the problem and the solution.

For simple model references you can set default paths/resolutions so
that file: works, but the error message on
"file:/mypathtofile/transformations/ECORE2UML.qvto" strongly suggests
you have not done this.

UML registrations are particularly hard to get right because of the
multiple versions and namespaces. This gets even harder in Juno with the
additional UML 2.3, 2.4 and 2.4.1 namespaces, which is why we are
working on an initialisation routine;
https://bugs.eclipse.org/bugs/show_bug.cgi?id=364419.

Regards

Ed Willink


On 21/12/2011 16:35, David wrote:
> Hey,
>
> I'm trying to execute my transformation basically via the code given
> here: http://wiki.eclipse.org/QVTOML/Examples/InvokeInJava
>
> It has been changed a little to make it usabel from within an rcp
> application. All my files are stored within a plugin and can be loaded
> with the FileOperator. This works for my resources, but doesn't seem
> to work for the transformation itself.
>
>
> ResourceSet resourceSet = new ResourceSetImpl();
>
> URI transformationURI =
> FileOperator.getFileFromPlugin("transformations/ECORE2UML.qvto");
> TransformationExecutor executor = new
> TransformationExecutor(transformationURI);
>
> ExecutionContextImpl context = new ExecutionContextImpl();
>
> /*
> * put UMLPackage into PackageRegistry
> */
> resourceSet.getPackageRegistry().put(UMLPackage.eNS_URI,
> UMLPackage.eINSTANCE);
> Resource inResource =
> resourceSet.getResource(FileOperator.getFileFromPlugin("models/model.uml")
> , true);
> EList<EObject> inObjects = inResource.getContents();
>
> ModelExtent input = new BasicModelExtent(inObjects);
> // create an empty extent to catch the output
> ModelExtent output = new BasicModelExtent();
>
> context.setConfigProperty("keepModeling", true);
>
> ExecutionDiagnostic result = executor.execute(context, input,
> output);
>
> if(result.getSeverity() == Diagnostic.OK) {
>
> List<EObject> outObjects = output.getContents();
> Resource outResource =
> resourceSet.getResource(FileOperator.getFileFromPlugin("models/target.ecore"),
> true);
> outResource.getContents().addAll(outObjects);
> outResource.save(Collections.emptyMap());
>
> } else {
> IStatus status = BasicDiagnostic.toIStatus(result);
> Activator.getDefault().getLog().log(status);
> }
> }
> This causes the following log-entry:
> !ENTRY org.eclipse.m2m.qvt.oml.execution 4 200 2011-12-21 17:17:42.004
> !MESSAGE Could not find unit
> 'file:/mypathtofile/transformations/ECORE2UML.qvto'
>
> If I try to recieve my URI any other way e.g.
> URI.createPlatformPluginURI( ... ) its working neither.
> I've tried many suggestions dealing with similar problems, but none of
> them is working. I seem to miss something important. Do I have to put
> some plugins in my applications runconfig or manually register some
> Packages (like I did with the UMLPackage). I'm stuck ...
> Thanks in advance for any hint.
>
> Regards,
> David
Re: [QVTo] Unit not found while executing qvto in own application [message #769689 is a reply to message #769522] Thu, 22 December 2011 14:38 Go to previous messageGo to next message
David Mising name is currently offline David Mising name
Messages: 9
Registered: December 2010
Location: Aachen
Junior Member

Hi Ed,

thanks a lot for the reply.
Quote:

You say you have changed the example a little. Have you made sure that
it works unchanged?

I have tried but the following code following the instructions from the example gives me the same log message (unit not found).

		URI transformationURI = URI.createURI("platform:/resource/de.configurator.files/ECORE2UML.qvto");
		// create executor for the given transformation
		TransformationExecutor executor = new TransformationExecutor(transformationURI);
		
		Diagnostic diag = executor.loadTransformation();
		
		System.out.println(diag.getMessage());


Either the log message is misleading and I have to look for the error at some other point or the transformation really could not be found.

There does not seem to be any problem with referencing the models. I can load from their persisted state and access the EObjects, even though it really was not trivial to accomplish that as you have pointed out.

Quote:
For simple model references you can set default paths/resolutions so
that file: works, but the error message on
"file:/mypathtofile/transformations/ECORE2UML.qvto" strongly suggests
you have not done this.


Sorry, I don't get what you mean by this. Where can I set those default paths? The error message I got was logged by the TransformationExecutor, I don't think it is related to EMF.

Regards
David
Re: [QVTo] Unit not found while executing qvto in own application [message #769818 is a reply to message #769689] Thu, 22 December 2011 18:19 Go to previous messageGo to next message
Ed Willink is currently offline Ed Willink
Messages: 4097
Registered: July 2009
Senior Member
Hi

It appears that http://wiki.eclipse.org/QVTOML/Examples/InvokeInJava was
written solely for the http://www.eclipse.org/forums/index.php/m/549655/
thread and was not tested. It is not linked from anywhere. It is
obviously incomplete
- no package/import/class/function
- no EMF registrations
It is also inaccurate: ||

"platform:/resources/myqvtprj/ChangeTheWorld.qvto"


has a typo. Radek's original posting invited feedback. I suggest you
contact him directly to encourage him to provide a complete debugged
example.

As it stands the example provides sufficient clues for an experienced
EMF programmer to use it standalone, but no more.

In an RCP context it should be easy since platform: should work. You
need to follow my earlier advice and investigate basic resource opening.

Regards

Ed Willink


On 22/12/2011 14:38, David wrote:
> Hi Ed,
>
> thanks a lot for the reply.
> Quote:
>> You say you have changed the example a little. Have you made sure that
>> it works unchanged?
>
> I have tried but the following code following the instructions from
> the example gives me the same log message (unit not found).
>
> URI transformationURI =
> URI.createURI("platform:/resource/de.configurator.files/ECORE2UML.qvto");
> // create executor for the given transformation
> TransformationExecutor executor = new
> TransformationExecutor(transformationURI);
>
> Diagnostic diag = executor.loadTransformation();
>
> System.out.println(diag.getMessage());
>
> Either the log message is misleading and I have to look for the error
> at some other point or the transformation really could not be found.
>
> There does not seem to be any problem with referencing the models. I
> can load from their persisted state and access the EObjects, even
> though it really was not trivial to accomplish that as you have
> pointed out.
>
> Quote:
>> For simple model references you can set default paths/resolutions so
>> that file: works, but the error message on
>> "file:/mypathtofile/transformations/ECORE2UML.qvto" strongly suggests
>> you have not done this.
>
>
> Sorry, I don't get what you mean by this. Where can I set those
> default paths? The error message I got was logged by the
> TransformationExecutor, I don't think it is related to EMF.
> Regards
> David
Re: [QVTo] Unit not found while executing qvto in own application [message #775139 is a reply to message #769818] Thu, 05 January 2012 12:23 Go to previous message
David Mising name is currently offline David Mising name
Messages: 9
Registered: December 2010
Location: Aachen
Junior Member

Hey,

thanks for your response and sorry for the delay, haven't been around in a while.


Anyway, I found the solution to my problem and wanted to share it. The problem has not been related to the way I opened the resources, that worked fine all along. I simply missed a dependency to one (or more) plugin(s) that is not referenced by any dependency in the plugins that are needed to execute the given code. I run it in my own application and added the following plugins to my application-plugins dependency:


org.eclipse.ui
org.eclipse.core.runtime
org.eclipse.emf.ecore
org.elicpse.emf.ecore.xmi
net.sourceforge.lpg.lpgjavaruntime
org.eclipse.ocl
org.elcipse.ocl.ecore
org.eclipse.m2m.qvt.oml
org.eclipse.m2m.qvt.oml.common
org.eclipse.m2m.qvt.oml.emf.util
org.eclipse.jdt.ui
org.eclipse.m2m.qvt.oml.project


I found the list of dependencies to be set somewhere, but can't find a link. For me it was uncomplete anyway as the last one "org.eclipse.m2m.qvt.oml.project" didn't occur in there. Changing nothing, but adding a dependency to this got me rid of the 'could not find unit ... ' message. (Didn't test if it was exactly this plugins or any of it dependencies, that solved the problem.)

If you "Add Required Plug-ins" to your run config, all the needed plugins will be added to your application and it runs perfectly.


Still I have no understanding of what is happening internally, that makes a non depending plug-in important. I guess it was plain luck, that I tracked down a solution.

Regards,
David
Previous Topic:incomplete output because containment reference
Next Topic:Output based on current and previous input values
Goto Forum:
  


Current Time: Fri Oct 24 15:33:03 GMT 2014

Powered by FUDForum. Page generated in 0.04984 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software