aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-batch/src/test
diff options
context:
space:
mode:
Diffstat (limited to 'sonar-batch/src/test')
-rw-r--r--sonar-batch/src/test/java/org/sonar/batch/issue/IssueFiltersTest.java19
-rw-r--r--sonar-batch/src/test/java/org/sonar/batch/issue/ModuleIssuesTest.java33
-rw-r--r--sonar-batch/src/test/java/org/sonar/batch/mediumtest/issues/MultilineIssuesMediumTest.java69
-rw-r--r--sonar-batch/src/test/java/org/sonar/batch/mediumtest/preview/PreviewAndReportsMediumTest.java4
-rw-r--r--sonar-batch/src/test/java/org/sonar/batch/postjob/DefaultPostJobContextTest.java11
-rw-r--r--sonar-batch/src/test/java/org/sonar/batch/report/ComponentsPublisherTest.java22
-rw-r--r--sonar-batch/src/test/java/org/sonar/batch/report/CoveragePublisherTest.java5
-rw-r--r--sonar-batch/src/test/java/org/sonar/batch/report/DuplicationsPublisherTest.java16
-rw-r--r--sonar-batch/src/test/java/org/sonar/batch/report/SourcePublisherTest.java5
-rw-r--r--sonar-batch/src/test/java/org/sonar/batch/sensor/DefaultSensorStorageTest.java2
-rw-r--r--sonar-batch/src/test/java/org/sonar/batch/source/HighlightableBuilderTest.java6
-rw-r--r--sonar-batch/src/test/java/org/sonar/batch/source/SymbolizableBuilderTest.java6
-rw-r--r--sonar-batch/src/test/resources/mediumtest/xoo/sample-multiline/xources/hello/HelloJava.xoo.measures2
-rw-r--r--sonar-batch/src/test/resources/mediumtest/xoo/sample-multiline/xources/hello/Multiline.xoo9
-rw-r--r--sonar-batch/src/test/resources/mediumtest/xoo/sample-multiline/xources/hello/Multiple.xoo9
-rw-r--r--sonar-batch/src/test/resources/mediumtest/xoo/sample-multiline/xources/hello/Single.xoo (renamed from sonar-batch/src/test/resources/mediumtest/xoo/sample-multiline/xources/hello/HelloJava.xoo)0
16 files changed, 145 insertions, 73 deletions
diff --git a/sonar-batch/src/test/java/org/sonar/batch/issue/IssueFiltersTest.java b/sonar-batch/src/test/java/org/sonar/batch/issue/IssueFiltersTest.java
index b99aefe9bb8..e83ce83d157 100644
--- a/sonar-batch/src/test/java/org/sonar/batch/issue/IssueFiltersTest.java
+++ b/sonar-batch/src/test/java/org/sonar/batch/issue/IssueFiltersTest.java
@@ -21,7 +21,8 @@ package org.sonar.batch.issue;
import org.junit.Test;
import org.sonar.api.issue.Issue;
-import org.sonar.core.issue.DefaultIssue;
+import org.sonar.api.resources.Project;
+import org.sonar.batch.protocol.output.BatchReport;
import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.Matchers.any;
@@ -38,19 +39,19 @@ public class IssueFiltersTest {
org.sonar.api.issue.IssueFilter ko = mock(org.sonar.api.issue.IssueFilter.class);
when(ko.accept(any(Issue.class))).thenReturn(false);
- IssueFilters filters = new IssueFilters(new org.sonar.api.issue.IssueFilter[] {ok, ko});
- assertThat(filters.accept(new DefaultIssue())).isFalse();
+ IssueFilters filters = new IssueFilters(new Project("foo"), new org.sonar.api.issue.IssueFilter[] {ok, ko});
+ assertThat(filters.accept("foo:src/Foo.java", BatchReport.Issue.newBuilder().build())).isFalse();
- filters = new IssueFilters(new org.sonar.api.issue.IssueFilter[] {ok});
- assertThat(filters.accept(new DefaultIssue())).isTrue();
+ filters = new IssueFilters(new Project("foo"), new org.sonar.api.issue.IssueFilter[] {ok});
+ assertThat(filters.accept("foo:src/Foo.java", BatchReport.Issue.newBuilder().build())).isTrue();
- filters = new IssueFilters(new org.sonar.api.issue.IssueFilter[] {ko});
- assertThat(filters.accept(new DefaultIssue())).isFalse();
+ filters = new IssueFilters(new Project("foo"), new org.sonar.api.issue.IssueFilter[] {ko});
+ assertThat(filters.accept("foo:src/Foo.java", BatchReport.Issue.newBuilder().build())).isFalse();
}
@Test
public void should_always_accept_if_no_filters() {
- IssueFilters filters = new IssueFilters();
- assertThat(filters.accept(new DefaultIssue())).isTrue();
+ IssueFilters filters = new IssueFilters(new Project("foo"));
+ assertThat(filters.accept("foo:src/Foo.java", BatchReport.Issue.newBuilder().build())).isTrue();
}
}
diff --git a/sonar-batch/src/test/java/org/sonar/batch/issue/ModuleIssuesTest.java b/sonar-batch/src/test/java/org/sonar/batch/issue/ModuleIssuesTest.java
index fb9cf921e2f..0d50150a8a1 100644
--- a/sonar-batch/src/test/java/org/sonar/batch/issue/ModuleIssuesTest.java
+++ b/sonar-batch/src/test/java/org/sonar/batch/issue/ModuleIssuesTest.java
@@ -20,7 +20,6 @@
package org.sonar.batch.issue;
import java.io.StringReader;
-import java.util.Date;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -35,7 +34,6 @@ import org.sonar.api.batch.rule.internal.RulesBuilder;
import org.sonar.api.batch.sensor.issue.internal.DefaultIssue;
import org.sonar.api.batch.sensor.issue.internal.DefaultIssueLocation;
import org.sonar.api.resources.File;
-import org.sonar.api.resources.Project;
import org.sonar.api.rule.RuleKey;
import org.sonar.api.rule.Severity;
import org.sonar.api.utils.MessageException;
@@ -46,6 +44,7 @@ import org.sonar.batch.report.ReportPublisher;
import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.Assert.fail;
import static org.mockito.Matchers.any;
+import static org.mockito.Matchers.anyString;
import static org.mockito.Matchers.eq;
import static org.mockito.Mockito.RETURNS_DEEP_STUBS;
import static org.mockito.Mockito.mock;
@@ -59,8 +58,6 @@ public class ModuleIssuesTest {
static final RuleKey SQUID_RULE_KEY = RuleKey.of("squid", "AvoidCycle");
static final String SQUID_RULE_NAME = "Avoid Cycle";
- Project project = new Project("foo").setAnalysisDate(new Date());
-
@Mock
IssueFilters filters;
@@ -75,14 +72,14 @@ public class ModuleIssuesTest {
@Before
public void prepare() {
- componentCache.add(File.create("src/Foo.php").setEffectiveKey("foo:src/Foo.php"), null).setInputPath(file);
+ componentCache.add(File.create("src/Foo.php").setEffectiveKey("foo:src/Foo.php"), null).setInputComponent(file);
}
@Test
public void fail_on_unknown_rule() {
initModuleIssues();
DefaultIssue issue = new DefaultIssue()
- .addLocation(new DefaultIssueLocation().onFile(file).at(file.selectLine(3)).message("Foo"))
+ .at(new DefaultIssueLocation().on(file).at(file.selectLine(3)).message("Foo"))
.forRule(SQUID_RULE_KEY);
try {
moduleIssues.initAndAddIssue(issue);
@@ -99,7 +96,7 @@ public class ModuleIssuesTest {
ruleBuilder.add(SQUID_RULE_KEY).setInternalKey(SQUID_RULE_KEY.rule());
initModuleIssues();
DefaultIssue issue = new DefaultIssue()
- .addLocation(new DefaultIssueLocation().onFile(file).at(file.selectLine(3)).message(""))
+ .at(new DefaultIssueLocation().on(file).at(file.selectLine(3)).message(""))
.forRule(SQUID_RULE_KEY);
try {
moduleIssues.initAndAddIssue(issue);
@@ -116,7 +113,7 @@ public class ModuleIssuesTest {
ruleBuilder.add(SQUID_RULE_KEY).setName(SQUID_RULE_NAME);
initModuleIssues();
DefaultIssue issue = new DefaultIssue()
- .addLocation(new DefaultIssueLocation().onFile(file).at(file.selectLine(3)).message("Foo"))
+ .at(new DefaultIssueLocation().on(file).at(file.selectLine(3)).message("Foo"))
.forRule(SQUID_RULE_KEY);
boolean added = moduleIssues.initAndAddIssue(issue);
@@ -131,7 +128,7 @@ public class ModuleIssuesTest {
initModuleIssues();
DefaultIssue issue = new DefaultIssue()
- .addLocation(new DefaultIssueLocation().onFile(file).at(file.selectLine(3)).message("Foo"))
+ .at(new DefaultIssueLocation().on(file).at(file.selectLine(3)).message("Foo"))
.forRule(SQUID_RULE_KEY);
boolean added = moduleIssues.initAndAddIssue(issue);
@@ -146,11 +143,11 @@ public class ModuleIssuesTest {
initModuleIssues();
DefaultIssue issue = new DefaultIssue()
- .addLocation(new DefaultIssueLocation().onFile(file).at(file.selectLine(3)).message("Foo"))
+ .at(new DefaultIssueLocation().on(file).at(file.selectLine(3)).message("Foo"))
.forRule(SQUID_RULE_KEY)
.overrideSeverity(org.sonar.api.batch.rule.Severity.CRITICAL);
- when(filters.accept(any(org.sonar.core.issue.DefaultIssue.class))).thenReturn(true);
+ when(filters.accept(anyString(), any(BatchReport.Issue.class))).thenReturn(true);
boolean added = moduleIssues.initAndAddIssue(issue);
@@ -167,9 +164,9 @@ public class ModuleIssuesTest {
initModuleIssues();
DefaultIssue issue = new DefaultIssue()
- .addLocation(new DefaultIssueLocation().onFile(file).at(file.selectLine(3)).message("Foo"))
+ .at(new DefaultIssueLocation().on(file).at(file.selectLine(3)).message("Foo"))
.forRule(SQUID_RULE_KEY);
- when(filters.accept(any(org.sonar.core.issue.DefaultIssue.class))).thenReturn(true);
+ when(filters.accept(anyString(), any(BatchReport.Issue.class))).thenReturn(true);
moduleIssues.initAndAddIssue(issue);
ArgumentCaptor<BatchReport.Issue> argument = ArgumentCaptor.forClass(BatchReport.Issue.class);
@@ -184,9 +181,9 @@ public class ModuleIssuesTest {
initModuleIssues();
DefaultIssue issue = new DefaultIssue()
- .addLocation(new DefaultIssueLocation().onFile(file).at(file.selectLine(3)).message(""))
+ .at(new DefaultIssueLocation().on(file).at(file.selectLine(3)).message(""))
.forRule(SQUID_RULE_KEY);
- when(filters.accept(any(org.sonar.core.issue.DefaultIssue.class))).thenReturn(true);
+ when(filters.accept(anyString(), any(BatchReport.Issue.class))).thenReturn(true);
boolean added = moduleIssues.initAndAddIssue(issue);
@@ -203,10 +200,10 @@ public class ModuleIssuesTest {
initModuleIssues();
DefaultIssue issue = new DefaultIssue()
- .addLocation(new DefaultIssueLocation().onFile(file).at(file.selectLine(3)).message(""))
+ .at(new DefaultIssueLocation().on(file).at(file.selectLine(3)).message(""))
.forRule(SQUID_RULE_KEY);
- when(filters.accept(any(org.sonar.core.issue.DefaultIssue.class))).thenReturn(false);
+ when(filters.accept(anyString(), any(BatchReport.Issue.class))).thenReturn(false);
boolean added = moduleIssues.initAndAddIssue(issue);
@@ -218,7 +215,7 @@ public class ModuleIssuesTest {
* Every rules and active rules has to be added in builders before creating ModuleIssues
*/
private void initModuleIssues() {
- moduleIssues = new ModuleIssues(activeRulesBuilder.build(), ruleBuilder.build(), project, filters, reportPublisher, componentCache);
+ moduleIssues = new ModuleIssues(activeRulesBuilder.build(), ruleBuilder.build(), filters, reportPublisher, componentCache);
}
}
diff --git a/sonar-batch/src/test/java/org/sonar/batch/mediumtest/issues/MultilineIssuesMediumTest.java b/sonar-batch/src/test/java/org/sonar/batch/mediumtest/issues/MultilineIssuesMediumTest.java
index a9c1317b014..3411fd118e4 100644
--- a/sonar-batch/src/test/java/org/sonar/batch/mediumtest/issues/MultilineIssuesMediumTest.java
+++ b/sonar-batch/src/test/java/org/sonar/batch/mediumtest/issues/MultilineIssuesMediumTest.java
@@ -20,6 +20,7 @@
package org.sonar.batch.mediumtest.issues;
import java.io.File;
+import java.util.List;
import org.apache.commons.io.FileUtils;
import org.junit.After;
import org.junit.Before;
@@ -29,6 +30,8 @@ import org.sonar.batch.mediumtest.BatchMediumTester;
import org.sonar.batch.mediumtest.TaskResult;
import org.sonar.batch.protocol.input.ActiveRule;
import org.sonar.batch.protocol.input.Rule;
+import org.sonar.batch.protocol.output.BatchReport.Issue;
+import org.sonar.batch.protocol.output.BatchReport.IssueLocation;
import org.sonar.xoo.XooPlugin;
import org.sonar.xoo.rule.XooRulesDefinition;
@@ -47,9 +50,19 @@ public class MultilineIssuesMediumTest {
.activateRule(new ActiveRule("xoo", "MultilineIssue", null, "Multinile Issue", "MAJOR", null, "xoo"))
.build();
+ private TaskResult result;
+
@Before
- public void prepare() {
+ public void prepare() throws Exception {
tester.start();
+
+ File projectDir = new File(MultilineIssuesMediumTest.class.getResource("/mediumtest/xoo/sample-multiline").toURI());
+ File tmpDir = temp.newFolder();
+ FileUtils.copyDirectory(projectDir, tmpDir);
+
+ result = tester
+ .newScanTask(new File(tmpDir, "sonar-project.properties"))
+ .start();
}
@After
@@ -59,16 +72,54 @@ public class MultilineIssuesMediumTest {
@Test
public void testIssueRange() throws Exception {
- File projectDir = new File(MultilineIssuesMediumTest.class.getResource("/mediumtest/xoo/sample-multiline").toURI());
- File tmpDir = temp.newFolder();
- FileUtils.copyDirectory(projectDir, tmpDir);
+ List<Issue> issues = result.issuesFor(result.inputFile("xources/hello/Single.xoo"));
+ assertThat(issues).hasSize(1);
+ Issue issue = issues.get(0);
+ assertThat(issue.getLine()).isEqualTo(6);
+ assertThat(issue.getMsg()).isEqualTo("Primary location");
+ IssueLocation primaryLocation = issue.getPrimaryLocation();
+ assertThat(primaryLocation.getMsg()).isEqualTo("Primary location");
+ assertThat(primaryLocation.getTextRange().getStartLine()).isEqualTo(6);
+ assertThat(primaryLocation.getTextRange().getStartOffset()).isEqualTo(25);
+ assertThat(primaryLocation.getTextRange().getEndLine()).isEqualTo(6);
+ assertThat(primaryLocation.getTextRange().getEndOffset()).isEqualTo(52);
+ }
- TaskResult result = tester
- .newScanTask(new File(tmpDir, "sonar-project.properties"))
- .start();
+ @Test
+ public void testMultilineIssueRange() throws Exception {
+ List<Issue> issues = result.issuesFor(result.inputFile("xources/hello/Multiline.xoo"));
+ assertThat(issues).hasSize(1);
+ Issue issue = issues.get(0);
+ assertThat(issue.getLine()).isEqualTo(6);
+ assertThat(issue.getMsg()).isEqualTo("Primary location");
+ IssueLocation primaryLocation = issue.getPrimaryLocation();
+ assertThat(primaryLocation.getMsg()).isEqualTo("Primary location");
+ assertThat(primaryLocation.getTextRange().getStartLine()).isEqualTo(6);
+ assertThat(primaryLocation.getTextRange().getStartOffset()).isEqualTo(25);
+ assertThat(primaryLocation.getTextRange().getEndLine()).isEqualTo(7);
+ assertThat(primaryLocation.getTextRange().getEndOffset()).isEqualTo(23);
+ }
- assertThat(result.issuesFor(result.inputFile("xources/hello/HelloJava.xoo"))).hasSize(1);
+ @Test
+ public void testMultipleIssueLocation() throws Exception {
+ List<Issue> issues = result.issuesFor(result.inputFile("xources/hello/Multiple.xoo"));
+ assertThat(issues).hasSize(1);
+ Issue issue = issues.get(0);
+ assertThat(issue.getLine()).isEqualTo(6);
+ assertThat(issue.getMsg()).isEqualTo("Primary location");
+ IssueLocation primaryLocation = issue.getPrimaryLocation();
+ assertThat(primaryLocation.getMsg()).isEqualTo("Primary location");
+ assertThat(primaryLocation.getTextRange().getStartLine()).isEqualTo(6);
+ assertThat(primaryLocation.getTextRange().getStartOffset()).isEqualTo(25);
+ assertThat(primaryLocation.getTextRange().getEndLine()).isEqualTo(6);
+ assertThat(primaryLocation.getTextRange().getEndOffset()).isEqualTo(52);
+ assertThat(issue.getAdditionalLocationList()).hasSize(1);
+ IssueLocation additionalLocation = issue.getAdditionalLocation(0);
+ assertThat(additionalLocation.getMsg()).isEqualTo("Location #2");
+ assertThat(additionalLocation.getTextRange().getStartLine()).isEqualTo(7);
+ assertThat(additionalLocation.getTextRange().getStartOffset()).isEqualTo(25);
+ assertThat(additionalLocation.getTextRange().getEndLine()).isEqualTo(7);
+ assertThat(additionalLocation.getTextRange().getEndOffset()).isEqualTo(52);
}
-
}
diff --git a/sonar-batch/src/test/java/org/sonar/batch/mediumtest/preview/PreviewAndReportsMediumTest.java b/sonar-batch/src/test/java/org/sonar/batch/mediumtest/preview/PreviewAndReportsMediumTest.java
index 3ba49c04107..11610fa10c1 100644
--- a/sonar-batch/src/test/java/org/sonar/batch/mediumtest/preview/PreviewAndReportsMediumTest.java
+++ b/sonar-batch/src/test/java/org/sonar/batch/mediumtest/preview/PreviewAndReportsMediumTest.java
@@ -247,8 +247,8 @@ public class PreviewAndReportsMediumTest {
.setIssueListener(issueListener)
.start();
- assertThat(result.trackedIssues()).hasSize(14);
- assertThat(issueListener.issueList).hasSize(14);
+ assertThat(result.trackedIssues()).hasSize(17);
+ assertThat(issueListener.issueList).hasSize(17);
assertThat(result.trackedIssues()).containsExactlyElementsOf(issueListener.issueList);
}
diff --git a/sonar-batch/src/test/java/org/sonar/batch/postjob/DefaultPostJobContextTest.java b/sonar-batch/src/test/java/org/sonar/batch/postjob/DefaultPostJobContextTest.java
index 081dcb968b5..a350ba4a952 100644
--- a/sonar-batch/src/test/java/org/sonar/batch/postjob/DefaultPostJobContextTest.java
+++ b/sonar-batch/src/test/java/org/sonar/batch/postjob/DefaultPostJobContextTest.java
@@ -19,6 +19,7 @@
*/
package org.sonar.batch.postjob;
+import java.util.Arrays;
import org.junit.Before;
import org.junit.Test;
import org.sonar.api.batch.AnalysisMode;
@@ -26,12 +27,10 @@ import org.sonar.api.batch.fs.InputFile;
import org.sonar.api.batch.postjob.issue.Issue;
import org.sonar.api.batch.rule.Severity;
import org.sonar.api.config.Settings;
-import org.sonar.core.issue.DefaultIssue;
import org.sonar.api.resources.File;
import org.sonar.batch.index.BatchComponentCache;
import org.sonar.batch.issue.IssueCache;
-
-import java.util.Arrays;
+import org.sonar.core.issue.DefaultIssue;
import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.Mockito.mock;
@@ -77,11 +76,11 @@ public class DefaultPostJobContextTest {
assertThat(issue.line()).isEqualTo(1);
assertThat(issue.message()).isEqualTo("msg");
assertThat(issue.severity()).isEqualTo(Severity.BLOCKER);
- assertThat(issue.inputPath()).isNull();
+ assertThat(issue.inputComponent()).isNull();
InputFile inputPath = mock(InputFile.class);
- resourceCache.add(File.create("src/Foo.php").setEffectiveKey("foo:src/Foo.php"), null).setInputPath(inputPath);
- assertThat(issue.inputPath()).isEqualTo(inputPath);
+ resourceCache.add(File.create("src/Foo.php").setEffectiveKey("foo:src/Foo.php"), null).setInputComponent(inputPath);
+ assertThat(issue.inputComponent()).isEqualTo(inputPath);
}
}
diff --git a/sonar-batch/src/test/java/org/sonar/batch/report/ComponentsPublisherTest.java b/sonar-batch/src/test/java/org/sonar/batch/report/ComponentsPublisherTest.java
index d859b83ce47..49b7de0dc3c 100644
--- a/sonar-batch/src/test/java/org/sonar/batch/report/ComponentsPublisherTest.java
+++ b/sonar-batch/src/test/java/org/sonar/batch/report/ComponentsPublisherTest.java
@@ -25,7 +25,9 @@ import org.junit.Test;
import org.junit.rules.TemporaryFolder;
import org.sonar.api.CoreProperties;
import org.sonar.api.batch.bootstrap.ProjectDefinition;
+import org.sonar.api.batch.fs.internal.DefaultInputDir;
import org.sonar.api.batch.fs.internal.DefaultInputFile;
+import org.sonar.api.batch.fs.internal.DefaultInputModule;
import org.sonar.api.resources.Directory;
import org.sonar.api.resources.Java;
import org.sonar.api.resources.Project;
@@ -55,33 +57,33 @@ public class ComponentsPublisherTest {
Project root = new Project("foo").setName("Root project").setDescription("Root description")
.setAnalysisDate(DateUtils.parseDate(("2012-12-12")));
root.setId(1).setUuid("PROJECT_UUID");
- resourceCache.add(root, null);
+ resourceCache.add(root, null).setInputComponent(new DefaultInputModule("foo"));
Project module1 = new Project("module1").setName("Module1").setDescription("Module description");
module1.setParent(root);
module1.setId(2).setUuid("MODULE_UUID");
- resourceCache.add(module1, root);
+ resourceCache.add(module1, root).setInputComponent(new DefaultInputModule("module1"));
rootDef.addSubProject(ProjectDefinition.create().setKey("module1"));
Directory dir = Directory.create("src");
dir.setEffectiveKey("module1:src");
dir.setId(3).setUuid("DIR_UUID");
- resourceCache.add(dir, module1);
+ resourceCache.add(dir, module1).setInputComponent(new DefaultInputDir("foo", "src"));
org.sonar.api.resources.File file = org.sonar.api.resources.File.create("src/Foo.java", Java.INSTANCE, false);
file.setEffectiveKey("module1:src/Foo.java");
file.setId(4).setUuid("FILE_UUID");
- resourceCache.add(file, dir).setInputPath(new DefaultInputFile("module1", "src/Foo.java").setLines(2));
+ resourceCache.add(file, dir).setInputComponent(new DefaultInputFile("module1", "src/Foo.java").setLines(2));
org.sonar.api.resources.File fileWithoutLang = org.sonar.api.resources.File.create("src/make", null, false);
fileWithoutLang.setEffectiveKey("module1:src/make");
fileWithoutLang.setId(5).setUuid("FILE_WITHOUT_LANG_UUID");
- resourceCache.add(fileWithoutLang, dir).setInputPath(new DefaultInputFile("module1", "src/make").setLines(10));
+ resourceCache.add(fileWithoutLang, dir).setInputComponent(new DefaultInputFile("module1", "src/make").setLines(10));
org.sonar.api.resources.File testFile = org.sonar.api.resources.File.create("test/FooTest.java", Java.INSTANCE, true);
testFile.setEffectiveKey("module1:test/FooTest.java");
testFile.setId(6).setUuid("TEST_FILE_UUID");
- resourceCache.add(testFile, dir).setInputPath(new DefaultInputFile("module1", "test/FooTest.java").setLines(4));
+ resourceCache.add(testFile, dir).setInputComponent(new DefaultInputFile("module1", "test/FooTest.java").setLines(4));
ImmutableProjectReactor reactor = new ImmutableProjectReactor(rootDef);
@@ -122,14 +124,14 @@ public class ComponentsPublisherTest {
Project root = new Project("foo:my_branch").setName("Root project")
.setAnalysisDate(DateUtils.parseDate(("2012-12-12")));
root.setId(1).setUuid("PROJECT_UUID");
- resourceCache.add(root, null);
+ resourceCache.add(root, null).setInputComponent(new DefaultInputModule("foo"));
rootDef.properties().put(CoreProperties.LINKS_HOME_PAGE, "http://home");
rootDef.properties().put(CoreProperties.PROJECT_BRANCH_PROPERTY, "my_branch");
Project module1 = new Project("module1:my_branch").setName("Module1");
module1.setParent(root);
module1.setId(2).setUuid("MODULE_UUID");
- resourceCache.add(module1, root);
+ resourceCache.add(module1, root).setInputComponent(new DefaultInputModule("module1"));
ProjectDefinition moduleDef = ProjectDefinition.create().setKey("module1");
moduleDef.properties().put(CoreProperties.LINKS_CI, "http://ci");
rootDef.addSubProject(moduleDef);
@@ -137,12 +139,12 @@ public class ComponentsPublisherTest {
Directory dir = Directory.create("src");
dir.setEffectiveKey("module1:my_branch:my_branch:src");
dir.setId(3).setUuid("DIR_UUID");
- resourceCache.add(dir, module1);
+ resourceCache.add(dir, module1).setInputComponent(new DefaultInputDir("foo", "src"));
org.sonar.api.resources.File file = org.sonar.api.resources.File.create("src/Foo.java", Java.INSTANCE, false);
file.setEffectiveKey("module1:my_branch:my_branch:src/Foo.java");
file.setId(4).setUuid("FILE_UUID");
- resourceCache.add(file, dir).setInputPath(new DefaultInputFile("module1", "src/Foo.java").setLines(2));
+ resourceCache.add(file, dir).setInputComponent(new DefaultInputFile("module1", "src/Foo.java").setLines(2));
ImmutableProjectReactor reactor = new ImmutableProjectReactor(rootDef);
diff --git a/sonar-batch/src/test/java/org/sonar/batch/report/CoveragePublisherTest.java b/sonar-batch/src/test/java/org/sonar/batch/report/CoveragePublisherTest.java
index e143fd3e3d0..a9f6b81068e 100644
--- a/sonar-batch/src/test/java/org/sonar/batch/report/CoveragePublisherTest.java
+++ b/sonar-batch/src/test/java/org/sonar/batch/report/CoveragePublisherTest.java
@@ -28,6 +28,7 @@ import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.TemporaryFolder;
import org.sonar.api.batch.fs.internal.DefaultInputFile;
+import org.sonar.api.batch.fs.internal.DefaultInputModule;
import org.sonar.api.measures.CoreMetrics;
import org.sonar.api.measures.Measure;
import org.sonar.api.resources.Project;
@@ -58,8 +59,8 @@ public class CoveragePublisherTest {
Project p = new Project("foo").setAnalysisDate(new Date(1234567L));
BatchComponentCache resourceCache = new BatchComponentCache();
sampleFile = org.sonar.api.resources.File.create("src/Foo.php").setEffectiveKey("foo:src/Foo.php");
- resourceCache.add(p, null);
- resourceCache.add(sampleFile, null).setInputPath(new DefaultInputFile("foo", "src/Foo.php").setLines(5));
+ resourceCache.add(p, null).setInputComponent(new DefaultInputModule("foo"));
+ resourceCache.add(sampleFile, null).setInputComponent(new DefaultInputFile("foo", "src/Foo.php").setLines(5));
measureCache = mock(MeasureCache.class);
when(measureCache.byMetric(anyString(), anyString())).thenReturn(Collections.<Measure>emptyList());
publisher = new CoveragePublisher(resourceCache, measureCache);
diff --git a/sonar-batch/src/test/java/org/sonar/batch/report/DuplicationsPublisherTest.java b/sonar-batch/src/test/java/org/sonar/batch/report/DuplicationsPublisherTest.java
index 8fe1eff1f17..731bad05db4 100644
--- a/sonar-batch/src/test/java/org/sonar/batch/report/DuplicationsPublisherTest.java
+++ b/sonar-batch/src/test/java/org/sonar/batch/report/DuplicationsPublisherTest.java
@@ -19,10 +19,15 @@
*/
package org.sonar.batch.report;
+import java.io.File;
+import java.util.Arrays;
+import java.util.Collections;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.TemporaryFolder;
+import org.sonar.api.batch.fs.internal.DefaultInputFile;
+import org.sonar.api.batch.fs.internal.DefaultInputModule;
import org.sonar.api.batch.sensor.duplication.Duplication;
import org.sonar.api.batch.sensor.duplication.internal.DefaultDuplication;
import org.sonar.api.resources.Project;
@@ -31,11 +36,6 @@ import org.sonar.batch.index.BatchComponentCache;
import org.sonar.batch.protocol.output.BatchReport;
import org.sonar.batch.protocol.output.BatchReportReader;
import org.sonar.batch.protocol.output.BatchReportWriter;
-
-import java.io.File;
-import java.util.Arrays;
-import java.util.Collections;
-import java.util.List;
import org.sonar.core.util.CloseableIterator;
import static org.assertj.core.api.Assertions.assertThat;
@@ -55,11 +55,11 @@ public class DuplicationsPublisherTest {
public void prepare() {
BatchComponentCache resourceCache = new BatchComponentCache();
Project p = new Project("foo");
- resourceCache.add(p, null);
+ resourceCache.add(p, null).setInputComponent(new DefaultInputModule("foo"));
org.sonar.api.resources.Resource sampleFile = org.sonar.api.resources.File.create("src/Foo.php").setEffectiveKey("foo:src/Foo.php");
- resourceCache.add(sampleFile, null);
+ resourceCache.add(sampleFile, null).setInputComponent(new DefaultInputFile("foo", "src/Foo.php").setLines(5));
org.sonar.api.resources.Resource sampleFile2 = org.sonar.api.resources.File.create("src/Foo2.php").setEffectiveKey("foo:src/Foo2.php");
- resourceCache.add(sampleFile2, null);
+ resourceCache.add(sampleFile2, null).setInputComponent(new DefaultInputFile("foo", "src/Foo2.php").setLines(5));
duplicationCache = mock(DuplicationCache.class);
when(duplicationCache.byComponent(anyString())).thenReturn(Collections.<DefaultDuplication>emptyList());
publisher = new DuplicationsPublisher(resourceCache, duplicationCache);
diff --git a/sonar-batch/src/test/java/org/sonar/batch/report/SourcePublisherTest.java b/sonar-batch/src/test/java/org/sonar/batch/report/SourcePublisherTest.java
index 83f58a78afe..ae21b89551e 100644
--- a/sonar-batch/src/test/java/org/sonar/batch/report/SourcePublisherTest.java
+++ b/sonar-batch/src/test/java/org/sonar/batch/report/SourcePublisherTest.java
@@ -29,6 +29,7 @@ import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.TemporaryFolder;
import org.sonar.api.batch.fs.internal.DefaultInputFile;
+import org.sonar.api.batch.fs.internal.DefaultInputModule;
import org.sonar.api.resources.Project;
import org.sonar.api.resources.Qualifiers;
import org.sonar.batch.index.BatchComponentCache;
@@ -55,10 +56,10 @@ public class SourcePublisherTest {
BatchComponentCache resourceCache = new BatchComponentCache();
sampleFile = org.sonar.api.resources.File.create("src/Foo.php");
sampleFile.setEffectiveKey("foo:src/Foo.php");
- resourceCache.add(p, null);
+ resourceCache.add(p, null).setInputComponent(new DefaultInputModule("foo"));
File baseDir = temp.newFolder();
sourceFile = new File(baseDir, "src/Foo.php");
- resourceCache.add(sampleFile, null).setInputPath(
+ resourceCache.add(sampleFile, null).setInputComponent(
new DefaultInputFile("foo", "src/Foo.php").setLines(5).setModuleBaseDir(baseDir.toPath()).setCharset(StandardCharsets.ISO_8859_1));
publisher = new SourcePublisher(resourceCache);
File outputDir = temp.newFolder();
diff --git a/sonar-batch/src/test/java/org/sonar/batch/sensor/DefaultSensorStorageTest.java b/sonar-batch/src/test/java/org/sonar/batch/sensor/DefaultSensorStorageTest.java
index 5d8a9a5cdf3..3ad99b57f31 100644
--- a/sonar-batch/src/test/java/org/sonar/batch/sensor/DefaultSensorStorageTest.java
+++ b/sonar-batch/src/test/java/org/sonar/batch/sensor/DefaultSensorStorageTest.java
@@ -106,7 +106,7 @@ public class DefaultSensorStorageTest {
ArgumentCaptor<org.sonar.api.measures.Measure> argumentCaptor = ArgumentCaptor.forClass(org.sonar.api.measures.Measure.class);
Resource sonarFile = File.create("src/Foo.php").setEffectiveKey("foo:src/Foo.php");
- resourceCache.add(sonarFile, null).setInputPath(file);
+ resourceCache.add(sonarFile, null).setInputComponent(file);
when(measureCache.put(eq(sonarFile), argumentCaptor.capture())).thenReturn(null);
sensorStorage.store(new DefaultMeasure()
.onFile(file)
diff --git a/sonar-batch/src/test/java/org/sonar/batch/source/HighlightableBuilderTest.java b/sonar-batch/src/test/java/org/sonar/batch/source/HighlightableBuilderTest.java
index 3d05b7eb3ed..2b3d0cc4abf 100644
--- a/sonar-batch/src/test/java/org/sonar/batch/source/HighlightableBuilderTest.java
+++ b/sonar-batch/src/test/java/org/sonar/batch/source/HighlightableBuilderTest.java
@@ -20,6 +20,8 @@
package org.sonar.batch.source;
import org.junit.Test;
+import org.sonar.api.batch.fs.internal.DefaultInputFile;
+import org.sonar.api.batch.fs.internal.DefaultInputModule;
import org.sonar.api.batch.sensor.internal.SensorStorage;
import org.sonar.api.resources.File;
import org.sonar.api.resources.Project;
@@ -35,7 +37,7 @@ public class HighlightableBuilderTest {
@Test
public void should_load_default_perspective() {
Resource file = File.create("foo.c").setEffectiveKey("myproject:path/to/foo.c");
- BatchComponent component = new BatchComponent(1, file, null);
+ BatchComponent component = new BatchComponent(1, file, null).setInputComponent(new DefaultInputFile("foo", "foo.c"));
HighlightableBuilder builder = new HighlightableBuilder(mock(SensorStorage.class));
Highlightable perspective = builder.loadPerspective(Highlightable.class, component);
@@ -45,7 +47,7 @@ public class HighlightableBuilderTest {
@Test
public void project_should_not_be_highlightable() {
- BatchComponent component = new BatchComponent(1, new Project("struts").setEffectiveKey("org.struts"), null);
+ BatchComponent component = new BatchComponent(1, new Project("struts").setEffectiveKey("org.struts"), null).setInputComponent(new DefaultInputModule("struts"));
HighlightableBuilder builder = new HighlightableBuilder(mock(SensorStorage.class));
Highlightable perspective = builder.loadPerspective(Highlightable.class, component);
diff --git a/sonar-batch/src/test/java/org/sonar/batch/source/SymbolizableBuilderTest.java b/sonar-batch/src/test/java/org/sonar/batch/source/SymbolizableBuilderTest.java
index 9b29c6ff3c3..2bc3f32368f 100644
--- a/sonar-batch/src/test/java/org/sonar/batch/source/SymbolizableBuilderTest.java
+++ b/sonar-batch/src/test/java/org/sonar/batch/source/SymbolizableBuilderTest.java
@@ -21,6 +21,8 @@
package org.sonar.batch.source;
import org.junit.Test;
+import org.sonar.api.batch.fs.internal.DefaultInputFile;
+import org.sonar.api.batch.fs.internal.DefaultInputModule;
import org.sonar.api.component.Perspective;
import org.sonar.api.resources.File;
import org.sonar.api.resources.Project;
@@ -37,7 +39,7 @@ public class SymbolizableBuilderTest {
@Test
public void should_load_perspective() {
Resource file = File.create("foo.c").setEffectiveKey("myproject:path/to/foo.c");
- BatchComponent component = new BatchComponent(1, file, null);
+ BatchComponent component = new BatchComponent(1, file, null).setInputComponent(new DefaultInputFile("foo", "foo.c"));
SymbolizableBuilder perspectiveBuilder = new SymbolizableBuilder(mock(DefaultSensorStorage.class));
Perspective perspective = perspectiveBuilder.loadPerspective(Symbolizable.class, component);
@@ -47,7 +49,7 @@ public class SymbolizableBuilderTest {
@Test
public void project_should_not_be_highlightable() {
- BatchComponent component = new BatchComponent(1, new Project("struts").setEffectiveKey("org.struts"), null);
+ BatchComponent component = new BatchComponent(1, new Project("struts").setEffectiveKey("org.struts"), null).setInputComponent(new DefaultInputModule("struts"));
SymbolizableBuilder builder = new SymbolizableBuilder(mock(DefaultSensorStorage.class));
Perspective perspective = builder.loadPerspective(Symbolizable.class, component);
diff --git a/sonar-batch/src/test/resources/mediumtest/xoo/sample-multiline/xources/hello/HelloJava.xoo.measures b/sonar-batch/src/test/resources/mediumtest/xoo/sample-multiline/xources/hello/HelloJava.xoo.measures
deleted file mode 100644
index 9eaf8ba2549..00000000000
--- a/sonar-batch/src/test/resources/mediumtest/xoo/sample-multiline/xources/hello/HelloJava.xoo.measures
+++ /dev/null
@@ -1,2 +0,0 @@
-ncloc:3
-complexity:1
diff --git a/sonar-batch/src/test/resources/mediumtest/xoo/sample-multiline/xources/hello/Multiline.xoo b/sonar-batch/src/test/resources/mediumtest/xoo/sample-multiline/xources/hello/Multiline.xoo
new file mode 100644
index 00000000000..4043133acfd
--- /dev/null
+++ b/sonar-batch/src/test/resources/mediumtest/xoo/sample-multiline/xources/hello/Multiline.xoo
@@ -0,0 +1,9 @@
+package hello;
+
+public class HelloJava {
+
+ public static void main(String[] args) {
+ {xoo-start-issue:1:1}System.out
+ .println("Hello"){xoo-end-issue:1:1};
+ }
+} \ No newline at end of file
diff --git a/sonar-batch/src/test/resources/mediumtest/xoo/sample-multiline/xources/hello/Multiple.xoo b/sonar-batch/src/test/resources/mediumtest/xoo/sample-multiline/xources/hello/Multiple.xoo
new file mode 100644
index 00000000000..c3840bf283a
--- /dev/null
+++ b/sonar-batch/src/test/resources/mediumtest/xoo/sample-multiline/xources/hello/Multiple.xoo
@@ -0,0 +1,9 @@
+package hello;
+
+public class HelloJava {
+
+ public static void main(String[] args) {
+ {xoo-start-issue:1:1}System.out.println("Hello"){xoo-end-issue:1:1};
+ {xoo-start-issue:1:2}System.out.println("World"){xoo-end-issue:1:2};
+ }
+} \ No newline at end of file
diff --git a/sonar-batch/src/test/resources/mediumtest/xoo/sample-multiline/xources/hello/HelloJava.xoo b/sonar-batch/src/test/resources/mediumtest/xoo/sample-multiline/xources/hello/Single.xoo
index 0b815e09295..0b815e09295 100644
--- a/sonar-batch/src/test/resources/mediumtest/xoo/sample-multiline/xources/hello/HelloJava.xoo
+++ b/sonar-batch/src/test/resources/mediumtest/xoo/sample-multiline/xources/hello/Single.xoo