From 0b6c756fc44fcda303cf1268a9efa64f936724ad Mon Sep 17 00:00:00 2001
From: Ioannis Kappas <ioannis.kappas@gmamil.com>
Date: Sun, 19 Jun 2022 09:44:26 +0100
Subject: [PATCH v5 3/3] Finalize openjfx libraries

* java-openjfx-graphics
  1. Normalize inputs, only build against gtk-2.0.
  2. Output native libs to openjfx standard share/amd64 dir.
  3. Do not build libjpeg from source, but rather use corresponding
     package.
  4. Run all tests.
* java-openjfx-controls
  1. Run all tests.
  2. Fix java-openjfx-graphics name typo.
* java-openjfx-media
  1. Build against gstreamer.
  2. Compile native library and modify loader to load it directly from
     the store path.
* java-openjfx-web
  1. Include version.
  2. Modify loader to load native web kit lib directly from the store.
  3. Fix a failing test, by applying new
     java-openjfx-build-web-js-test.patch as picked up from a later
     openjfx revision source code revision, to fix a failing test.
  4. Run all tests.
* java-swt
  1. Modify loader to load native library directly from the gnu/store
     path if it can't be found otherwise. This is required for
     seamlessly loading java-swt as an input.
---
 gnu/local.mk          |   1 +
 gnu/packages/java.scm | 482 ++++++++++++++++++++++++++++++++++--------
 2 files changed, 399 insertions(+), 84 deletions(-)

diff --git a/gnu/local.mk b/gnu/local.mk
index 9b982c42db..29c3f750aa 100644
--- a/gnu/local.mk
+++ b/gnu/local.mk
@@ -1327,6 +1327,7 @@ dist_patch_DATA =						\
   %D%/packages/patches/java-openjfx-build-web-WTF.patch			\
   %D%/packages/patches/java-openjfx-build-web-WebKitCompilerFlags.cmake.patch	\
   %D%/packages/patches/java-openjfx-build-web-icu.patch			\
+  %D%/packages/patches/java-openjfx-build-web-js-test.patch     \
   %D%/packages/patches/java-powermock-fix-java-files.patch		\
   %D%/packages/patches/java-simple-xml-fix-tests.patch		\
   %D%/packages/patches/java-svg-salamander-Fix-non-det.patch	\
diff --git a/gnu/packages/java.scm b/gnu/packages/java.scm
index 8ac501252c..5940df018b 100644
--- a/gnu/packages/java.scm
+++ b/gnu/packages/java.scm
@@ -72,6 +72,7 @@ (define-module (gnu packages java)
   #:use-module (gnu packages ghostscript) ;lcms
   #:use-module (gnu packages gnome)
   #:use-module (gnu packages groovy)
+  #:use-module (gnu packages gstreamer)
   #:use-module (gnu packages gtk)
   #:use-module (gnu packages guile)
   #:use-module (gnu packages icu4c)
@@ -2527,6 +2528,7 @@ (define-public java-openjfx-build
                   ;; Delete source code of a ThirdParty libraries
                   (delete-file-recursively "modules/web/src/main/native/Source/ThirdParty")
                   (delete-file-recursively "modules/web/src/main/native/Source/PlatformJava.cmake")
+                  (delete-file-recursively "modules/graphics/src/main/native-iio/libjpeg")
                   #t))
               (sha256
                (base32
@@ -2539,7 +2541,7 @@ (define-public java-openjfx-build
                                        "java-openjfx-build-web-WTF.patch"
                                        "java-openjfx-build-web-WebKitCompilerFlags.cmake.patch"
                                        "java-openjfx-build-web-icu.patch"
-                                       ))))
+                                       "java-openjfx-build-web-js-test.patch"))))
     (build-system ant-build-system)
     (arguments
      `(#:jar-name "java-openjfx.jar"
@@ -2611,7 +2613,6 @@ (define-public java-openjfx-graphics
     (arguments
      `(#:jar-name "java-openjfx-graphics.jar"
        #:source-dir "modules/graphics/src/main/java"
-       #:tests? #f               ; requires X
        #:test-dir "modules/graphics/src/test"
        #:test-include (list "**/*Test.*")
        #:modules ((guix build ant-build-system)
@@ -2975,13 +2976,15 @@ (class (match:suffix (regexp-exec rx class))))
                #t))
 
            (add-after 'compile-linux-font-pango-lib 'compile-linux-glass-lib
-             (lambda* (#:key inputs #:allow-other-keys)
+             (lambda* (#:key inputs outputs #:allow-other-keys)
                (let* ((classes "modules/graphics/build/classes/java/main")
                       ;; glass
                       (glass-gen-headers "modules/graphics/build/generated-src/headers/glass/linux")
                       (glass-native-lib "modules/graphics/build/libs/glass/linux/libglass.so")
                       (glass-native-obj "modules/graphics/build/native/glass/linux/glass")
-                      (glass-native-src "modules/graphics/src/main/native-glass/gtk/launcher.c")
+                      (glass-native-src "modules/graphics/src/main/native-glass/gtk")
+                      (glass-lib-path (string-append (assoc-ref outputs "out")
+                                                     "/share/amd64"))
                       (jdk (assoc-ref inputs "jdk"))
                       (cc-flags
                        `(,@common-flags "-c" "-ffunction-sections" "-fdata-sections"
@@ -2989,20 +2992,22 @@ (class (match:suffix (regexp-exec rx class))))
                                         "-I" ,(string-append jdk "/include/linux")))
                       (glass-cc-flags
                        `(,@cc-flags
-                         "$(pkg-config --cflags glib-2.0 gdk-2.0 gtk+-2.0 gthread-2.0 xtst)"
+                         "$(pkg-config --cflags glib-2.0 gtk+-2.0 xtst)"
+                         "-Wno-deprecated-declarations"
                          "-Werror"
                          "-Wno-cast-function-type"
                          ))
                       (glass-link-flags
-                       `(,@link-flags "$(pkg-config --libs x11)" "-ldl"))
+                       `(,@link-flags
+                         "$(pkg-config --libs x11 gtk+-2.0)" "-ldl"))
                       ;; glass-gtk2
                       (gtk (assoc-ref inputs "gtk"))
                       (glass-gtk2-native-obj "modules/graphics/build/native/glass/linux/glassgtk2")
-                      (glass-gtk2-native-src (dirname glass-native-src))
+                      (glass-gtk2-native-src glass-native-src)
                       (glass-gtk2-native-lib "modules/graphics/build/libs/glass/linux/libglassgtk2.so")
                       (glass-gtk2-cc-flags
                        `(,@cc-flags
-                         "$(pkg-config --cflags gtk+-2.0 gthread-2.0 xtst)"
+                         "$(pkg-config --cflags gtk+-2.0 xtst)"
                          ;; XX: GTimeVal has been deprecated in GLIB since
                          ;; version 2.62. GTimeVal s not year-2038-safe. Gtk
                          ;; 2.24 uses GTimeVal so our build is also failing.
@@ -3011,21 +3016,7 @@ (class (match:suffix (regexp-exec rx class))))
                          "-Wno-cast-function-type"
                          ))
                       (glass-gtk2-link-flags
-                       `(,@link-flags
-                         "$(pkg-config --libs gtk+-2.0 gthread-2.0 xtst)"))
-                      ;; glass-gtk3
-                      (gtk3 (assoc-ref inputs "gtk3"))
-                      (glass-gtk3-native-obj "modules/graphics/build/native/glass/linux/glassgtk3")
-                      (glass-gtk3-native-src (dirname glass-native-src))
-                      (glass-gtk3-native-lib "modules/graphics/build/libs/glass/linux/libglassgtk3.so")
-                      (glass-gtk3-cc-flags
-                       `(,@cc-flags
-                         "$(pkg-config --cflags gtk+-3.0 gthread-2.0 xtst)"
-                         "-Wno-deprecated-declarations" "-Werror"
-                         "-Wno-cast-function-type"
-                         ))
-                      (glass-gtk3-link-flags
-                       `(,@link-flags "$(pkg-config --libs gtk+-3.0 gthread-2.0 xtst)")))
+                       `(,@link-flags "$(pkg-config --libs gtk+-2.0 xtst)")))
                  ;; glass
                  (mkdir-p glass-gen-headers)
                  (apply invoke "javah"
@@ -3038,14 +3029,16 @@ (class (match:suffix (regexp-exec rx class))))
                                               (string-prefix? "com.sun.glass.ui" class)))
                                         (java-list-classes classes))))
                  (mkdir-p glass-native-obj)
-                 (invoke "bash" "-c"
-                         (string-join `("gcc"
-                                        ,@glass-cc-flags
-                                        "-I" ,glass-gen-headers
-                                        "-I" ,(dirname glass-native-src)
-                                        "-o" ,(string-append glass-native-obj "/"
-                                                             (basename glass-native-src ".c") ".obj")
-                                        ,glass-native-src)))
+                 (for-each (lambda (c)
+                             (invoke "bash" "-c"
+                                     (string-join `("gcc"
+                                                    ,@glass-cc-flags
+                                                    "-I" ,glass-gen-headers
+                                                    "-I" ,glass-native-src
+                                                    "-o" ,(string-append glass-native-obj "/"
+                                                                         (basename c ".c") ".obj")
+                                                    ,c))))
+                           (find-files glass-native-src "\\.c$"))
                  (mkdir-p (dirname glass-native-lib))
                  (invoke "bash" "-c"
                          (string-join `("g++"
@@ -3068,24 +3061,7 @@ (class (match:suffix (regexp-exec rx class))))
                          (string-join `("g++"
                                         ,@glass-gtk2-link-flags
                                         "-o" ,glass-gtk2-native-lib
-                                        ,@(find-files glass-gtk2-native-obj "\\.obj$"))))
-                 ;; gtk3
-                 (mkdir-p glass-gtk3-native-obj)
-                 (for-each (lambda (cpp)
-                             (invoke "bash" "-c"
-                                     (string-join `("gcc"
-                                                    ,@glass-gtk3-cc-flags
-                                                    "-I" ,glass-gen-headers
-                                                    "-o" ,(string-append glass-gtk3-native-obj "/"
-                                                                         (basename cpp ".cpp") ".obj")
-                                                    ,cpp))))
-                           (find-files glass-gtk3-native-src "\\.cpp$"))
-                 (mkdir-p (dirname glass-gtk3-native-lib))
-                 (invoke "bash" "-c"
-                         (string-join `("g++"
-                                        ,@glass-gtk3-link-flags
-                                        "-o" ,glass-gtk3-native-lib
-                                        ,@(find-files glass-gtk3-native-obj "\\.obj$")))))
+                                        ,@(find-files glass-gtk2-native-obj "\\.obj$")))))
                #t))
 
            (add-after 'compile-linux-glass-lib  'compile-linux-iio
@@ -3101,7 +3077,7 @@ (class (match:suffix (regexp-exec rx class))))
                                         "-I" ,(string-append jdk "/include")
                                         "-I" ,(string-append jdk "/include/linux")))
                       (iio-cc-flags cc-flags)
-                      (iio-link-flags link-flags))
+                      (iio-link-flags `(,@link-flags "$(pkg-config --libs libjpeg)")))
                  (mkdir-p iio-gen-headers)
                  (apply invoke "javah"
                         "-d" iio-gen-headers
@@ -3160,7 +3136,7 @@ (class (match:suffix (regexp-exec rx class))))
                                                     "-o" ,(string-append prism-native-obj "/"
                                                                          (basename c ".c") ".obj")
                                                     ,c))))
-                           (find-files prism-native-obj "\\.c$"))
+                           (find-files prism-native-src "\\.c$"))
                  (mkdir-p (dirname prism-native-lib))
                  (invoke "bash" "-c"
                          (string-join `("g++"
@@ -3183,14 +3159,14 @@ (class (match:suffix (regexp-exec rx class))))
                                         "-I" ,(string-append jdk "/include/linux")))
                       (prism-es2-cc-flags `("-DLINUX" ,@cc-flags))
                       (prism-es2-link-flags
-                       `(,@link-flags "$(pkg-config --libs x11 xxf86vm gl)"))
+                       `(,@link-flags "$(pkg-config --libs x11 xxf86vm gl fontconfig)"))
                       ;; We need all *.c files in the root and only those
                       ;; which are in a specific directories.
                       (filter-src
                        (lambda (abs _)
-                         (or (regexp-exec (make-regexp (string-append prism-es2-native-src "[^/]*\\.c$"))
+                         (or (regexp-exec (make-regexp (string-append prism-es2-native-src "/[[:alnum:]]+\\.c$"))
                                           abs)
-                             (regexp-exec (make-regexp (string-append prism-es2-native-src "(x11/|GL/)"))
+                             (regexp-exec (make-regexp (string-append prism-es2-native-src "/(x11/|GL/).*\\.c$"))
                                           abs)))))
                  (mkdir-p prism-es2-gen-headers)
                  (apply invoke "javah"
@@ -3202,7 +3178,6 @@ (class (match:suffix (regexp-exec rx class))))
                  (mkdir-p prism-es2-native-obj)
                  (for-each (lambda (c)
                              (apply invoke "gcc"
-                                    "-I" glass-native-src
                                     "-I" prism-es2-gen-headers
                                     "-I" prism-es2-native-src
                                     "-I" (string-append prism-es2-native-src "/GL")
@@ -3258,7 +3233,7 @@ (class (match:suffix (regexp-exec rx class))))
 
            (add-after 'compile-linux-prism-sw 'install-native
              (lambda* (#:key outputs #:allow-other-keys)
-               (let ((lib (string-append (assoc-ref outputs "out") "/lib")))
+               (let ((lib (string-append (assoc-ref outputs "out") "/share/amd64")))
                  (for-each (lambda (file)
                              (install-file file lib))
                            (find-files "." "\\.so$"))
@@ -3267,25 +3242,54 @@ (class (match:suffix (regexp-exec rx class))))
            (add-after 'install-native 'build-jar
              (lambda _
                (let* ((module (string-append "modules/graphics"))
+                      (decora (string-append module "/build/classes/jsl-decora"))
+                      (prism (string-append module "/build/classes/jsl-prism"))
                       (resources (string-append module "/src/main/resources"))
                       (classes (string-append module "/build/classes/java/main")))
+                 (copy-recursively decora classes)
+                 (copy-recursively prism classes)
                  (copy-recursively resources classes)
 
                  (invoke "ant" "jar" (string-append "-Dclasses.dir=" classes)))
-               #t))))))
+               #t))
+
+           (add-before 'check 'copy-classes
+             (lambda _
+             (copy-recursively "modules/graphics/build/classes/java/main" "build/classes")
+             (substitute* "build.xml"
+               (("<junit.*haltonfailure=\"yes\">" all)
+                (string-append
+                 all
+                 "<sysproperty key=\"java.library.path\" value=\""
+                 (string-join '("modules/graphics/build/libs/prism/linux/"
+                                "modules/graphics/build/libs/font/linux/"
+                                "modules/graphics/build/libs/fontFreetype/linux/"
+                                "modules/graphics/build/libs/fontPango/linux/"
+                                "modules/graphics/build/libs/iio/linux/")
+                              ":")
+                  "\"/>"
+                 "<sysproperty key=\"javafx.toolkit\" value=\"com.sun.javafx.pgstub.StubToolkit\"/>")))
+             #t))))))
     (native-inputs
+     `(("antlr3" ,antlr3)
+       ("java-stringtemplate" ,java-stringtemplate)
+       ("gcc" ,gcc)
+       ("jdk" ,icedtea-8 "jdk")
+       ("pkg-config" ,pkg-config)
+       ("java-junit" ,java-junit)))
+    (inputs
      `(("freetype" ,freetype)
        ("fontconfig" ,fontconfig)
-       ("gcc" ,gcc)
        ("glib" ,glib)
        ("zlib" ,zlib)
        ("gtk" ,gtk+-2)
-       ("gtk3" ,gtk+)
        ("jpeg" ,libjpeg-turbo)
        ("libxtst" ,libxtst)
+       ("mesa" ,mesa)
        ("pango" ,pango)
        ("libpng" ,libpng)
-       ("pkg-config" ,pkg-config)))
+       ("xxf86vm" ,libxxf86vm)
+       ("x11" ,libx11)))
     (propagated-inputs
      `(("java-openjfx-base" ,java-openjfx-base)
        ("java-swt" ,java-swt)))))
@@ -3296,10 +3300,21 @@ (define-public java-openjfx-swing
     (arguments
      `(#:jar-name "java-openjfx-swing.jar"
        #:source-dir "modules/swing/src/main/java"
-       #:tests? #f))
-    (inputs
-     `(("antlr3" ,antlr3)
-       ("java-stringtemplate" ,java-stringtemplate)))
+       #:test-dir "modules/swing/src/test"
+       #:test-include (list "**/*Test.*")
+       #:modules ((guix build ant-build-system)
+                  (guix build utils)
+                  (ice-9 regex))
+       #:phases
+       (modify-phases %standard-phases
+         (add-before 'check 'x-test-setup
+           (lambda _
+             (system "Xvfb :33 &")
+             (setenv "DISPLAY" ":33")
+             #t)))))
+    (native-inputs
+     `(("java-junit" ,java-junit)
+       ("xorg-server" ,xorg-server-for-tests)))
     (propagated-inputs
      `(("java-openjfx-graphics" ,java-openjfx-graphics)))))
 
@@ -3309,6 +3324,7 @@ (define-public java-openjfx-swt
     (arguments
      `(#:jar-name "java-openjfx-swt.jar"
        #:source-dir "modules/swt/src/main/java"
+       ;; no tests available in src
        #:tests? #f))
     (inputs
      `(("antlr3" ,antlr3)
@@ -3322,25 +3338,255 @@ (define-public java-openjfx-controls
     (arguments
      `(#:jar-name "java-openjfx-controls.jar"
        #:source-dir "modules/controls/src/main/java"
-       #:tests? #f
-       #:phases
-       (modify-phases %standard-phases
-         (add-before 'build 'copy-resources
+       #:test-dir "modules/controls/src/test"
+       #:test-include (list "**/*Test.*")
+       #:modules ((guix build ant-build-system)
+                  (guix build utils)
+                  (ice-9 regex))
+       #:phases
+       (modify-phases %standard-phases
+         (add-after 'unpack 'copy-resources
+           (lambda _
+             ;; copy test support files (but not the actual tests themselves)
+             ;; from other modules
+             (copy-recursively "modules/graphics/src/test/java/com/sun/javafx/pgstub"
+                               "modules/controls/src/test/java/com/sun/javafx/pgstub")
+             (for-each delete-file (find-files "modules/controls/src/test/java/com/sun/javafx/pgstub" ".*Test.java$"))
+             (copy-recursively "modules/base/src/test/java/com/sun/javafx/binding"
+                               "modules/controls/src/test/java/com/sun/javafx/binding")
+             (for-each delete-file (find-files "modules/controls/src/test/java/com/sun/javafx/binding" ".*Test.java$"))
+             (copy-recursively "modules/base/src/test/java/javafx/beans"
+                               "modules/controls/src/test/java/javafx/beans")
+             (for-each delete-file (find-files "modules/controls/src/test/java/javafx/beans" ".*Test.java$"))
+             (copy-recursively "modules/base/src/test/java/javafx/collections"
+                               "modules/controls/src/test/java/javafx/collections")
+             (for-each delete-file (find-files "modules/controls/src/test/java/javafx/collections" ".*Test.java$"))
+             (copy-recursively "modules/base/src/test/java/javafx/binding"
+                               "modules/controls/src/test/java/javafx/binding")
+             (for-each delete-file (find-files "modules/controls/src/test/java/javafx/binding" ".*Test.java$"))
+
+             (copy-recursively "modules/controls/src/test/resources"
+                               "build/test-classes")
+             (copy-recursively "modules/controls/src/main/resources"
+                               "build/classes")))
+
+         (add-before 'check 'toolkit
            (lambda _
-             (let ((resources (string-append (getcwd) "/modules/controls/src/main/resources")))
-               (copy-recursively resources "build/classes")) #t)))))
+             (substitute* "build.xml"
+               (("<junit.*haltonfailure=\"yes\">" all)
+                (string-append all
+                               "<sysproperty key=\"javafx.toolkit\" value=\"com.sun.javafx.pgstub.StubToolkit\"/>")))
+             #t)))))
     (propagated-inputs
-     `(("java-openjfx-graphics" ,java-openjfx-graphics)))))
+     `(("java-openjxf-graphics" ,java-openjfx-graphics)))))
 
 (define-public java-openjfx-media
   (package (inherit java-openjfx-build)
     (name "java-openjfx-media")
+    (native-inputs
+     `(("gcc" ,gcc)
+       ("jdk" ,icedtea-8 "jdk")
+       ("pkg-config" ,pkg-config)))
+    (inputs
+     `(("xz" ,xz) ;; workaround for gstreamer's elfutils bug#55793.
+       ("gstreamer" ,gstreamer)
+       ("gst-plugins-base" ,gst-plugins-base)))
     (propagated-inputs
-     `(("java-openjxf-graphics" ,java-openjfx-graphics)))
+     `(("java-openjfx-graphics" ,java-openjfx-graphics)))
     (arguments
      `(#:jar-name "java-openjfx-media.jar"
-       #:source-dir "modules/media/src/main/java"
-       #:tests? #f)); no tests
+       #:source-dir "modules/media/src/main/java:modules/media/src/tools/java"
+       ;; no tests available in src
+       #:tests? #f
+       #:modules ((ice-9 match)
+                  (ice-9 regex)
+                  (guix build ant-build-system)
+                  (guix build utils))
+       #:phases
+       (modify-phases %standard-phases
+         (replace 'build
+           (lambda* (#:key outputs #:allow-other-keys)
+             (let ((lib (string-append (assoc-ref outputs "out")
+                                       "/lib/libjfxmedia.so")))
+               ;; Load jfxmedia.so library directly from output path.
+               (substitute* "modules/media/src/main/java/com/sun/media/jfxmediaimpl/NativeMediaManager.java"
+                 (((regexp-quote "NativeLibLoader.loadLibrary(\"jfxmedia\");"))
+                  (string-append
+                   "System.load(\""
+                   lib
+                   "\");"))))
+             (invoke "ant" "compile" "-Dclasses.dir=modules/media/build/classes/java/main")
+             #t))
+
+         (add-after 'build 'generate-headers
+           (lambda* (#:key inputs #:allow-other-keys)
+             (let* ((classes "modules/media/build/classes/java/main")
+                    (media-generated-headers "modules/media/build/generated-src/headers")
+                    (media-generated-classes
+                     '("com.sun.media.jfxmedia.logging.Logger"
+                       "com.sun.media.jfxmedia.track.AudioTrack"
+                       "com.sun.media.jfxmedia.control.VideoDataBuffer"
+                       "com.sun.media.jfxmedia.control.VideoFormat$FormatTypes"
+                       "com.sun.media.jfxmediaimpl.NativeAudioClip"
+                       "com.sun.media.jfxmediaimpl.NativeMediaPlayer"
+                       "com.sun.media.jfxmediaimpl.NativeVideoBuffer"
+                       "com.sun.media.jfxmediaimpl.platform.gstreamer.GSTPlatform"
+                       "com.sun.media.jfxmediaimpl.platform.gstreamer.GSTMedia"
+                       "com.sun.media.jfxmediaimpl.platform.gstreamer.GSTMediaPlayer"
+                       "com.sun.media.jfxmediaimpl.NativeAudioEqualizer"
+                       "com.sun.media.jfxmediaimpl.NativeEqualizerBand"
+                       "com.sun.media.jfxmediaimpl.NativeAudioSpectrum"))
+                    (graphics (assoc-ref inputs "java-openjfx-graphics")))
+               (mkdir-p media-generated-headers)
+               (invoke "java"
+                       "-Djava.ext.dirs="
+                       "-classpath" classes
+                       "headergen.HeaderGen"
+                       (string-append media-generated-headers "/" "jfxmedia_errors.h")
+                       classes)
+               (apply invoke
+                      "javah"
+                      "-Djava.ext.dirs="
+                      "-XDignore.symbol.file"
+                      "-XDuseUnsharedTable=true"
+                      "-d" media-generated-headers
+                      "-cp" (string-join (cons* classes (find-files graphics "\\.jar$")) ":")
+                      media-generated-classes))
+             #t))
+
+         (add-after 'generate-headers 'media-native-lib
+             (lambda* (#:key inputs #:allow-other-keys)
+               (let* ((classes "modules/media/build/classes/java/main")
+                      (media-gen-headers "modules/media/build/generated-src/headers")
+                      (media-gen-src "modules/media/build/generated-src")
+                      (media-native-lib "modules/media/build/libs/linux/libjfxmedia.so")
+                      (media-native-obj "modules/media/build/native/linux")
+                      ;; ref: modules/media/src/main/native/jfxmedia/projects/linux/Makefile
+                      (media-native-src "modules/media/src/main/native/jfxmedia")
+                      (media-native-src-files
+                       '("jni/com_sun_media_jfxmedia_logging_Logger.cpp"
+                         "jni/JavaBandsHolder.cpp"
+                         "jni/JavaMediaWarningListener.cpp"
+                         "jni/JavaPlayerEventDispatcher.cpp"
+                         "jni/JniUtils.cpp"
+                         "jni/Logger.cpp"
+                         "jni/NativeVideoBuffer.cpp"
+                         "jni/NativeAudioEqualizer.cpp"
+                         "jni/NativeAudioSpectrum.cpp"
+                         "jni/NativeEqualizerBand.cpp"
+                         "jni/JavaInputStreamCallbacks.cpp"
+                         "PipelineManagement/AudioTrack.cpp"
+                         "PipelineManagement/Pipeline.cpp"
+                         "PipelineManagement/PipelineFactory.cpp"
+                         "PipelineManagement/Track.cpp"
+                         "PipelineManagement/VideoFrame.cpp"
+                         "PipelineManagement/VideoTrack.cpp"
+                         "PipelineManagement/SubtitleTrack.cpp"
+                         "MediaManagement/Media.cpp"
+                         "MediaManagement/MediaManager.cpp"
+                         "Locator/Locator.cpp"
+                         "Locator/LocatorStream.cpp"
+                         "Utils/MediaWarningDispatcher.cpp"
+                         "Utils/posix/posix_critical_section.cpp"
+                          "platform/gstreamer/GstMedia.cpp"
+                         "platform/gstreamer/GstMediaPlayer.cpp"
+                         "platform/gstreamer/GstPlatform.cpp"
+                         "platform/gstreamer/GstAudioEqualizer.cpp"
+                         "platform/gstreamer/GstAudioPlaybackPipeline.cpp"
+                         "platform/gstreamer/GstAudioSpectrum.cpp"
+                         "platform/gstreamer/GstAVPlaybackPipeline.cpp"
+                         "platform/gstreamer/GstElementContainer.cpp"
+                         "platform/gstreamer/GstJniUtils.cpp"
+                         "platform/gstreamer/GstMediaManager.cpp"
+                         "platform/gstreamer/GstPipelineFactory.cpp"
+                         "platform/gstreamer/GstVideoFrame.cpp"))
+                      (media-native-src-c "Utils/ColorConverter.c")
+                      (media-src "modules/media/src/main")
+                      (media-classes "modules/media/build/classes")
+                      (jdk (assoc-ref inputs "jdk"))
+                      (gstreamer (assoc-ref inputs "gstreamer"))
+                      (link-flags
+                       '("-pthread"
+                         "-static-libgcc" "-static-libstdc++" "-shared"
+                         "-z" "relro"
+                         "-Wl,--gc-sections"
+                         "$(pkg-config --libs gstreamer-1.0)"
+                         "$(pkg-config --libs gstreamer-plugins-base-1.0)"
+                         "$(pkg-config --libs gstreamer-app-1.0)"))
+                      (cc-flags
+                       `("-pthread"
+                         "-fno-strict-aliasing" "-fPIC" "-fno-omit-frame-pointer" ;; optimization flags
+                         "-fstack-protector"
+                         "-W" "-Wall"
+                         "-DTARGET_OS_LINUX=1"
+                         "-D_GNU_SOURCE"
+                         "-DGST_REMOVE_DEPRECATED"
+                         "-DGST_DISABLE_GST_DEBUG"
+                         "-DGST_DISABLE_LOADSAVE"
+                         "-DGST_DISABLE_XML"
+                         "-DHAVE_CONFIG_H"
+                         "-DJFXMEDIA_JNI_EXPORTS"
+                         "-DLINUX"
+                         "-DG_DISABLE_DEPRECATED"
+                         "-ffunction-sections"
+                         "-fdata-sections"
+                         "-fno-rtti"
+                         "$(pkg-config --cflags gstreamer-1.0)"
+                         "$(pkg-config --cflags gstreamer-plugins-base-1.0)"
+                         "$(pkg-config --cflags gstreamer-app-1.0)"
+                         "-I" ,(string-append jdk "/include")
+                         "-I" ,(string-append jdk "/include/linux"))))
+                 (mkdir-p media-native-obj)
+                 (for-each (lambda (cpp)
+                             (let ((cpp (string-append media-native-src "/" cpp)))
+                               (invoke "bash" "-c"
+                                       (string-join
+                                        (append
+                                         `("g++"
+                                           "-c"
+                                           "-I" ,media-gen-headers
+                                           "-I" ,media-gen-src
+                                           "-I" ,media-native-src
+                                           "-o" ,(string-append media-native-obj
+                                                                "/" (basename cpp ".cpp") ".obj"))
+                                         cc-flags (list cpp))))))
+                           media-native-src-files)
+                 (let ((c (string-append media-native-src "/" media-native-src-c)))
+                   (invoke "bash" "-c"
+                           (string-join
+                            (append
+                             `("g++"
+                               "-c"
+                               "-I" ,media-gen-headers
+                               "-I" ,media-gen-src
+                               "-I" ,media-native-src
+                               "-o" ,(string-append media-native-obj
+                                                    "/" (basename c ".c")
+                                                    ".obj"))
+                             cc-flags (list c)))))
+                 (mkdir-p (dirname media-native-lib))
+                 (invoke "bash" "-c"
+                         (string-join (append
+                                       `("gcc" "-o" ,media-native-lib)
+                                       link-flags
+                                       (find-files media-native-obj "\\.obj$")))))
+               #t))
+         (add-after 'media-native-lib 'install-native
+           (lambda* (#:key outputs #:allow-other-keys)
+             (let ((lib (string-append (assoc-ref outputs "out") "/lib")))
+               (for-each (lambda (file)
+                             (install-file file lib))
+                         (find-files "." "\\.so$"))
+               #t)))
+         (add-after 'install-native 'build-jar
+           (lambda _
+             (let* ((module (string-append "modules/media"))
+                    (resources (string-append module "/src/main/resources"))
+                    (classes (string-append module "/build/classes/java/main")))
+               (copy-recursively resources classes)
+
+               (invoke "ant" "jar" (string-append "-Dclasses.dir=" classes)))
+             #t)))))
     (description "OpenJFX is a client application platform for desktop,
 mobile and embedded systems built on Java.  Its goal is to produce a
 modern, efficient, and fully featured toolkit for developing rich client
@@ -3350,19 +3596,28 @@ (define-public java-openjfx-media
 (define-public java-openjfx-web
   (package (inherit java-openjfx-build)
     (name "java-openjfx-web")
+    (version "8.202")
     (arguments
      `(#:jar-name "java-openjfx-web.jar"
        #:source-dir (string-join '("modules/web/src/main/java"
                                    "modules/web/src/main/native/Source/WebCore/bindings/java/dom3")
                                  ";")
-       #:tests? #f
+       #:test-dir "modules/web/src/test"
+       #:test-include (list "**/*Test.*")
        #:modules ((ice-9 match)
+                  (ice-9 regex)
                   (guix build ant-build-system)
                   (guix build utils))
        #:phases
        (modify-phases %standard-phases
          (replace 'build
-           (lambda* _
+           (lambda* (#:key outputs #:allow-other-keys)
+             (let ((lib (string-append (assoc-ref outputs "out")
+                                       "/lib/libjfxwebkit.so")))
+               (substitute* "modules/web/src/main/java/com/sun/webkit/WebPage.java"
+                 (((regexp-quote "NativeLibLoader.loadLibrary(\"jfxwebkit\");") all)
+                  (string-append
+                   "System.load(\"" lib "\");"))))
              (invoke "ant" "compile" "-Dclasses.dir=modules/web/build/classes/java/main")
              #t))
 
@@ -3418,6 +3673,12 @@ (define-public java-openjfx-web
                       web-generated-classes))
              #t))
 
+         (add-after 'unpack 'copy-resources
+           (lambda _
+             (copy-recursively "modules/web/src/test/resources"
+                               "build/test-classes")
+             (copy-recursively "modules/web/src/main/resources"
+                               "build/classes")))
          (add-after 'generate-headers 'compile-native-linux
            (lambda* (#:key inputs system outputs #:allow-other-keys)
              (let*  ((module (string-append (getcwd) "/modules/web"))
@@ -3468,10 +3729,17 @@ (define-public java-openjfx-web
                                (string-join (list "-W"
                                                   "-DU_DEFINE_FALSE_AND_TRUE=1"
                                                   "-Wall"
-                                                  "-Werror=implicit-function-declaration"
                                                   "-Wl,--gc-sections"
                                                   "-Wno-parentheses"
                                                   "-Wno-unused"
+
+                                                  ;; silence excessive warnings
+                                                  " -Wno-expansion-to-defined"
+                                                  " -Wno-deprecated-copy"
+                                                  " -Wno-redundant-move"
+                                                  " -Wno-class-memaccess"
+                                                  " -Wno-undef"
+
                                                   "-fPIC"
                                                   "-fno-omit-frame-pointer"
                                                   "-fno-strict-aliasing"
@@ -3488,6 +3756,37 @@ (define-public java-openjfx-web
                          (find-files "." "\\.so$")))
              #t))
 
+         (add-before 'check 'x-test-setup
+           (lambda _
+             (system "Xvfb :33 &")
+             (setenv "DISPLAY" ":33")
+             #t))
+
+         (add-before 'x-test-setup 'copy-classes
+           (lambda _
+
+             (mkdir-p "src/test/resources")
+             (copy-recursively
+              "modules/web/src/test/resources"
+              "src/test/resources")
+
+             (mkdir-p "src/main/native/Tools/TestWebKitAPI/Tests/mac/")
+             (copy-file "modules/web/src/main/native/Tools/TestWebKitAPI/Tests/mac/Ahem.ttf"
+                        "src/main/native/Tools/TestWebKitAPI/Tests/mac/Ahem.ttf")
+
+             (with-directory-excursion "modules/web/src/test/resources/test/html/"
+               (apply invoke "jar" "cf" "webArchiveJar.jar" (find-files ".")))
+
+             (copy-recursively "modules/web/build/classes/java/main" "build/classes")
+             (substitute* "build.xml"
+               (("<junit.*haltonfailure=\"yes\">" all)
+                (string-append "<mkdir dir=\"${test.home}/home\" />" ;; home dir required for some tests.
+                               all
+                               "<sysproperty key=\"user.home\" value=\"${test.home}/home\"/>"
+                               "<sysproperty key=\"java.library.path\" value=\"modules/web/build/linux/Release/lib/\"/>"
+                               "<jvmarg value=\"-DWEB_ARCHIVE_JAR_TEST_DIR=modules/web/src/test/resources/test/html/\"/>")))
+             #t))
+
          (add-before 'install 'build-jar
            (lambda _
              (let* ((resources "modules/web/src/main/resources")
@@ -3498,19 +3797,15 @@ (define-public java-openjfx-web
 
     (native-inputs
      `(("java-junit" ,java-junit)
-       ("java-hamcrest-core" ,java-hamcrest-core)
        ("cmake" ,cmake)
-       ("gtk" ,gtk+-2)
-       ("gtk3" ,gtk+)
        ("ruby" ,ruby)
        ("perl" ,perl)
        ("gperf" ,gperf)
        ("python-2" ,python-2)
-       ("pkg-config" ,pkg-config)))
+       ("pkg-config" ,pkg-config)
+       ("xorg-server" ,xorg-server-for-tests)))
     (inputs
-     `(("antlr3" ,antlr3)
-       ("java-stringtemplate" ,java-stringtemplate)
-       ;; Webkit Java port dependencies
+     `(;; Webkit Java port dependencies
        ("icu4c" ,icu4c)
        ("libxml2" ,libxml2)
        ("libxslt" ,libxslt)
@@ -4310,6 +4605,9 @@ (define-public java-swt
      `(#:jar-name "swt.jar"
        #:jdk ,icedtea-8
        #:tests? #f ; no "check" target
+       #:modules ((guix build ant-build-system)
+                  (guix build utils)
+                  (ice-9 regex))
        #:phases
        (modify-phases %standard-phases
          (replace 'unpack
@@ -4319,6 +4617,22 @@ (define-public java-swt
              (chdir "swt")
              (mkdir "src")
              (invoke "unzip" "src.zip" "-d" "src")))
+         ;; explicitly load native library from gnu/store if it can't be found
+         ;; by any of other standard means.
+         (add-before 'configure 'engrave-swt-path
+           (lambda* (#:key outputs #:allow-other-keys)
+             (let ((lib (string-append (assoc-ref outputs "out")
+                                       "/lib")))
+               (substitute* "src/org/eclipse/swt/internal/Library.java"
+                 (((regexp-quote "/* Failed to find the library */") all)
+                  (string-append
+                   "if (path != null) {
+                     path = new File (\"" lib "\").getAbsolutePath ();
+                     if (load (path + SEPARATOR + mappedName1, message)) return;
+                     if (mapName && load (path + SEPARATOR + mappedName2, message)) return;
+                    }\n\n"
+                     all))))
+             #t))
          ;; The classpath contains invalid icecat jars.  Since we don't need
          ;; anything other than the JDK on the classpath, we can simply unset
          ;; it.
-- 
2.34.0

