Changeset 35805 in osm


Ignore:
Timestamp:
2021-08-23T01:12:53+02:00 (3 years ago)
Author:
Don-vip
Message:

see #17858 - do no longer ship Java FX through giant openjfx plugin

Location:
applications/editors/josm/plugins/javafx
Files:
3 deleted
5 edited

Legend:

Unmodified
Added
Removed
  • applications/editors/josm/plugins/javafx/README

    r34623 r35805  
    11README
    22======
    3 This plugin provides the openjfx (JavaFX) library for JOSM plugins.
     3This plugin provides openjfx (JavaFX) additional features such as MP3 audio playback.
    44    * Licensed under GPL v3 (see LICENSE)
  • applications/editors/josm/plugins/javafx/build.xml

    r35371 r35805  
    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="14234"/>
     6    <property name="plugin.main.version" value="18166"/>
    77
    88    <!-- Configure these properties (replace "..." accordingly).
     
    1010    -->
    1111    <property name="plugin.author" value="Don-vip"/>
    12     <property name="plugin.class.windows" value="org.openstreetmap.josm.plugins.javafx.JavaFxPluginWindows"/>
    13     <property name="plugin.class.unixoid" value="org.openstreetmap.josm.plugins.javafx.JavaFxPluginUnixoid"/>
    14     <property name="plugin.class.osx" value="org.openstreetmap.josm.plugins.javafx.JavaFxPluginOsx"/>
    15     <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."/>
     12    <property name="plugin.class" value="org.openstreetmap.josm.plugins.javafx.JavaFxPlugin"/>
     13    <property name="plugin.description" value="Provides additional OpenJFX (JavaFX) features such as MP3 audio playback."/>
    1614    <!--<property name="plugin.minimum.java.version" value="10"/>-->
    1715    <property name="plugin.provides" value="javafx"/>
     
    2220    <property name="plugin.stage" value="5"/>
    2321
    24     <condition property="isWindows"><os family="Windows"/></condition>
    25     <condition property="isUnix"><os family="Unix"/></condition>
    26     <condition property="isMac"><os family="Mac"/></condition>
    2722    <property name="plugin.dist.dir" location="../../dist"/>
    28     <property name="plugin.jar"      location="${plugin.dist.dir}/${ant.project.name}-windows.jar" if:set="isWindows"/>
    29     <property name="plugin.jar"      location="${plugin.dist.dir}/${ant.project.name}-osx.jar" if:set="isMac"/>
    30     <property name="plugin.jar"      location="${plugin.dist.dir}/${ant.project.name}-unixoid.jar" if:set="isUnix"/>
    3123
    3224        <!-- ** include targets that all plugins have in common ** -->
     
    3729    </target>
    3830
    39     <macrodef name="build-native-manifest">
    40         <attribute name="class"/>
    41         <attribute name="manifest"/>
    42         <attribute name="platform"/>
    43         <sequential>
    44             <copy file="MANIFEST" tofile="@{manifest}" />
    45             <manifest file="@{manifest}" mode="update">
    46                 <attribute name="Plugin-Class" value="@{class}" />
    47                 <attribute name="Plugin-Platform" value="@{platform}" />
    48             </manifest>
    49         </sequential>
    50     </macrodef>
    51 
    52     <target name="additional-manifest">
    53         <build-native-manifest platform="Windows" class="${plugin.class.windows}" manifest="${manifest.windows}"/>
    54         <build-native-manifest platform="Unixoid" class="${plugin.class.unixoid}" manifest="${manifest.unixoid}" />
    55         <build-native-manifest platform="Osx" class="${plugin.class.osx}" manifest="${manifest.osx}" />
    56     </target>
    57 
    58     <macrodef name="build-native-jar">
    59         <attribute name="jar"/>
    60         <attribute name="manifest"/>
    61         <attribute name="qualifier"/>
    62         <attribute name="copy"/>
    63         <sequential>
    64             <echo>Building @{qualifier} jar...</echo>
    65             <!-- Building the JAR file directly from javafx jar files is awfully slow,
    66                  see https://bz.apache.org/bugzilla/show_bug.cgi?id=43144 -->
    67             <mkdir dir="${plugin.lib.dir}/@{qualifier}"/>
    68             <unzip dest="${plugin.lib.dir}/@{qualifier}">
    69                 <patternset>
    70                     <exclude name="META-INF/maven/*"/>
    71                     <exclude name="META-INF/DEPENDENCIES"/>
    72                     <exclude name="META-INF/LICENSE"/>
    73                     <exclude name="META-INF/NOTICE"/>
    74                     <exclude name="META-INF/*.RSA"/>
    75                     <exclude name="META-INF/*.SF"/>
    76                     <exclude name="module-info.class"/>
    77                 </patternset>
    78                 <fileset dir="${plugin.lib.dir}">
    79                     <include name="*-@{qualifier}.jar"/>
    80                     <include name="*-monocle*.jar"/>
    81                 </fileset>
    82             </unzip>
    83             <jar destfile="@{jar}" manifest="@{manifest}" manifestencoding="UTF-8" level="9">
    84                 <fileset dir="${plugin.build.dir}"/>
    85                 <fileset dir="${plugin.lib.dir}/@{qualifier}"/>
    86             </jar>
    87             <delete dir="${plugin.lib.dir}/@{qualifier}" failonerror="false" />
    88         </sequential>
    89     </macrodef>
    90 
    9131    <target name="build-jar">
    92         <build-native-jar jar="${plugin.unixoid.jar}" manifest="${manifest.unixoid}" qualifier="linux" copy="isUnix" />
    93         <build-native-jar jar="${plugin.windows.jar}" manifest="${manifest.windows}" qualifier="win" copy="isWindows" />
    94         <build-native-jar jar="${plugin.osx.jar}" manifest="${manifest.osx}" qualifier="mac" copy="isMac" />
     32        <jar destfile="${plugin.jar}" basedir="${plugin.build.dir}" manifest="${manifest}" manifestencoding="UTF-8" duplicate="preserve" level="9"/>
    9533    </target>
    9634</project>
  • applications/editors/josm/plugins/javafx/ivy.xml

    r35655 r35805  
    66        <dependencies>
    77        <dependency org="org.testfx" name="openjfx-monocle" rev="jdk-11+26"/>
    8         <dependency org="org.openjfx" name="javafx-swing" rev="15.0.1">
     8        <dependency org="org.openjfx" name="javafx-swing" rev="16">
    99            <artifact name="javafx-swing" type="jar" m:classifier="linux"/>
    1010            <artifact name="javafx-swing" type="jar" m:classifier="mac"/>
     
    1313            <artifact name="javafx-swing" type="jar" m:classifier="javadoc"/>
    1414        </dependency>
    15         <dependency org="org.openjfx" name="javafx-fxml" rev="15.0.1">
     15        <dependency org="org.openjfx" name="javafx-fxml" rev="16">
    1616            <artifact name="javafx-fxml" type="jar" m:classifier="linux"/>
    1717            <artifact name="javafx-fxml" type="jar" m:classifier="mac"/>
     
    2020            <artifact name="javafx-fxml" type="jar" m:classifier="javadoc"/>
    2121        </dependency>
    22         <dependency org="org.openjfx" name="javafx-web" rev="15.0.1">
     22        <dependency org="org.openjfx" name="javafx-web" rev="16">
    2323            <artifact name="javafx-web" type="jar" m:classifier="linux"/>
    2424            <artifact name="javafx-web" type="jar" m:classifier="mac"/>
     
    2727            <artifact name="javafx-web" type="jar" m:classifier="javadoc"/>
    2828        </dependency>
    29         <dependency org="org.openjfx" name="javafx-media" rev="15.0.1">
     29        <dependency org="org.openjfx" name="javafx-media" rev="16">
    3030            <artifact name="javafx-media" type="jar" m:classifier="linux"/>
    3131            <artifact name="javafx-media" type="jar" m:classifier="mac"/>
     
    3434            <artifact name="javafx-media" type="jar" m:classifier="javadoc"/>
    3535        </dependency>
    36         <dependency org="org.openjfx" name="javafx-controls" rev="15.0.1">
     36        <dependency org="org.openjfx" name="javafx-controls" rev="16">
    3737            <artifact name="javafx-controls" type="jar" m:classifier="linux"/>
    3838            <artifact name="javafx-controls" type="jar" m:classifier="mac"/>
     
    4141            <artifact name="javafx-controls" type="jar" m:classifier="javadoc"/>
    4242        </dependency>
    43         <dependency org="org.openjfx" name="javafx-base" rev="15.0.1">
     43        <dependency org="org.openjfx" name="javafx-base" rev="16">
    4444            <artifact name="javafx-base" type="jar" m:classifier="linux"/>
    4545            <artifact name="javafx-base" type="jar" m:classifier="mac"/>
     
    4848            <artifact name="javafx-base" type="jar" m:classifier="javadoc"/>
    4949        </dependency>
    50         <dependency org="org.openjfx" name="javafx-graphics" rev="15.0.1">
     50        <dependency org="org.openjfx" name="javafx-graphics" rev="16">
    5151            <artifact name="javafx-graphics" type="jar" m:classifier="linux"/>
    5252            <artifact name="javafx-graphics" type="jar" m:classifier="mac"/>
  • applications/editors/josm/plugins/javafx/src/org/openstreetmap/josm/plugins/javafx/JavaFxPlugin.java

    r35371 r35805  
    33import static org.openstreetmap.josm.tools.I18n.tr;
    44
    5 import java.io.File;
    6 import java.io.IOException;
    7 import java.io.InputStream;
    8 import java.net.URISyntaxException;
    9 import java.nio.charset.StandardCharsets;
    10 import java.nio.file.FileVisitResult;
    11 import java.nio.file.Files;
    12 import java.nio.file.Path;
    13 import java.nio.file.Paths;
    14 import java.nio.file.SimpleFileVisitor;
    15 import java.nio.file.StandardCopyOption;
    16 import java.nio.file.attribute.BasicFileAttributes;
    17 import java.security.CodeSource;
    185import java.util.Collections;
    19 import java.util.Enumeration;
    20 import java.util.List;
    21 import java.util.Objects;
    22 import java.util.zip.ZipEntry;
    23 import java.util.zip.ZipFile;
    246
    25 import org.openstreetmap.josm.data.Preferences;
    267import org.openstreetmap.josm.gui.MainApplication;
    278import org.openstreetmap.josm.io.audio.AudioPlayer;
    28 import org.openstreetmap.josm.plugins.DynamicURLClassLoader;
    299import org.openstreetmap.josm.plugins.Plugin;
    3010import org.openstreetmap.josm.plugins.PluginHandler;
     
    3313import org.openstreetmap.josm.tools.Logging;
    3414import org.openstreetmap.josm.tools.PlatformManager;
    35 import org.openstreetmap.josm.tools.Utils;
    3615
    3716/**
    38  * JavaFX plugin brings OpenJFX (JavaFX) to other plugins.
     17 * JavaFX plugin brings OpenJFX (JavaFX) additional features.
    3918 */
    40 abstract class JavaFxPlugin extends Plugin {
     19public class JavaFxPlugin extends Plugin {
    4120
    4221    /**
    43      * Constructs a new {@code OpenJfxPlugin}.
     22     * Constructs a new {@code JavaFxPlugin}.
    4423     * @param info plugin info
    45      * @param ext native libraries extension
    46      * @param orderedNativeLibraries native libraries that must be loaded in this order
    4724     */
    48     protected JavaFxPlugin(PluginInformation info, String ext, List<String> orderedNativeLibraries) {
     25    protected JavaFxPlugin(PluginInformation info) {
    4926        super(info);
    50         boolean isJavaFx = Utils.getSystemProperty("javafx.runtime.version") != null || ("Oracle Corporation".equals(Utils.getSystemProperty("java.vendor")) && Utils.getJavaVersion() < 11);
    51         if (!isJavaFx && Utils.getJavaVersion() >= 10) {
    52             extractNativeLibs(ext);
    53             loadNativeLibs(ext, orderedNativeLibraries);
    54         } else if (!isJavaFx) {
     27        if (!isJavaFx()) {
    5528            Logging.error("JavaFX is not available");
    5629            StringBuilder message = new StringBuilder(tr("JavaFX is not available."));
     
    6942    }
    7043
    71     private static void extractNativeLibs(String ext) {
    72         CodeSource src = JavaFxPlugin.class.getProtectionDomain().getCodeSource();
    73         if (src != null) {
    74             try (ZipFile zf = new ZipFile(Paths.get(src.getLocation().toURI()).toFile(), StandardCharsets.UTF_8)) {
    75                 Path dir = getNativeDir();
    76                 Enumeration<? extends ZipEntry> es = zf.entries();
    77                 while (es.hasMoreElements()) {
    78                     ZipEntry ze = es.nextElement();
    79                     String name = ze.getName();
    80                     if (name.endsWith(ext) || name.endsWith(".jar")) {
    81                         Path targetPath = dir.resolve(name);
    82                         File targetFile = targetPath.toFile();
    83                         if (!targetFile.exists() || targetFile.lastModified() < ze.getTime()) {
    84                             try (InputStream is = zf.getInputStream(ze)) {
    85                                 Logging.debug("Extracting " + targetPath);
    86                                 Files.copy(is, targetPath, StandardCopyOption.REPLACE_EXISTING);
    87                             }
    88                         }
    89                     }
    90                 }
    91             } catch (IOException | URISyntaxException e) {
    92                 Logging.error(e);
    93             }
    94         } else {
    95             Logging.error("Unable to locate javafx jar file");
    96         }
    97     }
    98 
    99     private static Path getNativeDir() throws IOException {
    100         return Files.createDirectories(new File(Preferences.main().getPluginsDirectory(), "javafx").toPath());
    101     }
    102 
    103     private static class LibVisitor extends SimpleFileVisitor<Path> {
    104         private final ClassLoader ccl = Thread.currentThread().getContextClassLoader();
    105         private final String ext;
    106         private final List<String> orderedNativeLibraries;
    107 
    108         public LibVisitor(String ext, List<String> orderedNativeLibraries) {
    109             this.ext = Objects.requireNonNull(ext);
    110             this.orderedNativeLibraries = Objects.requireNonNull(orderedNativeLibraries);
    111         }
    112 
    113         @Override
    114         public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException {
    115             if (ccl instanceof DynamicURLClassLoader) {
    116                 String path = file.toAbsolutePath().toString();
    117                 if (path.endsWith(ext) && !orderedNativeLibraries.contains(file.getFileName().toString())) {
    118                     loadNativeLib(path);
    119                 } else if (path.endsWith(".jar")) {
    120                     Logging.debug("Loading {0}", path);
    121                     ((DynamicURLClassLoader) ccl).addURL(file.toUri().toURL());
    122                 }
    123             } else {
    124                 Logging.error("Unexpected context class loader: " + ccl);
    125                 return FileVisitResult.TERMINATE;
    126             }
    127             return FileVisitResult.CONTINUE;
    128         }
    129     }
    130 
    131     private static void loadNativeLib(String absolutePath) {
     44    private boolean isJavaFx() {
    13245        try {
    133             Logging.debug("Loading {0}", absolutePath);
    134             System.load(absolutePath);
    135         } catch (LinkageError e) {
    136             Logging.error(e);
    137         }
    138     }
    139 
    140     private static void loadNativeLibs(String ext, List<String> orderedNativeLibraries) {
    141         try {
    142             Path nativeDir = getNativeDir();
    143             Files.walkFileTree(nativeDir, new LibVisitor(ext, orderedNativeLibraries));
    144             for (String lib : orderedNativeLibraries) {
    145                 loadNativeLib(nativeDir.resolve(lib).toAbsolutePath().toString());
    146             }
    147         } catch (IOException e) {
    148             Logging.error(e);
     46            return Class.forName("javafx.scene.Node") != null && Class.forName("javafx.scene.media.Media") != null;
     47        } catch (ClassNotFoundException e) {
     48            Logging.trace(e);
     49            return false;
    14950        }
    15051    }
  • applications/editors/josm/plugins/javafx/src/org/openstreetmap/josm/plugins/javafx/gui/JavaFxWrapper.java

    r35492 r35805  
    101101
    102102    /**
     103     * Initializes FX
    103104     * @return The scene to be used for initializing JavaFX
    104105     */
Note: See TracChangeset for help on using the changeset viewer.