Skip to content

Commit

Permalink
Headless compilation on Windows is now possible again.
Browse files Browse the repository at this point in the history
  • Loading branch information
JanMosigItemis committed Mar 14, 2019
1 parent 5037299 commit a1f43ec
Show file tree
Hide file tree
Showing 5 changed files with 71 additions and 5 deletions.
1 change: 0 additions & 1 deletion DownloadEntryTestFakePath

This file was deleted.

3 changes: 0 additions & 3 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -583,9 +583,6 @@
</activation>
<properties>
<current.os>win</current.os>
<!-- Deactivating headless build by removing the headless
JVM options. This is a workaround for bug https://github.com/javafxports/openjdk-jfx/issues/66 -->
<jvm.options></jvm.options>
</properties>
</profile>
<profile>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ public class AddDownloadSourceDialogUiTest {

private AddDownloadSourceDialogUiTestDriver dialog;

static {
OpenJfxMonocleWindowsBugWorkaround.runIfOnWindows();
}

@BeforeEach
public void setUp() {
dialog = new JavaFxAddDownloadSourceDialogUiTestDriver();
Expand Down
7 changes: 6 additions & 1 deletion src/test/java/de/itemis/jmo/dodo/ui/DodoUiTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,12 @@ public class DodoUiTest {
* Managed in a static way, because it is not possible to "restart" a JavaFX app during one test
* run.
*/
private static final DodoUiTestDriver DODO = new JavaFxDodoTestDriver();
private static final DodoUiTestDriver DODO;

static {
OpenJfxMonocleWindowsBugWorkaround.runIfOnWindows();
DODO = new JavaFxDodoTestDriver();
}

@BeforeAll
public static void setUpStatic() {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
package de.itemis.jmo.dodo.ui;

import static com.google.common.base.Strings.nullToEmpty;

import com.google.common.base.StandardSystemProperty;

import de.itemis.jmo.dodo.util.InstantiationNotAllowedException;

/**
* <p>
* The currently used version of OpenJFX (11.0.2) has a bug when run in headless mode with Monocle
* on Windows machines. A fix will not be available before release 13.x. However, there exists a
* workaround.
* </p>
* <p>
* Run {@link #runIfOnWindows()} before any JavaFX code is run or initialized, e. g.:
*
* <pre>
* package a.b.c
*
* public class SomeMain {
* static {
* OpenJfxMonocleWindowsBugWorkaround.runIfOnWindows();
* }
*
* public static void main(String[] args) {
* // Run FX App
* }
* }
* </pre>
*
* @see <a href="https://github.com/javafxports/openjdk-jfx">OpenJFX</a>
* @see <a href="https://wiki.openjdk.java.net/display/OpenJFX/Monocle">Monocle</a>
* @see <a href=
* "https://github.com/javafxports/openjdk-jfx/issues/66#issuecomment-468370664">Workaround</a>
*/
final class OpenJfxMonocleWindowsBugWorkaround {

private static boolean alreadyLoaded = false;

private OpenJfxMonocleWindowsBugWorkaround() {
throw new InstantiationNotAllowedException();
}

/**
* Check if we are running on a Windows OS and perform workaround if so.
*
* @see <a href=
* "https://github.com/javafxports/openjdk-jfx/issues/66#issuecomment-468370664">Workaround</a>
*/
public static void runIfOnWindows() {
if (!alreadyLoaded && osIsWindows()) {
alreadyLoaded = true;
System.load("C:\\Windows\\System32\\WindowsCodecs.dll");
}
}

private static boolean osIsWindows() {
return nullToEmpty(System.getProperty(StandardSystemProperty.OS_NAME.key())).toLowerCase().contains("windows");
}
}

0 comments on commit a1f43ec

Please sign in to comment.