Skip to content

Commit 67eed6d

Browse files
8309381: Support JavaFX incubator modules
Reviewed-by: angorya, arapte
1 parent da6ad4b commit 67eed6d

File tree

4 files changed

+164
-4
lines changed

4 files changed

+164
-4
lines changed

build.gradle

Lines changed: 50 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2810,6 +2810,20 @@ project(":controls") {
28102810
addValidateSourceSets(project, sourceSets)
28112811
}
28122812

2813+
// Add a project declaration for each incubator module here, leaving the
2814+
// incubator placeholder lines as an example.
2815+
// See CSR JDK-8344644 for more information.
2816+
// BEGIN: incubator placeholder
2817+
//project(":incubator.mymod") {
2818+
// project.ext.buildModule = true
2819+
// project.ext.includeSources = true
2820+
// project.ext.moduleRuntime = true
2821+
// project.ext.moduleName = "jfx.incubator.mymod"
2822+
// project.ext.incubating = true
2823+
// ...
2824+
//}
2825+
// END: incubator placeholder
2826+
28132827
project(":swing") {
28142828

28152829
// We need to skip setting compiler.options.release for this module,
@@ -3965,7 +3979,21 @@ project(":systemTests") {
39653979
testImplementation project(":swing").sourceSets.test.output
39663980
}
39673981

3968-
def dependentProjects = [ 'base', 'graphics', 'controls', 'media', 'jsobject', 'web', 'swing', 'fxml' ]
3982+
def dependentProjects = [
3983+
'base',
3984+
'graphics',
3985+
'controls',
3986+
// Add an entry for each incubator module here, leaving the incubator
3987+
// placeholder lines as an example.
3988+
// BEGIN: incubator placeholder
3989+
//'incubator.mymod',
3990+
// END: incubator placeholder
3991+
'media',
3992+
'jsobject',
3993+
'web',
3994+
'swing',
3995+
'fxml'
3996+
]
39693997
commonModuleSetup(project, dependentProjects)
39703998

39713999
File testRunArgsFile = new File(rootProject.buildDir,TESTRUNARGSFILE);
@@ -4407,8 +4435,21 @@ task javadoc(type: Javadoc, dependsOn: createMSPfile) {
44074435
description = "Generates the JavaDoc for all the public API"
44084436
executable = JAVADOC
44094437
def projectsToDocument = [
4410-
project(":base"), project(":graphics"), project(":controls"), project(":media"),
4411-
project(":swing"), /*project(":swt"),*/ project(":fxml"), project(":jsobject"), project(":web")]
4438+
project(":base"),
4439+
project(":graphics"),
4440+
project(":controls"),
4441+
// Add an entry for each incubator module here, leaving the incubator
4442+
// placeholder lines as an example.
4443+
// BEGIN: incubator placeholder
4444+
//project(":incubator.mymod"),
4445+
// END: incubator placeholder
4446+
project(":media"),
4447+
project(":swing"),
4448+
/*project(":swt"),*/
4449+
project(":fxml"),
4450+
project(":jsobject"),
4451+
project(":web")
4452+
]
44124453
source(projectsToDocument.collect({
44134454
[it.sourceSets.main.java]
44144455
}));
@@ -5787,6 +5828,8 @@ compileTargets { t ->
57875828
def jmodName = "${moduleName}.jmod"
57885829
def jmodFile = "${jmodsDir}/${jmodName}"
57895830

5831+
def incubating = project.hasProperty("incubating") && project.ext.incubating
5832+
57905833
// On Windows, copy the native libraries in the jmod image
57915834
// to a "javafx" subdir to avoid conflicting with the Microsoft
57925835
// DLLs that are shipped with the JDK
@@ -5828,6 +5871,10 @@ compileTargets { t ->
58285871
if (sourceDateEpoch != null) {
58295872
args("--date", extendedTimestamp)
58305873
}
5874+
if (incubating) {
5875+
args("--do-not-resolve-by-default")
5876+
args("--warn-if-resolved=incubating")
5877+
}
58315878
args(jmodFile)
58325879
}
58335880
}
Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
/*
2+
* Copyright (c) 2024, Oracle and/or its affiliates. All rights reserved.
3+
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4+
*
5+
* This code is free software; you can redistribute it and/or modify it
6+
* under the terms of the GNU General Public License version 2 only, as
7+
* published by the Free Software Foundation. Oracle designates this
8+
* particular file as subject to the "Classpath" exception as provided
9+
* by Oracle in the LICENSE file that accompanied this code.
10+
*
11+
* This code is distributed in the hope that it will be useful, but WITHOUT
12+
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13+
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14+
* version 2 for more details (a copy is included in the LICENSE file that
15+
* accompanied this code).
16+
*
17+
* You should have received a copy of the GNU General Public License version
18+
* 2 along with this work; if not, write to the Free Software Foundation,
19+
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20+
*
21+
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22+
* or visit www.oracle.com if you need additional information or have any
23+
* questions.
24+
*/
25+
26+
package com.sun.javafx;
27+
28+
import java.util.HashSet;
29+
import java.util.Set;
30+
31+
/**
32+
* Module utilities.
33+
*/
34+
public class ModuleUtil {
35+
36+
private static final Set<Module> warnedModules = new HashSet<>();
37+
private static final Set<Package> warnedPackages = new HashSet<>();
38+
39+
private static final Module MODULE_JAVA_BASE = Module.class.getModule();
40+
41+
/**
42+
* Prints a warning that an incubator module was loaded. This warning is
43+
* printed to {@code System.err} one time per module.
44+
* An incubator module should call this method from the static initializer
45+
* of each primary class in the module. A primary class is a publicly exported
46+
* class that provides functionality that can be used by an application.
47+
* An incubator module should choose the set of primary classes such that
48+
* any application using an incubating API would access at least one of the
49+
* primary classes.
50+
*/
51+
public static void incubatorWarning() {
52+
var stackWalker = StackWalker.getInstance(StackWalker.Option.RETAIN_CLASS_REFERENCE);
53+
var callerClass = stackWalker.walk(s ->
54+
s.dropWhile(f -> {
55+
var clazz = f.getDeclaringClass();
56+
return ModuleUtil.class.equals(clazz) || MODULE_JAVA_BASE.equals(clazz.getModule());
57+
})
58+
.map(StackWalker.StackFrame::getDeclaringClass)
59+
.findFirst()
60+
.orElseThrow(IllegalStateException::new));
61+
//System.err.println("callerClass = " + callerClass);
62+
var callerModule = callerClass.getModule();
63+
64+
// If we are using incubating API from the unnamed module, issue
65+
// a warning one time for each package. This is not a supported
66+
// mode, but can happen if the modular jar is put on the classpath.
67+
if (!callerModule.isNamed()) {
68+
var callerPackage = callerClass.getPackage();
69+
if (!warnedPackages.contains(callerPackage)) {
70+
System.err.println("WARNING: Using incubating API from an unnamed module: " + callerPackage);
71+
warnedPackages.add(callerPackage);
72+
}
73+
return;
74+
}
75+
76+
// Issue warning one time for this module
77+
if (!warnedModules.contains(callerModule)) {
78+
// FIXME: Check whether this module is jlinked into the runtime
79+
// and thus has already printed a warning. Skip the warning in that
80+
// case to avoid duplicate warnings.
81+
System.err.println("WARNING: Using incubator modules: " + callerModule.getName());
82+
warnedModules.add(callerModule);
83+
}
84+
}
85+
86+
// Prevent instantiation
87+
private ModuleUtil() {
88+
}
89+
}

modules/javafx.base/src/main/java/module-info.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,11 @@
4747

4848
exports com.sun.javafx to
4949
javafx.controls,
50+
// Add an entry for each incubator module here, leaving the incubator
51+
// placeholder lines as an example.
52+
// BEGIN: incubator placeholder
53+
//jfx.incubator.mymod,
54+
// END: incubator placeholder
5055
javafx.graphics,
5156
javafx.fxml,
5257
javafx.media,

settings.gradle

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,30 @@
2323
* questions.
2424
*/
2525

26-
include "base", "graphics", "controls", "swing", "swt", "fxml", "jsobject", "web", "media", "systemTests"
26+
include "base",
27+
"graphics",
28+
"controls",
29+
// Add an entry for each incubator module here, leaving the incubator
30+
// placeholder lines as an example.
31+
// BEGIN: incubator placeholder
32+
//"incubator.mymod",
33+
// END: incubator placeholder
34+
"swing",
35+
"swt",
36+
"fxml",
37+
"jsobject",
38+
"web",
39+
"media",
40+
"systemTests"
2741

2842
project(":base").projectDir = file("modules/javafx.base")
2943
project(":graphics").projectDir = file("modules/javafx.graphics")
3044
project(":controls").projectDir = file("modules/javafx.controls")
45+
// Add an entry for each incubator module here, leaving the incubator
46+
// placeholder lines as an example.
47+
// BEGIN: incubator placeholder
48+
//project(":incubator.mymod").projectDir = file("modules/jfx.incubator.mymod")
49+
// END: incubator placeholder
3150
project(":swing").projectDir = file("modules/javafx.swing")
3251
project(":swt").projectDir = file("modules/javafx.swt")
3352
project(":fxml").projectDir = file("modules/javafx.fxml")

0 commit comments

Comments
 (0)