Search in sources :

Example 1 with SFPluginDetailsLoader

use of com.biglybt.pifimpl.update.sf.SFPluginDetailsLoader in project BiglyBT by BiglySoftware.

the class PluginInstallerImpl method getStandardPlugins.

@Override
public StandardPlugin[] getStandardPlugins() throws PluginException {
    try {
        SFPluginDetailsLoader loader = SFPluginDetailsLoaderFactory.getSingleton();
        SFPluginDetails[] details = loader.getPluginDetails();
        List res = new ArrayList();
        for (int i = 0; i < details.length; i++) {
            SFPluginDetails detail = details[i];
            String name = detail.getId();
            String version = "";
            if (Constants.isCVSVersion()) {
                version = detail.getCVSVersion();
            }
            if (version == null || version.length() == 0 || !Character.isDigit(version.charAt(0))) {
                version = detail.getVersion();
            } else {
                // if cvs version and non-cvs version are the same then show the
                // non-cvs version
                String non_cvs_version = detail.getVersion();
                if (version.equals(non_cvs_version + "_CVS")) {
                    version = non_cvs_version;
                }
            }
            if (name.startsWith("azplatform") || name.equals("azupdater")) {
            // skip built in ones we don't want to let user install directly
            // not the cleanest of fixes, but it'll do for the moment
            } else if (version == null || version.length() == 0 || !Character.isDigit(version.charAt(0))) {
            // dodgy version
            } else if (detail.getCategory().equalsIgnoreCase("hidden")) {
            // not public
            } else {
                res.add(new StandardPluginImpl(this, details[i], version));
            }
        }
        StandardPlugin[] res_a = new StandardPlugin[res.size()];
        res.toArray(res_a);
        return (res_a);
    } catch (SFPluginDetailsException e) {
        throw (new PluginException("Failed to load standard plugin details", e));
    }
}
Also used : SFPluginDetailsException(com.biglybt.pifimpl.update.sf.SFPluginDetailsException) SFPluginDetails(com.biglybt.pifimpl.update.sf.SFPluginDetails) SFPluginDetailsLoader(com.biglybt.pifimpl.update.sf.SFPluginDetailsLoader)

Example 2 with SFPluginDetailsLoader

use of com.biglybt.pifimpl.update.sf.SFPluginDetailsLoader in project BiglyBT by BiglySoftware.

the class PluginInstallerImpl method getStandardPlugin.

@Override
public StandardPlugin getStandardPlugin(String id) throws PluginException {
    try {
        SFPluginDetailsLoader loader = SFPluginDetailsLoaderFactory.getSingleton();
        SFPluginDetails[] details = loader.getPluginDetails();
        for (int i = 0; i < details.length; i++) {
            SFPluginDetails detail = details[i];
            String name = detail.getId();
            if (name.equalsIgnoreCase(id)) {
                String version = "";
                if (Constants.isCVSVersion()) {
                    version = detail.getCVSVersion();
                }
                if (version == null || version.length() == 0 || !Character.isDigit(version.charAt(0))) {
                    version = detail.getVersion();
                } else {
                    // if cvs version and non-cvs version are the same then show the
                    // non-cvs version
                    String non_cvs_version = detail.getVersion();
                    if (version.equals(non_cvs_version + "_CVS")) {
                        version = non_cvs_version;
                    }
                }
                if (name.startsWith("azplatform") || name.equals("azupdater")) {
                // skip built in ones we don't want to let user install directly
                // not the cleanest of fixes, but it'll do for the moment
                } else if (version == null || version.length() == 0 || !Character.isDigit(version.charAt(0))) {
                // dodgy version
                } else {
                    return (new StandardPluginImpl(this, details[i], version));
                }
            }
        }
        return (null);
    } catch (SFPluginDetailsException e) {
        throw (new PluginException("Failed to load standard plugin details", e));
    }
}
Also used : SFPluginDetailsException(com.biglybt.pifimpl.update.sf.SFPluginDetailsException) SFPluginDetails(com.biglybt.pifimpl.update.sf.SFPluginDetails) SFPluginDetailsLoader(com.biglybt.pifimpl.update.sf.SFPluginDetailsLoader)

Example 3 with SFPluginDetailsLoader

use of com.biglybt.pifimpl.update.sf.SFPluginDetailsLoader in project BiglyBT by BiglySoftware.

the class PluginUpdatePlugin method checkForUpdateSupport.

protected int checkForUpdateSupport(UpdateChecker checker, // explicit ids or null for all
String[] ids_to_check, boolean mandatory) {
    int num_updates_found = 0;
    try {
        if ((!mandatory) && // allow custom actions through
        (ids_to_check == null) && (!plugin_interface.getPluginconfig().getPluginBooleanParameter("enable.update", true))) {
            return (num_updates_found);
        }
        PluginInterface[] plugins = plugin_interface.getPluginManager().getPlugins();
        List plugins_to_check = new ArrayList();
        List plugins_to_check_ids = new ArrayList();
        Map plugins_to_check_names = new HashMap();
        for (int i = 0; i < plugins.length; i++) {
            PluginInterface pi = plugins[i];
            if (pi.getPluginState().isDisabled()) {
                if (!pi.getPluginState().hasFailed()) {
                    continue;
                }
            }
            String mand = pi.getPluginProperties().getProperty("plugin.mandatory");
            boolean pi_mandatory = mand != null && mand.trim().toLowerCase().equals("true");
            if (pi_mandatory != mandatory) {
                continue;
            }
            String id = pi.getPluginID();
            String version = pi.getPluginVersion();
            String name = pi.getPluginName();
            if (ids_to_check != null) {
                boolean id_selected = false;
                for (int j = 0; j < ids_to_check.length; j++) {
                    if (ids_to_check[j].equals(id)) {
                        id_selected = true;
                        break;
                    }
                }
                if (!id_selected) {
                    continue;
                }
            }
            if (version != null) {
                if (plugins_to_check_ids.contains(id)) {
                    String s = (String) plugins_to_check_names.get(id);
                    if (!name.equals(id)) {
                        plugins_to_check_names.put(id, s + "," + name);
                    }
                } else {
                    plugins_to_check_ids.add(id);
                    plugins_to_check.add(pi);
                    plugins_to_check_names.put(id, name.equals(id) ? "" : name);
                }
            }
            String location = pi.getPluginDirectoryName();
            log.log(LoggerChannel.LT_INFORMATION, (mandatory ? "*" : "-") + pi.getPluginName() + ", id = " + id + (version == null ? "" : (", version = " + pi.getPluginVersion())) + (location == null ? "" : (", loc = " + location)));
        }
        SFPluginDetailsLoader loader = SFPluginDetailsLoaderFactory.getSingleton();
        if (!loader_listener_added) {
            loader_listener_added = true;
            loader.addListener(new SFPluginDetailsLoaderListener() {

                @Override
                public void log(String str) {
                    log.log(LoggerChannel.LT_INFORMATION, "[" + str + "]");
                }
            });
        }
        String[] ids = loader.getPluginIDs();
        String id_info = "";
        for (int i = 0; i < ids.length; i++) {
            String id = ids[i];
            SFPluginDetails details = loader.getPluginDetails(id);
            id_info += (i == 0 ? "" : ",") + ids[i] + "=" + details.getVersion() + "/" + details.getCVSVersion();
        }
        if (!id_info.equals(last_id_info)) {
            last_id_info = id_info;
            log.log(LoggerChannel.LT_INFORMATION, "Downloaded plugin info = " + id_info);
        }
        for (int i = 0; i < plugins_to_check.size(); i++) {
            if (checker.getCheckInstance().isCancelled()) {
                // XXX: Uh?
                throw (new Exception("Update check cancelled"));
            }
            final PluginInterface pi_being_checked = (PluginInterface) plugins_to_check.get(i);
            final String plugin_id = pi_being_checked.getPluginID();
            boolean found = false;
            for (int j = 0; j < ids.length; j++) {
                if (ids[j].equalsIgnoreCase(plugin_id)) {
                    found = true;
                    break;
                }
            }
            if (!found) {
                if (!pi_being_checked.getPluginState().isBuiltIn()) {
                    log.log(LoggerChannel.LT_INFORMATION, "Skipping " + plugin_id + " as not listed on web site");
                }
                continue;
            }
            String plugin_names = (String) plugins_to_check_names.get(plugin_id);
            // final boolean	plugin_unloadable 	= ((Boolean)plugins_to_check_unloadable.get( plugin_id )).booleanValue();
            log.log(LoggerChannel.LT_INFORMATION, "Checking " + plugin_id);
            try {
                checker.reportProgress("Loading details for " + plugin_id + "/" + pi_being_checked.getPluginName());
                SFPluginDetails details = loader.getPluginDetails(plugin_id);
                if (plugin_names.length() == 0) {
                    plugin_names = details.getName();
                }
                boolean az_cvs = plugin_interface.getUtilities().isCVSVersion();
                String pi_version_info = pi_being_checked.getPluginProperties().getProperty("plugin.version.info");
                String az_plugin_version = pi_being_checked.getPluginVersion();
                String sf_plugin_version = details.getVersion();
                String sf_comp_version = sf_plugin_version;
                if (az_cvs) {
                    String sf_cvs_version = details.getCVSVersion();
                    if (sf_cvs_version.length() > 0) {
                        // sf cvs version ALWAYS ends in _CVS
                        sf_plugin_version = sf_cvs_version;
                        sf_comp_version = sf_plugin_version.substring(0, sf_plugin_version.length() - 4);
                    }
                }
                if (sf_comp_version.length() == 0 || !Character.isDigit(sf_comp_version.charAt(0))) {
                    log.log(LoggerChannel.LT_INFORMATION, "Skipping " + plugin_id + " as no valid version to check");
                    continue;
                }
                // System.out.println("comp version = " + sf_comp_version );
                int comp = PluginUtils.comparePluginVersions(az_plugin_version, sf_comp_version);
                // if they're the same version and latest is CVS then stick a _CVS on
                // the end of current to avoid confusion
                log.log(LoggerChannel.LT_INFORMATION, "Plugin: " + plugin_id + " versions (current=" + az_plugin_version + (comp == 0 && sf_plugin_version.endsWith("_CVS") ? "_CVS" : "") + ", latest=" + sf_plugin_version + (pi_version_info == null ? "" : " [" + pi_version_info + "]") + ")");
                checker.reportProgress("Plugin: " + plugin_id + "versions (current=" + az_plugin_version + (comp == 0 && sf_plugin_version.endsWith("_CVS") ? "_CVS" : "") + ", latest=" + sf_plugin_version + ")");
                if (comp < 0 && !(pi_being_checked.getPlugin() instanceof UpdatableComponent)) {
                    // only update if newer version + plugin itself doesn't handle
                    // the update
                    String sf_plugin_download = details.getDownloadURL();
                    if (az_cvs) {
                        String sf_cvs_version = details.getCVSVersion();
                        if (sf_cvs_version.length() > 0) {
                            sf_plugin_download = details.getCVSDownloadURL();
                        }
                    }
                    log.log(LoggerChannel.LT_INFORMATION, "    Description:");
                    List update_desc = new ArrayList();
                    List desc_lines = HTMLUtils.convertHTMLToText("", details.getDescription());
                    logMultiLine("        ", desc_lines);
                    update_desc.addAll(desc_lines);
                    log.log(LoggerChannel.LT_INFORMATION, "    Comment:");
                    List comment_lines = HTMLUtils.convertHTMLToText("    ", details.getComment());
                    logMultiLine("    ", comment_lines);
                    update_desc.addAll(comment_lines);
                    String msg = "A newer version (version " + sf_plugin_version + ") of plugin '" + plugin_id + "' " + (plugin_names.length() == 0 ? "" : "(" + plugin_names + ") ") + "is available. ";
                    log.log(LoggerChannel.LT_INFORMATION, "");
                    log.log(LoggerChannel.LT_INFORMATION, "        " + msg + "Download from " + sf_plugin_download);
                    ResourceDownloaderFactory rdf = plugin_interface.getUtilities().getResourceDownloaderFactory();
                    ResourceDownloader direct_rdl = rdf.create(new URL(sf_plugin_download));
                    ResourceDownloader direct_ap_rdl = rdf.createWithAutoPluginProxy(new URL(sf_plugin_download));
                    // work out what the torrent download will be, if it exists
                    // sf_plugin_download will be something like ../plugins/safepeer_2.4.zip
                    // torrent is safepeer_2.4.zip.torrent
                    String torrent_download = Constants.URL_PLUGINS_TORRENT_BASE;
                    int slash_pos = sf_plugin_download.lastIndexOf("/");
                    if (slash_pos == -1) {
                        torrent_download += sf_plugin_download;
                    } else {
                        torrent_download += sf_plugin_download.substring(slash_pos + 1);
                    }
                    torrent_download += ".torrent";
                    if (I2PHelpers.isI2PInstalled()) {
                        torrent_download += "?i2p=1";
                    }
                    ResourceDownloader torrent_rdl = rdf.create(new URL(torrent_download));
                    // ResourceDownloader torrent_ap_rdl 	= rdf.createWithAutoPluginProxy( new URL( torrent_download ));
                    torrent_rdl = rdf.getSuffixBasedDownloader(torrent_rdl);
                    // create an alternate downloader with torrent attempt first
                    ResourceDownloader alternate_rdl = rdf.getAlternateDownloader(new ResourceDownloader[] { torrent_rdl, direct_rdl, direct_ap_rdl });
                    // get size so it is cached
                    rdf.getTimeoutDownloader(rdf.getRetryDownloader(alternate_rdl, RD_SIZE_RETRIES), RD_SIZE_TIMEOUT).getSize();
                    String[] update_d = new String[update_desc.size()];
                    update_desc.toArray(update_d);
                    num_updates_found++;
                    // see if unloadable
                    boolean plugin_unloadable = true;
                    for (int j = 0; j < plugins.length; j++) {
                        PluginInterface pi = plugins[j];
                        if (pi.getPluginID().equals(plugin_id)) {
                            plugin_unloadable &= pi.getPluginState().isUnloadable();
                        }
                    }
                    if (plugin_unloadable) {
                        checker.reportProgress("Plugin is unloadable");
                    }
                    Update update = addUpdate(pi_being_checked, checker, plugin_id + "/" + plugin_names, update_d, az_plugin_version, sf_plugin_version, alternate_rdl, sf_plugin_download.toLowerCase().endsWith(".jar"), plugin_unloadable ? Update.RESTART_REQUIRED_NO : Update.RESTART_REQUIRED_YES, true);
                    update.setRelativeURLBase(details.getRelativeURLBase());
                    update.setDescriptionURL(details.getInfoURL());
                }
            } catch (Throwable e) {
                checker.reportProgress("Failed to load details for plugin '" + plugin_id + "': " + Debug.getNestedExceptionMessage(e));
                log.log("    Plugin check failed", e);
            }
        }
    } catch (Throwable e) {
        if (!"Update check cancelled".equals(e.getMessage())) {
            log.log("Failed to load plugin details", e);
        }
        checker.reportProgress("Failed to load plugin details: " + Debug.getNestedExceptionMessage(e));
        checker.setFailed(new Exception("Failed to load plugin details", e));
    } finally {
        // any prior failure will take precedence
        checker.completed();
    }
    return (num_updates_found);
}
Also used : SFPluginDetailsLoaderListener(com.biglybt.pifimpl.update.sf.SFPluginDetailsLoaderListener) ResourceDownloader(com.biglybt.pif.utils.resourcedownloader.ResourceDownloader) ResourceDownloaderException(com.biglybt.pif.utils.resourcedownloader.ResourceDownloaderException) URL(java.net.URL) ResourceDownloaderFactory(com.biglybt.pif.utils.resourcedownloader.ResourceDownloaderFactory) SFPluginDetails(com.biglybt.pifimpl.update.sf.SFPluginDetails) SFPluginDetailsLoader(com.biglybt.pifimpl.update.sf.SFPluginDetailsLoader)

Aggregations

SFPluginDetails (com.biglybt.pifimpl.update.sf.SFPluginDetails)3 SFPluginDetailsLoader (com.biglybt.pifimpl.update.sf.SFPluginDetailsLoader)3 SFPluginDetailsException (com.biglybt.pifimpl.update.sf.SFPluginDetailsException)2 ResourceDownloader (com.biglybt.pif.utils.resourcedownloader.ResourceDownloader)1 ResourceDownloaderException (com.biglybt.pif.utils.resourcedownloader.ResourceDownloaderException)1 ResourceDownloaderFactory (com.biglybt.pif.utils.resourcedownloader.ResourceDownloaderFactory)1 SFPluginDetailsLoaderListener (com.biglybt.pifimpl.update.sf.SFPluginDetailsLoaderListener)1 URL (java.net.URL)1