Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » M2T (model-to-text transformation) » Templates not in project?
Templates not in project? [message #6560] Fri, 23 March 2007 18:57 Go to next message
Julen Parra is currently offline Julen ParraFriend
Messages: 12
Registered: July 2009
Junior Member
Hi, everybody,

I work in a database plugin for Eclipse, QuantumDB
(quantum.sourceforge.net), that generates some XML from the structure of
the database inspected. I'd like to apply some transforms on that XML and
I'm trying to use JET2 for the task, with partial success. I'd like the
user to select the tables for which it wants some text generated (for
example the CREATE TABLE statement), select a transform to apply, and the
plugin would generate the XML from those tables and apply the transform.

To date, I've managed to do that, using something like this code:
...
String xmlInput = getXMLfromSelectedTables();
IProgressMonitor monitor = new NullProgressMonitor();
Map<String, String> variables = new HashMap<String, String>();
variables.put("org.eclipse.jet.resource.project.name","/Test ");
JET2Platform.runTransformOnString("Test", xmlInput, "xml", variables,
monitor);
...

Only that, for this code to work, I need to have a "Test" project in the
workspace, with JET nature, and the templates that I want. In that way I
cannot deploy ready-made templates with common transforms.

I'd like to do the same but with templates coming from other places, not
from the workspace in the form of a JET project. Can I do something like
what I have, but using not a transform id, but actual templates in form of
a String or a stream or something of that nature?

If it's not possible with the current framework, some pointers to the
classes/methods where I could grab the needed functionality to mount
something like what I need would be much appreciated.

Thanks in advance.

Julen.
Re: Templates not in project? [message #18137 is a reply to message #6560] Mon, 28 May 2007 07:27 Go to previous messageGo to next message
Francis Gavino is currently offline Francis GavinoFriend
Messages: 57
Registered: July 2009
Member
Hi Julen,

I also have the same problem. I would like to reuse some JET templates
across JET plug-in projects (i don't want to use just 1 plug-in project)
but I haven't found any solution to this yet.

A concrete application to this is having 1 common place to write the
copyright/legal text in one template and just "c:include" them in the
other templates which may or may not be in the same plug-in project.
Another approach to this is to use "c:load" and have an XML file that
contains the copyright text. But again, this tag seems to only support
having the XML file in the same plug-in project (urlContext='transform'),
or in a project in the runtime workspace (urlContext='workspace') - which
is not desired since the template should be hidden/internal in a plug-in.

Has anyone found a solution to this?

Thanks.
Francis



Julen Parra wrote:

> Hi, everybody,

> I work in a database plugin for Eclipse, QuantumDB
> (quantum.sourceforge.net), that generates some XML from the structure of
> the database inspected. I'd like to apply some transforms on that XML and
> I'm trying to use JET2 for the task, with partial success. I'd like the
> user to select the tables for which it wants some text generated (for
> example the CREATE TABLE statement), select a transform to apply, and the
> plugin would generate the XML from those tables and apply the transform.

> To date, I've managed to do that, using something like this code:
> ...
> String xmlInput = getXMLfromSelectedTables();
> IProgressMonitor monitor = new NullProgressMonitor();
> Map<String, String> variables = new HashMap<String, String>();
> variables.put("org.eclipse.jet.resource.project.name","/Test ");
> JET2Platform.runTransformOnString("Test", xmlInput, "xml", variables,
> monitor);
> ...

> Only that, for this code to work, I need to have a "Test" project in the
> workspace, with JET nature, and the templates that I want. In that way I
> cannot deploy ready-made templates with common transforms.

> I'd like to do the same but with templates coming from other places, not
> from the workspace in the form of a JET project. Can I do something like
> what I have, but using not a transform id, but actual templates in form of
> a String or a stream or something of that nature?

> If it's not possible with the current framework, some pointers to the
> classes/methods where I could grab the needed functionality to mount
> something like what I need would be much appreciated.

> Thanks in advance.

> Julen.
Re: Templates not in project? [message #18183 is a reply to message #18137] Mon, 28 May 2007 13:07 Go to previous messageGo to next message
Paul Elder is currently offline Paul ElderFriend
Messages: 849
Registered: July 2009
Senior Member
Francis:

I had not thought of this 'common include file' use case before, but here's
a possible solution:

1) Create a JET project "my.copyright.notices". Include a template
'standardCopyright.jet'.

2) When creating other JET projects, open plugin.xml, go to the Extensions
tab, expand 'org.eclipse.jet.transform', and click on "(transform)". Then,
set the 'overrides' attribute to 'my.copyright.notices'.

Templates in the the transformation can then do exactly what you want:

<c:include template="standardCopyright.jet'/>

The intent of override was to let you selectively customize templates in an
existing transformation, but I think you'll find this works well for your
scenario, too.

Paul
Re: Templates not in project? [message #18201 is a reply to message #6560] Mon, 28 May 2007 13:41 Go to previous messageGo to next message
Paul Elder is currently offline Paul ElderFriend
Messages: 849
Registered: July 2009
Senior Member
Julen:

Apologies for not responding sooner - you post some escaped my notice.

I do not understand why you must have your 'Test' project - are you
generated JET templates on the fly?

If you are, then getting JET to work for you will be a challenge. The JET
compiler produces Java source files - JET relies on the Java project builder
to turn those into Java class files.

But, if you are not creating JET templates on-the-fly, then you should be
able to package your JET transformation in any of the following ways:

1) as a normally installed Eclipse plug-in
2) as a JAR file included within another Eclipse plug-in, and declared via
the org.eclipse.jet.deployedTransforms extension point.
3) as a JAR file located in a directory that is referenced by the
'Additional locations for JET transformations' preference.

Lastly, if you are looking for templates that just produce text that you
then save, you should consider some of the following:

1) JET now can compile JET1 (EMF codegen-style) templates. These produce a
Java class with a String generate(Object argument) method. You pass the
method an object, it returns you a String. The advantage of JET1 templates
are that they have no dependencies other that what you introduce. The
disadvantage is that they do not support tag libraries. You can use JET1
templates in any Java project, not just plug-in projects. Unfortunately,
there is not yet any UI to install this in an arbitrary Java project. The
easiest way to do this is to modify the .project for to add the JET nature
and JET builder (copied out of an existing JET project), and then to modify
the JET project properties to compile as JET1 source.

2) Alternatively, you could use org.eclipse.emf.codegen.

3) In JET 0.8.M7, I introduced a utility to allow you to run individual JET2
templates (complete with tags) from you Java code. The templates are still
loaded from a JET2 transformation (either project, or packaged plug-in), but
instead of template results being written to the workspace, you received
them as a String. Take a look at org.eclipse.jet.JET2TemplateManager. A
typical usage would be:

String[] transformIdsSupplyingTemplates = new String[] { ... };
final Object sourceModel = ...; // possibly loaded via
JET2Platform.getModelLoaderManager() ...
JET2TemplateManager.run( transformIdsSupplyingTemplates, new
JET2TemplateManager.ITemplateOperation() {
public void run(JET2TemplateManager.ITemplateRunner templateRunner) {
JET2Context context = new JET2Context(sourceModel);

...
BodyContentWriter out = new BodyContentWriter();
templateRunner.generate("template-path", context, out);
... do something with the result: out.getContent() ...
}
}

Paul

"Julen Parra" <jparrai@terra.es> wrote in message
news:83deea43e5c23973954353e306031e04$1@www.eclipse.org...
> Hi, everybody,
>
> I work in a database plugin for Eclipse, QuantumDB
> (quantum.sourceforge.net), that generates some XML from the structure of
> the database inspected. I'd like to apply some transforms on that XML and
> I'm trying to use JET2 for the task, with partial success. I'd like the
> user to select the tables for which it wants some text generated (for
> example the CREATE TABLE statement), select a transform to apply, and the
> plugin would generate the XML from those tables and apply the transform.
>
> To date, I've managed to do that, using something like this code:
> ..
> String xmlInput = getXMLfromSelectedTables();
> IProgressMonitor monitor = new NullProgressMonitor();
> Map<String, String> variables = new HashMap<String, String>();
> variables.put("org.eclipse.jet.resource.project.name","/Test ");
> JET2Platform.runTransformOnString("Test", xmlInput, "xml", variables,
> monitor);
> ..
>
> Only that, for this code to work, I need to have a "Test" project in the
> workspace, with JET nature, and the templates that I want. In that way I
> cannot deploy ready-made templates with common transforms.
>
> I'd like to do the same but with templates coming from other places, not
> from the workspace in the form of a JET project. Can I do something like
> what I have, but using not a transform id, but actual templates in form of
> a String or a stream or something of that nature?
>
> If it's not possible with the current framework, some pointers to the
> classes/methods where I could grab the needed functionality to mount
> something like what I need would be much appreciated.
>
> Thanks in advance.
>
> Julen.
>
Re: Templates not in project? [message #18250 is a reply to message #18183] Tue, 29 May 2007 05:04 Go to previous message
Francis Gavino is currently offline Francis GavinoFriend
Messages: 57
Registered: July 2009
Member
Works like a charm! Thanks Paul.
Previous Topic:Multiple Files
Next Topic:JET2 access to ecore references
Goto Forum:
  


Current Time: Fri Mar 29 00:41:21 GMT 2024

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

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

Back to the top