aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-scanner-engine
diff options
context:
space:
mode:
authorPhilippe Perrin <philippe.perrin@sonarsource.com>2022-01-12 15:17:17 +0100
committersonartech <sonartech@sonarsource.com>2022-01-14 20:02:49 +0000
commitf68eafbf6d67bb50d519bf245c0b4e6f90004f62 (patch)
treead0276c364577ec68ee34b297e7978ca2f84a792 /sonar-scanner-engine
parent5eb1875e1dcee92a75c313e9ec906c74277cc67d (diff)
downloadsonarqube-f68eafbf6d67bb50d519bf245c0b4e6f90004f62.tar.gz
sonarqube-f68eafbf6d67bb50d519bf245c0b4e6f90004f62.zip
SONAR-15906 Fix documentation links in analysis warning
Diffstat (limited to 'sonar-scanner-engine')
-rw-r--r--sonar-scanner-engine/src/main/java/org/sonar/scanner/scm/DefaultBlameOutput.java9
-rw-r--r--sonar-scanner-engine/src/main/java/org/sonar/scanner/scm/ScmPublisher.java7
-rw-r--r--sonar-scanner-engine/src/main/java/org/sonar/scm/git/GitScmProvider.java5
-rw-r--r--sonar-scanner-engine/src/test/java/org/sonar/scanner/scm/DefaultBlameOutputTest.java27
-rw-r--r--sonar-scanner-engine/src/test/java/org/sonar/scm/git/GitScmProviderTest.java21
5 files changed, 29 insertions, 40 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 2a32f113624..d0004ebba81 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,7 +35,6 @@ 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;
@@ -49,16 +48,14 @@ 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, ScannerWsClient client) {
+ DefaultBlameOutput(ScannerReportWriter writer, AnalysisWarnings analysisWarnings, List<InputFile> filesToBlame) {
this.writer = writer;
this.analysisWarnings = analysisWarnings;
- this.client = client;
this.allFilesToBlame.addAll(filesToBlame);
count = 0;
total = filesToBlame.size();
@@ -137,9 +134,9 @@ 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/";
+ String link = "/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=\"%s\" 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",
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 77de4987b3e..6bc2572caca 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,7 +31,6 @@ 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;
@@ -51,11 +50,10 @@ 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, ScannerWsClient client) {
+ ReportPublisher reportPublisher, BranchConfiguration branchConfiguration, AnalysisWarnings analysisWarnings) {
this.configuration = configuration;
this.projectRepositoriesSupplier = projectRepositoriesSupplier;
this.componentStore = componentStore;
@@ -63,7 +61,6 @@ public final class ScmPublisher {
this.branchConfiguration = branchConfiguration;
this.writer = reportPublisher.getWriter();
this.analysisWarnings = analysisWarnings;
- this.client = client;
}
public void publish() {
@@ -82,7 +79,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, client);
+ DefaultBlameOutput output = new DefaultBlameOutput(writer, analysisWarnings, filesToBlame);
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 907861e67a2..1fb9d8eda24 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,7 +59,6 @@ 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 {
@@ -71,12 +70,12 @@ public class GitScmProvider extends ScmProvider {
private final System2 system2;
private final String documentationLink;
- public GitScmProvider(JGitBlameCommand jgitBlameCommand, AnalysisWarnings analysisWarnings, GitIgnoreCommand gitIgnoreCommand, System2 system2, ScannerWsClient client) {
+ public GitScmProvider(JGitBlameCommand jgitBlameCommand, AnalysisWarnings analysisWarnings, GitIgnoreCommand gitIgnoreCommand, System2 system2) {
this.jgitBlameCommand = jgitBlameCommand;
this.analysisWarnings = analysisWarnings;
this.gitIgnoreCommand = gitIgnoreCommand;
this.system2 = system2;
- this.documentationLink = client.baseUrl() + "/documentation/analysis/scm-integration/";
+ this.documentationLink = "/documentation/analysis/scm-integration/";
}
@Override
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 dce0ef0a204..7cc1de01a4c 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
@@ -25,45 +25,42 @@ 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.assertj.core.api.Assertions.assertThatThrownBy;
import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.when;
public class DefaultBlameOutputTest {
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), client).blameResult(file, singletonList(new BlameLine().revision("1").author("guy")));
+ new DefaultBlameOutput(null, analysisWarnings, singletonList(file)).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();
- when(client.baseUrl()).thenReturn("http://sonarqube/v1");
- new DefaultBlameOutput(null, analysisWarnings, singletonList(file), client).finish(true);
+ new DefaultBlameOutput(null, analysisWarnings, singletonList(file)).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=\"http://sonarqube/v1/documentation/analysis/scm-integration/\" target=\"_blank\">the documentation</a>.");
+ "Please check the analysis logs and refer to <a href=\"/documentation/analysis/scm-integration/\" target=\"_blank\">the documentation</a>.");
}
@Test
public void shouldFailIfNotExpectedFile() {
InputFile file = new TestInputFileBuilder("foo", "src/main/java/Foo.java").build();
+ var blameOutput = new DefaultBlameOutput(null, analysisWarnings,
+ singletonList(new TestInputFileBuilder("foo", "src/main/java/Foo2.java").build()));
+ var lines = singletonList(new BlameLine().revision("1").author("guy"));
- assertThatThrownBy(() -> new DefaultBlameOutput(null, analysisWarnings,
- singletonList(new TestInputFileBuilder("foo", "src/main/java/Foo2.java").build()), client)
- .blameResult(file, singletonList(new BlameLine().revision("1").author("guy"))))
+ assertThatThrownBy(() -> blameOutput.blameResult(file, lines))
.isInstanceOf(IllegalArgumentException.class)
.hasMessage("It was not expected to blame file " + file);
}
@@ -71,9 +68,10 @@ public class DefaultBlameOutputTest {
@Test
public void shouldFailIfNullDate() {
InputFile file = new TestInputFileBuilder("foo", "src/main/java/Foo.java").setLines(1).build();
+ var blameOutput = new DefaultBlameOutput(null, analysisWarnings, singletonList(file));
+ var lines = singletonList(new BlameLine().revision("1").author("guy"));
- assertThatThrownBy(() -> new DefaultBlameOutput(null, analysisWarnings, singletonList(file), client)
- .blameResult(file, singletonList(new BlameLine().revision("1").author("guy"))))
+ assertThatThrownBy(() -> blameOutput.blameResult(file, lines))
.isInstanceOf(IllegalArgumentException.class)
.hasMessage("Blame date is null for file " + file + " at line 1");
}
@@ -81,9 +79,10 @@ public class DefaultBlameOutputTest {
@Test
public void shouldFailIfNullRevision() {
InputFile file = new TestInputFileBuilder("foo", "src/main/java/Foo.java").setLines(1).build();
+ var blameOUtput = new DefaultBlameOutput(null, analysisWarnings, singletonList(file));
+ var lines = singletonList(new BlameLine().date(new Date()).author("guy"));
- assertThatThrownBy(() -> new DefaultBlameOutput(null, analysisWarnings, singletonList(file), client)
- .blameResult(file, singletonList(new BlameLine().date(new Date()).author("guy"))))
+ assertThatThrownBy(() -> blameOUtput.blameResult(file, lines))
.isInstanceOf(IllegalArgumentException.class)
.hasMessage("Blame revision is blank for file " + file + " at line 1");
}
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 a98137a80f2..a3c9f88a0e0 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
@@ -60,7 +60,6 @@ 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;
@@ -120,7 +119,6 @@ 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 {
@@ -138,7 +136,7 @@ public class GitScmProviderTest {
@Test
public void returnImplem() {
JGitBlameCommand jblameCommand = new JGitBlameCommand(new PathResolver(), analysisWarnings);
- GitScmProvider gitScmProvider = new GitScmProvider(jblameCommand, analysisWarnings, gitIgnoreCommand, system2, client);
+ GitScmProvider gitScmProvider = new GitScmProvider(jblameCommand, analysisWarnings, gitIgnoreCommand, system2);
assertThat(gitScmProvider.blameCommand()).isEqualTo(jblameCommand);
}
@@ -627,7 +625,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, client) {
+ GitScmProvider provider = new GitScmProvider(mockCommand(), analysisWarnings, gitIgnoreCommand, system2) {
@Override
Repository buildRepo(Path basedir) throws IOException {
throw new IOException();
@@ -643,9 +641,8 @@ 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, client) {
+ GitScmProvider provider = new GitScmProvider(mockCommand(), analysisWarnings, gitIgnoreCommand, system2) {
@Override
Repository buildRepo(Path basedir) {
return repository;
@@ -660,7 +657,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=\"http://sonarqube.org/documentation/analysis/scm-integration/\" target=\"_blank\">the documentation</a>.";
+ + " and refer to <a href=\"/documentation/analysis/scm-integration/\" target=\"_blank\">the documentation</a>.";
verify(analysisWarnings).addUnique(warning);
}
@@ -675,7 +672,7 @@ public class GitScmProviderTest {
Git git = mock(Git.class);
when(git.diff()).thenReturn(diffCommand);
- GitScmProvider provider = new GitScmProvider(mockCommand(), analysisWarnings, gitIgnoreCommand, system2, client) {
+ GitScmProvider provider = new GitScmProvider(mockCommand(), analysisWarnings, gitIgnoreCommand, system2) {
@Override
Git newGit(Repository repo) {
return git;
@@ -708,7 +705,7 @@ public class GitScmProviderTest {
commit(f2);
AtomicInteger callCount = new AtomicInteger(0);
- GitScmProvider provider = new GitScmProvider(mockCommand(), analysisWarnings, gitIgnoreCommand, system2, client) {
+ GitScmProvider provider = new GitScmProvider(mockCommand(), analysisWarnings, gitIgnoreCommand, system2) {
@Override
AbstractTreeIterator prepareTreeParser(Repository repo, RevCommit commit) throws IOException {
if (callCount.getAndIncrement() == 1) {
@@ -727,7 +724,7 @@ public class GitScmProviderTest {
@Test
public void branchChangedLines_returns_null_on_io_errors_of_repo_builder() {
- GitScmProvider provider = new GitScmProvider(mockCommand(), analysisWarnings, gitIgnoreCommand, system2, client) {
+ GitScmProvider provider = new GitScmProvider(mockCommand(), analysisWarnings, gitIgnoreCommand, system2) {
@Override
Repository buildRepo(Path basedir) throws IOException {
throw new IOException();
@@ -742,7 +739,7 @@ public class GitScmProviderTest {
}
private GitScmProvider newGitScmProvider() {
- return new GitScmProvider(mock(JGitBlameCommand.class), analysisWarnings, gitIgnoreCommand, system2, client);
+ return new GitScmProvider(mock(JGitBlameCommand.class), analysisWarnings, gitIgnoreCommand, system2);
}
@Test
@@ -887,6 +884,6 @@ public class GitScmProviderTest {
}
private GitScmProvider newScmProvider() {
- return new GitScmProvider(mockCommand(), analysisWarnings, gitIgnoreCommand, system2, client);
+ return new GitScmProvider(mockCommand(), analysisWarnings, gitIgnoreCommand, system2);
}
}