Wednesday, March 4, 2009

First Month as an Apple User: *%@#&$

So, on 09-Feb at 9am, I placed an order for a MacBook Pro 15".

There were a few delays in shipping the order, but it finally shipped on 14-Feb and I got it on the 17th. A little slow, but no big deal. I spent the week setting it up so that it would be ready for personal use and contract work.

On Friday (20th), the ethernet port suddenly died altogether. Wifi was still working, so I signed up for the Genius Bar Monday morning, then took it home. I tried it with some more networking equipment over the weekend to make sure the problem was the laptop, but sadly nothing worked.

On monday (23rd) the Genius Bar agreed that the ethernet port was dead, and suggested I send it back for a replacement. The joy of getting a custom-configured machine from apple (more RAM, faster HD) is that instead of doing a quick in-store exchange, they can make you wait for another few days. I returned it the next day after getting their RMA form, and they processed the return.

The order status updated to show the return processed on the 25th, and I began to wait some more. By 01-Mar, I was starting my new contract, without a good machine to do it on, which was really irritating. On 02-Mar, Apple updated their processor lineup. I checked my order status again and noticed that I was getting the 2.66GHz update, but that my hard drive was downgraded to the 5400 rpm.

After another half-hour with support, I'm back to a 7200rpm hard drive, and I've learned that the hold on the replacement laptop was never released after I returned the original, so I've been waiting for no reason. The hold is now released, and now, sometime over a month after I ordered it, I may receive a working laptop.

So far, my user experience as an Apple convert isn't working out all that well. The apple support people are nice enough, but the fact that I've had to call them several times in the first month of ownership, most of which I've spent without an actual Apple is really starting to piss me off.

This had better be the last hangup.

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 ...

Building Flex with Maven and Flex Mojos

I've been getting to know a project that uses Maven and Flex.  The flex portion of the project is currently built using FlexBuilder, and it seemed worth investigating whether or not buildng the Flex using Maven were feasible.


I took a look around at the options, and it seems like the Flex-Mojos project is the one with the most momentum.  It's relatively current, gets updated regularly, and the team seems to be working with Sonatype, well-known in the Maven community.

The Flex Mojos project is still pretty rough in some areas.  In order to get things done, you need to search the blog, the google group, the google code home and the newer wiki and source code repository hosted at Sonatype, as well as the plugin documentation.  I'm hoping that with a little more time, the documentation will start to coalesce in a single location and get better, although sparse documentation is par for the course when it comes to Maven plugins.

With a little work, I was able to get the project to build an SWF file:


<parent>
<groupid>info.flex-mojos</groupid>
<artifactid>flex-super-pom</artifactid>
<version>2.0</version>
</parent>

<repositories>
<repository>
<id>flex-mojos-repository</id>
<url>http://svn.sonatype.org/flexmojos/repository</url>
<releases><enabled>true</enabled></releases>
<snapshots><enabled>false</enabled></snapshots>
</repository>
</repositories>

<build>
<plugins>

<plugin>
<groupid>info.flex-mojos</groupid>
<artifactid>flex-compiler-mojo</artifactid>
<configuration>
<sourcefile>CrystalQ2.mxml</sourcefile>
</configuration>
</plugin>

</plugins>
</build>

I also needed to declare a dependency on the SWC library on which the project depended:


<dependencies>
<dependency>
<groupid>com.caucho</groupid>
<artifactid>hessian-flex</artifactid>
<version>3.2.0</version>
<type>swc</type>
</dependency>
</dependencies>
There's still other things I'd need to do to mimic what Flex Builder offers, such as generate an HTML Wrapper and copy assets needed by the final application but not included in the SWF.
That said, I'd say that the basics are already in place and I'm starting to feel comfortable that there are options for putting Flex and Maven together, should you so desire.