BlazeDS 4.7.1をビルドしてみる

おひさしぶりですこんばんは。
3か月ぶりの更新になったわけですが、今回はBlazeDSをソースからBuildしようと思います。

半月ほど前の8月半ばにBlazeDSの脆弱性(CVE-2015-3269)が報告されました。Adobe LiveCycle Data Servicesを使用している場合は公式サイトのPatchを取り込めばよいですが、そうでない場合はBuildするかMavenに登録されているJarを取り込むかのいずれかになります。
ただ、BlazeDSはOSSであり、現在はApacheで管理・運営されているのですが、他のApache系プロジェクトと比べると使用者にはあまりやさしい作りにはなっていません。
例えば、現時点(2015/09/04)では公式サイトでリリースしているのは4.7.0のみで対策版はMavenからのみだったり、MavenのものもJava 1.8が前提だったりします。1)

前々からBlazeDSの自前コンパイルに興味はあったのでこれを機会に簡単に纏めようと思います。
纏めるといってもやったことを淡々とコピペになりますけどね^_^;
やったことはREADMEに書いてある通りです。なわけで、この記事自体はおさらいです。

git repositryからソースを取得

適当な場所にgit repositoryからソースを取得。
取得するのはこの3つ。

  •  flex-sdk
  •  flex-tlf
  •  flex-blazeds

apache flexの各種Repositoryについてはここで参照可能。

先に書いておけばよかったですが、今回のディレクトリはだいたい以下の構成で行います。

  •  E:\FlexBuild : 作業用ディレクトリ
  •  .\src : gitからcloneするディレクトリ

あと、環境はWindows 8.1ですがLinuxでもやることはさほど変わらないので適当に読み替えてください。

まずはclone。

E:\FlexBuild\src>git clone https://git-wip-us.apache.org/repos/asf/flex-sdk.git flex-sdk
Cloning into 'flex-sdk'...
remote: Counting objects: 345646, done.
remote: Compressing objects: 100% (123412/123412), done.
remote: Total 345646 (delta 237691), reused 314391 (delta 211537)
Receiving objects: 100% (345646/345646), 244.12 MiB | 638.00 KiB/s, done.
Resolving deltas: 100% (237691/237691), done.
Checking connectivity... done.
Checking out files: 100% (52867/52867), done.

E:\FlexBuild\src>git clone https://git-wip-us.apache.org/repos/asf/flex-tlf.git flex-tlf
Cloning into 'flex-tlf'...
remote: Counting objects: 3665, done.
remote: Compressing objects: 100% (2473/2473), done.
remote: Total 3665 (delta 2433), reused 1699 (delta 1110)
Receiving objects: 100% (3665/3665), 6.41 MiB | 1.59 MiB/s, done.
Resolving deltas: 100% (2433/2433), done.
Checking connectivity... done.
Checking out files: 100% (793/793), done.

E:\FlexBuild\src>git clone https://git-wip-us.apache.org/repos/asf/flex-blazeds.git flex-blazeds
Cloning into 'flex-blazeds'...
remote: Counting objects: 7962, done.
remote: Compressing objects: 100% (4175/4175), done.
remote: Total 7962 (delta 4371), reused 6458 (delta 3239)
Receiving objects: 100% (7962/7962), 78.44 MiB | 1.77 MiB/s, done.
Resolving deltas: 100% (4371/4371), done.
Checking connectivity... done.
Checking out files: 100% (2094/2094), done.

次にflex-sdkとflex-blazedsは特定のTagでCheckout。

現時点ではsdkは4.14.1が最新なのでtag「apache-flex-sdk-4.14.1」でcheckout。同様ににblazedsは「blazeds-4.7.1」。

余談ですが、BlazeDSの対策は4.8.0のBranchで行われています。対策は1つだけだしそれように準備するのも煩わしかったのかな?

E:\FlexBuild\src>cd flex-sdk

E:\FlexBuild\src\flex-sdk>git tag
OK_commit_donation
apache-flex-sdk-14.4.0RC1
  (中略)
apache-flex-sdk-4.14.1
apache-flex-sdk-4.14.1RC0
  (後略)

E:\FlexBuild\src\flex-sdk>git checkout apache-flex-sdk-4.14.1

E:\FlexBuild\src\flex-sdk>cd ..\flex-blazeds

E:\FlexBuild\src\flex-blazeds>git tag
apache-flex-sdk-14.4.0
apache-flex-sdk-14.4.0RC2
apache-flex-sdk-4.14.0RC2
apache-flex-sdk-4.14.1RC1
blazeds-4.7.0
blazeds-4.7.0.0-RC1
blazeds-4.7.1

E:\FlexBuild\src\flex-blazeds>git checkout blazeds-4.7.1

環境変数及びBuildに必要なファイルの取得

ソースを取得したところで必要なバイナリと環境変数を設定します。

# 変数 説明
1 JAVA_HOME 使用するJava SDKのインストールディレクトリを指定。1.7を使用しました。
2 ANT_HOME 使用するAntのインストールディレクトリを指定。1.9.2を使用しました。
3 AIR_HOME Adobe AIR Integration Kitのインストールディレクトリを指定。
4 PLAYERGLOBAL_HOME Adobe Flash Player playerglobal swcを格納したディレクトリを指定。ディレクトリ構成があるので後で詳細を書きます。
5 FLEX_HOME Flex SDKのインストールディレクトリを指定。指定しなくてもBuildできました。flex-blazedsと同階層にあるflex-sdkが指定されいるように見える。
6 FLASHPLAYER_DEBUGGER Adobe Flash Player Content Debugger。指定しなくてもBuildできました。
「C:\MyPath\FlashPlayerDebugger.exe」のようにexeまで指定するみたいです。
7 path 既存のpathに対してJava及びAntのbinを追加する。
e.g. set path=%ANT_HOME%\bin;%JAVA_HOME%\bin;%path%

Adobe AIRやPlayglobal、Flashplayer Debuggerの取得先はREADMEに記載があります。
READMEはflex-blazeds\READMEです。

JavaとAntはすでに入っている前提で話を進めていますが、まだ持っていない場合は取得してください。

playerglobalについて

PLAYERGLOBAL_HOMEについてですが、READMEにはディレクトリ構成を以下のようにすると書いてあります。

    /frameworks
            /libs
                /player
                    /10.2
                         /playerglobal.swc
                    /10.3
                         /playerglobal.swc
                    /11.0
                         /playerglobal.swc
                    /11.2
                         /playerglobal.swc
                    /.....

この場合、PLAYERGLOBAL_HOMEはplayerディレクトリを指定します。
playerglobalは10.2から13.0まで14ファイルあります。全部作るのは面倒なので必要なもののみを用意すればよいでしょう。
初期状態では11.1です。これはflex-sdkのbuild.propertiesにあるplyerglobal.versionで指定されています。

というわけで11.1以外を指定したい場合はflex-sdkのbuild.propertiesに記載されている内容を変更すればOKです。
他の変更方法ではflex-config.xmlやらコンパイル時の変数で指定する等々ありますが他の方法についてはREADMEを参照してください。

buildを実行

flex-sdkのbuild

flex-sdkでantを実行します。が、現時点(2015/09/04)でのビルドファイルではライブラリの取得で失敗します。

E:\FlexBuild\src\flex-sdk>ant
Buildfile: E:\FlexBuild\src\flex-sdk\build.xml(中略)thirdparty-downloads:pixelbender-check:pixelbender-download:
[mkdir] Created dir: E:\FlexBuild\src\flex-sdk\inget_from_mirror:download_using_mirror:
[get] Getting: http://www.apache.org/dyn/mirrors/mirrors.cgi/flex/pixelbender/1.0/binaries/apache-flex-sdk-pixel-bender-1.0.0-bin.zip?asjson=true
[get] To: E:\FlexBuild\src\flex-sdk\frameworks\mirror.json
[get] .
[delete] Deleting: E:\FlexBuild\src\flex-sdk\frameworks\mirror.json
[echo] Using mirror: ${preferred}BUILD FAILED
E:\FlexBuild\src\flex-sdk\build.xml:177: The following error occurred while executing this line:
E:\FlexBuild\src\flex-sdk\frameworks\build.xml:100: The following error occurred while executing this line:
E:\FlexBuild\src\flex-sdk\frameworks\downloads.xml:121: The following error occurred while executing this line:
E:\FlexBuild\src\flex-sdk\frameworks\downloads.xml:300: The following error occurred while executing this line:
E:\FlexBuild\src\flex-sdk\frameworks\downloads.xml:325: java.net.MalformedURLException: no protocol: ${preferred}flex/pixelbender/1.0/binaries/apache-flex-sdk-pixel-bender-1.0.0-bin.zip
at java.net.URL.<init>(URL.java:585)

apache.orgの仕様が変わったのかわかりませんが、動的にMirrorサイトを取得することができないようです。
というわけでpreferredに入るべきサイトを先に調べてプロパティで指定します。

まずは「http://www.apache.org/dyn/mirrors/mirrors.cgi/flex/pixelbender/1.0/binaries/apache-flex-sdk-pixel-bender-1.0.0-bin.zip」にブラウザでアクセス。
表示したページでsuggestされたサイトをコピーし、ant実行時に指定します。
asjson=trueなURLからはサイトを取得できませんが、実行時に指定したpreferredを使用してライブラリを取得します。

E:\FlexBuild\src\flex-sdk>ant -Dpreferred=http://ftp.tsukuba.wide.ad.jp/software/apache/
Buildfile: E:\FlexBuild\src\flex-sdk\build.xml(中略)thirdparty-downloads:pixelbender-check:pixelbender-download:get_from_mirror:download_using_mirror:
[get] Getting: http://www.apache.org/dyn/mirrors/mirrors.cgi/flex/pixelbender/1.0/binaries/apache-flex-sdk-pixel-bender-1.0.0-bin.zip?asjson=true
[get] To: E:\FlexBuild\src\flex-sdk\frameworks\mirror.json
[get] .
[delete] Deleting: E:\FlexBuild\src\flex-sdk\frameworks\mirror.json
[echo] Using mirror: http://ftp.tsukuba.wide.ad.jp/software/apache/
[get] Getting: http://ftp.tsukuba.wide.ad.jp/software/apache/flex/pixelbender/1.0/binaries/apache-flex-sdk-pixel-bender-1.0.0-bin.zip
[get] To: E:\FlexBuild\src\flex-sdk\in\apache-flex-sdk-pixel-bender-1.0.0-bin.zipdownload_using_get:
[unzip] Expanding: E:\FlexBuild\src\flex-sdk\in\apache-flex-sdk-pixel-bender-1.0.0-bin.zip into E:\FlexBuild\src\flex-sdk
(後略)

途中でembedded fontについて聞かれます。そのままEnterで問題ありません。
欲しい場合は表示されている情報を読みましょう。

ask-font:
[input] Apache Flex can optionally integrate with Adobe's embedded font support.
[input] This feature requires a few font jars from the Adobe Flex SDK.
[input] The Adobe SDK license agreement for Adobe Flex 4.6 applies to these jars.
[input] This license is not compatible with the Apache v2 license.
[input]
[input] Adobe Flex SDK License Agreement:
[input]
[input] All files contained in this Adobe Flex SDK download are subject to and governed by the
[input] Adobe Flex SDK License Agreement specified here:
[input]     http://www.adobe.com/products/eulas/pdfs/adobe_flex_software_development_kit-combined-20110916_0930.pdf,
[input] By downloading, modifying, distributing, using and/or accessing any files in this Adobe Flex SDK,
[input] you agree to the terms and conditions of the applicable end user license agreement.
[input]
[input] In addition to the Adobe license terms, you also agree to be bound by the third-party terms specified here:
[input]     http://www.adobe.com/products/eula/third_party/.
[input] Adobe recommends that you review these third-party terms.
[input]
[input] Do you want to install these jars from the Adobe Flex SDK? (y, [n])

Buildが継続され、しばらくすると終了します。

(前略)

BUILD SUCCESSFUL
Total time: 10 minutes 13 seconds

flex-blazedsのbuild

flex-blazedsでantを実行します。

FLEX_HOMEを設定していない場合は以下のようにFLEX_HOMEを設定してくれます。

E:\FlexBuild\src\flex-blazeds>ant
Buildfile: E:\FlexBuild\src\flex-blazeds\build.xmlcheck-flex-home:
[echo] FLEX_HOME is E:\FlexBuild\src\flex-blazeds/../flex-sdk

環境変数をチェックし、
ディレクトリ等々をCleanし、
Thirdpartyライブラリをダウンロードし…
と続いていきます。

Thirdpartyライブラリ、いわゆるOSSですが、結構な量があるのでここで時間がかかります。
現時点(2015/09/04)時点のビルドファイルではjacksonの取得に失敗します。

E:\FlexBuild\src\flex-blazeds>ant
thirdparty-downloads:tomcat-check:tomcat-download:download-tomcat-zip:
[mkdir] Created dir: E:\FlexBuild\src\flex-blazeds\in
[get] Getting: http://archive.apache.org/dist/tomcat/tomcat-6/v6.0.29/bin/apache-tomcat-6.0.29.zip
[get] To: E:\FlexBuild\src\flex-blazeds\in\apache-tomcat-6.0.29.zip
[unzip] Expanding: E:\FlexBuild\src\flex-blazeds\in\apache-tomcat-6.0.29.zip into E:\FlexBuild\src\flex-blazeds\serversactivemq-check:activemq-download:download-activemq-zip:
[get] Getting: http://archive.apache.org/dist/activemq/apache-activemq/5.3.1/apache-activemq-5.3.1-bin.zip
[get] To: E:\FlexBuild\src\flex-blazeds\in\apache-activemq-5.3.1-bin.zip
[unzip] Expanding: E:\FlexBuild\src\flex-blazeds\in\apache-activemq-5.3.1-bin.zip into E:\FlexBuild\src\flex-blazeds\in\activemq
[copy] Copying 67 files to E:\FlexBuild\src\flex-blazeds\servers\apache-tomcat-6.0.29\lib\activemq-5.3.1codec-check:
codec-download:

download-codec-zip:
[get] Getting: http://archive.apache.org/dist/commons/codec/binaries/commons-codec-1.5-bin.zip

(中略)

[get] Getting: http://downloads.sourceforge.net/project/cglib/cglib2/cglib%202.1_03/cglib-nodep-2.1_3.jar?r=http%3A%2F%2Fsourceforge.net%2Fprojects%2Fcglib%2Ffiles%2Fcglib2%2Fcglib%25202.1_03%2F&ts=1378516297&use_mirror=hivelocity
[get] To: E:\FlexBuild\src\flex-blazeds\lib\spring\cglib-nodep-2.1_3.jar
[get] http://downloads.sourceforge.net/project/cglib/cglib2/cglib%202.1_03/cglib-nodep-2.1_3.jar?r=http%3A%2F%2Fsourceforge.net%2Fprojects%2Fcglib%2Ffiles%2Fcglib2%2Fcglib%25202.1_03%2F&ts=1378516297&use_mirror=hivelocity moved to http://jaist.dl.sourceforge.net/project/cglib/cglib2/cglib%202.1_03/cglib-nodep-2.1_3.jar
[get] Getting: http://repository.codehaus.org/org/codehaus/jackson/jackson-core-asl/1.0.0/jackson-core-asl-1.0.0.jar
[get] To: E:\FlexBuild\src\flex-blazeds\lib\spring\jackson-core-asl-1.0.0.jar
[get] Error getting http://repository.codehaus.org/org/codehaus/jackson/jackson-core-asl/1.0.0/jackson-core-asl-1.0.0.jar to E:\FlexBuild\src\flex-blazeds\lib\spring\jackson-core-asl-1.0.0.jar

BUILD FAILED
E:\FlexBuild\src\flex-blazeds\build.xml:137: The following error occurred while executing this line:
E:\FlexBuild\src\flex-blazeds\downloads.xml:396: The following error occurred while executing this line:
E:\FlexBuild\src\flex-blazeds\downloads.xml:461: java.net.UnknownHostException: repository.codehaus.org
at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:178)
at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:157)

どうやらrepository.codehaus.orgがみつからないらしいので、別のところからjackson-core-asl-1.0.0.jarを取得するように修正しましょう。
ここは無難にMavenのCentral Repositoryから取得します。
修正するファイルはdownload.xmlです。

[Before]
http://repository.codehaus.org/org/codehaus/jackson/jackson-core-asl/1.0.0/jackson-core-asl-1.0.0.jar

[After]
http://search.maven.org/remotecontent?filepath=org/codehaus/jackson/jackson-core-asl/1.0.0/jackson-core-asl-1.0.0.jar

気を取り直してもう一度antを実行。
Downloadが成功しているAntのTaskについてはほぼすっ飛ばしです。

E:\FlexBuild\src\flex-blazeds>ant

(中略)

log4j-check:

log4j-download:

spring-check:

spring-download:

download-spring-zip:
[unzip] Expanding: E:\FlexBuild\src\flex-blazeds\in\spring-framework-3.0.3.RELEASE.zip into E:\FlexBuild\src\flex-blazeds\in\spring
[copy] Copying 21 files to E:\FlexBuild\src\flex-blazeds\lib\spring
[unzip] Expanding: E:\FlexBuild\src\flex-blazeds\in\spring-security-3.0.3.RELEASE.zip into E:\FlexBuild\src\flex-blazeds\in\springsecurity

(後略)

Downloadが終わるとコンパイル等の処理が開始されます。
しばらくするとBuildが終了します。

(前略)

BUILD SUCCESSFUL
Total time: 41 seconds

41秒で完了していますがこれはライブラリのDownload時間を除いた時間です。

flex-sdkをbuildしていない場合

もし、FLEX_HOMEを未指定、もしくはflex-sdkをにしており、flex-sdkをbuildしていない場合は以下のエラーでBuildが失敗します。
この場合は先にflex-sdkをBuildしておきましょう。

(前略)

compile:
[echo] E:\FlexBuild\src\flex-blazeds/lib/xalan.jar
[echo] compiling sources with 1.5
[javac] E:\FlexBuild\src\flex-blazeds\qa\apps\qa-regress\build.xml:232: warning: 'includeantruntime' was not set, defaulting to build.sysclasspath=last; set
to false for repeatable builds
[javac] Compiling 73 source files to E:\FlexBuild\src\flex-blazeds\qa\apps\qa-regress\WEB-INF\classes

BUILD FAILED
E:\FlexBuild\src\flex-blazeds\build.xml:215: The following error occurred while executing this line:
E:\FlexBuild\src\flex-blazeds\qa\apps\qa-regress\build.xml:232: E:\FlexBuild\src\flex-sdk\lib does not exist.

できたもの

flex-blazeds\libに他のOSSとともに入っています。flex-messaging-*.jarがそれですね。
これで晴れてBlazeDSをソースからコンパイルできました。
気になるところをいくつか挙げておきます。

前提ライブラリ

私が知っている頃のBlazeDSははるか昔なのですが、そのころに比べると依存しているライブラリが増えたりバージョンが変わっていたりします。
とりあえずBuildしたもののどれがあれば動くのかな?という状態です。
flex-messaging-coreのpom.xmlをみるとActiveMQがprovidedになっていることから、実行環境に入っていることが期待されているわけですよね?

Manifestファイル

flex-messaging-core.jarのMANIFEST.MFを見ています。

Manifest-Version: 1.0
Ant-Version: Apache Ant 1.9.2
Created-By: 1.7.0_17-b02 (Oracle Corporation)
Sealed: false
Implementation-Title: BlazeDS - Community Edition
Implementation-Version: 4.6.0.dev
Implementation-Vendor: Adobe Systems Inc.

何も考えずにBuildするぐらいならどうでもよいのですが…うーむ。
Versionは4.7.1にするべきだし、VendorももはやAdobeではないよな。

Versionなどの値はflex-blazeds\build.propertiesの一番下にあります。

前提ライブラリ等まだ書くことがあるのですが、Buildに関してはこれで終わりです。

Footnotes
  1. Adobe LiveCycle Data Servicesの対策版はJava 1.5 でBuildされていますね。 []