diff --git a/buildSrc/linux.gradle b/buildSrc/linux.gradle index 387d5eee063..119449246a3 100644 --- a/buildSrc/linux.gradle +++ b/buildSrc/linux.gradle @@ -82,40 +82,9 @@ if (hasProperty('toolchainDir')) { toolchainDir = "" } -def gtk2CCFlags = [ "-Wno-deprecated-declarations" ]; def gtk3CCFlags = [ "-Wno-deprecated-declarations" ]; -def gtk2LinkFlags = [ ]; def gtk3LinkFlags = [ ]; -// Create $buildDir/linux_tools.properties file and load props from it -setupTools("linux_gtk2", - { propFile -> - ByteArrayOutputStream results1 = new ByteArrayOutputStream(); - exec { - commandLine("${toolchainDir}pkg-config", "--cflags", "gtk+-2.0", "gthread-2.0", "xtst") - setStandardOutput(results1); - } - propFile << "cflagsGTK2=" << results1.toString().trim() << "\n"; - - ByteArrayOutputStream results3 = new ByteArrayOutputStream(); - exec { - commandLine("${toolchainDir}pkg-config", "--libs", "gtk+-2.0", "gthread-2.0", "xtst") - setStandardOutput(results3); - } - propFile << "libsGTK2=" << results3.toString().trim() << "\n"; - }, - { properties -> - def cflagsGTK2 = properties.getProperty("cflagsGTK2") - def libsGTK2 = properties.getProperty("libsGTK2") - if (cflagsGTK2 && libsGTK2) { - gtk2CCFlags.addAll(cflagsGTK2.split(" ")) - gtk2LinkFlags.addAll(libsGTK2.split(" ")) - } else { - throw new IllegalStateException("GTK2 development packages not found. If GTK2 packages are installed, please remove the build directory and try again.") - } - } -) - setupTools("linux_gtk3", { propFile -> ByteArrayOutputStream results2 = new ByteArrayOutputStream(); @@ -216,7 +185,7 @@ LINUX.strip = "${toolchainDir}strip" LINUX.stripArgs = [ "-x" ] LINUX.glass = [:] -LINUX.glass.variants = ["glass", "glassgtk2", "glassgtk3"] +LINUX.glass.variants = ["glass", "glassgtk3"] FileTree ft_gtk_launcher = fileTree("${project(":graphics").projectDir}/src/main/native-glass/gtk/") { include("**/launcher.c") @@ -234,16 +203,6 @@ LINUX.glass.glass.linker = linker LINUX.glass.glass.linkFlags = IS_STATIC_BUILD? linkFlags : [linkFlags, "-lX11", "-ldl"].flatten() LINUX.glass.glass.lib = "glass" -LINUX.glass.glassgtk2 = [:] -LINUX.glass.glassgtk2.nativeSource = ft_gtk.getFiles() -LINUX.glass.glassgtk2.compiler = compiler -LINUX.glass.glassgtk2.ccFlags = IS_STATIC_BUILD ? - ["-fno-threadsafe-statics", cppFlags, gtk2CCFlags].flatten() : - [cppFlags, gtk2CCFlags, "-Werror"].flatten() -LINUX.glass.glassgtk2.linker = linker -LINUX.glass.glassgtk2.linkFlags = IS_STATIC_BUILD ? linkFlags : [linkFlags, gtk2LinkFlags].flatten() -LINUX.glass.glassgtk2.lib = "glassgtk2" - LINUX.glass.glassgtk3 = [:] LINUX.glass.glassgtk3.nativeSource = ft_gtk.getFiles() LINUX.glass.glassgtk3.compiler = compiler diff --git a/modules/javafx.graphics/src/main/java/com/sun/glass/ui/gtk/GtkApplication.java b/modules/javafx.graphics/src/main/java/com/sun/glass/ui/gtk/GtkApplication.java index 74281fbf2d7..38c7e0cf3a8 100644 --- a/modules/javafx.graphics/src/main/java/com/sun/glass/ui/gtk/GtkApplication.java +++ b/modules/javafx.graphics/src/main/java/com/sun/glass/ui/gtk/GtkApplication.java @@ -42,7 +42,6 @@ import com.sun.javafx.logging.PlatformLogger; import java.io.File; -import java.lang.reflect.Method; import java.nio.ByteBuffer; import java.nio.IntBuffer; import java.security.AccessController; @@ -51,72 +50,31 @@ import java.util.concurrent.CountDownLatch; import java.lang.annotation.Native; + final class GtkApplication extends Application implements InvokeLaterDispatcher.InvokeLaterSubmitter { - private static final String SWT_INTERNAL_CLASS = - "org.eclipse.swt.internal.gtk.OS"; private static final int forcedGtkVersion; - private static boolean gtk2WarningIssued = false; - private static final String GTK2_ALREADY_LOADED_WARNING = - "WARNING: Found GTK 2 library already loaded"; - private static final String GTK2_SPECIFIED_WARNING = - "WARNING: A command line option has enabled the GTK 2 library"; - private static final String GTK2_FALLBACK_WARNING = - "WARNING: Using GTK 2 library because GTK 3 cannot be loaded "; - private static final String GTK2_DEPRECATION_WARNING = - "WARNING: The JavaFX GTK 2 library is deprecated and will be removed in a future release"; + private static boolean gtkVersionWarningIssued = false; + private static final String GTK2_REMOVED_WARNING = + "WARNING: A command line option tried to select the GTK 2 library, which was removed from JavaFX."; + private static final String GTK_INVALID_VERSION_WARNING = + "WARNING: A command line option tried to select an invalid GTK library version."; + private static final String GTK3_FALLBACK_WARNING = "WARNING: The GTK 3 library will be used instead."; static { - //check for SWT-GTK lib presence - @SuppressWarnings("removal") - Class OS = AccessController. - doPrivileged((PrivilegedAction>) () -> { - try { - return Class.forName(SWT_INTERNAL_CLASS, true, - ClassLoader.getSystemClassLoader()); - } catch (Exception e) {} - try { - return Class.forName(SWT_INTERNAL_CLASS, true, - Thread.currentThread().getContextClassLoader()); - } catch (Exception e) {} - return null; - }); - if (OS != null) { + String gtkVersion = System.getProperty("org.eclipse.swt.internal.gtk.version"); + if (gtkVersion != null && gtkVersion.contains(".")) { PlatformLogger logger = Logging.getJavaFXLogger(); - logger.fine("SWT-GTK library found. Try to obtain GTK version."); - @SuppressWarnings("removal") - Method method = AccessController. - doPrivileged((PrivilegedAction) () -> { - try { - return OS.getMethod("gtk_major_version"); - } catch (Exception e) { - return null; - } - }); - int ver = 0; - if (method != null) { - try { - ver = ((Number)method.invoke(OS)).intValue(); - } catch (Exception e) { - logger.warning("Method gtk_major_version() of " + - "the org.eclipse.swt.internal.gtk.OS class " + - "returns error. SWT GTK version cannot be detected. " + - "GTK3 will be used as default."); - ver = 3; - } - } - if (ver < 2 || ver > 3) { - logger.warning("SWT-GTK uses unsupported major GTK version " - + ver + ". GTK3 will be used as default."); - ver = 3; + logger.fine(String.format("SWT-GTK library found. Gtk Version = %s.", gtkVersion)); + String[] vers = gtkVersion.split("\\."); + int ver = Integer.parseInt(vers[0]); + + if (ver != 3) { + throw new UnsupportedOperationException("SWT-GTK uses unsupported major GTK version " + ver + " ."); } + forcedGtkVersion = ver; - if (ver == 2 && !gtk2WarningIssued) { - System.err.println(GTK2_ALREADY_LOADED_WARNING); - System.err.println(GTK2_DEPRECATION_WARNING); - gtk2WarningIssued = true; - } } else { forcedGtkVersion = 0; } @@ -162,22 +120,24 @@ private static float getFloat(String propname, float defval, String description) GtkApplication() { @SuppressWarnings("removal") - final int gtkVersion = forcedGtkVersion == 0 ? + int gtkVersion = forcedGtkVersion == 0 ? AccessController.doPrivileged((PrivilegedAction) () -> { String v = System.getProperty("jdk.gtk.version","3"); - int ret = 0; - if ("3".equals(v) || v.startsWith("3.")) { - ret = 3; - } else if ("2".equals(v) || v.startsWith("2.")) { - ret = 2; - } - return ret; + return Character.getNumericValue(v.charAt(0)); }) : forcedGtkVersion; - if (gtkVersion == 2 && !gtk2WarningIssued) { - System.err.println(GTK2_SPECIFIED_WARNING); - System.err.println(GTK2_DEPRECATION_WARNING); - gtk2WarningIssued = true; + if (gtkVersion != 3) { + if (!gtkVersionWarningIssued) { + if (gtkVersion == 2) { + System.err.println(GTK2_REMOVED_WARNING); + } else { + System.err.println(GTK_INVALID_VERSION_WARNING); + } + } + + System.err.println(GTK3_FALLBACK_WARNING); + gtkVersionWarningIssued = true; + gtkVersion = 3; } @SuppressWarnings("removal") @@ -204,32 +164,18 @@ private static float getFloat(String propname, float defval, String description) if (gtkVersionVerbose) { System.out.println("Glass GTK library to load is already loaded"); } - } else if (libraryToLoad == QUERY_LOAD_GTK2) { - if (gtkVersionVerbose) { - System.out.println("Glass GTK library to load is glassgtk2"); - } - NativeLibLoader.loadLibrary("glassgtk2"); - if (!gtk2WarningIssued) { - System.err.println(GTK2_FALLBACK_WARNING); - System.err.println(GTK2_DEPRECATION_WARNING); - gtk2WarningIssued = true; - } } else if (libraryToLoad == QUERY_LOAD_GTK3) { if (gtkVersionVerbose) { System.out.println("Glass GTK library to load is glassgtk3"); } NativeLibLoader.loadLibrary("glassgtk3"); } else { - throw new UnsupportedOperationException("Internal Error"); + throw new UnsupportedOperationException("Unable to load glass GTK library."); } return null; }); - int version = _initGTK(gtkVersion, gtkVersionVerbose, overrideUIScale); - - if (version == -1) { - throw new RuntimeException("Error loading GTK libraries"); - } + _initGTK(gtkVersion, gtkVersionVerbose, overrideUIScale); // Embedded in SWT, with shared event thread @SuppressWarnings("removal") @@ -246,7 +192,6 @@ private static float getFloat(String propname, float defval, String description) @Native private static final int QUERY_ERROR = -2; @Native private static final int QUERY_NO_DISPLAY = -1; @Native private static final int QUERY_USE_CURRENT = 1; - @Native private static final int QUERY_LOAD_GTK2 = 2; @Native private static final int QUERY_LOAD_GTK3 = 3; /* * check the system and return an indication of which library to load @@ -254,7 +199,7 @@ private static float getFloat(String propname, float defval, String description) */ private static native int _queryLibrary(int version, boolean verbose); - private static native int _initGTK(int version, boolean verbose, float overrideUIScale); + private static native void _initGTK(int version, boolean verbose, float overrideUIScale); private void initDisplay() { Map ds = getDeviceDetails(); diff --git a/modules/javafx.graphics/src/main/native-glass/gtk/GlassApplication.cpp b/modules/javafx.graphics/src/main/native-glass/gtk/GlassApplication.cpp index e3614ba57ef..9a8c08d500d 100644 --- a/modules/javafx.graphics/src/main/native-glass/gtk/GlassApplication.cpp +++ b/modules/javafx.graphics/src/main/native-glass/gtk/GlassApplication.cpp @@ -95,9 +95,9 @@ jboolean gtk_verbose = JNI_FALSE; /* * Class: com_sun_glass_ui_gtk_GtkApplication * Method: _initGTK - * Signature: (IZ)I + * Signature: (IZ)V */ -JNIEXPORT jint JNICALL Java_com_sun_glass_ui_gtk_GtkApplication__1initGTK +JNIEXPORT void JNICALL Java_com_sun_glass_ui_gtk_GtkApplication__1initGTK (JNIEnv *env, jclass clazz, jint version, jboolean verbose, jfloat uiScale) { (void) clazz; @@ -112,7 +112,20 @@ JNIEXPORT jint JNICALL Java_com_sun_glass_ui_gtk_GtkApplication__1initGTK gdk_threads_enter(); gtk_init(NULL, NULL); - return JNI_TRUE; + // Major version is checked before loading + if (version == 3 + && gtk_check_version(version, GTK_3_MIN_MINOR_VERSION, GTK_3_MIN_MICRO_VERSION)) { + char message[100]; + snprintf(message, sizeof(message), + "Minimum GTK version required is %d.%d.%d. System has %d.%d.%d.", + version, GTK_3_MIN_MINOR_VERSION, GTK_3_MIN_MICRO_VERSION, + gtk_major_version, gtk_minor_version, gtk_micro_version); + + jclass uoe = env->FindClass("java/lang/UnsupportedOperationException"); + env->ThrowNew(uoe, message); + + return; + } } /* diff --git a/modules/javafx.graphics/src/main/native-glass/gtk/glass_general.h b/modules/javafx.graphics/src/main/native-glass/gtk/glass_general.h index 0f0f1b5b7cc..c96500322ff 100644 --- a/modules/javafx.graphics/src/main/native-glass/gtk/glass_general.h +++ b/modules/javafx.graphics/src/main/native-glass/gtk/glass_general.h @@ -42,6 +42,9 @@ #define GLASS_GTK3 #endif +#define GTK_3_MIN_MINOR_VERSION 8 +#define GTK_3_MIN_MICRO_VERSION 0 + #ifndef GDK_TOUCH_MASK #define GDK_TOUCH_MASK (1 << 22) #endif diff --git a/modules/javafx.graphics/src/main/native-glass/gtk/launcher.c b/modules/javafx.graphics/src/main/native-glass/gtk/launcher.c index 4cb3eda6179..9dab981a718 100644 --- a/modules/javafx.graphics/src/main/native-glass/gtk/launcher.c +++ b/modules/javafx.graphics/src/main/native-glass/gtk/launcher.c @@ -47,12 +47,8 @@ static jboolean gtk_versionDebug = JNI_FALSE; -static const char * gtk2_chain[] = { - "libglassgtk2.so", "libglassgtk3.so", 0 -}; - static const char * gtk3_chain[] = { - "libglassgtk3.so", "libglassgtk2.so", 0 + "libglassgtk3.so", 0 }; static JavaVM* javaVM; @@ -91,14 +87,12 @@ static char * gtk3_not_versioned[] = { }; // our library set orders defined, null terminated -static char ** two_to_three[] = { - gtk2_versioned, gtk2_not_versioned, +static char ** gtk3_lib_options[] = { gtk3_versioned, gtk3_not_versioned, 0 }; -static char ** three_to_two[] = { - gtk3_versioned, gtk3_not_versioned, +static char ** gtk2_lib_options[] = { gtk2_versioned, gtk2_not_versioned, 0 }; @@ -129,11 +123,11 @@ static int try_libraries_noload(char *names[3]) static int sniffLibs(int wantVersion) { if (gtk_versionDebug) { - printf("checking GTK version %d\n",wantVersion); + printf("checking GTK version %d\n", wantVersion); } int success = 1; - char *** use_chain = three_to_two; + char *** use_chain = gtk3_lib_options; int i, found = 0; //at first try to detect already loaded GTK version @@ -144,18 +138,25 @@ static int sniffLibs(int wantVersion) { } } - if (!found) { - if (wantVersion == 0 || wantVersion == 3) { - use_chain = three_to_two; - } else if (wantVersion == 2) { - use_chain = two_to_three; - } else { + if (!found) { + char *** bad_use_chain = gtk2_lib_options; + for (i = 0; bad_use_chain[i] && !found; i++) { + found = try_libraries_noload(bad_use_chain[i]); + if (found && gtk_versionDebug) { + printf("found already loaded unsupported GTK library %s\n", bad_use_chain[i][1]); + } + } + + if (found) { + return -1; + } + + if (wantVersion != 0 && wantVersion != 3) { // Note, this should never happen, java should be protecting us if (gtk_versionDebug) { printf("bad GTK version specified, assuming 3\n"); } wantVersion = 3; - use_chain = three_to_two; } for (i = 0; use_chain[i] && !found; i++) { @@ -208,10 +209,7 @@ JNIEXPORT jint JNICALL Java_com_sun_glass_ui_gtk_GtkApplication__1queryLibrary // now check the the presence of the libraries char version = sniffLibs(suggestedVersion); - - if (version == '2') { - return com_sun_glass_ui_gtk_GtkApplication_QUERY_LOAD_GTK2; - } else if (version == '3') { + if (version == '3') { return com_sun_glass_ui_gtk_GtkApplication_QUERY_LOAD_GTK3; } diff --git a/tests/system/src/test/java/test/com/sun/glass/ui/gtk/Gtk2Deprecation1Test.java b/tests/system/src/test/java/test/com/sun/glass/ui/gtk/Gtk2Removal1Test.java similarity index 72% rename from tests/system/src/test/java/test/com/sun/glass/ui/gtk/Gtk2Deprecation1Test.java rename to tests/system/src/test/java/test/com/sun/glass/ui/gtk/Gtk2Removal1Test.java index f558872fc47..938654a3e28 100644 --- a/tests/system/src/test/java/test/com/sun/glass/ui/gtk/Gtk2Deprecation1Test.java +++ b/tests/system/src/test/java/test/com/sun/glass/ui/gtk/Gtk2Removal1Test.java @@ -26,23 +26,22 @@ package test.com.sun.glass.ui.gtk; import com.sun.javafx.PlatformUtil; -import java.io.ByteArrayOutputStream; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; -import org.junit.AfterClass; -import org.junit.BeforeClass; -import org.junit.Test; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.junit.jupiter.api.Assumptions.assumeTrue; -import static org.junit.Assert.assertTrue; -import static org.junit.Assume.assumeTrue; +public class Gtk2Removal1Test extends Gtk2RemovalCommon { -public class Gtk2Deprecation1Test extends Gtk2DeprecationCommon { - - @BeforeClass + @BeforeAll public static void setup() throws Exception { doSetup(true); } - @AfterClass + @AfterAll public static void teardown() { doTeardown(); } @@ -53,9 +52,9 @@ public void testDeprecationMessage() throws Exception { final String output = out.toString(); System.err.println(output); - assertTrue("Missing warning message", output.contains("WARNING")); - assertTrue("Missing warning message", output.contains("deprecated")); - assertTrue("Missing warning message", output.contains("removed")); + assertTrue(output.contains("WARNING"), "Missing warning message"); + assertTrue(output.contains("removed"), "Missing removed message"); + assertFalse(output.contains("deprecated"), "Wrong message (deprecated)"); } } diff --git a/tests/system/src/test/java/test/com/sun/glass/ui/gtk/Gtk2Deprecation2Test.java b/tests/system/src/test/java/test/com/sun/glass/ui/gtk/Gtk2Removal2Test.java similarity index 74% rename from tests/system/src/test/java/test/com/sun/glass/ui/gtk/Gtk2Deprecation2Test.java rename to tests/system/src/test/java/test/com/sun/glass/ui/gtk/Gtk2Removal2Test.java index 93ed5a49c66..05aa6b17ef1 100644 --- a/tests/system/src/test/java/test/com/sun/glass/ui/gtk/Gtk2Deprecation2Test.java +++ b/tests/system/src/test/java/test/com/sun/glass/ui/gtk/Gtk2Removal2Test.java @@ -26,23 +26,23 @@ package test.com.sun.glass.ui.gtk; import com.sun.javafx.PlatformUtil; -import java.io.ByteArrayOutputStream; -import org.junit.AfterClass; -import org.junit.BeforeClass; -import org.junit.Test; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; -import static org.junit.Assert.assertFalse; -import static org.junit.Assume.assumeTrue; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assumptions.assumeTrue; -public class Gtk2Deprecation2Test extends Gtk2DeprecationCommon { - @BeforeClass +public class Gtk2Removal2Test extends Gtk2RemovalCommon { + + @BeforeAll public static void setup() throws Exception { doSetup(false); } - @AfterClass + @AfterAll public static void teardown() { doTeardown(); } @@ -53,9 +53,9 @@ public void testNoDeprecationMessage() throws Exception { final String output = out.toString(); System.err.println(output); - assertFalse("Unexpected warning message", output.contains("WARNING")); - assertFalse("Unexpected warning message", output.contains("deprecated")); - assertFalse("Unexpected warning message", output.contains("removed")); + assertFalse(output.contains("WARNING"), "Unexpected warning message"); + assertFalse(output.contains("deprecated"), "Unexpected warning message"); + assertFalse(output.contains("removed"), "Unexpected warning message"); } } diff --git a/tests/system/src/test/java/test/com/sun/glass/ui/gtk/Gtk2DeprecationCommon.java b/tests/system/src/test/java/test/com/sun/glass/ui/gtk/Gtk2RemovalCommon.java similarity index 97% rename from tests/system/src/test/java/test/com/sun/glass/ui/gtk/Gtk2DeprecationCommon.java rename to tests/system/src/test/java/test/com/sun/glass/ui/gtk/Gtk2RemovalCommon.java index 6dfac920644..0f1d19162f4 100644 --- a/tests/system/src/test/java/test/com/sun/glass/ui/gtk/Gtk2DeprecationCommon.java +++ b/tests/system/src/test/java/test/com/sun/glass/ui/gtk/Gtk2RemovalCommon.java @@ -31,11 +31,10 @@ import java.util.concurrent.CountDownLatch; import java.util.concurrent.TimeUnit; import javafx.application.Platform; -import test.util.Util; import static org.junit.Assert.fail; -public class Gtk2DeprecationCommon { +public class Gtk2RemovalCommon { private static final CountDownLatch startupLatch = new CountDownLatch(1); private static final PrintStream defaultErrorStream = System.err;