May 30, 2007
[Maven] Maven2 の assembly プラグインにチャレンジ
maven-assembly-plugin とは
いわゆる「出荷用アーカイブの作成」に近いイメージのプラグイン。 特に出荷用というわけではないのだけれど、プロジェクト内の好きなファイルをアーカイビングすることが出来る。 アーカイブの形式も zip、tar.gz、tar.bz2、jar など様々な形式に対応している。 今回は、開発環境(要するにソース一式)を他の開発者にそのままアーカイビングして渡すことをイメージして遊んでみた。
- Maven Assembly Plugin
- http://maven.apache.org/plugins/maven-assembly-plugin/
- assembly:assembly
- http://maven.apache.org/plugins/maven-assembly-plugin/assembly-mojo.html
- Guide to creating assemblies
- http://maven.apache.org/guides/mini/guide-assemblies.html
- ソースコード
- https://svn.apache.org/repos/asf/maven/plugins/tags/maven-assembly-plugin-2.2-beta-1/
pom.xml の設定
<project> <build> <plugins> <plugin> <artifactId>maven-assembly-plugin</artifactId> <configuration> <descriptor>assemple.xml</descriptor> <outputDirectory>..</outputDirectory> </configuration> </plugin> </plugins> </build> </project>
maven-assembly-plugin の設定ファイル
pom.xml で指定した名称で maven-assembly-plugin の設定ファイルを作成する。 下の例は開発環境を渡すことを想定しているため、ソースコード類とビルドツールをアーカイビングしている。
<?xml version="1.0" encoding="UTF-8"?> <assembly> <id>src</id> <formats> <format>tar.gz</format> </formats> <fileSets> <fileSet> <includes> <include>*.*</include> <include>.settings/**/*.*</include> <include>module1/pom.xml</include> <include>module1/src/**/*.*</include> <include>module2/pom.xml</include> <include>module2/src/**/*.*</include> <include>tool/maven-2.0.6/**/*.*</include> </includes> </fileSet> </fileSets> </assembly>
maven-assembly-plugin の実行
下のコマンドで実行できる。今回の例では、プロジェクトホームと同じディレクトリに ${finalName}-src.tar.gz というアーカイブが作成される。 アーカイブファイルに設定ファイルの id が付加される。
> mvn assembly:assembly
May 26, 2007
[Subversion] Subversion と Trac の連携にチャレンジ (2)
Subversion の Issue Tracker 連携機能は便利なのだけれど、ディレクトリ毎にいくつものプロパティを設定しなければいけないという面倒さがある。 auto-props を使用できれば良いのだが、auto-props は残念なことにファイル専用でディレクトリには適用されない。 ディレクトリを作成する度にプロパティを手動で設定するのは馬鹿らしいので、自動化を考えてみた。
自動化の方法
- auto-props
- ディレクトリには auto-props は適用されない。不可能。
- svn propset を CRON で実行。
- ディレクトリ作成直後に連携機能が使用できない。さすがに /etc/cron.minutely というのは無いし。
- pre-commit hook を利用
- pre-commit で svn co、svn propset、svn commit を実施するとコンフリクトが発生して元の svn commit が失敗してしまう。NG。ちなみに、svn propset は working copy が無いと動作しないので、面倒でも一度 svn co しないと propset できない(Subversion subversion Issue 2238 で議論されている)。ちなみに、proplist や propget は working copy 無しでも実行できる。
- post-commit hook を利用
- これが唯一の方法?? post-commit で svn co、svn propset、svn commit を行う。パフォーマンス的には問題だが、所詮個人用途のサーバだから大丈夫だろう。
post-commit で bugtraq プロパティ追加の自動化
/var/svn/hooks/post-commit
というわけで、post-commit 用のスクリプトを作成してみた。 善し悪しは別として、bugtraq:url プロパティが設定されていないディレクトリ(もしくはその直下のファイル)が commit された際に自動的に bugtraq 関連のプロパティをセットする。 ユーザ情報を埋め込まないと行けないのが難と言えば難だが、他に方法が無かったので必要悪ということで諦めた。 ちょっとややこしくなってしまったが、結果的に期待通りの動作が得られたので良しとする。
# cat /var/svn/hooks/post-commit #!/bin/sh # POST-COMMIT HOOK BUGTRAQ_PROPS=/var/svn/bugtraq_props.conf TMP_DIR=/var/tmp/svn SVN_REPOSITORY=file:///var/svn/ SVN_USER=me SVN_PASSWORD=mypassword SVNLOOK=/usr/bin/svnlook SVN=/usr/bin/svn REPOS="$1" REV="$2" #----------------------------------------------------------------- # propset bugtraq conrigurations to directories #----------------------------------------------------------------- configureBugtraqProps() { #--------------------------------------------------------------- # load configuration for bugtraq. # if configuration file does not exist, do nothing. #--------------------------------------------------------------- test -x $BUGTRAQ_PROPS || return . $BUGTRAQ_PROPS CHANGED_DIRS="$1" for i in $CHANGED_DIRS; do #------------------------------------------------------------- # if "bugtraq:url" prop is not set, assume that this directory # has no bagtraq configuration #------------------------------------------------------------- BUGTRAQ_URL=`$SVNLOOK propget -r "$REV" "$REPOS" "bugtraq:url" "$i"` if [ "$BUGTRAQ_URL" == "" ] then #----------------------------------------------------------- # unfortunately, svn propset command needs working copy of repository. # so, checkout target directory to temporary working copy #----------------------------------------------------------- rm -rf $TMP_DIR mkdir $TMP_DIR cd $TMP_DIR $SVN checkout "$SVN_REPOSITORY$i" --non-recursive -r HEAD --username "$SVN_USER" --password "$SVN_PASSWORD" --non-interactive #----------------------------------------------------------- # propset to target directory #----------------------------------------------------------- $SVN propset "bugtraq:url" "$bugtraq_url" `ls $TMP_DIR` $SVN propset "bugtraq:label" "$bugtraq_label" `ls $TMP_DIR` $SVN propset "bugtraq:message" "$bugtraq_message" `ls $TMP_DIR` $SVN propset "bugtraq:warnifnoissue" "$bugtraq_warnifnoissue" `ls $TMP_DIR` $SVN propset "bugtraq:number" "$bugtraq_number" `ls $TMP_DIR` $SVN propset "bugtraq:append" "$bugtraq_append" `ls $TMP_DIR` $SVN propset "bugtraq:logregex" "$bugtraq_logregex" `ls $TMP_DIR` #----------------------------------------------------------- # commit prop changes #----------------------------------------------------------- $SVN commit `ls $TMP_DIR` --username "$SVN_USER" --password "$SVN_PASSWORD" --message "set bugtraq props" #----------------------------------------------------------- # clean up temporary working copy #----------------------------------------------------------- rm -rf $TMP_DIR fi done } CHANGED_DIRS=`$SVNLOOK dirs-changed -r "$REV" "$REPOS"` configureBugtraqProps "$CHANGED_DIRS" exit 0
/var/svn/bugtraq_props.conf
この設定は環境に併せて適宜変更する必要がある。
# cat /var/svn/bugtraq_props.conf bugtraq_url=https://www.example.com/trac/ticket/%BUGID% bugtraq_label="Ticket ID" bugtraq_message="#%BUGID%" bugtraq_warnifnoissue=false bugtraq_number=true bugtraq_append=false bugtraq_logregex="#?(\d+)"
May 25, 2007
[Subversion] Subversion と Trac の連携にチャレンジ (1)
Subversion には、クライアントプログラム用に "bugtraq" で始まるプロパティが規定されている。 このプロパティが指定されているディレクトリはバグトラッキングシステムとの連携機能が特別に用意される(大抵のクライアントで)。 というわけで、Subversion と Trac を連携させてみた。
- Issue Tracker Integration
- http://svn.collab.net/subclipse/help/topic/org.tigris.subversion.subclipse.doc/html/reference/issuetracker.html
- Integration of Subversion (GUI) clients with Bug Tracking Tools
- http://guest:guest@tortoisesvn.tigris.org/svn/tortoisesvn/trunk/doc/issuetrackers.txt
設定したプロパティ
設定するのはディレクトリのみで OK。 TortoiseSVN を使用すると再帰的に設定を行ってくれるので便利。
bugtraq_url | https://www.example.com/trac/ticket/%BUGID% | Issue Tracker の URL。"%BUGID%"という文字列がコミット時に入力された Issue ID に自動的に置換される。 |
bugtraq_label | "Ticket ID" | Subversion クライアントに表示される ID 用のラベル。Trac の場合は Bug も Issue も Ticket と呼ばれているので Ticket ID にしている。 |
bugtraq_message | "#%BUGID%" | コミット時、コメントに自動的に追記されるメッセージ。 |
bugtraq_warnifnoissue | false | コミット時に Issue ID が指定されなかった場合に警告をするか否か。個人的にコード以外の情報も Subversion で管理しているので false にしているが、開発用リソースのみが格納されているディレクトリの場合は true の方が良いかもしれない。 |
bugtraq_number | true | Issue ID が数値かどうか。Issue ID が Subversion クライアントに入力された際、クライアントが Issue ID をバリデーションしてくれる。 |
bugtraq_append | false | bugtraq_message で指定したメッセージを、ユーザが入力したコメントの「前」に追記するか「後」に追記するかを指定する。false の時に前になる。 |
bugtraq_logregex | "#?(\d+)" | Issue ID の正規表現。Issue ID が Subversion クライアントに入力された際、クライアントが Issue ID をバリデーションしてくれる。 |
TortoiseSVN のコミット画面の変化
設定前 | 設定後 |
![]() |
![]() |
Subclipse のコミット画面の変化
設定前 | 設定後 |
![]() |
![]() |
May 24, 2007
[Library] Log4j を使用してログを syslog に出力する
Debian Etch の syslog にリモートから Log4j を使用してログを出力する方法をメモ。
syslogd の設定
Debian Etch では、デフォルト状態の syslogd はリモートからのログを受け付けない設定になっている。 そのため、syslogd の設定を変更して syslogd をリブートする必要がある。 設定は /etc/default/syslogd で行う。
設定が正常に反映されたか確認するために、syslog のポートが開いているかチェックする。# diff /etc/default/syslogd.original /etc/default/syslogd 13c13 < SYSLOGD="" --- > SYSLOGD="-r" # /etc/init.d/sysklogd restart #
UDP の 514 が開いていたら設定は成功。# netstat -an | grep -i udp | grep 514 udp 0 0 0.0.0.0:514 0.0.0.0:* #
Log4j の設定
Log4j にはデフォルトで syslog にログを出力してくれる org.apache.log4j.net.SyslogAppender が用意されている。 しかし、残念なことに org.apache.log4j.PatternLayout が文字エンコーディングの変換機能を持っていないので、マルチバイト文字をメッセージに使用するとログが文字化けしてしまう。 そのため、PatternLayout を拡張して文字エンコーディングを変換する機能を持った Layout クラスを自作する必要がある。 Debian Etch の場合は(インストール時の設定にもよるけれど)、通常デフォルトの文字エンコーディングは EUC-JP になっていると思うので、EUC-JP に変換できればマルチバイト文字をログに出力できる。
文字エンコーディング変換機能付き PatternLayout
PatternLayout の拡張は非常に簡単。 単純に文字エンコーディングを設定内容からインジェクションしてもらい、PatternLayout でメッセージをフォーマットした後に変換処理をするだけ。
package jp.in_vitro.samplecode; import java.io.UnsupportedEncodingException; import org.apache.log4j.PatternLayout; import org.apache.log4j.spi.LoggingEvent; /** * メッセージのフォーマット後に文字エンコーディング変換を行う {@link PatternLayout}。 */ public class CharsetSupportPatternLayout extends PatternLayout { /** メッセージをフォーマット後に変換する文字エンコーディング。 */ private String charset; public CharsetSupportPatternLayout() { super(); } public CharsetSupportPatternLayout(final String pattern) { super(pattern); } public void setCharset(final String charset) { this.charset = charset; } @Override public String format(final LoggingEvent event) { String message = super.format(event); if (this.charset != null) { try { message = new String(message.getBytes(this.charset)); } catch (UnsupportedEncodingException e) { } } return message; } }
Log4j の設定
log4j.properties に下記の様な感じで設定する。log4j.xml にする場合はこの内容に準じて XML に書き直せば良い。 Facility は syslog のカテゴリに相当するもので、デフォルトでは user、uucp などが規定されている。 システムにもよるけれど、専用の Facility を用意した方が分かり易いと個人的には思う。 前述の通り、Debian Etch の場合、charset は EUC-JP を指定する(と大抵は上手くいくと思う)。 ConversionPattern は通常と少し違い、時刻と改行コードを省略している。 時刻は syslogd が自動的に付加してくれるのと、改行コードはプラットフォーム毎に異なるのでメッセージには付加しないようにしている。 メッセージに改行コードが付いていなくても、syslogd が付加してくれる様なので特に問題はない(はず)。
log4j.appender.syslog=org.apache.log4j.net.SyslogAppender log4j.appender.syslog.Facility=[facility] log4j.appender.syslog.SyslogHost=[syslog server] log4j.appender.syslog.layout=jp.in_vitro.samplecode.CharsetSupportPatternLayout log4j.appender.syslog.layout.charset=[syslog server default character encoding] log4j.appender.syslog.layout.ConversionPattern=%5p %c{1} - %m
実験
下記の様なテストコードを Windows XP 上で実行してみた。 面倒なので facility は uucp を間借りした。
リモートの Debian Etch では以下の様なログが出力された。Logger log = Logger.getLogger(CharsetSupportPatternLayoutTest.class); log.fatal("Oh, my god!!"); log.error("緊急事態"); log.warn("気をつけて"); log.info("お知らせ"); log.debug("デバッグ");
というわけで、実験成功。 但し、何故か変な化け方をする文字が結構ある。 メッセージの 'る' が 'た' に変わってしまうといった感じ。 後で原因を調査しないと・・・。# tail -f /var/log/uucp.log May 26 16:14:03 192.168.1.101 FATAL Hoge - Oh, my god!! May 26 16:14:03 192.168.1.101 ERROR Hoge - 緊急事態 May 26 16:14:03 192.168.1.101 WARN Hoge - 気をつけて May 26 16:14:03 192.168.1.101 INFO Hoge - お知らせ May 26 16:14:04 192.168.1.101 DEBUG Hoge - デバッグ
May 23, 2007
[Misc] Subversion Web UI のデザインをカスタマイズする
Apache2 + Subversion で運用している場合、Subversion の Web UI を簡単にカスタマイズできる。 Debian Etch での方法をメモ。
svnindex.xsl、svnindex.css のコピー
/var/www/apache2-default/ に svnindex.xsl と svnindex.css が設置されているので、 この 2 つのファイルを Apache2 が参照可能な位置にコピー(DocumentRoot 直下など)。
/etc/apache2/mods-available/dav_svn.conf の編集
dav_svn.conf に SVNIndexXSLT を指定する。パスは DocumentRoot からの相対パスを指定。
<Location /svn> ...SNIP... # Web UI Design SVNIndexXSLT /svnindex.xsl ...SNIP... </Location>
svnindex.xsl、svnindex.css の編集
後はお好みで svnindex.xsl、svnindex.css を編集する。
デフォルト状態に多少手を入れたものが こちら。
興味のある方はお持ちください。
May 22, 2007
[Maven] packaging の際にソースコードの jar も生成する。
Maven2 で "mvn package" する際に同時にソースコード及びリソースを jar でアーカイビングする方法をメモ。 納品の際に便利。
pom.xml の設定
maven-source-plugin を使用するだけなので、設定は非常に簡単。 ただ、maven-source-plugin のソースコードを見ると、pom.xml に登録するだけで package phase になると自動的に実行される設定になっているのだが、 実際に動作させてみると何故か動かない。仕方がないので、executions を指定して実行するようにした。環境の問題だろうか?? バグだろうか??
<project> ...SNIP... <build> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-source-plugin</artifactId> <executions> <phase>package</phase> <execution> <goals> <goal>jar</goal> </goals> </execution> </executions> </plugin> </build> ...SNIP... </project>
May 21, 2007
[Library] Mock ライブラリを調査
Java で利用できる Mock ライブラリを調べてみた。 昔使用していた MockObjects は いつの間にか開発が停止して現在ではダウンロード出来なくなっているようだ。
Mock ライブラリ
EasyMock
現時点で一番情報が多そうなのが EasyMock か。 多少慣れるのに時間がかかりそうだが、結構使い出はありそう。 jMock とどちらを選択するかは好みの問題になるだろうか。
- EasyMock
- http://www.easymock.org/
- EasyMock 2.2 Readme
- http://www.easymock.org/EasyMock2_2_Documentation.html
- EasyMock 2 License (MIT License)
- http://www.easymock.org/License.html
jMock
EasyMock とどちらを選択するか悩むところ。 とりあえず両方試してみて自分に合う方を選択するということになりそう。
- jMock
- http://www.jmock.org/index.html
- Getting Started
- http://www.jmock.org/getting-started.html
- jMock Project License
- http://www.jmock.org/license.html
RMock
- RMock testing framework
- http://rmock.sourceforge.net/
- The RMock 2.0.0 user guide
- http://rmock.sourceforge.net/documentation/xdoc.html
- Project License (Apache License Version 2.0)
- http://rmock.sourceforge.net/documentation/license.html
mocquer
May 20, 2007
[Misc] GUI プログラミングで使用できるフリーのアイコン集
GUI プログラミングをすると、いつもアイコンをどうするかで困ってしまう。 大抵は簡単なものを自作するのだが、時間がかかって仕方がない。 というわけで、フリーで使用できる GUI 用のアイコン集を探してみた。
- Icon Collection
- http://sourceforge.net/projects/icon-collection/
- Ximian Open-Officeのアイコン
- http://www.novell.com/coolsolutions/nnlsmag/assets/ooo-stock.zip
- Gnomeのアイコン:
- http://art.gnome.org/themes/icon/
- SVG BlueSphereのアイコンとテーマ:
- http://svgicons.sourceforge.net/
- KDEのアイコン:
-
http://www.buzzard.me.uk/jonathan/kde-icons.html
http://www.kde-look.org/ - Iconize Textlinks with CSS
- http://www.pooliestudios.com/projects/iconize/
- Drunkey Love
- http://www.el73.be/drunkey-love/downloads/
- Eclipse Icons
- http://codehaus.org/~bwalding/eclipse-icons/
- Sanscons
- http://somerandomdude.net/srd-projects/clearbits
情報源
上記のアイコン集は下記のサイトから GUI に使用できそうなものをチョイスした。 下記のサイトを公開してくださっている方に感謝。
- Java GUIプログラミングの、とてもBasicなFAQ
- http://homepage1.nifty.com/algafield/JavaGUIFaq19j.html
- POP*POP的アイコン配布サイトまとめ
- http://www.popxpop.com/archives/2006/12/post_48.html
May 18, 2007
[Maven] Maven2 Cobertura plugin でカバレッジにチャレンジ
Cobertura とは
Cobertura は、Java 用のカバレッジツール。類似のものに Clover、EMMA、jcoverage などがある。 けれど、Clover は商用利用はライセンス購入が必要、EMMA は Maven2 用のプラグインが無い、JCoverage はいつの間にか Eclipse Plugin 専用になっている、ということで現状 Maven2 で気楽にカバレッジツールを使用する場合は Cobertura しか選択肢が無い。 というわけで、Cobertura を使用してカバレッジレポートを作成してみた。
- Cobertura
- http://cobertura.sourceforge.net/
pom.xml の設定
Cobertura の設定は build で instrument して、report で結果を出力するようにすれば良い。 pom.xml に下記の様な設定をして、"mvn site" で簡単にカバレッジレポートを見ることができる。
<project> ...SNIP... <build> <plugins> <plugin> <groupId>org.codehaus.mojo</groupId> <artifactId>cobertura-maven-plugin</artifactId> <executions> <phase>pre-site</phase> <execution> <goals> <goal>clean</goal> <goal>check</goal> </goals> </execution> </executions> </plugin> </plugins> </build> ...SNIP... <reporting> <plugins> <plugin> <groupId>org.codehaus.mojo</groupId> <artifactId>cobertura-maven-plugin</artifactId> </plugin> </plugins> </reporting> </project>
May 17, 2007
[Trac] Mylar で Eclipse + Trac Ticket 連携にチャレンジ
Mylar とは
Eclipse Mylar Project によると、Mylar とは
Eclipse Mylar is a task-focused UI that reduces information overload and makes multi-tasking easy.というものだそうだ。要するに、Eclipse 上で Eclipse UI に従ってタスク管理をすることができるというプラグインのこと。 面白いのは、Trac 用の Mylar Connector が用意されていて、Trac 側で XML-RPC プラグインを用意しておくと Mylar で Trac のチケットを管理できるようになるということ。 Trac はチケットの上手な活用が肝になるので、Eclipse と連携できると便利。 ということで、早速試してみた。
- Eclipse Mylar
- http://www.eclipse.org/mylar/
- Trac XML-RPC プラグイン
- http://trac-hacks.org/wiki/XmlRpcPlugin
Trac XML-RPC プラグインのインストール
これは、上記の Trac XML-RPC プラグインのページに従ってインストール作業をすれば OK。
Eclipse Mylar のインストール
Eclipse 3.3M7 で Mylar のインストールを試してみた。
Mylar は Callisto の後継となる Europa に含まれているので、インストールは非常に簡単。
Subversion にも Mylar 用プラグインがあったので、ついでにインストールしておいたが、
何の役に立っているのか良くわかっていない(^^; まぁ、大は小を兼ねるということで。
Mylar は Europa でインストールできるので、Software Updates の機能を使用する。
"Search for new features to install" を選択して次へ。
今回は Mylar 関連のプラグインとして Europa に登録されている Mylar プラグインと Subclipseに含まれている Mylar プラグインをインストールするので、Europa と Subclipse にチェックして次へ。
Mylar 関連のプラグインをチェックして次へ。図では全て選択してあるが、Connector は必要なものだけで良い。例えば、Trac にしか接続しないのであれば、Trac Connector だけ選択しておけば良い。
後はお決まりのライセンス確認。次へ。
インストールされるプラグインを確認。次へ。
インストールの最終確認。次へ。
Eclipse リブートの確認。次へ。
Eclipse Mylar の設定
Eclipse Mylar プラグインのインストールが終了して、Eclipse の再起動が終わったら Mylar の設定を行う。
Eclipse のリブートが完了すると、Mylar の設定画面が表示される。特に変更すべき内容も無かったのでデフォルトの設定のまま次へ(変更したい方はどうぞ)。
"Task List" View を右クリックして "New" を選択すると、"Query..." が表示されるのでこれを選択。
デフォルトではタスクリポジトリに "Eclipse.org" しか登録されていないので、自分の Trac を登録する。"Add Task Repository" を選択。
Server に Trac の URL を入力。Label は任意の文字列で良い。後は、認証が必要であれば認証情報を入力。Trac の場合、Access Type は XML-RPC にする。一通り入力が終わったら、"Validate Settings" を押して一度タスクリポジトリに接続してみる。エラーが出なければ設定完了。
今追加したタスクリポジトリを選択して次へ。
クエリの内容を入力する。今回は全てのチケットを表示する様にしておくため何も設定を行わずに次へ。
"Task List" にチケットが表示されたら設定完了。後は、ここからチケットの起票や更新が可能となる。便利。
May 16, 2007
[Maven] Maven2 で POM の inheritance & aggregation を整理してみる(4)
まとめ
結局、Maven2 の Inheritance と Aggregation は上手く使いわけると結構便利だと再認識できた。
Maven2 の POM を階層化して管理する場合は下記の図の様になるだろうか。
May 14, 2007
[Maven] Maven2 で POM の inheritance & aggregation を整理してみる(3)
inheritance & aggregation の実験
inheritance & aggregation 用のサンプルプロジェクトは下記の様な構成。 基本的には前回 2 つと全く同じ。 \both\pom.xml は packageing=pom で aggregation を使用できるようにしてある。 \both\child\pom.xml は継承を表す parent タグを使用して \both\pom.xml を継承してある。
\both ├pom.xml └child ├pom.xml └src └java └com └example └HelloWorld.java
\both\pom.xml
artifactId、name 以外は aggregation のサンプルと全く同一。
<?xml version="1.0" encoding="UTF-8" ?> <project> <modelVersion>4.0.0</modelVersion> <name>pom both sample</name> <groupId>com.example</groupId> <artifactId>pom-both-sample</artifactId> <version>1.0.0</version> <packaging>pom</packaging> <build> <plugins> <plugin> <groupId>jp.in-vitro.largo</groupId> <artifactId>largo-support-pom</artifactId> <version>2.0.0</version> <executions> <execution> <phase>compile</phase> <goals> <goal>dumpPom</goal> </goals> </execution> </executions> </plugin> </plugins> </build> <reporting> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-javadoc-plugin</artifactId> <configuration> <charset>Shift_JIS</charset> </configuration> </plugin> </plugins> </reporting> <organization> <name>example.com</name> <url>http://www.example.com/</url> </organization> <developers> <developer> <id>me</id> <name>me</name> </developer> </developers> <issueManagement> <system>Bugzilla</system> <url>http://www.example.com/bugzilla</url> </issueManagement> <ciManagement> <system>continuum</system> <url>http://www.example.com/continuum</url> </ciManagement> <mailingLists> <mailingList> <name>Developer ML</name> <subscribe>subscribe@example.com</subscribe> <unsubscribe>unsubscribe@example.com</unsubscribe> <post>developer@example.com</post> </mailingList> </mailingLists> <scm> <connection>scm:svn:http://www.example.com/svn/my-project</connection> <developerConnection>scm:svn:https://127.0.0.1/svn/my-project</developerConnection> <tag>HEAD</tag> <url>http://www.example.com/websvn/my-project</url> </scm> <repositories> <repository> <id>repository.example.com</id> <name>example.com repository</name> <url>http://www.example.com/maven2</url> </repository> </repositories> <distributionManagement> <repository> <id>repository.example.com</id> <name>example.com repository</name> <url>scp://www.example.com/maven2</url> </repository> </distributionManagement> <modules> <module>child</module> </modules> </project>
\both\child\pom.xml
artifactId、name 以外は inheritance のサンプルと全く同一。
<?xml version="1.0" encoding="UTF-8" ?> <project> <modelVersion>4.0.0</modelVersion> <parent> <groupId>com.example</groupId> <artifactId>pom-both-sample</artifactId> <version>1.0.0</version> </parent> <artifactId>pom-both-sample-child</artifactId> <name>pom both sample - child</name> <packaging>jar</packaging> </project>
\both で Maven2 による compile を実行した結果
aggregation を使用しているので、\both\pom.xml を使用してコンパイルを実行すると \both\child\pom.xml も同時に処理されている。 また、inheritance も使用しているので、\both\pom.xml の設定項目が \both\child\pom.xml に継承されている。
both>mvn compile [INFO] Scanning for projects... [INFO] Reactor build order: [INFO] pom both sample [INFO] pom both sample - child [INFO] ------------------------------------------------------------------------- --- [INFO] Building pom both sample [INFO] task-segment: [compile] [INFO] ------------------------------------------------------------------------- --- [INFO] [largo-support-pom:dumpPom {execution: default}] ***** POM INFORMATION ************************************* id : com.example:pom-both-sample:pom:1.0.0 groupId : com.example atrifactId : pom-both-sample version : 1.0.0 name : pom both sample *********************************************************** Parent : null File : D:\both\pom.xml Basedir : D:\both Repositories : [org.apache.maven.model.Repository@13059051[name=example.com repo sitory,url=http://www.example.com/maven2,id=repository.example.com,layout=defaul t,releases=null,snapshots=null],org.apache.maven.model.Repository@3945515[name=M aven Repository Switchboard,url=http://repo1.maven.org/maven2,id=central,layout= default,releases=null,snapshots=org.apache.maven.model.RepositoryPolicy@8530b8], ] Modules : [child,] BuildPlugins : [Plugin [jp.in-vitro.largo:largo-support-pom],] ReportPlugins : [org.apache.maven.model.ReportPlugin@1deeb40,] Developers : [org.apache.maven.model.Developer@30633470[name=me,email=null,id=me ,organization=null,organizationUrl=null,roles=[]],] Organization : org.apache.maven.model.Organization@25109548[name=example.com,url =http://www.example.com/] [INFO] ------------------------------------------------------------------------- --- [INFO] Building pom both sample - child [INFO] task-segment: [compile] [INFO] ------------------------------------------------------------------------- --- [INFO] [resources:resources] [INFO] Using default encoding to copy filtered resources. [INFO] [compiler:compile] [INFO] Compiling 1 source file to D:\both\child\target\classes [INFO] [largo-support-pom:dumpPom {execution: default}] ***** POM INFORMATION ************************************* id : com.example:pom-both-sample-child:jar:1.0.0 groupId : com.example atrifactId : pom-both-sample-child version : 1.0.0 name : pom both sample - child *********************************************************** Parent : org.apache.maven.project.MavenProject@f328409 File : D:\both\child\pom.xml Basedir : D:\both\child Repositories : [org.apache.maven.model.Repository@29857804[name=example.com repo sitory,url=http://www.example.com/maven2,id=repository.example.com,layout=defaul t,releases=null,snapshots=null],org.apache.maven.model.Repository@13594894[name= Maven Repository Switchboard,url=http://repo1.maven.org/maven2,id=central,layout =default,releases=null,snapshots=org.apache.maven.model.RepositoryPolicy@1077fc9 ],] Modules : [] BuildPlugins : [Plugin [jp.in-vitro.largo:largo-support-pom],Plugin [org.apache. maven.plugins:maven-resources-plugin],Plugin [org.apache.maven.plugins:maven-com piler-plugin],] ReportPlugins : [org.apache.maven.model.ReportPlugin@a2220f,] Developers : [org.apache.maven.model.Developer@1668655[name=me,email=null,id=me, organization=null,organizationUrl=null,roles=[]],] Organization : org.apache.maven.model.Organization@7388808[name=example.com,url= http://www.example.com/] ***** POM INFORMATION ************************************* id : com.example:pom-both-sample:pom:1.0.0 groupId : com.example atrifactId : pom-both-sample version : 1.0.0 name : pom both sample *********************************************************** Parent : null File : D:\both\pom.xml Basedir : D:\both Repositories : [org.apache.maven.model.Repository@13059051[name=example.com repo sitory,url=http://www.example.com/maven2,id=repository.example.com,layout=defaul t,releases=null,snapshots=null],org.apache.maven.model.Repository@3945515[name=M aven Repository Switchboard,url=http://repo1.maven.org/maven2,id=central,layout= default,releases=null,snapshots=org.apache.maven.model.RepositoryPolicy@8530b8], ] Modules : [child,] BuildPlugins : [Plugin [jp.in-vitro.largo:largo-support-pom],] ReportPlugins : [org.apache.maven.model.ReportPlugin@1deeb40,] Developers : [org.apache.maven.model.Developer@30633470[name=me,email=null,id=me ,organization=null,organizationUrl=null,roles=[]],] Organization : org.apache.maven.model.Organization@25109548[name=example.com,url =http://www.example.com/] [INFO] [INFO] [INFO] ------------------------------------------------------------------------ [INFO] Reactor Summary: [INFO] ------------------------------------------------------------------------ [INFO] pom both sample ....................................... SUCCESS [0.969s] [INFO] pom both sample - child ............................... SUCCESS [1.766s] [INFO] ------------------------------------------------------------------------ [INFO] ------------------------------------------------------------------------ [INFO] BUILD SUCCESSFUL [INFO] ------------------------------------------------------------------------ [INFO] Total time: 3 seconds [INFO] Finished at: Mon May 14 00:14:11 JST 2007 [INFO] Final Memory: 4M/13M [INFO] ------------------------------------------------------------------------ both>
\both\child で Maven2 による compile を実行した結果
\both\child\pom.xml を使用してコンパイルを実行してみる。 \both\pom.xml を継承しているので、\both\child\pom.xml がきちんと \both\pom.xml の内容を引き継いでいることが分かる。
both\child>mvn compile [INFO] Scanning for projects... [INFO] ------------------------------------------------------------------------- --- [INFO] Building pom both sample - child [INFO] task-segment: [compile] [INFO] ------------------------------------------------------------------------- --- [INFO] [resources:resources] [INFO] Using default encoding to copy filtered resources. [INFO] [compiler:compile] [INFO] Compiling 1 source file to D:\both\child\target\classes [INFO] [largo-support-pom:dumpPom {execution: default}] ***** POM INFORMATION ************************************* id : com.example:pom-both-sample-child:jar:1.0.0 groupId : com.example atrifactId : pom-both-sample-child version : 1.0.0 name : pom both sample - child *********************************************************** Parent : org.apache.maven.project.MavenProject@f328409 File : D:\both\child\pom.xml Basedir : D:\both\child Repositories : [org.apache.maven.model.Repository@33459432[name=example.com repo sitory,url=http://www.example.com/maven2,id=repository.example.com,layout=defaul t,releases=null,snapshots=null],org.apache.maven.model.Repository@13948523[name= Maven Repository Switchboard,url=http://repo1.maven.org/maven2,id=central,layout =default,releases=null,snapshots=org.apache.maven.model.RepositoryPolicy@149105b ],] Modules : [] BuildPlugins : [Plugin [jp.in-vitro.largo:largo-support-pom],Plugin [org.apache. maven.plugins:maven-resources-plugin],Plugin [org.apache.maven.plugins:maven-com piler-plugin],] ReportPlugins : [org.apache.maven.model.ReportPlugin@196f4b5,] Developers : [org.apache.maven.model.Developer@33445663[name=me,email=null,id=me ,organization=null,organizationUrl=null,roles=[]],] Organization : org.apache.maven.model.Organization@6326112[name=example.com,url= http://www.example.com/] ***** POM INFORMATION ************************************* id : com.example:pom-both-sample:pom:1.0.0 groupId : com.example atrifactId : pom-both-sample version : 1.0.0 name : pom both sample *********************************************************** Parent : null File : D:\both\pom.xml Basedir : D:\both Repositories : [org.apache.maven.model.Repository@13301441[name=example.com repo sitory,url=http://www.example.com/maven2,id=repository.example.com,layout=defaul t,releases=null,snapshots=null],org.apache.maven.model.Repository@17708501[name= Maven Repository Switchboard,url=http://repo1.maven.org/maven2,id=central,layout =default,releases=null,snapshots=org.apache.maven.model.RepositoryPolicy@1f03691 ],] Modules : [child,] BuildPlugins : [Plugin [jp.in-vitro.largo:largo-support-pom],] ReportPlugins : [org.apache.maven.model.ReportPlugin@1b03c1a,] Developers : [org.apache.maven.model.Developer@5313146[name=me,email=null,id=me, organization=null,organizationUrl=null,roles=[]],] Organization : org.apache.maven.model.Organization@6888942[name=example.com,url= http://www.example.com/] [INFO] ------------------------------------------------------------------------ [INFO] BUILD SUCCESSFUL [INFO] ------------------------------------------------------------------------ [INFO] Total time: 4 seconds [INFO] Finished at: Mon May 14 00:22:39 JST 2007 [INFO] Final Memory: 4M/8M [INFO] ------------------------------------------------------------------------ both\child>
May 13, 2007
[Maven] Maven2 で POM の inheritance & aggregation を整理してみる(2)
aggregation の実験
aggregation 用のサンプルプロジェクトは下記の様な構成。 基本的には inheritance 用と全く同じ。 \aggregation\pom.xml は packageing=pom で aggregation を使用できるようにしてある。 \aggregation\child\pom.xml は inheritance の時とは異なり、継承を表す parent タグを外してある。
\aggregation ├pom.xml └child ├pom.xml └src └java └com └example └HelloWorld.java
\aggregation\pom.xml
<?xml version="1.0" encoding="UTF-8" ?> <project> <modelVersion>4.0.0</modelVersion> <name>pom aggregation sample</name> <groupId>com.example</groupId> <artifactId>pom-aggregation-sample</artifactId> <version>1.0.0</version> <packaging>pom</packaging> <build> <plugins> <plugin> <groupId>jp.in-vitro.largo</groupId> <artifactId>largo-support-pom</artifactId> <version>2.0.0</version> <executions> <execution> <phase>compile</phase> <goals> <goal>dumpPom</goal> </goals> </execution> </executions> </plugin> </plugins> </build> <reporting> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-javadoc-plugin</artifactId> <configuration> <charset>Shift_JIS</charset> </configuration> </plugin> </plugins> </reporting> <organization> <name>example.com</name> <url>http://www.example.com/</url> </organization> <developers> <developer> <id>me</id> <name>me</name> </developer> </developers> <issueManagement> <system>Bugzilla</system> <url>http://www.example.com/bugzilla</url> </issueManagement> <ciManagement> <system>continuum</system> <url>http://www.example.com/continuum</url> </ciManagement> <mailingLists> <mailingList> <name>Developer ML</name> <subscribe>subscribe@example.com</subscribe> <unsubscribe>unsubscribe@example.com</unsubscribe> <post>developer@example.com</post> </mailingList> </mailingLists> <scm> <connection>scm:svn:http://www.example.com/svn/my-project</connection> <developerConnection>scm:svn:https://127.0.0.1/svn/my-project</developerConnection> <tag>HEAD</tag> <url>http://www.example.com/websvn/my-project</url> </scm> <repositories> <repository> <id>repository.example.com</id> <name>example.com repository</name> <url>http://www.example.com/maven2</url> </repository> </repositories> <distributionManagement> <repository> <id>repository.example.com</id> <name>example.com repository</name> <url>scp://www.example.com/maven2</url> </repository> </distributionManagement> <modules> <module>child</module> </modules> </project>
\aggregation\child\pom.xml
今回は aggregation のみ使用することが目的なので、inheritance を表す parent タグは使用していない。 \aggregation\pom.xml との違いを明確にするために、わざとほとんどの設定を省略している。
<?xml version="1.0" encoding="UTF-8" ?> <project> <modelVersion>4.0.0</modelVersion> <groupId>com.example</groupId> <artifactId>pom-aggregation-sample-child</artifactId> <version>1.0.0</version> <name>pom aggregation sample - child</name> <packaging>jar</packaging> <build> <plugins> <plugin> <groupId>jp.in-vitro.largo</groupId> <artifactId>largo-support-pom</artifactId> <version>2.0.0</version> <executions> <execution> <phase>compile</phase> <goals> <goal>dumpPom</goal> </goals> </execution> </executions> </plugin> </plugins> </build> </project>
\aggregation で Maven2 による compile を実行した結果
aggregation を使用しているので、\aggregation\pom.xml を使用してコンパイルを実行すると \aggregation\child\pom.xml も同時に処理されている。 今回は inheritance を使用していないので、\aggregation\child\pom.xml では \aggregation\pom.xml の内容は引き継がれていない。 例えば、Developer や Organization といった項目に注目してみると、\aggregation\child\pom.xml では空になっていることが分かる。 また、\aggregation\pom.xml では、Modules に child が設定されていることが分かる。
aggregation>mvn compile [INFO] Scanning for projects... [INFO] Reactor build order: [INFO] pom aggregation sample - child [INFO] pom aggregation sample [INFO] ------------------------------------------------------------------------- --- [INFO] Building pom aggregation sample - child [INFO] task-segment: [compile] [INFO] ------------------------------------------------------------------------- --- [INFO] [resources:resources] [INFO] Using default encoding to copy filtered resources. [INFO] [compiler:compile] [INFO] Compiling 1 source file to D:\aggregation\child\tar get\classes [INFO] [largo-support-pom:dumpPom {execution: default}] ***** POM INFORMATION ************************************* id : com.example:pom-aggregation-sample-child:jar:1.0.0 groupId : com.example atrifactId : pom-aggregation-sample-child version : 1.0.0 name : pom aggregation sample - child *********************************************************** Parent : null File : D:\aggregation\child\pom.xml Basedir : D:\aggregation\child Repositories : [org.apache.maven.model.Repository@29345020[name=Maven Repository Switchboard,url=http://repo1.maven.org/maven2,id=central,layout=default,release s=null,snapshots=org.apache.maven.model.RepositoryPolicy@11db6bb],] BuildPlugins : [Plugin [jp.in-vitro.largo:largo-support-pom],Plugin [org.apache. maven.plugins:maven-resources-plugin],Plugin [org.apache.maven.plugins:maven-com piler-plugin],] ReportPlugins : [] Developers : [] Organization : null [INFO] ------------------------------------------------------------------------- --- [INFO] Building pom aggregation sample [INFO] task-segment: [compile] [INFO] ------------------------------------------------------------------------- --- [INFO] [largo-support-pom:dumpPom {execution: default}] ***** POM INFORMATION ************************************* id : com.example:pom-aggregation-sample:pom:1.0.0 groupId : com.example atrifactId : pom-aggregation-sample version : 1.0.0 name : pom aggregation sample *********************************************************** Parent : null File : D:\aggregation\pom.xml Basedir : D:\aggregation Repositories : [org.apache.maven.model.Repository@30311876[name=example.com repo sitory,url=http://www.example.com/maven2,id=repository.example.com,layout=defaul t,releases=null,snapshots=null],org.apache.maven.model.Repository@28326938[name= Maven Repository Switchboard,url=http://repo1.maven.org/maven2,id=central,layout =default,releases=null,snapshots=org.apache.maven.model.RepositoryPolicy@139e351 ],] Modules : [child,] BuildPlugins : [Plugin [jp.in-vitro.largo:largo-support-pom],] ReportPlugins : [org.apache.maven.model.ReportPlugin@51127a,] Developers : [org.apache.maven.model.Developer@30167145[name=me,email=null,id=me ,organization=null,organizationUrl=null,roles=[]],] Organization : org.apache.maven.model.Organization@13594894[name=example.com,url =http://www.example.com/] [INFO] [INFO] [INFO] ------------------------------------------------------------------------ [INFO] Reactor Summary: [INFO] ------------------------------------------------------------------------ [INFO] pom aggregation sample - child ........................ SUCCESS [2.640s] [INFO] pom aggregation sample ................................ SUCCESS [0.047s] [INFO] ------------------------------------------------------------------------ [INFO] ------------------------------------------------------------------------ [INFO] BUILD SUCCESSFUL [INFO] ------------------------------------------------------------------------ [INFO] Total time: 3 seconds [INFO] Finished at: Sun May 13 18:05:02 JST 2007 [INFO] Final Memory: 4M/9M [INFO] ------------------------------------------------------------------------ aggregation>
\aggregation\child で Maven2 による compile を実行した結果
\aggregation\child\pom.xml を使用してコンパイルを実行してみる。 aggregation を使用していても、基本的には \aggregation\pom.xml との親子関係は無いので単体で問題なくコンパイルできる。
aggregation\child>mvn compile [INFO] Scanning for projects... [INFO] ------------------------------------------------------------------------- --- [INFO] Building pom aggregation sample - child [INFO] task-segment: [compile] [INFO] ------------------------------------------------------------------------- --- [INFO] [resources:resources] [INFO] Using default encoding to copy filtered resources. [INFO] [compiler:compile] [INFO] Compiling 1 source file to D:\aggregation\child\target\classes [INFO] [largo-support-pom:dumpPom {execution: default}] ***** POM INFORMATION ************************************* id : com.example:pom-aggregation-sample-child:jar:1.0.0 groupId : com.example atrifactId : pom-aggregation-sample-child version : 1.0.0 name : pom aggregation sample - child *********************************************************** Parent : null File : D:\aggregation\child\pom.xml Basedir : D:\aggregation\child Repositories : [org.apache.maven.model.Repository@33459432[name=Maven Repository Switchboard,url=http://repo1.maven.org/maven2,id=central,layout=default,release s=null,snapshots=org.apache.maven.model.RepositoryPolicy@d4d66b],] Modules : [] BuildPlugins : [Plugin [jp.in-vitro.largo:largo-support-pom],Plugin [org.apache. maven.plugins:maven-resources-plugin],Plugin [org.apache.maven.plugins:maven-com piler-plugin],] ReportPlugins : [] Developers : [] Organization : null [INFO] ------------------------------------------------------------------------ [INFO] BUILD SUCCESSFUL [INFO] ------------------------------------------------------------------------ [INFO] Total time: 3 seconds [INFO] Finished at: Sun May 13 18:12:51 JST 2007 [INFO] Final Memory: 4M/8M [INFO] ------------------------------------------------------------------------ aggregation\child>
May 12, 2007
[Maven] Maven2 で POM の inheritance & aggregation を整理してみる(1)
POM の inheritance & aggregation
普段何気なく使っている POM の inheritance や aggregation だけれど、 考えてみると極端に複雑なプロジェクトを構築したことが無いので常に両方を同時に使用することが多かった。 そこで、一度 inheritance と aggregation の違いとそれぞれの意味を整理してみた。
inheritance の実験
下記の様な構成のプロジェクトをでっち上げてみた。 \inheritance\pom.xml は packageing=pom で親 POM になれるようにしてある(下記参照)。 \inheritance\child\pom.xml は \inheritance\pom.xml を継承するように設定してある。
\inheritance ├pom.xml └child ├pom.xml └src └java └com └example └HelloWorld.java
\inheritance\pom.xml
<?xml version="1.0" encoding="UTF-8" ?> <project> <modelVersion>4.0.0</modelVersion> <name>pom inheritance sample</name> <groupId>com.example</groupId> <artifactId>pom-inheritance-sample</artifactId> <version>1.0.0</version> <packaging>pom</packaging> <build> <plugins> <plugin> <groupId>jp.in-vitro.largo</groupId> <artifactId>largo-support-pom</artifactId> <version>2.0.0</version> <executions> <execution> <phase>compile</phase> <goals> <goal>dumpPom</goal> </goals> </execution> </executions> </plugin> </plugins> </build> <reporting> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-javadoc-plugin</artifactId> <configuration> <charset>Shift_JIS</charset> </configuration> </plugin> </plugins> </reporting> <organization> <name>example.com</name> <url>http://www.example.com/</url> </organization> <developers> <developer> <id>me</id> <name>me</name> </developer> </developers> <repositories> <repository> <id>repository.example.com</id> <name>example.com repository</name> <url>http://www.example.com/maven2</url> </repository> </repositories> </project>
\inheritance\child\pom.xml
今回は inheritance のみ使用することが目的なので、aggregation を表す modules タグは使用していない。 ただ、parent タグで親の POM を指定しているため、記述量が圧倒的に減少していることがすぐに分かる。 ちなみに、POM の内容は簡単な自作の Maven Plugin で出力している。
<?xml version="1.0" encoding="UTF-8" ?> <project> <modelVersion>4.0.0</modelVersion> <parent> <groupId>com.example</groupId> <artifactId>pom-inheritance-sample</artifactId> <version>1.0.0</version> </parent> <artifactId>pom-inheritance-sample-child</artifactId> <name>pom inheritance sample - child</name> <packaging>jar</packaging> </project>
\inheritance で Maven2 による compile を実行した結果
aggregation を使用していないので、\inheritance\pom.xml が表しているプロジェクトのみがコンパイルされている。 \inheritance\child\pom.xml は全く無視されていることに注目。
inheritance>mvn compile [INFO] Scanning for projects... [INFO] ------------------------------------------------------------------------- --- [INFO] Building pom inheritance sample [INFO] task-segment: [compile] [INFO] ------------------------------------------------------------------------- --- [INFO] [resources:resources] [INFO] Using default encoding to copy filtered resources. [INFO] [compiler:compile] [INFO] Compiling 1 source file to D:\inheritance\target\classes [INFO] [largo-support-pom:dumpPom {execution: default}] ***** POM INFORMATION ************************************* id : com.example:pom-inheritance-sample:pom:1.0.0 groupId : com.example atrifactId : pom-inheritance-sample version : 1.0.0 name : pom inheritance sample *********************************************************** Parent : null File : D:\inheritance\pom.xml Basedir : D:\inheritance Repositories : [org.apache.maven.model.Repository@33459432[name=example.com repo sitory,url=http://www.example.com/maven2,id=repository.example.com,layout=defaul t,releases=null,snapshots=null],org.apache.maven.model.Repository@13948523[name= Maven Repository Switchboard,url=http://repo1.maven.org/maven2,id=central,layout =default,releases=null,snapshots=org.apache.maven.model.RepositoryPolicy@149105b ],] BuildPlugins : [Plugin [jp.in-vitro.largo:largo-support-pom],Plugin [org.apache. maven.plugins:maven-resources-plugin],Plugin [org.apache.maven.plugins:maven-com piler-plugin],] ReportPlugins : [org.apache.maven.model.ReportPlugin@196f4b5,] Developers : [org.apache.maven.model.Developer@17427094[name=me,email=null,id=me ,organization=null,organizationUrl=null,roles=[]],] Organization : org.apache.maven.model.Organization@14069849[name=example.com,url =http://www.example.com/] [INFO] ------------------------------------------------------------------------ [INFO] BUILD SUCCESSFUL [INFO] ------------------------------------------------------------------------ [INFO] Total time: 3 seconds [INFO] Finished at: Sun May 13 16:40:33 JST 2007 [INFO] Final Memory: 4M/9M [INFO] ------------------------------------------------------------------------ inheritance>
\inheritance\child で Maven2 による compile を実行した結果
\inheritance\child\pom.xml を使用してコンパイルを実行してみる。 こちらもこちらで自分自身のプロジェクトのみを処理対象としている。 但し、POM の内容は \inheritance\pom.xml の内容を継承しているため、 \interitance\child\pom.xml では設定をしていない項目もきちんと設定が受け継がれていることが分かる。 例えば、Developer や Organization といった項目を見ると良く分かる。
inheritance>cd child inheritance\child>mvn compile [INFO] Scanning for projects... [INFO] ------------------------------------------------------------------------- --- [INFO] Building pom inheritance sample - child [INFO] task-segment: [compile] [INFO] ------------------------------------------------------------------------- --- [INFO] [resources:resources] [INFO] Using default encoding to copy filtered resources. [INFO] [compiler:compile] [INFO] Compiling 1 source file to D:\inheritance\child\target\classes [INFO] [largo-support-pom:dumpPom {execution: default}] ***** POM INFORMATION ************************************* id : com.example:pom-inheritance-sample-child:jar:1.0.0 groupId : com.example atrifactId : pom-inheritance-sample-child version : 1.0.0 name : pom inheritance sample - child *********************************************************** Parent : org.apache.maven.project.MavenProject@a6be9458 File : D:\inheritance\child\pom.xml Basedir : D:\inheritance\child Repositories : [org.apache.maven.model.Repository@13948523[name=example.com repo sitory,url=http://www.example.com/maven2,id=repository.example.com,layout=defaul t,releases=null,snapshots=null],org.apache.maven.model.Repository@21565531[name= Maven Repository Switchboard,url=http://repo1.maven.org/maven2,id=central,layout =default,releases=null,snapshots=org.apache.maven.model.RepositoryPolicy@1d0d45b ],] BuildPlugins : [Plugin [jp.in-vitro.largo:largo-support-pom],Plugin [org.apache. ReportPlugins : [org.apache.maven.model.ReportPlugin@19ba640,] Developers : [org.apache.maven.model.Developer@539419[name=me,email=null,id=me,o rganization=null,organizationUrl=null,roles=[]],] Organization : org.apache.maven.model.Organization@13878877[name=example.com,url =http://www.example.com/] ***** POM INFORMATION ************************************* id : com.example:pom-inheritance-sample:pom:1.0.0 groupId : com.example atrifactId : pom-inheritance-sample version : 1.0.0 name : pom inheritance sample *********************************************************** Parent : null File : D:\inheritance\pom.xml Basedir : D:\inheritance Repositories : [org.apache.maven.model.Repository@26117441[name=example.com repo sitory,url=http://www.example.com/maven2,id=repository.example.com,layout=defaul t,releases=null,snapshots=null],org.apache.maven.model.Repository@30311876[name= Maven Repository Switchboard,url=http://repo1.maven.org/maven2,id=central,layout =default,releases=null,snapshots=org.apache.maven.model.RepositoryPolicy@1b03c1a ],] BuildPlugins : [Plugin [jp.in-vitro.largo:largo-support-pom],] ReportPlugins : [org.apache.maven.model.ReportPlugin@1578aab,] Developers : [org.apache.maven.model.Developer@19658898[name=me,email=null,id=me ,organization=null,organizationUrl=null,roles=[]],] Organization : org.apache.maven.model.Organization@13594894[name=example.com,url =http://www.example.com/] [INFO] ------------------------------------------------------------------------ [INFO] BUILD SUCCESSFUL [INFO] ------------------------------------------------------------------------ [INFO] Total time: 3 seconds [INFO] Finished at: Sun May 13 17:28:32 JST 2007 [INFO] Final Memory: 4M/8M [INFO] ------------------------------------------------------------------------ inheritance\child>
May 09, 2007
[Maven] Maven2 で AbstractMethodError
まれに Maven2 実行時に AbstractMethodError が発生することがある。
例えば、mvn site 実行時に上記の様に発生する。 この場合、%USER_HOME%\.m2\repository\org を全部削除すれば良い。 Maven2 のバージョンアップを繰り返しているうちに plugin 関連の依存関係が実行時におかしくなることがあるようだ。[INFO] Velocimacro : initialization complete. [INFO] Velocity successfully started. [INFO] [site:site] [INFO] ------------------------------------------------------------------------ [ERROR] FATAL ERROR [INFO] ------------------------------------------------------------------------ [INFO] null [INFO] ------------------------------------------------------------------------ [INFO] Trace java.lang.AbstractMethodError at org.apache.maven.plugins.site.SiteMojo.filterReports(SiteMojo.java:40 7) at org.apache.maven.plugins.site.SiteMojo.execute(SiteMojo.java:221) at org.apache.maven.plugin.DefaultPluginManager.executeMojo(DefaultPlugi nManager.java:443) at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoals(Defa ultLifecycleExecutor.java:539) at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoalWithLi fecycle(DefaultLifecycleExecutor.java:480) at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoal(Defau ltLifecycleExecutor.java:459) at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoalAndHan dleFailures(DefaultLifecycleExecutor.java:311) at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeTaskSegmen ts(DefaultLifecycleExecutor.java:278) at org.apache.maven.lifecycle.DefaultLifecycleExecutor.execute(DefaultLi fecycleExecutor.java:143) at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:334) at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:125) at org.apache.maven.cli.MavenCli.main(MavenCli.java:272) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl. java:39) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAcces sorImpl.java:25) at java.lang.reflect.Method.invoke(Method.java:585) at org.codehaus.classworlds.Launcher.launchEnhanced(Launcher.java:315) at org.codehaus.classworlds.Launcher.launch(Launcher.java:255) at org.codehaus.classworlds.Launcher.mainWithExitCode(Launcher.java:430) at org.codehaus.classworlds.Launcher.main(Launcher.java:375) [INFO] ------------------------------------------------------------------------ [INFO] Total time: 1 minute 31 seconds [INFO] Finished at: Thu May 10 09:11:00 JST 2007 [INFO] Final Memory: 15M/27M [INFO] ------------------------------------------------------------------------
May 08, 2007
[Maven] プライベートなリモートリポジトリの設定変更
Maven2 用のプライベートなリモートリポジトリを整理してみた。 今までは URL を一切公開していないので、特にアクセス制限はかけていなかったのだが、 とりあえず HTTPS + Basic 認証 くらいはかけておこうかと設定を変更してみた。
Maven2 リモートリポジトリの Basic 認証
これは非常に簡単。 サーバ側で Basic 認証の設定をしておいて、pom.xml、settings.xml を編集するだけ。
pom.xml
<project> ...SNIP... <repositories> <repository> <id>my-private-repository</id> <name>my private repository</name> <url>http://www.example.com/maven2</url> </repository> </repositories> ...SNIP... </project>
settings.xml
<settings> ...SNIP... <servers> <server> <id>my-private-repository</id> <username>me</username> <password>mypassword</password> </server> </servers> ...SNIP... </settings>
Maven2 リモートリポジトリの HTTPS アクセス
これは結局実現できなかった。 プライベートサーバなのでディジタル証明書を正規に購入するわけもなく、 オレオレ証明書で運用しているのだが、結局はそれがネックになってしまった。 JDK の cacerts にオレオレ証明書を登録してみたり、独自の keystore にオレオレ証明書を登録して MAVEN_OPTS に "-Djavax.net.ssl.trustStore=keystore -Djavax.net.ssl.trustStorePassword=password" を指定したりと色々試してみたのだが、結局動作しなかった。
自前のコードで HTTPS 接続を試してみたところ、証明書に問題がある可能性も出てきてこれ以上の調査は結構時間がかかりそうだったので断念。 いつの日か HTTPS + Basic 認証で Maven2 リモートリポジトリにアクセスしたいものだ。 ・・・ディジタル証明書を買う、というのが一番手っ取り早い解決方法なのだが。
May 01, 2007
[Linux] Debian Etch + Apache2.2 で ActiveDirectory 認証にチャレンジ
Debian Etch で Apache2.2 から Windows 2003 Server の ActiveDirectory を使用してユーザ認証設定をした。 上手く行くまでに結構苦労したので、メモ。
今回は Subversion の認証を ActiveDirectory で行うことにした。 /etc/apache2/mods-available/dav_svn.conf を色々編集していたのだが、中々上手く行かなかった。 結局下記の様に設定することで正常にユーザ認証できるようになった。
<Location /svn> ...SNIP... AuthType Basic AuthName "Subversion Repositoryr" AuthBasicProvider ldap AuthLDAPUrl "ldap://pdc.example.com:389/OU=employees,dc=example,dc=com?sAMAccountName?sub?(objectClass=*)" AuthLDAPBindDN ldap@example.com AuthLDAPBindPassword ldap-user-password Require ldap-attribute objectClass=person </Location>
AuthLDAPUrl、AuthLDAPBindDN、AuthLDAPBindPassword は色々なサイトに記述されている通りで問題は無かったのだが(強いて言えば、私の試した環境では AuthLDAPUrl に OU を指定しないと動作しなかった)、 Require ディレクティブの設定でかなり時間をかけてしまった。
Require ディレクティブに
やRequire valid-user
と記述すると、ActiveDirectory の認証は上手く行くのだが Apache が認証エラーを返してしまう。 その場合、Apache の error.log には何も表示されず原因が分かりづらい。 結局、mod_authnz_ldap のマニュアルに記述されていた Require ディレクティブの解説通りの設定をしたら正常に認証されるようになった。Require ldap-user
- Apache Module mod_authnz_ldap
- http://httpd.apache.org/docs/2.2/mod/mod_authnz_ldap.html
- require ldap-attribute
- http://httpd.apache.org/docs/2.2/mod/mod_authnz_ldap.html#reqattribute