Changeset 14384 in josm for trunk/src


Ignore:
Timestamp:
2018-10-29T22:24:29+01:00 (5 years ago)
Author:
Don-vip
Message:

see #16912 - introduce native and virtual plugins using new Plugin-Platform and Plugin-Provides manifest entries

Use case: javafx-windows, javafx-osx and javafx-unixoid are three native plugins providing the virtual javafx plugin on which other plugins can depend

Location:
trunk/src/org/openstreetmap/josm
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/gui/preferences/plugin/PluginCheckBox.java

    r11848 r14384  
    6363                if (!p.equals(pi) && p.requires != null && ppModel.isSelectedPlugin(p.getName())) {
    6464                    for (String s : p.getRequiredPlugins()) {
    65                         if (s.equals(pi.getName())) {
     65                        if (s.equals(pi.getName()) || s.equals(pi.provides)) {
    6666                            otherPlugins.add(p.getName());
    6767                            break;
  • trunk/src/org/openstreetmap/josm/gui/preferences/plugin/PluginPreferencesModel.java

    r13802 r14384  
    237237     */
    238238    public PluginInformation getPluginInformation(String name) {
    239         for (PluginInformation pi: availablePlugins) {
    240             if (pi.getName() != null && pi.getName().equals(name))
    241                 return pi;
     239        if (name != null) {
     240            for (PluginInformation pi: availablePlugins) {
     241                if (name.equals(pi.getName()) || name.equals(pi.provides))
     242                    return pi;
     243            }
    242244        }
    243245        return null;
  • trunk/src/org/openstreetmap/josm/plugins/PluginHandler.java

    r14327 r14384  
    607607    }
    608608
     609    private static void logWrongPlatform(String plugin, String pluginPlatform) {
     610        Logging.warn(
     611                tr("Plugin {0} must be run on a {1} platform.",
     612                        plugin, pluginPlatform
     613                ));
     614    }
     615
    609616    private static void logJavaUpdateRequired(String plugin, int requiredVersion) {
    610617        Logging.warn(
     
    640647    public static boolean checkLoadPreconditions(Component parent, Collection<PluginInformation> plugins, PluginInformation plugin) {
    641648
     649        // make sure the plugin is not meant for another platform
     650        if (!plugin.isForCurrentPlatform()) {
     651            // Just log a warning, this is unlikely to happen as we display only relevant plugins in HMI
     652            logWrongPlatform(plugin.name, plugin.platform);
     653            return false;
     654        }
     655
    642656        // make sure the plugin is compatible with the current Java version
    643657        if (plugin.localminjavaversion > Utils.getJavaVersion()) {
    644             // Just log a warning until we switch to Java 11 so that openjfx plugin does not trigger a popup
     658            // Just log a warning until we switch to Java 11 so that javafx plugin does not trigger a popup
    645659            logJavaUpdateRequired(plugin.name, plugin.localminjavaversion);
    646660            return false;
     
    686700            for (PluginInformation pi: plugins) {
    687701                pluginNames.add(pi.name);
     702                if (pi.provides != null) {
     703                    pluginNames.add(pi.provides);
     704                }
    688705            }
    689706            Set<String> missingPlugins = new HashSet<>();
  • trunk/src/org/openstreetmap/josm/plugins/PluginInformation.java

    r14378 r14384  
    3131import org.openstreetmap.josm.tools.LanguageInfo;
    3232import org.openstreetmap.josm.tools.Logging;
     33import org.openstreetmap.josm.tools.Platform;
     34import org.openstreetmap.josm.tools.PlatformManager;
    3335import org.openstreetmap.josm.tools.Utils;
    3436
     
    6264    /** The list of required plugins, separated by ';' (from locally available jar). */
    6365    public String localrequires;
     66    /** The plugin platform on which it is meant to run (windows, osx, unixoid). */
     67    public String platform;
     68    /** The virtual plugin provided by this plugin, if native for a given platform. */
     69    public String provides;
    6470    /** The plugin link (for documentation). */
    6571    public String link;
     
    169175        this.className = other.className;
    170176        this.requires = other.requires;
     177        this.provides = other.provides;
     178        this.platform = other.platform;
    171179        this.link = other.link;
    172180        this.description = other.description;
     
    216224        }
    217225        link = s;
     226        platform = attr.getValue("Plugin-Platform");
     227        provides = attr.getValue("Plugin-Provides");
    218228        requires = attr.getValue("Plugin-Requires");
    219229        s = attr.getValue(lang+"Plugin-Description");
     
    422432        Collection<String> locations = getPluginLocations();
    423433
     434        String[] nameCandidates = new String[] {
     435                pluginName,
     436                pluginName + "-" + PlatformManager.getPlatform().getPlatform().name().toLowerCase(Locale.ENGLISH)};
    424437        for (String s : locations) {
    425             File pluginFile = new File(s, pluginName + ".jar");
    426             if (pluginFile.exists()) {
    427                 return new PluginInformation(pluginFile);
     438            for (String nameCandidate: nameCandidates) {
     439                File pluginFile = new File(s, nameCandidate + ".jar");
     440                if (pluginFile.exists()) {
     441                    return new PluginInformation(pluginFile);
     442                }
    428443            }
    429444        }
     
    579594        }
    580595    }
     596
     597    /**
     598     * Determines if this plugin can be run on the current platform.
     599     * @return {@code true} if this plugin can be run on the current platform
     600     * @since 14384
     601     */
     602    public boolean isForCurrentPlatform() {
     603        try {
     604            return platform == null || PlatformManager.getPlatform().getPlatform() == Platform.valueOf(platform.toUpperCase(Locale.ENGLISH));
     605        } catch (IllegalArgumentException e) {
     606            Logging.warn(e);
     607            return true;
     608        }
     609    }
    581610}
  • trunk/src/org/openstreetmap/josm/plugins/ReadLocalPluginInformationTask.java

    r13647 r14384  
    190190    }
    191191
     192    protected void filterIrrelevantPlugins() {
     193        availablePlugins.entrySet().removeIf(e -> !e.getValue().isForCurrentPlatform());
     194    }
     195
    192196    @Override
    193197    protected void realRun() throws SAXException, IOException, OsmTransferException {
     
    207211        if (canceled) return;
    208212        filterOldPlugins();
     213        filterIrrelevantPlugins();
    209214        getProgressMonitor().worked(1);
    210215    }
  • trunk/src/org/openstreetmap/josm/plugins/ReadRemotePluginInformationTask.java

    r14149 r14384  
    2525import java.util.Optional;
    2626import java.util.Set;
     27import java.util.stream.Collectors;
    2728
    2829import javax.swing.JLabel;
     
    283284    }
    284285
     286    protected List<PluginInformation> filterIrrelevantPlugins(List<PluginInformation> plugins) {
     287        return plugins.stream().filter(PluginInformation::isForCurrentPlatform).collect(Collectors.toList());
     288    }
     289
    285290    /**
    286291     * Parses the plugin list
     
    294299            InputStream in = new ByteArrayInputStream(doc.getBytes(StandardCharsets.UTF_8));
    295300            List<PluginInformation> pis = new PluginListParser().parse(in);
    296             availablePlugins.addAll(filterDeprecatedPlugins(pis));
     301            availablePlugins.addAll(filterIrrelevantPlugins(filterDeprecatedPlugins(pis)));
    297302        } catch (PluginListParseException e) {
    298303            Logging.error(tr("Failed to parse plugin list document from site ''{0}''. Skipping site. Exception was: {1}", site, e.toString()));
Note: See TracChangeset for help on using the changeset viewer.