Search in sources :

Example 1 with DetectorFactoryCollection

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

the class PlaceholderTest method setup.

@Before
public void setup() {
    Project project = new Project();
    reporter = new SarifBugReporter(project);
    writer = new StringWriter();
    reporter.setWriter(new PrintWriter(writer));
    reporter.setPriorityThreshold(Priorities.IGNORE_PRIORITY);
    DetectorFactoryCollection.resetInstance(new DetectorFactoryCollection());
    IAnalysisCache analysisCache = ClassFactory.instance().createAnalysisCache(new ClassPathImpl(), reporter);
    Global.setAnalysisCacheForCurrentThread(analysisCache);
    FindBugs2.registerBuiltInAnalysisEngines(analysisCache);
    AnalysisContext analysisContext = new AnalysisContext(project) {

        public boolean isApplicationClass(@DottedClassName String className) {
            // treat all classes as application class, to report bugs in it
            return true;
        }
    };
    AnalysisContext.setCurrentAnalysisContext(analysisContext);
}
Also used : Project(edu.umd.cs.findbugs.Project) StringWriter(java.io.StringWriter) ClassPathImpl(edu.umd.cs.findbugs.classfile.impl.ClassPathImpl) IAnalysisCache(edu.umd.cs.findbugs.classfile.IAnalysisCache) AnalysisContext(edu.umd.cs.findbugs.ba.AnalysisContext) PrintWriter(java.io.PrintWriter) DetectorFactoryCollection(edu.umd.cs.findbugs.DetectorFactoryCollection) DottedClassName(edu.umd.cs.findbugs.internalAnnotations.DottedClassName) Before(org.junit.Before)

Example 2 with DetectorFactoryCollection

use of edu.umd.cs.findbugs.DetectorFactoryCollection 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 DetectorFactoryCollection

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

the class PrintBugDescriptions method print.

public void print() throws IOException {
    // Ensure bug patterns are loaded
    DetectorFactoryCollection factories = DetectorFactoryCollection.instance();
    // Find all bug patterns reported by at least one non-disabled detector.
    Collection<BugPattern> enabledPatternSet = new HashSet<BugPattern>();
    for (Iterator<DetectorFactory> i = factories.factoryIterator(); i.hasNext(); ) {
        DetectorFactory factory = i.next();
        if (isEnabled(factory)) {
            enabledPatternSet.addAll(factory.getReportedBugPatterns());
        }
    }
    prologue();
    Iterator<BugPattern> i = DetectorFactoryCollection.instance().bugPatternIterator();
    while (i.hasNext()) {
        BugPattern bugPattern = i.next();
        if (!enabledPatternSet.contains(bugPattern)) {
            continue;
        }
        emit(bugPattern);
    }
    epilogue();
}
Also used : DetectorFactory(edu.umd.cs.findbugs.DetectorFactory) BugPattern(edu.umd.cs.findbugs.BugPattern) DetectorFactoryCollection(edu.umd.cs.findbugs.DetectorFactoryCollection) HashSet(java.util.HashSet)

Example 4 with DetectorFactoryCollection

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

the class TestDataflowAnalysis method initialize.

private void initialize() {
    initialized = true;
    IAnalysisCache analysisCache = Global.getAnalysisCache();
    Class<? extends Dataflow<Fact, AnalysisType>> cls = null;
    // First, try loading the dataflow class from the general findBugs code.
    try {
        Class<?> c = getClass().getClassLoader().loadClass(dataflowClassName);
        cls = asDataflowClass(c);
    } catch (ClassNotFoundException e) {
        assert true;
    }
    if (cls == null) {
        // Find the dataflow class from the plugin in which it was loaded
        DetectorFactoryCollection detectorFactoryCollection = analysisCache.getDatabase(DetectorFactoryCollection.class);
        for (Iterator<Plugin> i = detectorFactoryCollection.pluginIterator(); i.hasNext(); ) {
            Plugin plugin = i.next();
            try {
                cls = asDataflowClass(plugin.getClassLoader().loadClass(dataflowClassName));
                break;
            } catch (ClassNotFoundException e) {
                assert true;
            }
        }
    }
    if (cls == null) {
        analysisCache.getErrorLogger().logError("TestDataflowAnalysis: could not load class " + dataflowClassName);
        return;
    }
    dataflowClass = cls;
}
Also used : IAnalysisCache(edu.umd.cs.findbugs.classfile.IAnalysisCache) DetectorFactoryCollection(edu.umd.cs.findbugs.DetectorFactoryCollection) Plugin(edu.umd.cs.findbugs.Plugin)

Example 5 with DetectorFactoryCollection

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

the class ExecutionPlan method main.

public static void main(String[] argv) throws Exception {
    DetectorFactoryCollection detectorFactoryCollection = DetectorFactoryCollection.instance();
    ExecutionPlan execPlan = new ExecutionPlan();
    for (String pluginId : argv) {
        Plugin plugin = detectorFactoryCollection.getPluginById(pluginId);
        if (plugin != null) {
            execPlan.addPlugin(plugin);
        }
    }
    execPlan.build();
    System.out.println(execPlan.getNumPasses() + " passes in plan");
    execPlan.print();
}
Also used : DetectorFactoryCollection(edu.umd.cs.findbugs.DetectorFactoryCollection) Plugin(edu.umd.cs.findbugs.Plugin)

Aggregations

DetectorFactoryCollection (edu.umd.cs.findbugs.DetectorFactoryCollection)13 DetectorFactory (edu.umd.cs.findbugs.DetectorFactory)5 Plugin (edu.umd.cs.findbugs.Plugin)4 Project (edu.umd.cs.findbugs.Project)3 IAnalysisCache (edu.umd.cs.findbugs.classfile.IAnalysisCache)3 BugPattern (edu.umd.cs.findbugs.BugPattern)2 AnalysisContext (edu.umd.cs.findbugs.ba.AnalysisContext)2 ClassPathImpl (edu.umd.cs.findbugs.classfile.impl.ClassPathImpl)2 DottedClassName (edu.umd.cs.findbugs.internalAnnotations.DottedClassName)2 PrintWriter (java.io.PrintWriter)2 StringWriter (java.io.StringWriter)2 HashSet (java.util.HashSet)2 Before (org.junit.Before)2 Gson (com.google.gson.Gson)1 JsonArray (com.google.gson.JsonArray)1 JsonObject (com.google.gson.JsonObject)1 BugCollectionBugReporter (edu.umd.cs.findbugs.BugCollectionBugReporter)1 BugInstance (edu.umd.cs.findbugs.BugInstance)1 FindBugs2 (edu.umd.cs.findbugs.FindBugs2)1 PluginLoader (edu.umd.cs.findbugs.PluginLoader)1