Java Code Examples for edu.umd.cs.findbugs.Project#addAuxClasspathEntry()

The following examples show how to use edu.umd.cs.findbugs.Project#addAuxClasspathEntry() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AnalysisRunner.java    From spotbugs with GNU Lesser General Public License v2.1 6 votes vote down vote up
@CheckReturnValue
private Project createProject(Path[] files) {
    final Project project = new Project();
    project.setProjectName(getClass().getSimpleName());
    if (PLUGIN_JAR != null) {
        try {
            String pluginId = Plugin.addCustomPlugin(PLUGIN_JAR.toURI()).getPluginId();
            project.setPluginStatusTrinary(pluginId, Boolean.TRUE);
        } catch (PluginException e) {
            throw new AssertionError("Failed to load plugin", e);
        }
    }

    for (Path file : files) {
        project.addFile(file.toAbsolutePath().toString());
    }
    for (Path auxClasspathEntry : auxClasspathEntries) {
        project.addAuxClasspathEntry(auxClasspathEntry.toAbsolutePath().toString());
    }
    return project;
}
 
Example 2
Source File: FindBugsLauncher.java    From Android_Code_Arbiter with GNU Lesser General Public License v3.0 4 votes vote down vote up
/**
 * Launch an analysis on the given source files.
 *
 * @param classFiles
 * @param classPaths
 * @param bugReporter
 * @throws java.io.IOException
 * @throws InterruptedException
 * @throws edu.umd.cs.findbugs.PluginException
 * @throws URISyntaxException
 *
 */
public void analyze(String[] classFiles, String[] classPaths, BugReporter bugReporter) throws IOException, InterruptedException,
		PluginException, NoSuchFieldException, IllegalAccessException, URISyntaxException {
    Project project = new Project();
    project.setProjectName("automate-test-project");
    for (String file : classFiles) {
        project.addFile(file);
    }

    // Add classpath list to project's auxclasspath
    for (String classpath : classPaths) {
    	project.addAuxClasspathEntry(classpath);
    }

    if (loadedPlugin == null) {
        //Initialize the plugin base on the findbugs.xml
        byte[] archive = buildFakePluginJar();

        File f = new File(System.getProperty("java.io.tmpdir"), "plugin.jar");
        log.info("Writing " + f.getCanonicalPath());
        f.deleteOnExit();
        FileOutputStream out = new FileOutputStream(f);
        out.write(archive);
        out.close();

        loadedPlugin = Plugin.loadCustomPlugin(f.toURI().toURL(), project);
    }

    //FindBugs engine
    FindBugs2 engine = new FindBugs2();
    engine.setNoClassOk(true);
    engine.setMergeSimilarWarnings(false);
    engine.setBugReporter(bugReporter);
    engine.setProject(project);
    engine.setProgressCallback(mock(FindBugsProgress.class));

    engine.setDetectorFactoryCollection(DetectorFactoryCollection.instance());

    //User preferences set to miss no bugs report
    UserPreferences prefs = UserPreferences.createDefaultUserPreferences();

    ProjectFilterSettings filter = prefs.getFilterSettings();
    filter.setMinRank(20);
    filter.setDisplayFalseWarnings(true);
    filter.setMinPriority("Low");

    engine.setUserPreferences(prefs);

    log.info("Analyzing... {}", classFiles);
    engine.execute();
}