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

support Cobertura coverage reports with drive letter only in source tag #2268

Merged
merged 1 commit into from
Oct 22, 2021
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
8 changes: 4 additions & 4 deletions appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ install:
}
(new-object System.Net.WebClient).DownloadFile(
'https://www-us.apache.org/dist/maven/maven-3/3.6.3/binaries/apache-maven-3.6.3-bin.zip',
'https://dlcdn.apache.org/maven/maven-3/3.8.3/binaries/apache-maven-3.8.3-bin.zip',
'C:\maven-bin.zip'
)
[System.IO.Compression.ZipFile]::ExtractToDirectory("C:\maven-bin.zip", "C:\maven")
Expand Down Expand Up @@ -62,9 +62,9 @@ install:
$env:VCVARS_PLATFORM="amd64"
$env:LANG_PLATFORM="-x64"
}
- cmd: SET PATH=C:\maven\apache-maven-3.6.3\bin;%JAVA_HOME%\bin;C:\sonar-scanner\sonar-scanner-4.6.2.2472\bin;%PATH%
- cmd: SET M2_HOME=C:\maven\apache-maven-3.6.3
- cmd: SET MAVEN_HOME=C:\maven\apache-maven-3.6.3
- cmd: SET PATH=C:\maven\apache-maven-3.8.3\bin;%JAVA_HOME%\bin;C:\sonar-scanner\sonar-scanner-4.6.2.2472\bin;%PATH%
- cmd: SET M2_HOME=C:\maven\apache-maven-3.8.3
- cmd: SET MAVEN_HOME=C:\maven\apache-maven-3.8.3
- cmd: SET SONARHOME=C:\sonarqube\sonarqube-8.9.2.46101
- cmd: SET TestDataFolder=C:\projects\sonar-cxx\integration-tests\testdata
- cmd: SET
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,13 +49,13 @@ public class CoberturaParser implements CoverageParser {
/**
* Join two paths
*
* path1 | path2 | result
* path1 | path2 | result
* ---------|----------|-------
* empty | empty | empty
* empty | absolute | absolute path2
* empty | relative | relative path2
* absolute | empty | empty
* relative | empty | empty
* empty | empty | empty
* empty | absolute | absolute path2
* empty | relative | relative path2
* absolute | empty | empty
* relative | empty | empty
* absolute | absolute | absolute path2
* absolute | relative | absolute path1 + relative path2
* relative | absolute | absolute path2
Expand All @@ -70,7 +70,12 @@ public static String join(Path path1, Path path2) {
return "";
}
if (!path1.isAbsolute()) {
path1 = Paths.get(".", path1.toString());
var root = path1.getRoot();
if (root != null && !root.toString().endsWith(File.separator)) { // special case drive letter only, e.g. c:
path1 = Paths.get(path1.toString(), File.separator);
} else {
path1 = Paths.get(".", path1.toString());
}
}
if (!path2.isAbsolute()) {
path2 = Paths.get(".", path2.toString());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,70 +75,79 @@ public void testPathJoin() {
if (TestUtils.isWindows()) {

// Windows
var abs1 = Paths.get("c:\\test1");
var rel1 = Paths.get("\\test1");
var abs2 = Paths.get("c:\\test2\\report.txt");
var rel2 = Paths.get("\\test2\\report.txt");
var p1_abs1 = Paths.get("c:\\test1");
var p1_abs2 = Paths.get("c:");
var p1_abs3 = Paths.get("c:\\");
var p1_rel1 = Paths.get("\\test1");
var p2_abs1 = Paths.get("c:\\test2\\report.txt");
var p2_rel1 = Paths.get("\\test2\\report.txt");
var p2_rel2 = Paths.get("test2\\report.txt");

result = CoberturaParser.join(empty, empty);
assertThat(result).isEmpty();

result = CoberturaParser.join(empty, abs2);
result = CoberturaParser.join(empty, p2_abs1);
assertThat(result).isEqualTo("c:\\test2\\report.txt");

result = CoberturaParser.join(empty, rel2);
result = CoberturaParser.join(empty, p2_rel1);
assertThat(result).isEqualTo(".\\test2\\report.txt");

result = CoberturaParser.join(abs1, empty);
result = CoberturaParser.join(p1_abs1, empty);
assertThat(result).isEmpty();

result = CoberturaParser.join(rel1, empty);
result = CoberturaParser.join(p1_rel1, empty);
assertThat(result).isEmpty();

result = CoberturaParser.join(abs1, abs2);
result = CoberturaParser.join(p1_abs1, p2_abs1);
assertThat(result).isEqualTo("c:\\test2\\report.txt");

result = CoberturaParser.join(abs1, rel2);
result = CoberturaParser.join(p1_abs1, p2_rel1);
assertThat(result).isEqualTo("c:\\test1\\test2\\report.txt");

result = CoberturaParser.join(rel1, abs2);
result = CoberturaParser.join(p1_rel1, p2_abs1);
assertThat(result).isEqualTo("c:\\test2\\report.txt");

result = CoberturaParser.join(rel1, rel2);
result = CoberturaParser.join(p1_rel1, p2_rel1);
assertThat(result).isEqualTo(".\\test1\\test2\\report.txt");

result = CoberturaParser.join(p1_abs2, p2_rel2);
assertThat(result).isEqualTo("c:\\test2\\report.txt");

result = CoberturaParser.join(p1_abs3, p2_rel2);
assertThat(result).isEqualTo("c:\\test2\\report.txt");
} else {

// Linux
var abs1 = Paths.get("/home/test1");
var rel1 = Paths.get("test1");
var abs2 = Paths.get("/home/test2/report.txt");
var rel2 = Paths.get("test2/report.txt");
var p1_abs1 = Paths.get("/home/test1");
var p1_rel1 = Paths.get("test1");
var p2_abs1 = Paths.get("/home/test2/report.txt");
var p2_rel1 = Paths.get("test2/report.txt");

result = CoberturaParser.join(empty, empty);
assertThat(result).isEmpty();

result = CoberturaParser.join(empty, abs2);
result = CoberturaParser.join(empty, p2_abs1);
assertThat(result).isEqualTo("/home/test2/report.txt");

result = CoberturaParser.join(empty, rel2);
result = CoberturaParser.join(empty, p2_rel1);
assertThat(result).isEqualTo("./test2/report.txt");

result = CoberturaParser.join(abs1, empty);
result = CoberturaParser.join(p1_abs1, empty);
assertThat(result).isEmpty();

result = CoberturaParser.join(rel1, empty);
result = CoberturaParser.join(p1_rel1, empty);
assertThat(result).isEmpty();

result = CoberturaParser.join(abs1, abs2);
result = CoberturaParser.join(p1_abs1, p2_abs1);
assertThat(result).isEqualTo("/home/test2/report.txt");

result = CoberturaParser.join(abs1, rel2);
result = CoberturaParser.join(p1_abs1, p2_rel1);
assertThat(result).isEqualTo("/home/test1/test2/report.txt");

result = CoberturaParser.join(rel1, abs2);
result = CoberturaParser.join(p1_rel1, p2_abs1);
assertThat(result).isEqualTo("/home/test2/report.txt");

result = CoberturaParser.join(rel1, rel2);
result = CoberturaParser.join(p1_rel1, p2_rel1);
assertThat(result).isEqualTo("./test1/test2/report.txt");
}

Expand Down