Kengo's blog

Technical articles about original projects, JVM, Static Analysis and TypeScript.

PMD ruleset for SLF4J

 I wanted to use ruleset to validate my codes so I asked to ML of SLF4J, but there is no tool to help. So I've created a PMD ruleset for SLF4J. It may help to code with unified valid logging.
 コードを統一するためのルールセットがほしくてSLF4JのMLに問い合わせてみたのですが、特に存在しないようなので自分で書いてみました。簡単なPMDのルールセットで、コードの統一に役立つはずです。

How to use

 If you have already used PMD ruleset, you can use this package as it. Please type `mvn clean package` in the ruleset directory. The xml file is here.
 PMDの外部ルールセットを既に利用したことがある方は、ビルドの成果物をルールセットとしてご利用ください。rulesetディレクトリ`mvn clean package`と実行することでjarが作成されます。xmlファイルはここにあります。

 If you don't have, you can learn how to use at official site, but I recommend to use Sonar plugin which I'll explain. Original PMD ruleset is not easy to use I think.
 PMDルールセットを使ったことがない方には(使い方を公式ページで調べることもできますが)次に紹介するSonarプラグインを利用することをオススメします。PMD独自ルールセットは正直使いにくいです。

Install Sonar plugin to your sonar

 My product has sonar-plugin module. To create plugin file, please type `mvn clean package` in this module. You can find jar file in target directory after building, so please copy it to ${sonar.home}/extensions/plugin. Your Sonar will read this jar and use it.
 sonar-pluginモジュールを用意していますので、こちらで`mvn clean package`してSonarプラグインを作成してください。targetディレクトリにできたjarファイルを${sonar.home}/extensions/pluginに突っ込んでやるだけで使えます。Sonarえらい。


Next step

 It has only 4 rules but I plan to enhance -- for example, joining String and avoid to use LoggerFactory in method. I think this is simple and effective tool to help coding. Please try to use and fork it!
 まだ4つのルールしか持っていませんが、今後すこしずつ機能拡充しようと思っています。Stringの結合周りとかLoggerFactoryをメソッド内で使うなとか。地味に役立つツールだと思いますのでぜひお試しください。