Skip to main content

Notice: this Wiki will be going read only early in 2024 and edits will no longer be possible. Please see: https://gitlab.eclipse.org/eclipsefdn/helpdesk/-/wikis/Wiki-shutdown-plan for the plan.

Jump to: navigation, search

JET FAQ How do I run a JET transformation from Java?

Question

How do I run a JET transformation from my plug-in?

Answer

The class JET2Platform has a number of runTransformOnXXX methods that run a transform programmatically. None of these methods will impact the Eclipse UI. If you want an execution console, see JET FAQ How do I get a console when running JET from Java?

runTransformOnResource

This is intended to be used if you have a workspace file that you want to load as the transformation input. This is the closest thing to running the transform like the UI. (The UI does is slightly differently in order to get the console hooked up, etc.... The runTransformOnXXX methods do not hook into the console).

runTransformOnObject

This method is intended to be used if you have your model already loaded in memory. This would likely be the case if you have a GMF-created editor, and you are adding an action to the editor to transform this model into something else via a JET transform.

runTransformOnString

This method takes a model (typically an XML document) as a string, and run the transformation against it. As with runTransformOnObject, if you are using the org.eclipse.jet.resource variables in you transform, you will have to set them manually.

Tips

There are two 'tricks' to using runTransformOnObject and runTransformOnString.

1) For runTransformOnObject, you must pass an Object that represents the in-memory model. If your EMF model was generated directly from ECore, pass in the EMF Resource object. If you EMF model was generated from an XSD Schema, pass in the instanced of the generated DocumentRoot class.

2) The predefined JET variables for the form org.eclipse.jet.resource.* are not set, because no Eclipse resource was processed during model loading. This will usually cause some grief with at least the default ws:file tag that generates a dump of your input model, as it uses $org.eclipse.jet.resource.project.name. You can pass a Map of variable names to variable values to an overload of runTransformOnXXX.

See Also

Back to M2T-JET-FAQ.

Back to the top