Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Set up CI with Azure Pipelines #2826

Merged
merged 14 commits into from
Dec 10, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
441 changes: 441 additions & 0 deletions azure-pipelines.yml

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions its/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<parent>
<groupId>org.sonarsource.parent</groupId>
<artifactId>parent</artifactId>
<version>49</version>
<version>53</version>
</parent>

<groupId>com.sonarsource.it</groupId>
Expand All @@ -21,7 +21,7 @@
</organization>

<properties>
<scannerMsbuild.version>4.3.1.1372</scannerMsbuild.version>
<scannerMsbuild.version>4.7.1.2311</scannerMsbuild.version>
<surefire.argLine>-server</surefire.argLine>
</properties>

Expand Down
15 changes: 9 additions & 6 deletions its/src/test/java/com/sonar/it/csharp/AutoGeneratedTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

import com.sonar.it.shared.TestUtils;
import com.sonar.orchestrator.Orchestrator;
import com.sonar.orchestrator.build.ScannerForMSBuild;
import com.sonar.orchestrator.http.HttpMethod;
import java.io.IOException;
import java.nio.file.Path;
Expand All @@ -37,8 +38,8 @@ public class AutoGeneratedTest {
@ClassRule
public static final Orchestrator orchestrator = Tests.ORCHESTRATOR;

@Rule
public TemporaryFolder temp = new TemporaryFolder();
@ClassRule
public static TemporaryFolder temp = TestUtils.createTempFolder();

@Before
public void init() {
Expand Down Expand Up @@ -93,15 +94,17 @@ private void analyzeCoverageTestProject(String projectName, boolean analyzeGener
.execute();

Path projectDir = Tests.projectDir(temp, projectName);
orchestrator.executeBuild(TestUtils.newScanner(projectDir)

ScannerForMSBuild beginStep = TestUtils.newScanner(projectDir)
.addArgument("begin")
.setProjectKey(projectName)
.setProjectName(projectName)
.setProjectVersion("1.0"));
.setProjectVersion("1.0");

orchestrator.executeBuild(beginStep);

TestUtils.runMSBuild(orchestrator, projectDir, "/t:Rebuild");

orchestrator.executeBuild(TestUtils.newScanner(projectDir)
.addArgument("end"));
orchestrator.executeBuild(TestUtils.newEndStep(projectDir));
}
}
18 changes: 13 additions & 5 deletions its/src/test/java/com/sonar/it/csharp/CasingAppTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
package com.sonar.it.csharp;

import com.sonar.it.shared.TestUtils;
import com.sonar.orchestrator.build.ScannerForMSBuild;
import org.junit.Before;
import org.junit.ClassRule;
import org.junit.Rule;
Expand All @@ -29,6 +30,7 @@

import com.sonar.orchestrator.Orchestrator;

import java.io.File;
import java.io.IOException;
import java.nio.file.Path;
import java.util.List;
Expand All @@ -40,8 +42,9 @@
import static org.assertj.core.api.Assertions.assertThat;

public class CasingAppTest {

@Rule
public TemporaryFolder temp = new TemporaryFolder();
public TemporaryFolder temp = TestUtils.createTempFolder();

@ClassRule
public static final Orchestrator orchestrator = Tests.ORCHESTRATOR;
Expand All @@ -54,18 +57,23 @@ public void init() {
@Test
public void class1_should_have_metrics_and_issues() throws IOException {
Path projectDir = Tests.projectDir(temp, "CasingApp");
orchestrator.executeBuild(TestUtils.newScanner(projectDir)
String baseDir = projectDir.toString() + File.separator + "CasingApp";

ScannerForMSBuild beginStep = TestUtils.newScanner(projectDir)
.addArgument("begin")
.setProjectKey("CasingApp")
.setProjectName("CasingApp")
.setProjectVersion("1.0"));
.setProjectVersion("1.0")
.setProperty("sonar.projectBaseDir", baseDir);

orchestrator.executeBuild(beginStep);

TestUtils.runMSBuild(orchestrator, projectDir, "/t:Rebuild");

orchestrator.executeBuild(TestUtils.newScanner(projectDir)
.addArgument("end"));
orchestrator.executeBuild(TestUtils.newEndStep(projectDir));

String class1ComponentKey = TestUtils.hasModules(ORCHESTRATOR) ? "CasingApp:CasingApp:600E8C27-9AB2-48E9-AA48-2713E4B34288:SRC/Class1.cs" : "CasingApp:SRC/Class1.cs";

assertThat(getComponent(class1ComponentKey)).isNotNull();

assertThat(getMeasureAsInt(class1ComponentKey, "files")).isEqualTo(1);
Expand Down
35 changes: 24 additions & 11 deletions its/src/test/java/com/sonar/it/csharp/CoverageTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,11 @@
import com.sonar.orchestrator.Orchestrator;
import com.sonar.orchestrator.build.BuildResult;

import java.io.File;
import java.io.IOException;
import java.nio.file.Path;

import com.sonar.orchestrator.build.ScannerForMSBuild;
import org.junit.Before;
import org.junit.ClassRule;
import org.junit.Rule;
Expand All @@ -42,7 +45,7 @@ public class CoverageTest {
public static final Orchestrator orchestrator = Tests.ORCHESTRATOR;

@Rule
public TemporaryFolder temp = new TemporaryFolder();
public TemporaryFolder temp = TestUtils.createTempFolder();

@Before
public void init() {
Expand All @@ -66,7 +69,12 @@ public void should_not_import_coverage_without_report() throws Exception {

@Test
public void ncover3() throws Exception {
BuildResult buildResult = analyzeCoverageTestProject("sonar.cs.ncover3.reportsPaths", "reports/ncover3.nccov");

String reportPath = temp.getRoot().getAbsolutePath() + File.separator +
"CoverageTest" + File.separator +
"reports" + File.separator + "ncover3.nccov";

BuildResult buildResult = analyzeCoverageTestProject("sonar.cs.ncover3.reportsPaths", reportPath);

assertThat(buildResult.getLogs()).contains(
"Sensor C# Tests Coverage Report Import",
Expand Down Expand Up @@ -115,17 +123,20 @@ public void visual_studio() throws Exception {
@Test
public void no_coverage_on_tests() throws Exception {
Path projectDir = Tests.projectDir(temp, "NoCoverageOnTests");
orchestrator.executeBuild(TestUtils.newScanner(projectDir)

ScannerForMSBuild beginStep = TestUtils.newScanner(projectDir)
.addArgument("begin")
.setProjectKey("NoCoverageOnTests")
.setProjectVersion("1.0")
.setProfile("no_rule")
.setProperty("sonar.cs.vscoveragexml.reportsPaths", "reports/visualstudio.coveragexml"));
.setProperty("sonar.cs.vscoveragexml.reportsPaths", "reports/visualstudio.coveragexml")
.setProperty("sonar.projectBaseDir", projectDir.toString());

orchestrator.executeBuild(beginStep);

TestUtils.runMSBuild(orchestrator, projectDir, "/t:Rebuild");

BuildResult buildResult = orchestrator.executeBuild(TestUtils.newScanner(projectDir)
.addArgument("end"));
BuildResult buildResult = orchestrator.executeBuild(TestUtils.newEndStep(projectDir));

assertThat(buildResult.getLogs()).contains(
"Sensor C# Tests Coverage Report Import",
Expand All @@ -134,6 +145,7 @@ public void no_coverage_on_tests() throws Exception {

assertThat(getMeasureAsInt("NoCoverageOnTests", "files")).isEqualTo(2); // Only main files are counted
String unitTestComponentId = TestUtils.hasModules(ORCHESTRATOR) ? "NoCoverageOnTests:NoCoverageOnTests:8A3B715A-6E95-4BC1-93C6-A59E9D3F5D5C:UnitTest1.cs" : "NoCoverageOnTests:MyLib.Tests/UnitTest1.cs";

assertThat(Tests.getComponent(unitTestComponentId)).isNotNull();
assertThat(getMeasureAsInt("NoCoverageOnTests", "lines_to_cover")).isNull();
assertThat(getMeasureAsInt("NoCoverageOnTests", "uncovered_lines")).isNull();
Expand All @@ -152,18 +164,19 @@ public void should_support_wildcard_patterns() throws Exception {

private BuildResult analyzeCoverageTestProject(String... keyValues) throws IOException {
Path projectDir = Tests.projectDir(temp, "CoverageTest");
orchestrator.executeBuild(TestUtils.newScanner(projectDir)

ScannerForMSBuild beginStep = TestUtils.newScanner(projectDir)
.addArgument("begin")
.setProjectKey("CoverageTest")
.setProjectName("CoverageTest")
.setProjectVersion("1.0")
.setProfile("no_rule")
.setProperties(keyValues));
.setProperties(keyValues);

orchestrator.executeBuild(beginStep);

TestUtils.runMSBuild(orchestrator, projectDir, "/t:Rebuild");

return orchestrator.executeBuild(TestUtils.newScanner(projectDir)
.addArgument("end"));
return orchestrator.executeBuild(TestUtils.newEndStep(projectDir));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,11 @@

import com.sonar.it.shared.TestUtils;
import com.sonar.orchestrator.Orchestrator;

import java.io.File;
import java.nio.file.Path;

import com.sonar.orchestrator.build.ScannerForMSBuild;
import org.junit.Before;
import org.junit.ClassRule;
import org.junit.Rule;
Expand All @@ -35,7 +39,7 @@
public class DoNotAnalyzeTestFilesTest {

@Rule
public TemporaryFolder temp = new TemporaryFolder();
public TemporaryFolder temp = TestUtils.createTempFolder();

@ClassRule
public static final Orchestrator orchestrator = Tests.ORCHESTRATOR;
Expand All @@ -48,24 +52,26 @@ public void init() {
@Test
public void should_not_increment_test() throws Exception {
Path projectDir = Tests.projectDir(temp, "DoNotAnalyzeTestFilesTest");
orchestrator.executeBuild(TestUtils.newScanner(projectDir)

ScannerForMSBuild beginStep = TestUtils.newScanner(projectDir)
.addArgument("begin")
.setProjectKey("DoNotAnalyzeTestFilesTest")
.setProjectName("DoNotAnalyzeTestFilesTest")
.setProjectVersion("1.0")
.setProfile("no_rule")
.setProperty("sonar.cs.vscoveragexml.reportsPaths", "reports/visualstudio.coveragexml"));
.setProperty("sonar.cs.vscoveragexml.reportsPaths", "reports/visualstudio.coveragexml")
.setProperty("sonar.projectBaseDir", projectDir.toString() + File.separator + "MyLib.Tests");

orchestrator.executeBuild(beginStep);

TestUtils.runMSBuild(orchestrator, projectDir, "/t:Rebuild");

orchestrator.executeBuild(TestUtils.newScanner(projectDir)
.addArgument("end"));
orchestrator.executeBuild(TestUtils.newEndStep(projectDir));

String unitTestComponentId = TestUtils.hasModules(ORCHESTRATOR) ? "DoNotAnalyzeTestFilesTest:DoNotAnalyzeTestFilesTest:8A3B715A-6E95-4BC1-93C6-A59E9D3F5D5C:UnitTest1.cs" : "DoNotAnalyzeTestFilesTest:UnitTest1.cs";
assertThat(Tests.getComponent(unitTestComponentId)).isNotNull();
assertThat(getMeasureAsInt("DoNotAnalyzeTestFilesTest", "files")).isNull();
assertThat(getMeasureAsInt("DoNotAnalyzeTestFilesTest", "lines")).isNull();
assertThat(getMeasureAsInt("DoNotAnalyzeTestFilesTest", "ncloc")).isNull();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@
import java.io.FileWriter;
import java.io.IOException;
import java.nio.file.Path;

import com.sonar.orchestrator.build.ScannerForMSBuild;
import org.apache.commons.io.FileUtils;
import org.apache.commons.lang.SystemUtils;
import org.junit.ClassRule;
Expand All @@ -47,7 +49,7 @@
*/
public class MetricsIncludeHeaderCommentTest {

public static TemporaryFolder temp = new TemporaryFolder();
public static TemporaryFolder temp = TestUtils.createTempFolder();

private static final String PROJECT = "MetricsTest";
private static final String DIRECTORY = TestUtils.hasModules(ORCHESTRATOR) ? "MetricsTest:MetricsTest:1F026ECA-900A-488D-9D07-AD23216FA32B:foo" : "MetricsTest:foo";
Expand Down Expand Up @@ -80,21 +82,24 @@ protected void before() throws Throwable {
ORCHESTRATOR.resetData();

Path projectDir = Tests.projectDir(temp, "MetricsTest");
ORCHESTRATOR.executeBuild(TestUtils.newScanner(projectDir)

ScannerForMSBuild beginStep = TestUtils.newScanner(projectDir)
.addArgument("begin")
.setProjectKey("MetricsTest")
.setProjectName("MetricsTest")
.setProjectVersion("1.0")
.setProfile("no_rule")
// Without that, the MetricsTest project is considered as a Test project :)
.setProperty("sonar.msbuild.testProjectPattern", "noTests"));
.setProperty("sonar.msbuild.testProjectPattern", "noTests")
.setProperty("sonar.projectBaseDir", projectDir.toString());

ORCHESTRATOR.executeBuild(beginStep);

setIgnoreHeaderCommentsToFalse(projectDir);

TestUtils.runMSBuild(ORCHESTRATOR, projectDir, "/t:Rebuild");

ORCHESTRATOR.executeBuild(TestUtils.newScanner(projectDir)
.addArgument("end"));
ORCHESTRATOR.executeBuild(TestUtils.newEndStep(projectDir));
}
});
}
Expand All @@ -110,17 +115,17 @@ public void projectIsAnalyzed() {

@Test
public void linesAtProjectLevel() {
assertThat(getProjectMeasureAsInt("lines")).isEqualTo(117);
assertThat(getProjectMeasureAsInt("lines")).isEqualTo(118);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

note: this test MetricsIncludeHeaderCommentTest.java was not being run before on the QA (when I added it 6 months ago I forgot to update Tests.java). These metrics are the same with the ones in Metrics.java.

So these changes are fine

}

@Test
public void linesAtDirectoryLevel() {
assertThat(getDirectoryMeasureAsInt("lines")).isEqualTo(79);
assertThat(getDirectoryMeasureAsInt("lines")).isEqualTo(80);
}

@Test
public void linesAtFileLevel() {
assertThat(getFileMeasureAsInt("lines")).isEqualTo(41);
assertThat(getFileMeasureAsInt("lines")).isEqualTo(42);
}

/* Lines of code - must be the same */
Expand Down
14 changes: 9 additions & 5 deletions its/src/test/java/com/sonar/it/csharp/MetricsTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import java.io.IOException;
import java.nio.file.Path;

import com.sonar.orchestrator.build.ScannerForMSBuild;
import org.apache.commons.io.FileUtils;
import org.apache.commons.lang.SystemUtils;
import org.junit.ClassRule;
Expand All @@ -41,7 +42,7 @@

public class MetricsTest {

public static TemporaryFolder temp = new TemporaryFolder();
public static TemporaryFolder temp = TestUtils.createTempFolder();

private static final String PROJECT = "MetricsTest";
private static final String DIRECTORY = TestUtils.hasModules(ORCHESTRATOR) ? "MetricsTest:MetricsTest:1F026ECA-900A-488D-9D07-AD23216FA32B:foo" : "MetricsTest:foo";
Expand Down Expand Up @@ -73,19 +74,22 @@ protected void before() throws Throwable {
ORCHESTRATOR.resetData();

Path projectDir = Tests.projectDir(temp, "MetricsTest");
ORCHESTRATOR.executeBuild(TestUtils.newScanner(projectDir)

ScannerForMSBuild beginStep = TestUtils.newScanner(projectDir)
.addArgument("begin")
.setProjectKey("MetricsTest")
.setProjectName("MetricsTest")
.setProjectVersion("1.0")
.setProfile("no_rule")
// Without that, the MetricsTest project is considered as a Test project :)
.setProperty("sonar.msbuild.testProjectPattern", "noTests"));
.setProperty("sonar.msbuild.testProjectPattern", "noTests")
.setProperty("sonar.projectBaseDir", projectDir.toString());

ORCHESTRATOR.executeBuild(beginStep);

TestUtils.runMSBuild(ORCHESTRATOR, projectDir, "/t:Rebuild");

ORCHESTRATOR.executeBuild(TestUtils.newScanner(projectDir)
.addArgument("end"));
ORCHESTRATOR.executeBuild(TestUtils.newEndStep(projectDir));
}
});
}
Expand Down
Loading