From 984c87cf767a46a2c1000a4030dfd91a62b03b4d Mon Sep 17 00:00:00 2001 From: Phil Race Date: Tue, 4 Nov 2025 21:47:58 +0000 Subject: [PATCH] 8370719: [Linux] Use /etc/os-release values for font configuration file names Reviewed-by: kizune, psadhukhan --- .../classes/sun/font/FcFontConfiguration.java | 34 ++----------------- .../classes/sun/font/MFontConfiguration.java | 34 ++----------------- 2 files changed, 6 insertions(+), 62 deletions(-) diff --git a/src/java.desktop/unix/classes/sun/font/FcFontConfiguration.java b/src/java.desktop/unix/classes/sun/font/FcFontConfiguration.java index 328e2454842..27d6773105e 100644 --- a/src/java.desktop/unix/classes/sun/font/FcFontConfiguration.java +++ b/src/java.desktop/unix/classes/sun/font/FcFontConfiguration.java @@ -317,42 +317,14 @@ public final class FcFontConfiguration extends FontConfiguration { return; } try { - File f; - if ((f = new File("/etc/lsb-release")).canRead()) { - /* Ubuntu and (perhaps others) use only lsb-release. - * Syntax and encoding is compatible with java properties. - * For Ubuntu the ID is "Ubuntu". - */ - Properties props = new Properties(); - try (FileInputStream fis = new FileInputStream(f)) { - props.load(fis); - } - osName = extractInfo(props.getProperty("DISTRIB_ID")); - osVersion = extractInfo(props.getProperty("DISTRIB_RELEASE")); - } else if ((f = new File("/etc/redhat-release")).canRead()) { - osName = "RedHat"; - osVersion = getVersionString(f); - } else if ((f = new File("/etc/SuSE-release")).canRead()) { - osName = "SuSE"; - osVersion = getVersionString(f); - } else if ((f = new File("/etc/turbolinux-release")).canRead()) { - osName = "Turbo"; - osVersion = getVersionString(f); - } else if ((f = new File("/etc/fedora-release")).canRead()) { - osName = "Fedora"; - osVersion = getVersionString(f); - } else if ((f = new File("/etc/os-release")).canRead()) { + File f = new File("/etc/os-release"); + if (f.canRead()) { Properties props = new Properties(); try (FileInputStream fis = new FileInputStream(f)) { props.load(fis); } - osName = extractInfo(props.getProperty("NAME")); + osName = extractInfo(props.getProperty("ID")); osVersion = extractInfo(props.getProperty("VERSION_ID")); - if (osName.equals("SLES")) { - osName = "SuSE"; - } else { - osName = extractInfo(props.getProperty("ID")); - } } } catch (Exception e) { if (FontUtilities.debugFonts()) { diff --git a/src/java.desktop/unix/classes/sun/font/MFontConfiguration.java b/src/java.desktop/unix/classes/sun/font/MFontConfiguration.java index 3d7e68d8dea..f5a8fe8b3c0 100644 --- a/src/java.desktop/unix/classes/sun/font/MFontConfiguration.java +++ b/src/java.desktop/unix/classes/sun/font/MFontConfiguration.java @@ -91,42 +91,14 @@ public final class MFontConfiguration extends FontConfiguration { if (osName.equals("Linux")) { try { - File f; - if ((f = new File("/etc/fedora-release")).canRead()) { - osName = "Fedora"; - osVersion = getVersionString(f); - } else if ((f = new File("/etc/redhat-release")).canRead()) { - osName = "RedHat"; - osVersion = getVersionString(f); - } else if ((f = new File("/etc/turbolinux-release")).canRead()) { - osName = "Turbo"; - osVersion = getVersionString(f); - } else if ((f = new File("/etc/SuSE-release")).canRead()) { - osName = "SuSE"; - osVersion = getVersionString(f); - } else if ((f = new File("/etc/lsb-release")).canRead()) { - /* Ubuntu and (perhaps others) use only lsb-release. - * Syntax and encoding is compatible with java properties. - * For Ubuntu the ID is "Ubuntu". - */ + File f = new File("/etc/os-release"); + if (f.canRead()) { Properties props = new Properties(); try (FileInputStream fis = new FileInputStream(f)) { props.load(fis); } - osName = extractInfo(props.getProperty("DISTRIB_ID")); - osVersion = extractInfo(props.getProperty("DISTRIB_RELEASE")); - } else if ((f = new File("/etc/os-release")).canRead()) { - Properties props = new Properties(); - try (FileInputStream fis = new FileInputStream(f)) { - props.load(fis); - } - osName = extractInfo(props.getProperty("NAME")); + osName = extractInfo(props.getProperty("ID")); osVersion = extractInfo(props.getProperty("VERSION_ID")); - if (osName.equals("SLES")) { - osName = "SuSE"; - } else { - osName = extractInfo(props.getProperty("ID")); - } } } catch (Exception e) { }