From: Julien HENRY Date: Wed, 12 Apr 2017 13:35:13 +0000 (+0200) Subject: SQSCANNER-39 Don't filter properties with blank value X-Git-Tag: 3.0.1.733~2 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=3f8feb090594863155ce0cb1451128559965836d;p=sonar-scanner-cli.git SQSCANNER-39 Don't filter properties with blank value --- diff --git a/it/pom.xml b/it/pom.xml index ea1dfac..4e3e090 100644 --- a/it/pom.xml +++ b/it/pom.xml @@ -6,7 +6,7 @@ org.sonarsource.parent parent - 37 + 40 diff --git a/it/src/test/java/com/sonar/runner/it/JavaTest.java b/it/src/test/java/com/sonar/runner/it/JavaTest.java index 3519159..2e7f95c 100644 --- a/it/src/test/java/com/sonar/runner/it/JavaTest.java +++ b/it/src/test/java/com/sonar/runner/it/JavaTest.java @@ -60,8 +60,7 @@ public class JavaTest extends ScannerTestCase { orchestrator.getServer().associateProjectToQualityProfile("java:sample", "java", "sonar-way"); SonarScanner build = newScanner(new File("projects/java-sample")) - .setProperty("sonar.verbose", "true") - .addArguments("-e"); + .setProperty("sonar.verbose", "true"); // SONARPLUGINS-3061 // Add a trailing slash build.setProperty("sonar.host.url", orchestrator.getServer().getUrl() + "/"); @@ -86,6 +85,26 @@ public class JavaTest extends ScannerTestCase { assertThat(parseInt(fileMeasures.get("violations").getValue())).isGreaterThan(0); } + /** + * Only tests, no sources + */ + @Test + public void scan_java_tests() { + orchestrator.getServer().restoreProfile(ResourceLocation.create("/sonar-way-profile.xml")); + orchestrator.getServer().provisionProject("java:sampletest", "Java Sample"); + orchestrator.getServer().associateProjectToQualityProfile("java:sampletest", "java", "sonar-way"); + + SonarScanner build = newScanner(new File("projects/java-sample")) + .setProperty("sonar.projectKey", "java:sampletest") + .setProperty("sonar.tests", "src") + .setProperty("sonar.sources", ""); + orchestrator.executeBuild(build); + + Component file = getComponent("java:sampletest:src/basic/Hello.java"); + assertThat(file.getName()).isEqualTo("Hello.java"); + assertThat(file.getQualifier()).isEqualTo("UTS"); + } + @Test public void scan_java_sources_and_bytecode() { orchestrator.getServer().restoreProfile(ResourceLocation.create("/requires-bytecode-profile.xml")); diff --git a/pom.xml b/pom.xml index b25c8a0..abaa87f 100644 --- a/pom.xml +++ b/pom.xml @@ -8,7 +8,7 @@ org.sonarsource.scanner.cli sonar-scanner-cli - 3.0-SNAPSHOT + 3.0.1-SNAPSHOT jar SonarQube Scanner http://docs.sonarqube.org/display/SONAR/Analyzing+with+SonarQube+Scanner diff --git a/src/main/java/org/sonarsource/scanner/cli/PropertyResolver.java b/src/main/java/org/sonarsource/scanner/cli/PropertyResolver.java index d1fe2c8..d92f7fe 100644 --- a/src/main/java/org/sonarsource/scanner/cli/PropertyResolver.java +++ b/src/main/java/org/sonarsource/scanner/cli/PropertyResolver.java @@ -67,6 +67,7 @@ public class PropertyResolver { private String resolveProperty(String propKey) { String propValue = getValue(propKey); if (propValue.isEmpty()) { + resolved.setProperty(propKey, propValue); return propValue; } diff --git a/src/test/java/org/sonarsource/scanner/cli/PropertyResolverTest.java b/src/test/java/org/sonarsource/scanner/cli/PropertyResolverTest.java index cece2a0..eecca98 100644 --- a/src/test/java/org/sonarsource/scanner/cli/PropertyResolverTest.java +++ b/src/test/java/org/sonarsource/scanner/cli/PropertyResolverTest.java @@ -19,16 +19,15 @@ */ package org.sonarsource.scanner.cli; -import static org.assertj.core.api.Assertions.assertThat; - import java.util.HashMap; import java.util.Map; import java.util.Properties; - import org.junit.Rule; import org.junit.Test; import org.junit.rules.ExpectedException; +import static org.assertj.core.api.Assertions.assertThat; + public class PropertyResolverTest { @Rule public ExpectedException exception = ExpectedException.none(); @@ -120,4 +119,18 @@ public class PropertyResolverTest { PropertyResolver resolver = new PropertyResolver(map, env); resolver.resolve(); } + + @Test + public void preserve_empty() { + Properties map = new Properties(); + Map env = new HashMap<>(); + + map.put("A", ""); + map.put("B", "${A}"); + + PropertyResolver resolver = new PropertyResolver(map, env); + Properties resolved = resolver.resolve(); + assertThat(resolved.get("A")).isEqualTo(""); + assertThat(resolved.get("B")).isEqualTo(""); + } }