diff options
| author | Robin Gloster <mail@glob.in> | 2021-05-24 09:55:24 -0500 |
|---|---|---|
| committer | Robin Gloster <mail@glob.in> | 2021-05-24 09:55:24 -0500 |
| commit | 4bc5fbef9d159e143fb7e2c3231932e6e76f667c (patch) | |
| tree | e2198f5c552e0667d838b8ec764ddb3a4d8f6dec /pkgs/development/compilers/openjdk/tests | |
| parent | jq: fix build with structured-attrs on darwin (diff) | |
| parent | Merge pull request #123802 from superherointj/package-virtmanager-bugfix (diff) | |
| download | nixpkgs-origin/structured-attrs.tar.gz | |
Merge remote-tracking branch 'upstream/master' into structured-attrsorigin/structured-attrs
Diffstat (limited to 'pkgs/development/compilers/openjdk/tests')
4 files changed, 126 insertions, 0 deletions
diff --git a/pkgs/development/compilers/openjdk/tests/hello-logging.nix b/pkgs/development/compilers/openjdk/tests/hello-logging.nix new file mode 100644 index 000000000000..71f3a5543f7c --- /dev/null +++ b/pkgs/development/compilers/openjdk/tests/hello-logging.nix @@ -0,0 +1,47 @@ +{ jdk +, jre +, pkgs +}: + +/* 'Hello world' Java application derivation for use in tests */ +let + source = pkgs.writeTextDir "src/Hello.java" '' + import java.util.logging.Logger; + import java.util.logging.Level; + + class Hello { + static Logger logger = Logger.getLogger(Hello.class.getName()); + + public static void main(String[] args) { + logger.log(Level.INFO, "Hello, world!"); + } + } + ''; +in + pkgs.stdenv.mkDerivation { + pname = "hello"; + version = "1.0.0"; + + src = source; + + buildPhase = '' + runHook preBuildPhase + ${jdk}/bin/javac src/Hello.java + runHook postBuildPhase + ''; + installPhase = '' + runHook preInstallPhase + + mkdir -p $out/lib + cp src/Hello.class $out/lib + + mkdir -p $out/bin + cat >$out/bin/hello <<EOF; + #!/usr/bin/env sh + ${jre}/bin/java -cp $out/lib Hello + EOF + chmod a+x $out/bin/hello + + runHook postInstallPhase + ''; + } diff --git a/pkgs/development/compilers/openjdk/tests/hello.nix b/pkgs/development/compilers/openjdk/tests/hello.nix new file mode 100644 index 000000000000..bc5be4a9e9a9 --- /dev/null +++ b/pkgs/development/compilers/openjdk/tests/hello.nix @@ -0,0 +1,42 @@ +{ jdk +, jre +, pkgs +}: + +/* 'Hello world' Java application derivation for use in tests */ +let + source = pkgs.writeTextDir "src/Hello.java" '' + class Hello { + public static void main(String[] args) { + System.out.println("Hello, world!"); + } + } + ''; +in + pkgs.stdenv.mkDerivation { + pname = "hello"; + version = "1.0.0"; + + src = source; + + buildPhase = '' + runHook preBuildPhase + ${jdk}/bin/javac src/Hello.java + runHook postBuildPhase + ''; + installPhase = '' + runHook preInstallPhase + + mkdir -p $out/lib + cp src/Hello.class $out/lib + + mkdir -p $out/bin + cat >$out/bin/hello <<EOF; + #!/usr/bin/env sh + ${jre}/bin/java -cp $out/lib Hello + EOF + chmod a+x $out/bin/hello + + runHook postInstallPhase + ''; + } diff --git a/pkgs/development/compilers/openjdk/tests/test_jre_minimal.nix b/pkgs/development/compilers/openjdk/tests/test_jre_minimal.nix new file mode 100644 index 000000000000..ed7b839cd22b --- /dev/null +++ b/pkgs/development/compilers/openjdk/tests/test_jre_minimal.nix @@ -0,0 +1,16 @@ +{ runCommand +, callPackage +, jdk +, jre_minimal +}: + +let + hello = callPackage ./hello.nix { + jdk = jdk; + jre = jre_minimal; + }; +in + runCommand "test" {} '' + ${hello}/bin/hello | grep "Hello, world!" + touch $out + '' diff --git a/pkgs/development/compilers/openjdk/tests/test_jre_minimal_with_logging.nix b/pkgs/development/compilers/openjdk/tests/test_jre_minimal_with_logging.nix new file mode 100644 index 000000000000..b9c417d3949c --- /dev/null +++ b/pkgs/development/compilers/openjdk/tests/test_jre_minimal_with_logging.nix @@ -0,0 +1,21 @@ +{ runCommand +, callPackage +, jdk +, jre_minimal +}: + +let + hello-logging = callPackage ./hello-logging.nix { + jdk = jdk; + jre = jre_minimal.override { + modules = [ + "java.base" + "java.logging" + ]; + }; + }; +in + runCommand "test" {} '' + ${hello-logging}/bin/hello &>/dev/stdout | grep "Hello, world!" + touch $out + '' |
