From 343451de65e850b5ec226f0782dbb4646756d57f Mon Sep 17 00:00:00 2001 From: Ingo Kegel Date: Fri, 5 Mar 2021 16:44:08 +0100 Subject: [PATCH 1/5] Make the module dependency on java.logging optional Currently, FlatLaf has the following module dependencies: $ jdeps --list-deps --multi-release 9 flatlaf-1.0.jar java.base java.desktop java.logging This commit makes the java.logging dependency optional and hides logging behind a facade that falls back to printing to stderr if the java.logging module is not available. To test, create a reduced JRE with a command like jdk-15/bin/jlink.exe --module-path jdk-15/jmods --add-modules java.desktop --add-modules java.instrument --output jre-15-desktop-only (adding java.instrument, so the FlatLafDemo main class can be started from IntelliJ IDEA) --- .../java/com/formdev/flatlaf/FlatLaf.java | 11 ++--- .../com/formdev/flatlaf/IntelliJTheme.java | 5 +- .../com/formdev/flatlaf/LinuxFontPolicy.java | 7 ++- .../com/formdev/flatlaf/LoggingFacade.java | 46 +++++++++++++++++++ .../com/formdev/flatlaf/UIDefaultsLoader.java | 20 ++++---- .../flatlaf/ui/JBRCustomDecorations.java | 9 ++-- .../flatlaf/util/JavaCompatibility.java | 12 ++--- .../src/main/module-info/module-info.java | 2 +- .../formdev/flatlaf/intellijthemes/Utils.java | 8 +--- .../materialthemeuilite/Utils.java | 8 +--- 10 files changed, 81 insertions(+), 47 deletions(-) create mode 100644 flatlaf-core/src/main/java/com/formdev/flatlaf/LoggingFacade.java diff --git a/flatlaf-core/src/main/java/com/formdev/flatlaf/FlatLaf.java b/flatlaf-core/src/main/java/com/formdev/flatlaf/FlatLaf.java index 02fed69b..2e27d600 100644 --- a/flatlaf-core/src/main/java/com/formdev/flatlaf/FlatLaf.java +++ b/flatlaf-core/src/main/java/com/formdev/flatlaf/FlatLaf.java @@ -38,8 +38,6 @@ import java.util.Properties; import java.util.ServiceLoader; import java.util.function.Consumer; import java.util.function.Function; -import java.util.logging.Level; -import java.util.logging.Logger; import javax.swing.BorderFactory; import javax.swing.Icon; import javax.swing.ImageIcon; @@ -74,7 +72,6 @@ import com.formdev.flatlaf.util.UIScale; public abstract class FlatLaf extends BasicLookAndFeel { - static final Logger LOG = Logger.getLogger( FlatLaf.class.getName() ); private static final String DESKTOPFONTHINTS = "awt.font.desktophints"; private static List customDefaultsSources; @@ -103,7 +100,7 @@ public abstract class FlatLaf UIManager.setLookAndFeel( newLookAndFeel ); return true; } catch( Exception ex ) { - LOG.log( Level.SEVERE, "FlatLaf: Failed to initialize look and feel '" + newLookAndFeel.getClass().getName() + "'.", ex ); + LoggingFacade.logSevere( "FlatLaf: Failed to initialize look and feel '" + newLookAndFeel.getClass().getName() + "'.", ex ); return false; } } @@ -341,7 +338,7 @@ public abstract class FlatLaf } else aquaLaf = (BasicLookAndFeel) Class.forName( aquaLafClassName ).newInstance(); } catch( Exception ex ) { - LOG.log( Level.SEVERE, "FlatLaf: Failed to initialize Aqua look and feel '" + aquaLafClassName + "'.", ex ); + LoggingFacade.logSevere( "FlatLaf: Failed to initialize Aqua look and feel '" + aquaLafClassName + "'.", ex ); throw new IllegalStateException(); } @@ -577,7 +574,7 @@ public abstract class FlatLaf .invoke( null, true ); defaults.put( key, value ); } catch( Exception ex ) { - Logger.getLogger( FlatLaf.class.getName() ).log( Level.SEVERE, null, ex ); + LoggingFacade.logSevere( null, ex ); throw new RuntimeException( ex ); } } @@ -684,7 +681,7 @@ public abstract class FlatLaf // update UI updateUI(); } catch( UnsupportedLookAndFeelException ex ) { - LOG.log( Level.SEVERE, "FlatLaf: Failed to reinitialize look and feel '" + lookAndFeel.getClass().getName() + "'.", ex ); + LoggingFacade.logSevere( "FlatLaf: Failed to reinitialize look and feel '" + lookAndFeel.getClass().getName() + "'.", ex ); } } ); } diff --git a/flatlaf-core/src/main/java/com/formdev/flatlaf/IntelliJTheme.java b/flatlaf-core/src/main/java/com/formdev/flatlaf/IntelliJTheme.java index 1c3fa053..5c66f938 100644 --- a/flatlaf-core/src/main/java/com/formdev/flatlaf/IntelliJTheme.java +++ b/flatlaf-core/src/main/java/com/formdev/flatlaf/IntelliJTheme.java @@ -30,7 +30,6 @@ import java.util.HashSet; import java.util.List; import java.util.Map; import java.util.Set; -import java.util.logging.Level; import javax.swing.UIDefaults; import javax.swing.plaf.ColorUIResource; import com.formdev.flatlaf.json.Json; @@ -76,7 +75,7 @@ public class IntelliJTheme try { return FlatLaf.install( createLaf( in ) ); } catch( Exception ex ) { - FlatLaf.LOG.log( Level.SEVERE, "FlatLaf: Failed to load IntelliJ theme", ex ); + LoggingFacade.logSevere( "FlatLaf: Failed to load IntelliJ theme", ex ); return false; } } @@ -324,7 +323,7 @@ public class IntelliJTheme try { uiValue = UIDefaultsLoader.parseValue( key, valueStr ); } catch( RuntimeException ex ) { - UIDefaultsLoader.logParseError( Level.CONFIG, key, valueStr, ex ); + UIDefaultsLoader.logParseError( key, valueStr, ex, false ); return; // ignore invalid value } } diff --git a/flatlaf-core/src/main/java/com/formdev/flatlaf/LinuxFontPolicy.java b/flatlaf-core/src/main/java/com/formdev/flatlaf/LinuxFontPolicy.java index fbd7f8c0..e4008b1b 100644 --- a/flatlaf-core/src/main/java/com/formdev/flatlaf/LinuxFontPolicy.java +++ b/flatlaf-core/src/main/java/com/formdev/flatlaf/LinuxFontPolicy.java @@ -28,7 +28,6 @@ import java.util.ArrayList; import java.util.Collections; import java.util.List; import java.util.StringTokenizer; -import java.util.logging.Level; import com.formdev.flatlaf.util.StringUtils; import com.formdev.flatlaf.util.SystemInfo; import com.formdev.flatlaf.util.UIScale; @@ -172,7 +171,7 @@ class LinuxFontPolicy if( "1".equals( strs.get( 5 ) ) ) style |= Font.ITALIC; } catch( RuntimeException ex ) { - FlatLaf.LOG.log( Level.CONFIG, "FlatLaf: Failed to parse 'font=" + generalFont + "'.", ex ); + LoggingFacade.logConfig( "FlatLaf: Failed to parse 'font=" + generalFont + "'.", ex ); } } @@ -186,7 +185,7 @@ class LinuxFontPolicy if( dpi < 50 ) dpi = 50; } catch( NumberFormatException ex ) { - FlatLaf.LOG.log( Level.CONFIG, "FlatLaf: Failed to parse 'forceFontDPI=" + forceFontDPI + "'.", ex ); + LoggingFacade.logConfig( "FlatLaf: Failed to parse 'forceFontDPI=" + forceFontDPI + "'.", ex ); } } @@ -225,7 +224,7 @@ class LinuxFontPolicy while( (line = reader.readLine()) != null ) lines.add( line ); } catch( IOException ex ) { - FlatLaf.LOG.log( Level.CONFIG, "FlatLaf: Failed to read '" + filename + "'.", ex ); + LoggingFacade.logConfig( "FlatLaf: Failed to read '" + filename + "'.", ex ); } return lines; } diff --git a/flatlaf-core/src/main/java/com/formdev/flatlaf/LoggingFacade.java b/flatlaf-core/src/main/java/com/formdev/flatlaf/LoggingFacade.java new file mode 100644 index 00000000..254d8cba --- /dev/null +++ b/flatlaf-core/src/main/java/com/formdev/flatlaf/LoggingFacade.java @@ -0,0 +1,46 @@ +package com.formdev.flatlaf; + +import java.util.logging.Level; +import java.util.logging.Logger; + +public class LoggingFacade +{ + private static final Logger LOG = createLogger(); + + private static Logger createLogger() { + try { + return Logger.getLogger( FlatLaf.class.getName() ); + } catch( Throwable e ) { + // Module java.logging is not present + return null; + } + } + + public static void logSevere( Throwable t ) { + logSevere( null, t ); + } + + public static void logSevere( String message ) { + logSevere( message, null ); + } + + public static void logSevere( String message, Throwable t ) { + if( LOG != null ) { + LOG.log( Level.SEVERE, message, t ); + } else { + System.err.println( message ); + t.printStackTrace(); + } + } + + public static void logConfig( String message, Throwable t ) { + if( LOG != null ) { + LOG.log( Level.CONFIG, message, t ); + } else { + if (Boolean.getBoolean( "flatLaf.logConfig" )) { + System.err.println( message ); + t.printStackTrace(); + } + } + } +} diff --git a/flatlaf-core/src/main/java/com/formdev/flatlaf/UIDefaultsLoader.java b/flatlaf-core/src/main/java/com/formdev/flatlaf/UIDefaultsLoader.java index 07c83736..3a8f4118 100644 --- a/flatlaf-core/src/main/java/com/formdev/flatlaf/UIDefaultsLoader.java +++ b/flatlaf-core/src/main/java/com/formdev/flatlaf/UIDefaultsLoader.java @@ -33,7 +33,6 @@ import java.util.Map; import java.util.Map.Entry; import java.util.Properties; import java.util.function.Function; -import java.util.logging.Level; import javax.swing.UIDefaults; import javax.swing.UIManager; import javax.swing.UIDefaults.ActiveValue; @@ -243,16 +242,21 @@ class UIDefaultsLoader try { defaults.put( key, parseValue( key, value, null, resolver, addonClassLoaders ) ); } catch( RuntimeException ex ) { - logParseError( Level.SEVERE, key, value, ex ); + logParseError( key, value, ex, true ); } } } catch( IOException ex ) { - FlatLaf.LOG.log( Level.SEVERE, "FlatLaf: Failed to load properties files.", ex ); + LoggingFacade.logSevere( "FlatLaf: Failed to load properties files.", ex ); } } - static void logParseError( Level level, String key, String value, RuntimeException ex ) { - FlatLaf.LOG.log( level, "FlatLaf: Failed to parse: '" + key + '=' + value + '\'', ex ); + static void logParseError( String key, String value, RuntimeException ex, boolean severe ) { + String message = "FlatLaf: Failed to parse: '" + key + '=' + value + '\''; + if (severe) { + LoggingFacade.logSevere( message, ex ); + } else { + LoggingFacade.logConfig( message, ex ); + } } static String resolveValue( String value, Function propertiesGetter ) { @@ -440,7 +444,7 @@ class UIDefaultsLoader try { return findClass( value, addonClassLoaders ).newInstance(); } catch( InstantiationException | IllegalAccessException | ClassNotFoundException ex ) { - FlatLaf.LOG.log( Level.SEVERE, "FlatLaf: Failed to instantiate '" + value + "'.", ex ); + LoggingFacade.logSevere( "FlatLaf: Failed to instantiate '" + value + "'.", ex ); return null; } }; @@ -451,7 +455,7 @@ class UIDefaultsLoader try { return findClass( value, addonClassLoaders ); } catch( ClassNotFoundException ex ) { - FlatLaf.LOG.log( Level.SEVERE, "FlatLaf: Failed to find class '" + value + "'.", ex ); + LoggingFacade.logSevere( "FlatLaf: Failed to find class '" + value + "'.", ex ); return null; } }; @@ -928,7 +932,7 @@ class UIDefaultsLoader Object value = UIManager.get( uiKey ); if( value == null && !optional ) - FlatLaf.LOG.log( Level.SEVERE, "FlatLaf: '" + uiKey + "' not found in UI defaults." ); + LoggingFacade.logSevere( "FlatLaf: '" + uiKey + "' not found in UI defaults." ); return value; } } diff --git a/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/JBRCustomDecorations.java b/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/JBRCustomDecorations.java index e3d68e7d..56623e35 100644 --- a/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/JBRCustomDecorations.java +++ b/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/JBRCustomDecorations.java @@ -30,8 +30,6 @@ import java.awt.event.HierarchyListener; import java.beans.PropertyChangeListener; import java.lang.reflect.Method; import java.util.List; -import java.util.logging.Level; -import java.util.logging.Logger; import javax.swing.JDialog; import javax.swing.JFrame; import javax.swing.JRootPane; @@ -40,6 +38,7 @@ import javax.swing.UIManager; import javax.swing.plaf.BorderUIResource; import com.formdev.flatlaf.FlatLaf; import com.formdev.flatlaf.FlatSystemProperties; +import com.formdev.flatlaf.LoggingFacade; import com.formdev.flatlaf.util.HiDPIUtils; import com.formdev.flatlaf.util.SystemInfo; @@ -155,7 +154,7 @@ public class JBRCustomDecorations try { return (Boolean) Window_hasCustomDecoration.invoke( window ); } catch( Exception ex ) { - Logger.getLogger( FlatLaf.class.getName() ).log( Level.SEVERE, null, ex ); + LoggingFacade.logSevere( null, ex ); return false; } } @@ -167,7 +166,7 @@ public class JBRCustomDecorations try { Window_setHasCustomDecoration.invoke( window ); } catch( Exception ex ) { - Logger.getLogger( FlatLaf.class.getName() ).log( Level.SEVERE, null, ex ); + LoggingFacade.logSevere( null, ex ); } } @@ -181,7 +180,7 @@ public class JBRCustomDecorations WWindowPeer_setCustomDecorationHitTestSpots.invoke( peer, hitTestSpots ); WWindowPeer_setCustomDecorationTitleBarHeight.invoke( peer, titleBarHeight ); } catch( Exception ex ) { - Logger.getLogger( FlatLaf.class.getName() ).log( Level.SEVERE, null, ex ); + LoggingFacade.logSevere( null, ex ); } } diff --git a/flatlaf-core/src/main/java/com/formdev/flatlaf/util/JavaCompatibility.java b/flatlaf-core/src/main/java/com/formdev/flatlaf/util/JavaCompatibility.java index f4e740fc..547d74d2 100644 --- a/flatlaf-core/src/main/java/com/formdev/flatlaf/util/JavaCompatibility.java +++ b/flatlaf-core/src/main/java/com/formdev/flatlaf/util/JavaCompatibility.java @@ -21,10 +21,8 @@ import java.awt.Graphics; import java.awt.Graphics2D; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; -import java.util.logging.Level; -import java.util.logging.Logger; import javax.swing.JComponent; -import com.formdev.flatlaf.FlatLaf; +import com.formdev.flatlaf.LoggingFacade; /** * Provides Java version compatibility methods. @@ -58,7 +56,7 @@ public class JavaCompatibility ? new Class[] { JComponent.class, Graphics2D.class, String.class, int.class, float.class, float.class } : new Class[] { JComponent.class, Graphics.class, String.class, int.class, int.class, int.class } ); } catch( Exception ex ) { - Logger.getLogger( FlatLaf.class.getName() ).log( Level.SEVERE, null, ex ); + LoggingFacade.logSevere( ex ); throw new RuntimeException( ex ); } } @@ -70,7 +68,7 @@ public class JavaCompatibility else drawStringUnderlineCharAtMethod.invoke( null, c, g, text, underlinedIndex, x, y ); } catch( IllegalAccessException | IllegalArgumentException | InvocationTargetException ex ) { - Logger.getLogger( FlatLaf.class.getName() ).log( Level.SEVERE, null, ex ); + LoggingFacade.logSevere( ex ); throw new RuntimeException( ex ); } } @@ -94,7 +92,7 @@ public class JavaCompatibility : "clipStringIfNecessary", new Class[] { JComponent.class, FontMetrics.class, String.class, int.class } ); } catch( Exception ex ) { - Logger.getLogger( FlatLaf.class.getName() ).log( Level.SEVERE, null, ex ); + LoggingFacade.logSevere( ex ); throw new RuntimeException( ex ); } } @@ -103,7 +101,7 @@ public class JavaCompatibility try { return (String) getClippedStringMethod.invoke( null, c, fm, string, availTextWidth ); } catch( IllegalAccessException | IllegalArgumentException | InvocationTargetException ex ) { - Logger.getLogger( FlatLaf.class.getName() ).log( Level.SEVERE, null, ex ); + LoggingFacade.logSevere( ex ); throw new RuntimeException( ex ); } } diff --git a/flatlaf-core/src/main/module-info/module-info.java b/flatlaf-core/src/main/module-info/module-info.java index e8e9dc4c..ee57bed2 100644 --- a/flatlaf-core/src/main/module-info/module-info.java +++ b/flatlaf-core/src/main/module-info/module-info.java @@ -19,7 +19,7 @@ */ module com.formdev.flatlaf { requires java.desktop; - requires java.logging; + requires static java.logging; exports com.formdev.flatlaf; exports com.formdev.flatlaf.icons; diff --git a/flatlaf-intellij-themes/src/main/java/com/formdev/flatlaf/intellijthemes/Utils.java b/flatlaf-intellij-themes/src/main/java/com/formdev/flatlaf/intellijthemes/Utils.java index 0392cd94..a2d87c2d 100644 --- a/flatlaf-intellij-themes/src/main/java/com/formdev/flatlaf/intellijthemes/Utils.java +++ b/flatlaf-intellij-themes/src/main/java/com/formdev/flatlaf/intellijthemes/Utils.java @@ -17,25 +17,21 @@ package com.formdev.flatlaf.intellijthemes; import java.io.IOException; -import java.util.logging.Level; -import java.util.logging.Logger; -import com.formdev.flatlaf.FlatLaf; import com.formdev.flatlaf.IntelliJTheme; +import com.formdev.flatlaf.LoggingFacade; /** * @author Karl Tauber */ class Utils { - static final Logger LOG = Logger.getLogger( FlatLaf.class.getName() ); - static IntelliJTheme loadTheme( String name ) { try { return new IntelliJTheme( Utils.class.getResourceAsStream( "/com/formdev/flatlaf/intellijthemes/themes/" + name ) ); } catch( IOException ex ) { String msg = "FlatLaf: Failed to load IntelliJ theme '" + name + "'"; - LOG.log( Level.SEVERE, msg, ex ); + LoggingFacade.logSevere( msg, ex ); throw new RuntimeException( msg, ex ); } } diff --git a/flatlaf-intellij-themes/src/main/java/com/formdev/flatlaf/intellijthemes/materialthemeuilite/Utils.java b/flatlaf-intellij-themes/src/main/java/com/formdev/flatlaf/intellijthemes/materialthemeuilite/Utils.java index f5523cca..9faba7d1 100644 --- a/flatlaf-intellij-themes/src/main/java/com/formdev/flatlaf/intellijthemes/materialthemeuilite/Utils.java +++ b/flatlaf-intellij-themes/src/main/java/com/formdev/flatlaf/intellijthemes/materialthemeuilite/Utils.java @@ -17,25 +17,21 @@ package com.formdev.flatlaf.intellijthemes.materialthemeuilite; import java.io.IOException; -import java.util.logging.Level; -import java.util.logging.Logger; -import com.formdev.flatlaf.FlatLaf; import com.formdev.flatlaf.IntelliJTheme; +import com.formdev.flatlaf.LoggingFacade; /** * @author Karl Tauber */ class Utils { - static final Logger LOG = Logger.getLogger( FlatLaf.class.getName() ); - static IntelliJTheme loadTheme( String name ) { try { return new IntelliJTheme( Utils.class.getResourceAsStream( "/com/formdev/flatlaf/intellijthemes/themes/material-theme-ui-lite/" + name ) ); } catch( IOException ex ) { String msg = "FlatLaf: Failed to load IntelliJ theme '" + name + "'"; - LOG.log( Level.SEVERE, msg, ex ); + LoggingFacade.logSevere( msg, ex ); throw new RuntimeException( msg, ex ); } } From eedfcf86aa2ef54657283a4ccc3ffacb5dcade0f Mon Sep 17 00:00:00 2001 From: Ingo Kegel Date: Wed, 10 Mar 2021 17:06:12 +0100 Subject: [PATCH 2/5] LoggingFacade: moved to com.formdev.flatlaf.util, added license header, fixed NPEs in logging calls and removed overloads of logSevere --- .../java/com/formdev/flatlaf/FlatLaf.java | 1 + .../com/formdev/flatlaf/IntelliJTheme.java | 1 + .../com/formdev/flatlaf/LinuxFontPolicy.java | 2 + .../com/formdev/flatlaf/LoggingFacade.java | 46 -------------- .../com/formdev/flatlaf/UIDefaultsLoader.java | 3 +- .../flatlaf/ui/JBRCustomDecorations.java | 2 +- .../flatlaf/util/JavaCompatibility.java | 9 ++- .../formdev/flatlaf/util/LoggingFacade.java | 63 +++++++++++++++++++ .../formdev/flatlaf/intellijthemes/Utils.java | 2 +- .../materialthemeuilite/Utils.java | 2 +- 10 files changed, 76 insertions(+), 55 deletions(-) delete mode 100644 flatlaf-core/src/main/java/com/formdev/flatlaf/LoggingFacade.java create mode 100644 flatlaf-core/src/main/java/com/formdev/flatlaf/util/LoggingFacade.java diff --git a/flatlaf-core/src/main/java/com/formdev/flatlaf/FlatLaf.java b/flatlaf-core/src/main/java/com/formdev/flatlaf/FlatLaf.java index 2e27d600..d703ea3e 100644 --- a/flatlaf-core/src/main/java/com/formdev/flatlaf/FlatLaf.java +++ b/flatlaf-core/src/main/java/com/formdev/flatlaf/FlatLaf.java @@ -60,6 +60,7 @@ import javax.swing.text.html.HTMLEditorKit; import com.formdev.flatlaf.ui.FlatPopupFactory; import com.formdev.flatlaf.ui.JBRCustomDecorations; import com.formdev.flatlaf.util.GrayFilter; +import com.formdev.flatlaf.util.LoggingFacade; import com.formdev.flatlaf.util.MultiResolutionImageSupport; import com.formdev.flatlaf.util.SystemInfo; import com.formdev.flatlaf.util.UIScale; diff --git a/flatlaf-core/src/main/java/com/formdev/flatlaf/IntelliJTheme.java b/flatlaf-core/src/main/java/com/formdev/flatlaf/IntelliJTheme.java index 5c66f938..e3154907 100644 --- a/flatlaf-core/src/main/java/com/formdev/flatlaf/IntelliJTheme.java +++ b/flatlaf-core/src/main/java/com/formdev/flatlaf/IntelliJTheme.java @@ -34,6 +34,7 @@ import javax.swing.UIDefaults; import javax.swing.plaf.ColorUIResource; import com.formdev.flatlaf.json.Json; import com.formdev.flatlaf.json.ParseException; +import com.formdev.flatlaf.util.LoggingFacade; import com.formdev.flatlaf.util.StringUtils; /** diff --git a/flatlaf-core/src/main/java/com/formdev/flatlaf/LinuxFontPolicy.java b/flatlaf-core/src/main/java/com/formdev/flatlaf/LinuxFontPolicy.java index e4008b1b..71c8d9a6 100644 --- a/flatlaf-core/src/main/java/com/formdev/flatlaf/LinuxFontPolicy.java +++ b/flatlaf-core/src/main/java/com/formdev/flatlaf/LinuxFontPolicy.java @@ -28,6 +28,8 @@ import java.util.ArrayList; import java.util.Collections; import java.util.List; import java.util.StringTokenizer; + +import com.formdev.flatlaf.util.LoggingFacade; import com.formdev.flatlaf.util.StringUtils; import com.formdev.flatlaf.util.SystemInfo; import com.formdev.flatlaf.util.UIScale; diff --git a/flatlaf-core/src/main/java/com/formdev/flatlaf/LoggingFacade.java b/flatlaf-core/src/main/java/com/formdev/flatlaf/LoggingFacade.java deleted file mode 100644 index 254d8cba..00000000 --- a/flatlaf-core/src/main/java/com/formdev/flatlaf/LoggingFacade.java +++ /dev/null @@ -1,46 +0,0 @@ -package com.formdev.flatlaf; - -import java.util.logging.Level; -import java.util.logging.Logger; - -public class LoggingFacade -{ - private static final Logger LOG = createLogger(); - - private static Logger createLogger() { - try { - return Logger.getLogger( FlatLaf.class.getName() ); - } catch( Throwable e ) { - // Module java.logging is not present - return null; - } - } - - public static void logSevere( Throwable t ) { - logSevere( null, t ); - } - - public static void logSevere( String message ) { - logSevere( message, null ); - } - - public static void logSevere( String message, Throwable t ) { - if( LOG != null ) { - LOG.log( Level.SEVERE, message, t ); - } else { - System.err.println( message ); - t.printStackTrace(); - } - } - - public static void logConfig( String message, Throwable t ) { - if( LOG != null ) { - LOG.log( Level.CONFIG, message, t ); - } else { - if (Boolean.getBoolean( "flatLaf.logConfig" )) { - System.err.println( message ); - t.printStackTrace(); - } - } - } -} diff --git a/flatlaf-core/src/main/java/com/formdev/flatlaf/UIDefaultsLoader.java b/flatlaf-core/src/main/java/com/formdev/flatlaf/UIDefaultsLoader.java index 3a8f4118..d34b3b6a 100644 --- a/flatlaf-core/src/main/java/com/formdev/flatlaf/UIDefaultsLoader.java +++ b/flatlaf-core/src/main/java/com/formdev/flatlaf/UIDefaultsLoader.java @@ -47,6 +47,7 @@ import com.formdev.flatlaf.util.ColorFunctions.ColorFunction; import com.formdev.flatlaf.util.DerivedColor; import com.formdev.flatlaf.util.GrayFilter; import com.formdev.flatlaf.util.HSLColor; +import com.formdev.flatlaf.util.LoggingFacade; import com.formdev.flatlaf.util.StringUtils; import com.formdev.flatlaf.util.SystemInfo; import com.formdev.flatlaf.util.UIScale; @@ -932,7 +933,7 @@ class UIDefaultsLoader Object value = UIManager.get( uiKey ); if( value == null && !optional ) - LoggingFacade.logSevere( "FlatLaf: '" + uiKey + "' not found in UI defaults." ); + LoggingFacade.logSevere( "FlatLaf: '" + uiKey + "' not found in UI defaults.", null ); return value; } } diff --git a/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/JBRCustomDecorations.java b/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/JBRCustomDecorations.java index 56623e35..97f21724 100644 --- a/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/JBRCustomDecorations.java +++ b/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/JBRCustomDecorations.java @@ -38,7 +38,7 @@ import javax.swing.UIManager; import javax.swing.plaf.BorderUIResource; import com.formdev.flatlaf.FlatLaf; import com.formdev.flatlaf.FlatSystemProperties; -import com.formdev.flatlaf.LoggingFacade; +import com.formdev.flatlaf.util.LoggingFacade; import com.formdev.flatlaf.util.HiDPIUtils; import com.formdev.flatlaf.util.SystemInfo; diff --git a/flatlaf-core/src/main/java/com/formdev/flatlaf/util/JavaCompatibility.java b/flatlaf-core/src/main/java/com/formdev/flatlaf/util/JavaCompatibility.java index 547d74d2..bc177a66 100644 --- a/flatlaf-core/src/main/java/com/formdev/flatlaf/util/JavaCompatibility.java +++ b/flatlaf-core/src/main/java/com/formdev/flatlaf/util/JavaCompatibility.java @@ -22,7 +22,6 @@ import java.awt.Graphics2D; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; import javax.swing.JComponent; -import com.formdev.flatlaf.LoggingFacade; /** * Provides Java version compatibility methods. @@ -56,7 +55,7 @@ public class JavaCompatibility ? new Class[] { JComponent.class, Graphics2D.class, String.class, int.class, float.class, float.class } : new Class[] { JComponent.class, Graphics.class, String.class, int.class, int.class, int.class } ); } catch( Exception ex ) { - LoggingFacade.logSevere( ex ); + LoggingFacade.logSevere( null, ex ); throw new RuntimeException( ex ); } } @@ -68,7 +67,7 @@ public class JavaCompatibility else drawStringUnderlineCharAtMethod.invoke( null, c, g, text, underlinedIndex, x, y ); } catch( IllegalAccessException | IllegalArgumentException | InvocationTargetException ex ) { - LoggingFacade.logSevere( ex ); + LoggingFacade.logSevere( null, ex ); throw new RuntimeException( ex ); } } @@ -92,7 +91,7 @@ public class JavaCompatibility : "clipStringIfNecessary", new Class[] { JComponent.class, FontMetrics.class, String.class, int.class } ); } catch( Exception ex ) { - LoggingFacade.logSevere( ex ); + LoggingFacade.logSevere( null, ex ); throw new RuntimeException( ex ); } } @@ -101,7 +100,7 @@ public class JavaCompatibility try { return (String) getClippedStringMethod.invoke( null, c, fm, string, availTextWidth ); } catch( IllegalAccessException | IllegalArgumentException | InvocationTargetException ex ) { - LoggingFacade.logSevere( ex ); + LoggingFacade.logSevere( null, ex ); throw new RuntimeException( ex ); } } diff --git a/flatlaf-core/src/main/java/com/formdev/flatlaf/util/LoggingFacade.java b/flatlaf-core/src/main/java/com/formdev/flatlaf/util/LoggingFacade.java new file mode 100644 index 00000000..12172f7f --- /dev/null +++ b/flatlaf-core/src/main/java/com/formdev/flatlaf/util/LoggingFacade.java @@ -0,0 +1,63 @@ +/* + * Copyright 2020 FormDev Software GmbH + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.formdev.flatlaf.util; + +import com.formdev.flatlaf.FlatLaf; +import java.util.logging.Level; +import java.util.logging.Logger; + +public class LoggingFacade +{ + private static final Logger LOG = createLogger(); + + private static Logger createLogger() { + try { + return Logger.getLogger( FlatLaf.class.getName() ); + } catch( Throwable e ) { + // Module java.logging is not present + return null; + } + } + + public static void logSevere( String message, Throwable t ) { + if( LOG != null ) { + LOG.log( Level.SEVERE, message, t ); + } else { + if( message != null ) { + System.err.println( message ); + } + if( t != null ) { + t.printStackTrace(); + } + } + } + + public static void logConfig( String message, Throwable t ) { + if( LOG != null ) { + LOG.log( Level.CONFIG, message, t ); + } else { + if (Boolean.getBoolean( "flatLaf.logConfig" )) { + if( message != null ) { + System.err.println( message ); + } + if( t != null ) { + t.printStackTrace(); + } + } + } + } +} diff --git a/flatlaf-intellij-themes/src/main/java/com/formdev/flatlaf/intellijthemes/Utils.java b/flatlaf-intellij-themes/src/main/java/com/formdev/flatlaf/intellijthemes/Utils.java index a2d87c2d..0e31e66b 100644 --- a/flatlaf-intellij-themes/src/main/java/com/formdev/flatlaf/intellijthemes/Utils.java +++ b/flatlaf-intellij-themes/src/main/java/com/formdev/flatlaf/intellijthemes/Utils.java @@ -18,7 +18,7 @@ package com.formdev.flatlaf.intellijthemes; import java.io.IOException; import com.formdev.flatlaf.IntelliJTheme; -import com.formdev.flatlaf.LoggingFacade; +import com.formdev.flatlaf.util.LoggingFacade; /** * @author Karl Tauber diff --git a/flatlaf-intellij-themes/src/main/java/com/formdev/flatlaf/intellijthemes/materialthemeuilite/Utils.java b/flatlaf-intellij-themes/src/main/java/com/formdev/flatlaf/intellijthemes/materialthemeuilite/Utils.java index 9faba7d1..2a1558ce 100644 --- a/flatlaf-intellij-themes/src/main/java/com/formdev/flatlaf/intellijthemes/materialthemeuilite/Utils.java +++ b/flatlaf-intellij-themes/src/main/java/com/formdev/flatlaf/intellijthemes/materialthemeuilite/Utils.java @@ -18,7 +18,7 @@ package com.formdev.flatlaf.intellijthemes.materialthemeuilite; import java.io.IOException; import com.formdev.flatlaf.IntelliJTheme; -import com.formdev.flatlaf.LoggingFacade; +import com.formdev.flatlaf.util.LoggingFacade; /** * @author Karl Tauber From 712bff9c999f825858f813ef562ab4ac3a006eec Mon Sep 17 00:00:00 2001 From: Ingo Kegel Date: Wed, 10 Mar 2021 17:52:23 +0100 Subject: [PATCH 3/5] Use System.Logger for logging with Java 9+ --- .../src/main/kotlin/flatlaf-java9.gradle.kts | 4 ++ .../java/com/formdev/flatlaf/FlatLaf.java | 8 ++-- .../com/formdev/flatlaf/IntelliJTheme.java | 2 +- .../com/formdev/flatlaf/LinuxFontPolicy.java | 6 +-- .../com/formdev/flatlaf/UIDefaultsLoader.java | 12 ++--- .../flatlaf/ui/JBRCustomDecorations.java | 6 +-- .../flatlaf/util/JavaCompatibility.java | 8 ++-- .../formdev/flatlaf/util/LoggingFacade.java | 45 ++----------------- .../flatlaf/util/LoggingFacadeImpl.java | 34 ++++++++++++++ .../flatlaf/util/LoggingFacadeImpl.java | 32 +++++++++++++ .../formdev/flatlaf/intellijthemes/Utils.java | 2 +- .../materialthemeuilite/Utils.java | 2 +- 12 files changed, 97 insertions(+), 64 deletions(-) create mode 100644 flatlaf-core/src/main/java/com/formdev/flatlaf/util/LoggingFacadeImpl.java create mode 100644 flatlaf-core/src/main/java9/com/formdev/flatlaf/util/LoggingFacadeImpl.java diff --git a/buildSrc/src/main/kotlin/flatlaf-java9.gradle.kts b/buildSrc/src/main/kotlin/flatlaf-java9.gradle.kts index 7e5b2ceb..311d7af4 100644 --- a/buildSrc/src/main/kotlin/flatlaf-java9.gradle.kts +++ b/buildSrc/src/main/kotlin/flatlaf-java9.gradle.kts @@ -27,6 +27,10 @@ if( JavaVersion.current() >= JavaVersion.VERSION_1_9 ) { } } + dependencies { + add("java9Compile", sourceSets.main.get().output) + } + tasks { named( "compileJava9Java" ) { sourceCompatibility = "9" diff --git a/flatlaf-core/src/main/java/com/formdev/flatlaf/FlatLaf.java b/flatlaf-core/src/main/java/com/formdev/flatlaf/FlatLaf.java index d703ea3e..04d73c04 100644 --- a/flatlaf-core/src/main/java/com/formdev/flatlaf/FlatLaf.java +++ b/flatlaf-core/src/main/java/com/formdev/flatlaf/FlatLaf.java @@ -101,7 +101,7 @@ public abstract class FlatLaf UIManager.setLookAndFeel( newLookAndFeel ); return true; } catch( Exception ex ) { - LoggingFacade.logSevere( "FlatLaf: Failed to initialize look and feel '" + newLookAndFeel.getClass().getName() + "'.", ex ); + LoggingFacade.INSTANCE.logSevere( "FlatLaf: Failed to initialize look and feel '" + newLookAndFeel.getClass().getName() + "'.", ex ); return false; } } @@ -339,7 +339,7 @@ public abstract class FlatLaf } else aquaLaf = (BasicLookAndFeel) Class.forName( aquaLafClassName ).newInstance(); } catch( Exception ex ) { - LoggingFacade.logSevere( "FlatLaf: Failed to initialize Aqua look and feel '" + aquaLafClassName + "'.", ex ); + LoggingFacade.INSTANCE.logSevere( "FlatLaf: Failed to initialize Aqua look and feel '" + aquaLafClassName + "'.", ex ); throw new IllegalStateException(); } @@ -575,7 +575,7 @@ public abstract class FlatLaf .invoke( null, true ); defaults.put( key, value ); } catch( Exception ex ) { - LoggingFacade.logSevere( null, ex ); + LoggingFacade.INSTANCE.logSevere( null, ex ); throw new RuntimeException( ex ); } } @@ -682,7 +682,7 @@ public abstract class FlatLaf // update UI updateUI(); } catch( UnsupportedLookAndFeelException ex ) { - LoggingFacade.logSevere( "FlatLaf: Failed to reinitialize look and feel '" + lookAndFeel.getClass().getName() + "'.", ex ); + LoggingFacade.INSTANCE.logSevere( "FlatLaf: Failed to reinitialize look and feel '" + lookAndFeel.getClass().getName() + "'.", ex ); } } ); } diff --git a/flatlaf-core/src/main/java/com/formdev/flatlaf/IntelliJTheme.java b/flatlaf-core/src/main/java/com/formdev/flatlaf/IntelliJTheme.java index e3154907..86c443b5 100644 --- a/flatlaf-core/src/main/java/com/formdev/flatlaf/IntelliJTheme.java +++ b/flatlaf-core/src/main/java/com/formdev/flatlaf/IntelliJTheme.java @@ -76,7 +76,7 @@ public class IntelliJTheme try { return FlatLaf.install( createLaf( in ) ); } catch( Exception ex ) { - LoggingFacade.logSevere( "FlatLaf: Failed to load IntelliJ theme", ex ); + LoggingFacade.INSTANCE.logSevere( "FlatLaf: Failed to load IntelliJ theme", ex ); return false; } } diff --git a/flatlaf-core/src/main/java/com/formdev/flatlaf/LinuxFontPolicy.java b/flatlaf-core/src/main/java/com/formdev/flatlaf/LinuxFontPolicy.java index 71c8d9a6..d6c585bf 100644 --- a/flatlaf-core/src/main/java/com/formdev/flatlaf/LinuxFontPolicy.java +++ b/flatlaf-core/src/main/java/com/formdev/flatlaf/LinuxFontPolicy.java @@ -173,7 +173,7 @@ class LinuxFontPolicy if( "1".equals( strs.get( 5 ) ) ) style |= Font.ITALIC; } catch( RuntimeException ex ) { - LoggingFacade.logConfig( "FlatLaf: Failed to parse 'font=" + generalFont + "'.", ex ); + LoggingFacade.INSTANCE.logConfig( "FlatLaf: Failed to parse 'font=" + generalFont + "'.", ex ); } } @@ -187,7 +187,7 @@ class LinuxFontPolicy if( dpi < 50 ) dpi = 50; } catch( NumberFormatException ex ) { - LoggingFacade.logConfig( "FlatLaf: Failed to parse 'forceFontDPI=" + forceFontDPI + "'.", ex ); + LoggingFacade.INSTANCE.logConfig( "FlatLaf: Failed to parse 'forceFontDPI=" + forceFontDPI + "'.", ex ); } } @@ -226,7 +226,7 @@ class LinuxFontPolicy while( (line = reader.readLine()) != null ) lines.add( line ); } catch( IOException ex ) { - LoggingFacade.logConfig( "FlatLaf: Failed to read '" + filename + "'.", ex ); + LoggingFacade.INSTANCE.logConfig( "FlatLaf: Failed to read '" + filename + "'.", ex ); } return lines; } diff --git a/flatlaf-core/src/main/java/com/formdev/flatlaf/UIDefaultsLoader.java b/flatlaf-core/src/main/java/com/formdev/flatlaf/UIDefaultsLoader.java index d34b3b6a..209723e4 100644 --- a/flatlaf-core/src/main/java/com/formdev/flatlaf/UIDefaultsLoader.java +++ b/flatlaf-core/src/main/java/com/formdev/flatlaf/UIDefaultsLoader.java @@ -247,16 +247,16 @@ class UIDefaultsLoader } } } catch( IOException ex ) { - LoggingFacade.logSevere( "FlatLaf: Failed to load properties files.", ex ); + LoggingFacade.INSTANCE.logSevere( "FlatLaf: Failed to load properties files.", ex ); } } static void logParseError( String key, String value, RuntimeException ex, boolean severe ) { String message = "FlatLaf: Failed to parse: '" + key + '=' + value + '\''; if (severe) { - LoggingFacade.logSevere( message, ex ); + LoggingFacade.INSTANCE.logSevere( message, ex ); } else { - LoggingFacade.logConfig( message, ex ); + LoggingFacade.INSTANCE.logConfig( message, ex ); } } @@ -445,7 +445,7 @@ class UIDefaultsLoader try { return findClass( value, addonClassLoaders ).newInstance(); } catch( InstantiationException | IllegalAccessException | ClassNotFoundException ex ) { - LoggingFacade.logSevere( "FlatLaf: Failed to instantiate '" + value + "'.", ex ); + LoggingFacade.INSTANCE.logSevere( "FlatLaf: Failed to instantiate '" + value + "'.", ex ); return null; } }; @@ -456,7 +456,7 @@ class UIDefaultsLoader try { return findClass( value, addonClassLoaders ); } catch( ClassNotFoundException ex ) { - LoggingFacade.logSevere( "FlatLaf: Failed to find class '" + value + "'.", ex ); + LoggingFacade.INSTANCE.logSevere( "FlatLaf: Failed to find class '" + value + "'.", ex ); return null; } }; @@ -933,7 +933,7 @@ class UIDefaultsLoader Object value = UIManager.get( uiKey ); if( value == null && !optional ) - LoggingFacade.logSevere( "FlatLaf: '" + uiKey + "' not found in UI defaults.", null ); + LoggingFacade.INSTANCE.logSevere( "FlatLaf: '" + uiKey + "' not found in UI defaults.", null ); return value; } } diff --git a/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/JBRCustomDecorations.java b/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/JBRCustomDecorations.java index 97f21724..e79fb165 100644 --- a/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/JBRCustomDecorations.java +++ b/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/JBRCustomDecorations.java @@ -154,7 +154,7 @@ public class JBRCustomDecorations try { return (Boolean) Window_hasCustomDecoration.invoke( window ); } catch( Exception ex ) { - LoggingFacade.logSevere( null, ex ); + LoggingFacade.INSTANCE.logSevere( null, ex ); return false; } } @@ -166,7 +166,7 @@ public class JBRCustomDecorations try { Window_setHasCustomDecoration.invoke( window ); } catch( Exception ex ) { - LoggingFacade.logSevere( null, ex ); + LoggingFacade.INSTANCE.logSevere( null, ex ); } } @@ -180,7 +180,7 @@ public class JBRCustomDecorations WWindowPeer_setCustomDecorationHitTestSpots.invoke( peer, hitTestSpots ); WWindowPeer_setCustomDecorationTitleBarHeight.invoke( peer, titleBarHeight ); } catch( Exception ex ) { - LoggingFacade.logSevere( null, ex ); + LoggingFacade.INSTANCE.logSevere( null, ex ); } } diff --git a/flatlaf-core/src/main/java/com/formdev/flatlaf/util/JavaCompatibility.java b/flatlaf-core/src/main/java/com/formdev/flatlaf/util/JavaCompatibility.java index bc177a66..1f94dc55 100644 --- a/flatlaf-core/src/main/java/com/formdev/flatlaf/util/JavaCompatibility.java +++ b/flatlaf-core/src/main/java/com/formdev/flatlaf/util/JavaCompatibility.java @@ -55,7 +55,7 @@ public class JavaCompatibility ? new Class[] { JComponent.class, Graphics2D.class, String.class, int.class, float.class, float.class } : new Class[] { JComponent.class, Graphics.class, String.class, int.class, int.class, int.class } ); } catch( Exception ex ) { - LoggingFacade.logSevere( null, ex ); + LoggingFacade.INSTANCE.logSevere( null, ex ); throw new RuntimeException( ex ); } } @@ -67,7 +67,7 @@ public class JavaCompatibility else drawStringUnderlineCharAtMethod.invoke( null, c, g, text, underlinedIndex, x, y ); } catch( IllegalAccessException | IllegalArgumentException | InvocationTargetException ex ) { - LoggingFacade.logSevere( null, ex ); + LoggingFacade.INSTANCE.logSevere( null, ex ); throw new RuntimeException( ex ); } } @@ -91,7 +91,7 @@ public class JavaCompatibility : "clipStringIfNecessary", new Class[] { JComponent.class, FontMetrics.class, String.class, int.class } ); } catch( Exception ex ) { - LoggingFacade.logSevere( null, ex ); + LoggingFacade.INSTANCE.logSevere( null, ex ); throw new RuntimeException( ex ); } } @@ -100,7 +100,7 @@ public class JavaCompatibility try { return (String) getClippedStringMethod.invoke( null, c, fm, string, availTextWidth ); } catch( IllegalAccessException | IllegalArgumentException | InvocationTargetException ex ) { - LoggingFacade.logSevere( null, ex ); + LoggingFacade.INSTANCE.logSevere( null, ex ); throw new RuntimeException( ex ); } } diff --git a/flatlaf-core/src/main/java/com/formdev/flatlaf/util/LoggingFacade.java b/flatlaf-core/src/main/java/com/formdev/flatlaf/util/LoggingFacade.java index 12172f7f..afdef194 100644 --- a/flatlaf-core/src/main/java/com/formdev/flatlaf/util/LoggingFacade.java +++ b/flatlaf-core/src/main/java/com/formdev/flatlaf/util/LoggingFacade.java @@ -16,48 +16,11 @@ package com.formdev.flatlaf.util; -import com.formdev.flatlaf.FlatLaf; -import java.util.logging.Level; -import java.util.logging.Logger; - -public class LoggingFacade +public interface LoggingFacade { - private static final Logger LOG = createLogger(); + LoggingFacade INSTANCE = new LoggingFacadeImpl(); - private static Logger createLogger() { - try { - return Logger.getLogger( FlatLaf.class.getName() ); - } catch( Throwable e ) { - // Module java.logging is not present - return null; - } - } + void logSevere( String message, Throwable t ); - public static void logSevere( String message, Throwable t ) { - if( LOG != null ) { - LOG.log( Level.SEVERE, message, t ); - } else { - if( message != null ) { - System.err.println( message ); - } - if( t != null ) { - t.printStackTrace(); - } - } - } - - public static void logConfig( String message, Throwable t ) { - if( LOG != null ) { - LOG.log( Level.CONFIG, message, t ); - } else { - if (Boolean.getBoolean( "flatLaf.logConfig" )) { - if( message != null ) { - System.err.println( message ); - } - if( t != null ) { - t.printStackTrace(); - } - } - } - } + void logConfig( String message, Throwable t ); } diff --git a/flatlaf-core/src/main/java/com/formdev/flatlaf/util/LoggingFacadeImpl.java b/flatlaf-core/src/main/java/com/formdev/flatlaf/util/LoggingFacadeImpl.java new file mode 100644 index 00000000..5da1655a --- /dev/null +++ b/flatlaf-core/src/main/java/com/formdev/flatlaf/util/LoggingFacadeImpl.java @@ -0,0 +1,34 @@ +/* + * Copyright 2020 FormDev Software GmbH + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.formdev.flatlaf.util; + +import com.formdev.flatlaf.FlatLaf; +import java.util.logging.Level; +import java.util.logging.Logger; + +public class LoggingFacadeImpl implements LoggingFacade +{ + private static final Logger LOG = Logger.getLogger( FlatLaf.class.getName() ); + + public void logSevere( String message, Throwable t ) { + LOG.log( Level.SEVERE, message, t ); + } + + public void logConfig( String message, Throwable t ) { + LOG.log( Level.CONFIG, message, t ); + } +} diff --git a/flatlaf-core/src/main/java9/com/formdev/flatlaf/util/LoggingFacadeImpl.java b/flatlaf-core/src/main/java9/com/formdev/flatlaf/util/LoggingFacadeImpl.java new file mode 100644 index 00000000..d7e5902f --- /dev/null +++ b/flatlaf-core/src/main/java9/com/formdev/flatlaf/util/LoggingFacadeImpl.java @@ -0,0 +1,32 @@ +/* + * Copyright 2020 FormDev Software GmbH + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.formdev.flatlaf.util; + +import com.formdev.flatlaf.FlatLaf; + +public class LoggingFacadeImpl implements LoggingFacade +{ + private static final System.Logger LOG = System.getLogger( FlatLaf.class.getName() ); + + public void logSevere( String message, Throwable t ) { + LOG.log( System.Logger.Level.ERROR, message, t ); + } + + public void logConfig( String message, Throwable t ) { + LOG.log( System.Logger.Level.DEBUG, message, t ); + } +} diff --git a/flatlaf-intellij-themes/src/main/java/com/formdev/flatlaf/intellijthemes/Utils.java b/flatlaf-intellij-themes/src/main/java/com/formdev/flatlaf/intellijthemes/Utils.java index 0e31e66b..4d37b99b 100644 --- a/flatlaf-intellij-themes/src/main/java/com/formdev/flatlaf/intellijthemes/Utils.java +++ b/flatlaf-intellij-themes/src/main/java/com/formdev/flatlaf/intellijthemes/Utils.java @@ -31,7 +31,7 @@ class Utils "/com/formdev/flatlaf/intellijthemes/themes/" + name ) ); } catch( IOException ex ) { String msg = "FlatLaf: Failed to load IntelliJ theme '" + name + "'"; - LoggingFacade.logSevere( msg, ex ); + LoggingFacade.INSTANCE.logSevere( msg, ex ); throw new RuntimeException( msg, ex ); } } diff --git a/flatlaf-intellij-themes/src/main/java/com/formdev/flatlaf/intellijthemes/materialthemeuilite/Utils.java b/flatlaf-intellij-themes/src/main/java/com/formdev/flatlaf/intellijthemes/materialthemeuilite/Utils.java index 2a1558ce..957c2ddc 100644 --- a/flatlaf-intellij-themes/src/main/java/com/formdev/flatlaf/intellijthemes/materialthemeuilite/Utils.java +++ b/flatlaf-intellij-themes/src/main/java/com/formdev/flatlaf/intellijthemes/materialthemeuilite/Utils.java @@ -31,7 +31,7 @@ class Utils "/com/formdev/flatlaf/intellijthemes/themes/material-theme-ui-lite/" + name ) ); } catch( IOException ex ) { String msg = "FlatLaf: Failed to load IntelliJ theme '" + name + "'"; - LoggingFacade.logSevere( msg, ex ); + LoggingFacade.INSTANCE.logSevere( msg, ex ); throw new RuntimeException( msg, ex ); } } From 617a35c51b411490dbe9bc63c0a74c5cb0eeab1d Mon Sep 17 00:00:00 2001 From: Karl Tauber Date: Fri, 12 Mar 2021 21:16:57 +0100 Subject: [PATCH 4/5] LoggingFacade: - make LoggingFacadeImpl classes package private - added missing @Override - minor formatting changes --- .../main/java/com/formdev/flatlaf/UIDefaultsLoader.java | 5 ++--- .../main/java/com/formdev/flatlaf/util/LoggingFacade.java | 3 +-- .../java/com/formdev/flatlaf/util/LoggingFacadeImpl.java | 7 +++++-- .../java9/com/formdev/flatlaf/util/LoggingFacadeImpl.java | 7 +++++-- 4 files changed, 13 insertions(+), 9 deletions(-) diff --git a/flatlaf-core/src/main/java/com/formdev/flatlaf/UIDefaultsLoader.java b/flatlaf-core/src/main/java/com/formdev/flatlaf/UIDefaultsLoader.java index 209723e4..f490e6a3 100644 --- a/flatlaf-core/src/main/java/com/formdev/flatlaf/UIDefaultsLoader.java +++ b/flatlaf-core/src/main/java/com/formdev/flatlaf/UIDefaultsLoader.java @@ -253,11 +253,10 @@ class UIDefaultsLoader static void logParseError( String key, String value, RuntimeException ex, boolean severe ) { String message = "FlatLaf: Failed to parse: '" + key + '=' + value + '\''; - if (severe) { + if( severe ) LoggingFacade.INSTANCE.logSevere( message, ex ); - } else { + else LoggingFacade.INSTANCE.logConfig( message, ex ); - } } static String resolveValue( String value, Function propertiesGetter ) { diff --git a/flatlaf-core/src/main/java/com/formdev/flatlaf/util/LoggingFacade.java b/flatlaf-core/src/main/java/com/formdev/flatlaf/util/LoggingFacade.java index afdef194..ec0a933b 100644 --- a/flatlaf-core/src/main/java/com/formdev/flatlaf/util/LoggingFacade.java +++ b/flatlaf-core/src/main/java/com/formdev/flatlaf/util/LoggingFacade.java @@ -1,5 +1,5 @@ /* - * Copyright 2020 FormDev Software GmbH + * Copyright 2021 FormDev Software GmbH * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -21,6 +21,5 @@ public interface LoggingFacade LoggingFacade INSTANCE = new LoggingFacadeImpl(); void logSevere( String message, Throwable t ); - void logConfig( String message, Throwable t ); } diff --git a/flatlaf-core/src/main/java/com/formdev/flatlaf/util/LoggingFacadeImpl.java b/flatlaf-core/src/main/java/com/formdev/flatlaf/util/LoggingFacadeImpl.java index 5da1655a..433a0944 100644 --- a/flatlaf-core/src/main/java/com/formdev/flatlaf/util/LoggingFacadeImpl.java +++ b/flatlaf-core/src/main/java/com/formdev/flatlaf/util/LoggingFacadeImpl.java @@ -1,5 +1,5 @@ /* - * Copyright 2020 FormDev Software GmbH + * Copyright 2021 FormDev Software GmbH * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -20,14 +20,17 @@ import com.formdev.flatlaf.FlatLaf; import java.util.logging.Level; import java.util.logging.Logger; -public class LoggingFacadeImpl implements LoggingFacade +class LoggingFacadeImpl + implements LoggingFacade { private static final Logger LOG = Logger.getLogger( FlatLaf.class.getName() ); + @Override public void logSevere( String message, Throwable t ) { LOG.log( Level.SEVERE, message, t ); } + @Override public void logConfig( String message, Throwable t ) { LOG.log( Level.CONFIG, message, t ); } diff --git a/flatlaf-core/src/main/java9/com/formdev/flatlaf/util/LoggingFacadeImpl.java b/flatlaf-core/src/main/java9/com/formdev/flatlaf/util/LoggingFacadeImpl.java index d7e5902f..0f29120f 100644 --- a/flatlaf-core/src/main/java9/com/formdev/flatlaf/util/LoggingFacadeImpl.java +++ b/flatlaf-core/src/main/java9/com/formdev/flatlaf/util/LoggingFacadeImpl.java @@ -1,5 +1,5 @@ /* - * Copyright 2020 FormDev Software GmbH + * Copyright 2021 FormDev Software GmbH * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -18,14 +18,17 @@ package com.formdev.flatlaf.util; import com.formdev.flatlaf.FlatLaf; -public class LoggingFacadeImpl implements LoggingFacade +class LoggingFacadeImpl + implements LoggingFacade { private static final System.Logger LOG = System.getLogger( FlatLaf.class.getName() ); + @Override public void logSevere( String message, Throwable t ) { LOG.log( System.Logger.Level.ERROR, message, t ); } + @Override public void logConfig( String message, Throwable t ) { LOG.log( System.Logger.Level.DEBUG, message, t ); } From 7c7ff289de24df7a0b597ff089a84f76fe1ff941 Mon Sep 17 00:00:00 2001 From: Karl Tauber Date: Fri, 12 Mar 2021 22:52:59 +0100 Subject: [PATCH 5/5] removed module `java.logging` from `module-info.java`s --- buildSrc/src/main/kotlin/flatlaf-java9.gradle.kts | 2 +- .../src/main/kotlin/flatlaf-module-info.gradle.kts | 12 ++++++++++-- flatlaf-core/src/main/module-info/module-info.java | 1 - .../src/main/module-info/module-info.java | 1 - 4 files changed, 11 insertions(+), 5 deletions(-) diff --git a/buildSrc/src/main/kotlin/flatlaf-java9.gradle.kts b/buildSrc/src/main/kotlin/flatlaf-java9.gradle.kts index 311d7af4..49c751a1 100644 --- a/buildSrc/src/main/kotlin/flatlaf-java9.gradle.kts +++ b/buildSrc/src/main/kotlin/flatlaf-java9.gradle.kts @@ -28,7 +28,7 @@ if( JavaVersion.current() >= JavaVersion.VERSION_1_9 ) { } dependencies { - add("java9Compile", sourceSets.main.get().output) + add( "java9Compile", sourceSets.main.get().output ) } tasks { diff --git a/buildSrc/src/main/kotlin/flatlaf-module-info.gradle.kts b/buildSrc/src/main/kotlin/flatlaf-module-info.gradle.kts index a78879c6..5c464a84 100644 --- a/buildSrc/src/main/kotlin/flatlaf-module-info.gradle.kts +++ b/buildSrc/src/main/kotlin/flatlaf-module-info.gradle.kts @@ -33,9 +33,17 @@ if( JavaVersion.current() >= JavaVersion.VERSION_1_9 ) { sourceSets { create( "module-info" ) { java { - // include "src/main/java" here to get compile errors if classes are + // include "src/main/java" and "src/main/java9" here to get compile errors if classes are // used from other modules that are not specified in module dependencies - setSrcDirs( listOf( "src/main/module-info", "src/main/java" ) ) + setSrcDirs( listOf( "src/main/module-info", "src/main/java", "src/main/java9" ) ) + + // exclude Java 8 source file if an equally named Java 9+ source file exists + exclude { + if( it.isDirectory ) + return@exclude false + val java9file = file( "${projectDir}/src/main/java9/${it.path}" ) + java9file.exists() && java9file != it.file + } } } } diff --git a/flatlaf-core/src/main/module-info/module-info.java b/flatlaf-core/src/main/module-info/module-info.java index ee57bed2..55b361f7 100644 --- a/flatlaf-core/src/main/module-info/module-info.java +++ b/flatlaf-core/src/main/module-info/module-info.java @@ -19,7 +19,6 @@ */ module com.formdev.flatlaf { requires java.desktop; - requires static java.logging; exports com.formdev.flatlaf; exports com.formdev.flatlaf.icons; diff --git a/flatlaf-intellij-themes/src/main/module-info/module-info.java b/flatlaf-intellij-themes/src/main/module-info/module-info.java index c6c87c20..fc6caf64 100644 --- a/flatlaf-intellij-themes/src/main/module-info/module-info.java +++ b/flatlaf-intellij-themes/src/main/module-info/module-info.java @@ -19,7 +19,6 @@ */ module com.formdev.flatlaf.intellijthemes { requires java.desktop; - requires java.logging; requires com.formdev.flatlaf; exports com.formdev.flatlaf.intellijthemes;