Setup Maven and FlexPMD, tune them to use for Flex applications build process automatize/report.
Download Apache Maven 2, setup and register it in system, write proper command file to download and setup all needed FlexPMD. Build, compile and install test project site. Setup FlexPMD plugin and use it for test project reporting.
In big or branched projects with several build conditions it can be usefull to use Maven+FlexPMD link, especially in case project has Java parts and Apache Maven already used in developer's environment. In this recipe we will setup Maven 2 and tune it for use with Flex mojo plugin first and than retune to use FlexPMD plugin. We will build several common case config and bat-files and compile/install simple test project. Hope given schema will be clear enought to give You an ability to build more complecated tasks.
1. So, first step is to download Apache Maven 2 install pack ( from http://www.apache.org/dyn/closer.cgi/maven/binaries/apache-maven-2.2.1-bin.zip ), unpack archive in the folder You've prefer and add environment varables ({maven_folder/bin} to PATH and Java/jdk* as JAVA_HOME if You still haven't it). To be sure everithing done ok run cmd and execute command mvn -help - You should see keys and parameters list.
2.Second step is to setup some Flex Maven plugin and create test project. Create some bat file (I've used testmaven.bat in Maven instalation folder) with commands on it:
mvn archetype:create -DarchetypeArtifactId=maven-archetype-flex -DarchetypeVersion=1.0 -DarchetypeGroupId=dk.jacobve.maven.archetypes -DgroupId=org.epseelon.samples -DartifactId=myMavenPMDBuild
With this bat file we are creating test project in myMavenPMDBuild folder using maven-archetype-flex archetype (to find out more about Maven archetypes read http://maven.apache.org/plugins/maven-archetype-plugin/). Here we will use http://flex-mojos.googlecode.com but this is not the only one - in http://sebastien-arbogast.com/2008/04/11/flex-spring-and-blazeds-the-full-stack-part-2/ You can see example of info.rvin.mojo use. Run created bat file. All needed repositories will be checked and plugins downloaded. Buy architype symple test flex project will be generated - "myMavenPMDBuild" folder with pom.xml file (config) and folder tree with simple Main.mxml file in it. As for me this tree is too complecated - I've moved up Main.mxml to src/main/flex folder.
3. Third step is to change generated pom.xml file to use with our sdk and so on. My test pom.xml looks like:
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.epseelon.samples</groupId>
<artifactId>myMavenPMDBuild</artifactId>
<packaging>swf</packaging>
<version>1.0-SNAPSHOT</version>
<name>myMavenPMDBuild Maven Flex</name>
<url>http://maven.apache.org</url>
<properties>
<flex.home>C:\Program Files (x86)\Adobe\Flex Builder 3\sdks\3.0.0</flex.home>
</properties>
<pluginRepositories>
<pluginRepository>
<id>flex-mojos-repository</id>
<url>http://flex-mojos.googlecode.com/svn/trunk/repository/</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>false</enabled>
</snapshots>
</pluginRepository>
<pluginRepository>
<id>epseelon-repository</id>
<url>http://m2repo.epseelon.org/</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>false</enabled>
</snapshots>
</pluginRepository>
</pluginRepositories>
<build>
<sourceDirectory>src\main\flex</sourceDirectory>
<plugins>
<plugin>
<groupId>net.israfil.mojo</groupId>
<artifactId>maven-flex2-plugin</artifactId>
<extensions>true</extensions>
<configuration>
<flexHome>${flex.home}</flexHome>
<useNetwork>true</useNetwork>
<main>Main.mxml</main>
</configuration>
</plugin>
</plugins>
<defaultGoal>install</defaultGoal>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>2.0</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<version>2.2-beta-2</version>
</plugin>
</plugins>
</pluginManagement>
</build>
</project>
With cmd move to myMavenPMDBuild folder and execute command mvn compile. After successfull build "target" folder with swf file in it will be generated.
4. So, now our project can be build with Maven. It's time for FlexPMD to appear on the stage. We will use Maven plugin (http://opensource.adobe.com/svn/opensource/flexpmd/maven-repository/release/com/adobe/ac/flex-pmd-maven-plugin/) from adobe opensource. For this perpose we need to change pom.xml file for use FlexPMD plugin instead the mojo. Add into repository plugin section following code:
<pluginRepositories>
<pluginRepository>
<id>flexpmd.opensource.adobe</id>
<releases>
<enabled>false</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
<name>FlexPMD repository on opensource.adobe.com</name>
<url>http://opensource.adobe.com/svn/opensource/flexpmd/maven-repository/release/</url>
</pluginRepository>
</pluginRepositories>
<reporting>
<plugins>
<plugin>
<groupId>com.adobe.ac</groupId>
<artifactId>flex-pmd-maven-plugin</artifactId>
<version>1.0.RC3</version>
</plugin>
</plugins>
</reporting>
Execute mvn compile command from command line being in our project folder. All needed jars and so on will be downloaded. After project build (execute mvn compile, mvn install and mvn site commands successfully) in output folder (near generated swf file) pmd.xml file will be added with violationd found for our test project.
To use this approache in Your real project tune Maven pom.xml file ( <groupId>,<artifactId>,<packaging> and <build> sections) in accordance to project data and location. Execute mvn compile to generate report for project.
To find out more about report data visualization and interpritation visit http://opensource.adobe.com/wiki/display/flexpmd/How+to+interpret+results or go to http://opensource.adobe.com/svn/opensource/flexpmd/bin/flex-pmd-violations-viewer.html for free online visualization tool use. On http://opensource.adobe.com/svn/opensource/flexpmd/bin/flex-pmd-ruleset-creator.html You can find a tool for rulsets creation.
to be continued... please do not rate this post for a while it's under construction - some repository servers are down now...