summaryrefslogtreecommitdiff
path: root/pkgs/development/compilers/openjdk/tests/hello-logging.nix
diff options
context:
space:
mode:
Diffstat (limited to 'pkgs/development/compilers/openjdk/tests/hello-logging.nix')
-rw-r--r--pkgs/development/compilers/openjdk/tests/hello-logging.nix47
1 files changed, 47 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
+ '';
+ }