Tuesday, March 3, 2009

Generating Flex HTML Templates with Flex Mojos in Maven

Since I'd managed to reach a base level of comfort with Flex Mojos fairly quickly, we decided to see how hard it would be to extend it the rest of the way. As it turns out, not terrifically difficult.

I wasn't willing to disable the working FlexBuilder-integrated build that would take the results that FlexBuilder would generate from target/bin-release and include it into an assembly, so I took a little time to use a dual-profile approach to setting up the assembly:


<profiles>
<profile>
<id>flex-mojos-assembly</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<build>
<plugins>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<configuration>
<descriptors>
<descriptor>flex-mojos-assembly.xml</descriptor>
</descriptors>
</configuration>
</plugin>
</plugins>
</build>
</profile>

<profile>
<id>flex-builder-assembly</id>
<build>
<plugins>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<configuration>
<descriptors>
<descriptor>flex-builder-assembly.xml</descriptor>
</descriptors>
</configuration>
</plugin>
</plugins>
</build>
</profile>
</profiles>


This gave me the freedom to continue working on integrating Flex Mojos approach without breaking what was already in place, particularly since we haven't thoroughly gone over the SWF that Flex Mojos generates. If I want to build an assembly with the SWF that flex-mojos generates, I simply run the build. If I want to use the release build from FlexBuilder, I run the same build but turn on the flex-builder-assembly profile (which automatically takes the other profile out).

Now, this approach doesn't take Flex Mojos out entirely; it just ignores the results of the flexmojo compilation process if it isn't being used. This is a little wasteful, so I may come back and revisit that approach later. For now, it's a lot less complex than trying to remove the flexmojos integration entirely, which is done through a parent POM approach.

After that, it was a matter of generating the HTML using the local custom html template by adding this to the flex-mojos-assembly profile:


<plugin>
<groupId>info.flex-mojos</groupId>
<artifactId>html-wrapper-mojo</artifactId>
<executions>
<execution>
<goals>
<goal>wrapper</goal>
</goals>
<configuration>
<targetPlayer>9.0.124</targetPlayer>
<templateURI>folder:html-template</templateURI>
<outputDirectory>${project.build.directory}/html-template</outputDirectory>
<parameters>
<bgcolor>#ffffff</bgcolor>
<!-- Defaults Follow -->
<!--
Version comes from 'targetPlayer' or '9.0.0' if no targetPlayer.
<version_major>9</version_major>
<version_minor>0</version_minor>
<version_revision>0</version_revision>
<swf>${project.build.finalName}</swf>
<width>100%</height>
<height>100%</height>
<application>${project.artifactId}</application>
<bgcolor>#869ca7</bgcolor>
-->
</parameters>
</configuration>
</execution>
</executions>
</plugin>


And setting up an assembly descriptor to pull in what I needed from the project structure and the results of the generation:


<assembly>
<id>flex</id>
<formats>
<format>zip</format>
</formats>
<includeBaseDirectory>false</includeBaseDirectory>
<files>
<!-- SWF -->
<file>
<source>${project.build.directory}/${project.build.finalName}.swf</source>
</file>
</files>
<fileSets>
<!-- HTML Template -->
<fileSet>
<directory>target/html-template</directory>
<outputDirectory />
<includes>
<include>**/*</include>
</includes>
</fileSet>
<!-- Project Resources -->
<fileSet>
<directory>src/main/flex</directory>
<outputDirectory />
<includes>
<include>assets/**/*</include>
<include>images/**/*</include>
<include>*.html</include>
<include>*.mp3</include>
</includes>
</fileSet>
</fileSets>
</assembly>


This gives me a final assembly that looks a lot like the assembly the project was already generating. Now to find out if it works the same way ...

1 comment:

Anonymous said...

please can you mark the xml snippets, to indicate in which file they are expected to be.

I could undertand the first XML (profiles..profile..../profiles>) belonged to the ~\,m2\settings.xml)

but not so sure about the other xml snippets

thx