Skip to content
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

list_packages should not fail when the jar is invalid #867

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,13 @@ maven_install(
group = "com.sun.xml.bind",
version = "2.3.6",
),
# https://github.com/bazelbuild/rules_jvm_external/issues/865
maven.artifact(
artifact = "google-api-services-compute",
classifier = "javadoc",
group = "com.google.apis",
version = "v1-rev235-1.25.0",
),
],
generate_compat_repositories = True,
maven_install_json = "//tests/custom_maven_install:regression_testing_install.json",
Expand Down Expand Up @@ -615,6 +622,16 @@ http_file(
],
)

# https://github.com/bazelbuild/rules_jvm_external/issues/865
http_file(
name = "google_api_services_compute_javadoc_for_test",
downloaded_file_path = "google-api-services-compute-v1-rev235-1.25.0-javadoc.jar",
sha256 = "b03be5ee8effba3bfbaae53891a9c01d70e2e3bd82ad8889d78e641b22bd76c2",
urls = [
"https://repo1.maven.org/maven2/com/google/apis/google-api-services-compute/v1-rev235-1.25.0/google-api-services-compute-v1-rev235-1.25.0-javadoc.jar",
],
)

# End test dependencies

http_archive(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import java.util.regex.Pattern;
import java.util.stream.Collectors;
import java.util.zip.ZipEntry;
import java.util.zip.ZipException;
import java.util.zip.ZipInputStream;

public class ListPackages {
Expand Down Expand Up @@ -57,17 +58,20 @@ public static SortedSet<String> process(Path path) throws IOException {
SortedSet<String> packages = new TreeSet<>();
try (InputStream fis = new BufferedInputStream(Files.newInputStream(path));
ZipInputStream zis = new ZipInputStream(fis)) {

ZipEntry entry;
while ((entry = zis.getNextEntry()) != null) {
if (!entry.getName().endsWith(".class")) {
continue;
}
if ("module-info.class".equals(entry.getName())
|| entry.getName().endsWith("/module-info.class")) {
continue;
try {
ZipEntry entry;
while ((entry = zis.getNextEntry()) != null) {
if (!entry.getName().endsWith(".class")) {
continue;
}
if ("module-info.class".equals(entry.getName())
|| entry.getName().endsWith("/module-info.class")) {
continue;
}
packages.add(extractPackageName(entry.getName()));
}
packages.add(extractPackageName(entry.getName()));
} catch (ZipException e) {
System.err.printf("Caught ZipException: %s%n", e);
}
}
return packages;
Expand Down
6 changes: 3 additions & 3 deletions private/tools/prebuilt/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
# To update the prebuilt binaries, `bazel run //scripts:refresh-prebuilts`

exports_files([
"hasher_deploy.jar", # built from //private/tools/java/rules/jvm/external:hasher-tool_deploy.jar
"list_packages_deploy.jar", # built from //private/tools/java/rules/jvm/external/jar:ListPackages_deploy.jar
"hasher_deploy.jar", # built from //private/tools/java/com/github/bazelbuild/rules_jvm_external:hasher-tool_deploy.jar
"list_packages_deploy.jar", # built from //private/tools/java/com/github/bazelbuild/rules_jvm_external/jar:ListPackages_deploy.jar
"lock_file_converter_deploy.jar", # built from //private/tools/java/com/github/bazelbuild/rules_jvm_external/coursier:LockFileConverter_deploy.jar
"outdated_deploy.jar", # built from //private/tools/java/rules/jvm/external/maven:outdated_deploy.jar
"outdated_deploy.jar", # built from //private/tools/java/com/github/bazelbuild/rules_jvm_external/maven:outdated_deploy.jar
])
Binary file modified private/tools/prebuilt/list_packages_deploy.jar
Binary file not shown.
1 change: 1 addition & 0 deletions tests/com/github/bazelbuild/rules_jvm_external/jar/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ java_test(
name = "ListPackagesTest",
srcs = ["ListPackagesTest.java"],
data = [
"@google_api_services_compute_javadoc_for_test//file",
"@gson_for_test//file",
"@hamcrest_core_for_test//file",
"@hamcrest_core_srcs_for_test//file",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,12 @@ public void noPackages() throws Exception {
doTest("hamcrest_core_srcs_for_test/file/hamcrest-core-1.3-sources.jar");
}

@Test
public void invalidCRC() throws Exception {
doTest(
"google_api_services_compute_javadoc_for_test/file/google-api-services-compute-v1-rev235-1.25.0-javadoc.jar");
}

private void doTest(String runfileJar, String... expectedPackages) throws IOException {
SortedSet<String> expected = sortedSet(expectedPackages);
Path jar = Paths.get(Runfiles.create().rlocation(runfileJar));
Expand Down
Loading