[infer][PR] [mvn] Handle recursive modules

Summary:
Don't assume pom.xml is always stored in init_work_dir/MODULE.
Use directory of the parent pom.xml instead.

Fixes  reading of invalid pom.xml filenames when using > 1 levels of modules. [Apache Beam](https://github.com/apache/beam):

> infer  -g --print-logs --  mvn -pl 'org.apache.beam:beam-sdks-java-io-jdbc' compile
> Infer version v0.10.0-1580e5b3
> Copyright 2009 - present Facebook. All Rights Reserved.
> INFER_ARGS = -g^--print-logs
> rest arg: compile
> rest arg: org.apache.beam:beam-sdks-java-io-jdbc
> rest arg: -pl
> rest arg: mvn
> Project root = /home/juergen/java/beam
> CWD = /home/juergen/java/beam
> Driver mode:
> Maven driver mode:
> prog = mvn
> Arg: -pl
> Arg: org.apache.beam:beam-sdks-java-io-jdbc
> Arg: compile
>
> Capturing in maven mode...
> Adding maven module /home/juergen/java/beam/sdks/java/build-tools
> Adding maven module /home/juergen/java/beam/sdks
> Adding maven module /home/juergen/java/beam/runners
> Adding maven module /home/juergen/java/beam/example
Closes https://github.com/facebook/infer/pull/593

Reviewed By: sblackshear

Differential Revision: D4627315

Pulled By: jvillard

fbshipit-source-id: 7ba33cc
master
Juergen Hoetzel 8 years ago committed by Facebook Github Bot
parent 9147e071f3
commit fbaa1988b3

@ -37,7 +37,7 @@ let infer_profile = lazy
let pom_worklist = ref [CLOpt.init_work_dir] let pom_worklist = ref [CLOpt.init_work_dir]
let add_infer_profile_to_xml maven_xml infer_xml = let add_infer_profile_to_xml dir maven_xml infer_xml =
let copy xml_in xml_out = Xmlm.output xml_out (Xmlm.input xml_in) in let copy xml_in xml_out = Xmlm.output xml_out (Xmlm.input xml_in) in
(* whether we ever found a <profiles> tag *) (* whether we ever found a <profiles> tag *)
let found_profiles_tag = ref false in let found_profiles_tag = ref false in
@ -90,7 +90,7 @@ let add_infer_profile_to_xml maven_xml infer_xml =
L.do_out "Found infer profile, not adding one@."; L.do_out "Found infer profile, not adding one@.";
found_infer_profile := true found_infer_profile := true
| "module"::"modules"::_ -> | "module"::"modules"::_ ->
let abs_data = CLOpt.init_work_dir ^/ data in let abs_data = dir ^/ data in
L.do_out "Adding maven module %s@." abs_data; L.do_out "Adding maven module %s@." abs_data;
pom_worklist := abs_data::!pom_worklist pom_worklist := abs_data::!pom_worklist
| _ -> () | _ -> ()
@ -118,7 +118,7 @@ let add_infer_profile mvn_pom infer_pom =
let with_ic () = let with_ic () =
let xml_in = Xmlm.make_input ~strip:false (`Channel ic) in let xml_in = Xmlm.make_input ~strip:false (`Channel ic) in
let xml_out = Xmlm.make_output ~nl:true (`Channel out_chan) in let xml_out = Xmlm.make_output ~nl:true (`Channel out_chan) in
add_infer_profile_to_xml xml_in xml_out in add_infer_profile_to_xml (Filename.dirname mvn_pom) xml_in xml_out in
protect ~f:with_ic ~finally:(fun () -> In_channel.close ic) in protect ~f:with_ic ~finally:(fun () -> In_channel.close ic) in
Utils.with_file infer_pom ~f:with_oc Utils.with_file infer_pom ~f:with_oc

@ -0,0 +1,13 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.mycompany</groupId>
<artifactId>module2parent</artifactId>
<version>1.0-SNAPSHOT</version>
</parent>
<artifactId>module2</artifactId>
<packaging>jar</packaging>
<version>1.0-SNAPSHOT</version>
<name>module2</name>
</project>

@ -2,10 +2,13 @@
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
<groupId>com.mycompany</groupId> <groupId>com.mycompany</groupId>
<artifactId>module2</artifactId> <artifactId>module2parent</artifactId>
<packaging>jar</packaging>
<version>1.0-SNAPSHOT</version> <version>1.0-SNAPSHOT</version>
<name>module2</name> <name>module2parent</name>
<packaging>pom</packaging>
<modules>
<module>module2</module>
</modules>
<dependencies> <dependencies>
<dependency> <dependency>
<groupId>com.mycompany</groupId> <groupId>com.mycompany</groupId>

@ -9,6 +9,6 @@
<url>http://maven.apache.org</url> <url>http://maven.apache.org</url>
<modules> <modules>
<module>module1</module> <module>module1</module>
<module>module2</module> <module>module2parent</module>
</modules> </modules>
</project> </project>

@ -1,7 +1,7 @@
-- app_with_submodules -- app_with_submodules
build_systems/codetoanalyze/mvn/app_with_submodules/module2/src/main/java/com/mycompany/Hello2.java, void Hello2.mayCauseNPE2(), 4, NULL_DEREFERENCE, [start of procedure mayCauseNPE2(),start of procedure mayReturnNull(...),Taking false branch,return from a call to Pointers$A Pointers.mayReturnNull(int)] build_systems/codetoanalyze/mvn/app_with_submodules/module2parent/module2/src/main/java/com/mycompany/Hello2.java, void Hello2.mayCauseNPE2(), 4, NULL_DEREFERENCE, [start of procedure mayCauseNPE2(),start of procedure mayReturnNull(...),Taking false branch,return from a call to Pointers$A Pointers.mayReturnNull(int)]
build_systems/codetoanalyze/mvn/app_with_submodules/module2/src/main/java/com/mycompany/Hello2.java, void Hello2.mayLeakResource2(), 7, RESOURCE_LEAK, [start of procedure mayLeakResource2(),start of procedure allocateResource(),return from a call to FileOutputStream Resources.allocateResource(),Taking false branch] build_systems/codetoanalyze/mvn/app_with_submodules/module2parent/module2/src/main/java/com/mycompany/Hello2.java, void Hello2.mayLeakResource2(), 7, RESOURCE_LEAK, [start of procedure mayLeakResource2(),start of procedure allocateResource(),return from a call to FileOutputStream Resources.allocateResource(),Taking false branch]
build_systems/codetoanalyze/mvn/app_with_submodules/module2/src/main/java/com/mycompany/Hello2.java, void Hello2.twoResources2(), 11, RESOURCE_LEAK, [start of procedure twoResources2(),Taking true branch,exception java.io.IOException] build_systems/codetoanalyze/mvn/app_with_submodules/module2parent/module2/src/main/java/com/mycompany/Hello2.java, void Hello2.twoResources2(), 11, RESOURCE_LEAK, [start of procedure twoResources2(),Taking true branch,exception java.io.IOException]
build_systems/codetoanalyze/mvn/simple_app/src/main/java/com/mycompany/Hello.java, void Hello.mayCauseNPE(), 4, NULL_DEREFERENCE, [start of procedure mayCauseNPE(),start of procedure mayReturnNull(...),Taking false branch,return from a call to Pointers$A Pointers.mayReturnNull(int)] build_systems/codetoanalyze/mvn/simple_app/src/main/java/com/mycompany/Hello.java, void Hello.mayCauseNPE(), 4, NULL_DEREFERENCE, [start of procedure mayCauseNPE(),start of procedure mayReturnNull(...),Taking false branch,return from a call to Pointers$A Pointers.mayReturnNull(int)]
build_systems/codetoanalyze/mvn/simple_app/src/main/java/com/mycompany/Hello.java, void Hello.mayLeakResource(), 7, RESOURCE_LEAK, [start of procedure mayLeakResource(),start of procedure allocateResource(),return from a call to FileOutputStream Resources.allocateResource(),Taking false branch] build_systems/codetoanalyze/mvn/simple_app/src/main/java/com/mycompany/Hello.java, void Hello.mayLeakResource(), 7, RESOURCE_LEAK, [start of procedure mayLeakResource(),start of procedure allocateResource(),return from a call to FileOutputStream Resources.allocateResource(),Taking false branch]
build_systems/codetoanalyze/mvn/simple_app/src/main/java/com/mycompany/Hello.java, void Hello.twoResources(), 11, RESOURCE_LEAK, [start of procedure twoResources(),Taking true branch,exception java.io.IOException] build_systems/codetoanalyze/mvn/simple_app/src/main/java/com/mycompany/Hello.java, void Hello.twoResources(), 11, RESOURCE_LEAK, [start of procedure twoResources(),Taking true branch,exception java.io.IOException]

Loading…
Cancel
Save