-
Notifications
You must be signed in to change notification settings - Fork 274
unify jar list and classpath #2763
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Changes from 2 commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,7 +13,6 @@ Author: Daniel Kroening, [email protected] | |
|
||
#include <util/suffix.h> | ||
#include <util/prefix.h> | ||
#include <util/config.h> | ||
|
||
#include "java_bytecode_parser.h" | ||
|
||
|
@@ -69,6 +68,19 @@ java_class_loadert::parse_tree_with_overlayst &java_class_loadert::operator()( | |
return class_map.at(class_name); | ||
} | ||
|
||
void java_class_loadert::add_classpath_entry(const std::string &path) | ||
{ | ||
if(has_suffix(path, ".jar")) | ||
{ | ||
classpath_entries.push_back(classpath_entryt(classpath_entryt::JAR, path)); | ||
} | ||
else | ||
{ | ||
classpath_entries.push_back( | ||
classpath_entryt(classpath_entryt::DIRECTORY, path)); | ||
} | ||
} | ||
|
||
optionalt<java_bytecode_parse_treet> java_class_loadert::get_class_from_jar( | ||
const irep_idt &class_name, | ||
const std::string &jar_file, | ||
|
@@ -124,55 +136,47 @@ java_class_loadert::get_parse_tree( | |
return parse_trees; | ||
} | ||
|
||
// First add all given JAR files | ||
for(const auto &jar_file : jar_files) | ||
// Rummage through the class path | ||
for(const auto &cp_entry : classpath_entries) | ||
{ | ||
jar_index_optcreft index = read_jar_file(jar_file); | ||
if(!index) | ||
continue; | ||
optionalt<java_bytecode_parse_treet> parse_tree = | ||
get_class_from_jar(class_name, jar_file, *index); | ||
if(parse_tree) | ||
parse_trees.emplace_back(std::move(*parse_tree)); | ||
} | ||
|
||
// Then add everything on the class path | ||
for(const auto &cp_entry : config.java.classpath) | ||
{ | ||
if(has_suffix(cp_entry, ".jar")) | ||
{ | ||
jar_index_optcreft index = read_jar_file(cp_entry); | ||
if(!index) | ||
continue; | ||
optionalt<java_bytecode_parse_treet> parse_tree = | ||
get_class_from_jar(class_name, cp_entry, *index); | ||
if(parse_tree) | ||
parse_trees.emplace_back(std::move(*parse_tree)); | ||
} | ||
else | ||
switch(cp_entry.kind) | ||
{ | ||
// Look in the given directory | ||
const std::string class_file = class_name_to_file(class_name); | ||
const std::string full_path = | ||
#ifdef _WIN32 | ||
cp_entry + '\\' + class_file; | ||
#else | ||
cp_entry + '/' + class_file; | ||
#endif | ||
|
||
if(!class_loader_limit.load_class_file(class_file)) | ||
continue; | ||
|
||
if(std::ifstream(full_path)) | ||
case classpath_entryt::JAR: | ||
{ | ||
debug() | ||
<< "Getting class `" << class_name << "' from file " << full_path | ||
<< eom; | ||
jar_index_optcreft index = read_jar_file(cp_entry.path); | ||
if(!index) | ||
continue; | ||
optionalt<java_bytecode_parse_treet> parse_tree = | ||
java_bytecode_parse(full_path, get_message_handler()); | ||
get_class_from_jar(class_name, cp_entry.path, *index); | ||
if(parse_tree) | ||
parse_trees.emplace_back(std::move(*parse_tree)); | ||
} | ||
break; | ||
|
||
case classpath_entryt::DIRECTORY: | ||
{ | ||
// Look in the given directory | ||
const std::string class_file = class_name_to_file(class_name); | ||
const std::string full_path = | ||
#ifdef _WIN32 | ||
cp_entry.path + '\\' + class_file; | ||
#else | ||
cp_entry.path + '/' + class_file; | ||
#endif | ||
|
||
if(!class_loader_limit.load_class_file(class_file)) | ||
continue; | ||
|
||
if(std::ifstream(full_path)) | ||
{ | ||
debug() << "Getting class `" << class_name << "' from file " | ||
<< full_path << eom; | ||
optionalt<java_bytecode_parse_treet> parse_tree = | ||
java_bytecode_parse(full_path, get_message_handler()); | ||
if(parse_tree) | ||
parse_trees.emplace_back(std::move(*parse_tree)); | ||
} | ||
} | ||
} | ||
} | ||
|
||
|
@@ -234,12 +238,13 @@ void java_class_loadert::load_entire_jar( | |
if(!jar_index) | ||
return; | ||
|
||
jar_files.push_front(jar_path); | ||
classpath_entries.push_front( | ||
classpath_entryt(classpath_entryt::JAR, jar_path)); | ||
|
||
for(const auto &e : jar_index->get()) | ||
operator()(e.first); | ||
|
||
jar_files.pop_front(); | ||
classpath_entries.pop_front(); | ||
} | ||
|
||
java_class_loadert::jar_index_optcreft java_class_loadert::read_jar_file( | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -74,11 +74,19 @@ class java_class_loadert:public messaget | |
for(const auto &id : classes) | ||
java_load_classes.push_back(id); | ||
} | ||
void add_jar_file(const std::string &f) | ||
|
||
/// Clear all classpath entries | ||
void clear_classpath() | ||
{ | ||
jar_files.push_back(f); | ||
classpath_entries.clear(); | ||
} | ||
|
||
/// Appends an entry to the class path, used for loading classes. The | ||
/// argument may be | ||
/// 1) The name of a directory, used for searching for .class files | ||
/// 2) The name of a JAR file | ||
void add_classpath_entry(const std::string &); | ||
|
||
static std::string file_to_class_name(const std::string &); | ||
static std::string class_name_to_file(const irep_idt &); | ||
|
||
|
@@ -111,10 +119,21 @@ class java_class_loadert:public messaget | |
/// information. | ||
std::string java_cp_include_files; | ||
|
||
/// List of filesystem paths to .jar files that will be used, in the given | ||
/// order, to find and load a class, provided its name (see \ref | ||
/// get_parse_tree). | ||
std::list<std::string> jar_files; | ||
/// An entry in the classpath | ||
struct classpath_entryt | ||
{ | ||
using kindt = enum { JAR, DIRECTORY }; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. An enum class provides no obvious benefit here -- the namespace isn't crowded. |
||
kindt kind; | ||
std::string path; | ||
|
||
classpath_entryt(kindt _kind, const std::string &_path) | ||
: kind(_kind), path(_path) | ||
{ | ||
} | ||
}; | ||
|
||
/// List of entries in the classpath | ||
std::list<classpath_entryt> classpath_entries; | ||
|
||
/// Classes to be explicitly loaded | ||
std::vector<irep_idt> java_load_classes; | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
isn't this already checked above?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Indeed, removed that.