aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-scanner-engine
diff options
context:
space:
mode:
authorJanos Gyerik <janos.gyerik@sonarsource.com>2017-01-31 15:57:10 +0100
committerGitHub <noreply@github.com>2017-01-31 15:57:10 +0100
commit8a08d8d93634e061f928e2f03edbee5f7b5a377e (patch)
tree086fc72c0da61902e47f10d87c9df358fc2fddfc /sonar-scanner-engine
parenta08474177de41d48905b7184f84888cb2209485e (diff)
downloadsonarqube-8a08d8d93634e061f928e2f03edbee5f7b5a377e.tar.gz
sonarqube-8a08d8d93634e061f928e2f03edbee5f7b5a377e.zip
Add OneIssuePerDirectory rule in Xoo (#1606)
Diffstat (limited to 'sonar-scanner-engine')
-rw-r--r--sonar-scanner-engine/src/test/java/org/sonar/scanner/mediumtest/fs/FileSystemMediumTest.java51
1 files changed, 51 insertions, 0 deletions
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 1aaa9b7b02f..6e777488397 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
@@ -20,6 +20,9 @@
package org.sonar.scanner.mediumtest.fs;
import com.google.common.collect.ImmutableMap;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.Paths;
import org.apache.commons.io.FileUtils;
import org.apache.commons.lang.StringUtils;
import org.junit.After;
@@ -273,6 +276,54 @@ public class FileSystemMediumTest {
}
@Test
+ public void publishDirsWithIssues() throws IOException {
+ ScannerMediumTester tester2 = ScannerMediumTester.builder()
+ .registerPlugin("xoo", new XooPlugin())
+ .addDefaultQProfile("xoo", "Sonar Way")
+ .addRules(new XooRulesDefinition())
+ .addActiveRule("xoo", "OneIssuePerDirectory", null, "OneIssuePerDirectory", "MAJOR", null, "xoo")
+ .build();
+ tester2.start();
+
+ builder = ImmutableMap.<String, String>builder()
+ .put("sonar.task", "scan")
+ .put("sonar.verbose", "true")
+ .put("sonar.projectBaseDir", baseDir.getAbsolutePath())
+ .put("sonar.projectKey", "com.foo.project")
+ .put("sonar.projectVersion", "1.0-SNAPSHOT")
+ .put("sonar.projectDescription", "Description of Foo Project");
+
+ Path unknownRelative = Paths.get("src/unknown/file.unknown");
+ Path unknown = baseDir.toPath().resolve(unknownRelative);
+ Files.createDirectories(unknown.getParent());
+ Files.write(unknown, "dummy content".getBytes());
+
+ Path emptyDirRelative = Paths.get("src/emptydir");
+ Files.createDirectories(emptyDirRelative);
+
+ TaskResult result = tester2.newTask()
+ .properties(builder
+ .put("sonar.sources", "src")
+ .build())
+ .start();
+
+ DefaultInputFile unknownInputFile = (DefaultInputFile) result.inputFile(unknownRelative.toString());
+ InputDir unknownInputDir = result.inputDir(unknownRelative.getParent().toString());
+ assertThat(unknownInputFile.publish()).isFalse();
+ assertThat(result.getReportComponent(unknownInputDir.key())).isNotNull();
+
+ // no issues on empty dir
+ InputDir emptyInputDir = result.inputDir(emptyDirRelative.toString());
+ assertThat(emptyInputDir).isNull();
+
+ // no issues on parent dir
+ InputDir parentInputDir = result.inputDir(unknownRelative.getParent().getParent().toString());
+ assertThat(parentInputDir).isNull();
+
+ tester2.stop();
+ }
+
+ @Test
public void scanProjectWithSourceDir() throws IOException {
File srcDir = new File(baseDir, "src");
srcDir.mkdir();