Skip to content

Commit

Permalink
Adjust IkonHandler loading mechanism. Fixes #124
Browse files Browse the repository at this point in the history
  • Loading branch information
aalmiray committed Dec 6, 2020
1 parent 93d4cca commit a697e63
Show file tree
Hide file tree
Showing 7 changed files with 26 additions and 19 deletions.
2 changes: 2 additions & 0 deletions core/ikonli-core/src/main/java/module-info.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
requires static org.kordamp.jipsy.annotations;
requires java.logging;

uses org.kordamp.ikonli.IkonHandler;

provides org.kordamp.ikonli.IkonHandler
with org.kordamp.ikonli.IkonliIkonResolver;
provides org.kordamp.ikonli.IkonProvider
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

import java.util.Arrays;
import java.util.LinkedHashSet;
import java.util.ServiceLoader;
import java.util.Set;
import java.util.logging.Logger;

Expand Down Expand Up @@ -94,4 +95,23 @@ private void throwOrWarn(String message) {
private boolean strictChecksEnabled() {
return System.getProperty(ORG_KORDAMP_IKONLI_STRICT) == null || Boolean.getBoolean(ORG_KORDAMP_IKONLI_STRICT);
}

public static ServiceLoader<IkonHandler> resolveServiceLoader() {
// Check if handlers must be loaded from a ModuleLayer
if (null != IkonHandler.class.getModule().getLayer()) {
ServiceLoader<IkonHandler> handlers = ServiceLoader.load(IkonHandler.class.getModule().getLayer(), IkonHandler.class);
if (handlers.stream().count() > 0) {
return handlers;
}
}

// Check if the IkonHandler.class.classLoader works
ServiceLoader<IkonHandler> handlers = ServiceLoader.load(IkonHandler.class, IkonHandler.class.getClassLoader());
if (handlers.stream().count() > 0) {
return handlers;
}

// If *nothing* else works
return ServiceLoader.load(IkonHandler.class);
}
}
2 changes: 0 additions & 2 deletions core/ikonli-javafx/src/main/java/module-info.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,4 @@
requires javafx.base;
requires javafx.graphics;
requires javafx.controls;

uses org.kordamp.ikonli.IkonHandler;
}
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,6 @@ private IkonResolver() {

}

private static ServiceLoader<IkonHandler> resolveServiceLoader() {
if (null != IkonHandler.class.getModule().getLayer()) {
return ServiceLoader.load(IkonHandler.class.getModule().getLayer(), IkonHandler.class);
}
return ServiceLoader.load(IkonHandler.class);
}

public static IkonResolver getInstance() {
return INSTANCE;
}
Expand Down
5 changes: 3 additions & 2 deletions core/ikonli-swing/src/main/java/module-info.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,9 @@
* limitations under the License.
*/
module org.kordamp.ikonli.swing {
exports org.kordamp.ikonli.swing;

requires org.kordamp.ikonli.core;

requires java.desktop;
uses org.kordamp.ikonli.IkonHandler;
exports org.kordamp.ikonli.swing;
}
Original file line number Diff line number Diff line change
Expand Up @@ -54,13 +54,6 @@ private IkonResolver() {

}

private static ServiceLoader<IkonHandler> resolveServiceLoader() {
if (null != IkonHandler.class.getModule().getLayer()) {
return ServiceLoader.load(IkonHandler.class.getModule().getLayer(), IkonHandler.class);
}
return ServiceLoader.load(IkonHandler.class);
}

public static IkonResolver getInstance() {
return INSTANCE;
}
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
#

ikonliJdk8Version = 2.6.0
version = 12.0.0
version = 12.0.1-SNAPSHOT
group = org.kordamp.ikonli

sourceCompatibility = 11
Expand Down

0 comments on commit a697e63

Please sign in to comment.