@Test public void testSourceLocation() throws IOException { Path tmpDir = Files.createTempDirectory("spotbugs"); new File(tmpDir.toFile(), "SampleClass.java").createNewFile(); SourceFinder sourceFinder = reporter.getProject().getSourceFinder(); sourceFinder.setSourceBaseList(Collections.singleton(tmpDir.toString())); BugPattern bugPattern = new BugPattern("TYPE", "abbrev", "category", false, "shortDescription", "longDescription", "detailText", "https: DetectorFactoryCollection.instance().registerBugPattern(bugPattern); reporter.reportBug(new BugInstance(bugPattern.getType(), bugPattern.getPriorityAdjustment()).addInt(10).addClass("SampleClass")); reporter.finish(); String json = writer.toString(); JSONObject jsonObject = new JSONObject(json); JSONObject run = jsonObject.getJSONArray("runs").getJSONObject(0); JSONObject originalUriBaseIds = run.getJSONObject("originalUriBaseIds"); String uriBaseId = takeFirstKey(originalUriBaseIds).get(); assertThat(URI.create(originalUriBaseIds.getJSONObject(uriBaseId).getString("uri")), is(tmpDir.toUri())); JSONArray results = run.getJSONArray("results"); assertThat(results.length(), is(1)); JSONObject result = results.getJSONObject(0); JSONObject artifactLocation = result.getJSONArray("locations").getJSONObject(0).getJSONObject("physicalLocation").getJSONObject( "artifactLocation"); String relativeUri = artifactLocation.getString("uri"); assertThat("relative URI that can be resolved by the uriBase", relativeUri, is("SampleClass.java")); assertThat(artifactLocation.getString("uriBaseId"), is(uriBaseId)); }
@Override public void finish() { try { JSONWriter jsonWriter = new JSONWriter(outputStream); jsonWriter.object(); jsonWriter.key("version").value("2.1.0").key("$schema").value( "https: processRuns(jsonWriter); jsonWriter.endObject(); getBugCollection().bugsPopulated(); } finally { outputStream.close(); } }
SarifBugReporter extends BugCollectionBugReporter { @Override public void finish() { try { JSONWriter jsonWriter = new JSONWriter(outputStream); jsonWriter.object(); jsonWriter.key("version").value("2.1.0").key("$schema").value( "https: processRuns(jsonWriter); jsonWriter.endObject(); getBugCollection().bugsPopulated(); } finally { outputStream.close(); } } }
SarifBugReporter extends BugCollectionBugReporter { @Override public void finish() { try { JSONWriter jsonWriter = new JSONWriter(outputStream); jsonWriter.object(); jsonWriter.key("version").value("2.1.0").key("$schema").value( "https: processRuns(jsonWriter); jsonWriter.endObject(); getBugCollection().bugsPopulated(); } finally { outputStream.close(); } } SarifBugReporter(Project project); }
SarifBugReporter extends BugCollectionBugReporter { @Override public void finish() { try { JSONWriter jsonWriter = new JSONWriter(outputStream); jsonWriter.object(); jsonWriter.key("version").value("2.1.0").key("$schema").value( "https: processRuns(jsonWriter); jsonWriter.endObject(); getBugCollection().bugsPopulated(); } finally { outputStream.close(); } } SarifBugReporter(Project project); @Override void finish(); }
SarifBugReporter extends BugCollectionBugReporter { @Override public void finish() { try { JSONWriter jsonWriter = new JSONWriter(outputStream); jsonWriter.object(); jsonWriter.key("version").value("2.1.0").key("$schema").value( "https: processRuns(jsonWriter); jsonWriter.endObject(); getBugCollection().bugsPopulated(); } finally { outputStream.close(); } } SarifBugReporter(Project project); @Override void finish();  }