private void updateScm(Component component) { scmEditor.setText(""); Changesets changesets = reader.readChangesets(component.getRef()); if (changesets == null) { return; } List<Integer> changesetIndexByLine = changesets.getChangesetIndexByLineList(); try { int index = 0; for (Changeset changeset : changesets.getChangesetList()) { scmEditor.getDocument().insertString(scmEditor.getDocument().getEndPosition().getOffset(), Integer.toString(index) + "\n", null); scmEditor.getDocument().insertString(scmEditor.getDocument().getEndPosition().getOffset(), changeset + "\n", null); index++; } scmEditor.getDocument().insertString(scmEditor.getDocument().getEndPosition().getOffset(), "\n", null); int line = 1; for (Integer idx : changesetIndexByLine) { scmEditor.getDocument().insertString(scmEditor.getDocument().getEndPosition().getOffset(), Integer.toString(line) + ": " + idx + "\n", null); line++; } } catch (Exception e) { throw new IllegalStateException("Can't read SCM for " + getNodeName(component), e); } }
@Test public void testScmMeasure() throws IOException, URISyntaxException { File baseDir = prepareProject(); tester.newAnalysis() .properties(ImmutableMap.<String, String>builder() .put("sonar.task", "scan") .put("sonar.projectBaseDir", baseDir.getAbsolutePath()) .put("sonar.projectKey", "com.foo.project") .put("sonar.projectName", "Foo Project") .put("sonar.projectVersion", "1.0-SNAPSHOT") .put("sonar.projectDescription", "Description of Foo Project") .put("sonar.sources", "src") .put("sonar.scm.provider", "xoo") .build()) .execute(); ScannerReport.Changesets fileScm = getChangesets(baseDir, "src/sample.xoo"); assertThat(fileScm.getChangesetIndexByLineList()).hasSize(5); Changeset changesetLine1 = fileScm.getChangeset(fileScm.getChangesetIndexByLine(0)); assertThat(changesetLine1.getAuthor()).isEmpty(); Changeset changesetLine2 = fileScm.getChangeset(fileScm.getChangesetIndexByLine(1)); assertThat(changesetLine2.getAuthor()).isEqualTo(getNonAsciiAuthor().toLowerCase()); Changeset changesetLine3 = fileScm.getChangeset(fileScm.getChangesetIndexByLine(2)); assertThat(changesetLine3.getAuthor()).isEqualTo("julien"); Changeset changesetLine4 = fileScm.getChangeset(fileScm.getChangesetIndexByLine(3)); assertThat(changesetLine4.getAuthor()).isEqualTo("julien"); Changeset changesetLine5 = fileScm.getChangeset(fileScm.getChangesetIndexByLine(4)); assertThat(changesetLine5.getAuthor()).isEqualTo("simon"); }
private void updateScm(Component component) { scmEditor.setText(""); Changesets changesets = reader.readChangesets(component.getRef()); if (changesets == null) { return; } List<Integer> changesetIndexByLine = changesets.getChangesetIndexByLineList(); try { int index = 0; for (Changeset changeset : changesets.getChangesetList()) { scmEditor.getDocument().insertString(scmEditor.getDocument().getEndPosition().getOffset(), Integer.toString(index) + "\n", null); scmEditor.getDocument().insertString(scmEditor.getDocument().getEndPosition().getOffset(), changeset + "\n", null); index++; } scmEditor.getDocument().insertString(scmEditor.getDocument().getEndPosition().getOffset(), "\n", null); int line = 1; for (Integer idx : changesetIndexByLine) { scmEditor.getDocument().insertString(scmEditor.getDocument().getEndPosition().getOffset(), Integer.toString(line) + ": " + idx + "\n", null); line++; } } catch (Exception e) { throw new IllegalStateException("Can't read SCM for " + getNodeName(component), e); } }