Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » M2T (model-to-text transformation) » Invoke JET2 Transformation from Java
Invoke JET2 Transformation from Java [message #22666] Tue, 19 June 2007 13:40 Go to next message
Tex Twil is currently offline Tex TwilFriend
Messages: 179
Registered: July 2009
Senior Member
Hello,
Are there any tutorials about how to invoke a JET transformation
programaticly ?

I have a JET project which works fine. Its input is one XML file and the
output is another XML file. Now, I would like to use this transformation
in another java project. I copied the JET sources
(_jet_transformation.java, _jet_main.java, ...) to the src folder but
know I dont know where is the entry point to the transformation so I can
call it from my Java program.

Thanks,
Rex
Re: Invoke JET2 Transformation from Java [message #22753 is a reply to message #22666] Tue, 19 June 2007 14:46 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: evaandoli.dodo.com.au

a Quick snip from my GMF project calling Jet hope it helps:-

From Extention plugin class:-
Map<String, String> variables = new HashMap<String, String>();

variables.put("org.eclipse.jet.resource.project.name",resource.getURI().segments()[1]);

System.out.println("About to call common generate method in JET project");

variables.put("loadVar","sample1.xml");

IStatus status = PerformJetTest.runTransformTest(resource,variables,
aProgressMonitor);

========

Class below is defined in same project as Jet templates and has the
following method:

public static IStatus runTransformTest(XMIResourceImpl aResource,

Map<String, String> aVariables, NullProgressMonitor aProgressMonitor) {

return JET2Platform.runTransformOnObject( "TestProjectJETId",
(Resource)aResource, aVariables, aProgressMonitor );

}



Hope that helps.



"Tex Twil" <chaljan@hotmail.com> wrote in message
news:f58mdg$ste$1@build.eclipse.org...
> Hello,
> Are there any tutorials about how to invoke a JET transformation
> programaticly ?
>
> I have a JET project which works fine. Its input is one XML file and the
> output is another XML file. Now, I would like to use this transformation
> in another java project. I copied the JET sources
> (_jet_transformation.java, _jet_main.java, ...) to the src folder but know
> I dont know where is the entry point to the transformation so I can call
> it from my Java program.
>
> Thanks,
> Rex
Re: Invoke JET2 Transformation from Java [message #22797 is a reply to message #22753] Wed, 20 June 2007 07:50 Go to previous messageGo to next message
Tex Twil is currently offline Tex TwilFriend
Messages: 179
Registered: July 2009
Senior Member
Hello,
I also want to call the transformation from a GMF project. I don't
really understand what you mean by "From Extention plugin class".

In my case I have a custom menu in my GMF model where I have a button
"generate". I handle its action in a class:

myMenuProvider extends ActionDelegate implements IEditorActionDelegate

I'd like to call the transformation from here. How can I access the
IResource here ?

Tex.



Stu wrote:
> a Quick snip from my GMF project calling Jet hope it helps:-
>
> From Extention plugin class:-
> Map<String, String> variables = new HashMap<String, String>();
>
> variables.put("org.eclipse.jet.resource.project.name",resource.getURI().segments()[1]);
>
> System.out.println("About to call common generate method in JET project");
>
> variables.put("loadVar","sample1.xml");
>
> IStatus status = PerformJetTest.runTransformTest(resource,variables,
> aProgressMonitor);
>
> ========
>
> Class below is defined in same project as Jet templates and has the
> following method:
>
> public static IStatus runTransformTest(XMIResourceImpl aResource,
>
> Map<String, String> aVariables, NullProgressMonitor aProgressMonitor) {
>
> return JET2Platform.runTransformOnObject( "TestProjectJETId",
> (Resource)aResource, aVariables, aProgressMonitor );
>
> }
>
>
>
> Hope that helps.
>
>
>
> "Tex Twil" <chaljan@hotmail.com> wrote in message
> news:f58mdg$ste$1@build.eclipse.org...
>> Hello,
>> Are there any tutorials about how to invoke a JET transformation
>> programaticly ?
>>
>> I have a JET project which works fine. Its input is one XML file and the
>> output is another XML file. Now, I would like to use this transformation
>> in another java project. I copied the JET sources
>> (_jet_transformation.java, _jet_main.java, ...) to the src folder but know
>> I dont know where is the entry point to the transformation so I can call
>> it from my Java program.
>>
>> Thanks,
>> Rex
>
>
Re: Invoke JET2 Transformation from Java [message #22842 is a reply to message #22797] Wed, 20 June 2007 08:37 Go to previous messageGo to next message
Tex Twil is currently offline Tex TwilFriend
Messages: 179
Registered: July 2009
Senior Member
Again sone questions:

- the parameters of your runTransformOnObject fit more to a
runTransformOnResource is that normal ?

- this method has an ID parameter of the JET transformation. Is that the
ID I have in my plugin.xml file i.e.
<extension
id="myID"
name=""
point="org.eclipse.jet.transform"
...
?

- I want to merge the JET project with the GMF project. I copied all the
java sources/templates (_jet_transformation.java, _jet_main.java ... )
of the JET transformation to a package of my GMF project is that ok ?
Shall I then also merge the plugin.xml of the JET project with the
plugin.xml of GMF ?

Thank you again for your help !
Tex.

Tex Twil wrote:
> Hello,
> I also want to call the transformation from a GMF project. I don't
> really understand what you mean by "From Extention plugin class".
>
> In my case I have a custom menu in my GMF model where I have a button
> "generate". I handle its action in a class:
>
> myMenuProvider extends ActionDelegate implements IEditorActionDelegate
>
> I'd like to call the transformation from here. How can I access the
> IResource here ?
>
> Tex.
>
>
>
> Stu wrote:
>> a Quick snip from my GMF project calling Jet hope it helps:-
>>
>> From Extention plugin class:-
>> Map<String, String> variables = new HashMap<String, String>();
>>
>> variables.put("org.eclipse.jet.resource.project.name",resource.getURI().segments()[1]);
>>
>>
>> System.out.println("About to call common generate method in JET
>> project");
>>
>> variables.put("loadVar","sample1.xml");
>>
>> IStatus status = PerformJetTest.runTransformTest(resource,variables,
>> aProgressMonitor);
>>
>> ========
>>
>> Class below is defined in same project as Jet templates and has the
>> following method:
>>
>> public static IStatus runTransformTest(XMIResourceImpl aResource,
>>
>> Map<String, String> aVariables, NullProgressMonitor aProgressMonitor) {
>>
>> return JET2Platform.runTransformOnObject( "TestProjectJETId",
>> (Resource)aResource, aVariables, aProgressMonitor );
>>
>> }
>>
>>
>>
>> Hope that helps.
>>
>>
>>
>> "Tex Twil" <chaljan@hotmail.com> wrote in message
>> news:f58mdg$ste$1@build.eclipse.org...
>>> Hello,
>>> Are there any tutorials about how to invoke a JET transformation
>>> programaticly ?
>>>
>>> I have a JET project which works fine. Its input is one XML file and
>>> the output is another XML file. Now, I would like to use this
>>> transformation in another java project. I copied the JET sources
>>> (_jet_transformation.java, _jet_main.java, ...) to the src folder but
>>> know I dont know where is the entry point to the transformation so I
>>> can call it from my Java program.
>>>
>>> Thanks,
>>> Rex
>>
>>
Re: Invoke JET2 Transformation from Java [message #22929 is a reply to message #22842] Wed, 20 June 2007 10:33 Go to previous messageGo to next message
Tex Twil is currently offline Tex TwilFriend
Messages: 179
Registered: July 2009
Senior Member
I don't really understand the parameter of runTransformOnResource
"resource - the Eclipse Resource to load"
Is it the input to the JET transformation ?

In my case, the input file for JET is a XMI file of the instance of my
GMF model from my workspace. How
can I specify it ?

tex.


Tex Twil wrote:
> Again sone questions:
>
> - the parameters of your runTransformOnObject fit more to a
> runTransformOnResource is that normal ?
>
> - this method has an ID parameter of the JET transformation. Is that the
> ID I have in my plugin.xml file i.e.
> <extension
> id="myID"
> name=""
> point="org.eclipse.jet.transform"
> ...
> ?
>
> - I want to merge the JET project with the GMF project. I copied all the
> java sources/templates (_jet_transformation.java, _jet_main.java ... )
> of the JET transformation to a package of my GMF project is that ok ?
> Shall I then also merge the plugin.xml of the JET project with the
> plugin.xml of GMF ?
>
> Thank you again for your help !
> Tex.
>
> Tex Twil wrote:
>> Hello,
>> I also want to call the transformation from a GMF project. I don't
>> really understand what you mean by "From Extention plugin class".
>>
>> In my case I have a custom menu in my GMF model where I have a button
>> "generate". I handle its action in a class:
>>
>> myMenuProvider extends ActionDelegate implements IEditorActionDelegate
>>
>> I'd like to call the transformation from here. How can I access the
>> IResource here ?
>>
>> Tex.
>>
>>
>>
>> Stu wrote:
>>> a Quick snip from my GMF project calling Jet hope it helps:-
>>>
>>> From Extention plugin class:-
>>> Map<String, String> variables = new HashMap<String, String>();
>>>
>>> variables.put("org.eclipse.jet.resource.project.name",resource.getURI().segments()[1]);
>>>
>>>
>>> System.out.println("About to call common generate method in JET
>>> project");
>>>
>>> variables.put("loadVar","sample1.xml");
>>>
>>> IStatus status = PerformJetTest.runTransformTest(resource,variables,
>>> aProgressMonitor);
>>>
>>> ========
>>>
>>> Class below is defined in same project as Jet templates and has the
>>> following method:
>>>
>>> public static IStatus runTransformTest(XMIResourceImpl aResource,
>>>
>>> Map<String, String> aVariables, NullProgressMonitor aProgressMonitor) {
>>>
>>> return JET2Platform.runTransformOnObject( "TestProjectJETId",
>>> (Resource)aResource, aVariables, aProgressMonitor );
>>>
>>> }
>>>
>>>
>>>
>>> Hope that helps.
>>>
>>>
>>>
>>> "Tex Twil" <chaljan@hotmail.com> wrote in message
>>> news:f58mdg$ste$1@build.eclipse.org...
>>>> Hello,
>>>> Are there any tutorials about how to invoke a JET transformation
>>>> programaticly ?
>>>>
>>>> I have a JET project which works fine. Its input is one XML file and
>>>> the output is another XML file. Now, I would like to use this
>>>> transformation in another java project. I copied the JET sources
>>>> (_jet_transformation.java, _jet_main.java, ...) to the src folder
>>>> but know I dont know where is the entry point to the transformation
>>>> so I can call it from my Java program.
>>>>
>>>> Thanks,
>>>> Rex
>>>
>>>
Re: Invoke JET2 Transformation from Java [message #22973 is a reply to message #22929] Wed, 20 June 2007 12:00 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: evaandoli.dodo.com.au

A few quick replies but maybe not the answer to all your questions:-

Don't merge projects - I tried a few times and it was a disaster :-)
Keep JET separate that is why I copied in 2 class (one the extention action
class called by GMF diagram, the other was the JET class ussed for calling
the transformation).

Getting the resource in the extention plugin class use
XMIResourceImpl resource = (XMIResourceImpl)
selectedRuleConductor.getEditingDomain().getResourceSet().ge tResources().get(1);

Hope that all helps a bit,

Stu


"Tex Twil" <chaljan@hotmail.com> wrote in message
news:f5avrf$dn7$1@build.eclipse.org...
>I don't really understand the parameter of runTransformOnResource
> "resource - the Eclipse Resource to load"
> Is it the input to the JET transformation ?
>
> In my case, the input file for JET is a XMI file of the instance of my GMF
> model from my workspace. How
> can I specify it ?
>
> tex.
>
>
> Tex Twil wrote:
>> Again sone questions:
>>
>> - the parameters of your runTransformOnObject fit more to a
>> runTransformOnResource is that normal ?
>>
>> - this method has an ID parameter of the JET transformation. Is that the
>> ID I have in my plugin.xml file i.e.
>> <extension
>> id="myID"
>> name=""
>> point="org.eclipse.jet.transform"
>> ...
>> ?
>>
>> - I want to merge the JET project with the GMF project. I copied all the
>> java sources/templates (_jet_transformation.java, _jet_main.java ... ) of
>> the JET transformation to a package of my GMF project is that ok ? Shall
>> I then also merge the plugin.xml of the JET project with the plugin.xml
>> of GMF ?
>>
>> Thank you again for your help !
>> Tex.
>>
>> Tex Twil wrote:
>>> Hello,
>>> I also want to call the transformation from a GMF project. I don't
>>> really understand what you mean by "From Extention plugin class".
>>>
>>> In my case I have a custom menu in my GMF model where I have a button
>>> "generate". I handle its action in a class:
>>>
>>> myMenuProvider extends ActionDelegate implements IEditorActionDelegate
>>>
>>> I'd like to call the transformation from here. How can I access the
>>> IResource here ?
>>>
>>> Tex.
>>>
>>>
>>>
>>> Stu wrote:
>>>> a Quick snip from my GMF project calling Jet hope it helps:-
>>>>
>>>> From Extention plugin class:-
>>>> Map<String, String> variables = new HashMap<String, String>();
>>>>
>>>> variables.put("org.eclipse.jet.resource.project.name",resource.getURI().segments()[1]);
>>>>
>>>> System.out.println("About to call common generate method in JET
>>>> project");
>>>>
>>>> variables.put("loadVar","sample1.xml");
>>>>
>>>> IStatus status = PerformJetTest.runTransformTest(resource,variables,
>>>> aProgressMonitor);
>>>>
>>>> ========
>>>>
>>>> Class below is defined in same project as Jet templates and has the
>>>> following method:
>>>>
>>>> public static IStatus runTransformTest(XMIResourceImpl aResource,
>>>>
>>>> Map<String, String> aVariables, NullProgressMonitor aProgressMonitor) {
>>>>
>>>> return JET2Platform.runTransformOnObject( "TestProjectJETId",
>>>> (Resource)aResource, aVariables, aProgressMonitor );
>>>>
>>>> }
>>>>
>>>>
>>>>
>>>> Hope that helps.
>>>>
>>>>
>>>>
>>>> "Tex Twil" <chaljan@hotmail.com> wrote in message
>>>> news:f58mdg$ste$1@build.eclipse.org...
>>>>> Hello,
>>>>> Are there any tutorials about how to invoke a JET transformation
>>>>> programaticly ?
>>>>>
>>>>> I have a JET project which works fine. Its input is one XML file and
>>>>> the output is another XML file. Now, I would like to use this
>>>>> transformation in another java project. I copied the JET sources
>>>>> (_jet_transformation.java, _jet_main.java, ...) to the src folder but
>>>>> know I dont know where is the entry point to the transformation so I
>>>>> can call it from my Java program.
>>>>>
>>>>> Thanks,
>>>>> Rex
>>>>
>>>>
Re: Invoke JET2 Transformation from Java [message #23058 is a reply to message #22973] Wed, 20 June 2007 14:48 Go to previous messageGo to next message
Tex Twil is currently offline Tex TwilFriend
Messages: 179
Registered: July 2009
Senior Member
Yes it helps !

I'm able to run the transformation now :)

But ... I'm stuck at another point. I would like to redirect the output
of the transformation to the Eclipse console. Which means, using a
IProgressMonitor instead of NullProgressMonitor.

The constructor takes the following params:
ProgressMonitorPart(Composite parent, Layout layout)

but I don't know where to get the parent parameter.

Tex.



Stu wrote:
> A few quick replies but maybe not the answer to all your questions:-
>
> Don't merge projects - I tried a few times and it was a disaster :-)
> Keep JET separate that is why I copied in 2 class (one the extention action
> class called by GMF diagram, the other was the JET class ussed for calling
> the transformation).
>
> Getting the resource in the extention plugin class use
> XMIResourceImpl resource = (XMIResourceImpl)
> selectedRuleConductor.getEditingDomain().getResourceSet().ge tResources().get(1);
>
> Hope that all helps a bit,
>
> Stu
>
>
> "Tex Twil" <chaljan@hotmail.com> wrote in message
> news:f5avrf$dn7$1@build.eclipse.org...
>> I don't really understand the parameter of runTransformOnResource
>> "resource - the Eclipse Resource to load"
>> Is it the input to the JET transformation ?
>>
>> In my case, the input file for JET is a XMI file of the instance of my GMF
>> model from my workspace. How
>> can I specify it ?
>>
>> tex.
>>
>>
>> Tex Twil wrote:
>>> Again sone questions:
>>>
>>> - the parameters of your runTransformOnObject fit more to a
>>> runTransformOnResource is that normal ?
>>>
>>> - this method has an ID parameter of the JET transformation. Is that the
>>> ID I have in my plugin.xml file i.e.
>>> <extension
>>> id="myID"
>>> name=""
>>> point="org.eclipse.jet.transform"
>>> ...
>>> ?
>>>
>>> - I want to merge the JET project with the GMF project. I copied all the
>>> java sources/templates (_jet_transformation.java, _jet_main.java ... ) of
>>> the JET transformation to a package of my GMF project is that ok ? Shall
>>> I then also merge the plugin.xml of the JET project with the plugin.xml
>>> of GMF ?
>>>
>>> Thank you again for your help !
>>> Tex.
>>>
>>> Tex Twil wrote:
>>>> Hello,
>>>> I also want to call the transformation from a GMF project. I don't
>>>> really understand what you mean by "From Extention plugin class".
>>>>
>>>> In my case I have a custom menu in my GMF model where I have a button
>>>> "generate". I handle its action in a class:
>>>>
>>>> myMenuProvider extends ActionDelegate implements IEditorActionDelegate
>>>>
>>>> I'd like to call the transformation from here. How can I access the
>>>> IResource here ?
>>>>
>>>> Tex.
>>>>
>>>>
>>>>
>>>> Stu wrote:
>>>>> a Quick snip from my GMF project calling Jet hope it helps:-
>>>>>
>>>>> From Extention plugin class:-
>>>>> Map<String, String> variables = new HashMap<String, String>();
>>>>>
>>>>> variables.put("org.eclipse.jet.resource.project.name",resource.getURI().segments()[1]);
>>>>>
>>>>> System.out.println("About to call common generate method in JET
>>>>> project");
>>>>>
>>>>> variables.put("loadVar","sample1.xml");
>>>>>
>>>>> IStatus status = PerformJetTest.runTransformTest(resource,variables,
>>>>> aProgressMonitor);
>>>>>
>>>>> ========
>>>>>
>>>>> Class below is defined in same project as Jet templates and has the
>>>>> following method:
>>>>>
>>>>> public static IStatus runTransformTest(XMIResourceImpl aResource,
>>>>>
>>>>> Map<String, String> aVariables, NullProgressMonitor aProgressMonitor) {
>>>>>
>>>>> return JET2Platform.runTransformOnObject( "TestProjectJETId",
>>>>> (Resource)aResource, aVariables, aProgressMonitor );
>>>>>
>>>>> }
>>>>>
>>>>>
>>>>>
>>>>> Hope that helps.
>>>>>
>>>>>
>>>>>
>>>>> "Tex Twil" <chaljan@hotmail.com> wrote in message
>>>>> news:f58mdg$ste$1@build.eclipse.org...
>>>>>> Hello,
>>>>>> Are there any tutorials about how to invoke a JET transformation
>>>>>> programaticly ?
>>>>>>
>>>>>> I have a JET project which works fine. Its input is one XML file and
>>>>>> the output is another XML file. Now, I would like to use this
>>>>>> transformation in another java project. I copied the JET sources
>>>>>> (_jet_transformation.java, _jet_main.java, ...) to the src folder but
>>>>>> know I dont know where is the entry point to the transformation so I
>>>>>> can call it from my Java program.
>>>>>>
>>>>>> Thanks,
>>>>>> Rex
>>>>>
>
>
Re: Invoke JET2 Transformation from Java [message #23182 is a reply to message #23058] Thu, 21 June 2007 04:36 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: evaandoli.dodo.com.au

Look at other methods within GMF that use IProgressMonitor.
There is probably a good example somewhere within GMF.

Sorry but I haven't used one yet, let me know how you go,

Stuart

"Tex Twil" <chaljan@hotmail.com> wrote in message
news:f5beo3$acs$1@build.eclipse.org...
> Yes it helps !
>
> I'm able to run the transformation now :)
>
> But ... I'm stuck at another point. I would like to redirect the output of
> the transformation to the Eclipse console. Which means, using a
> IProgressMonitor instead of NullProgressMonitor.
>
> The constructor takes the following params:
> ProgressMonitorPart(Composite parent, Layout layout)
>
> but I don't know where to get the parent parameter.
>
> Tex.
>
>
>
> Stu wrote:
>> A few quick replies but maybe not the answer to all your questions:-
>>
>> Don't merge projects - I tried a few times and it was a disaster :-)
>> Keep JET separate that is why I copied in 2 class (one the extention
>> action class called by GMF diagram, the other was the JET class ussed for
>> calling the transformation).
>>
>> Getting the resource in the extention plugin class use
>> XMIResourceImpl resource = (XMIResourceImpl)
>> selectedRuleConductor.getEditingDomain().getResourceSet().ge tResources().get(1);
>>
>> Hope that all helps a bit,
>>
>> Stu
>>
>>
>> "Tex Twil" <chaljan@hotmail.com> wrote in message
>> news:f5avrf$dn7$1@build.eclipse.org...
>>> I don't really understand the parameter of runTransformOnResource
>>> "resource - the Eclipse Resource to load"
>>> Is it the input to the JET transformation ?
>>>
>>> In my case, the input file for JET is a XMI file of the instance of my
>>> GMF model from my workspace. How
>>> can I specify it ?
>>>
>>> tex.
>>>
>>>
>>> Tex Twil wrote:
>>>> Again sone questions:
>>>>
>>>> - the parameters of your runTransformOnObject fit more to a
>>>> runTransformOnResource is that normal ?
>>>>
>>>> - this method has an ID parameter of the JET transformation. Is that
>>>> the ID I have in my plugin.xml file i.e.
>>>> <extension
>>>> id="myID"
>>>> name=""
>>>> point="org.eclipse.jet.transform"
>>>> ...
>>>> ?
>>>>
>>>> - I want to merge the JET project with the GMF project. I copied all
>>>> the java sources/templates (_jet_transformation.java, _jet_main.java
>>>> ... ) of the JET transformation to a package of my GMF project is that
>>>> ok ? Shall I then also merge the plugin.xml of the JET project with the
>>>> plugin.xml of GMF ?
>>>>
>>>> Thank you again for your help !
>>>> Tex.
>>>>
>>>> Tex Twil wrote:
>>>>> Hello,
>>>>> I also want to call the transformation from a GMF project. I don't
>>>>> really understand what you mean by "From Extention plugin class".
>>>>>
>>>>> In my case I have a custom menu in my GMF model where I have a button
>>>>> "generate". I handle its action in a class:
>>>>>
>>>>> myMenuProvider extends ActionDelegate implements IEditorActionDelegate
>>>>>
>>>>> I'd like to call the transformation from here. How can I access the
>>>>> IResource here ?
>>>>>
>>>>> Tex.
>>>>>
>>>>>
>>>>>
>>>>> Stu wrote:
>>>>>> a Quick snip from my GMF project calling Jet hope it helps:-
>>>>>>
>>>>>> From Extention plugin class:-
>>>>>> Map<String, String> variables = new HashMap<String, String>();
>>>>>>
>>>>>> variables.put("org.eclipse.jet.resource.project.name",resource.getURI().segments()[1]);
>>>>>>
>>>>>> System.out.println("About to call common generate method in JET
>>>>>> project");
>>>>>>
>>>>>> variables.put("loadVar","sample1.xml");
>>>>>>
>>>>>> IStatus status = PerformJetTest.runTransformTest(resource,variables,
>>>>>> aProgressMonitor);
>>>>>>
>>>>>> ========
>>>>>>
>>>>>> Class below is defined in same project as Jet templates and has the
>>>>>> following method:
>>>>>>
>>>>>> public static IStatus runTransformTest(XMIResourceImpl aResource,
>>>>>>
>>>>>> Map<String, String> aVariables, NullProgressMonitor aProgressMonitor)
>>>>>> {
>>>>>>
>>>>>> return JET2Platform.runTransformOnObject( "TestProjectJETId",
>>>>>> (Resource)aResource, aVariables, aProgressMonitor );
>>>>>>
>>>>>> }
>>>>>>
>>>>>>
>>>>>>
>>>>>> Hope that helps.
>>>>>>
>>>>>>
>>>>>>
>>>>>> "Tex Twil" <chaljan@hotmail.com> wrote in message
>>>>>> news:f58mdg$ste$1@build.eclipse.org...
>>>>>>> Hello,
>>>>>>> Are there any tutorials about how to invoke a JET transformation
>>>>>>> programaticly ?
>>>>>>>
>>>>>>> I have a JET project which works fine. Its input is one XML file and
>>>>>>> the output is another XML file. Now, I would like to use this
>>>>>>> transformation in another java project. I copied the JET sources
>>>>>>> (_jet_transformation.java, _jet_main.java, ...) to the src folder
>>>>>>> but know I dont know where is the entry point to the transformation
>>>>>>> so I can call it from my Java program.
>>>>>>>
>>>>>>> Thanks,
>>>>>>> Rex
>>>>>>
>>
Re: Invoke JET2 Transformation from Java [message #23327 is a reply to message #23058] Thu, 21 June 2007 16:07 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: vincent.lg.voila.fr

Hi Tex and Stu,

I've also developed an action to call a jet transformation by code, and I
would like to redirect the output to the console. Can you give me some
feedback if you succeed in implementing that stuff ?

For the moment, I've tried a more complicated code than just calling
JET2Platform.runTransformOnResource(...), but it was useless :

JET2Context context = new JET2Context(null);
String id = "jetplugin.id";

IJETBundleDescriptor descriptor =
JET2Platform.getJETBundleManager().getDescriptor(id);

if(descriptor!=null) {
String loaderId = descriptor.getModelLoader();
String fileType = descriptor.getModelExtension();

WorkspaceContextExtender.loadResourceAsSource(context, modelFile,
loaderId, fileType);

status = JET2Platform.runTransform(id, context, new
NullProgressMonitor());
context.logInfo(status.getMessage());
//...
}

This works fine but it does not log any info to the console. I don't know
if creating a JET2Context with a not null param could resolve the problem.

Let me know if you've resolved it, I'll do the same.

Thanks,
Vincent.
Re: Invoke JET2 Transformation from Java [message #23545 is a reply to message #23327] Fri, 22 June 2007 08:56 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: vincent.lg.voila.fr

Ok, done !

I've found a solution seeking deep into the JET framework, using a lot of
breakpoints, but there is some code that behave as the launch
configuration does, providing progress and console support :


/**
* @param id id of the JET transform (ex. "my.jetplugin.id")
* @param res the resource (IFile) input model to be transformed
*/
private void runTransform(String id, IResource res) {

ILaunchConfigurationType jetLct = null;
ILaunchManager lm = DebugPlugin.getDefault().getLaunchManager();
// get the default JET configuration type
jetLct = lm.getLaunchConfigurationType(JETLaunchConstants.CONFIG_ID);

try {
// create a tmp config with given attributes
ILaunchConfigurationWorkingCopy wCopy = jetLct.newInstance(null,
lm.generateUniqueLaunchConfigurationNameFrom(id+res.getName( )));
wCopy.setAttribute(JETLaunchConstants.ID, id);
wCopy.setAttribute(JETLaunchConstants.SOURCE,
res.getFullPath().toString());
wCopy.setAttribute(JETLaunchConstants.LOG_FILTER_LEVEL,
RuntimeLoggerContextExtender.INFO_LEVEL);

final IJETBundleDescriptor jetDesc =
JET2Platform.getJETBundleManager().getDescriptor(id);
// if the JET plugin if found, try to launch it
if(jetDesc!=null) {
// get the launch configuration from the copy
ILaunchConfiguration config = wCopy.doSave();

// launch the JET configuration
DebugUITools.launch(config, ILaunchManager.RUN_MODE);
}
} catch (CoreException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}

Hope this helps,
Vincent.
Re: Invoke JET2 Transformation from Java [message #23676 is a reply to message #23545] Fri, 22 June 2007 14:49 Go to previous messageGo to next message
Paul Elder is currently offline Paul ElderFriend
Messages: 849
Registered: July 2009
Senior Member
Vincent:

Very impressive. I have created a FAQ entry, and would like to include your
code. My I have your permission? Contributing it to the FAQ means you are
granting use of it under the EPL (see the Eclipse Wiki Terms of Use:
http://www.eclipse.org//legal/termsofuse.php)

Here is a like to the FAQ article:

http://wiki.eclipse.org/JET_FAQ_How_do_I_get_a_console_when_ running_JET_from_Java%3F

Paul

"vincent" <vincent.lg@voila.fr> wrote in message
news:a95de639f0831e052eb6a7ac26081a31$1@www.eclipse.org...
> Ok, done !
>
> I've found a solution seeking deep into the JET framework, using a lot of
> breakpoints, but there is some code that behave as the launch
> configuration does, providing progress and console support :
>
>
> /**
> * @param id id of the JET transform (ex. "my.jetplugin.id")
> * @param res the resource (IFile) input model to be transformed
> */ private void runTransform(String id, IResource res) {
>
> ILaunchConfigurationType jetLct = null;
> ILaunchManager lm = DebugPlugin.getDefault().getLaunchManager();
> // get the default JET configuration type
> jetLct = lm.getLaunchConfigurationType(JETLaunchConstants.CONFIG_ID);
>
> try {
> // create a tmp config with given attributes
> ILaunchConfigurationWorkingCopy wCopy = jetLct.newInstance(null,
> lm.generateUniqueLaunchConfigurationNameFrom(id+res.getName( )));
> wCopy.setAttribute(JETLaunchConstants.ID, id);
> wCopy.setAttribute(JETLaunchConstants.SOURCE,
> res.getFullPath().toString());
> wCopy.setAttribute(JETLaunchConstants.LOG_FILTER_LEVEL,
> RuntimeLoggerContextExtender.INFO_LEVEL);
>
> final IJETBundleDescriptor jetDesc =
> JET2Platform.getJETBundleManager().getDescriptor(id);
> // if the JET plugin if found, try to launch it
> if(jetDesc!=null) {
> // get the launch configuration from the copy
> ILaunchConfiguration config = wCopy.doSave();
>
> // launch the JET configuration
> DebugUITools.launch(config, ILaunchManager.RUN_MODE);
> }
> } catch (CoreException e) {
> // TODO Auto-generated catch block
> e.printStackTrace();
> }
> }
>
> Hope this helps,
> Vincent.
Re: Invoke JET2 Transformation from Java [message #23800 is a reply to message #23676] Mon, 25 June 2007 13:28 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: vincent.lg.voila.fr

Hi Paul,

I'm glad that my code would help other people, you have my permission ;-)
Nevertheless, as you mention it in the JET FAQ, some constants from
RuntimeLoggerContextExtender are packaged with restriction access, even if
one can use them. Giving full access to them would be great.

Here are some other tricks you could add to the FAQ example :

DebugUITools#launch(...) runs asynchronously by default, add this code to
change the default behavior :
> wCopy.setAttribute(IDebugUIConstants.ATTR_LAUNCH_IN_BACKGROU ND, false);
(this is great if you have something to run after launch is complete)

ILaunchConfiguration#launch() runs synchronously, but does not support
progress monitor
> ILaunch launch = config.launch( ILaunchManager.RUN_MODE, new
NullProgressMonitor(), true);
Re: Invoke JET2 Transformation from Java [message #24891 is a reply to message #23545] Wed, 04 July 2007 10:27 Go to previous messageGo to next message
Tex Twil is currently offline Tex TwilFriend
Messages: 179
Registered: July 2009
Senior Member
Hi,
how can I adapt this to a XMIResourceImpl as input of the JET
transformation ?

thanks,
Tex.
vincent wrote:
> Ok, done !
>
> I've found a solution seeking deep into the JET framework, using a lot
> of breakpoints, but there is some code that behave as the launch
> configuration does, providing progress and console support :
>
>
> /**
> * @param id id of the JET transform (ex. "my.jetplugin.id")
> * @param res the resource (IFile) input model to be transformed
> */ private void runTransform(String id, IResource res) {
>
> ILaunchConfigurationType jetLct = null;
> ILaunchManager lm = DebugPlugin.getDefault().getLaunchManager();
> // get the default JET configuration type
> jetLct = lm.getLaunchConfigurationType(JETLaunchConstants.CONFIG_ID);
>
> try {
> // create a tmp config with given attributes
> ILaunchConfigurationWorkingCopy wCopy = jetLct.newInstance(null,
> lm.generateUniqueLaunchConfigurationNameFrom(id+res.getName( )));
> wCopy.setAttribute(JETLaunchConstants.ID, id);
> wCopy.setAttribute(JETLaunchConstants.SOURCE,
> res.getFullPath().toString());
> wCopy.setAttribute(JETLaunchConstants.LOG_FILTER_LEVEL,
> RuntimeLoggerContextExtender.INFO_LEVEL);
>
> final IJETBundleDescriptor jetDesc =
> JET2Platform.getJETBundleManager().getDescriptor(id);
> // if the JET plugin if found, try to launch it
> if(jetDesc!=null) {
> // get the launch configuration from the copy
> ILaunchConfiguration config = wCopy.doSave();
>
> // launch the JET configuration
> DebugUITools.launch(config, ILaunchManager.RUN_MODE);
> }
> } catch (CoreException e) {
> // TODO Auto-generated catch block
> e.printStackTrace();
> }
> }
>
> Hope this helps,
> Vincent.
Re: Invoke JET2 Transformation from Java [message #25125 is a reply to message #24891] Thu, 05 July 2007 13:05 Go to previous messageGo to next message
Paul Elder is currently offline Paul ElderFriend
Messages: 849
Registered: July 2009
Senior Member
Tex:

This approach requires the workspace relative path of the resource being
loaded. You cannot pass your in memory XMIResourceImpl directly. Instead,
you must save it, and set the JETLaunchConstants.SOURCE to the workspace
relative path of the XMIResourceImpl. If you are using EMF 2.3, this is as
easy as:

wCopy.setAttribute(JETLaunchConstants.SOURCE,
xmiRes.getURI().toPlatformString(true/*decode*/));

Paul

"Tex Twil" <chaljan@hotmail.com> wrote in message
news:f6fsn0$p6k$1@build.eclipse.org...
> Hi,
> how can I adapt this to a XMIResourceImpl as input of the JET
> transformation ?
>
> thanks,
> Tex.
> vincent wrote:
>> Ok, done !
>>
>> I've found a solution seeking deep into the JET framework, using a lot of
>> breakpoints, but there is some code that behave as the launch
>> configuration does, providing progress and console support :
>>
>>
>> /**
>> * @param id id of the JET transform (ex. "my.jetplugin.id")
>> * @param res the resource (IFile) input model to be transformed
>> */ private void runTransform(String id, IResource res) {
>> ILaunchConfigurationType jetLct = null;
>> ILaunchManager lm = DebugPlugin.getDefault().getLaunchManager();
>> // get the default JET configuration type
>> jetLct = lm.getLaunchConfigurationType(JETLaunchConstants.CONFIG_ID);
>>
>> try {
>> // create a tmp config with given attributes
>> ILaunchConfigurationWorkingCopy wCopy = jetLct.newInstance(null,
>> lm.generateUniqueLaunchConfigurationNameFrom(id+res.getName( )));
>> wCopy.setAttribute(JETLaunchConstants.ID, id);
>> wCopy.setAttribute(JETLaunchConstants.SOURCE,
>> res.getFullPath().toString());
>> wCopy.setAttribute(JETLaunchConstants.LOG_FILTER_LEVEL,
>> RuntimeLoggerContextExtender.INFO_LEVEL);
>> final IJETBundleDescriptor jetDesc =
>> JET2Platform.getJETBundleManager().getDescriptor(id);
>> // if the JET plugin if found, try to launch it
>> if(jetDesc!=null) {
>> // get the launch configuration from the copy
>> ILaunchConfiguration config = wCopy.doSave();
>>
>> // launch the JET configuration
>> DebugUITools.launch(config, ILaunchManager.RUN_MODE);
>> }
>> } catch (CoreException e) {
>> // TODO Auto-generated catch block
>> e.printStackTrace();
>> }
>> }
>>
>> Hope this helps,
>> Vincent.
Re: Invoke JET2 Transformation from Java [message #25447 is a reply to message #25125] Mon, 09 July 2007 14:55 Go to previous messageGo to next message
Tex Twil is currently offline Tex TwilFriend
Messages: 179
Registered: July 2009
Senior Member
Ok.

Two more questions.

- If I run this code in Eclipse , it runs the JET execution but it also
creates a JET run configuration which stays. So if I run it 3 times, it
will create 3 new Run Configurations. How to avoid this ?


- How can I pass variables to the JET execution. i.e. :

variables.put("org.eclipse.jet.resource.project.outdir", outputDir);

and then in the use in JET
{$org.eclipse.jet.resource.project.outdir}

Thanks,
Tex.


Paul Elder wrote:
> Tex:
>
> This approach requires the workspace relative path of the resource being
> loaded. You cannot pass your in memory XMIResourceImpl directly. Instead,
> you must save it, and set the JETLaunchConstants.SOURCE to the workspace
> relative path of the XMIResourceImpl. If you are using EMF 2.3, this is as
> easy as:
>
> wCopy.setAttribute(JETLaunchConstants.SOURCE,
> xmiRes.getURI().toPlatformString(true/*decode*/));
>
> Paul
>
> "Tex Twil" <chaljan@hotmail.com> wrote in message
> news:f6fsn0$p6k$1@build.eclipse.org...
>> Hi,
>> how can I adapt this to a XMIResourceImpl as input of the JET
>> transformation ?
>>
>> thanks,
>> Tex.
>> vincent wrote:
>>> Ok, done !
>>>
>>> I've found a solution seeking deep into the JET framework, using a lot of
>>> breakpoints, but there is some code that behave as the launch
>>> configuration does, providing progress and console support :
>>>
>>>
>>> /**
>>> * @param id id of the JET transform (ex. "my.jetplugin.id")
>>> * @param res the resource (IFile) input model to be transformed
>>> */ private void runTransform(String id, IResource res) {
>>> ILaunchConfigurationType jetLct = null;
>>> ILaunchManager lm = DebugPlugin.getDefault().getLaunchManager();
>>> // get the default JET configuration type
>>> jetLct = lm.getLaunchConfigurationType(JETLaunchConstants.CONFIG_ID);
>>>
>>> try {
>>> // create a tmp config with given attributes
>>> ILaunchConfigurationWorkingCopy wCopy = jetLct.newInstance(null,
>>> lm.generateUniqueLaunchConfigurationNameFrom(id+res.getName( )));
>>> wCopy.setAttribute(JETLaunchConstants.ID, id);
>>> wCopy.setAttribute(JETLaunchConstants.SOURCE,
>>> res.getFullPath().toString());
>>> wCopy.setAttribute(JETLaunchConstants.LOG_FILTER_LEVEL,
>>> RuntimeLoggerContextExtender.INFO_LEVEL);
>>> final IJETBundleDescriptor jetDesc =
>>> JET2Platform.getJETBundleManager().getDescriptor(id);
>>> // if the JET plugin if found, try to launch it
>>> if(jetDesc!=null) {
>>> // get the launch configuration from the copy
>>> ILaunchConfiguration config = wCopy.doSave();
>>>
>>> // launch the JET configuration
>>> DebugUITools.launch(config, ILaunchManager.RUN_MODE);
>>> }
>>> } catch (CoreException e) {
>>> // TODO Auto-generated catch block
>>> e.printStackTrace();
>>> }
>>> }
>>>
>>> Hope this helps,
>>> Vincent.
>
>
Re: Invoke JET2 Transformation from Java [message #25820 is a reply to message #25447] Wed, 11 July 2007 04:45 Go to previous messageGo to next message
hamlin is currently offline hamlinFriend
Messages: 8
Registered: July 2009
Junior Member
Hi Tex,
I met the problem as your first question described when I was using JET1.
I have no better way instead of writing some code to delete it after the
JET execution.

When you got the solutions for your two questions, please let me know. I
believe they would be very helpful for me. Thanks a lot.

BR,
Chaohong

Tex Twil wrote:

> Ok.

> Two more questions.

> - If I run this code in Eclipse , it runs the JET execution but it also
> creates a JET run configuration which stays. So if I run it 3 times, it
> will create 3 new Run Configurations. How to avoid this ?


> - How can I pass variables to the JET execution. i.e. :

> variables.put("org.eclipse.jet.resource.project.outdir", outputDir);

> and then in the use in JET
> {$org.eclipse.jet.resource.project.outdir}

> Thanks,
> Tex.
Re: Invoke JET2 Transformation from Java [message #26071 is a reply to message #25447] Wed, 11 July 2007 16:14 Go to previous message
Paul Elder is currently offline Paul ElderFriend
Messages: 849
Registered: July 2009
Senior Member
Tex:

The JET UI has code to discover a run configuration. Take a look at
JETLaunchHelper.findConfigsForTransformAndResource().
( http://dev.eclipse.org/viewcvs/index.cgi/org.eclipse.m2t/org .eclipse.jet/plugins/org.eclipse.jet.ui/src/org/eclipse/jet/ internal/ui/launch/JETLaunchHelper.java?revision=1.2&roo t=Modeling_Project&view=markup).
This is private API, but you could always cut and paste.

Alternatively, you could just remove the launch configuration once you have
finished with it.


As for defining variables in launch configurations, this cannot currently be
done. Would it be possible to put such information in you input model?

And, although it won't solve the problem for you, you can submit an
enhancement request:

https://bugs.eclipse.org/bugs/enter_bug.cgi?product=M2T& version=unspecified&component=Jet&rep_platform=PC&am p;op_sys=Windows%20XP&priority=P3&bug_severity=enhan cement&bug_status=NEW&bug_file_loc=http%3A%2F%2F& ;short_desc=&comment=&commentprivacy=0&keywords= &dependson=&blocked=&maketemplate=Remember%20val ues%20as%20bookmarkable%20template&form_name=enter_bug&a mp;assigned_to=m2t.jet-inbox%40eclipse.org

Paul

"Tex Twil" <chaljan@hotmail.com> wrote in message
news:f6ti8k$ep2$1@build.eclipse.org...
> Ok.
>
> Two more questions.
>
> - If I run this code in Eclipse , it runs the JET execution but it also
> creates a JET run configuration which stays. So if I run it 3 times, it
> will create 3 new Run Configurations. How to avoid this ?
>
>
> - How can I pass variables to the JET execution. i.e. :
>
> variables.put("org.eclipse.jet.resource.project.outdir", outputDir);
>
> and then in the use in JET
> {$org.eclipse.jet.resource.project.outdir}
>
> Thanks,
> Tex.
>
>
> Paul Elder wrote:
>> Tex:
>>
>> This approach requires the workspace relative path of the resource being
>> loaded. You cannot pass your in memory XMIResourceImpl directly. Instead,
>> you must save it, and set the JETLaunchConstants.SOURCE to the workspace
>> relative path of the XMIResourceImpl. If you are using EMF 2.3, this is
>> as easy as:
>>
>> wCopy.setAttribute(JETLaunchConstants.SOURCE,
>> xmiRes.getURI().toPlatformString(true/*decode*/));
>>
>> Paul
>>
>> "Tex Twil" <chaljan@hotmail.com> wrote in message
>> news:f6fsn0$p6k$1@build.eclipse.org...
>>> Hi,
>>> how can I adapt this to a XMIResourceImpl as input of the JET
>>> transformation ?
>>>
>>> thanks,
>>> Tex.
>>> vincent wrote:
>>>> Ok, done !
>>>>
>>>> I've found a solution seeking deep into the JET framework, using a lot
>>>> of breakpoints, but there is some code that behave as the launch
>>>> configuration does, providing progress and console support :
>>>>
>>>>
>>>> /**
>>>> * @param id id of the JET transform (ex. "my.jetplugin.id")
>>>> * @param res the resource (IFile) input model to be transformed
>>>> */ private void runTransform(String id, IResource res) {
>>>> ILaunchConfigurationType jetLct = null;
>>>> ILaunchManager lm = DebugPlugin.getDefault().getLaunchManager();
>>>> // get the default JET configuration type
>>>> jetLct = lm.getLaunchConfigurationType(JETLaunchConstants.CONFIG_ID);
>>>>
>>>> try {
>>>> // create a tmp config with given attributes
>>>> ILaunchConfigurationWorkingCopy wCopy = jetLct.newInstance(null,
>>>> lm.generateUniqueLaunchConfigurationNameFrom(id+res.getName( )));
>>>> wCopy.setAttribute(JETLaunchConstants.ID, id);
>>>> wCopy.setAttribute(JETLaunchConstants.SOURCE,
>>>> res.getFullPath().toString());
>>>> wCopy.setAttribute(JETLaunchConstants.LOG_FILTER_LEVEL,
>>>> RuntimeLoggerContextExtender.INFO_LEVEL);
>>>> final IJETBundleDescriptor jetDesc =
>>>> JET2Platform.getJETBundleManager().getDescriptor(id);
>>>> // if the JET plugin if found, try to launch it
>>>> if(jetDesc!=null) {
>>>> // get the launch configuration from the copy
>>>> ILaunchConfiguration config = wCopy.doSave();
>>>>
>>>> // launch the JET configuration
>>>> DebugUITools.launch(config, ILaunchManager.RUN_MODE);
>>>> }
>>>> } catch (CoreException e) {
>>>> // TODO Auto-generated catch block
>>>> e.printStackTrace();
>>>> }
>>>> }
>>>>
>>>> Hope this helps,
>>>> Vincent.
>>
Previous Topic:Re: Spaces in URLs
Next Topic:How to run a jet transformation in the plug-ins?
Goto Forum:
  


Current Time: Thu Dec 18 02:30:52 GMT 2014

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

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