aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--sonar-scanner-engine/src/main/java/org/sonar/scanner/scm/DefaultBlameOutput.java11
-rw-r--r--sonar-scanner-engine/src/main/java/org/sonar/scanner/scm/ScmPublisher.java9
-rw-r--r--sonar-scanner-engine/src/main/java/org/sonar/scm/git/GitScmProvider.java22
-rw-r--r--sonar-scanner-engine/src/test/java/org/sonar/scanner/scm/DefaultBlameOutputTest.java17
-rw-r--r--sonar-scanner-engine/src/test/java/org/sonar/scm/git/GitScmProviderTest.java23
5 files changed, 49 insertions, 33 deletions
diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/scm/DefaultBlameOutput.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/scm/DefaultBlameOutput.java
index 9a7381826bc..2a32f113624 100644
--- a/sonar-scanner-engine/src/main/java/org/sonar/scanner/scm/DefaultBlameOutput.java
+++ b/sonar-scanner-engine/src/main/java/org/sonar/scanner/scm/DefaultBlameOutput.java
@@ -35,6 +35,7 @@ import org.sonar.api.batch.scm.BlameLine;
import org.sonar.api.notifications.AnalysisWarnings;
import org.sonar.api.utils.log.Logger;
import org.sonar.api.utils.log.Loggers;
+import org.sonar.scanner.bootstrap.ScannerWsClient;
import org.sonar.scanner.protocol.output.ScannerReport;
import org.sonar.scanner.protocol.output.ScannerReport.Changesets.Builder;
import org.sonar.scanner.protocol.output.ScannerReportWriter;
@@ -48,14 +49,16 @@ class DefaultBlameOutput implements BlameOutput {
private final ScannerReportWriter writer;
private AnalysisWarnings analysisWarnings;
+ private final ScannerWsClient client;
private final Set<InputFile> allFilesToBlame = new LinkedHashSet<>();
private ProgressReport progressReport;
private int count;
private int total;
- DefaultBlameOutput(ScannerReportWriter writer, AnalysisWarnings analysisWarnings, List<InputFile> filesToBlame) {
+ DefaultBlameOutput(ScannerReportWriter writer, AnalysisWarnings analysisWarnings, List<InputFile> filesToBlame, ScannerWsClient client) {
this.writer = writer;
this.analysisWarnings = analysisWarnings;
+ this.client = client;
this.allFilesToBlame.addAll(filesToBlame);
count = 0;
total = filesToBlame.size();
@@ -134,10 +137,12 @@ class DefaultBlameOutput implements BlameOutput {
LOG.warn(" * " + f);
}
LOG.warn("This may lead to missing/broken features in SonarQube");
+ String link = client.baseUrl() + "/documentation/analysis/scm-integration/";
analysisWarnings.addUnique(String.format("Missing blame information for %d %s. This may lead to some features not working correctly. " +
- "Please check the analysis logs and refer to <a href=\"/documentation/analysis/scm-integration/\" target=\"_blank\">the documentation</a>.",
+ "Please check the analysis logs and refer to <a href=\"%s\" target=\"_blank\">the documentation</a>.",
allFilesToBlame.size(),
- allFilesToBlame.size() > 1 ? "files" : "file"));
+ allFilesToBlame.size() > 1 ? "files" : "file",
+ link));
}
}
diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/scm/ScmPublisher.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/scm/ScmPublisher.java
index c5fec9ffb41..77de4987b3e 100644
--- a/sonar-scanner-engine/src/main/java/org/sonar/scanner/scm/ScmPublisher.java
+++ b/sonar-scanner-engine/src/main/java/org/sonar/scanner/scm/ScmPublisher.java
@@ -31,6 +31,7 @@ import org.sonar.api.batch.scm.ScmProvider;
import org.sonar.api.notifications.AnalysisWarnings;
import org.sonar.api.utils.log.Logger;
import org.sonar.api.utils.log.Loggers;
+import org.sonar.scanner.bootstrap.ScannerWsClient;
import org.sonar.scanner.protocol.output.ScannerReport;
import org.sonar.scanner.protocol.output.ScannerReport.Changesets.Builder;
import org.sonar.scanner.protocol.output.ScannerReportWriter;
@@ -50,10 +51,11 @@ public final class ScmPublisher {
private final FileSystem fs;
private final ScannerReportWriter writer;
private AnalysisWarnings analysisWarnings;
+ private final ScannerWsClient client;
private final BranchConfiguration branchConfiguration;
- public ScmPublisher(ScmConfiguration configuration, ProjectRepositoriesSupplier projectRepositoriesSupplier,
- InputComponentStore componentStore, FileSystem fs, ReportPublisher reportPublisher, BranchConfiguration branchConfiguration, AnalysisWarnings analysisWarnings) {
+ public ScmPublisher(ScmConfiguration configuration, ProjectRepositoriesSupplier projectRepositoriesSupplier, InputComponentStore componentStore, FileSystem fs,
+ ReportPublisher reportPublisher, BranchConfiguration branchConfiguration, AnalysisWarnings analysisWarnings, ScannerWsClient client) {
this.configuration = configuration;
this.projectRepositoriesSupplier = projectRepositoriesSupplier;
this.componentStore = componentStore;
@@ -61,6 +63,7 @@ public final class ScmPublisher {
this.branchConfiguration = branchConfiguration;
this.writer = reportPublisher.getWriter();
this.analysisWarnings = analysisWarnings;
+ this.client = client;
}
public void publish() {
@@ -79,7 +82,7 @@ public final class ScmPublisher {
if (!filesToBlame.isEmpty()) {
String key = provider.key();
LOG.info("SCM Publisher SCM provider for this project is: " + key);
- DefaultBlameOutput output = new DefaultBlameOutput(writer, analysisWarnings, filesToBlame);
+ DefaultBlameOutput output = new DefaultBlameOutput(writer, analysisWarnings, filesToBlame, client);
try {
provider.blameCommand().blame(new DefaultBlameInput(fs, filesToBlame), output);
} catch (Exception e) {
diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scm/git/GitScmProvider.java b/sonar-scanner-engine/src/main/java/org/sonar/scm/git/GitScmProvider.java
index f728b2be2ac..c91cf055ced 100644
--- a/sonar-scanner-engine/src/main/java/org/sonar/scm/git/GitScmProvider.java
+++ b/sonar-scanner-engine/src/main/java/org/sonar/scm/git/GitScmProvider.java
@@ -59,6 +59,7 @@ import org.sonar.api.utils.MessageException;
import org.sonar.api.utils.System2;
import org.sonar.api.utils.log.Logger;
import org.sonar.api.utils.log.Loggers;
+import org.sonar.scanner.bootstrap.ScannerWsClient;
public class GitScmProvider extends ScmProvider {
@@ -68,12 +69,14 @@ public class GitScmProvider extends ScmProvider {
private final AnalysisWarnings analysisWarnings;
private final GitIgnoreCommand gitIgnoreCommand;
private final System2 system2;
+ private final String documentationLink;
- public GitScmProvider(JGitBlameCommand jgitBlameCommand, AnalysisWarnings analysisWarnings, GitIgnoreCommand gitIgnoreCommand, System2 system2) {
+ public GitScmProvider(JGitBlameCommand jgitBlameCommand, AnalysisWarnings analysisWarnings, GitIgnoreCommand gitIgnoreCommand, System2 system2, ScannerWsClient client) {
this.jgitBlameCommand = jgitBlameCommand;
this.analysisWarnings = analysisWarnings;
this.gitIgnoreCommand = gitIgnoreCommand;
this.system2 = system2;
+ this.documentationLink = client.baseUrl() + "/documentation/analysis/scm-integration/";
}
@Override
@@ -103,10 +106,7 @@ public class GitScmProvider extends ScmProvider {
try (Repository repo = buildRepo(rootBaseDir)) {
Ref targetRef = resolveTargetRef(targetBranchName, repo);
if (targetRef == null) {
- analysisWarnings.addUnique(String.format(COULD_NOT_FIND_REF
- + ". You may see unexpected issues and changes. "
- + "Please make sure to fetch this ref before pull request analysis and refer to"
- + " <a href=\"/documentation/analysis/scm-integration/\" target=\"_blank\">the documentation</a>.", targetBranchName));
+ addWarningTargetNotFound(targetBranchName);
return null;
}
@@ -148,10 +148,7 @@ public class GitScmProvider extends ScmProvider {
try (Repository repo = buildRepo(projectBaseDir)) {
Ref targetRef = resolveTargetRef(targetBranchName, repo);
if (targetRef == null) {
- analysisWarnings.addUnique(String.format(COULD_NOT_FIND_REF
- + ". You may see unexpected issues and changes. "
- + "Please make sure to fetch this ref before pull request analysis"
- + " and refer to <a href=\"/documentation/analysis/scm-integration/\" target=\"_blank\">the documentation</a>.", targetBranchName));
+ addWarningTargetNotFound(targetBranchName);
return null;
}
@@ -181,6 +178,13 @@ public class GitScmProvider extends ScmProvider {
return null;
}
+ private void addWarningTargetNotFound(String targetBranchName) {
+ analysisWarnings.addUnique(String.format(COULD_NOT_FIND_REF
+ + ". You may see unexpected issues and changes. "
+ + "Please make sure to fetch this ref before pull request analysis and refer to"
+ + " <a href=\"%s\" target=\"_blank\">the documentation</a>.", targetBranchName, documentationLink));
+ }
+
private void collectChangedLines(Repository repo, RevCommit mergeBaseCommit, Map<Path, Set<Integer>> changedLines, Path changedFile) {
ChangedLinesComputer computer = new ChangedLinesComputer();
diff --git a/sonar-scanner-engine/src/test/java/org/sonar/scanner/scm/DefaultBlameOutputTest.java b/sonar-scanner-engine/src/test/java/org/sonar/scanner/scm/DefaultBlameOutputTest.java
index 21ba297db5e..56a157ac369 100644
--- a/sonar-scanner-engine/src/test/java/org/sonar/scanner/scm/DefaultBlameOutputTest.java
+++ b/sonar-scanner-engine/src/test/java/org/sonar/scanner/scm/DefaultBlameOutputTest.java
@@ -27,11 +27,13 @@ import org.sonar.api.batch.fs.InputFile;
import org.sonar.api.batch.fs.internal.TestInputFileBuilder;
import org.sonar.api.batch.scm.BlameLine;
import org.sonar.api.utils.System2;
+import org.sonar.scanner.bootstrap.ScannerWsClient;
import org.sonar.scanner.notifications.DefaultAnalysisWarnings;
import static java.util.Collections.singletonList;
import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
public class DefaultBlameOutputTest {
@@ -39,22 +41,23 @@ public class DefaultBlameOutputTest {
public ExpectedException thrown = ExpectedException.none();
private System2 system2 = mock(System2.class);
private DefaultAnalysisWarnings analysisWarnings = new DefaultAnalysisWarnings(system2);
+ private ScannerWsClient client = mock(ScannerWsClient.class);
@Test
public void shouldNotFailIfNotSameNumberOfLines() {
InputFile file = new TestInputFileBuilder("foo", "src/main/java/Foo.java").setLines(10).build();
- new DefaultBlameOutput(null, analysisWarnings, singletonList(file)).blameResult(file, singletonList(new BlameLine().revision("1").author("guy")));
+ new DefaultBlameOutput(null, analysisWarnings, singletonList(file), client).blameResult(file, singletonList(new BlameLine().revision("1").author("guy")));
}
@Test
public void addWarningIfFilesMissing() {
InputFile file = new TestInputFileBuilder("foo", "src/main/java/Foo.java").setLines(10).build();
-
- new DefaultBlameOutput(null, analysisWarnings, singletonList(file)).finish(true);
+ when(client.baseUrl()).thenReturn("http://sonarqube/v1");
+ new DefaultBlameOutput(null, analysisWarnings, singletonList(file), client).finish(true);
assertThat(analysisWarnings.warnings()).extracting(DefaultAnalysisWarnings.Message::getText)
.containsOnly("Missing blame information for 1 file. This may lead to some features not working correctly. " +
- "Please check the analysis logs and refer to <a href=\"/documentation/analysis/scm-integration/\" target=\"_blank\">the documentation</a>.");
+ "Please check the analysis logs and refer to <a href=\"http://sonarqube/v1/documentation/analysis/scm-integration/\" target=\"_blank\">the documentation</a>.");
}
@Test
@@ -64,7 +67,7 @@ public class DefaultBlameOutputTest {
thrown.expect(IllegalArgumentException.class);
thrown.expectMessage("It was not expected to blame file " + file);
- new DefaultBlameOutput(null, analysisWarnings, singletonList(new TestInputFileBuilder("foo", "src/main/java/Foo2.java").build()))
+ new DefaultBlameOutput(null, analysisWarnings, singletonList(new TestInputFileBuilder("foo", "src/main/java/Foo2.java").build()), client)
.blameResult(file, singletonList(new BlameLine().revision("1").author("guy")));
}
@@ -75,7 +78,7 @@ public class DefaultBlameOutputTest {
thrown.expect(IllegalArgumentException.class);
thrown.expectMessage("Blame date is null for file " + file + " at line 1");
- new DefaultBlameOutput(null, analysisWarnings, singletonList(file))
+ new DefaultBlameOutput(null, analysisWarnings, singletonList(file), client)
.blameResult(file, singletonList(new BlameLine().revision("1").author("guy")));
}
@@ -86,7 +89,7 @@ public class DefaultBlameOutputTest {
thrown.expect(IllegalArgumentException.class);
thrown.expectMessage("Blame revision is blank for file " + file + " at line 1");
- new DefaultBlameOutput(null, analysisWarnings, singletonList(file))
+ new DefaultBlameOutput(null, analysisWarnings, singletonList(file), client)
.blameResult(file, singletonList(new BlameLine().date(new Date()).author("guy")));
}
diff --git a/sonar-scanner-engine/src/test/java/org/sonar/scm/git/GitScmProviderTest.java b/sonar-scanner-engine/src/test/java/org/sonar/scm/git/GitScmProviderTest.java
index 3082c716bc9..96226264aa7 100644
--- a/sonar-scanner-engine/src/test/java/org/sonar/scm/git/GitScmProviderTest.java
+++ b/sonar-scanner-engine/src/test/java/org/sonar/scm/git/GitScmProviderTest.java
@@ -44,11 +44,9 @@ import org.eclipse.jgit.api.Git;
import org.eclipse.jgit.api.errors.GitAPIException;
import org.eclipse.jgit.lib.ObjectId;
import org.eclipse.jgit.lib.PersonIdent;
-import org.eclipse.jgit.lib.Ref;
import org.eclipse.jgit.lib.RefDatabase;
import org.eclipse.jgit.lib.Repository;
import org.eclipse.jgit.lib.RepositoryBuilder;
-import org.eclipse.jgit.merge.MergeStrategy;
import org.eclipse.jgit.revwalk.RevCommit;
import org.eclipse.jgit.storage.file.FileRepositoryBuilder;
import org.eclipse.jgit.treewalk.AbstractTreeIterator;
@@ -63,6 +61,7 @@ import org.sonar.api.utils.MessageException;
import org.sonar.api.utils.System2;
import org.sonar.api.utils.log.LogAndArguments;
import org.sonar.api.utils.log.LogTester;
+import org.sonar.scanner.bootstrap.ScannerWsClient;
import static java.util.Collections.emptySet;
import static org.assertj.core.api.Assertions.assertThat;
@@ -124,6 +123,7 @@ public class GitScmProviderTest {
private Path worktree;
private Git git;
private final AnalysisWarnings analysisWarnings = mock(AnalysisWarnings.class);
+ private final ScannerWsClient client = mock(ScannerWsClient.class);
@Before
public void before() throws IOException, GitAPIException {
@@ -141,7 +141,7 @@ public class GitScmProviderTest {
@Test
public void returnImplem() {
JGitBlameCommand jblameCommand = new JGitBlameCommand(new PathResolver(), analysisWarnings);
- GitScmProvider gitScmProvider = new GitScmProvider(jblameCommand, analysisWarnings, gitIgnoreCommand, system2);
+ GitScmProvider gitScmProvider = new GitScmProvider(jblameCommand, analysisWarnings, gitIgnoreCommand, system2, client);
assertThat(gitScmProvider.blameCommand()).isEqualTo(jblameCommand);
}
@@ -630,7 +630,7 @@ public class GitScmProviderTest {
@Test
public void branchChangedFiles_should_return_null_on_io_errors_of_repo_builder() {
- GitScmProvider provider = new GitScmProvider(mockCommand(), analysisWarnings, gitIgnoreCommand, system2) {
+ GitScmProvider provider = new GitScmProvider(mockCommand(), analysisWarnings, gitIgnoreCommand, system2, client) {
@Override
Repository buildRepo(Path basedir) throws IOException {
throw new IOException();
@@ -646,8 +646,9 @@ public class GitScmProviderTest {
RefDatabase refDatabase = mock(RefDatabase.class);
when(repository.getRefDatabase()).thenReturn(refDatabase);
when(refDatabase.findRef(BRANCH_NAME)).thenReturn(null);
+ when(client.baseUrl()).thenReturn("http://sonarqube.org");
- GitScmProvider provider = new GitScmProvider(mockCommand(), analysisWarnings, gitIgnoreCommand, system2) {
+ GitScmProvider provider = new GitScmProvider(mockCommand(), analysisWarnings, gitIgnoreCommand, system2, client) {
@Override
Repository buildRepo(Path basedir) {
return repository;
@@ -662,7 +663,7 @@ public class GitScmProviderTest {
String warning = refNotFound
+ ". You may see unexpected issues and changes. Please make sure to fetch this ref before pull request analysis"
- + " and refer to <a href=\"/documentation/analysis/scm-integration/\" target=\"_blank\">the documentation</a>.";
+ + " and refer to <a href=\"http://sonarqube.org/documentation/analysis/scm-integration/\" target=\"_blank\">the documentation</a>.";
verify(analysisWarnings).addUnique(warning);
}
@@ -677,7 +678,7 @@ public class GitScmProviderTest {
Git git = mock(Git.class);
when(git.diff()).thenReturn(diffCommand);
- GitScmProvider provider = new GitScmProvider(mockCommand(), analysisWarnings, gitIgnoreCommand, system2) {
+ GitScmProvider provider = new GitScmProvider(mockCommand(), analysisWarnings, gitIgnoreCommand, system2, client) {
@Override
Git newGit(Repository repo) {
return git;
@@ -710,7 +711,7 @@ public class GitScmProviderTest {
commit(f2);
AtomicInteger callCount = new AtomicInteger(0);
- GitScmProvider provider = new GitScmProvider(mockCommand(), analysisWarnings, gitIgnoreCommand, system2) {
+ GitScmProvider provider = new GitScmProvider(mockCommand(), analysisWarnings, gitIgnoreCommand, system2, client) {
@Override
AbstractTreeIterator prepareTreeParser(Repository repo, RevCommit commit) throws IOException {
if (callCount.getAndIncrement() == 1) {
@@ -729,7 +730,7 @@ public class GitScmProviderTest {
@Test
public void branchChangedLines_returns_null_on_io_errors_of_repo_builder() {
- GitScmProvider provider = new GitScmProvider(mockCommand(), analysisWarnings, gitIgnoreCommand, system2) {
+ GitScmProvider provider = new GitScmProvider(mockCommand(), analysisWarnings, gitIgnoreCommand, system2, client) {
@Override
Repository buildRepo(Path basedir) throws IOException {
throw new IOException();
@@ -744,7 +745,7 @@ public class GitScmProviderTest {
}
private GitScmProvider newGitScmProvider() {
- return new GitScmProvider(mock(JGitBlameCommand.class), analysisWarnings, gitIgnoreCommand, system2);
+ return new GitScmProvider(mock(JGitBlameCommand.class), analysisWarnings, gitIgnoreCommand, system2, client);
}
@Test
@@ -889,6 +890,6 @@ public class GitScmProviderTest {
}
private GitScmProvider newScmProvider() {
- return new GitScmProvider(mockCommand(), analysisWarnings, gitIgnoreCommand, system2);
+ return new GitScmProvider(mockCommand(), analysisWarnings, gitIgnoreCommand, system2, client);
}
}