Search in sources :

Example 1 with PluginLoader

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

the class SarifBugReporterTest method testExtensions.

@Test
public void testExtensions() throws PluginException {
    PluginLoader pluginLoader = DetectorFactoryCollection.instance().getCorePlugin().getPluginLoader();
    Plugin plugin = new Plugin("pluginId", "version", null, pluginLoader, true, false);
    DetectorFactoryCollection dfc = new DetectorFactoryCollection(plugin);
    try {
        DetectorFactoryCollection.resetInstance(dfc);
        reporter.finish();
    } finally {
        DetectorFactoryCollection.resetInstance(null);
    }
    String json = writer.toString();
    JsonObject jsonObject = new Gson().fromJson(json, JsonObject.class);
    JsonObject run = jsonObject.getAsJsonArray("runs").get(0).getAsJsonObject();
    JsonObject tool = run.getAsJsonObject("tool");
    JsonArray extensions = tool.getAsJsonArray("extensions");
    assertThat(extensions.size(), is(1));
    JsonObject extension = extensions.get(0).getAsJsonObject();
    assertThat(extension.get("name").getAsString(), is("pluginId"));
    assertThat(extension.get("version").getAsString(), is("version"));
}
Also used : JsonArray(com.google.gson.JsonArray) JsonObject(com.google.gson.JsonObject) Gson(com.google.gson.Gson) PluginLoader(edu.umd.cs.findbugs.PluginLoader) Plugin(edu.umd.cs.findbugs.Plugin) DetectorFactoryCollection(edu.umd.cs.findbugs.DetectorFactoryCollection) Test(org.junit.Test)

Aggregations

Gson (com.google.gson.Gson)1 JsonArray (com.google.gson.JsonArray)1 JsonObject (com.google.gson.JsonObject)1 DetectorFactoryCollection (edu.umd.cs.findbugs.DetectorFactoryCollection)1 Plugin (edu.umd.cs.findbugs.Plugin)1 PluginLoader (edu.umd.cs.findbugs.PluginLoader)1 Test (org.junit.Test)1