静的解析ツールをまさぐっていたところ、
しばらく前にfacebook が Inferという静的解析ツールをオープンソース化しており、
且つ、
Maven Plugin もあったので、使ってみた結果をメモします。
1. 参考サイト
2. 実施したこと
2-1. POMへPlugin定義を追加する。
2-1-1. pom.xmlへpluginの記述を追加。
<plugin>
<groupId>com.anthemengineering.mojo</groupId>
<artifactId>infer-maven-plugin</artifactId>
<version>0.1.0-SNAPSHOT</version>
<configuration>
<consoleOut>false</consoleOut>
</configuration>
<executions>
<execution>
<phase>verify</phase>
<id>infer</id>
<goals>
<goal>infer</goal>
</goals>
</execution>
</executions>
</plugin>
2-1-2. buildを実行したところ、以下のエラーが発生。
Plugin com.anthemengineering.mojo:infer-maven-plugin:0.1.0-SNAPSHOT or one of its dependencies could not be resolved:
Failed to read artifact descriptor for com.anthemengineering.mojo:infer-maven-plugin:jar:0.1.0-SNAPSHOT:
Could not find artifact com.anthemengineering.mojo:infer-maven-plugin:pom:0.1.0-SNAPSHOT -> [Help 1]
To see the full stack trace of the errors, re-run Maven with the -e switch.
Re-run Maven using the -X switch to enable full debug logging.
For more information about the errors and possible solutions, please read the following articles:
2-1-3. pom.xmlのversion記述を変更
- 変更前
<version>0.1.0-SNAPSHOT</version>
- 変更後
<version>0.1.0</version>
2-1-4. buildを実行したところ、以下のエラーが発生。
--- infer-maven-plugin:0.1.0:infer (infer) @ festivals4partypeople-parent ---
Maven-infer-plugin is configured to download Infer. Downloading now.
Invalid URL: %s! Cannot continue Infer check.
java.io.FileNotFoundException: https://github.com/facebook/infer/releases/download/v0.1.0/infer-osx-v0.1.0.tar.xz
at sun.net.www.protocol.http.HttpURLConnection.getInputStream0(HttpURLConnection.java:1835)
at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1440)
at sun.net.www.protocol.https.HttpsURLConnectionImpl.getInputStream(HttpsURLConnectionImpl.java:254)
at org.apache.commons.io.FileUtils.copyURLToFile(FileUtils.java:1489)
at com.anthemengineering.mojo.infer.InferMojo.downloadInfer(InferMojo.java:487)
at com.anthemengineering.mojo.infer.InferMojo.execute(InferMojo.java:166)
at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:101)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:209)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:153)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:145)
at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:84)
at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:59)
at org.apache.maven.lifecycle.internal.LifecycleStarter.singleThreadedBuild(LifecycleStarter.java:183)
at org.apache.maven.lifecycle.internal.LifecycleStarter.execute(LifecycleStarter.java:161)
at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:320)
at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:156)
at org.apache.maven.cli.MavenCli.execute(MavenCli.java:537)
at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:196)
at org.apache.maven.cli.MavenCli.main(MavenCli.java:141)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:497)
at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:290)
at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:230)
at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:409)
at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:352)
------------------------------------------------------------------------
Reactor Summary:
2-1-5. GitHubのIssueを、確認。
INSTALL.md を読んで、インストールしたら、 以下を実施すれば、良いとのこと。
-
プロパティ値 download を [false] にする。
-
PATH を設定するか、 プロパティ値 commandPath に コマンドのフルパスを設定する。
2-1-6. INSTALL.md に従ってインストール
-
環境 sw_vers の実行結果
ProductName: Mac OS X ProductVersion: 10.11.4 BuildVersion: 15E65
-
以下コマンドを実行
brew install autoconf automake opam caskroom/cask/brew-cask && brew cask install caskroom/versions/java7
-
結果
Error: undefined method `<' for nil:NilClass Please report this bug: https://git.io/brew-troubleshooting /usr/local/Library/Homebrew/formula_support.rb:21:in `valid?'
-
こちらで対処して、再度、コマンドを実行。
brew install autoconf automake opam caskroom/cask/brew-cask && brew cask install caskroom/versions/java7
-
infer をインストール
brew install infer
-
結果
==> Downloading https://homebrew.bintray.com/bottles/infer-0.8.0.el_capitan.bottle.tar.gz ######################################################################## 100.0% ==> Pouring infer-0.8.0.el_capitan.bottle.tar.gz 🍺 /usr/local/Cellar/infer/0.8.0: 11,355 files, 692.8M
-
インストール先を確認
which infer
- 結果
/usr/local/bin/infer
2-1-6. pom.xmlを編集
<!-- infer-maven-plugin -->
<plugin>
<groupId>com.anthemengineering.mojo</groupId>
<artifactId>infer-maven-plugin</artifactId>
<version>0.1.0</version>
<configuration>
<download>false</download>
<consoleOut>false</consoleOut>
</configuration>
<executions>
<execution>
<phase>verify</phase>
<id>infer</id>
<goals>
<goal>infer</goal>
</goals>
</execution>
</executions>
</plugin>
Exception occurred while trying to perform Infer execution; output not complete
java.io.IOException: Cannot run program "infer": error=2, No such file or directory
at java.lang.ProcessBuilder.start(ProcessBuilder.java:1048)
at com.anthemengineering.mojo.infer.InferMojo$1.run(InferMojo.java:357)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
2-1-8. inferをPATHに追加。
cd ~
vi .bash_profile
# infer
export PATH=$PATH:"/usr/local/bin/infer"
2-1-9. 再実行結果は変わらない。
Exception occurred while trying to perform Infer execution; output not complete
java.io.IOException: Cannot run program "infer": error=2, No such file or directory
at java.lang.ProcessBuilder.start(ProcessBuilder.java:1048)
at com.anthemengineering.mojo.infer.InferMojo$1.run(InferMojo.java:357)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
2-1-10. pom.xmlを編集
- configuration:inferCommandを追加
<!-- infer-maven-plugin -->
<plugin>
<groupId>com.anthemengineering.mojo</groupId>
<artifactId>infer-maven-plugin</artifactId>
<version>0.1.0</version>
<configuration>
<download>false</download>
<consoleOut>false</consoleOut>
<inferCommand>/usr/local/bin/infer</inferCommand>
</configuration>
<executions>
<execution>
<phase>verify</phase>
<id>infer</id>
<goals>
<goal>infer</goal>
</goals>
</execution>
</executions>
</plugin>
2-1-11. buildを再実行
Infer output can be located at: /Users/kensakurai/Bitbucket/festivals4partypeople_java/festivals4partypeople-models/target/infer-out
Results of Infer check:
No issues found
Infer review complete; 52 files were analyzed for this module, 52 files have been analyzed so far, in total.
以上です。
PATHを設定するも、効かず、
inferCommandにコマンドフルパスを指定することで、
実行できるようになりました。
コメント