aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-scanner-engine/src/test
diff options
context:
space:
mode:
authorMichal Duda <michal.duda@sonarsource.com>2019-06-13 17:27:43 +0200
committerSonarTech <sonartech@sonarsource.com>2019-06-15 20:21:05 +0200
commit7054dc9bf9ddd30eebf038094d6cc9b4a3be5db2 (patch)
tree13edb4537b7f18299021b626aced6115fc0970d9 /sonar-scanner-engine/src/test
parent382e45e3126fadc557464d52eb9ce73ee9d1bcaa (diff)
downloadsonarqube-7054dc9bf9ddd30eebf038094d6cc9b4a3be5db2.tar.gz
sonarqube-7054dc9bf9ddd30eebf038094d6cc9b4a3be5db2.zip
SONAR-12182 drop "sonar.branch" from SQ
Diffstat (limited to 'sonar-scanner-engine/src/test')
-rw-r--r--sonar-scanner-engine/src/test/java/org/sonar/scanner/mediumtest/ScannerMediumTester.java47
-rw-r--r--sonar-scanner-engine/src/test/java/org/sonar/scanner/mediumtest/branch/DeprecatedBranchMediumTest.java45
-rw-r--r--sonar-scanner-engine/src/test/java/org/sonar/scanner/mediumtest/fs/FileSystemMediumTest.java7
-rw-r--r--sonar-scanner-engine/src/test/java/org/sonar/scanner/mediumtest/fs/ProjectBuilderMediumTest.java2
-rw-r--r--sonar-scanner-engine/src/test/java/org/sonar/scanner/mediumtest/scm/ScmMediumTest.java2
5 files changed, 93 insertions, 10 deletions
diff --git a/sonar-scanner-engine/src/test/java/org/sonar/scanner/mediumtest/ScannerMediumTester.java b/sonar-scanner-engine/src/test/java/org/sonar/scanner/mediumtest/ScannerMediumTester.java
index 28cb9ba3ed8..2eb7a188e8b 100644
--- a/sonar-scanner-engine/src/test/java/org/sonar/scanner/mediumtest/ScannerMediumTester.java
+++ b/sonar-scanner-engine/src/test/java/org/sonar/scanner/mediumtest/ScannerMediumTester.java
@@ -41,12 +41,17 @@ import javax.annotation.Nullable;
import org.apache.commons.io.FileUtils;
import org.junit.rules.ExternalResource;
import org.sonar.api.Plugin;
+import org.sonar.api.SonarEdition;
+import org.sonar.api.SonarProduct;
+import org.sonar.api.SonarQubeSide;
+import org.sonar.api.SonarRuntime;
import org.sonar.api.measures.CoreMetrics;
import org.sonar.api.measures.Metric;
import org.sonar.api.rule.RuleKey;
import org.sonar.api.server.rule.RulesDefinition;
import org.sonar.api.server.rule.RulesDefinition.Repository;
import org.sonar.api.utils.DateUtils;
+import org.sonar.api.utils.Version;
import org.sonar.batch.bootstrapper.Batch;
import org.sonar.batch.bootstrapper.EnvironmentInformation;
import org.sonar.batch.bootstrapper.LogOutput;
@@ -89,6 +94,7 @@ public class ScannerMediumTester extends ExternalResource {
private final FakeRulesLoader rulesLoader = new FakeRulesLoader();
private final FakeQualityProfileLoader qualityProfiles = new FakeQualityProfileLoader();
private final FakeActiveRulesLoader activeRules = new FakeActiveRulesLoader();
+ private final FakeSonarRuntime sonarRuntime = new FakeSonarRuntime();
private LogOutput logOutput = null;
private static void createWorkingDirs() throws IOException {
@@ -220,7 +226,7 @@ public class ScannerMediumTester extends ExternalResource {
}
@Override
- protected void before() throws Throwable {
+ protected void before() {
try {
createWorkingDirs();
} catch (IOException e) {
@@ -287,6 +293,7 @@ public class ScannerMediumTester extends ExternalResource {
tester.activeRules,
tester.globalSettingsLoader,
tester.projectSettingsLoader,
+ tester.sonarRuntime,
result)
.setLogOutput(tester.logOutput)
.build().execute();
@@ -404,6 +411,39 @@ public class ScannerMediumTester extends ExternalResource {
}
}
+ private static class FakeSonarRuntime implements SonarRuntime {
+
+ private SonarEdition edition;
+
+ FakeSonarRuntime() {
+ this.edition = SonarEdition.COMMUNITY;
+ }
+
+ @Override
+ public Version getApiVersion() {
+ return Version.create(7, 8);
+ }
+
+ @Override
+ public SonarProduct getProduct() {
+ return SonarProduct.SONARQUBE;
+ }
+
+ @Override
+ public SonarQubeSide getSonarQubeSide() {
+ return SonarQubeSide.SCANNER;
+ }
+
+ @Override
+ public SonarEdition getEdition() {
+ return edition;
+ }
+
+ public void setEdition(SonarEdition edition) {
+ this.edition = edition;
+ }
+ }
+
public ScannerMediumTester setBranchType(BranchType branchType) {
branchConfiguration.branchType = branchType;
return this;
@@ -424,6 +464,11 @@ public class ScannerMediumTester extends ExternalResource {
return this;
}
+ public ScannerMediumTester setEdition(SonarEdition edition) {
+ this.sonarRuntime.setEdition(edition);
+ return this;
+ }
+
private class FakeBranchConfigurationLoader implements BranchConfigurationLoader {
@Override
public BranchConfiguration load(Map<String, String> localSettings, Supplier<Map<String, String>> settingsSupplier, ProjectBranches branches, ProjectPullRequests pullRequests) {
diff --git a/sonar-scanner-engine/src/test/java/org/sonar/scanner/mediumtest/branch/DeprecatedBranchMediumTest.java b/sonar-scanner-engine/src/test/java/org/sonar/scanner/mediumtest/branch/DeprecatedBranchMediumTest.java
index 41ea161bc72..627e285af3a 100644
--- a/sonar-scanner-engine/src/test/java/org/sonar/scanner/mediumtest/branch/DeprecatedBranchMediumTest.java
+++ b/sonar-scanner-engine/src/test/java/org/sonar/scanner/mediumtest/branch/DeprecatedBranchMediumTest.java
@@ -31,9 +31,11 @@ import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.junit.rules.TemporaryFolder;
+import org.sonar.api.SonarEdition;
import org.sonar.api.batch.fs.internal.DefaultInputFile;
-import org.sonar.scanner.mediumtest.ScannerMediumTester;
+import org.sonar.api.utils.MessageException;
import org.sonar.scanner.mediumtest.AnalysisResult;
+import org.sonar.scanner.mediumtest.ScannerMediumTester;
import org.sonar.xoo.XooPlugin;
import org.sonar.xoo.rule.XooRulesDefinition;
@@ -55,6 +57,15 @@ public class DeprecatedBranchMediumTest {
.addActiveRule("xoo", "xoo:OneIssuePerFile", null, "One Issue Per File", null, null, null)
.addDefaultQProfile("xoo", "Sonar Way");
+ @Rule
+ public ScannerMediumTester testerSC = new ScannerMediumTester()
+ .setEdition(SonarEdition.SONARCLOUD)
+ .registerPlugin("xoo", new XooPlugin())
+ .addRules(new XooRulesDefinition())
+ // active a rule just to be sure that xoo files are published
+ .addActiveRule("xoo", "xoo:OneIssuePerFile", null, "One Issue Per File", null, null, null)
+ .addDefaultQProfile("xoo", "Sonar Way");
+
private File baseDir;
private Map<String, String> commonProps;
@@ -75,14 +86,34 @@ public class DeprecatedBranchMediumTest {
}
@Test
- public void scanProjectWithBranch() throws IOException {
+ public void scanProjectWithBranchOnSonarQube() throws IOException {
+ File srcDir = new File(baseDir, "src");
+ srcDir.mkdir();
+
+ File xooFile = new File(srcDir, "sample.xoo");
+ FileUtils.write(xooFile, "Sample xoo\ncontent");
+
+ thrown.expect(MessageException.class);
+ thrown.expectMessage("The 'sonar.branch' parameter is no longer supported. You should stop using it. " +
+ "Branch analysis is available in Developer Edition and above. See https://redirect.sonarsource.com/editions/developer.html for more information.");
+
+ tester.newAnalysis()
+ .properties(ImmutableMap.<String, String>builder()
+ .putAll(commonProps)
+ .put("sonar.branch", "branch")
+ .build())
+ .execute();
+ }
+
+ @Test
+ public void scanProjectWithBranchOnSonarCloud() throws IOException {
File srcDir = new File(baseDir, "src");
srcDir.mkdir();
File xooFile = new File(srcDir, "sample.xoo");
FileUtils.write(xooFile, "Sample xoo\ncontent");
- AnalysisResult result = tester.newAnalysis()
+ AnalysisResult result = testerSC.newAnalysis()
.properties(ImmutableMap.<String, String>builder()
.putAll(commonProps)
.put("sonar.branch", "branch")
@@ -97,7 +128,7 @@ public class DeprecatedBranchMediumTest {
assertThat(result.getReportReader().readMetadata().getDeprecatedBranch()).isEqualTo("branch");
- result = tester.newAnalysis()
+ result = testerSC.newAnalysis()
.properties(ImmutableMap.<String, String>builder()
.putAll(commonProps)
.put("sonar.branch", "")
@@ -109,14 +140,14 @@ public class DeprecatedBranchMediumTest {
}
@Test
- public void scanMultiModuleWithBranch() throws IOException {
+ public void scanMultiModuleWithBranchOnSonarCloud() throws IOException {
Path srcDir = baseDir.toPath().resolve("moduleA").resolve("src");
Files.createDirectories(srcDir);
File xooFile = new File(srcDir.toFile(), "sample.xoo");
FileUtils.write(xooFile, "Sample xoo\ncontent");
- AnalysisResult result = tester.newAnalysis()
+ AnalysisResult result = testerSC.newAnalysis()
.properties(ImmutableMap.<String, String>builder()
.putAll(commonProps)
.put("sonar.branch", "branch")
@@ -133,7 +164,7 @@ public class DeprecatedBranchMediumTest {
assertThat(result.getReportReader().readMetadata().getDeprecatedBranch()).isEqualTo("branch");
- result = tester.newAnalysis()
+ result = testerSC.newAnalysis()
.properties(ImmutableMap.<String, String>builder()
.putAll(commonProps)
.put("sonar.branch", "")
diff --git a/sonar-scanner-engine/src/test/java/org/sonar/scanner/mediumtest/fs/FileSystemMediumTest.java b/sonar-scanner-engine/src/test/java/org/sonar/scanner/mediumtest/fs/FileSystemMediumTest.java
index af073681944..cb1537ae00c 100644
--- a/sonar-scanner-engine/src/test/java/org/sonar/scanner/mediumtest/fs/FileSystemMediumTest.java
+++ b/sonar-scanner-engine/src/test/java/org/sonar/scanner/mediumtest/fs/FileSystemMediumTest.java
@@ -34,6 +34,7 @@ import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.junit.rules.TemporaryFolder;
import org.sonar.api.CoreProperties;
+import org.sonar.api.SonarEdition;
import org.sonar.api.batch.fs.InputFile;
import org.sonar.api.batch.fs.internal.DefaultInputFile;
import org.sonar.api.utils.MessageException;
@@ -65,6 +66,7 @@ public class FileSystemMediumTest {
@Rule
public ScannerMediumTester tester = new ScannerMediumTester()
+ .setEdition(SonarEdition.SONARCLOUD)
.registerPlugin("xoo", new XooPlugin())
.addDefaultQProfile("xoo", "Sonar Way")
.addDefaultQProfile("xoo2", "Sonar Way");
@@ -152,7 +154,7 @@ public class FileSystemMediumTest {
}
@Test
- public void logBranchNameAndType() throws IOException {
+ public void logBranchNameAndType() {
builder.put("sonar.branch.name", "my-branch");
File srcDir = new File(baseDir, "src");
assertThat(srcDir.mkdir()).isTrue();
@@ -1065,7 +1067,8 @@ public class FileSystemMediumTest {
.execute();
assertThat(result.inputFiles()).hasSize(1);
- assertThat(logTester.logs(LoggerLevel.WARN)).contains("File '" + xooFile2.getAbsolutePath() + "' is ignored. It is not located in module basedir '" + new File(baseDir, "moduleA") + "'.");
+ assertThat(logTester.logs(LoggerLevel.WARN))
+ .contains("File '" + xooFile2.getAbsolutePath() + "' is ignored. It is not located in module basedir '" + new File(baseDir, "moduleA") + "'.");
}
@Test
diff --git a/sonar-scanner-engine/src/test/java/org/sonar/scanner/mediumtest/fs/ProjectBuilderMediumTest.java b/sonar-scanner-engine/src/test/java/org/sonar/scanner/mediumtest/fs/ProjectBuilderMediumTest.java
index f61411b4898..b90b24d96e7 100644
--- a/sonar-scanner-engine/src/test/java/org/sonar/scanner/mediumtest/fs/ProjectBuilderMediumTest.java
+++ b/sonar-scanner-engine/src/test/java/org/sonar/scanner/mediumtest/fs/ProjectBuilderMediumTest.java
@@ -30,6 +30,7 @@ import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.junit.rules.TemporaryFolder;
+import org.sonar.api.SonarEdition;
import org.sonar.api.batch.bootstrap.ProjectBuilder;
import org.sonar.api.utils.MessageException;
import org.sonar.scanner.mediumtest.AnalysisResult;
@@ -56,6 +57,7 @@ public class ProjectBuilderMediumTest {
@Rule
public ScannerMediumTester tester = new ScannerMediumTester()
+ .setEdition(SonarEdition.SONARCLOUD)
.registerPlugin("xoo", new XooPluginWithBuilder(projectBuilder))
.addRules(new XooRulesDefinition())
.addDefaultQProfile("xoo", "Sonar Way")
diff --git a/sonar-scanner-engine/src/test/java/org/sonar/scanner/mediumtest/scm/ScmMediumTest.java b/sonar-scanner-engine/src/test/java/org/sonar/scanner/mediumtest/scm/ScmMediumTest.java
index b317ac1c4cb..16d3e528e91 100644
--- a/sonar-scanner-engine/src/test/java/org/sonar/scanner/mediumtest/scm/ScmMediumTest.java
+++ b/sonar-scanner-engine/src/test/java/org/sonar/scanner/mediumtest/scm/ScmMediumTest.java
@@ -31,6 +31,7 @@ import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.junit.rules.TemporaryFolder;
+import org.sonar.api.SonarEdition;
import org.sonar.api.utils.log.LogTester;
import org.sonar.scanner.mediumtest.ScannerMediumTester;
import org.sonar.scanner.mediumtest.ScannerMediumTester.AnalysisBuilder;
@@ -64,6 +65,7 @@ public class ScmMediumTest {
@Rule
public ScannerMediumTester tester = new ScannerMediumTester()
+ .setEdition(SonarEdition.SONARCLOUD)
.registerPlugin("xoo", new XooPlugin())
.addDefaultQProfile("xoo", "Sonar Way")
.addRules(new XooRulesDefinition())