Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: Modular app with jlink/jpackage build #89

Draft
wants to merge 3 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions bootloader/src/main/java/jGnash.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

import jgnash.app.jGnashFx;
import jgnash.bootloader.BootLoader;
import jgnash.bootloader.BootLoaderDialog;

Expand Down
2 changes: 1 addition & 1 deletion jgnash-core/build.gradle
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
description = "jGnash Core"

project.ext {
moduleName = "jgnash-core"
moduleName = "jgnash.core"
}

dependencies {
Expand Down
89 changes: 38 additions & 51 deletions jgnash-fx/build.gradle
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
plugins {
id 'application'
id "org.openjfx.javafxplugin"
id 'org.beryx.jlink' version '2.15.1'
id 'org.javamodularity.moduleplugin' version "1.5.0"
}

apply plugin: "distribution"
apply plugin: "application" // creates a task to run the full application

description = "jGnash JavaFx"
mainClassName = "jGnashFx"

application {
mainClassName = "$moduleName/jgnash.app.jGnashFx"
applicationName = 'jGnashFx'
}


dependencies {
//compile project(":jgnash-manual")
Expand All @@ -16,42 +21,7 @@ dependencies {
compile project(":jgnash-plugin")

compile group: "info.picocli", name: "picocli", version: picocliVersion

// Hack to include all javafx platforms in the classpath
// The platform specific libraries are excluded when distributions is assembled
compile "org.openjfx:javafx-base:" + javaFXVersion
compile "org.openjfx:javafx-controls:" + javaFXVersion
compile "org.openjfx:javafx-fxml:" + javaFXVersion
compile "org.openjfx:javafx-graphics:" + javaFXVersion
compile "org.openjfx:javafx-media:" + javaFXVersion
compile "org.openjfx:javafx-swing:" + javaFXVersion
compile "org.openjfx:javafx-web:" + javaFXVersion

compile "org.openjfx:javafx-base:" + javaFXVersion + ":linux"
compile "org.openjfx:javafx-controls:" + javaFXVersion + ":linux"
compile "org.openjfx:javafx-fxml:" + javaFXVersion + ":linux"
compile "org.openjfx:javafx-graphics:" + javaFXVersion + ":linux"
compile "org.openjfx:javafx-media:" + javaFXVersion + ":linux"
compile "org.openjfx:javafx-swing:" + javaFXVersion + ":linux"
compile "org.openjfx:javafx-web:" + javaFXVersion + ":linux"

compile "org.openjfx:javafx-base:" + javaFXVersion + ":win"
compile "org.openjfx:javafx-controls:" + javaFXVersion + ":win"
compile "org.openjfx:javafx-fxml:" + javaFXVersion + ":win"
compile "org.openjfx:javafx-graphics:" + javaFXVersion + ":win"
compile "org.openjfx:javafx-media:" + javaFXVersion + ":win"
compile "org.openjfx:javafx-swing:" + javaFXVersion + ":win"
compile "org.openjfx:javafx-web:" + javaFXVersion + ":win"

compile "org.openjfx:javafx-base:" + javaFXVersion + ":mac"
compile "org.openjfx:javafx-controls:" + javaFXVersion + ":mac"
compile "org.openjfx:javafx-fxml:" + javaFXVersion + ":mac"
compile "org.openjfx:javafx-graphics:" + javaFXVersion + ":mac"
compile "org.openjfx:javafx-media:" + javaFXVersion + ":mac"
compile "org.openjfx:javafx-swing:" + javaFXVersion + ":mac"
compile "org.openjfx:javafx-web:" + javaFXVersion + ":mac"
// end hack


// required of Unit testing JavaFX
testCompile group: 'org.testfx', name: 'testfx-junit5', version: '4.0.15-alpha'
testCompile group: 'org.testfx', name: 'openjfx-monocle', version: 'jdk-12.0.1+2'
Expand Down Expand Up @@ -84,17 +54,6 @@ distZip {
}
}

distributions {
main {
baseName = "jGnash"
contents {
exclude("**/*-linux*") // excludes linux specific JavaFx modules from cross platform zip
exclude("**/*-win*") // excludes windows specific JavaFx modules from cross platform zip
exclude("**/*-mac*") // excludes mac specific JavaFx modules from cross platform zip
}
}
}

jar {
// Keep jar clean:
exclude "META-INF/*.SF", "META-INF/*.DSA", "META-INF/*.RSA", "META-INF/*.MF"
Expand All @@ -104,3 +63,31 @@ jar {
"Class-Path": configurations.runtimeClasspath.files.collect { "lib/$it.name" }.join(" ")
}
}

jlink {
addExtraDependencies("javafx")
options = ['--strip-debug', '--compress', '2', '--no-header-files', '--no-man-pages']
launcher {
name = applicationName
jvmArgs = []
}
mergedModule {
requires 'java.logging'

requires 'javafx.controls'
requires 'javafx.fxml'
requires 'javafx.web'
requires 'javafx.swing'
requires 'javafx.graphics'
requires 'javafx.media'
}
jpackage {
// See https://badass-jlink-plugin.beryx.org/releases/latest/#_jpackage for
// where the plugin's jpackage task finds the path to the jpackage tool by default
// (Currently you need to manually install a OpenJDK 14 Early Access Build including jpackage)
jpackageHome = System.getenv('BADASS_JLINK_JPACKAGE_HOME')
skipInstaller = false
identifier = applicationName
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package jgnash.app;

import java.io.File;
import java.io.FileNotFoundException;
Expand Down Expand Up @@ -91,6 +92,10 @@ public static void main(final String[] args) {
Thread.setDefaultUncaughtExceptionHandler(new StaticUIMethods.ExceptionHandler());

final CommandLine commandLine = new CommandLine(new CommandLineOptions());
// Hack: Allow unmatched arguments due to Gradle -- because of xx plugin(s)? -- is putting the following args
// '-Dfile.encoding=UTF-8', '-Duser.country=US', '-Duser.language=en', '-Duser.variant' at the
// end of the JavaExec command line for :run task
commandLine.setUnmatchedArgumentsAllowed(true);
commandLine.setToggleBooleanFlags(false);
commandLine.setUsageHelpWidth(80);

Expand Down
15 changes: 12 additions & 3 deletions jgnash-fx/src/main/java/jgnash/uifx/views/main/MainView.java
Original file line number Diff line number Diff line change
Expand Up @@ -166,8 +166,14 @@ public void start(final Stage stage, @Nullable final File dataFile, final char[]

busyPane = new BusyPane();

final FXMLLoader fxmlLoader = new FXMLLoader(MenuBarController.class.getResource("MainMenuBar.fxml"), resources);
menuBar = fxmlLoader.load();
// It's nice to have some logging output when stuff fails in the FX start() method, and this code
// was failing as I was debugging module-info.java
try {
final FXMLLoader fxmlLoader = new FXMLLoader(MenuBarController.class.getResource("MainMenuBar.fxml"), resources);
menuBar = fxmlLoader.load();
} catch (Exception e) {
logger.log(Level.SEVERE, e.getLocalizedMessage(), e);
}

final ToolBar mainToolBar = FXMLLoader.load(MainToolBarController.class.getResource("MainToolBar.fxml"), resources);

Expand All @@ -193,7 +199,10 @@ public void start(final Stage stage, @Nullable final File dataFile, final char[]
scene.getRoot().styleProperty().bind(ThemeManager.styleProperty());

stage.setTitle(TITLE);
stage.getIcons().add(StaticUIMethods.getApplicationIcon());
// Hack: Comment out this line so `./gradlew :jgnash-fx:run` can at least start the app
// The hack is just kicking the can down the road as the app will crash later when the icon is expected
// to be non-null
//stage.getIcons().add(StaticUIMethods.getApplicationIcon());
stage.setScene(scene);
stage.setResizable(true);

Expand Down
27 changes: 27 additions & 0 deletions jgnash-fx/src/main/java/module-info.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
module jgnashfx {
requires java.logging;
requires java.prefs;
requires java.desktop;
requires java.scripting;

requires javafx.base;
requires javafx.controls;
requires javafx.fxml;
requires javafx.web;
requires javafx.swing;
requires javafx.graphics;
requires javafx.media;

requires info.picocli;

requires jgnash.resources;

exports jgnash.app;
exports jgnash.uifx;

opens jgnash.uifx to javafx.fxml, java.base;
opens jgnash.uifx.views.main to javafx.fxml;
opens jgnash.uifx.resource.font to javafx.fxml;
opens jgnash.uifx.control to javafx.fxml;
opens jgnash.app to javafx.fxml, java.base, info.picocli;
}
2 changes: 1 addition & 1 deletion jgnash-fx/src/main/resources/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Manifest-Version: 1.0
Application-Name: jGnashFx
JavaFX-Application-Class: jGnashFx
Main-Class: jGnashFx
Main-Class: jgnash.app.jGnashFx
2 changes: 1 addition & 1 deletion jgnash-resources/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import static org.gradle.internal.os.OperatingSystem.*
description = "jGnash Resources"

project.ext {
moduleName = "jgnash.convert"
moduleName = "jgnash.resources"

javaVersion = Jvm.current()
osName = current()
Expand Down