Open3

Neo4j で Java のクラスの依存関係を分析したい

negokaznegokaz

docker-compose exec でパイプ使えるよね?

-T オプションを付ければ大丈夫。(Windows 環境特有かも)
TTY を無効化するので対話モードでユーザーに何か入力させるというのができなくなるはず。

❯ echo 'echo hello' | docker-compose exec ubuntu bash
the input device is not a TTY.  If you are using mintty, try prefixing the command with 'winpty'
❯ echo 'echo hello' | docker-compose exec -T ubuntu bash
hello
    -T                Disable pseudo-tty allocation. By default `docker-compose exec`
                      allocates a TTY.
negokaznegokaz

jdeps の出力フォーマット

https://github.com/lerna-stack/lerna-sample-payment-app 内のクラスを分析してみる。

❯ java -version
openjdk version "11.0.8" 2020-07-14
OpenJDK Runtime Environment AdoptOpenJDK (build 11.0.8+10)
OpenJDK 64-Bit Server VM AdoptOpenJDK (build 11.0.8+10, mixed mode)

オプションなし


sbt プロジェクトなので、各サブプロジェクトの target ディレクトリに *.class ファイルが出力される

❯ find payment-app -type d -name target | xargs jdeps

target -> java.base
target -> payment-app\utility\target
target -> 見つかりません
   jp.co.tis.lerna.payment.adapter.ecpayment.issuing  -> java.lang                                         java.base
   jp.co.tis.lerna.payment.adapter.ecpayment.issuing  -> jp.co.tis.lerna.payment.adapter.ecpayment.issuing.model target
   jp.co.tis.lerna.payment.adapter.ecpayment.issuing  -> jp.co.tis.lerna.payment.utility                    target

パッケージ同士の依存関係が依存元、依存先、モジュール名 or ディレクトリ名の順で出る。パッケージの依存関係とは別の形式でクラスファイルがあるディレクトリ 'target' が依存するディレクトリやモジュールの依存関係も出る。java.base はモジュール名みたい。

java.base: https://docs.oracle.com/en/java/javase/11/docs/api/java.base/module-summary.html

-verbose オプションを指定

❯ find payment-app -type d -name target | xargs jdeps -verbose

target -> java.base
target -> payment-app\utility\target
target -> 見つかりません
   jp.co.tis.lerna.payment.adapter.ecpayment.issuing.IssuingServiceECPaymentApplication -> java.lang.Object                                   java.base
   jp.co.tis.lerna.payment.adapter.ecpayment.issuing.IssuingServiceECPaymentApplication -> jp.co.tis.lerna.payment.adapter.ecpayment.issuing.model.PaymentCancelParameter target
   jp.co.tis.lerna.payment.adapter.ecpayment.issuing.IssuingServiceECPaymentApplication -> jp.co.tis.lerna.payment.adapter.ecpayment.issuing.model.PaymentParameter target

パッケージ同士の依存関係の代わりにクラス同士の依存関係が出る。

-summary オプションを指定

❯ find payment-app -type d -name target | xargs jdeps -summary

target -> java.base
target -> payment-app\utility\target
target -> 見つかりません
target -> java.base

クラスファイルがあるディレクトリが依存するモジュールやディレクトリのみ出る。

この情報は今回の分析対象からは外していいかも。