aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-scanner-engine
diff options
context:
space:
mode:
authorMichal Duda <michalno1@gmail.com>2018-11-13 11:00:42 +0100
committersonartech <sonartech@sonarsource.com>2019-01-16 09:43:00 +0100
commit6dd294b1f5af7c74191db30101e3721d00102204 (patch)
tree372dbc219371a610c32fb8b723869291a7148c5f /sonar-scanner-engine
parentb44c75c2b93ca2d91d6ce559a08a0d994c73bd85 (diff)
downloadsonarqube-6dd294b1f5af7c74191db30101e3721d00102204.tar.gz
sonarqube-6dd294b1f5af7c74191db30101e3721d00102204.zip
SONAR-11459 move dir and module issues to root
Diffstat (limited to 'sonar-scanner-engine')
-rw-r--r--sonar-scanner-engine/src/main/java/org/sonar/scanner/mediumtest/TaskResult.java8
-rw-r--r--sonar-scanner-engine/src/main/java/org/sonar/scanner/sensor/DefaultSensorContext.java9
-rw-r--r--sonar-scanner-engine/src/test/java/org/sonar/scanner/issue/ModuleIssuesTest.java47
-rw-r--r--sonar-scanner-engine/src/test/java/org/sonar/scanner/mediumtest/fs/FileSystemMediumTest.java6
-rw-r--r--sonar-scanner-engine/src/test/java/org/sonar/scanner/mediumtest/issues/IssuesOnDirMediumTest.java6
-rw-r--r--sonar-scanner-engine/src/test/java/org/sonar/scanner/sensor/DefaultSensorContextTest.java10
-rw-r--r--sonar-scanner-engine/src/test/java/org/sonar/scanner/sensor/DefaultSensorStorageTest.java12
7 files changed, 77 insertions, 21 deletions
diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/mediumtest/TaskResult.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/mediumtest/TaskResult.java
index b510f895a51..d2ea9681433 100644
--- a/sonar-scanner-engine/src/main/java/org/sonar/scanner/mediumtest/TaskResult.java
+++ b/sonar-scanner-engine/src/main/java/org/sonar/scanner/mediumtest/TaskResult.java
@@ -36,6 +36,7 @@ import org.sonar.api.batch.AnalysisMode;
import org.sonar.api.batch.fs.InputComponent;
import org.sonar.api.batch.fs.InputDir;
import org.sonar.api.batch.fs.InputFile;
+import org.sonar.api.batch.fs.InputModule;
import org.sonar.api.batch.fs.TextPointer;
import org.sonar.api.batch.fs.TextRange;
import org.sonar.api.batch.fs.internal.DefaultInputFile;
@@ -63,6 +64,7 @@ public class TaskResult implements org.sonar.scanner.mediumtest.ScanTaskObserver
private Map<String, InputFile> inputFiles = new HashMap<>();
private Map<String, Component> reportComponents = new HashMap<>();
private Map<String, InputDir> inputDirs = new HashMap<>();
+ private InputModule root;
private ScannerReportReader reader;
@Override
@@ -78,6 +80,8 @@ public class TaskResult implements org.sonar.scanner.mediumtest.ScanTaskObserver
Metadata readMetadata = getReportReader().readMetadata();
int rootComponentRef = readMetadata.getRootComponentRef();
storeReportComponents(rootComponentRef, null);
+ InputComponentStore inputFileCache = container.getComponentByType(InputComponentStore.class);
+ root = inputFileCache.root();
}
storeFs(container);
@@ -154,6 +158,10 @@ public class TaskResult implements org.sonar.scanner.mediumtest.ScanTaskObserver
return result;
}
+ public InputModule root() {
+ return root;
+ }
+
public Collection<InputFile> inputFiles() {
return inputFiles.values();
}
diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/sensor/DefaultSensorContext.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/sensor/DefaultSensorContext.java
index 1df2834b0eb..ed8640d7732 100644
--- a/sonar-scanner-engine/src/main/java/org/sonar/scanner/sensor/DefaultSensorContext.java
+++ b/sonar-scanner-engine/src/main/java/org/sonar/scanner/sensor/DefaultSensorContext.java
@@ -27,6 +27,7 @@ import org.sonar.api.batch.fs.FileSystem;
import org.sonar.api.batch.fs.InputFile;
import org.sonar.api.batch.fs.InputModule;
import org.sonar.api.batch.fs.internal.DefaultInputFile;
+import org.sonar.api.batch.fs.internal.InputModuleHierarchy;
import org.sonar.api.batch.rule.ActiveRules;
import org.sonar.api.batch.sensor.SensorContext;
import org.sonar.api.batch.sensor.code.NewSignificantCode;
@@ -79,9 +80,10 @@ public class DefaultSensorContext implements SensorContext {
private final InputModule module;
private final SonarRuntime sonarRuntime;
private final Configuration config;
+ private final InputModuleHierarchy hierarchy;
public DefaultSensorContext(InputModule module, Configuration config, Settings mutableSettings, FileSystem fs, ActiveRules activeRules,
- AnalysisMode analysisMode, SensorStorage sensorStorage, SonarRuntime sonarRuntime) {
+ AnalysisMode analysisMode, SensorStorage sensorStorage, SonarRuntime sonarRuntime, InputModuleHierarchy hierarchy) {
this.module = module;
this.config = config;
this.mutableSettings = mutableSettings;
@@ -90,6 +92,7 @@ public class DefaultSensorContext implements SensorContext {
this.analysisMode = analysisMode;
this.sensorStorage = sensorStorage;
this.sonarRuntime = sonarRuntime;
+ this.hierarchy = hierarchy;
}
@Override
@@ -134,7 +137,7 @@ public class DefaultSensorContext implements SensorContext {
@Override
public NewIssue newIssue() {
- return new DefaultIssue(sensorStorage);
+ return new DefaultIssue(hierarchy.root(), sensorStorage);
}
@Override
@@ -142,7 +145,7 @@ public class DefaultSensorContext implements SensorContext {
if (analysisMode.isIssues()) {
return NO_OP_NEW_EXTERNAL_ISSUE;
}
- return new DefaultExternalIssue(sensorStorage);
+ return new DefaultExternalIssue(hierarchy.root(), sensorStorage);
}
@Override
diff --git a/sonar-scanner-engine/src/test/java/org/sonar/scanner/issue/ModuleIssuesTest.java b/sonar-scanner-engine/src/test/java/org/sonar/scanner/issue/ModuleIssuesTest.java
index ab8dd62ce52..f001bfc555d 100644
--- a/sonar-scanner-engine/src/test/java/org/sonar/scanner/issue/ModuleIssuesTest.java
+++ b/sonar-scanner-engine/src/test/java/org/sonar/scanner/issue/ModuleIssuesTest.java
@@ -19,14 +19,20 @@
*/
package org.sonar.scanner.issue;
+import java.io.IOException;
import java.util.Collections;
import java.util.HashSet;
+import org.junit.Before;
+import org.junit.Rule;
import org.junit.Test;
+import org.junit.rules.TemporaryFolder;
import org.junit.runner.RunWith;
import org.mockito.ArgumentCaptor;
import org.mockito.Mock;
import org.mockito.runners.MockitoJUnitRunner;
+import org.sonar.api.batch.bootstrap.ProjectDefinition;
import org.sonar.api.batch.fs.internal.DefaultInputFile;
+import org.sonar.api.batch.fs.internal.DefaultInputModule;
import org.sonar.api.batch.fs.internal.TestInputFileBuilder;
import org.sonar.api.batch.rule.internal.ActiveRulesBuilder;
import org.sonar.api.batch.rule.internal.NewActiveRule;
@@ -57,6 +63,11 @@ public class ModuleIssuesTest {
static final String SQUID_RULE_NAME = "Avoid Cycle";
private static final RuleKey NOSONAR_RULE_KEY = RuleKey.of("squid", "NoSonarCheck");
+ private DefaultInputModule projectRoot;
+
+ @Rule
+ public TemporaryFolder temp = new TemporaryFolder();
+
@Mock
ModuleIssueFilters filters;
@@ -68,11 +79,19 @@ public class ModuleIssuesTest {
DefaultInputFile file = new TestInputFileBuilder("foo", "src/Foo.php").initMetadata("Foo\nBar\nBiz\n").build();
ReportPublisher reportPublisher = mock(ReportPublisher.class, RETURNS_DEEP_STUBS);
+ @Before
+ public void prepare() throws IOException {
+ projectRoot = new DefaultInputModule(ProjectDefinition.create()
+ .setKey("foo")
+ .setBaseDir(temp.newFolder())
+ .setWorkDir(temp.newFolder()));
+ }
+
@Test
public void ignore_null_active_rule() {
ruleBuilder.add(SQUID_RULE_KEY).setName(SQUID_RULE_NAME);
initModuleIssues();
- DefaultIssue issue = new DefaultIssue()
+ DefaultIssue issue = new DefaultIssue(projectRoot)
.at(new DefaultIssueLocation().on(file).at(file.selectLine(3)).message("Foo"))
.forRule(SQUID_RULE_KEY);
boolean added = moduleIssues.initAndAddIssue(issue);
@@ -87,7 +106,7 @@ public class ModuleIssuesTest {
activeRulesBuilder.addRule(new NewActiveRule.Builder().setRuleKey(SQUID_RULE_KEY).setQProfileKey("qp-1").build());
initModuleIssues();
- DefaultIssue issue = new DefaultIssue()
+ DefaultIssue issue = new DefaultIssue(projectRoot)
.at(new DefaultIssueLocation().on(file).at(file.selectLine(3)).message("Foo"))
.forRule(SQUID_RULE_KEY);
boolean added = moduleIssues.initAndAddIssue(issue);
@@ -106,7 +125,7 @@ public class ModuleIssuesTest {
.build());
initModuleIssues();
- DefaultIssue issue = new DefaultIssue()
+ DefaultIssue issue = new DefaultIssue(projectRoot)
.at(new DefaultIssueLocation().on(file).at(file.selectLine(3)).message("Foo"))
.forRule(SQUID_RULE_KEY)
.overrideSeverity(org.sonar.api.batch.rule.Severity.CRITICAL);
@@ -126,7 +145,7 @@ public class ModuleIssuesTest {
ruleBuilder.add(SQUID_RULE_KEY).setName(SQUID_RULE_NAME);
initModuleIssues();
- DefaultExternalIssue issue = new DefaultExternalIssue()
+ DefaultExternalIssue issue = new DefaultExternalIssue(projectRoot)
.at(new DefaultIssueLocation().on(file).at(file.selectLine(3)).message("Foo"))
.type(RuleType.BUG)
.forRule(SQUID_RULE_KEY)
@@ -149,7 +168,7 @@ public class ModuleIssuesTest {
.build());
initModuleIssues();
- DefaultIssue issue = new DefaultIssue()
+ DefaultIssue issue = new DefaultIssue(projectRoot)
.at(new DefaultIssueLocation().on(file).at(file.selectLine(3)).message("Foo"))
.forRule(SQUID_RULE_KEY);
when(filters.accept(anyString(), any(ScannerReport.Issue.class))).thenReturn(true);
@@ -170,7 +189,7 @@ public class ModuleIssuesTest {
.build());
initModuleIssues();
- DefaultIssue issue = new DefaultIssue()
+ DefaultIssue issue = new DefaultIssue(projectRoot)
.at(new DefaultIssueLocation().on(file).at(file.selectLine(3)).message(""))
.forRule(SQUID_RULE_KEY);
@@ -185,10 +204,14 @@ public class ModuleIssuesTest {
@Test
public void should_ignore_lines_commented_with_nosonar() {
ruleBuilder.add(SQUID_RULE_KEY).setName(SQUID_RULE_NAME);
- activeRulesBuilder.create(SQUID_RULE_KEY).setSeverity(Severity.INFO).activate();
+ activeRulesBuilder.addRule(new NewActiveRule.Builder()
+ .setRuleKey(SQUID_RULE_KEY)
+ .setSeverity(Severity.INFO)
+ .setQProfileKey("qp-1")
+ .build());
initModuleIssues();
- DefaultIssue issue = new DefaultIssue()
+ DefaultIssue issue = new DefaultIssue(projectRoot)
.at(new DefaultIssueLocation().on(file).at(file.selectLine(3)).message(""))
.forRule(SQUID_RULE_KEY);
@@ -204,12 +227,16 @@ public class ModuleIssuesTest {
public void should_accept_issues_on_no_sonar_rules() {
// The "No Sonar" rule logs violations on the lines that are flagged with "NOSONAR" !!
ruleBuilder.add(NOSONAR_RULE_KEY).setName("No Sonar");
- activeRulesBuilder.create(NOSONAR_RULE_KEY).setSeverity(Severity.INFO).activate();
+ activeRulesBuilder.addRule(new NewActiveRule.Builder()
+ .setRuleKey(NOSONAR_RULE_KEY)
+ .setSeverity(Severity.INFO)
+ .setQProfileKey("qp-1")
+ .build());
initModuleIssues();
file.noSonarAt(new HashSet<>(Collections.singletonList(3)));
- DefaultIssue issue = new DefaultIssue()
+ DefaultIssue issue = new DefaultIssue(projectRoot)
.at(new DefaultIssueLocation().on(file).at(file.selectLine(3)).message(""))
.forRule(NOSONAR_RULE_KEY);
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 674fcc347a7..d30beea2c53 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
@@ -36,6 +36,7 @@ import org.junit.rules.ExpectedException;
import org.junit.rules.TemporaryFolder;
import org.sonar.api.batch.fs.InputDir;
import org.sonar.api.batch.fs.InputFile;
+import org.sonar.api.batch.fs.InputModule;
import org.sonar.api.batch.fs.internal.DefaultInputFile;
import org.sonar.api.utils.MessageException;
import org.sonar.api.utils.System2;
@@ -432,9 +433,10 @@ public class FileSystemMediumTest {
.execute();
DefaultInputFile unknownInputFile = (DefaultInputFile) result.inputFile("src/unknown/file.notanalyzed");
- InputDir unknownInputDir = result.inputDir("src/unknown");
+ InputModule root = result.root();
+
assertThat(unknownInputFile.isPublished()).isFalse();
- assertThat(result.getReportComponent(unknownInputDir.key())).isNotNull();
+ assertThat(result.getReportComponent(root.key())).isNotNull();
// no issues on empty dir
InputDir emptyInputDir = result.inputDir(emptyDirRelative.toString());
diff --git a/sonar-scanner-engine/src/test/java/org/sonar/scanner/mediumtest/issues/IssuesOnDirMediumTest.java b/sonar-scanner-engine/src/test/java/org/sonar/scanner/mediumtest/issues/IssuesOnDirMediumTest.java
index 36bd841552c..95b92faf565 100644
--- a/sonar-scanner-engine/src/test/java/org/sonar/scanner/mediumtest/issues/IssuesOnDirMediumTest.java
+++ b/sonar-scanner-engine/src/test/java/org/sonar/scanner/mediumtest/issues/IssuesOnDirMediumTest.java
@@ -70,7 +70,8 @@ public class IssuesOnDirMediumTest {
.build())
.execute();
- assertThat(result.issuesFor(result.inputDir("src"))).hasSize(2);
+ assertThat(result.issuesFor(result.inputDir("src"))).hasSize(0);
+ assertThat(result.issuesFor(result.root())).hasSize(2);
}
@Test
@@ -96,7 +97,8 @@ public class IssuesOnDirMediumTest {
.build())
.execute();
- assertThat(result.issuesFor(result.inputDir(""))).hasSize(2);
+ assertThat(result.issuesFor(result.inputDir(""))).hasSize(0);
+ assertThat(result.issuesFor(result.root())).hasSize(2);
}
}
diff --git a/sonar-scanner-engine/src/test/java/org/sonar/scanner/sensor/DefaultSensorContextTest.java b/sonar-scanner-engine/src/test/java/org/sonar/scanner/sensor/DefaultSensorContextTest.java
index 83ac5e1a977..9747021d1d9 100644
--- a/sonar-scanner-engine/src/test/java/org/sonar/scanner/sensor/DefaultSensorContextTest.java
+++ b/sonar-scanner-engine/src/test/java/org/sonar/scanner/sensor/DefaultSensorContextTest.java
@@ -27,8 +27,11 @@ import org.junit.rules.TemporaryFolder;
import org.sonar.api.SonarQubeSide;
import org.sonar.api.SonarRuntime;
import org.sonar.api.batch.AnalysisMode;
+import org.sonar.api.batch.bootstrap.ProjectDefinition;
import org.sonar.api.batch.fs.InputModule;
import org.sonar.api.batch.fs.internal.DefaultFileSystem;
+import org.sonar.api.batch.fs.internal.DefaultInputModule;
+import org.sonar.api.batch.fs.internal.InputModuleHierarchy;
import org.sonar.api.batch.measure.MetricFinder;
import org.sonar.api.batch.rule.ActiveRules;
import org.sonar.api.batch.rule.internal.ActiveRulesBuilder;
@@ -37,6 +40,7 @@ import org.sonar.api.config.internal.MapSettings;
import org.sonar.api.internal.SonarRuntimeImpl;
import org.sonar.api.measures.CoreMetrics;
import org.sonar.api.utils.Version;
+import org.sonar.scanner.scan.DefaultInputModuleHierarchy;
import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.Mockito.mock;
@@ -57,6 +61,7 @@ public class DefaultSensorContextTest {
private SensorStorage sensorStorage;
private AnalysisMode analysisMode;
private SonarRuntime runtime;
+ private InputModuleHierarchy hierarchy;
@Before
public void prepare() throws Exception {
@@ -69,7 +74,10 @@ public class DefaultSensorContextTest {
sensorStorage = mock(SensorStorage.class);
analysisMode = mock(AnalysisMode.class);
runtime = SonarRuntimeImpl.forSonarQube(Version.parse("5.5"), SonarQubeSide.SCANNER);
- adaptor = new DefaultSensorContext(mock(InputModule.class), settings.asConfig(), settings, fs, activeRules, analysisMode, sensorStorage, runtime);
+ hierarchy = new DefaultInputModuleHierarchy(new DefaultInputModule(ProjectDefinition.create()
+ .setWorkDir(temp.newFolder())
+ .setBaseDir(temp.newFolder()).setKey("foo")));
+ adaptor = new DefaultSensorContext(mock(InputModule.class), settings.asConfig(), settings, fs, activeRules, analysisMode, sensorStorage, runtime, hierarchy);
}
@Test
diff --git a/sonar-scanner-engine/src/test/java/org/sonar/scanner/sensor/DefaultSensorStorageTest.java b/sonar-scanner-engine/src/test/java/org/sonar/scanner/sensor/DefaultSensorStorageTest.java
index 1d05cfeb8f8..a270f807611 100644
--- a/sonar-scanner-engine/src/test/java/org/sonar/scanner/sensor/DefaultSensorStorageTest.java
+++ b/sonar-scanner-engine/src/test/java/org/sonar/scanner/sensor/DefaultSensorStorageTest.java
@@ -80,6 +80,7 @@ public class DefaultSensorStorageTest {
private ScannerReportWriter reportWriter;
private ContextPropertiesCache contextPropertiesCache = new ContextPropertiesCache();
private BranchConfiguration branchConfiguration;
+ private DefaultInputModule projectRoot;
@Before
public void prepare() throws Exception {
@@ -101,6 +102,11 @@ public class DefaultSensorStorageTest {
underTest = new DefaultSensorStorage(metricFinder,
moduleIssues, settings.asConfig(), reportPublisher, measureCache,
mock(SonarCpdBlockIndex.class), contextPropertiesCache, new ScannerMetrics(), branchConfiguration);
+
+ projectRoot = new DefaultInputModule(ProjectDefinition.create()
+ .setKey("foo")
+ .setBaseDir(temp.newFolder())
+ .setWorkDir(temp.newFolder()));
}
@Test
@@ -120,7 +126,7 @@ public class DefaultSensorStorageTest {
public void should_save_issue() {
InputFile file = new TestInputFileBuilder("foo", "src/Foo.php").build();
- DefaultIssue issue = new DefaultIssue().at(new DefaultIssueLocation().on(file));
+ DefaultIssue issue = new DefaultIssue(projectRoot).at(new DefaultIssueLocation().on(file));
underTest.store(issue);
ArgumentCaptor<Issue> argumentCaptor = ArgumentCaptor.forClass(Issue.class);
@@ -132,7 +138,7 @@ public class DefaultSensorStorageTest {
public void should_save_external_issue() {
InputFile file = new TestInputFileBuilder("foo", "src/Foo.php").build();
- DefaultExternalIssue externalIssue = new DefaultExternalIssue().at(new DefaultIssueLocation().on(file));
+ DefaultExternalIssue externalIssue = new DefaultExternalIssue(projectRoot).at(new DefaultIssueLocation().on(file));
underTest.store(externalIssue);
ArgumentCaptor<ExternalIssue> argumentCaptor = ArgumentCaptor.forClass(ExternalIssue.class);
@@ -145,7 +151,7 @@ public class DefaultSensorStorageTest {
InputFile file = new TestInputFileBuilder("foo", "src/Foo.php").setStatus(InputFile.Status.SAME).build();
when(branchConfiguration.isShortOrPullRequest()).thenReturn(true);
- DefaultIssue issue = new DefaultIssue().at(new DefaultIssueLocation().on(file));
+ DefaultIssue issue = new DefaultIssue(projectRoot).at(new DefaultIssueLocation().on(file));
underTest.store(issue);
verifyZeroInteractions(moduleIssues);