// Path: src/main/java/org/jmeterplugins/repository/logging/LoggingHooker.java
// public class LoggingHooker {
//     private static final org.slf4j.Logger log = LoggerFactory.getLogger(LoggingHooker.class);
//     private final PluginManager mgr;
// 
//     public LoggingHooker(PluginManager mgr) {
//         this.mgr = mgr;
//     }
// 
//     public void hook() {
//         try {
//             if (!isJMeter32orLater()) {
//                 Logger logger = LoggerFactory.getLogger("jmeter.save.SaveService");
//                 // FIXME: what to do? logger.setLogTargets(new LogTarget[]{new LoggerPanelWrapping(mgr)});
//             } else {
//                 Class<?> cls = Class.forName("org.jmeterplugins.repository.logging.LoggerAppender");
//                 Constructor<?> constructor = cls.getConstructor(String.class, PluginManager.class);
//                 constructor.newInstance("pmgr-logging-appender", mgr);
//             }
//         } catch (Throwable ex) {
//             log.error("Cannot hook into logging", ex);
//         }
//     }
// 
//     public static boolean isJMeter32orLater() {
//         try {
//             Class<?> cls = LoggingHooker.class.getClassLoader().loadClass("org.apache.jmeter.gui.logging.GuiLogEventBus");
//             if (cls != null) {
//                 return true;
//             }
//         } catch (ClassNotFoundException ex) {
//             log.debug("Class 'org.apache.jmeter.gui.logging.GuiLogEventBus' not found", ex);
//         } catch (Throwable ex) {
//             log.warn("Fail to detect JMeter version", ex);
//         }
//         return false;
//     }
// }
// 
// Path: src/main/java/org/jmeterplugins/repository/util/ComponentFinder.java
// public class ComponentFinder<T extends Component> {
//     private static final Logger log = LoggerFactory.getLogger(ComponentFinder.class);
// 
//     private final Class<T> search;
// 
//     public ComponentFinder(Class<T> cls) {
//         search = cls;
//     }
// 
//     public T findComponentIn(Container container) {
//         log.debug("Searching in " + container);
//         for (Component a : container.getComponents()) {
//             if (search.isAssignableFrom(a.getClass())) {
//                 log.debug("Found " + a);
//                 return (T) a;
//             }
// 
//             if (a instanceof Container) {
//                 T res = findComponentIn((Container) a);
//                 if (res != null) {
//                     return res;
//                 }
//             }
//         }
// 
//         return null;
//     }
// }


import org.apache.jmeter.gui.GuiPackage;
import org.apache.jmeter.gui.MainFrame;
import org.apache.jmeter.gui.util.JMeterToolBar;
import org.jmeterplugins.repository.logging.LoggingHooker;
import org.jmeterplugins.repository.util.ComponentFinder;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.Arrays;

        new Thread("repo-downloader-thread") {
            @Override
            public void run() {
                try {
                    mgr.load();
                } catch (Throwable e) {
                    log.warn("Failed to load plugin updates info", e);
                }

                if (mgr.hasAnyUpdates()) {
                    setText("Plugins Manager (has upgrades)");
                    log.info("Plugins Manager has upgrades: " + Arrays.toString(mgr.getUpgradablePlugins().toArray()));
                }

                boolean hasAnyUpdates = mgr.hasAnyUpdates();
                setIcon(PluginIcon.getPluginsIcon(hasAnyUpdates));
                toolbarButton.setIcon(PluginIcon.getIcon22Px(hasAnyUpdates));
                toolbarButton.setToolTipText(hasAnyUpdates ?
                        "Plugins Manager (has upgrades)" :
                        "Plugins Manager"
                );
            }
        }.start();
    }

    private void addToolbarIcon(final Component toolbarButton) {
        GuiPackage instance = GuiPackage.getInstance();
        if (instance != null) {
            final MainFrame mf = instance.getMainFrame();
// Path: src/main/java/org/jmeterplugins/repository/logging/LoggingHooker.java
// public class LoggingHooker {
//     private static final org.slf4j.Logger log = LoggerFactory.getLogger(LoggingHooker.class);
//     private final PluginManager mgr;
// 
//     public LoggingHooker(PluginManager mgr) {
//         this.mgr = mgr;
//     }
// 
//     public void hook() {
//         try {
//             if (!isJMeter32orLater()) {
//                 Logger logger = LoggerFactory.getLogger("jmeter.save.SaveService");
//                 // FIXME: what to do? logger.setLogTargets(new LogTarget[]{new LoggerPanelWrapping(mgr)});
//             } else {
//                 Class<?> cls = Class.forName("org.jmeterplugins.repository.logging.LoggerAppender");
//                 Constructor<?> constructor = cls.getConstructor(String.class, PluginManager.class);
//                 constructor.newInstance("pmgr-logging-appender", mgr);
//             }
//         } catch (Throwable ex) {
//             log.error("Cannot hook into logging", ex);
//         }
//     }
// 
//     public static boolean isJMeter32orLater() {
//         try {
//             Class<?> cls = LoggingHooker.class.getClassLoader().loadClass("org.apache.jmeter.gui.logging.GuiLogEventBus");
//             if (cls != null) {
//                 return true;
//             }
//         } catch (ClassNotFoundException ex) {
//             log.debug("Class 'org.apache.jmeter.gui.logging.GuiLogEventBus' not found", ex);
//         } catch (Throwable ex) {
//             log.warn("Fail to detect JMeter version", ex);
//         }
//         return false;
//     }
// }
// 
// Path: src/main/java/org/jmeterplugins/repository/util/ComponentFinder.java
// public class ComponentFinder<T extends Component> {
//     private static final Logger log = LoggerFactory.getLogger(ComponentFinder.class);
// 
//     private final Class<T> search;
// 
//     public ComponentFinder(Class<T> cls) {
//         search = cls;
//     }
// 
//     public T findComponentIn(Container container) {
//         log.debug("Searching in " + container);
//         for (Component a : container.getComponents()) {
//             if (search.isAssignableFrom(a.getClass())) {
//                 log.debug("Found " + a);
//                 return (T) a;
//             }
// 
//             if (a instanceof Container) {
//                 T res = findComponentIn((Container) a);
//                 if (res != null) {
//                     return res;
//                 }
//             }
//         }
// 
//         return null;
//     }
// }


// Path: src/main/java/org/jmeterplugins/repository/PluginManagerMenuItem.java
import org.apache.jmeter.gui.GuiPackage;
import org.apache.jmeter.gui.MainFrame;
import org.apache.jmeter.gui.util.JMeterToolBar;
import org.jmeterplugins.repository.logging.LoggingHooker;
import org.jmeterplugins.repository.util.ComponentFinder;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.Arrays;


        new Thread("repo-downloader-thread") {
            @Override
            public void run() {
                try {
                    mgr.load();
                } catch (Throwable e) {
                    log.warn("Failed to load plugin updates info", e);
                }

                if (mgr.hasAnyUpdates()) {
                    setText("Plugins Manager (has upgrades)");
                    log.info("Plugins Manager has upgrades: " + Arrays.toString(mgr.getUpgradablePlugins().toArray()));
                }

                boolean hasAnyUpdates = mgr.hasAnyUpdates();
                setIcon(PluginIcon.getPluginsIcon(hasAnyUpdates));
                toolbarButton.setIcon(PluginIcon.getIcon22Px(hasAnyUpdates));
                toolbarButton.setToolTipText(hasAnyUpdates ?
                        "Plugins Manager (has upgrades)" :
                        "Plugins Manager"
                );
            }
        }.start();
    }

    private void addToolbarIcon(final Component toolbarButton) {
        GuiPackage instance = GuiPackage.getInstance();
        if (instance != null) {
            final MainFrame mf = instance.getMainFrame();
            final ComponentFinder<JMeterToolBar> finder = new ComponentFinder<>(JMeterToolBar.class);