Ignore:
Timestamp:
2018-11-01T15:24:19+01:00 (6 years ago)
Author:
donvip
Message:

see #josm16912 - functional version of javafx plugin (tested on Windows only)

Location:
applications/editors/josm/plugins/javafx/src/org/openstreetmap/josm/plugins/javafx
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • applications/editors/josm/plugins/javafx/src/org/openstreetmap/josm/plugins/javafx/JavaFxPlugin.java

    r34703 r34713  
    1616import java.security.CodeSource;
    1717import java.util.Enumeration;
     18import java.util.List;
    1819import java.util.Objects;
    1920import java.util.zip.ZipEntry;
     
    3738     * @param info plugin info
    3839     * @param ext native libraries extension
     40     * @param orderedNativeLibraries native librarires that must be loaded in this order
    3941     */
    40     protected JavaFxPlugin(PluginInformation info, String ext) {
     42    protected JavaFxPlugin(PluginInformation info, String ext, List<String> orderedNativeLibraries) {
    4143        super(info);
    4244        AudioPlayer.setSoundPlayerClass(JavaFxMediaPlayer.class);
    4345        extractNativeLibs(ext);
    44         loadNativeLibs(ext);
     46        loadNativeLibs(ext, orderedNativeLibraries);
    4547    }
    4648
     
    8082        private final ClassLoader ccl = Thread.currentThread().getContextClassLoader();
    8183        private final String ext;
     84        private final List<String> orderedNativeLibraries;
    8285
    83         public LibVisitor(String ext) {
     86        public LibVisitor(String ext, List<String> orderedNativeLibraries) {
    8487            this.ext = Objects.requireNonNull(ext);
     88            this.orderedNativeLibraries = Objects.requireNonNull(orderedNativeLibraries);
    8589        }
    8690
     
    8892        public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException {
    8993            if (ccl instanceof DynamicURLClassLoader) {
    90                 if (file.endsWith(ext)) {
    91                     Logging.debug("Loading " + file);
    92                     System.load(file.toAbsolutePath().toString());
    93                 } else if (file.endsWith(".jar")) {
    94                     Logging.debug("Loading " + file);
     94                String path = file.toAbsolutePath().toString();
     95                if (path.endsWith(ext) && !orderedNativeLibraries.contains(file.getFileName().toString())) {
     96                    loadNativeLib(path);
     97                } else if (path.endsWith(".jar")) {
     98                    Logging.debug("Loading {0}", path);
    9599                    ((DynamicURLClassLoader) ccl).addURL(file.toUri().toURL());
    96100                }
     
    103107    }
    104108
    105     private void loadNativeLibs(String ext) {
     109    private static void loadNativeLib(String absolutePath) {
    106110        try {
    107             Files.walkFileTree(getNativeDir(), new LibVisitor(ext));
     111            Logging.debug("Loading {0}", absolutePath);
     112            System.load(absolutePath);
     113        } catch (LinkageError e) {
     114            Logging.error(e);
     115        }
     116    }
     117
     118    private static void loadNativeLibs(String ext, List<String> orderedNativeLibraries) {
     119        try {
     120            Path nativeDir = getNativeDir();
     121            Files.walkFileTree(nativeDir, new LibVisitor(ext, orderedNativeLibraries));
     122            for (String lib : orderedNativeLibraries) {
     123                loadNativeLib(nativeDir.resolve(lib).toAbsolutePath().toString());
     124            }
    108125        } catch (IOException e) {
    109126            Logging.error(e);
  • applications/editors/josm/plugins/javafx/src/org/openstreetmap/josm/plugins/javafx/JavaFxPluginOsx.java

    r34703 r34713  
    11// License: GPL. For details, see LICENSE file.
    22package org.openstreetmap.josm.plugins.javafx;
     3
     4import java.util.Arrays;
    35
    46import org.openstreetmap.josm.plugins.PluginInformation;
     
    1012
    1113    /**
    12      * Constructs a new {@code OpenJfxPlugin}.
     14     * Constructs a new {@code JavaFxPluginOsx}.
    1315     * @param info plugin info
    1416     */
    1517    public JavaFxPluginOsx(PluginInformation info) {
    16         super(info, ".dylib");
     18        super(info, ".dylib", Arrays.asList());
    1719    }
    1820}
  • applications/editors/josm/plugins/javafx/src/org/openstreetmap/josm/plugins/javafx/JavaFxPluginUnixoid.java

    r34703 r34713  
    11// License: GPL. For details, see LICENSE file.
    22package org.openstreetmap.josm.plugins.javafx;
     3
     4import java.util.Arrays;
    35
    46import org.openstreetmap.josm.plugins.PluginInformation;
     
    1012
    1113    /**
    12      * Constructs a new {@code OpenJfxPlugin}.
     14     * Constructs a new {@code JavaFxPluginUnixoid}.
    1315     * @param info plugin info
    1416     */
    1517    public JavaFxPluginUnixoid(PluginInformation info) {
    16         super(info, ".so");
     18        super(info, ".so", Arrays.asList());
    1719    }
    1820}
  • applications/editors/josm/plugins/javafx/src/org/openstreetmap/josm/plugins/javafx/JavaFxPluginWindows.java

    r34703 r34713  
    11// License: GPL. For details, see LICENSE file.
    22package org.openstreetmap.josm.plugins.javafx;
     3
     4import java.util.Arrays;
    35
    46import org.openstreetmap.josm.plugins.PluginInformation;
     
    1012
    1113    /**
    12      * Constructs a new {@code OpenJfxPlugin}.
     14     * Constructs a new {@code JavaFxPluginWindows}.
    1315     * @param info plugin info
    1416     */
    1517    public JavaFxPluginWindows(PluginInformation info) {
    16         super(info, ".dll");
     18        super(info, ".dll", Arrays.asList("fxplugins.dll"));
    1719    }
    1820}
Note: See TracChangeset for help on using the changeset viewer.