@@ -70,7 +70,15 @@ java_class_loadert::parse_tree_with_overlayst &java_class_loadert::operator()(
7070
7171void java_class_loadert::add_classpath_entry (const std::string &path)
7272{
73- classpath_entries.push_back (path);
73+ if (has_suffix (path, " .jar" ))
74+ {
75+ classpath_entries.push_back (classpath_entryt (classpath_entryt::JAR, path));
76+ }
77+ else
78+ {
79+ classpath_entries.push_back (
80+ classpath_entryt (classpath_entryt::DIRECTORY, path));
81+ }
7482}
7583
7684optionalt<java_bytecode_parse_treet> java_class_loadert::get_class_from_jar (
@@ -131,40 +139,44 @@ java_class_loadert::get_parse_tree(
131139 // Rummage through the class path
132140 for (const auto &cp_entry : classpath_entries)
133141 {
134- if ( has_suffix ( cp_entry, " .jar " ) )
142+ switch ( cp_entry. kind )
135143 {
136- jar_index_optcreft index = read_jar_file (cp_entry);
137- if (!index)
138- continue ;
139- optionalt<java_bytecode_parse_treet> parse_tree =
140- get_class_from_jar (class_name, cp_entry, *index);
141- if (parse_tree)
142- parse_trees.emplace_back (std::move (*parse_tree));
143- }
144- else
145- {
146- // Look in the given directory
147- const std::string class_file = class_name_to_file (class_name);
148- const std::string full_path =
149- #ifdef _WIN32
150- cp_entry + ' \\ ' + class_file;
151- #else
152- cp_entry + ' /' + class_file;
153- #endif
154-
155- if (!class_loader_limit.load_class_file (class_file))
156- continue ;
157-
158- if (std::ifstream (full_path))
144+ case classpath_entryt::JAR:
159145 {
160- debug ()
161- << " Getting class ` " << class_name << " ' from file " << full_path
162- << eom ;
146+ jar_index_optcreft index = read_jar_file (cp_entry. path );
147+ if (!index)
148+ continue ;
163149 optionalt<java_bytecode_parse_treet> parse_tree =
164- java_bytecode_parse (full_path, get_message_handler () );
150+ get_class_from_jar (class_name, cp_entry. path , *index );
165151 if (parse_tree)
166152 parse_trees.emplace_back (std::move (*parse_tree));
167153 }
154+ break ;
155+
156+ case classpath_entryt::DIRECTORY:
157+ {
158+ // Look in the given directory
159+ const std::string class_file = class_name_to_file (class_name);
160+ const std::string full_path =
161+ #ifdef _WIN32
162+ cp_entry.path + ' \\ ' + class_file;
163+ #else
164+ cp_entry.path + ' /' + class_file;
165+ #endif
166+
167+ if (!class_loader_limit.load_class_file (class_file))
168+ continue ;
169+
170+ if (std::ifstream (full_path))
171+ {
172+ debug () << " Getting class `" << class_name << " ' from file "
173+ << full_path << eom;
174+ optionalt<java_bytecode_parse_treet> parse_tree =
175+ java_bytecode_parse (full_path, get_message_handler ());
176+ if (parse_tree)
177+ parse_trees.emplace_back (std::move (*parse_tree));
178+ }
179+ }
168180 }
169181 }
170182
@@ -226,7 +238,8 @@ void java_class_loadert::load_entire_jar(
226238 if (!jar_index)
227239 return ;
228240
229- classpath_entries.push_front (jar_path);
241+ classpath_entries.push_front (
242+ classpath_entryt (classpath_entryt::JAR, jar_path));
230243
231244 for (const auto &e : jar_index->get ())
232245 operator ()(e.first );
0 commit comments