Changeset 34623 in osm


Ignore:
Timestamp:
2018-09-09T22:03:36+02:00 (6 years ago)
Author:
donvip
Message:

see #josm16682 - first version of openjfx plugin

Location:
applications/editors/josm/plugins/openjfx
Files:
1 added
5 edited

Legend:

Unmodified
Added
Removed
  • applications/editors/josm/plugins/openjfx/.classpath

    r34602 r34623  
    44        <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8"/>
    55        <classpathentry combineaccessrules="false" kind="src" path="/JOSM"/>
    6         <classpathentry exported="true" kind="lib" path="lib/javafx-base-11-ea+23-win.jar" sourcepath="lib/javafx-base-11-ea+23-sources.jar">
     6        <classpathentry exported="true" kind="lib" path="lib/javafx-base-11-ea+25-win.jar" sourcepath="lib/javafx-base-11-ea+25-sources.jar">
    77                <attributes>
    8                         <attribute name="javadoc_location" value="jar:platform:/resource/JOSM-openjfx/lib/javafx-base-11-ea+23-javadoc.jar!/"/>
     8                        <attribute name="javadoc_location" value="jar:platform:/resource/JOSM-openjfx/lib/javafx-base-11-ea+25-javadoc.jar!/"/>
    99                </attributes>
    1010        </classpathentry>
    11         <classpathentry exported="true" kind="lib" path="lib/javafx-controls-11-ea+23-win.jar" sourcepath="lib/javafx-controls-11-ea+23-sources.jar">
     11        <classpathentry exported="true" kind="lib" path="lib/javafx-controls-11-ea+25-win.jar" sourcepath="lib/javafx-controls-11-ea+25-sources.jar">
    1212                <attributes>
    13                         <attribute name="javadoc_location" value="jar:platform:/resource/JOSM-openjfx/lib/javafx-controls-11-ea+23-javadoc.jar!/"/>
     13                        <attribute name="javadoc_location" value="jar:platform:/resource/JOSM-openjfx/lib/javafx-controls-11-ea+25-javadoc.jar!/"/>
    1414                </attributes>
    1515        </classpathentry>
    16         <classpathentry exported="true" kind="lib" path="lib/javafx-fxml-11-ea+23-win.jar" sourcepath="lib/javafx-fxml-11-ea+23-sources.jar">
     16        <classpathentry exported="true" kind="lib" path="lib/javafx-fxml-11-ea+25-win.jar" sourcepath="lib/javafx-fxml-11-ea+25-sources.jar">
    1717                <attributes>
    18                         <attribute name="javadoc_location" value="jar:platform:/resource/JOSM-openjfx/lib/javafx-fxml-11-ea+23-javadoc.jar!/"/>
     18                        <attribute name="javadoc_location" value="jar:platform:/resource/JOSM-openjfx/lib/javafx-fxml-11-ea+25-javadoc.jar!/"/>
    1919                </attributes>
    2020        </classpathentry>
    21         <classpathentry exported="true" kind="lib" path="lib/javafx-graphics-11-ea+23-win.jar" sourcepath="lib/javafx-graphics-11-ea+23-sources.jar">
     21        <classpathentry exported="true" kind="lib" path="lib/javafx-graphics-11-ea+25-win.jar" sourcepath="lib/javafx-graphics-11-ea+25-sources.jar">
    2222                <attributes>
    23                         <attribute name="javadoc_location" value="jar:platform:/resource/JOSM-openjfx/lib/javafx-graphics-11-ea+23-javadoc.jar!/"/>
     23                        <attribute name="javadoc_location" value="jar:platform:/resource/JOSM-openjfx/lib/javafx-graphics-11-ea+25-javadoc.jar!/"/>
    2424                </attributes>
    2525        </classpathentry>
    26         <classpathentry exported="true" kind="lib" path="lib/javafx-media-11-ea+23-win.jar" sourcepath="lib/javafx-media-11-ea+23-sources.jar">
     26        <classpathentry exported="true" kind="lib" path="lib/javafx-media-11-ea+25-win.jar" sourcepath="lib/javafx-media-11-ea+25-sources.jar">
    2727                <attributes>
    28                         <attribute name="javadoc_location" value="jar:platform:/resource/JOSM-openjfx/lib/javafx-media-11-ea+23-javadoc.jar!/"/>
     28                        <attribute name="javadoc_location" value="jar:platform:/resource/JOSM-openjfx/lib/javafx-media-11-ea+25-javadoc.jar!/"/>
    2929                </attributes>
    3030        </classpathentry>
    31         <classpathentry exported="true" kind="lib" path="lib/javafx-swing-11-ea+23-win.jar" sourcepath="lib/javafx-swing-11-ea+23-sources.jar">
     31        <classpathentry exported="true" kind="lib" path="lib/javafx-swing-11-ea+25-win.jar" sourcepath="lib/javafx-swing-11-ea+25-sources.jar">
    3232                <attributes>
    33                         <attribute name="javadoc_location" value="jar:platform:/resource/JOSM-openjfx/lib/javafx-swing-11-ea+23-javadoc.jar!/"/>
     33                        <attribute name="javadoc_location" value="jar:platform:/resource/JOSM-openjfx/lib/javafx-swing-11-ea+25-javadoc.jar!/"/>
    3434                </attributes>
    3535        </classpathentry>
    36         <classpathentry exported="true" kind="lib" path="lib/javafx-web-11-ea+23-win.jar" sourcepath="lib/javafx-web-11-ea+23-sources.jar">
     36        <classpathentry exported="true" kind="lib" path="lib/javafx-web-11-ea+25-win.jar" sourcepath="lib/javafx-web-11-ea+25-sources.jar">
    3737                <attributes>
    38                         <attribute name="javadoc_location" value="jar:platform:/resource/JOSM-openjfx/lib/javafx-web-11-ea+23-javadoc.jar!/"/>
     38                        <attribute name="javadoc_location" value="jar:platform:/resource/JOSM-openjfx/lib/javafx-web-11-ea+25-javadoc.jar!/"/>
    3939                </attributes>
    4040        </classpathentry>
  • applications/editors/josm/plugins/openjfx/README

    r34602 r34623  
    11README
    22======
    3 This plugin provides the openjfx library for JOSM plugins.
     3This plugin provides the openjfx (JavaFX) library for JOSM plugins.
    44    * Licensed under GPL v3 (see LICENSE)
  • applications/editors/josm/plugins/openjfx/build.xml

    r34604 r34623  
    44    <property name="commit.message" value="Commit message"/>
    55    <!-- enter the *lowest* JOSM version this plugin is currently compatible with -->
    6     <property name="plugin.main.version" value="14183"/>
     6    <property name="plugin.main.version" value="14234"/>
    77
    88        <!-- Configure these properties (replace "..." accordingly).
     
    1010    -->
    1111    <property name="plugin.author" value="Don-vip"/>
    12     <property name="plugin.class" value="org.openstreetmap.josm.plugins.jaxb.OpenJfxPlugin"/>
     12    <property name="plugin.class" value="org.openstreetmap.josm.plugins.openjfx.OpenJfxPlugin"/>
    1313    <property name="plugin.description" value="Provides the OpenJFX (JavaFX) library for JOSM core and other JOSM plugins. Provides additional features such as MP3 audio playback."/>
    1414    <property name="plugin.minimum.java.version" value="11"/>
     
    2525                <!-- include fetch_dependencies task -->
    2626        </target>
     27
     28    <!-- Override build-jar target to speed up merging from 16 minutes to 7 minutes -->
     29    <target name="build-jar">
     30        <echo>Building commong jar...</echo>
     31        <jar destfile="${plugin.jar}" basedir="${plugin.build.dir}" manifest="MANIFEST" manifestencoding="UTF-8" duplicate="preserve" level="9">
     32            <restrict>
     33                <not><or>
     34                    <name name="META-INF/maven/*"/>
     35                    <name name="META-INF/DEPENDENCIES"/>
     36                    <name name="META-INF/LICENSE"/>
     37                    <name name="META-INF/NOTICE"/>
     38                    <name name="META-INF/*.RSA"/>
     39                    <name name="META-INF/*.SF"/>
     40                    <name name="module-info.class"/>
     41                </or></not>
     42                <archives>
     43                    <zips>
     44                        <fileset dir="${plugin.lib.dir}" includes="*-linux.jar"/>
     45                    </zips>
     46                </archives>
     47            </restrict>
     48        </jar>
     49        <echo>Adding macOS artifacts...</echo>
     50        <jar destfile="${plugin.jar}" update="true" duplicate="preserve" level="9">
     51            <restrict>
     52                <or>
     53                    <name name="*.dylib"/>
     54                    <name name="com/sun/glass/events/mac/**"/>
     55                    <name name="com/sun/glass/ui/mac/**"/>
     56                    <name name="com/sun/media/jfxmediaimpl/platform/osx/**"/>
     57                    <name name="com/sun/prism/es2/**"/>
     58                </or>
     59                <archives>
     60                    <zips>
     61                        <fileset dir="${plugin.lib.dir}" includes="*-mac.jar"/>
     62                    </zips>
     63                </archives>
     64            </restrict>
     65        </jar>
     66        <echo>Adding Windows artifacts...</echo>
     67        <jar destfile="${plugin.jar}" update="true" duplicate="preserve" level="9">
     68            <restrict>
     69                <or>
     70                    <name name="*.dll"/>
     71                    <name name="com/sun/glass/ui/win/**"/>
     72                    <name name="com/sun/prism/d3d/**"/>
     73                    <name name="com/sun/scenario/effect/impl/hw/d3d/**"/>
     74                </or>
     75                <archives>
     76                    <zips>
     77                        <fileset dir="${plugin.lib.dir}" includes="*-win.jar"/>
     78                    </zips>
     79                </archives>
     80            </restrict>
     81        </jar>
     82    </target>
    2783</project>
  • applications/editors/josm/plugins/openjfx/ivy.xml

    r34602 r34623  
    55        </configurations>
    66        <dependencies>
    7         <dependency org="org.openjfx" name="javafx-swing" rev="11-ea+23">
     7        <dependency org="org.openjfx" name="javafx-swing" rev="11-ea+25">
    88            <artifact name="javafx-swing" type="jar" m:classifier="linux"/>
    99            <artifact name="javafx-swing" type="jar" m:classifier="mac"/>
     
    1212            <artifact name="javafx-swing" type="jar" m:classifier="javadoc"/>
    1313        </dependency>
    14         <dependency org="org.openjfx" name="javafx-fxml" rev="11-ea+23">
     14        <dependency org="org.openjfx" name="javafx-fxml" rev="11-ea+25">
    1515            <artifact name="javafx-fxml" type="jar" m:classifier="linux"/>
    1616            <artifact name="javafx-fxml" type="jar" m:classifier="mac"/>
     
    1919            <artifact name="javafx-fxml" type="jar" m:classifier="javadoc"/>
    2020        </dependency>
    21         <dependency org="org.openjfx" name="javafx-web" rev="11-ea+23">
     21        <dependency org="org.openjfx" name="javafx-web" rev="11-ea+25">
    2222            <artifact name="javafx-web" type="jar" m:classifier="linux"/>
    2323            <artifact name="javafx-web" type="jar" m:classifier="mac"/>
     
    2626            <artifact name="javafx-web" type="jar" m:classifier="javadoc"/>
    2727        </dependency>
    28         <dependency org="org.openjfx" name="javafx-media" rev="11-ea+23">
     28        <dependency org="org.openjfx" name="javafx-media" rev="11-ea+25">
    2929            <artifact name="javafx-media" type="jar" m:classifier="linux"/>
    3030            <artifact name="javafx-media" type="jar" m:classifier="mac"/>
     
    3333            <artifact name="javafx-media" type="jar" m:classifier="javadoc"/>
    3434        </dependency>
    35         <dependency org="org.openjfx" name="javafx-controls" rev="11-ea+23">
     35        <dependency org="org.openjfx" name="javafx-controls" rev="11-ea+25">
    3636            <artifact name="javafx-controls" type="jar" m:classifier="linux"/>
    3737            <artifact name="javafx-controls" type="jar" m:classifier="mac"/>
     
    4040            <artifact name="javafx-controls" type="jar" m:classifier="javadoc"/>
    4141        </dependency>
    42         <dependency org="org.openjfx" name="javafx-base" rev="11-ea+23">
     42        <dependency org="org.openjfx" name="javafx-base" rev="11-ea+25">
    4343            <artifact name="javafx-base" type="jar" m:classifier="linux"/>
    4444            <artifact name="javafx-base" type="jar" m:classifier="mac"/>
     
    4747            <artifact name="javafx-base" type="jar" m:classifier="javadoc"/>
    4848        </dependency>
    49         <dependency org="org.openjfx" name="javafx-graphics" rev="11-ea+23">
     49        <dependency org="org.openjfx" name="javafx-graphics" rev="11-ea+25">
    5050            <artifact name="javafx-graphics" type="jar" m:classifier="linux"/>
    5151            <artifact name="javafx-graphics" type="jar" m:classifier="mac"/>
  • applications/editors/josm/plugins/openjfx/src/org/openstreetmap/josm/plugins/openjfx/OpenJfxPlugin.java

    r34603 r34623  
    22package org.openstreetmap.josm.plugins.openjfx;
    33
     4import java.io.File;
     5import java.io.IOException;
     6import java.io.InputStream;
     7import java.net.URISyntaxException;
     8import java.nio.charset.StandardCharsets;
     9import java.nio.file.FileVisitResult;
     10import java.nio.file.Files;
     11import java.nio.file.Path;
     12import java.nio.file.Paths;
     13import java.nio.file.SimpleFileVisitor;
     14import java.nio.file.StandardCopyOption;
     15import java.nio.file.attribute.BasicFileAttributes;
     16import java.security.CodeSource;
     17import java.util.Enumeration;
     18import java.util.Objects;
     19import java.util.zip.ZipEntry;
     20import java.util.zip.ZipFile;
     21
     22import org.openstreetmap.josm.data.Preferences;
    423import org.openstreetmap.josm.io.audio.AudioPlayer;
     24import org.openstreetmap.josm.plugins.DynamicURLClassLoader;
    525import org.openstreetmap.josm.plugins.Plugin;
    626import org.openstreetmap.josm.plugins.PluginInformation;
    727import org.openstreetmap.josm.plugins.openjfx.io.audio.JavaFxMediaPlayer;
     28import org.openstreetmap.josm.tools.Logging;
     29import org.openstreetmap.josm.tools.PlatformManager;
    830
    931/**
    10  * JAXB plugin brings OpenJFX (JavaFX) to other plugins.
     32 * OpenJFX plugin brings OpenJFX (JavaFX) to other plugins.
    1133 */
    1234public class OpenJfxPlugin extends Plugin {
     
    1941        super(info);
    2042        AudioPlayer.setSoundPlayerClass(JavaFxMediaPlayer.class);
     43        String ext = null;
     44        if (PlatformManager.isPlatformWindows()) {
     45            ext = ".dll";
     46        } else if (PlatformManager.isPlatformUnixoid()) {
     47            ext = ".so";
     48        } else if (PlatformManager.isPlatformOsx()) {
     49            ext = ".dylib";
     50        }
     51        extractNativeLibs(ext);
     52        loadNativeLibs(ext);
     53    }
     54
     55    private static void extractNativeLibs(String ext) {
     56        CodeSource src = OpenJfxPlugin.class.getProtectionDomain().getCodeSource();
     57        if (src != null) {
     58            try (ZipFile zf = new ZipFile(Paths.get(src.getLocation().toURI()).toFile(), StandardCharsets.UTF_8)) {
     59                Path dir = getNativeDir();
     60                Enumeration<? extends ZipEntry> es = zf.entries();
     61                while (es.hasMoreElements()) {
     62                    ZipEntry ze = es.nextElement();
     63                    String name = ze.getName();
     64                    if (name.endsWith(ext) || name.endsWith(".jar")) {
     65                        Path targetPath = dir.resolve(name);
     66                        File targetFile = targetPath.toFile();
     67                        if (!targetFile.exists() || targetFile.lastModified() < ze.getTime()) {
     68                            try (InputStream is = zf.getInputStream(ze)) {
     69                                Logging.debug("Extracting " + targetPath);
     70                                Files.copy(is, targetPath, StandardCopyOption.REPLACE_EXISTING);
     71                            }
     72                        }
     73                    }
     74                }
     75            } catch (IOException | URISyntaxException e) {
     76                Logging.error(e);
     77            }
     78        } else {
     79            Logging.error("Unable to locate openjfx jar file");
     80        }
     81    }
     82
     83    private static Path getNativeDir() throws IOException {
     84        return Files.createDirectories(new File(Preferences.main().getPluginsDirectory(), "openjfx").toPath());
     85    }
     86
     87    private static class LibVisitor extends SimpleFileVisitor<Path> {
     88        private final ClassLoader ccl = Thread.currentThread().getContextClassLoader();
     89        private final String ext;
     90
     91        public LibVisitor(String ext) {
     92            this.ext = Objects.requireNonNull(ext);
     93        }
     94
     95        @Override
     96        public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException {
     97            if (ccl instanceof DynamicURLClassLoader) {
     98                if (file.endsWith(ext)) {
     99                    Logging.debug("Loading " + file);
     100                    System.load(file.toAbsolutePath().toString());
     101                } else if (file.endsWith(".jar")) {
     102                    Logging.debug("Loading " + file);
     103                    ((DynamicURLClassLoader) ccl).addURL(file.toUri().toURL());
     104                }
     105            } else {
     106                Logging.error("Unexpected context class loader: " + ccl);
     107                return FileVisitResult.TERMINATE;
     108            }
     109            return FileVisitResult.CONTINUE;
     110        }
     111    }
     112
     113    private void loadNativeLibs(String ext) {
     114        try {
     115            Files.walkFileTree(getNativeDir(), new LibVisitor(ext));
     116        } catch (IOException e) {
     117            Logging.error(e);
     118        }
    21119    }
    22120}
Note: See TracChangeset for help on using the changeset viewer.