Skip to content

Commit ca76da4

Browse files
committed
major updates to JavaFX and modules handling
1 parent e59966f commit ca76da4

File tree

5 files changed

+97
-56
lines changed

5 files changed

+97
-56
lines changed

java/libraries/javafx/build.xml

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -95,15 +95,16 @@
9595
<!-- extract the .jar files from the first javafx we run across -->
9696
<!-- <target name="unzip-gluon-jars" unless="${javafx.jars.exist}"> -->
9797
<target name="unzip-gluon-jars">
98-
<echo message="Extracting jars from ${gluon.base}.zip" />
98+
<property name="modules.path" value="${platform.path}/modules" />
99+
<echo message="Extracting jars from ${gluon.base}.zip to ${modules.path}" />
99100
<!-- should javafx.properties be copyed? is it used for anything? [fry 210620] -->
100101

101102
<!-- https://ant.apache.org/manual/Tasks/unzip.html -->
102103
<!-- <unzip dest="${library.path}" src="${gluon.base}.zip" overwrite="true"> -->
103104
<!-- !#($*#! the builds have *slightly* different classes in each release
104105
(WinPlatformFactory not in macOS .jar... FFS it 1100 bytes of glue code)
105106
So the .jar files go into the native subdirectories as well. -->
106-
<unzip dest="${natives.path}" src="${gluon.base}.zip" overwrite="true">
107+
<unzip dest="${modules.path}" src="${gluon.base}.zip" overwrite="true">
107108
<patternset>
108109
<include name="**/*.jar" />
109110
<!-- These two aren't supported/used -->
@@ -117,9 +118,9 @@
117118
</target>
118119

119120
<target name="unzip-gluon-natives">
120-
<echo message="Extracting ${gluon.base}.zip to ${natives.path}" />
121+
<echo message="Extracting native libs from ${gluon.base}.zip to ${platform.path}" />
121122

122-
<unzip dest="${natives.path}" src="${gluon.base}.zip" overwrite="true">
123+
<unzip dest="${platform.path}" src="${gluon.base}.zip" overwrite="true">
123124
<patternset>
124125
<include name="**/*.dll" />
125126
<include name="**/*.dylib" />
@@ -155,17 +156,17 @@
155156
<!-- javafx-${gluon.version}-sdk-${gluon.platform} -->
156157
<antcall target="retrieve-gluon">
157158
<param name="gluon.base" value="javafx-${gluon.version}-sdk-mac" />
158-
<param name="natives.path" value="${library.path}/macosx" />
159+
<param name="platform.path" value="${library.path}/macosx" />
159160
</antcall>
160161

161162
<antcall target="retrieve-gluon">
162163
<param name="gluon.base" value="javafx-${gluon.version}-sdk-windows" />
163-
<param name="natives.path" value="${library.path}/windows64" />
164+
<param name="platform.path" value="${library.path}/windows64" />
164165
</antcall>
165166

166167
<antcall target="retrieve-gluon">
167168
<param name="gluon.base" value="javafx-${gluon.version}-sdk-linux" />
168-
<param name="natives.path" value="${library.path}/linux64" />
169+
<param name="platform.path" value="${library.path}/linux64" />
169170
</antcall>
170171
</target>
171172

@@ -361,8 +362,8 @@
361362
</condition>
362363
-->
363364

364-
<!-- just pick a platform; this should be sufficient for building -->
365-
<property name="javafx.jar.path" value="library/macosx" />
365+
<!-- just pick a platform; any should be sufficient for building -->
366+
<property name="javafx.jar.path" value="library/macosx/modules" />
366367

367368
<mkdir dir="bin" />
368369
<javac source="11" target="11"

java/libraries/javafx/src/processing/javafx/PGraphicsFX2D.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1570,7 +1570,7 @@ protected void textCharImpl(char ch, float x, float y) { //, float z) {
15701570
PFont.Glyph glyph = textFont.getGlyph(ch);
15711571
if (glyph != null) {
15721572
if (textMode == MODEL) {
1573-
float bitmapSize = (float) textFont.getSize();
1573+
float bitmapSize = textFont.getSize();
15741574
float high = glyph.height / bitmapSize;
15751575
float wide = glyph.width / bitmapSize;
15761576
float leftExtent = glyph.leftExtent / bitmapSize;

java/src/processing/mode/java/JavaBuild.java

Lines changed: 55 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -281,7 +281,11 @@ public String preprocess(File srcFolder,
281281
if (library != null) {
282282
if (!importedLibraries.contains(library)) {
283283
importedLibraries.add(library);
284-
classPath += library.getClassPath();
284+
// don't add the JavaFX libraries to the classpath
285+
// https://github.com/processing/processing4/issues/212
286+
if (!library.getName().equals("JavaFX")) {
287+
classPath += library.getClassPath();
288+
}
285289
javaLibraryPath += File.pathSeparator + library.getNativePath();
286290
}
287291
} else {
@@ -440,13 +444,13 @@ public String getClassPath() {
440444
}
441445

442446

443-
/** Returns the dummy "module" path so that JavaFX doesn't complain. */
444-
public String getModulePath() {
445-
// Just set this to the main core/library directory to pick up JavaFX
446-
//return mode.getCoreLibrary().getLibraryPath();
447-
File folder = new File(mode.getFolder(), "libraries/javafx/library");
448-
return folder.getAbsolutePath();
449-
}
447+
// /** Returns the dummy "module" path so that JavaFX doesn't complain. */
448+
// public String getModulePath() {
449+
// // Just set this to the main core/library directory to pick up JavaFX
450+
// //return mode.getCoreLibrary().getLibraryPath();
451+
// File folder = new File(mode.getFolder(), "libraries/javafx/library");
452+
// return folder.getAbsolutePath();
453+
// }
450454

451455

452456
/** Return the java.library.path for this sketch (for all the native DLLs etc). */
@@ -831,6 +835,14 @@ protected boolean exportApplication(File destFolder,
831835
runOptions.append("-Djava.library.path=\"%EXEDIR%\\lib\"");
832836
}
833837

838+
Library javafx = findJavaFX();
839+
if (javafx != null) {
840+
String modulePath = exportPlatform == PConstants.MACOS ?
841+
"$APP_ROOT/Contents/Java/modules" : "lib/modules";
842+
for (String opt : getArgsJavaFX(modulePath)) {
843+
runOptions.append(opt);
844+
}
845+
}
834846

835847
/// macosx: write out Info.plist (template for classpath, etc)
836848

@@ -843,6 +855,7 @@ protected boolean exportApplication(File destFolder,
843855
runOptionsXML.append('\n');
844856
}
845857

858+
846859
String PLIST_TEMPLATE = "Info.plist.tmpl";
847860
File plistTemplate = new File(sketch.getFolder(), PLIST_TEMPLATE);
848861
if (!plistTemplate.exists()) {
@@ -935,16 +948,13 @@ protected boolean exportApplication(File destFolder,
935948
for (String opt : runOptions) {
936949
jre.addChild("opt").setContent(opt);
937950
}
938-
939-
final String[] fxOptions = new String[]{
940-
"--module-path=" + getModulePath(),
941-
"--add-modules=javafx.base,javafx.graphics,javafx.swing",
942-
"--add-exports=javafx.graphics/com.sun.javafx.geom=ALL-UNNAMED",
943-
"--add-exports=javafx.graphics/com.sun.glass.ui=ALL-UNNAMED"
944-
};
945-
for (String opt : fxOptions) {
946-
jre.addChild("opt").setContent(opt);
951+
/*
952+
if (javafx != null) {
953+
for (String opt : getArgsJavaFX("lib")) {
954+
jre.addChild("opt").setContent(opt);
955+
}
947956
}
957+
*/
948958

949959
config.save(configFile);
950960
project.save(buildFile);
@@ -1021,6 +1031,34 @@ protected boolean exportApplication(File destFolder,
10211031
}
10221032

10231033

1034+
// This is a workaround until a more complete solution is found.
1035+
public Library findJavaFX() {
1036+
for (Library library : getImportedLibraries()) {
1037+
if (library.getName().equals("JavaFX")) {
1038+
return library;
1039+
}
1040+
}
1041+
return null;
1042+
}
1043+
1044+
1045+
static public String[] getArgsJavaFX(String modulePath) {
1046+
return new String[] {
1047+
"--module-path", modulePath,
1048+
1049+
// Full list of modules, let's not commit to all of these unless
1050+
// a compelling argument is made or a reason presents itself.
1051+
//"javafx.base,javafx.controls,javafx.fxml,javafx.graphics,javafx.media,javafx.swing,javafx.web"
1052+
"--add-modules", "javafx.base,javafx.graphics,javafx.swing",
1053+
1054+
// TODO Presumably, this is only because com.sun.* classes are being used?
1055+
// https://github.com/processing/processing4/issues/208
1056+
"--add-exports", "javafx.graphics/com.sun.javafx.geom=ALL-UNNAMED",
1057+
"--add-exports", "javafx.graphics/com.sun.glass.ui=ALL-UNNAMED"
1058+
};
1059+
}
1060+
1061+
10241062
static Boolean xcodeInstalled;
10251063

10261064
static protected boolean isXcodeInstalled() {

java/src/processing/mode/java/runner/Runner.java

Lines changed: 15 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ protected void redirectStreams(VirtualMachine vm) {
205205

206206
/**
207207
* Additional access to the virtual machine. TODO: may not be needed
208-
* @return debugge VM or null if not running
208+
* @return debugger VM or null if not running
209209
*/
210210
public VirtualMachine vm() {
211211
return vm;
@@ -367,34 +367,29 @@ protected StringList getMachineParams() {
367367
// librariesClassPath will always have sep char prepended
368368
String javaLibraryPath = build.getJavaLibraryPath();
369369

370-
String javaLibraryPathParam = "-Djava.library.path=" +
371-
javaLibraryPath +
372-
File.pathSeparator +
373-
System.getProperty("java.library.path");
370+
String javaLibraryPathParam =
371+
"-Djava.library.path=" + javaLibraryPath +
372+
File.pathSeparator +
373+
System.getProperty("java.library.path");
374374

375375
params.append(javaLibraryPathParam);
376376

377-
// TODO this should only happen with sketches using the JavaFX library
378-
// https://github.com/processing/processing4/issues/209
379-
params.append("--module-path");
380-
params.append(build.getModulePath());
381-
params.append("--add-modules");
382-
//params.append("javafx.base,javafx.controls,javafx.fxml,javafx.graphics,javafx.media,javafx.swing,javafx.web");
383-
params.append("javafx.base,javafx.graphics,javafx.swing");
384-
// TODO Presumably, we need to move away from com.sun.* classes?
385-
// https://github.com/processing/processing4/issues/208
386-
params.append("--add-exports");
387-
params.append("javafx.graphics/com.sun.javafx.geom=ALL-UNNAMED");
388-
params.append("--add-exports");
389-
params.append("javafx.graphics/com.sun.glass.ui=ALL-UNNAMED");
377+
Library javafx = build.findJavaFX();
378+
if (javafx != null) {
379+
// The .jar files are in the same directory as the natives for windows64 et al,
380+
// because the .jar files are ever-so-slightly different per-platform.
381+
File modulesFolder = new File(javafx.getNativePath(), "modules");
382+
for (String arg : JavaBuild.getArgsJavaFX(modulesFolder.getAbsolutePath())) {
383+
params.append(arg);
384+
}
385+
}
390386

391387
params.append("-cp");
392388
params.append(build.getClassPath());
393389

394390
// enable assertions
395-
// http://dev.processing.org/bugs/show_bug.cgi?id=1188
391+
// http://processing.org/bugs/bugzilla/1188.html
396392
params.append("-ea");
397-
//PApplet.println(PApplet.split(sketch.classPath, ':'));
398393

399394
return params;
400395
}

todo.txt

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -56,19 +56,33 @@ X Only specify --modules-path when running JavaFX apps
5656
X https://github.com/processing/processing4/issues/209
5757
_ lots more cleanup to do in javafx/build.xml
5858

59+
major font cleanup
60+
X JDK fonts have been removed; fonts folder too? (not seeing it in the JDK)
61+
X https://www.oracle.com/java/technologies/javase/11-relnote-issues.html#JDK-8191522
62+
X more reliable loading of default mono fonts
63+
X processing.mono used in preferences.txt
64+
X remove Preferences.getFont(), deal with incorrect usage
65+
X getFont("editor.font") was returning getFont("editor.font.size")
66+
5967

60-
_ "Could not run" "For more information, read revisions.txt and Help → Troubleshooting."
61-
_ need to drop revisions.txt here and just reference Troubleshooting
6268

6369
for next release
6470
_ debug JavaFX and Export to Application on Windows
6571
_ this was working on Saturday, now broken after the move to a separate library
6672
_ now "Art Station" is broken because it actually creates an FX2D sketch
6773
_ (and FX2D isn't on the classpath by default)
6874
_ debug JavaFX and Export to Application on Linux
75+
_ fix modules path warning for Tools in the PDE
76+
_ "WARNING: Unsupported JavaFX configuration" when running Tools that use JavaFX
77+
_ we were probably spared the warnings because the older JARs were hanging around
78+
_ update modules path when exporting application
79+
_ automatically import JavaFX if FX2D is in sketch? or tell user?
6980
_ Code completion not working
7081
_ https://github.com/processing/processing4/issues/177
7182
_ confirmed not working from Sam's repo either
83+
_ "Could not run" "For more information, read revisions.txt and Help → Troubleshooting."
84+
_ need to drop revisions.txt here and just reference Troubleshooting
85+
7286

7387
_ replace bug numbers
7488
_ http://dev.processing.org/bugs/show_bug.cgi?id=1188
@@ -80,13 +94,6 @@ _ macosx vs macosx64 in JavaFX
8094
_ the latter is making the export fail because it won't embed a Java VM
8195
_ may be because it's exporting twice and overwriting? or 64 takes precedence?
8296

83-
_ fix modules path warning for Tools in the PDE
84-
_ "WARNING: Unsupported JavaFX configuration" when running Tools that use JavaFX
85-
_ we were probably spared the warnings because the older JARs were hanging around
86-
87-
_ update modules path when exporting application
88-
89-
_ automatically import JavaFX if FX2D is in sketch? or tell user?
9097

9198
_ Remove usage of com.sun.* in JavaFX library
9299
_ https://github.com/processing/processing4/issues/208

0 commit comments

Comments
 (0)