diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-29 04:41:38 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-29 04:41:38 +0000 |
commit | 7b6e527f440cd7e6f8be2b07cee320ee6ca18786 (patch) | |
tree | 4a2738d69fa2814659fdadddf5826282e73d81f4 /test cases/java | |
parent | Initial commit. (diff) | |
download | meson-upstream.tar.xz meson-upstream.zip |
Adding upstream version 1.0.1.upstream/1.0.1upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'test cases/java')
41 files changed, 420 insertions, 0 deletions
diff --git a/test cases/java/1 basic/com/mesonbuild/Simple.java b/test cases/java/1 basic/com/mesonbuild/Simple.java new file mode 100644 index 0000000..325a49a --- /dev/null +++ b/test cases/java/1 basic/com/mesonbuild/Simple.java @@ -0,0 +1,7 @@ +package com.mesonbuild; + +class Simple { + public static void main(String [] args) { + System.out.println("Java is working.\n"); + } +} diff --git a/test cases/java/1 basic/meson.build b/test cases/java/1 basic/meson.build new file mode 100644 index 0000000..ef1a4b7 --- /dev/null +++ b/test cases/java/1 basic/meson.build @@ -0,0 +1,11 @@ +project('simplejava', 'java') + +javaprog = jar('myprog', 'com/mesonbuild/Simple.java', + main_class : 'com.mesonbuild.Simple', + install : true, + install_dir : get_option('bindir')) +test('mytest', javaprog) + +jc = meson.get_compiler('java') +message(jc.get_id()) +message(jc.get_linker_id()) diff --git a/test cases/java/1 basic/test.json b/test cases/java/1 basic/test.json new file mode 100644 index 0000000..b5b1539 --- /dev/null +++ b/test cases/java/1 basic/test.json @@ -0,0 +1,5 @@ +{ + "installed": [ + {"type": "file", "file": "usr/bin/myprog.jar"} + ] +} diff --git a/test cases/java/10 resources/meson.build b/test cases/java/10 resources/meson.build new file mode 100644 index 0000000..3b87219 --- /dev/null +++ b/test cases/java/10 resources/meson.build @@ -0,0 +1,7 @@ +project('resources', ['java']) + +if meson.backend() != 'ninja' + error('MESON_SKIP_TEST: only valid on backends which support jar()') +endif + +subdir('src') diff --git a/test cases/java/10 resources/src/com/mesonbuild/Resources.java b/test cases/java/10 resources/src/com/mesonbuild/Resources.java new file mode 100644 index 0000000..de1b7d6 --- /dev/null +++ b/test cases/java/10 resources/src/com/mesonbuild/Resources.java @@ -0,0 +1,26 @@ +package com.mesonbuild; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.nio.charset.StandardCharsets; + +public class Resources { + public static void main(String[] args) throws IOException { + try (InputStreamReader reader = new InputStreamReader( + Resources.class.getResourceAsStream("/resource1.txt"), + StandardCharsets.UTF_8)) { + final BufferedReader buffered = new BufferedReader(reader); + + assert buffered.readLine() == "1"; + } + + try (InputStreamReader reader = new InputStreamReader( + Resources.class.getResourceAsStream("/subdir/resource2.txt"), + StandardCharsets.UTF_8)) { + final BufferedReader buffered = new BufferedReader(reader); + + assert buffered.readLine() == "2"; + } + } +} diff --git a/test cases/java/10 resources/src/meson.build b/test cases/java/10 resources/src/meson.build new file mode 100644 index 0000000..51f7d75 --- /dev/null +++ b/test cases/java/10 resources/src/meson.build @@ -0,0 +1,13 @@ +sources = files('com/mesonbuild/Resources.java') + +resources = jar( + meson.project_name(), + sources, + main_class: 'com.mesonbuild.Resources', + java_resources: structured_sources( + files('resources/resource1.txt'), + { + 'subdir': files('resources/subdir/resource2.txt'), + } + ) +) diff --git a/test cases/java/10 resources/src/resources/resource1.txt b/test cases/java/10 resources/src/resources/resource1.txt new file mode 100644 index 0000000..d00491f --- /dev/null +++ b/test cases/java/10 resources/src/resources/resource1.txt @@ -0,0 +1 @@ +1 diff --git a/test cases/java/10 resources/src/resources/subdir/resource2.txt b/test cases/java/10 resources/src/resources/subdir/resource2.txt new file mode 100644 index 0000000..0cfbf08 --- /dev/null +++ b/test cases/java/10 resources/src/resources/subdir/resource2.txt @@ -0,0 +1 @@ +2 diff --git a/test cases/java/2 subdir/meson.build b/test cases/java/2 subdir/meson.build new file mode 100644 index 0000000..5aaa028 --- /dev/null +++ b/test cases/java/2 subdir/meson.build @@ -0,0 +1,3 @@ +project('subdirjava', 'java') + +subdir('sub') diff --git a/test cases/java/2 subdir/sub/com/mesonbuild/Simple.java b/test cases/java/2 subdir/sub/com/mesonbuild/Simple.java new file mode 100644 index 0000000..05a73ac --- /dev/null +++ b/test cases/java/2 subdir/sub/com/mesonbuild/Simple.java @@ -0,0 +1,8 @@ +package com.mesonbuild; + +class Simple { + public static void main(String [] args) { + TextPrinter t = new TextPrinter("Printing from Java."); + t.print(); + } +} diff --git a/test cases/java/2 subdir/sub/com/mesonbuild/TextPrinter.java b/test cases/java/2 subdir/sub/com/mesonbuild/TextPrinter.java new file mode 100644 index 0000000..dc2771c --- /dev/null +++ b/test cases/java/2 subdir/sub/com/mesonbuild/TextPrinter.java @@ -0,0 +1,14 @@ +package com.mesonbuild; + +class TextPrinter { + + private String msg; + + TextPrinter(String s) { + msg = s; + } + + public void print() { + System.out.println(msg); + } +} diff --git a/test cases/java/2 subdir/sub/meson.build b/test cases/java/2 subdir/sub/meson.build new file mode 100644 index 0000000..2111c06 --- /dev/null +++ b/test cases/java/2 subdir/sub/meson.build @@ -0,0 +1,5 @@ +javaprog = jar('myprog', + 'com/mesonbuild/Simple.java', + 'com/mesonbuild/TextPrinter.java', + main_class : 'com.mesonbuild.Simple') +test('subdirtest', javaprog) diff --git a/test cases/java/3 args/com/mesonbuild/Simple.java b/test cases/java/3 args/com/mesonbuild/Simple.java new file mode 100644 index 0000000..325a49a --- /dev/null +++ b/test cases/java/3 args/com/mesonbuild/Simple.java @@ -0,0 +1,7 @@ +package com.mesonbuild; + +class Simple { + public static void main(String [] args) { + System.out.println("Java is working.\n"); + } +} diff --git a/test cases/java/3 args/meson.build b/test cases/java/3 args/meson.build new file mode 100644 index 0000000..d13573f --- /dev/null +++ b/test cases/java/3 args/meson.build @@ -0,0 +1,8 @@ +project('simplejava', 'java') + +add_project_arguments('-target', '1.7', language : 'java') + +javaprog = jar('myprog', 'com/mesonbuild/Simple.java', + main_class : 'com.mesonbuild.Simple', + java_args : ['-source', '1.7']) +test('mytest', javaprog) diff --git a/test cases/java/4 inner class/com/mesonbuild/Simple.java b/test cases/java/4 inner class/com/mesonbuild/Simple.java new file mode 100644 index 0000000..fd0e0bf --- /dev/null +++ b/test cases/java/4 inner class/com/mesonbuild/Simple.java @@ -0,0 +1,15 @@ +package com.mesonbuild; + +class Simple { + class Inner { + public String getString() { + return "Inner class is working.\n"; + } + } + + public static void main(String [] args) { + Simple s = new Simple(); + Simple.Inner ic = s.new Inner(); + System.out.println(ic.getString()); + } +} diff --git a/test cases/java/4 inner class/meson.build b/test cases/java/4 inner class/meson.build new file mode 100644 index 0000000..bed5c0f --- /dev/null +++ b/test cases/java/4 inner class/meson.build @@ -0,0 +1,5 @@ +project('simplejava', 'java') + +javaprog = jar('myprog', 'com/mesonbuild/Simple.java', + main_class : 'com.mesonbuild.Simple') +test('mytest', javaprog) diff --git a/test cases/java/5 includedirs/com/mesonbuild/Simple.java b/test cases/java/5 includedirs/com/mesonbuild/Simple.java new file mode 100644 index 0000000..05a73ac --- /dev/null +++ b/test cases/java/5 includedirs/com/mesonbuild/Simple.java @@ -0,0 +1,8 @@ +package com.mesonbuild; + +class Simple { + public static void main(String [] args) { + TextPrinter t = new TextPrinter("Printing from Java."); + t.print(); + } +} diff --git a/test cases/java/5 includedirs/com/mesonbuild/TextPrinter.java b/test cases/java/5 includedirs/com/mesonbuild/TextPrinter.java new file mode 100644 index 0000000..dc2771c --- /dev/null +++ b/test cases/java/5 includedirs/com/mesonbuild/TextPrinter.java @@ -0,0 +1,14 @@ +package com.mesonbuild; + +class TextPrinter { + + private String msg; + + TextPrinter(String s) { + msg = s; + } + + public void print() { + System.out.println(msg); + } +} diff --git a/test cases/java/5 includedirs/meson.build b/test cases/java/5 includedirs/meson.build new file mode 100644 index 0000000..cf0b565 --- /dev/null +++ b/test cases/java/5 includedirs/meson.build @@ -0,0 +1,14 @@ +# The Ninja backend used to try and pass -sourcepath repeatedly for +# multiple includes which would discard prior includes. Since this +# won't compile without the '.' include, this ensures that multiple +# paths are passed in a [semi-]colon separated list instead... + +project('includedirsjava', 'java') + +javaprog = jar('myprog', + 'com/mesonbuild/Simple.java', + 'com/mesonbuild/TextPrinter.java', + main_class : 'com.mesonbuild.Simple', + include_directories : [ include_directories('com'), + include_directories('com/mesonbuild') ]) +test('subdirtest', javaprog) diff --git a/test cases/java/6 codegen/com/mesonbuild/Config.java.in b/test cases/java/6 codegen/com/mesonbuild/Config.java.in new file mode 100644 index 0000000..fcc8811 --- /dev/null +++ b/test cases/java/6 codegen/com/mesonbuild/Config.java.in @@ -0,0 +1,5 @@ +package com.mesonbuild; + +public class Config { + public static final boolean FOOBAR = @foobar@; +} diff --git a/test cases/java/6 codegen/com/mesonbuild/Simple.java b/test cases/java/6 codegen/com/mesonbuild/Simple.java new file mode 100644 index 0000000..df3c53d --- /dev/null +++ b/test cases/java/6 codegen/com/mesonbuild/Simple.java @@ -0,0 +1,12 @@ +package com.mesonbuild; + +import com.mesonbuild.Config; + +class Simple { + public static void main(String [] args) { + if (Config.FOOBAR) { + TextPrinter t = new TextPrinter("Printing from Java."); + t.print(); + } + } +} diff --git a/test cases/java/6 codegen/com/mesonbuild/TextPrinter.java b/test cases/java/6 codegen/com/mesonbuild/TextPrinter.java new file mode 100644 index 0000000..dc2771c --- /dev/null +++ b/test cases/java/6 codegen/com/mesonbuild/TextPrinter.java @@ -0,0 +1,14 @@ +package com.mesonbuild; + +class TextPrinter { + + private String msg; + + TextPrinter(String s) { + msg = s; + } + + public void print() { + System.out.println(msg); + } +} diff --git a/test cases/java/6 codegen/com/mesonbuild/meson.build b/test cases/java/6 codegen/com/mesonbuild/meson.build new file mode 100644 index 0000000..188bedf --- /dev/null +++ b/test cases/java/6 codegen/com/mesonbuild/meson.build @@ -0,0 +1,6 @@ + +conf_data = configuration_data() +conf_data.set('foobar', 'true') +config_file = configure_file(input : 'Config.java.in', + output : 'Config.java', + configuration : conf_data) diff --git a/test cases/java/6 codegen/meson.build b/test cases/java/6 codegen/meson.build new file mode 100644 index 0000000..f85d45a --- /dev/null +++ b/test cases/java/6 codegen/meson.build @@ -0,0 +1,15 @@ +# If we generate code under the build directory then the backend needs to add +# the build directory to the -sourcepath passed to javac otherwise the compiler +# won't be able to handle the -implicit:class behaviour of automatically +# compiling dependency classes. + +project('codegenjava', 'java') + +subdir('com/mesonbuild') + +javaprog = jar('myprog', + config_file, + 'com/mesonbuild/Simple.java', + 'com/mesonbuild/TextPrinter.java', + main_class : 'com.mesonbuild.Simple') +test('subdirtest', javaprog) diff --git a/test cases/java/7 linking/com/mesonbuild/Linking.java b/test cases/java/7 linking/com/mesonbuild/Linking.java new file mode 100644 index 0000000..170e2aa --- /dev/null +++ b/test cases/java/7 linking/com/mesonbuild/Linking.java @@ -0,0 +1,9 @@ +package com.mesonbuild; + +import com.mesonbuild.SimpleLib; + +class Linking { + public static void main(String [] args) { + SimpleLib.func(); + } +} diff --git a/test cases/java/7 linking/meson.build b/test cases/java/7 linking/meson.build new file mode 100644 index 0000000..0ae0db3 --- /dev/null +++ b/test cases/java/7 linking/meson.build @@ -0,0 +1,8 @@ +project('linkingjava', 'java') + +subdir('sub') + +javaprog = jar('myprog', 'com/mesonbuild/Linking.java', + main_class : 'com.mesonbuild.Linking', + link_with : simplelib) +test('mytest', javaprog)
\ No newline at end of file diff --git a/test cases/java/7 linking/sub/com/mesonbuild/SimpleLib.java b/test cases/java/7 linking/sub/com/mesonbuild/SimpleLib.java new file mode 100644 index 0000000..835b2e4 --- /dev/null +++ b/test cases/java/7 linking/sub/com/mesonbuild/SimpleLib.java @@ -0,0 +1,7 @@ +package com.mesonbuild; + +public class SimpleLib { + public static void func() { + System.out.println("Java linking is working.\n"); + } +} diff --git a/test cases/java/7 linking/sub/meson.build b/test cases/java/7 linking/sub/meson.build new file mode 100644 index 0000000..13fd202 --- /dev/null +++ b/test cases/java/7 linking/sub/meson.build @@ -0,0 +1,2 @@ +simplelib = jar('simplelib', + 'com/mesonbuild/SimpleLib.java') diff --git a/test cases/java/8 codegen custom target/com/mesonbuild/Config.java.in b/test cases/java/8 codegen custom target/com/mesonbuild/Config.java.in new file mode 100644 index 0000000..8845985 --- /dev/null +++ b/test cases/java/8 codegen custom target/com/mesonbuild/Config.java.in @@ -0,0 +1,5 @@ +package com.mesonbuild; + +public class Config { + public static final boolean FOOBAR = true; +} diff --git a/test cases/java/8 codegen custom target/com/mesonbuild/Simple.java b/test cases/java/8 codegen custom target/com/mesonbuild/Simple.java new file mode 100644 index 0000000..df3c53d --- /dev/null +++ b/test cases/java/8 codegen custom target/com/mesonbuild/Simple.java @@ -0,0 +1,12 @@ +package com.mesonbuild; + +import com.mesonbuild.Config; + +class Simple { + public static void main(String [] args) { + if (Config.FOOBAR) { + TextPrinter t = new TextPrinter("Printing from Java."); + t.print(); + } + } +} diff --git a/test cases/java/8 codegen custom target/com/mesonbuild/TextPrinter.java b/test cases/java/8 codegen custom target/com/mesonbuild/TextPrinter.java new file mode 100644 index 0000000..dc2771c --- /dev/null +++ b/test cases/java/8 codegen custom target/com/mesonbuild/TextPrinter.java @@ -0,0 +1,14 @@ +package com.mesonbuild; + +class TextPrinter { + + private String msg; + + TextPrinter(String s) { + msg = s; + } + + public void print() { + System.out.println(msg); + } +} diff --git a/test cases/java/8 codegen custom target/com/mesonbuild/meson.build b/test cases/java/8 codegen custom target/com/mesonbuild/meson.build new file mode 100644 index 0000000..0309941 --- /dev/null +++ b/test cases/java/8 codegen custom target/com/mesonbuild/meson.build @@ -0,0 +1,8 @@ +python = import('python').find_installation('python3') + +config_file = custom_target('confgen', + input : 'Config.java.in', + output : 'Config.java', + command : [python, '-c', + 'import shutil, sys, time; time.sleep(1); shutil.copy(sys.argv[1], sys.argv[2])', + '@INPUT@', '@OUTPUT@']) diff --git a/test cases/java/8 codegen custom target/meson.build b/test cases/java/8 codegen custom target/meson.build new file mode 100644 index 0000000..ab441a6 --- /dev/null +++ b/test cases/java/8 codegen custom target/meson.build @@ -0,0 +1,15 @@ +# If we generate code under the build directory then the backend needs to add +# the build directory to the -sourcepath passed to javac otherwise the compiler +# won't be able to handle the -implicit:class behaviour of automatically +# compiling dependency classes. + +project('codegenjava', 'java') + +subdir('com/mesonbuild') + +javaprog = jar('myprog', + config_file[0], + 'com/mesonbuild/Simple.java', + 'com/mesonbuild/TextPrinter.java', + main_class : 'com.mesonbuild.Simple') +test('subdirtest', javaprog) diff --git a/test cases/java/9 jni/lib/com_mesonbuild_JniTest.c b/test cases/java/9 jni/lib/com_mesonbuild_JniTest.c new file mode 100644 index 0000000..5deca03 --- /dev/null +++ b/test cases/java/9 jni/lib/com_mesonbuild_JniTest.c @@ -0,0 +1,9 @@ +#include <jni.h> + +#include "com_mesonbuild_JniTest.h" + +JNIEXPORT jint JNICALL Java_com_mesonbuild_JniTest_jni_1test + (JNIEnv *env, jclass clazz) +{ + return (jint)0xdeadbeef; +} diff --git a/test cases/java/9 jni/lib/meson.build b/test cases/java/9 jni/lib/meson.build new file mode 100644 index 0000000..c2ddc7a --- /dev/null +++ b/test cases/java/9 jni/lib/meson.build @@ -0,0 +1,18 @@ +sources = [ + files( + 'native.c', + 'com_mesonbuild_JniTest.c', + ), + native_headers +] + +jnijava = shared_module( + 'jnijava', + sources, + dependencies : [jni_dep], + include_directories : [native_header_includes] +) + +jnijava_dep = declare_dependency( + link_with : jnijava +) diff --git a/test cases/java/9 jni/lib/native.c b/test cases/java/9 jni/lib/native.c new file mode 100644 index 0000000..0b5e718 --- /dev/null +++ b/test cases/java/9 jni/lib/native.c @@ -0,0 +1,11 @@ +#include <jni.h> + +JNIEXPORT jint JNICALL +JNI_OnLoad(JavaVM *vm, void *reserved) +{ + return JNI_VERSION_1_8; +} + +JNIEXPORT void JNICALL +JNI_OnUnload(JavaVM *vm, void *reserved) +{} diff --git a/test cases/java/9 jni/meson.build b/test cases/java/9 jni/meson.build new file mode 100644 index 0000000..7a68165 --- /dev/null +++ b/test cases/java/9 jni/meson.build @@ -0,0 +1,38 @@ +project('jnijava', ['c', 'java']) + +if build_machine.system() == 'cygwin' + error('MESON_SKIP_TEST: cygwin test failures') +endif + +if build_machine.system() == 'windows' and build_machine.cpu_family() == 'x86' + error('MESON_SKIP_TEST: failing builds on 32bit Windows because a 32bit JDK is not available in the Azure Pipelines Windows images') +endif + +fs = import('fs') +javamod = import('java') + +cc = meson.get_compiler('c') +java = find_program('java') + +jni_dep = dependency('jni', version : '>=1.8', modules: ['jvm', 'awt']) + +# Assert that the header can actually be found with the dependency. +cc.has_header('jni.h', dependencies: [jni_dep]) +# Assert that the platform-specific include directory is included in the compiler arguments. +cc.has_header('jni_md.h', dependencies: [jni_dep]) + +# generate native headers +subdir('src') +subdir('lib') + +test( + 'jnitest', + java, + args: [ + '-Djava.library.path=@0@'.format(fs.parent(jnijava.full_path())), + '-jar', + jnijar, + ], + protocol : 'exitcode', + depends : [jnijava], +) diff --git a/test cases/java/9 jni/src/com/mesonbuild/Configured.java.in b/test cases/java/9 jni/src/com/mesonbuild/Configured.java.in new file mode 100644 index 0000000..fac6e05 --- /dev/null +++ b/test cases/java/9 jni/src/com/mesonbuild/Configured.java.in @@ -0,0 +1,5 @@ +package com.mesonbuild; + +public final class Configured { + public static final int FINGERPRINT = @fingerprint@; +} diff --git a/test cases/java/9 jni/src/com/mesonbuild/JniTest.java b/test cases/java/9 jni/src/com/mesonbuild/JniTest.java new file mode 100644 index 0000000..4bfffe9 --- /dev/null +++ b/test cases/java/9 jni/src/com/mesonbuild/JniTest.java @@ -0,0 +1,15 @@ +package com.mesonbuild; + +public final class JniTest { + private static native int jni_test(); + + public static void main(String[] args) { + if (jni_test() != Configured.FINGERPRINT) { + throw new RuntimeException("jdk_test() did not return 0"); + } + } + + static { + System.loadLibrary("jnijava"); + } +} diff --git a/test cases/java/9 jni/src/com/mesonbuild/meson.build b/test cases/java/9 jni/src/com/mesonbuild/meson.build new file mode 100644 index 0000000..a505b1a --- /dev/null +++ b/test cases/java/9 jni/src/com/mesonbuild/meson.build @@ -0,0 +1,11 @@ +configured = configure_file( + input: files('Configured.java.in'), + output: 'Configured.java', + configuration: configuration_data({'fingerprint': '0xdeadbeef'}) +) + +sources += configured + +native_headers = javamod.native_headers( + sources, package: 'com.mesonbuild', classes: ['JniTest']) +native_header_includes = include_directories('.') diff --git a/test cases/java/9 jni/src/meson.build b/test cases/java/9 jni/src/meson.build new file mode 100644 index 0000000..af443b5 --- /dev/null +++ b/test cases/java/9 jni/src/meson.build @@ -0,0 +1,9 @@ +sources = [files('com/mesonbuild/JniTest.java')] + +subdir('com/mesonbuild') + +jnijar = jar( + 'jnijar', + sources, + main_class : 'com.mesonbuild.JniTest', +) |