Quantcast
Channel: プログラミング
Viewing all articles
Browse latest Browse all 7910

Grand: Apache Ant の依存関係を可視化する - kakakakakku blog

$
0
0

Grand を使うと Apache Ant ターゲットの依存関係を dot ファイルとして可視化できる.そもそも可視化したくなるほど依存関係が複雑なことが課題ではあると思うけど,既存の build.xmlを解析したり,新しく build.xmlを読むメンバーのために README.mdに図を貼っておいたりという用途はありそう👌

特に新しいツールではなく,また GitHub を見ると2020年頃からメンテナンスは止まってそうだけど,試す機会があってメモとして残しておく❗️

ant-grand.github.io

セットアップ

Grand は Grand 自身を Ant ターゲットとして実行できる.まずは GitHub の Releases から grand-1.9.7.jarをダウンロードしておく.今回は lib/ディレクトリに置いた.

github.com

Grand を実行するターゲットは可視化対象となる build.xmlに直接追加することもできるし,Grand 専用の build.xmlを作ることもできる.今回は後者のアイデアを採用して grand.xmlを以下のように設定した.

<project name="Grand"><target name="grand"><typedef resource="net/ggtools/grand/antlib.xml"classpath="lib/grand-1.9.7.jar"/><grand output="build.dot"buildfile="build.xml" /></target></project>

最終的に以下のようなディレクトリ構成になった👀

.
├── README.md
├── build.xml
├── grand.xml
└── lib
    └── grand-1.9.7.jar

お試し1

まずは Apache Ant のドキュメント Writing a Simple Buildfileに載っている build.xmlを使う.

ant.apache.org

<project name="MyProject"default="dist"basedir="."><description>
    simple example build file
  </description><!-- set global properties for this build --><property name="src"location="src"/><property name="build"location="build"/><property name="dist"location="dist"/><target name="init"><!-- Create the time stamp --><tstamp/><!-- Create the build directory structure used by compile --><mkdir dir="${build}"/></target><target name="compile"depends="init"description="compile the source"><!-- Compile the Java code from ${src} into ${build} --><javac srcdir="${src}"destdir="${build}"/></target><target name="dist"depends="compile"description="generate the distribution"><!-- Create the distribution directory --><mkdir dir="${dist}/lib"/><!-- Put everything in ${build} into the MyProject-${DSTAMP}.jar file --><jar jarfile="${dist}/lib/MyProject-${DSTAMP}.jar"basedir="${build}"/></target><target name="clean"description="clean up"><!-- Delete the ${build} and ${dist} directory trees --><delete dir="${build}"/><delete dir="${dist}"/></target></project>

そして ant -f grand.xml grandコマンドを実行すると依存関係を可視化できた❗️

お試し2

次に Apache Ant のドキュメント Tutorial: Hello World with Apache Antに載っている build.xmlを使う.

ant.apache.org

<project name="HelloWorld"basedir="."default="main"><property name="src.dir"value="src"/><property name="build.dir"value="build"/><property name="classes.dir"value="${build.dir}/classes"/><property name="jar.dir"value="${build.dir}/jar"/><property name="main-class"value="oata.HelloWorld"/><target name="clean"><delete dir="${build.dir}"/></target><target name="compile"><mkdir dir="${classes.dir}"/><javac srcdir="${src.dir}"destdir="${classes.dir}"/></target><target name="jar"depends="compile"><mkdir dir="${jar.dir}"/><jar destfile="${jar.dir}/${ant.project.name}.jar"basedir="${classes.dir}"><manifest><attribute name="Main-Class"value="${main-class}"/></manifest></jar></target><target name="run"depends="jar"><java jar="${jar.dir}/${ant.project.name}.jar"fork="true"/></target><target name="clean-build"depends="clean,jar"/><target name="main"depends="clean,run"/></project>

そして ant -f grand.xml grandコマンドを実行すると依存関係を可視化できた❗️

カスタマイズ用プロパティファイル

可視化した依存関係の色は以下のように決まっている🎨

  • 黄色: デフォルトターゲット
  • 緑色: descriptionありターゲット
  • 白色: descriptionなしターゲット

カスタマイズ用プロパティファイルを使うと一部の設定を変更できる.今回は以下の設定で grand.propertiesを作った.各ノードのフォントサイズを大きくして,descriptionありターゲットも 白色(楕円形)にしてみた.正直 descriptionは書かないこともあって,デフォルトの 緑色白色は同じで良いかな〜と思った.

dot.node.attributes=fontsize="20"
dot.mainnode.attributes=fillcolor="white"

そして grand.xmlpropertyタグの設定と grandタグに outputconfigfileオプションを追加すれば OK👌

<project name="Grand"><target name="grand"><property file="grand.properties"/><typedef resource="net/ggtools/grand/antlib.xml"classpath="lib/grand-1.9.7.jar"/><grand output="build.dot"buildfile="build.xml"outputconfigfile="grand.properties"/></target></project>

お試し1で使った build.xmlに対して ant -f grand.xml grandコマンドを実行すると,ちゃんとフォントサイズが大きくなって,緑色(長方形)もなくなっていた❗️


Viewing all articles
Browse latest Browse all 7910

Trending Articles