Skip to content

Commit

Permalink
Skip module-info files in output_jar
Browse files Browse the repository at this point in the history
bazelbuild/rules_java#260

PiperOrigin-RevId: 713312008
Change-Id: Ifaab4668abbf680912ded440e42bafe0cca7ec27
  • Loading branch information
cushon authored and copybara-github committed Jan 8, 2025
1 parent 60e0aa9 commit 4e597f2
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 2 deletions.
3 changes: 2 additions & 1 deletion src/tools/singlejar/options.cc
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,8 @@ bool Options::ParseToken(ArgTokenStream *tokens) {
tokens->MatchAndSet("--hermetic_java_home", &hermetic_java_home) ||
tokens->MatchAndSet("--add_exports", &add_exports) ||
tokens->MatchAndSet("--add_opens", &add_opens) ||
tokens->MatchAndSet("--output_jar_creator", &output_jar_creator)) {
tokens->MatchAndSet("--output_jar_creator", &output_jar_creator) ||
tokens->MatchAndSet("--no_strip_module_info", &no_strip_module_info)) {
return true;
} else if (tokens->MatchAndSet("--build_info_file", &optarg)) {
build_info_files.push_back(optarg);
Expand Down
4 changes: 3 additions & 1 deletion src/tools/singlejar/options.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ class Options {
verbose(false),
warn_duplicate_resources(false),
check_desugar_deps(false),
multi_release(false) {}
multi_release(false),
no_strip_module_info(false) {}

virtual ~Options() {}

Expand Down Expand Up @@ -69,6 +70,7 @@ class Options {
bool warn_duplicate_resources;
bool check_desugar_deps;
bool multi_release;
bool no_strip_module_info;
std::string hermetic_java_home;
std::vector<std::string> add_exports;
std::vector<std::string> add_opens;
Expand Down
12 changes: 12 additions & 0 deletions src/tools/singlejar/output_jar.cc
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
#include <sys/stat.h>
#include <time.h>

#include <cstring>

#ifndef _WIN32
#include <unistd.h>
#else
Expand Down Expand Up @@ -369,6 +371,16 @@ bool OutputJar::AddJar(int jar_path_index) {
continue;
}

// Skip module-info.class files
// Deploy jars are not modularized jars, and including module-infos from
// modularized dependencies doesn't work. See also b/204112761.
if (!options_->no_strip_module_info &&
(!strncmp(file_name, "module-info.class", file_name_length) ||
(begins_with(file_name, file_name_length, "META-INF/versions/") &&
ends_with(file_name, file_name_length, "/module-info.class")))) {
continue;
}

bool include_entry = true;
if (!options_->include_prefixes.empty()) {
for (auto &prefix : options_->include_prefixes) {
Expand Down

0 comments on commit 4e597f2

Please sign in to comment.