<html><head></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; ">Hi Rafael,<div><br></div><div>What do you mean by clone and forge the project? On github you can just clone the plugin-arquillian project and start hacking on it.</div><div>Formatting is a bit of a problem, that doesn't work very well now with the builder API. Maybe Lincoln can say more about that?</div><div><br></div><div>Note that within a few weeks Forge will have a new scaffolding plugin built-in, that does basically something that you are doing in your plugin.&nbsp;</div><div><br></div><div>Paul</div><div><br><div><div>On Oct 23, 2011, at 3:45 PM, Rafael Pestano wrote:</div><br class="Apple-interchange-newline"><blockquote type="cite">I've managed to clone forge repo with this address <a href="https://github.com/forge/core.git" target="_blank">https://github.com/forge/core.git</a> now, i was using the old <a>github.com/seam/forge.git</a>.<br><br><div class="gmail_quote">

<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;"><div><div class="h5"><div class="gmail_quote">2011/10/23 Rafael Pestano <span dir="ltr">&lt;<a href="mailto:rmpestano@gmail.com" target="_blank">rmpestano@gmail.com</a>&gt;</span><br>

<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Hello Paul, thanks for your enlightening reply.<br><br>The plugin is about a code generator for a home made Java EE6 framework and for instance it will generate very simple xhtml and java classes, so for example the generate-controller plugin would generate&nbsp; <br>




<br><i>@ViewAccessScoped<br>@Named("personMBean")<br>public class PersonMBean extends AbstractBaseMBean&lt;Person&gt; implements Serializable, ModalObserver {<br>&nbsp;&nbsp;&nbsp; <br>&nbsp;&nbsp; @Inject<br>&nbsp;&nbsp;&nbsp; public void setPersonService(PersonService personService) {</i>//service layer will be generated togheter<i><br>




&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; super.setBaseService(personService);<br>&nbsp;&nbsp;&nbsp; }<br><br>some other very simple methods<br>}</i><br><br>for the controller-plugin maybe i dont need to understand the model class (just to import it) cause its just a matter of replacing parammeters by the domain object but in the view-plugin it will be necessary for sure.<br>



<br>Another concern i have is how to format the generated code? maybe the velocity template could help on that.<br>
<br>Ive seen the Arquillian example, how can i clone it and forge project?<br><br>Thanks again!<div><div><br><br>&nbsp;<br><br><div class="gmail_quote">2011/10/23 Paul Bakker <span dir="ltr">&lt;<a href="mailto:paul.bakker.nl@gmail.com" target="_blank">paul.bakker.nl@gmail.com</a>&gt;</span><br>



<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div style="word-wrap:break-word"><div>Hi Rafael,</div><div><br></div>There are two things you need to do:<div>1) "understand" the Person class</div><div>2) generate new code</div><div><br></div><div><br></div>



<div>
1)</div><div>You can use a command parameter to get the Person class:&nbsp;@Option(name = "class", required = true, type = PromptType.JAVA_CLASS) JavaResource classUnderTest</div><div><br></div><div>JavaResource is a rich file representation of the class.&nbsp;</div>




<div>Now you can use the JavaSourceFacet to get information about the class itself:</div><div><div><br></div><div>JavaSourceFacet java = project.getFacet(JavaSourceFacet.class);</div><div>JavaSource&lt;?&gt; javaSource = classUnderTest.getJavaSource();</div>




</div><div><br></div><div>javaSource has methods such as getPackage() etc.</div><div><br></div><div>2)</div><div>Now you have to generate code. There are two ways to do this, depending on your needs.</div><div>The most elegant way is to use the "JavaParser" builder API:</div>




<div><br></div><div><div>JavaClass javaClass = JavaParser.create(JavaClass.class)</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;.setPackage(entityPackage)</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;.setName(entityName)</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;.setPublic()</div>




<div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;.addAnnotation(Entity.class).getOrigin()</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;.addInterface(Serializable.class);</div></div><div>Field&lt;JavaClass&gt; id = javaClass.addField("private Long id = null;");&nbsp;</div>




<div>….</div><div><br></div><div>My experience is that this works best for small classes. If you need to generate a lot of code it might be better to use a tempting framework such as Apache Velocity.</div><div>You can find an example of this in the code of the Arquillian plugin:&nbsp;<a href="https://github.com/forge/plugin-arquillian/blob/master/src/main/java/org/jboss/seam/forge/arquillian/ArquillianPlugin.java#L93" target="_blank">https://github.com/forge/plugin-arquillian/blob/master/src/main/java/org/jboss/seam/forge/arquillian/ArquillianPlugin.java#L93</a></div>




<div><br></div><div>You can just add Velocity to your pom file and it will work.</div><div><br></div><div>If you have any more questions, let us know! What kind of plugin are you writing?</div><div><br></div><div>Paul Bakker</div>




<div><br></div><div><br><div><div><div><div><div>On Oct 23, 2011, at 2:26 AM, Rafael Pestano wrote:</div><br></div></div><blockquote type="cite"><div><div>Hi everyone,<br><br>this is my first mail to this list and id like to <span lang="en"><span>congratulate the Forge team</span></span> for their work.<br>




<br>my question is, what's the best way to generate .java, .xhtml files with forge?<br>

<br>Id like to write a plugin which would receive an entity class as parameter and generate some code on top of it, eg:<br><br><code>$ generate-service Person</code><br><code>$ generate-controller Person</code><br>

<code>$ </code><code>generate-view</code> <code>Person</code><br><br><br>Where Person is a domain object, is it possible with Forge? if yes, whats the best way?<br>

<br><br>thanks in advance.<br><br><br><br clear="all"><br>-- <br><a href="http://www.advancedit.com.br/" target="_blank"><span style="color:black;text-decoration:none"></span></a><span></span><span><span style="color:rgb(192, 192, 192)">Att, </span><br style="color:rgb(192, 192, 192)">






<br style="color:rgb(192, 192, 192)"><span style="color:rgb(192, 192, 192)">Rafael M. Pestano</span><br style="color:rgb(192, 192, 192)"><br style="color:rgb(192, 192, 192)"><span style="color:rgb(192, 192, 192)">Desenvolvedor Java Cia. de Processamento de Dados do Rio Grande do Sul</span><br style="color:rgb(192, 192, 192)">






<span style="color:rgb(192, 192, 192)">Graduando em Ciência da Computação UFRGS</span></span><br></div></div>
_______________________________________________<br>forge-dev mailing list<br><a href="mailto:forge-dev@lists.jboss.org" target="_blank">forge-dev@lists.jboss.org</a><br><a href="https://lists.jboss.org/mailman/listinfo/forge-dev" target="_blank">https://lists.jboss.org/mailman/listinfo/forge-dev</a><br>




</blockquote></div><br></div></div></div></blockquote></div><br><br clear="all"><br>-- <br><a href="http://www.advancedit.com.br/" target="_blank"><span style="color:black;text-decoration:none"></span></a><span></span><span><span style="color:rgb(192, 192, 192)">Att, </span><br style="color:rgb(192, 192, 192)">




<br style="color:rgb(192, 192, 192)"><span style="color:rgb(192, 192, 192)">Rafael M. Pestano</span><br style="color:rgb(192, 192, 192)"><br style="color:rgb(192, 192, 192)"><span style="color:rgb(192, 192, 192)">Desenvolvedor Java Cia. de Processamento de Dados do Rio Grande do Sul</span><br style="color:rgb(192, 192, 192)">




<span style="color:rgb(192, 192, 192)">Graduando em Ciência da Computação UFRGS</span></span><br>
</div></div></blockquote></div><br><br clear="all"><br>-- <br><a href="http://www.advancedit.com.br/" target="_blank"><span style="color:black;text-decoration:none"></span></a><span></span><span><span style="color:rgb(192, 192, 192)">Att, </span><br style="color:rgb(192, 192, 192)">


<br style="color:rgb(192, 192, 192)"><span style="color:rgb(192, 192, 192)">Rafael M. Pestano</span><br style="color:rgb(192, 192, 192)"><br style="color:rgb(192, 192, 192)"><span style="color:rgb(192, 192, 192)">Desenvolvedor Java Cia. de Processamento de Dados do Rio Grande do Sul</span><br style="color:rgb(192, 192, 192)">


<span style="color:rgb(192, 192, 192)">Graduando em Ciência da Computação UFRGS</span></span><br>
</div></div></blockquote><br></div><br><br clear="all"><br>-- <br><a href="http://www.advancedit.com.br/" target="_blank"><span style="color:black;text-decoration:none"></span></a><span></span><span><span style="color:rgb(192, 192, 192)">Att, </span><br style="color:rgb(192, 192, 192)">

<br style="color:rgb(192, 192, 192)"><span style="color:rgb(192, 192, 192)">Rafael M. Pestano</span><br style="color:rgb(192, 192, 192)"><br style="color:rgb(192, 192, 192)"><span style="color:rgb(192, 192, 192)">Desenvolvedor Java Cia. de Processamento de Dados do Rio Grande do Sul</span><br style="color:rgb(192, 192, 192)">

<span style="color:rgb(192, 192, 192)">Graduando em Ciência da Computação UFRGS</span></span><br>
_______________________________________________<br>forge-dev mailing list<br><a href="mailto:forge-dev@lists.jboss.org">forge-dev@lists.jboss.org</a><br>https://lists.jboss.org/mailman/listinfo/forge-dev<br></blockquote></div><br></div></body></html>