Search in sources :

Example 1 with Plugin

use of edu.umd.cs.findbugs.Plugin in project spotbugs by spotbugs.

the class BugInfoView method addDetectorInfo.

private void addDetectorInfo(StringBuilder text) {
    DetectorFactory factory = bug.getDetectorFactory();
    if (factory != null) {
        Plugin plugin = factory.getPlugin();
        if (!plugin.isCorePlugin()) {
            text.append("<p><small><i>Reported by: ").append(factory.getFullName());
            text.append("<br>Contributed by plugin: ").append(plugin.getPluginId());
            text.append("<br>Provider: ").append(plugin.getProvider());
            String website = plugin.getWebsite();
            if (website != null && website.length() > 0) {
                text.append(" (<a href=\"").append(website).append("\">");
                text.append(website).append("</a>)");
            }
            text.append("</i></small>");
        }
    }
}
Also used : DetectorFactory(edu.umd.cs.findbugs.DetectorFactory) FindbugsPlugin(de.tobject.findbugs.FindbugsPlugin) Plugin(edu.umd.cs.findbugs.Plugin)

Example 2 with Plugin

use of edu.umd.cs.findbugs.Plugin in project spotbugs by spotbugs.

the class GenerateUpdateXml method main.

public static void main(String[] args) {
    FindBugs.setNoAnalysis();
    DetectorFactoryCollection dfc = DetectorFactoryCollection.instance();
    for (Plugin p : dfc.plugins()) {
        System.out.println(p.getPluginId());
        System.out.println(p.getReleaseDate());
        System.out.println(p.getVersion());
        System.out.println();
    }
}
Also used : DetectorFactoryCollection(edu.umd.cs.findbugs.DetectorFactoryCollection) Plugin(edu.umd.cs.findbugs.Plugin)

Example 3 with Plugin

use of edu.umd.cs.findbugs.Plugin in project spotbugs by spotbugs.

the class FB method main.

public static void main(String[] args) throws Throwable {
    String cmd;
    String[] a;
    if (args.length == 0) {
        cmd = "help";
        a = new String[0];
    } else {
        cmd = args[0];
        a = new String[args.length - 1];
        for (int i = 1; i < args.length; i++) {
            a[i - 1] = args[i];
        }
    }
    DetectorFactoryCollection.instance();
    for (Plugin plugin : Plugin.getAllPlugins()) {
        FindBugsMain main = plugin.getFindBugsMain(cmd);
        if (main != null) {
            try {
                main.invoke(a);
            } catch (java.lang.reflect.InvocationTargetException e) {
                throw e.getCause();
            }
            return;
        }
    }
    throw new IllegalArgumentException("Unable to find FindBugs main for " + cmd);
}
Also used : FindBugsMain(edu.umd.cs.findbugs.FindBugsMain) Plugin(edu.umd.cs.findbugs.Plugin)

Example 4 with Plugin

use of edu.umd.cs.findbugs.Plugin in project spotbugs by spotbugs.

the class DetectorProvider method getPluginElements.

/**
 * The complexity of the code below is partly caused by the fact that we
 * might have multiple ways to install and/or enable custom plugins. There
 * are plugins discovered by FB itself, plugins contributed to Eclipse and
 * plugins added by user manually via properties. Plugins can be disabled
 * via code or properties. The code below is still work in progress, see
 * also {@link FindbugsPlugin#applyCustomDetectors(boolean)}.
 *
 * @return a list with all known plugin paths known by FindBugs (they must
 *         neither be valid nor exists).
 */
public static List<IPathElement> getPluginElements(UserPreferences userPreferences) {
    DetectorValidator validator = new DetectorValidator();
    final List<IPathElement> newPaths = new ArrayList<>();
    Map<String, Boolean> pluginPaths = userPreferences.getCustomPlugins();
    Set<String> disabledSystemPlugins = new HashSet<>();
    Set<URI> customPlugins = new HashSet<>();
    Set<Entry<String, Boolean>> entrySet = pluginPaths.entrySet();
    for (Entry<String, Boolean> entry : entrySet) {
        String idOrPath = entry.getKey();
        if (new Path(idOrPath).segmentCount() == 1) {
            PathElement element = new PathElement(new Path(idOrPath), Status.OK_STATUS);
            element.setSystem(true);
            if (!entry.getValue().booleanValue()) {
                element.setEnabled(false);
                // this is not a path => this is a disabled plugin id
                disabledSystemPlugins.add(idOrPath);
                newPaths.add(element);
            } else {
                element.setEnabled(true);
            }
            continue;
        }
        // project is not supported (propertyPage.getProject() == null for workspace prefs).
        IPath pluginPath = FindBugsWorker.getFilterPath(idOrPath, null);
        URI uri = pluginPath.toFile().toURI();
        customPlugins.add(uri);
        ValidationStatus status = validator.validate(pluginPath.toOSString());
        PathElement element = new PathElement(pluginPath, status);
        Plugin plugin = Plugin.getByPluginId(status.getSummary().id);
        if (plugin != null && !uri.equals(plugin.getPluginLoader().getURI())) {
            // disable contribution if the plugin is already there
            // but loaded from different location
            element.setEnabled(false);
        } else {
            element.setEnabled(entry.getValue().booleanValue());
        }
        newPaths.add(element);
    }
    Map<URI, Plugin> allPlugins = Plugin.getAllPluginsMap();
    // List of plugins contributed by Eclipse
    SortedMap<String, String> contributedDetectors = DetectorsExtensionHelper.getContributedDetectors();
    for (Entry<String, String> entry : contributedDetectors.entrySet()) {
        String pluginId = entry.getKey();
        URI uri = new Path(entry.getValue()).toFile().toURI();
        Plugin plugin = allPlugins.get(uri);
        if (plugin != null && !isEclipsePluginDisabled(pluginId, allPlugins)) {
            PluginElement element = new PluginElement(plugin, true);
            newPaths.add(0, element);
            customPlugins.add(uri);
        }
    }
    // Remaining plugins contributed by FB itself
    for (Plugin plugin : allPlugins.values()) {
        PluginElement element = new PluginElement(plugin, false);
        if (!customPlugins.contains(plugin.getPluginLoader().getURI())) {
            newPaths.add(0, element);
            if (disabledSystemPlugins.contains(plugin.getPluginId())) {
                element.setEnabled(false);
            }
        }
    }
    return newPaths;
}
Also used : IPath(org.eclipse.core.runtime.IPath) Path(org.eclipse.core.runtime.Path) IPath(org.eclipse.core.runtime.IPath) ArrayList(java.util.ArrayList) URI(java.net.URI) ValidationStatus(de.tobject.findbugs.properties.DetectorValidator.ValidationStatus) Entry(java.util.Map.Entry) HashSet(java.util.HashSet) Plugin(edu.umd.cs.findbugs.Plugin) FindbugsPlugin(de.tobject.findbugs.FindbugsPlugin)

Example 5 with Plugin

use of edu.umd.cs.findbugs.Plugin in project spotbugs by spotbugs.

the class DetectorValidator method validate.

/**
 * @param path
 *            non null, full abstract path in the local file system
 * @return {@link Status#OK_STATUS} in case that given path might be a valid
 *         FindBugs detector package (jar file containing bugrank.txt,
 *         findbugs.xml, messages.xml and at least one class file). Returns
 *         error status in case anything goes wrong or file at given path is
 *         not considered as a valid plugin.
 */
@Nonnull
public ValidationStatus validate(String path) {
    File file = new File(path);
    Summary sum = null;
    try {
        sum = PluginLoader.validate(file);
    } catch (IllegalArgumentException e) {
        if (FindbugsPlugin.getDefault().isDebugging()) {
            e.printStackTrace();
        }
        return new ValidationStatus(IStatus.ERROR, "Invalid SpotBugs plugin archive: " + e.getMessage(), sum, e);
    }
    Plugin loadedPlugin = Plugin.getByPluginId(sum.id);
    URI uri = file.toURI();
    if (loadedPlugin != null && !uri.equals(loadedPlugin.getPluginLoader().getURI()) && loadedPlugin.isGloballyEnabled()) {
        return new ValidationStatus(IStatus.ERROR, "Duplicated SpotBugs plugin: " + sum.id + ", already loaded from: " + loadedPlugin.getPluginLoader().getURI(), sum, null);
    }
    return new ValidationStatus(IStatus.OK, Status.OK_STATUS.getMessage(), sum, null);
}
Also used : Summary(edu.umd.cs.findbugs.PluginLoader.Summary) File(java.io.File) URI(java.net.URI) FindbugsPlugin(de.tobject.findbugs.FindbugsPlugin) Plugin(edu.umd.cs.findbugs.Plugin) Nonnull(javax.annotation.Nonnull)

Aggregations

Plugin (edu.umd.cs.findbugs.Plugin)18 File (java.io.File)6 FindbugsPlugin (de.tobject.findbugs.FindbugsPlugin)5 DetectorFactoryCollection (edu.umd.cs.findbugs.DetectorFactoryCollection)4 PluginException (edu.umd.cs.findbugs.PluginException)4 DetectorFactory (edu.umd.cs.findbugs.DetectorFactory)3 Project (edu.umd.cs.findbugs.Project)3 DuplicatePluginIdException (edu.umd.cs.findbugs.plugins.DuplicatePluginIdException)3 URI (java.net.URI)3 URL (java.net.URL)3 ValidationStatus (de.tobject.findbugs.properties.DetectorValidator.ValidationStatus)2 UserPreferences (edu.umd.cs.findbugs.config.UserPreferences)2 IOException (java.io.IOException)2 MalformedURLException (java.net.MalformedURLException)2 URISyntaxException (java.net.URISyntaxException)2 ArrayList (java.util.ArrayList)2 HashSet (java.util.HashSet)2 EmptyBorder (javax.swing.border.EmptyBorder)2 ResourcesPlugin (org.eclipse.core.resources.ResourcesPlugin)2 AbstractUIPlugin (org.eclipse.ui.plugin.AbstractUIPlugin)2