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>");
}
}
}
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();
}
}
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);
}
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;
}
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);
}
Aggregations