package org.jmeterplugins.repository;

import org.apache.jmeter.util.JMeterUtils;
import org.apache.jorphan.logging.LoggingManager;
import org.apache.log.Logger;

import javax.swing.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.IOException;

public class PluginManagerMenuItem extends JMenuItem implements ActionListener {
    private static final Logger log = LoggingManager.getLoggerForClass();
    private static PluginManagerDialog dialog;
    private final PluginManager mgr;

    public PluginManagerMenuItem() {
        super("Plugins Manager", getPluginsIcon());
        addActionListener(this);

        mgr = new PluginManager(); // don't delay startup for longer that 1 second
        try {
            mgr.load();
        } catch (IOException e) {
            log.warn("Failed to load plugin updates info", e);
        }

        if (mgr.hasAnyUpdates()) {
            setText("Plugins Manager (has upgrades)");
        }
    }

    @Override
    public void actionPerformed(ActionEvent e) {
        if (dialog == null) {
            int timeout = Integer.parseInt(JMeterUtils.getPropDefault("jpgc.repo.timeout", "5000"));
            mgr.setTimeout(timeout);
            dialog = new PluginManagerDialog(mgr);
        }

        dialog.pack();
        dialog.setVisible(true);
    }

    public static ImageIcon getPluginsIcon() {
        return new ImageIcon(PluginManagerMenuItem.class.getResource("/org/jmeterplugins/logo.png"));
    }
}

@@ -1264,32 +1264,182 @@
 gr);%0A        %7D%0A%0A
+        try %7B%0A            mgr.load();%0A        %7D catch (IOException exc) %7B%0A            log.warn(%22Failed to load plugin updates info%22, exc);%0A        %7D%0A%0A
         dialog.p

make pmgr retry repo request