@ -63,16 +63,17 @@ let read_package_declaration source_file =
let remove_trailing_semicolon = Str . replace_first ( Str . regexp " ; " ) " " in
let remove_trailing_semicolon = Str . replace_first ( Str . regexp " ; " ) " " in
let empty_package = " " in
let empty_package = " " in
let rec loop () =
let rec loop () =
try
match remove_trailing_semicolon ( In_channel . input_line_exn file_in ) with
let line = remove_trailing_semicolon ( In_channel . input_line_exn file_in ) in
| exception End_of_file ->
In_channel . close file_in ; empty_package
| line -> (
match Str . split ( Str . regexp " [ \t ]+ " ) line with
match Str . split ( Str . regexp " [ \t ]+ " ) line with
| [] ->
| [] ->
loop ()
( loop [ @ tailcall ] ) ()
| [ hd ; package ] when String . equal hd " package " ->
| [ hd ; package ] when String . equal hd " package " ->
package
package
| _ ->
| _ ->
loop ()
( loop [ @ tailcall ] ) () )
with End_of_file -> In_channel . close file_in ; empty_package
in
in
loop ()
loop ()
@ -128,35 +129,36 @@ let load_from_verbose_output javac_verbose_out =
in
in
let classpath_re = Str . regexp " \\ [search path for class files: \\ (.* \\ ) \\ ] " in
let classpath_re = Str . regexp " \\ [search path for class files: \\ (.* \\ ) \\ ] " in
let rec loop paths roots sources classes =
let rec loop paths roots sources classes =
try
match In_channel . input_line_exn file_in with
let line = In_channel . input_line_exn file_in in
| exception End_of_file ->
In_channel . close file_in ;
let classpath = List . fold ~ f : append_path ~ init : " " ( String . Set . elements roots @ paths ) in
( classpath , sources , classes )
| line ->
if Str . string_match class_filename_re line 0 then
if Str . string_match class_filename_re line 0 then
let path =
let path =
try Str . matched_group 5 line with Caml . Not_found ->
try Str . matched_group 5 line with Caml . Not_found ->
(* either matched group 5 is found, or matched group 2 is found, see doc for [class_filename_re] above *)
(* either matched group 5 is found, or matched group 2 is found, see doc for [class_filename_re] above *)
Config . javac_classes_out ^/ Str . matched_group 2 line
Config . javac_classes_out ^/ Str . matched_group 2 line
in
in
let cn , root_info = Javalib . extract_class_name_from_file path in
match Javalib . extract_class_name_from_file path with
| exception ( JBasics . Class_structure_error _ | Invalid_argument _ ) ->
( loop [ @ tailcall ] ) paths roots sources classes
| cn , root_info ->
let root_dir =
let root_dir =
if String . equal root_info " " then Filename . current_dir_name else root_info
if String . equal root_info " " then Filename . current_dir_name else root_info
in
in
loop paths ( add_root_path root_dir roots ) sources ( JBasics . ClassSet . add cn classes )
( loop [ @ tailcall ] ) paths ( add_root_path root_dir roots ) sources
( JBasics . ClassSet . add cn classes )
else if Str . string_match source_filename_re line 0 then
else if Str . string_match source_filename_re line 0 then
let path = Str . matched_group 2 line in
let path = Str . matched_group 2 line in
loop paths roots ( add_source_file path sources ) classes
( loop [ @ tailcall ] ) paths roots ( add_source_file path sources ) classes
else if Str . string_match classpath_re line 0 then
else if Str . string_match classpath_re line 0 then
let classpath = Str . matched_group 1 line in
let classpath = Str . matched_group 1 line in
let parsed_paths = String . split ~ on : ',' classpath in
let parsed_paths = String . split ~ on : ',' classpath in
loop parsed_paths roots sources classes
( loop [ @ tailcall ] ) parsed_paths roots sources classes
else (* skip this line *)
else (* skip this line *)
loop paths roots sources classes
( loop [ @ tailcall ] ) paths roots sources classes
with
| JBasics . Class_structure_error _ | Invalid_argument _ ->
loop paths roots sources classes
| End_of_file ->
In_channel . close file_in ;
let classpath = List . fold ~ f : append_path ~ init : " " ( String . Set . elements roots @ paths ) in
( classpath , sources , classes )
in
in
loop [] String . Set . empty String . Map . empty JBasics . ClassSet . empty
loop [] String . Set . empty String . Map . empty JBasics . ClassSet . empty