diff options
author | Eugene Kliuchnikov <eustas@google.com> | 2017-10-09 17:07:34 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-10-09 17:07:34 +0200 |
commit | 42d78807bb56a336ff6b30d8e9dc14cd1cf8f105 (patch) | |
tree | 171473e64230d3b5dda796ec897b6563d0242b91 /java | |
parent | 4f8cd4c0f4443d51a9603790a445b06c073b7a4d (diff) | |
download | brotli-42d78807bb56a336ff6b30d8e9dc14cd1cf8f105.zip brotli-42d78807bb56a336ff6b30d8e9dc14cd1cf8f105.tar.gz brotli-42d78807bb56a336ff6b30d8e9dc14cd1cf8f105.tar.bz2 |
Improve Bazel/JNI portability (#611)
* Improve Bazel/JNI portability
* Update go and closure bazel addons
Diffstat (limited to 'java')
-rwxr-xr-x | java/org/brotli/integration/BUILD | 10 | ||||
-rwxr-xr-x | java/org/brotli/integration/BrotliJniTestBase.java | 13 | ||||
-rwxr-xr-x | java/org/brotli/wrapper/common/BUILD | 37 | ||||
-rwxr-xr-x | java/org/brotli/wrapper/common/SetRfcDictionaryTest.java | 9 | ||||
-rwxr-xr-x | java/org/brotli/wrapper/common/SetZeroDictionaryTest.java | 9 | ||||
-rwxr-xr-x | java/org/brotli/wrapper/dec/BUILD | 33 | ||||
-rwxr-xr-x | java/org/brotli/wrapper/dec/BrotliDecoderChannelTest.java | 9 | ||||
-rwxr-xr-x | java/org/brotli/wrapper/dec/BrotliInputStreamTest.java | 9 | ||||
-rwxr-xr-x | java/org/brotli/wrapper/dec/DecoderTest.java | 9 | ||||
-rwxr-xr-x | java/org/brotli/wrapper/enc/BUILD | 33 | ||||
-rwxr-xr-x | java/org/brotli/wrapper/enc/BrotliEncoderChannelTest.java | 9 | ||||
-rwxr-xr-x | java/org/brotli/wrapper/enc/BrotliOutputStreamTest.java | 9 | ||||
-rwxr-xr-x | java/org/brotli/wrapper/enc/EncoderTest.java | 10 |
13 files changed, 103 insertions, 96 deletions
diff --git a/java/org/brotli/integration/BUILD b/java/org/brotli/integration/BUILD index ac9bc2c..fc49e28 100755 --- a/java/org/brotli/integration/BUILD +++ b/java/org/brotli/integration/BUILD @@ -2,6 +2,16 @@ # Integration test runner + corpus for Java port of Brotli decoder. java_library( + name = "brotli_jni_test_base", + srcs = ["BrotliJniTestBase.java"], + visibility = [ + "//java/org/brotli/wrapper/common:__pkg__", + "//java/org/brotli/wrapper/dec:__pkg__", + "//java/org/brotli/wrapper/enc:__pkg__", + ], +) + +java_library( name = "bundle_helper", srcs = ["BundleHelper.java"], visibility = [ diff --git a/java/org/brotli/integration/BrotliJniTestBase.java b/java/org/brotli/integration/BrotliJniTestBase.java new file mode 100755 index 0000000..4d699d5 --- /dev/null +++ b/java/org/brotli/integration/BrotliJniTestBase.java @@ -0,0 +1,13 @@ +package org.brotli.integration; + +/** + * Optionally loads brotli JNI wrapper native library. + */ +public class BrotliJniTestBase { + static { + String jniLibrary = System.getProperty("BROTLI_JNI_LIBRARY"); + if (jniLibrary != null) { + System.load(new java.io.File(jniLibrary).getAbsolutePath()); + } + } +}
\ No newline at end of file diff --git a/java/org/brotli/wrapper/common/BUILD b/java/org/brotli/wrapper/common/BUILD index 8623272..8816a20 100755 --- a/java/org/brotli/wrapper/common/BUILD +++ b/java/org/brotli/wrapper/common/BUILD @@ -7,37 +7,32 @@ filegroup( srcs = ["common_jni.cc"], ) -######################################### -# WARNING: do not depend on this target! -######################################### -java_library( - name = "common_no_dictionary_data", - srcs = glob( - ["*.java"], - exclude = ["*Test*.java"], - ), - deps = ["//:jni_no_dictionary_data"], +filegroup( + name = "brotli_jni_no_dictionary_data", + srcs = ["//:brotli_jni_no_dictionary_data.dll"], ) -######################################### -# WARNING: do not depend on this target! -######################################### java_library( name = "common", srcs = glob( ["*.java"], exclude = ["*Test*.java"], ), - deps = ["//:jni"], ) java_test( name = "SetZeroDictionaryTest", size = "small", srcs = ["SetZeroDictionaryTest.java"], - data = ["//:jni_no_dictionary_data"], # Bazel JNI workaround + data = [ + ":brotli_jni_no_dictionary_data", # Bazel JNI workaround + ], + jvm_flags = [ + "-DBROTLI_JNI_LIBRARY=$(location :brotli_jni_no_dictionary_data)", + ], deps = [ - ":common_no_dictionary_data", + ":common", + "//java/org/brotli/integration:brotli_jni_test_base", "//java/org/brotli/wrapper/dec", "@junit_junit//jar", ], @@ -54,11 +49,15 @@ java_test( srcs = ["SetRfcDictionaryTest.java"], data = [ ":rfc_dictionary", - "//:jni_no_dictionary_data", # Bazel JNI workaround + ":brotli_jni_no_dictionary_data", # Bazel JNI workaround + ], + jvm_flags = [ + "-DRFC_DICTIONARY=$(location :rfc_dictionary)", + "-DBROTLI_JNI_LIBRARY=$(location :brotli_jni_no_dictionary_data)", ], - jvm_flags = ["-DRFC_DICTIONARY=$(location :rfc_dictionary)"], deps = [ - ":common_no_dictionary_data", + ":common", + "//java/org/brotli/integration:brotli_jni_test_base", "//java/org/brotli/wrapper/dec", "@junit_junit//jar", ], diff --git a/java/org/brotli/wrapper/common/SetRfcDictionaryTest.java b/java/org/brotli/wrapper/common/SetRfcDictionaryTest.java index 8577800..0c20f1c 100755 --- a/java/org/brotli/wrapper/common/SetRfcDictionaryTest.java +++ b/java/org/brotli/wrapper/common/SetRfcDictionaryTest.java @@ -11,6 +11,7 @@ import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; +import org.brotli.integration.BrotliJniTestBase; import org.brotli.wrapper.dec.BrotliInputStream; import java.io.ByteArrayInputStream; import java.io.FileInputStream; @@ -25,13 +26,7 @@ import org.junit.runners.JUnit4; * Tests for {@link BrotliCommon}. */ @RunWith(JUnit4.class) -public class SetRfcDictionaryTest { - - // TODO: remove when Bazel get JNI support. - static { - System.load(new java.io.File(new java.io.File(System.getProperty("java.library.path")), - "liblibjni_Uno_Udictionary_Udata.so").getAbsolutePath()); - } +public class SetRfcDictionaryTest extends BrotliJniTestBase { @Test public void testRfcDictionaryChecksums() throws IOException, NoSuchAlgorithmException { diff --git a/java/org/brotli/wrapper/common/SetZeroDictionaryTest.java b/java/org/brotli/wrapper/common/SetZeroDictionaryTest.java index 9046e31..669939c 100755 --- a/java/org/brotli/wrapper/common/SetZeroDictionaryTest.java +++ b/java/org/brotli/wrapper/common/SetZeroDictionaryTest.java @@ -9,6 +9,7 @@ package org.brotli.wrapper.common; import static org.junit.Assert.assertArrayEquals; import static org.junit.Assert.assertEquals; +import org.brotli.integration.BrotliJniTestBase; import org.brotli.wrapper.dec.BrotliInputStream; import java.io.ByteArrayInputStream; import java.io.IOException; @@ -20,13 +21,7 @@ import org.junit.runners.JUnit4; * Tests for {@link BrotliCommon}. */ @RunWith(JUnit4.class) -public class SetZeroDictionaryTest { - - // TODO: remove when Bazel get JNI support. - static { - System.load(new java.io.File(new java.io.File(System.getProperty("java.library.path")), - "liblibjni_Uno_Udictionary_Udata.so").getAbsolutePath()); - } +public class SetZeroDictionaryTest extends BrotliJniTestBase { @Test public void testZeroDictionary() throws IOException { diff --git a/java/org/brotli/wrapper/dec/BUILD b/java/org/brotli/wrapper/dec/BUILD index 58ab3d4..c8808fa 100755 --- a/java/org/brotli/wrapper/dec/BUILD +++ b/java/org/brotli/wrapper/dec/BUILD @@ -7,16 +7,17 @@ filegroup( srcs = ["decoder_jni.cc"], ) -######################################### -# WARNING: do not depend on this target! -######################################### java_library( name = "dec", srcs = glob( ["*.java"], exclude = ["*Test*.java"], ), - deps = ["//:jni"], +) + +filegroup( + name = "brotli_jni", + srcs = ["//:brotli_jni.dll"], ) filegroup( @@ -29,12 +30,16 @@ java_test( size = "large", srcs = ["BrotliDecoderChannelTest.java"], data = [ + ":brotli_jni", # Bazel JNI workaround ":test_bundle", - "//:jni", # Bazel JNI workaround ], - jvm_flags = ["-DTEST_BUNDLE=$(location :test_bundle)"], + jvm_flags = [ + "-DBROTLI_JNI_LIBRARY=$(location :brotli_jni)", + "-DTEST_BUNDLE=$(location :test_bundle)", + ], deps = [ ":dec", + "//java/org/brotli/integration:brotli_jni_test_base", "//java/org/brotli/integration:bundle_helper", "@junit_junit//jar", ], @@ -45,12 +50,16 @@ java_test( size = "large", srcs = ["BrotliInputStreamTest.java"], data = [ + ":brotli_jni", # Bazel JNI workaround ":test_bundle", - "//:jni", # Bazel JNI workaround ], - jvm_flags = ["-DTEST_BUNDLE=$(location :test_bundle)"], + jvm_flags = [ + "-DBROTLI_JNI_LIBRARY=$(location :brotli_jni)", + "-DTEST_BUNDLE=$(location :test_bundle)", + ], deps = [ ":dec", + "//java/org/brotli/integration:brotli_jni_test_base", "//java/org/brotli/integration:bundle_helper", "@junit_junit//jar", ], @@ -61,12 +70,16 @@ java_test( size = "large", srcs = ["DecoderTest.java"], data = [ + ":brotli_jni", # Bazel JNI workaround ":test_bundle", - "//:jni", # Bazel JNI workaround ], - jvm_flags = ["-DTEST_BUNDLE=$(location :test_bundle)"], + jvm_flags = [ + "-DBROTLI_JNI_LIBRARY=$(location :brotli_jni)", + "-DTEST_BUNDLE=$(location :test_bundle)", + ], deps = [ ":dec", + "//java/org/brotli/integration:brotli_jni_test_base", "//java/org/brotli/integration:bundle_helper", "@junit_junit//jar", ], diff --git a/java/org/brotli/wrapper/dec/BrotliDecoderChannelTest.java b/java/org/brotli/wrapper/dec/BrotliDecoderChannelTest.java index b6fc036..71d8f68 100755 --- a/java/org/brotli/wrapper/dec/BrotliDecoderChannelTest.java +++ b/java/org/brotli/wrapper/dec/BrotliDecoderChannelTest.java @@ -8,6 +8,7 @@ package org.brotli.wrapper.dec; import static org.junit.Assert.assertEquals; +import org.brotli.integration.BrotliJniTestBase; import org.brotli.integration.BundleHelper; import java.io.ByteArrayInputStream; import java.io.FileInputStream; @@ -23,13 +24,7 @@ import org.junit.runners.AllTests; /** Tests for {@link org.brotli.wrapper.dec.BrotliDecoderChannel}. */ @RunWith(AllTests.class) -public class BrotliDecoderChannelTest { - - // TODO: remove when Bazel get JNI support. - static { - System.load(new java.io.File(new java.io.File(System.getProperty("java.library.path")), - "liblibjni.so").getAbsolutePath()); - } +public class BrotliDecoderChannelTest extends BrotliJniTestBase { static InputStream getBundle() throws IOException { return new FileInputStream(System.getProperty("TEST_BUNDLE")); diff --git a/java/org/brotli/wrapper/dec/BrotliInputStreamTest.java b/java/org/brotli/wrapper/dec/BrotliInputStreamTest.java index aec26a0..5da7115 100755 --- a/java/org/brotli/wrapper/dec/BrotliInputStreamTest.java +++ b/java/org/brotli/wrapper/dec/BrotliInputStreamTest.java @@ -8,6 +8,7 @@ package org.brotli.wrapper.dec; import static org.junit.Assert.assertEquals; +import org.brotli.integration.BrotliJniTestBase; import org.brotli.integration.BundleHelper; import java.io.ByteArrayInputStream; import java.io.FileInputStream; @@ -21,13 +22,7 @@ import org.junit.runners.AllTests; /** Tests for {@link org.brotli.wrapper.dec.BrotliInputStream}. */ @RunWith(AllTests.class) -public class BrotliInputStreamTest { - - // TODO: remove when Bazel get JNI support. - static { - System.load(new java.io.File(new java.io.File(System.getProperty("java.library.path")), - "liblibjni.so").getAbsolutePath()); - } +public class BrotliInputStreamTest extends BrotliJniTestBase { static InputStream getBundle() throws IOException { return new FileInputStream(System.getProperty("TEST_BUNDLE")); diff --git a/java/org/brotli/wrapper/dec/DecoderTest.java b/java/org/brotli/wrapper/dec/DecoderTest.java index 0a8970f..74b77d3 100755 --- a/java/org/brotli/wrapper/dec/DecoderTest.java +++ b/java/org/brotli/wrapper/dec/DecoderTest.java @@ -8,6 +8,7 @@ package org.brotli.wrapper.dec; import static org.junit.Assert.assertEquals; +import org.brotli.integration.BrotliJniTestBase; import org.brotli.integration.BundleHelper; import java.io.ByteArrayInputStream; import java.io.FileInputStream; @@ -21,13 +22,7 @@ import org.junit.runners.AllTests; /** Tests for {@link org.brotli.wrapper.dec.Decoder}. */ @RunWith(AllTests.class) -public class DecoderTest { - - // TODO: remove when Bazel get JNI support. - static { - System.load(new java.io.File(new java.io.File(System.getProperty("java.library.path")), - "liblibjni.so").getAbsolutePath()); - } +public class DecoderTest extends BrotliJniTestBase { static InputStream getBundle() throws IOException { return new FileInputStream(System.getProperty("TEST_BUNDLE")); diff --git a/java/org/brotli/wrapper/enc/BUILD b/java/org/brotli/wrapper/enc/BUILD index 39b1b37..6ea048c 100755 --- a/java/org/brotli/wrapper/enc/BUILD +++ b/java/org/brotli/wrapper/enc/BUILD @@ -7,16 +7,17 @@ filegroup( srcs = ["encoder_jni.cc"], ) -######################################### -# WARNING: do not depend on this target! -######################################### +filegroup( + name = "brotli_jni", + srcs = ["//:brotli_jni.dll"], +) + java_library( name = "enc", srcs = glob( ["*.java"], exclude = ["*Test*.java"], ), - deps = ["//:jni"], ) filegroup( @@ -29,13 +30,17 @@ java_test( size = "large", srcs = ["BrotliEncoderChannelTest.java"], data = [ + ":brotli_jni", # Bazel JNI workaround ":test_bundle", - "//:jni", # Bazel JNI workaround ], - jvm_flags = ["-DTEST_BUNDLE=$(location :test_bundle)"], + jvm_flags = [ + "-DBROTLI_JNI_LIBRARY=$(location :brotli_jni)", + "-DTEST_BUNDLE=$(location :test_bundle)", + ], shard_count = 15, deps = [ ":enc", + "//java/org/brotli/integration:brotli_jni_test_base", "//java/org/brotli/integration:bundle_helper", "//java/org/brotli/wrapper/dec", "@junit_junit//jar", @@ -47,13 +52,17 @@ java_test( size = "large", srcs = ["BrotliOutputStreamTest.java"], data = [ + ":brotli_jni", # Bazel JNI workaround ":test_bundle", - "//:jni", # Bazel JNI workaround ], - jvm_flags = ["-DTEST_BUNDLE=$(location :test_bundle)"], + jvm_flags = [ + "-DBROTLI_JNI_LIBRARY=$(location :brotli_jni)", + "-DTEST_BUNDLE=$(location :test_bundle)", + ], shard_count = 15, deps = [ ":enc", + "//java/org/brotli/integration:brotli_jni_test_base", "//java/org/brotli/integration:bundle_helper", "//java/org/brotli/wrapper/dec", "@junit_junit//jar", @@ -65,13 +74,17 @@ java_test( size = "large", srcs = ["EncoderTest.java"], data = [ + ":brotli_jni", # Bazel JNI workaround ":test_bundle", - "//:jni", # Bazel JNI workaround ], - jvm_flags = ["-DTEST_BUNDLE=$(location :test_bundle)"], + jvm_flags = [ + "-DBROTLI_JNI_LIBRARY=$(location :brotli_jni)", + "-DTEST_BUNDLE=$(location :test_bundle)", + ], shard_count = 15, deps = [ ":enc", + "//java/org/brotli/integration:brotli_jni_test_base", "//java/org/brotli/integration:bundle_helper", "//java/org/brotli/wrapper/dec", "@junit_junit//jar", diff --git a/java/org/brotli/wrapper/enc/BrotliEncoderChannelTest.java b/java/org/brotli/wrapper/enc/BrotliEncoderChannelTest.java index 1ab7599..2492589 100755 --- a/java/org/brotli/wrapper/enc/BrotliEncoderChannelTest.java +++ b/java/org/brotli/wrapper/enc/BrotliEncoderChannelTest.java @@ -2,6 +2,7 @@ package org.brotli.wrapper.enc; import static org.junit.Assert.assertEquals; +import org.brotli.integration.BrotliJniTestBase; import org.brotli.integration.BundleHelper; import org.brotli.wrapper.dec.BrotliInputStream; import java.io.ByteArrayInputStream; @@ -20,19 +21,13 @@ import org.junit.runners.AllTests; /** Tests for {@link org.brotli.wrapper.enc.BrotliEncoderChannel}. */ @RunWith(AllTests.class) -public class BrotliEncoderChannelTest { +public class BrotliEncoderChannelTest extends BrotliJniTestBase { private enum TestMode { WRITE_ALL, WRITE_CHUNKS } - // TODO: remove when Bazel get JNI support. - static { - System.load(new java.io.File(new java.io.File(System.getProperty("java.library.path")), - "liblibjni.so").getAbsolutePath()); - } - private static final int CHUNK_SIZE = 256; static InputStream getBundle() throws IOException { diff --git a/java/org/brotli/wrapper/enc/BrotliOutputStreamTest.java b/java/org/brotli/wrapper/enc/BrotliOutputStreamTest.java index a436e81..699b4b2 100755 --- a/java/org/brotli/wrapper/enc/BrotliOutputStreamTest.java +++ b/java/org/brotli/wrapper/enc/BrotliOutputStreamTest.java @@ -2,6 +2,7 @@ package org.brotli.wrapper.enc; import static org.junit.Assert.assertEquals; +import org.brotli.integration.BrotliJniTestBase; import org.brotli.integration.BundleHelper; import org.brotli.wrapper.dec.BrotliInputStream; import java.io.ByteArrayInputStream; @@ -18,7 +19,7 @@ import org.junit.runners.AllTests; /** Tests for {@link org.brotli.wrapper.enc.BrotliOutputStream}. */ @RunWith(AllTests.class) -public class BrotliOutputStreamTest { +public class BrotliOutputStreamTest extends BrotliJniTestBase { private enum TestMode { WRITE_ALL, @@ -26,12 +27,6 @@ public class BrotliOutputStreamTest { WRITE_BYTE } - // TODO: remove when Bazel get JNI support. - static { - System.load(new java.io.File(new java.io.File(System.getProperty("java.library.path")), - "liblibjni.so").getAbsolutePath()); - } - private static final int CHUNK_SIZE = 256; static InputStream getBundle() throws IOException { diff --git a/java/org/brotli/wrapper/enc/EncoderTest.java b/java/org/brotli/wrapper/enc/EncoderTest.java index 0c26882..18ed647 100755 --- a/java/org/brotli/wrapper/enc/EncoderTest.java +++ b/java/org/brotli/wrapper/enc/EncoderTest.java @@ -2,6 +2,7 @@ package org.brotli.wrapper.enc; import static org.junit.Assert.assertEquals; +import org.brotli.integration.BrotliJniTestBase; import org.brotli.integration.BundleHelper; import org.brotli.wrapper.dec.BrotliInputStream; import java.io.ByteArrayInputStream; @@ -16,14 +17,7 @@ import org.junit.runners.AllTests; /** Tests for {@link org.brotli.wrapper.enc.Encoder}. */ @RunWith(AllTests.class) -public class EncoderTest { - - // TODO: remove when Bazel get JNI support. - static { - System.load(new java.io.File(new java.io.File(System.getProperty("java.library.path")), - "liblibjni.so").getAbsolutePath()); - } - +public class EncoderTest extends BrotliJniTestBase { static InputStream getBundle() throws IOException { return new FileInputStream(System.getProperty("TEST_BUNDLE")); } |