使用和研究flex项目可持续集成有一段时间了,现重新做一下总结。
主要相关软件版本:
flashbuilder 4.5 + flex sdk 4.5 + maven 2.2.1 + flexmojos 3.8 + mercurial 1.7.2 + hudson 2.0.1
Flex项目可持续集成方案在centos 5.6 i386下实现,需要安装的软件主要如下:
hudson-2.0.1
apache-maven-2.2.1
flexmojos-3.8
mercurial1.7.2
java-1.6.0-openjdk
flashplayer 10.3 (debug version)
maven相关插件及依赖库版本:
flexmojos-maven-plugin:https://repository.sonatype.org/content/sites/flexmojos-site/3.8/
compiler:https://repository.sonatype.org/content/groups/flexgroup/com/adobe/flex/compiler/4.5.0.19786/
flex-framework:https://repository.sonatype.org/content/groups/flexgroup/com/adobe/flex/framework/flex-framework/4.5.0.19786/
flexunit:http://www.flashnexus.org/nexus/content/groups/public/com/adobe/flexunit/flexunit/4.1.0-beta3/
相关文件及目录
源码目录: /data/source/InstantForge/Pugna/
hudson安装目录: /usr/lib/hudson/hudson.war
maven: /home/xjimmy/apache-maven-2.2.1/
flashplayer: /usr/bin/flashplayer
xvfb-run脚本: /usr/bin/xvfb-run
一、环境准备
cd /home/xjimmy
【安装java】
yum install java-1.6.0-openjdk #install jre
yum install java-1.6.0-openjdk-devel #install jdk
java -version
java version "1.6.0_20"
【安装mercurial(hg)】
yum install mercurial
hg --version
分布式软件配置管理工具 - 水银 (版本 1.7.2)
【下载hudson,maven,flashplayer】
wget http://www.apache.org/dyn/closer.cgi/maven/binaries/apache-maven-2.2.1-bin.tar.gz
wget http://download.macromedia.com/pub/flashplayer/updaters/10/flashplayer_10_sa_debug.tar.gz
【maven安装】
tar xzvf apache-maven-2.2.1-bin.tar.gz
#解开即可
【flashplayer安装】
tar xzvf flashplayer_10_sa_debug.tar.gz
flashplayerdebugger
cp flashplayerdebugger /usr/bin/flashplayer
【自启动脚本中加入环境变量】
vi /etc/profile
#加入如下内容
export JAVA_HOME=/usr/lib/jvm/java
export M2_HOME=/home/xjimmy/apache-maven-2.2.1
export PATH=$M2_HOME/bin:$PATH
export MAVEN_OPTS="-Djava.awt.headless=true"
【重新ssh登录,使环境变量生效】
二、Flex项目与maven整合
方法1、使用mvn创建flex 项目框架
mvn -v
Apache Maven 2.2.1 (r801777; 2009-08-07 03:16:01+0800)
Java version: 1.6.0_20
Java home: /usr/lib/jvm/java-1.6.0-openjdk-1.6.0.0/jre
Default locale: en_US, platform encoding: UTF-8
OS name: "linux" version: "2.6.18-238.el5" arch: "i386" Family: "unix"
#选择合适的flexmojos-maven-plugin版本呢,如3.8,参考一下网站
http://repo1.maven.org/maven2/org/sonatype/flexmojos/flexmojos-maven-plugin/
或
https://repository.sonatype.org/content/sites/flexmojos-site
【生成application项目框架】
mvn archetype:generate -DarchetypeRepository=http://repository.sonatype.org/content/groups/flexgroup -DarchetypeGroupId=org.sonatype.flexmojos -DarchetypeArtifactId=flexmojos-archetypes-application -DarchetypeVersion=3.8
安装时,设置groupId和artifactId分别改为INiT.Instant.Forge 、 Pugna 其它默认。
【初始目录结构】
[root@instant_redmine apache-maven-2.2.1]# tree Pugna
Pugna
`—swf
|-- pom.xml
`—src
`—main
`—flex
`-- Main.mxml
方法2:现有的Flex项目中加入pom.xml文件
在项目源码/opt/source/InstantForge/Pugna目录下加入pom.xml
pom.xml是maven的配置文件,每个项目需要一个。
本项目采用方法2。
【添加本地swc库文件到maven资料库】
mvn install:install-file -Dfile=./libs/as3corelib-flex-4.5.swc -DgroupId=INiT.Instant.Forge -DartifactId=as3corelib-flex -Dversion=4.5 -Dpackaging=swc
mvn install:install-file -Dfile=./libs/cmawslib-flex-4.5.swc -DgroupId=INiT.Instant.Forge -DartifactId=cmawslib-flex -Dversion=4.5 -Dpackaging=swc
mvn install:install-file -Dfile=./libs/flexlib-flex4-2.5.swc -DgroupId=INiT.Instant.Forge -DartifactId=flexlib-flex4 -Dversion=2.5 -Dpackaging=swc
mvn install:install-file -Dfile=./libs/parsley-flex4-2.4.0.swc -DgroupId=INiT.Instant.Forge -DartifactId=parsley-flex4 -Dversion=2.4.0 -Dpackaging=swc
mvn install:install-file -Dfile=./libs/spicelib-flex-2.4.0.swc -DgroupId=INiT.Instant.Forge -DartifactId=spicelib-flex -Dversion=2.4.0 -Dpackaging=swc
最关键部分:pom.xml文件配置
修改/opt/source/InstantForge/Pugna下的添加pom.xml文件(maven配置文件) flex sdk4.5 + 国际化支持
#内容如下:
#主要信息: project info, repositories,build(src,test,compiler,flashbuilder,flashplayer,locales),
# library(flex-framework,flexunit,as3corelib,cmawslib,flexlib,parsley,spicelib)
<?xml version="1.0" encoding="UTF-8"?>
<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>INiT.Instant.Forge</groupId>
<artifactId>Pugna</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>swf</packaging>
<name>Pugna Flex</name>
<repositories>
<repository>
<id>flex-mojos-repository</id>
<name>sonatype</name>
<url>http://repository.sonatype.org/content/groups/flexgroup</url>
</repository>
<repository>
<id>flex-mojos-internal-repository</id>
<url>http://repository.sonatype.org/content/groups/public</url>
</repository>
<repository>
<id>flash-nexus-repository</id>
<url>http://www.flashnexus.org/nexus/content/groups/public</url>
</repository>
</repositories>
<build>
<sourceDirectory>src</sourceDirectory>
<testSourceDirectory>test</testSourceDirectory>
<plugins>
<plugin>
<groupId>org.sonatype.flexmojos</groupId>
<artifactId>flexmojos-maven-plugin</artifactId>
<version>3.8</version>
<dependencies>
<dependency>
<groupId>com.adobe.flex</groupId>
<artifactId>compiler</artifactId>
<version>4.5.0.19786</version>
<type>pom</type>
</dependency>
</dependencies>
<extensions>true</extensions>
<configuration>
<targetPlayer>10.2.0</targetPlayer>
<licenses>
<flashbuilder4>1424-4008-9664-3602-3439-1711</flashbuilder4>
</licenses>
<testRunner>
<launcher>
<flashplayerCommand>/usr/bin/flashplayer</flashplayerCommand>
</launcher>
</testRunner>
<compiledLocales>
<locale>en_US</locale>
<!-- <locale>zh_CN</locale> -->
</compiledLocales>
<optimize>true</optimize>
<showWarnings>true</showWarnings>
<allowSourcePathOverlap>true</allowSourcePathOverlap>
<mergeResourceBundle>true</mergeResourceBundle>
<resourceBundlePath>${basedir}/locales/{locale}</resourceBundlePath>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>com.adobe.flex.framework</groupId>
<artifactId>flex-framework</artifactId>
<version>4.5.0.19786</version>
<type>pom</type>
</dependency>
<dependency>
<groupId>com.adobe.flexunit</groupId>
<artifactId>flexunit</artifactId>
<version>4.1.0-beta3</version>
<type>swc</type>
<scope>test</scope>
</dependency>
<dependency>
<groupId>INiT.Instant.Forge</groupId>
<artifactId>as3corelib-flex</artifactId>
<version>4.5</version>
<type>swc</type>
</dependency>
<dependency>
<groupId>INiT.Instant.Forge</groupId>
<artifactId>parsley-flex4</artifactId>
<version>2.4.0</version>
<type>swc</type>
</dependency>
<dependency>
<groupId>INiT.Instant.Forge</groupId>
<artifactId>spicelib-flex</artifactId>
<version>2.4.0</version>
<type>swc</type>
</dependency>
<dependency>
<groupId>INiT.Instant.Forge</groupId>
<artifactId>cmawslib-flex</artifactId>
<version>4.5</version>
<type>swc</type>
</dependency>
<dependency>
<groupId>INiT.Instant.Forge</groupId>
<artifactId>flexlib-flex4</artifactId>
<version>2.5</version>
<type>swc</type>
</dependency>
</dependencies>
<profiles>
<profile><!--https://docs.sonatype.org/pages/viewpage.action?pageId=2949459 -->
<id>m2e</id>
<activation>
<property>
<name>m2e.version</name>
</property>
</activation>
<build>
<plugins>
<plugin>
<groupId>org.maven.ide.eclipse</groupId>
<artifactId>lifecycle-mapping</artifactId>
<version>0.9.9-SNAPSHOT</version>
<configuration>
<mappingId>customizable</mappingId>
<configurators>
<configurator
id='org.maven.ide.eclipse.configuration.flex.configurator' />
</configurators>
<mojoExecutions>
<mojoExecution>org.apache.maven.plugins:maven-resources-plugin::</mojoExecution>
</mojoExecutions>
</configuration>
</plugin>
</plugins>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<version>2.4</version>
</plugin>
</plugins>
</pluginManagement>
</build>
</profile>
</profiles>
</project>
【mvn 自动化build】
cd /data/source/InstantForge/Pugna
mvn clean compile
mvn test
mvn install
或者
mvn clean install
【FAQ】
Q1.flashplayer必须在GUI环境下运行,如果在命令行下运行,maven会出现如下提示:
[INFO] Failed to launch Flash Player. Probably java was not able to find flashplayer.
Make sure flashplayer is available on PATH
or use -DflashPlayer.command=${flashplayer executable}
Read more at: https://docs.sonatype.org/display/FLEXMOJOS/Running+unit+tests
解决:
1.yum install xorg-x11-server-Xvfb
2.Get xvfb-run.sh from:
http://www.flexthinker.com/2009/09/building-a-flex-project-with-maven-using-hudson-on-centos/xvfb-run-sh/ (http://www.flexthinker.com/wp-content/uploads/2009/11/xvfb-run.sh.txt ) and copy it to /usr/bin (remove the .sh extension)
3. chmod 755 /usr/bin/xvfb-run
4. ldconfig
5. Add the following to your profile:
export MAVEN_OPTS="-Djava.awt.headless=true"
【参考1】
https://docs.sonatype.org/display/FLEXMOJOS/Running+unit+tests
【参考2】
How to do this in a headless environment?
You do need an actionScript virtual machine to run the test. Currently there are 2 real options: Flash Player and Air Player. Neither run on headless environment. So, you do need to adapt you env to run this. The good news is flexmojos already handle that. You just need xvfb installed (run xvfb-run)
---------------------------------------------------------------------------
Flex compiler and flex framework versions doesn't match. Compiler: '3.2.0.3958' - Framework: '4.1.0.16248'.
解决:pom.xml中设置Flex SDK compiler和flex-framwork为相同版本
Q3、运行 mvn install 时在执行 testcase 时失败:
Invalid state: the flashplayer is closed, but the sockets still running...
解决:指定Flash Player版本为10以上,如<targetPlayer>10.2.0</targetPlayer>
Q4、运行 mvn install 时在执行 testcase 时失败:
Accept timed out .../TestRunner.swf
解决:解决同Q3。若按上述设置后仍有问题,那有可能存在多个flashplayer。