29
Mar

Installing Flex SDK into maven repository

The past week I needed to mavenize one of my Flex projects and compile it with a Flex SDK 4.1.0 versions. Since the public repoo only offers the latest stable build of Flex SDK ( which is normal ), I found myself in the position to install the SDK into a custom repository.

To do so I had to dig the web a bit and I found some documentation provided by sonatype. According to sonatype, “The descriptors used by Flexmojos to publish Flex SDK aren’t public available and won’t be provided. The goal is to really make this process hard.” I got no problem with this limitation but that wouldn’t fulfill my need though.

To solve this, I followed one of the Agile principles, that is “to do the simplest thing that could possible work”.  To me, this got translated into some shell scripts.

I looked inside the pom files of a previous SDK that was installed in my local repo, and I tried to replicate it for a newer SDK. I had to take every dependency and install it with

mvn install:install-file

The result I eneded up with looks similar to:

install-flex-sdk /path/to/unzipped/sdk SDK_VERSION

If you want to use it, I’ve shared a ZIP file containing the script and the necessary files needed to install the Flex SDK into a local maven repository. You can download it here.

Prior to installing the SDK you need to, of course, go to opensource.adobe.com site, download and unzip the SDK. You can also use “wget” to download the SDK and you could even include it into the shell script. The reason I didn’t do it, is because you need to agree to the SDK’s “Terms and Conditions” prior to downloading the SDK.

After downloading the SDK, I had to issue this command:

./install-flex-sdk.sh /KITS/PROGRAMMING/ADOBE/Flex_SDK/flex_sdk_4.1.0.16076/ 4.1.0.16076

generating the following output ( I truncated it to show just the first lines ) :

---------------------------------
INSTALLING COMPILER
---------------------------------
---------------------------------
GENERATING: compiler pom
---------------------------------
Executing: sed 's/${SDK_VERSION}/4.1.0.16076/g' compiler.pom.template >> compiler.pom
---------------------------------
INSTALLING: compiler pom
---------------------------------
[INFO] Scanning for projects...
[INFO] Searching repository for plugin with prefix: 'install'.
[INFO] ------------------------------------------------------------------------
[INFO] Building Maven Default Project
[INFO]    task-segment: [install:install-file] (aggregator-style)
[INFO] ------------------------------------------------------------------------
[INFO] [install:install-file]
[INFO] Installing /KITS/PROGRAMMING/ADOBE/Flex_SDK/Maven_deployer/compiler.pom to /Users/dragos/.m2/repository/com/adobe/flex/compiler/4.1.0.16076/compiler-4.1.0.16076.pom
[INFO] Creating Checksums...
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESSFUL
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 1 second
[INFO] Finished at: Mon Mar 29 15:29:38 EEST 2010
[INFO] Final Memory: 5M/125M
[INFO] ------------------------------------------------------------------------
---------------------------------------------------
Installing artifact=adt form file=/KITS/PROGRAMMING/ADOBE/Flex_SDK/flex_sdk_4.1.0.16076//lib/adt.jar packaging=jar  ...

After installing the SDK into the local repository I had to find a way to expose it to Nexus, because I wanted other developers to be able to run the maven build successfully. Installing the SDK with the script I provided, it installs only into the local repository of the user, but Nexus runs an o a different user usually, having its own repository. If you don’t link the SDK you installed with Nexus, other developers won’t be able to run the build successfully. Fortunately, this process is pretty easy once you know that you need to do that. Simply issue a copy command, to copy your ~/.m2/repository/com/adobe/flex into the Nexus repository.

In my case I had to do:

cp -r ~/.m2/repository/com/adobe/flex/* /usr/share/tomcat5/sonatype-work/nexus/storage/MY_CUSTOM_LOCAL_REPOSITORY/

Installing into a custom repository, enforces you to let the pom.xml know where to look for dependencies. So don’t forget to add the url to your repository in the pom.xml files or in the settings.xml file. I won’t describe the process in this post but you can ask me if you don’t know how.

Where to go from here:

10
Mar

Flex4 ModuleLoader and Runtime Skins

Recently I’ve been trying to load a Module into a basic flex application and I hit a roadblock when dispalying them into the UI. Even though the styles were loaded correctly, the modules didn’t look properly.

Narrowing down the problem I realized that the difference is made by the code below:

var moduleLoader : ModuleLoader = new ModuleLoader();
moduleLoader.applicationDomain = ApplicationDomain.currentDomain;
addElement( moduleLoader );
moduleLoader.loadModule( "MyModule.swf" );

and

var moduleLoader2 : ModuleLoader = new ModuleLoader();
moduleLoader2.applicationDomain = ApplicationDomain.currentDomain;
moduleLoader2.addEventListener( ModuleEvent.READY , moduleLoader_readyHandler );
moduleLoader2.loadModule( "MyModule.swf" );
 
protected function moduleLoader_readyHandler( event : ModuleEvent ) : void
{
     addElement( IVisualElement( ModuleLoader( event.currentTarget ) ) );
}

In this last code, I wait until the module gets properly loaded and then I’m adding it to the display list.

In the first code, I’m adding the moduleLoader form the start, even before calling its load method.

The first code example is the one that works, and the last code example it doesn’t work. I don’t know how to explain this behavior, but according to my tests, if you add the moduleLoader to the display list, before loading the module itself, the styles are applied correctly. Otherwise, the loaded modules won’t have them applied.

Loading modules at runtime it’s a powerful feature, and at the same time, you have to use it carefully because it can lead to memory leaks. This post describes more about what the issues are, and how to avoid them.