Showing posts with label flex. Show all posts
Showing posts with label flex. Show all posts

Monday, July 6, 2009

Fixing Hessian Flex 3.2.0 References

If you're using Hessian Flex 3.2.0 and you'd like to fix the problem with references, the following one-line fix seems to do the job for me:


$ svn diff
Index: src/main/flex/hessian/io/Hessian2Input.as
===================================================================
--- src/main/flex/hessian/io/Hessian2Input.as (revision 1172)
+++ src/main/flex/hessian/io/Hessian2Input.as (working copy)
@@ -129,9 +129,10 @@
public override function init(di:IDataInput):void
{
_di = di;
_buffer = new ByteArray();
_offset = 0;
_length = 0;
+ _refs = null;
}


Basically, HessianOperation hangs on to a Hessian2Input class between invocations, and calls init() to clear out the state before using the class for another invocation. The init() doesn't currently clear the reference cache. By setting _refs to null, you clear the cache and Hessian2Input will simply instantiate a new array in its place if and when it needs to do so.

Thursday, June 25, 2009

Flex Builder 3 on Eclipse 3.5 (Gallileo) on OS X?

I spent a little time this morning trying to get FlexBuilder 3 up and running in Eclipse 3.5 (Gallileo). A little experimentation and reading implied that getting it up in the Cocoa version of Eclipse wasn't going to happen.

I then tried a few more times with Eclipse 3.5 carbon, and still wasn't able to get it working. So if you've managed to get FlexBuilder 3.X up and running on Eclipse 3.5 on OS X, I'd be happy to hear more.

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.