24 julio 2009

maven release version plugin

Para modificar las versiones de los pom.xml y sus hijos:

=======

http://stackoverflow.com/questions/415764/hierarchy-of-maven-projects-without-scattering-the-version-number
I think this approach can be complemented with Maven version plug-in: mojo.codehaus.org/versions-maven-plugin It can increment the parent.version tag in child projects automatically; see versions:update-child-modules goal. – Dan May 13 at 16:38


=======

Versions Maven Plugin




=======

Maven Release Plugin


=======

09 julio 2009

Taylor 1.3.0 - Writing Custom Generators


Writing Custom Generators

From Taylor

Taylor MDA comes with a set of code generation templates. But you may want to write your own templates for any number of reasons:

  • You want to use a different language: Ruby, PHP, .Net, etc
  • You want to use a different framework: Seam vs Spring, JSF vs GWT, etc
  • You simply want the code to generate different
  • Etc...

If you just want to fix a bug you can override a template: Customize Code Templates

The following outlines how to create your own code generator plugin. These are sometime called cartridges.

Contents

[hide]

Plugin Basics

For starters, code generators are just Eclipse plugins, so here is a good primer:

Create Plugin

  1. Start by creating a basic plugin project.
    1. Copy net.taylor.mda.samplegen to get a jump start.
  2. Modify the MANIFEST.MF to match the project name, package and version.
  3. Modify the PLUGIN_ID in the GeneratorPlugin class.
  4. Build the plugin

Here is the basic layout of a plugin:

  • project
    • src
      • net.taylor.mda.mygen.GeneratorPlugin
      • net.taylor.mda.generator.template.*
    • templates
      • main
        • java
        • resources
      • maven
      • test
        • java
        • resources
      • Header.jetinc
    • META-INF
      • MANIFEST.MF
    • plugin.xml
    • build.properties
    • .jetproperties
    • .classpath
    • .project

NOTE: By convention the template directory mimics the structure of the generated code. For example, src/main/java, src/main/resources, src/test/java, src/test/resources

Create Template

If you are new to JET, you will want to review and refer back to these tutorials:

The sample generator plugin contains a sample template.

Use the JET editor (included with taylor) to test the sample template

  • You will need to register it with *.*jet extensions

Here are the highlights of a template:

  • Name template files with an informational extensions such as: *.javajet, *.xmljet, *.xhtmljet
  • The first line of the template defines the class name and the imports.
  • The second line defines the type of UML element that is passed as an argument to the template.
<%@ jet package="net.taylor.mda.generator.template.main.java.sample" class="SampleGen"
imports="org.eclipse.uml2.uml.* java.util.* net.taylor.mda.generator.util.* org.eclipse.emf.codegen.util.*"
%>
<%Model uml2Package = (Model) argument;%>
  • This code handles formatting imports for java code. Imports are adding implicitly based on the UML model. Framework imports are added explicitly as shown below.
<%ImportManager importManager=null;%>
<%if (NameHelper.getQualifiedName(uml2Package) != null) {%>
<%importManager = ImportHelper.makeImportManager(NameHelper.getQualifiedName(uml2Package));%>
<%} else {%>
<%importManager = ImportHelper.makeImportManager("");%>
<%}%>
<%importManager.addImport("java.io.Serializable");%>
<%importManager.addImport("org.jboss.seam.ScopeType");%>
<%importManager.addImport("org.jboss.seam.annotations.Logger");%>
<%importManager.addImport("org.jboss.seam.annotations.Name");%>
<%importManager.addImport("org.jboss.seam.annotations.Observer");%>
<%importManager.addImport("org.jboss.seam.annotations.Scope");%>
<%importManager.addImport("org.jboss.seam.log.Log");%>

<%
StringBuffer importStringBuffer = stringBuffer;
int importInsertionPoint = stringBuffer.length();
importManager.addCompilationUnitImports(stringBuffer.toString());
%>

...

<%importStringBuffer.insert(importInsertionPoint, importManager.computeSortedImports());%>

  • This block shows an example of generating java code.
  • Various helper classes are available in package net.taylor.mda.generator.util.
<%@ include file="../../Header.jetinc"%>
package <%=NameHelper.getQualifiedName(uml2Package)%>;

...

/**
* <%=TypeHelper.getDocumentation(uml2Package)%>
*
* @author <%=System.getProperty("user.name")%>
* @generated
*/
@Name("<%=NameHelper.getUncapName(uml2Package)%>Init")
@Scope(ScopeType.APPLICATION)
public class <%=NameHelper.getCapName(uml2Package)%>Init implements Serializable {

/** @generated */
@Logger
private Log log;

/** @generated */
@Observer("org.jboss.seam.postInitialization")
public void init() throws Exception {
log.info("Starting <%=NameHelper.getCapName(uml2Package)%>Init...");
}
}

Register Template

This is the part that is uniquely Taylor.

Each template is registered in its plugin.xml file using the template extension point. The engine in the Generator plugin uses these extensions to determine which templates to execute and how to render the menus.

                  id="EntityClass"
path="/main/java/entity/EntityClass.javajet"
outputPattern="/src/main/java/{0}/{1}.java"
ifExists="merge"
projectSuffix="jpa"
hasStereotype="javax.persistence.Entity"
modelElement="org.eclipse.uml2.uml.internal.impl.ClassImpl">


  • id - a unique name that will be used to reference this template
  • path - the relative location and name of the template
  • modelElement - what UML type does the template apply to
  • hasStereotype - further restrict matches based on an applied stereotype
  • outputPattern - describes the generated file name and path with substitutions
    • {0} - path based on UML Package
    • {1} - name of UML element
    • {2} - name of parent UML element
    • {3} - fully qualified UML element name with '::' replaced with '-'
    • {4} - lower case model name with '_' replaced with '.'
    • {5} - model name with '_' replaced with '.'
  • ifExists - what to do if the file already exists: merge, skip, backup
  • projectSuffix - files are generated in project named -, a new project is created if it doesn't exist


See the existing template plugins as examples.

Test Template

We already used the JET Editor preview tab to unit test a template. Now we need to test that the template is properly registered.

  1. Run the plug-in project as an Eclipse Application from the tool bar.
  2. Create a test model
  3. Test the Generate menu to verify that you template appears (see Generate Code)
  4. Now Generate and validate the results
  • You will likely want to install the EMF and UML2 SDKs for debugging.
  • The Engine will also log exceptions to the console.
  • Plugging errors will show up in the Eclipse Error Log view.

That is basically it!

The following are some optional topics.

Profiles

Taylor comes with many profiles. However, you may want to create your own for a specific framework or specification.

If you are new to UML Profiles, you will want to review and refer back to this tutorial:

You can reverse engineer a profile from a jar that contains annotations.

  • File > Import > Taylor > Import Java Annotations to UML Profile

Package the profile in a plug-in, such as the one with the templates.

Adding the following extensions to the plugin.xml will automatically add the profile to any new models.

  
source="pathmap://MY_PROFILES/"
target="platform:/plugin/my.plugin.profiles/profiles/">




id="pathmap://MY_PROFILES/my.profile.uml"/>

See plug-in net.taylor.mda.profiles for examples.

Utility Actions

You often need to make mass changes to a model such as spinning through all the elements and adding various stereotypes. This saves time and improves consistency.

This is accomplished using the standard Eclipse action menu mechanism. Package these actions in a plugin along side your templates and profiles.

See the net.taylor.mda.jpagen plug-in for examples.

The following example shows how to register the utilities in a plugin.xml file to be applied to a particular type of UML element.

           point="org.eclipse.ui.navigator.viewer">
viewerId="net.taylor.mda.ModelNavigator">






point="org.eclipse.ui.navigator.navigatorContent">
id="net.taylor.mda.jpagen.actions.AddEnumerationAction"
class="net.taylor.mda.jpagen.actions.AddEnumerationActionExtension">







Taylor 1.3.0-building the plugins

Taylor 1.3.0

Building the plugins


Building the Plug-ins

  1. Start by creating a dedicated workspace.
  2. Then checkout the plug-ins from SVN.
  3. To build the plug-ins right-click on the net.taylor.mda project and select Export>Plug-in Development>Deployable features
  4. Specify a Destination Directory, such as C:\workspaces\build, and press Finish
  5. Copy the features and plugins directories from your build directory to your eclipse directory
  6. Restart Eclipse with the -clean option

Testing the Plug-ins

  1. Follow the steps above to checkout the plug-in projects
  2. Select the net.taylor.mda project
  3. Go to Run>Run As>Eclipse Application or Run>Debug As>Eclipse Application

Optional

  • Install the SDKs for GMF and its dependencies for debugging