Search in sources :

Example 1 with StopTimer

use of de.tobject.findbugs.util.Util.StopTimer in project spotbugs by spotbugs.

the class FindBugsWorker method work.

/**
 * Run FindBugs on the given collection of resources from same project
 * (note: This is currently not thread-safe)
 *
 * @param resources
 *            files or directories which should be on the project classpath.
 *            All resources must belong to the same project, and no one of
 *            the elements can contain another one. Ergo, if the list
 *            contains a project itself, then it must have only one element.
 * @throws CoreException
 */
public void work(List<WorkItem> resources) throws CoreException {
    if (resources == null || resources.isEmpty()) {
        if (DEBUG) {
            FindbugsPlugin.getDefault().logInfo("No resources to analyse for project " + project);
        }
        return;
    }
    if (DEBUG) {
        System.out.println(resources);
    }
    st = new StopTimer();
    st.newPoint("initPlugins");
    // make sure it's initialized
    FindbugsPlugin.applyCustomDetectors(false);
    st.newPoint("clearMarkers");
    // clear markers
    clearMarkers(resources);
    st.newPoint("configureOutputFiles");
    final Project findBugsProject = new Project();
    findBugsProject.setProjectName(javaProject.getElementName());
    final Reporter bugReporter = new Reporter(javaProject, findBugsProject, monitor);
    if (FindBugsConsole.getConsole() != null) {
        bugReporter.setReportingStream(FindBugsConsole.getConsole().newOutputStream());
    }
    bugReporter.setPriorityThreshold(userPrefs.getUserDetectorThreshold());
    FindBugs.setHome(FindbugsPlugin.getFindBugsEnginePluginLocation());
    Map<IPath, IPath> outLocations = createOutputLocations();
    // collect all related class/jar/war etc files for analysis
    collectClassFiles(resources, outLocations, findBugsProject);
    // attach source directories (can be used by some detectors, see
    // SwitchFallthrough)
    configureSourceDirectories(findBugsProject, outLocations);
    if (findBugsProject.getFileCount() == 0) {
        if (DEBUG) {
            FindbugsPlugin.getDefault().logInfo("No resources to analyse for project " + project);
        }
        return;
    }
    st.newPoint("createAuxClasspath");
    String[] classPathEntries = createAuxClasspath();
    // add to findbugs classpath
    for (String entry : classPathEntries) {
        findBugsProject.addAuxClasspathEntry(entry);
    }
    st.newPoint("configureProps");
    IPreferenceStore store = FindbugsPlugin.getPluginPreferences(project);
    boolean cacheClassData = store.getBoolean(FindBugsConstants.KEY_CACHE_CLASS_DATA);
    final FindBugs2 findBugs = new FindBugs2Eclipse(project, cacheClassData, bugReporter);
    findBugs.setNoClassOk(true);
    findBugs.setProject(findBugsProject);
    findBugs.setBugReporter(bugReporter);
    findBugs.setProgressCallback(bugReporter);
    findBugs.setDetectorFactoryCollection(DetectorFactoryCollection.instance());
    // configure detectors.
    userPrefs.setIncludeFilterFiles(relativeToAbsolute(userPrefs.getIncludeFilterFiles()));
    userPrefs.setExcludeFilterFiles(relativeToAbsolute(userPrefs.getExcludeFilterFiles()));
    userPrefs.setExcludeBugsFiles(relativeToAbsolute(userPrefs.getExcludeBugsFiles()));
    findBugs.setUserPreferences(userPrefs);
    // configure extended preferences
    findBugs.setAnalysisFeatureSettings(userPrefs.getAnalysisFeatureSettings());
    findBugs.setMergeSimilarWarnings(false);
    if (cacheClassData) {
        FindBugs2Eclipse.checkClassPathChanges(findBugs.getProject().getAuxClasspathEntryList(), project);
    }
    st.newPoint("runFindBugs");
    if (DEBUG) {
        FindbugsPlugin.log("Running SpotBugs");
    }
    runFindBugs(findBugs);
    if (DEBUG) {
        FindbugsPlugin.log("Done running SpotBugs");
    }
    // Merge new results into existing results
    // if the argument is project, then it's not incremental
    boolean incremental = !(resources.get(0) instanceof IProject);
    updateBugCollection(findBugsProject, bugReporter, incremental);
    st.newPoint("done");
    st = null;
    monitor.done();
}
Also used : IProject(org.eclipse.core.resources.IProject) Project(edu.umd.cs.findbugs.Project) IJavaProject(org.eclipse.jdt.core.IJavaProject) IPath(org.eclipse.core.runtime.IPath) FindBugs2(edu.umd.cs.findbugs.FindBugs2) Reporter(de.tobject.findbugs.reporter.Reporter) StopTimer(de.tobject.findbugs.util.Util.StopTimer) IPreferenceStore(org.eclipse.jface.preference.IPreferenceStore) IProject(org.eclipse.core.resources.IProject)

Example 2 with StopTimer

use of de.tobject.findbugs.util.Util.StopTimer in project spotbugs by spotbugs.

the class FindBugsWorker method loadXml.

/**
 * Load existing FindBugs xml report for the given collection of files.
 *
 * @param fileName
 *            xml file name to load bugs from
 * @throws CoreException
 */
public void loadXml(String fileName) throws CoreException {
    if (fileName == null) {
        return;
    }
    st = new StopTimer();
    // clear markers
    clearMarkers(null);
    final Project findBugsProject = new Project();
    final Reporter bugReporter = new Reporter(javaProject, findBugsProject, monitor);
    bugReporter.setPriorityThreshold(userPrefs.getUserDetectorThreshold());
    reportFromXml(fileName, findBugsProject, bugReporter);
    // Merge new results into existing results.
    updateBugCollection(findBugsProject, bugReporter, false);
    monitor.done();
}
Also used : IProject(org.eclipse.core.resources.IProject) Project(edu.umd.cs.findbugs.Project) IJavaProject(org.eclipse.jdt.core.IJavaProject) Reporter(de.tobject.findbugs.reporter.Reporter) StopTimer(de.tobject.findbugs.util.Util.StopTimer)

Aggregations

Reporter (de.tobject.findbugs.reporter.Reporter)2 StopTimer (de.tobject.findbugs.util.Util.StopTimer)2 Project (edu.umd.cs.findbugs.Project)2 IProject (org.eclipse.core.resources.IProject)2 IJavaProject (org.eclipse.jdt.core.IJavaProject)2 FindBugs2 (edu.umd.cs.findbugs.FindBugs2)1 IPath (org.eclipse.core.runtime.IPath)1 IPreferenceStore (org.eclipse.jface.preference.IPreferenceStore)1