| Home » Modeling » M2T (model-to-text transformation) » Running the result of a JET transform
 Goto Forum:| 
| Running the result of a JET transform [message #52826] | Sat, 01 November 2008 09:27  |  | 
| Eclipse User  |  |  |  |  | Hi, 
 I am trying to use JET2, on Eclipse 3.4 and am a total JET beginner. I
 have looked quite a lot at the available documentation for my problem,
 read quite a few tutorials and stuff on IBMs and Eclipses website, but I
 haven't yet come across what I'm looking for.
 
 I have no problem creating the JET project, and creating a simple
 template, and running the JET transformation to produce the JET output
 Java files, the "JSP" like compilation stage.
 
 Now I want to execute these Java files which will actually produce my
 actual output text from the template, but I can't seem to do it as I'm
 getting NullPointerExceptions in the JET2InternalPlatform class.
 
 From the stack traces that I'm getting, I'm coming to the conclusion that
 classes that are used in the JET plugin itself are required and really the
 generated code also has to run in the context of the JET2 plugin.
 
 I'm willing to take whatever steps are required to get it to run, but
 ideally what I'd like to be able to do, is run the template
 transformation, then run the produced code assuming it succeeds, if not in
 one fell swoop, then at least just a button click or an Ant task for each
 one assuming everything is configured correctly.
 
 In addition I'd like to be able to have another project share my JET
 project and be able to run the generated Java classes through simply
 configuring their project correctly.
 
 Finally I'd like to be able to deploy it as a standalone app (to run the
 generated code as one app, and to generate the code as another), and
 ideally package it as a plugin that I can then just include as a plugin in
 another app (again both to generate the code, and to run the generated
 code), and everything required to run, including classpaths for building
 and runtime would just get set correctly.
 
 I realise this is asking quite a lot and it's moving into plugin territory
 etc, but even if I could just get to running the generated code, that
 would get me going and be a great start.
 
 My template is simplicity itself...
 
 <%@taglib prefix="ws" id="org.eclipse.jet.workspaceTags" %>
 <%@jet imports="org.eclipse.emf.ecore.*"%>
 
 <c:load url="myModel/model/model.ecore" urlContext="workspace"
 loader="org.eclipse.jet.emf" var="myEcore"/>
 <%
 Object object=context.getVariable("myEcore");
 %>
 <%= object %>
 
 Here is the method in another class I create in the same project I create
 to try and run the generated _jet_transformation class.
 
 static public void methodOne() throws Exception
 {
 String[] jetTransformsToSearch = { "a.b.c"};
 //		final InternalJET2Platform internalJET2Platform=new
 InternalJET2Platform();
 final String templatePath = "templates/main.jet";
 final JET2Context context = new JET2Context(null);
 final BufferedJET2Writer out = new BodyContentWriter();
 JET2TemplateManager.run( jetTransformsToSearch, new
 JET2TemplateManager.ITemplateOperation() {
 public void run(JET2TemplateManager.ITemplateRunner templateRunner) {
 templateRunner.generate( templatePath, context, out );
 }
 });
 // do something with the result
 String output = out.getContent();
 System.out.println(output);
 }
 
 Compiles no problem. But I had to include as external JARs 4 to 5  Eclipse
 core, OSG, and other plugin JARs in the debug configuration Classpath tab
 to get it to run. Then I get...
 
 Exception in thread "main" java.lang.ExceptionInInitializerError
 at  org.eclipse.jet.JET2TemplateManager.run(JET2TemplateManager. java:133)
 at autoSysDirector.JetTest.methodOne(JetTest.java:27)
 at autoSysDirector.JetTest.main(JetTest.java:63)
 Caused by: java.lang.NullPointerException
 at org.eclipse.jet.JET2Platform.<clinit>(JET2Platform.java:76)
 ... 3 more
 
 Now this null is because the plugin member variable of
 InternalJET2Platform is null, I suspect because it's only set when the JET
 code is run as a plugin itself. This of course is required during the
 transformation, but also seems to be required during the execution of the
 generated code.
 
 Below is the line I've commented out above.
 
 final InternalJET2Platform internalJET2Platform=new InternalJET2Platform();
 
 This constructor sets the plugin static attribute to the
 InternalJET2Platform object itself, however, so when I uncomment that and
 include it, I get....
 
 java.lang.NullPointerException
 at
 org.eclipse.jet.internal.runtime.InstalledJETBundleProvider. startup(InstalledJETBundleProvider.java:76)
 at
 org.eclipse.jet.internal.runtime.JETBundleManager.startup(JE TBundleManager.java:296)
 at
 org.eclipse.jet.internal.InternalJET2Platform.checkBundleMan ager(InternalJET2Platform.java:355)
 at
 org.eclipse.jet.internal.InternalJET2Platform.getBundleManag er(InternalJET2Platform.java:489)
 at  org.eclipse.jet.JET2Platform.getJETBundleManager(JET2Platfor m.java:277)
 at  org.eclipse.jet.JET2TemplateManager.run(JET2TemplateManager. java:133)
 at autoSysDirector.JetTest.methodOne(JetTest.java:27)
 at autoSysDirector.JetTest.main(JetTest.java:63)
 
 This will probably go on and on. I think I have to run the transformed
 code itself in the context of the JET plugin.
 
 Any pointers greatly appreciated.
 
 Thx.
 
 
 Paul
 |  |  |  |  | 
| Re: Running the result of a JET transform [message #52883 is a reply to message #52826] | Mon, 03 November 2008 11:57   |  | 
| Eclipse User  |  |  |  |  | Paul: 
 JET2 projects/transformations must run within Eclipse. They depend on not
 only the jet plugin, but also on the Eclipse/OSGi environment being active.
 That means that the simple:
 
 class Main {
 public static void main(String[] args) {
 // do some magic to invoke JET transform
 }
 }
 
 will NOT work, even if you manage to get absolutely every plug-in loaded
 into the classpath.
 
 To run a JET transformation you have a number of possibilities:
 
 1) run it from the Eclipse Run UI.
 a) Click the menu Run > Run Configurations
 b) Select JET Transformation in the left-hand tree, then click the New
 icon
 c) Browse for the file that will serve as input to your transformation.
 d) Select the JET transformation from the ID combo box.
 e) Click Run
 
 2) run it from an ANT script (which is executed by the Eclipse Ant runner)
 via the <jet.transform> ant task.
 
 Details on the JET ant task are here:
 http://help.eclipse.org/ganymede/index.jsp?topic=/org.eclips e.jet.doc/references/ant/antTasks.xhtml
 
 From within Eclipse, you can run an ANT build 'hosted in Eclipse' by
 clicking Run > External Tools > External Tools Configurations. Choose your
 Ant build script, and on the JRE tab, choose 'Run in the same JRE as the
 workspace'.
 
 To run an ANT build headlessly, you need at a minimum an command line like:
 
 eclipse -application org.eclipse.ant.core.antRunner -data
 ....your-ws-location...  ...normal Ant command line options go here...
 
 3) run it from a plug-in (which is itself configured into an Eclipse
 environment) using JET2Platform.runTransformXXX.
 The easiest way to do this would be to:
 a) use the new plug-in wizard, and then use the 'Templates' page of the
 wizard to create a Hello, world plug-in.
 b) In manifest editor for the plug-in, add org.elcipse.jet as a dependency.
 c) Find the action class created by the project wizard, and your call to
 JET2Platform.runXXX.
 
 As for packaging your solution, JET transformations are Eclipse plug-ins.
 They can be packaged as part of a larger solution. For example, the new JET
 project wizard invokes a JET transformation.
 
 As for running outside of Eclipse, I hope to get JET
 transformations/templates to do this in the upcoming Galileo release. But,
 in that case, I expect some loss of functionality, as some JET tags depend
 on Eclipse functionality (the java:* tags, for example).
 
 Paul
 |  |  |  |  |  |  | 
| Re: Running the result of a JET transform [message #52988 is a reply to message #52963] | Fri, 07 November 2008 11:43   |  | 
| Eclipse User  |  |  |  |  | Paul: 
 I'll answer your specific question. But, fundamentally, I don't understand
 what you're trying to achieve. I think if I did, I (and JET) could be of
 much greater use to you.
 
 Answers to your specifc question
 ---------------------------------
 > Where does the output of the top level template main.jet go to?
 
 When running a JET transformation, the main template is run for its side
 effects (i.e. the tags it executes) - the expanded template is currently
 discarded.
 
 If you want to save text to a file, look at the ws:file tag.
 
 If you want to write text to the execution log, take a look at the c:log
 tag.
 
 
 What are you trying to acheive?
 --------------------------------
 This is from a re-reading of your original post. Let's leave JET entirely
 out of the picture, and talk about your goals. From what I see, you want to:
 
 1) Create a tool (I'll call it ToolX) that produces some Java code given
 some parameter(s) From your template, the parameter might an ECore model.
 2) The Java source code created by ToolX (lets call in SourceCodeA) should
 be deployable in stand alone appl.
 3) You want the production of  SourceCodeA and is compilation into is
 compiled from (call it CompileCodeB) to be as automatic as possible.
 4) You want ToolX to be reusable, so that with different inputs, you can get
 SourceCodeB, SourceCodeC, etc....
 5) It is unclear (to me) whether you want ToolX and the compilation of
 SourceCodeA into CompiledCodeB to be deployable as a stand alone
 application.
 
 Now, lets integrate JET and Eclipse back into that picture:
 
 * JET is a tool accomplishing #1, #2 and #4, so long as you are content with
 running ToolX within the Eclipse environment. Regardless of JET being bound
 to Eclipse, it can still produce SourceCodeA that has nothing to do with
 Eclipse.
 * Eclipse is an ideal enviornment for achieving #3. Eclipse Java projects
 automatically (and incrementally) compiled. The invocation of ToolX
 (assuming a JET implementation) can also be automated by introducing a Ant
 builder.
 * As for #5, there would be issues/roadblocks with a JET-based ToolX. But
 then you'd also be faced with all the issues of compiling Java code, and
 successfully loading and executing it. Basing such a stand-alone application
 on OSGi and perhaps the Eclipse JDT (Java development tools) might greatly
 simplify things. And, in that situation, using JET would no longer be an
 issue.
 
 If this is the way you want to go, this is how I would approach creating
 ToolX with JET:
 
 1) Create an example of SourceCodeA. Include all the variations you can
 think ToolX should produce. If you need ant scripts to compile and jar this,
 create those too. While you're doing this, make sure you're using Eclipse
 effectively, too. Name and configure the Eclipse projects the way you'd want
 it: Is the JVM version specified the way you want? What about copyright
 notices, warning levels, etc...? And, how about JUnits to confirm that the
 code works?
 
 2) Start looking at all the files (not just the Java classes) created in #1,
 and look for things would be driven by input to ToolX. This represent
 'points of variability'. You need to relate each point-of-variabililty and
 each file/artifact in #1 to some part of the input you will give to ToolX.
 If you don't already have a 'model' of the input to ToolX, then these points
 of variability and artifacts can serve to drive its development.
 
 3) Once you have a model in place, you can start creating JET templates. An
 easy way is to copy files for #1, and replace the points of variability
 already identified with references to the ToolX's input. You don't
 necessarily want to create a JET template for each file in #1, but you do
 want to account for file is some way. E.g. these .class files are produced
 by the Java compiler; this .java files would all be produced by this one JET
 template; ...
 
 4) Finally, orchestrate the template execution by writing main.jet, which
 would traverse the ToolX input, and fire off the various JET templates using
 ws:file tags.
 
 Does this help?
 
 Paul
 |  |  |  |  | 
| Re: Running the result of a JET transform [message #53405 is a reply to message #52988] | Sun, 23 November 2008 14:36  |  | 
| Eclipse User  |  |  |  |  | Thanks Paul for your help. 
 I've made some headway since, and am up and running. Rather than replying
 straight away, I thought I'd play around a bit more and get more au fait
 with what I can and can't do and then come back to you.
 
 So I'll post again at a future date with a description of how I have it
 working, the ideal scenario, and perhaps some more questions/suggestions.
 
 Paul
 |  |  |  | 
 
 
 Current Time: Fri Oct 31 10:54:16 EDT 2025 
 Powered by FUDForum . Page generated in 0.04567 seconds |