Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » M2T (model-to-text transformation) » JET2 Transform not working(Running a JET2 transform programmatically isn't working)
JET2 Transform not working [message #990345] Tue, 11 December 2012 23:54 Go to next message
Phillip Drew is currently offline Phillip Drew
Messages: 72
Registered: October 2012
Member
Basically I'm trying to run a JET2 Transform programmatically.

I've got a String representing XML input.

I've got a simple JET2 Transform:

main.jet

<%@taglib prefix="ws" id="org.eclipse.jet.workspaceTags" %>
<%-- Main entry point for com.themousewheel.sandbox.jet2 --%>

<%-- 
  Let c:iterate tags set the XPath context object.
  For 100% compatibility with JET 0.9.x or earlier, remove this statement
 --%>
<c:setVariable var="org.eclipse.jet.taglib.control.iterateSetsContext" select="true()"/>

<%-- 
TODO: traverse input model, performing calculations and storing 
the results as model annotations via c:set tag 
--%>


<%--
TODO: traverse annotated model, performing text generation actions 
such as ws:file, ws:folder and ws:project 
--%>
   

<%-- For debug purposes, dump the annotated input model in 
   the root of the project containing the original input model.
   
   Note that model formatting may not be identical, and that in
   the case of non-XML input models, the dump may look quite different.
--%>

<c:if test="isVariableDefined('org.eclipse.jet.resource.project.name')">
    <ws:file template="templates/dump.jet" path="{$org.eclipse.jet.resource.project.name}/dump.xml"/>
</c:if>


and dump.jet

<%@taglib prefix="ws" id="org.eclipse.jet.workspaceTags" %>
<ws:project name="TEST">

</ws:project>

Also some text in case dump.xml works

<ws:rebuildWorkspace/>


I figured after I couldn't find the dump.xml file that it might be easier to tell if the transform is working by creating a project in the workspace (in case I just had file paths a bit wonky).

I'm running the transform within an OSGi bundle activator using the following line
IStatus status = JET2Platform.runTransformOnString("com.themousewheel.sandbox.jet2", generator.getDomainXML(), new NullProgressMonitor());
		System.out.println(status);


which prints "Status OK: org.eclipse.jet code=0 Successful Execution null" to standard out.

However despite the transform apparently running successfully dump.xml and the project TEST aren't created!

Does anyone have any ideas? This problem is currently a blocker for me and I don't know how to proceed because I'm not getting any meaningful output to help me diagnose what's wrong!

Thanks in advance!
Re: JET2 Transform not working [message #990446 is a reply to message #990345] Wed, 12 December 2012 09:13 Go to previous messageGo to next message
Paul Elder is currently offline Paul Elder
Messages: 849
Registered: July 2009
Senior Member
Phillip:

The problem has to do with where you put your ws:project take - namely, in the dump.jet template.

The dump.jet template is invoked by the following code in main.jet:

<c:if test="isVariableDefined('org.eclipse.jet.resource.project.name')">
    <ws:file template="templates/dump.jet" path="{$org.eclipse.jet.resource.project.name}/dump.xml"/>
</c:if>


That is, only if the JET variable org.eclipse.jet.resource.project.name is defined. When you run the transformation from JET2Platform.runTransformOnString(), that variable is not defined.

So...

Move you ws:project tag into main.jet (outside of that c:if), and try again.

As an aside:

The general pattern I have used for JET transformations is that main.jet 'orchestrates' other template invocations. As the main.jet comments say, it typically does two passes through the input model: the first to 'annotate' it with additional values needed in code generation (set the c:set tag); the second to do the actual code generation/artifact creation.

The dump.jet template is simple-minded tool to let you see your input model complete with annotations, if you've added them. It probably should not be used for anything productive.

Paul
Re: JET2 Transform not working [message #990533 is a reply to message #990446] Wed, 12 December 2012 17:39 Go to previous message
Phillip Drew is currently offline Phillip Drew
Messages: 72
Registered: October 2012
Member
Well it appeared to be doing nothing but moving the <ws:project> tag outside of the <c:if> tag does actually create the project.

The problem is that it creates the new project in a location that is not my workspace so obviously the new project doesn't actually appear in Eclipse.

How do I force it to generate the project in my actual workspace folder?

New main.jet shown below

<%@taglib prefix="ws" id="org.eclipse.jet.workspaceTags" %>
<%-- Main entry point for com.themousewheel.sandbox.jet2 --%>

<%-- 
  Let c:iterate tags set the XPath context object.
  For 100% compatibility with JET 0.9.x or earlier, remove this statement
 --%>
<c:setVariable var="org.eclipse.jet.taglib.control.iterateSetsContext" select="true()"/>

<%-- 
TODO: traverse input model, performing calculations and storing 
the results as model annotations via c:set tag 
--%>


<%--
TODO: traverse annotated model, performing text generation actions 
such as ws:file, ws:folder and ws:project 
--%>
   

<%-- For debug purposes, dump the annotated input model in 
   the root of the project containing the original input model.
   
   Note that model formatting may not be identical, and that in
   the case of non-XML input models, the dump may look quite different.
--%>

<ws:project name="TEST">
	<ws:file template="templates/dump.jet" path="dump.xml"/>
</ws:project>

<ws:rebuildWorkspace/>

Previous Topic:[XPAND] Adding a template to classpath
Next Topic:acceleo java.lang.NumberFormatException: For input string: "aadlSpec[@name=test]"
Goto Forum:
  


Current Time: Wed Jul 30 11:22:44 EDT 2014

Powered by FUDForum. Page generated in 0.07218 seconds