Generator Mojo

Hi folks!!

On Flex we have several ways to integrate java-server and flex-client. My favorite is using RemoteObjects and/or Dataservices.

Using this, we have typed communication, but, it mean you must have the same DTO (Data Transfer Object or ValueObject or Pojo or whatever you use) on both side. That mean 2 sources files with same data.

Its common one side goes out-to-date. One good policy is write one side DTO and generate other. Is exactly that what Granite GAS3 Generator does.

Gas 3 is a AntTask to generate .as files based on .java files.

In other to get this behavior on flex-mojos I use Gas3’s generator on flex-mojos.

It works on a similar way. But it doesn’t run over a java project, it runs on a flex project.

There is a sample here.

The steps to get code generation are simple:
1 - Add generator mojo goal to your pom:

<plugin>
<groupId>info.rvin.mojo</groupId>
<artifactId>generator-mojo</artifactId>
<executions>
<execution>
<goals>
<goal>generate</goal>
</goals>
</execution>
</executions>
</plugin>

2 - Add a jar dependency, who contains Java DTO classes:

<dependency>
<groupId>info.rvin.itest</groupId>
<artifactId>generator-jar</artifactId>
<version>1.0-SNAPSHOT</version>
<type>jar</type>
</dependency>

All jar dependencies will be loaded at runtime. To filter what classes to generate use includeClasses/excludeClasses configuration.

3 - Update sourcePath:

<plugin>
<groupId>info.rvin.mojo</groupId>
<artifactId>flex-compiler-mojo</artifactId>
<configuration>
<sourcePaths>
<path>${project.build.sourceDirectory}</path>
<path>${project.build.directory}/generated-sources</path>
</sourcePaths>
</configuration>
</plugin>

4 - Compile your project.

Its the first release, and this project was only used on sample projects, so bugs are expected, please, don’t delete your .as DTOs, at least not now.

At this moment, it generate the sources with GAS3 style. But, I create this mojo with different styles in mind. Still, you can configure your custom template.

Well, I hope everyone enjoins it.

VELO

5 Responses to “Generator Mojo”

  1. Trying to use the flex mojo generator in a project. I must have it configured incorrectly. This is what I have configured so far.

    info.rvin.mojo
    generator-mojo

    generate

    com/relayhealth/payerhosting/model/Customer.class
    com.relayhealth.payerhosting.model.Customer.class

    com.relayhealth.payerhosting
    ph-core
    1.0-SNAPSHOT

    The output is
    [INFO] [generator-mojo:generate {execution: default}]
    [INFO] 0 files generated.

    As you can see I am trying to compile a single class in the dependent jar. I have not been successful in compiling and java classes yet. I have the granite ds GAS compiler working fine though.

    Any ideas?

  2. I spent a few hours on the same problem, eventually I debugged the code.

    The default include filter has been set to *.class and should be set to * in this mojo.

    You can override the include filters and that will make it work:

    see example:

    generate

    framework*Impl

    *DaoImpl

  3. <plugin>
    <groupId>info.rvin.mojo</groupId>
    <artifactId>generator-mojo</artifactId>
    <version>1.0-beta1</version>
    <executions>
    <execution>
    <goals>
    <goal>generate</goal>
    </goals>
    <configuration>
    <includeClasses>
    <param>framework*Impl</param>
    </includeClasses>
    <excludeClasses>
    <param>*DaoImpl</param>
    </excludeClasses>
    </configuration>
    </execution>
    </executions>
    </plugin>

  4. For the compilation phase I need to change the following:

    \src\main\java folder must exist

    Configuration must have the base class in
    <configuration>
    <includeSources>
    <path>${project.build.sourceDirectory}</path>
    <path>${project.build.directory}/generated-sources/flex-mojos</path>
    </includeSources>
    <sourcePaths>
    <path>${project.build.sourceDirectory}</path>
    <path>${project.build.directory}/generated-sources/flex-mojos</path>
    </sourcePaths>

    Framework libraries must be referenced
    <dependency>
    <groupId>com.adobe.flex.sdk</groupId>
    <artifactId>playerglobal</artifactId>
    <version>3.0.0.3.0.0.477</version>
    <type>swc</type>
    <scope>external</scope>
    </dependency>
    <dependency>
    <groupId>com.adobe.flex.sdk</groupId>
    <artifactId>flex</artifactId>
    <version>3.0.0.3.0.0.477</version>
    <type>swc</type>
    <scope>compile</scope>
    </dependency>
    <dependency>
    <groupId>com.adobe.flex.sdk</groupId>
    <artifactId>framework</artifactId>
    <version>3.0.0.3.0.0.477</version>
    <type>swc</type>
    <scope>compile</scope>
    </dependency>
    <dependency>
    <groupId>com.adobe.flex.sdk</groupId>
    <artifactId>framework</artifactId>
    <version>3.0.0.3.0.0.477</version>
    <type>resource-bundle</type>
    <classifier>en_US</classifier>
    <scope>compile</scope>
    </dependency>
    <dependency>
    <groupId>com.adobe.flex.sdk</groupId>
    <artifactId>rpc</artifactId>
    <version>3.0.0.3.0.0.477</version>
    <type>swc</type>
    <scope>compile</scope>
    </dependency>
    <dependency>
    <groupId>com.adobe.flex.sdk</groupId>
    <artifactId>rpc</artifactId>
    <version>3.0.0.3.0.0.477</version>
    <type>resource-bundle</type>
    <classifier>en_US</classifier>
    <scope>compile</scope>
    </dependency>
    <dependency>
    <groupId>com.adobe.flex.sdk</groupId>
    <artifactId>utilities</artifactId>
    <version>3.0.0.3.0.0.477</version>
    <type>swc</type>
    <scope>compile</scope>
    </dependency>

  5. To make it easier you could use flex-super-pom. You can read a old description of it here:
    http://blog.flex-mojos.info/2008/03/29/alpha-4-out-with-news/

    VELO

Discussion Area - Leave a Comment