Changeset 35805 in osm
- Timestamp:
- 2021-08-23T01:12:53+02:00 (4 years ago)
- Location:
- applications/editors/josm/plugins/javafx
- Files:
-
- 3 deleted
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/javafx/README
r34623 r35805 1 1 README 2 2 ====== 3 This plugin provides theopenjfx (JavaFX)library for JOSM plugins.3 This plugin provides openjfx (JavaFX) additional features such as MP3 audio playback. 4 4 * Licensed under GPL v3 (see LICENSE) -
applications/editors/josm/plugins/javafx/build.xml
r35371 r35805 4 4 <property name="commit.message" value="Commit message"/> 5 5 <!-- enter the *lowest* JOSM version this plugin is currently compatible with --> 6 <property name="plugin.main.version" value="1 4234"/>6 <property name="plugin.main.version" value="18166"/> 7 7 8 8 <!-- Configure these properties (replace "..." accordingly). … … 10 10 --> 11 11 <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."/> 16 14 <!--<property name="plugin.minimum.java.version" value="10"/>--> 17 15 <property name="plugin.provides" value="javafx"/> … … 22 20 <property name="plugin.stage" value="5"/> 23 21 24 <condition property="isWindows"><os family="Windows"/></condition>25 <condition property="isUnix"><os family="Unix"/></condition>26 <condition property="isMac"><os family="Mac"/></condition>27 22 <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"/>31 23 32 24 <!-- ** include targets that all plugins have in common ** --> … … 37 29 </target> 38 30 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 91 31 <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"/> 95 33 </target> 96 34 </project> -
applications/editors/josm/plugins/javafx/ivy.xml
r35655 r35805 6 6 <dependencies> 7 7 <dependency org="org.testfx" name="openjfx-monocle" rev="jdk-11+26"/> 8 <dependency org="org.openjfx" name="javafx-swing" rev="1 5.0.1">8 <dependency org="org.openjfx" name="javafx-swing" rev="16"> 9 9 <artifact name="javafx-swing" type="jar" m:classifier="linux"/> 10 10 <artifact name="javafx-swing" type="jar" m:classifier="mac"/> … … 13 13 <artifact name="javafx-swing" type="jar" m:classifier="javadoc"/> 14 14 </dependency> 15 <dependency org="org.openjfx" name="javafx-fxml" rev="1 5.0.1">15 <dependency org="org.openjfx" name="javafx-fxml" rev="16"> 16 16 <artifact name="javafx-fxml" type="jar" m:classifier="linux"/> 17 17 <artifact name="javafx-fxml" type="jar" m:classifier="mac"/> … … 20 20 <artifact name="javafx-fxml" type="jar" m:classifier="javadoc"/> 21 21 </dependency> 22 <dependency org="org.openjfx" name="javafx-web" rev="1 5.0.1">22 <dependency org="org.openjfx" name="javafx-web" rev="16"> 23 23 <artifact name="javafx-web" type="jar" m:classifier="linux"/> 24 24 <artifact name="javafx-web" type="jar" m:classifier="mac"/> … … 27 27 <artifact name="javafx-web" type="jar" m:classifier="javadoc"/> 28 28 </dependency> 29 <dependency org="org.openjfx" name="javafx-media" rev="1 5.0.1">29 <dependency org="org.openjfx" name="javafx-media" rev="16"> 30 30 <artifact name="javafx-media" type="jar" m:classifier="linux"/> 31 31 <artifact name="javafx-media" type="jar" m:classifier="mac"/> … … 34 34 <artifact name="javafx-media" type="jar" m:classifier="javadoc"/> 35 35 </dependency> 36 <dependency org="org.openjfx" name="javafx-controls" rev="1 5.0.1">36 <dependency org="org.openjfx" name="javafx-controls" rev="16"> 37 37 <artifact name="javafx-controls" type="jar" m:classifier="linux"/> 38 38 <artifact name="javafx-controls" type="jar" m:classifier="mac"/> … … 41 41 <artifact name="javafx-controls" type="jar" m:classifier="javadoc"/> 42 42 </dependency> 43 <dependency org="org.openjfx" name="javafx-base" rev="1 5.0.1">43 <dependency org="org.openjfx" name="javafx-base" rev="16"> 44 44 <artifact name="javafx-base" type="jar" m:classifier="linux"/> 45 45 <artifact name="javafx-base" type="jar" m:classifier="mac"/> … … 48 48 <artifact name="javafx-base" type="jar" m:classifier="javadoc"/> 49 49 </dependency> 50 <dependency org="org.openjfx" name="javafx-graphics" rev="1 5.0.1">50 <dependency org="org.openjfx" name="javafx-graphics" rev="16"> 51 51 <artifact name="javafx-graphics" type="jar" m:classifier="linux"/> 52 52 <artifact name="javafx-graphics" type="jar" m:classifier="mac"/> -
applications/editors/josm/plugins/javafx/src/org/openstreetmap/josm/plugins/javafx/JavaFxPlugin.java
r35371 r35805 3 3 import static org.openstreetmap.josm.tools.I18n.tr; 4 4 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;18 5 import 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;24 6 25 import org.openstreetmap.josm.data.Preferences;26 7 import org.openstreetmap.josm.gui.MainApplication; 27 8 import org.openstreetmap.josm.io.audio.AudioPlayer; 28 import org.openstreetmap.josm.plugins.DynamicURLClassLoader;29 9 import org.openstreetmap.josm.plugins.Plugin; 30 10 import org.openstreetmap.josm.plugins.PluginHandler; … … 33 13 import org.openstreetmap.josm.tools.Logging; 34 14 import org.openstreetmap.josm.tools.PlatformManager; 35 import org.openstreetmap.josm.tools.Utils;36 15 37 16 /** 38 * JavaFX plugin brings OpenJFX (JavaFX) to other plugins.17 * JavaFX plugin brings OpenJFX (JavaFX) additional features. 39 18 */ 40 abstractclass JavaFxPlugin extends Plugin {19 public class JavaFxPlugin extends Plugin { 41 20 42 21 /** 43 * Constructs a new {@code OpenJfxPlugin}.22 * Constructs a new {@code JavaFxPlugin}. 44 23 * @param info plugin info 45 * @param ext native libraries extension46 * @param orderedNativeLibraries native libraries that must be loaded in this order47 24 */ 48 protected JavaFxPlugin(PluginInformation info , String ext, List<String> orderedNativeLibraries) {25 protected JavaFxPlugin(PluginInformation info) { 49 26 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()) { 55 28 Logging.error("JavaFX is not available"); 56 29 StringBuilder message = new StringBuilder(tr("JavaFX is not available.")); … … 69 42 } 70 43 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() { 132 45 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; 149 50 } 150 51 } -
applications/editors/josm/plugins/javafx/src/org/openstreetmap/josm/plugins/javafx/gui/JavaFxWrapper.java
r35492 r35805 101 101 102 102 /** 103 * Initializes FX 103 104 * @return The scene to be used for initializing JavaFX 104 105 */
Note:
See TracChangeset
for help on using the changeset viewer.