diff options
author | 2015-12-03 18:23:09 +0000 | |
---|---|---|
committer | 2015-12-03 18:39:00 +0000 | |
commit | 220be7a7362bb27f3a23b2328b36d1a55f6f9197 (patch) | |
tree | 559e6c9a458305c84b28c191265413cf2c5c2662 /third_party/ijar/test | |
parent | 188d8eb7838ecc8aeaa9ba146908e2ad2db7de03 (diff) |
Add zip64 support to ijar
This allows ijar to process jars with >65535 entries.
--
MOS_MIGRATED_REVID=109321374
Diffstat (limited to 'third_party/ijar/test')
-rw-r--r-- | third_party/ijar/test/BUILD | 34 | ||||
-rw-r--r-- | third_party/ijar/test/GenZipWithEntries.java | 64 | ||||
-rw-r--r-- | third_party/ijar/test/ZipCount.java | 36 | ||||
-rwxr-xr-x | third_party/ijar/test/ijar_test.sh | 21 |
4 files changed, 154 insertions, 1 deletions
diff --git a/third_party/ijar/test/BUILD b/third_party/ijar/test/BUILD index 05bca7c100..15ebdb37ea 100644 --- a/third_party/ijar/test/BUILD +++ b/third_party/ijar/test/BUILD @@ -18,6 +18,7 @@ sh_test( # We assume unzip and zip to be on the path "unzip", "zip", + "$(location :zip_count)", ], data = [ "testenv.sh", @@ -31,6 +32,10 @@ sh_test( ":libtypeannotations2.jar", ":libmethodparameters.jar", ":source_debug_extension.jar", + ":largest_regular.jar", + ":smallest_zip64.jar", + ":definitely_zip64.jar", + ":zip_count", "TypeAnnotationTest2.java", # invokedynamic/ClassWithLambda.java, compiled with javac8 ":libinvokedynamic.jar", @@ -151,3 +156,32 @@ test_suite( testonly = 1, visibility = ["//visibility:public"], ) + +java_binary( + name = "gen_zip_with_entries", + srcs = ["GenZipWithEntries.java"], + jvm_flags = ["-Djdk.util.zip.inhibitZip64=false"], + main_class = "test.GenZipWithEntries", + deps = ["//third_party:asm"], +) + +[ + genrule( + name = name, + outs = [name + ".jar"], + cmd = "$(location :gen_zip_with_entries) %s $@" % entries, + tools = [":gen_zip_with_entries"], + ) + for name, entries in [ + ("largest_regular", 65535), + ("smallest_zip64", 65536), + ("definitely_zip64", 70000), + ] +] + +java_binary( + name = "zip_count", + srcs = ["ZipCount.java"], + jvm_flags = ["-Djdk.util.zip.inhibitZip64=false"], + main_class = "test.ZipCount", +) diff --git a/third_party/ijar/test/GenZipWithEntries.java b/third_party/ijar/test/GenZipWithEntries.java new file mode 100644 index 0000000000..1654e7abc3 --- /dev/null +++ b/third_party/ijar/test/GenZipWithEntries.java @@ -0,0 +1,64 @@ +// Copyright 2015 The Bazel Authors. All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package test; + +import org.objectweb.asm.ClassWriter; +import org.objectweb.asm.MethodVisitor; +import org.objectweb.asm.Opcodes; + +import java.io.IOException; +import java.io.OutputStream; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.util.jar.JarOutputStream; +import java.util.zip.ZipEntry; + +/** + * Generates a jar file with the specified number of .class entries. + * + * usage: GenZipWithEntries <number of zip entries> <output file> + */ +public class GenZipWithEntries { + + public static void main(String[] args) throws IOException { + int entries = Integer.parseInt(args[0]); + Path out = Paths.get(args[1]); + try (OutputStream os = Files.newOutputStream(out); + JarOutputStream jos = new JarOutputStream(os)) { + for (int i = 1; i <= entries; i++) { + String name = String.format("Test%d", i); + jos.putNextEntry(new ZipEntry(String.format("%s.class", name))); + jos.write(dump(name)); + } + } + } + + public static byte[] dump(String name) { + ClassWriter cw = new ClassWriter(0); + cw.visit(52, Opcodes.ACC_PUBLIC + Opcodes.ACC_SUPER, name, null, "java/lang/Object", null); + { + MethodVisitor mv = cw.visitMethod(Opcodes.ACC_PUBLIC, "<init>", "()V", null, null); + mv.visitCode(); + mv.visitVarInsn(Opcodes.ALOAD, 0); + mv.visitMethodInsn(Opcodes.INVOKESPECIAL, "java/lang/Object", "<init>", "()V", false); + mv.visitInsn(Opcodes.RETURN); + mv.visitMaxs(1, 1); + mv.visitEnd(); + } + cw.visitEnd(); + return cw.toByteArray(); + } +} diff --git a/third_party/ijar/test/ZipCount.java b/third_party/ijar/test/ZipCount.java new file mode 100644 index 0000000000..c72e8498f6 --- /dev/null +++ b/third_party/ijar/test/ZipCount.java @@ -0,0 +1,36 @@ +// Copyright 2015 The Bazel Authors. All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package test; + +import java.io.IOException; +import java.util.zip.ZipFile; + +/** + * Checks the number of entries in a zip file. + * + * <p>usage: ZipCount <zip file> <expected entries> + */ +public class ZipCount { + public static void main(String[] args) throws IOException { + int expect = Integer.parseInt(args[1]); + int count; + try (ZipFile zf = new ZipFile(args[0])) { + count = zf.size(); + } + if (count != expect) { + throw new AssertionError(String.format("expected %d entries, saw %d", expect, count)); + } + } +} diff --git a/third_party/ijar/test/ijar_test.sh b/third_party/ijar/test/ijar_test.sh index 6f1a241df9..93f858690c 100755 --- a/third_party/ijar/test/ijar_test.sh +++ b/third_party/ijar/test/ijar_test.sh @@ -35,6 +35,8 @@ UNZIP=$1 shift ZIP=$1 shift +ZIP_COUNT=$1 +shift ## Test framework source ${DIR}/testenv.sh || { echo "testenv.sh not found!" >&2; exit 1; } @@ -48,6 +50,7 @@ source ${DIR}/testenv.sh || { echo "testenv.sh not found!" >&2; exit 1; } [[ "$UNZIP" =~ ^(/|[^/]+$) ]] || UNZIP="$PWD/$UNZIP" [[ "$ZIP" =~ ^(/|[^/]+$) ]] || ZIP="$PWD/$ZIP" [[ "$JAVAP" =~ ^(/|[^/]+$) ]] || JAVAP="$PWD/$JAVAP" +[[ "$ZIP_COUNT" =~ ^(/|[^/]+$) ]] || ZIP_COUNT="$PWD/$ZIP_COUNT" IJAR_SRCDIR=$(dirname ${IJAR}) A_JAR=$TEST_TMPDIR/A.jar @@ -70,6 +73,9 @@ METHODPARAM_JAR=$IJAR_SRCDIR/test/libmethodparameters.jar METHODPARAM_IJAR=$TEST_TMPDIR/methodparameters_interface.jar SOURCEDEBUGEXT_JAR=$IJAR_SRCDIR/test/source_debug_extension.jar SOURCEDEBUGEXT_IJAR=$TEST_TMPDIR/source_debug_extension.jar +CENTRAL_DIR_LARGEST_REGULAR=$IJAR_SRCDIR/test/largest_regular.jar +CENTRAL_DIR_SMALLEST_ZIP64=$IJAR_SRCDIR/test/smallest_zip64.jar +CENTRAL_DIR_ZIP64=$IJAR_SRCDIR/test/definitely_zip64.jar #### Setup @@ -515,6 +521,19 @@ function test_source_debug_extension_attribute() { expect_not_log "SourceDebugExtension" "SourceDebugExtension preserved!" } -SOURCEDEBUGEXT_JAR=$IJAR_SRCDIR/test/source_debug_extension.jar +function test_central_dir_largest_regular() { + $IJAR $CENTRAL_DIR_LARGEST_REGULAR $TEST_TMPDIR/ijar.jar || fail "ijar failed" + $ZIP_COUNT $TEST_TMPDIR/ijar.jar 65535 || fail +} + +function test_central_dir_smallest_zip64() { + $IJAR $CENTRAL_DIR_SMALLEST_ZIP64 $TEST_TMPDIR/ijar.jar || fail "ijar failed" + $ZIP_COUNT $TEST_TMPDIR/ijar.jar 65536 || fail +} + +function test_central_dir_zip64() { + $IJAR $CENTRAL_DIR_ZIP64 $TEST_TMPDIR/ijar.jar || fail "ijar failed" + $ZIP_COUNT $TEST_TMPDIR/ijar.jar 70000 || fail +} run_suite "ijar tests" |