diff options
author | Julien HENRY <julien.henry@sonarsource.com> | 2015-01-28 22:41:25 +0100 |
---|---|---|
committer | Julien HENRY <julien.henry@sonarsource.com> | 2015-02-10 17:16:01 +0100 |
commit | e9b5effe30cf68820a3dfb00bf736a325313206b (patch) | |
tree | 74323c9b304a2b5f76d2f77ca6c4b86d03fa4296 /sonar-batch/src/test | |
parent | 46b6c6f692964e6202aa269245e579badb856e94 (diff) | |
download | sonarqube-e9b5effe30cf68820a3dfb00bf736a325313206b.tar.gz sonarqube-e9b5effe30cf68820a3dfb00bf736a325313206b.zip |
SONAR-6134, SONAR-6048 Improve performance of FS indexation
Diffstat (limited to 'sonar-batch/src/test')
74 files changed, 362 insertions, 421 deletions
diff --git a/sonar-batch/src/test/java/org/sonar/batch/DefaultFileLinesContextTest.java b/sonar-batch/src/test/java/org/sonar/batch/DefaultFileLinesContextTest.java index 9bf9dc201d4..e85e6003c2f 100644 --- a/sonar-batch/src/test/java/org/sonar/batch/DefaultFileLinesContextTest.java +++ b/sonar-batch/src/test/java/org/sonar/batch/DefaultFileLinesContextTest.java @@ -57,7 +57,7 @@ public class DefaultFileLinesContextTest { @Test(expected = IllegalArgumentException.class) public void shouldNotAllowCreationForDirectory() { - new DefaultFileLinesContext(index, new Directory("key")); + new DefaultFileLinesContext(index, Directory.create("key")); } @Test diff --git a/sonar-batch/src/test/java/org/sonar/batch/components/PastMeasuresLoaderTest.java b/sonar-batch/src/test/java/org/sonar/batch/components/PastMeasuresLoaderTest.java index 4be6293c27a..d032e2b1cd1 100644 --- a/sonar-batch/src/test/java/org/sonar/batch/components/PastMeasuresLoaderTest.java +++ b/sonar-batch/src/test/java/org/sonar/batch/components/PastMeasuresLoaderTest.java @@ -19,6 +19,8 @@ */ package org.sonar.batch.components; +import org.sonar.batch.components.PastMeasuresLoader; + import org.junit.Test; import org.sonar.api.database.model.Snapshot; import org.sonar.api.measures.Metric; diff --git a/sonar-batch/src/test/java/org/sonar/batch/components/PastSnapshotFinderTest.java b/sonar-batch/src/test/java/org/sonar/batch/components/PastSnapshotFinderTest.java index c335d3b87d6..f712b04dbc4 100644 --- a/sonar-batch/src/test/java/org/sonar/batch/components/PastSnapshotFinderTest.java +++ b/sonar-batch/src/test/java/org/sonar/batch/components/PastSnapshotFinderTest.java @@ -19,6 +19,12 @@ */ package org.sonar.batch.components; +import org.sonar.batch.components.PastSnapshotFinder; +import org.sonar.batch.deprecated.components.PastSnapshotFinderByDate; +import org.sonar.batch.deprecated.components.PastSnapshotFinderByDays; +import org.sonar.batch.deprecated.components.PastSnapshotFinderByPreviousAnalysis; +import org.sonar.batch.deprecated.components.PastSnapshotFinderByPreviousVersion; +import org.sonar.batch.deprecated.components.PastSnapshotFinderByVersion; import org.junit.Before; import org.junit.Test; import org.mockito.ArgumentMatcher; diff --git a/sonar-batch/src/test/java/org/sonar/batch/components/PastSnapshotTest.java b/sonar-batch/src/test/java/org/sonar/batch/components/PastSnapshotTest.java index 3d38431f780..201155b1188 100644 --- a/sonar-batch/src/test/java/org/sonar/batch/components/PastSnapshotTest.java +++ b/sonar-batch/src/test/java/org/sonar/batch/components/PastSnapshotTest.java @@ -19,6 +19,8 @@ */ package org.sonar.batch.components; +import org.sonar.batch.components.PastSnapshot; + import org.junit.Test; import org.sonar.api.CoreProperties; import org.sonar.api.database.model.Snapshot; diff --git a/sonar-batch/src/test/java/org/sonar/batch/components/TimeMachineConfigurationTest.java b/sonar-batch/src/test/java/org/sonar/batch/components/TimeMachineConfigurationTest.java index 023690acdbd..eae7b0f8377 100644 --- a/sonar-batch/src/test/java/org/sonar/batch/components/TimeMachineConfigurationTest.java +++ b/sonar-batch/src/test/java/org/sonar/batch/components/TimeMachineConfigurationTest.java @@ -19,6 +19,10 @@ */ package org.sonar.batch.components; +import org.sonar.batch.components.TimeMachineConfiguration; + +import org.sonar.batch.components.PastSnapshot; +import org.sonar.batch.deprecated.components.PeriodsDefinition; import org.junit.Before; import org.junit.Test; import org.sonar.api.database.model.Snapshot; diff --git a/sonar-batch/src/test/java/org/sonar/batch/debt/DebtDecoratorTest.java b/sonar-batch/src/test/java/org/sonar/batch/debt/DebtDecoratorTest.java index 945a3d7614b..7cb4b47c1c5 100644 --- a/sonar-batch/src/test/java/org/sonar/batch/debt/DebtDecoratorTest.java +++ b/sonar-batch/src/test/java/org/sonar/batch/debt/DebtDecoratorTest.java @@ -247,7 +247,7 @@ public class DebtDecoratorTest { // or for a file context = mock(DecoratorContext.class); - when(context.getResource()).thenReturn(new File("foo")); + when(context.getResource()).thenReturn(File.create("foo")); decorator.saveCharacteristicMeasure(context, (Characteristic) null, 12.0, false); verify(context, times(1)).saveMeasure(new Measure(CoreMetrics.TECHNICAL_DEBT)); } @@ -282,7 +282,7 @@ public class DebtDecoratorTest { @Test public void not_save_technical_debt_for_file_if_zero() throws Exception { DecoratorContext context = mock(DecoratorContext.class); - when(context.getResource()).thenReturn(new File("foo")); + when(context.getResource()).thenReturn(File.create("foo")); decorator.saveCharacteristicMeasure(context, null, 0.0, true); verify(context, never()).saveMeasure(new Measure(CoreMetrics.TECHNICAL_DEBT)); diff --git a/sonar-batch/src/test/java/org/sonar/batch/debt/NewDebtDecoratorTest.java b/sonar-batch/src/test/java/org/sonar/batch/debt/NewDebtDecoratorTest.java index 0bb25ad1d82..c930eb1075e 100644 --- a/sonar-batch/src/test/java/org/sonar/batch/debt/NewDebtDecoratorTest.java +++ b/sonar-batch/src/test/java/org/sonar/batch/debt/NewDebtDecoratorTest.java @@ -20,6 +20,9 @@ package org.sonar.batch.debt; +import org.sonar.batch.components.TimeMachineConfiguration; + +import org.sonar.batch.deprecated.components.Period; import org.apache.commons.lang.ObjectUtils; import org.apache.commons.lang.time.DateUtils; import org.junit.Before; @@ -42,8 +45,6 @@ import org.sonar.api.measures.Metric; import org.sonar.api.resources.Resource; import org.sonar.api.test.IsMeasure; import org.sonar.api.utils.Duration; -import org.sonar.batch.components.Period; -import org.sonar.batch.components.TimeMachineConfiguration; import org.sonar.batch.debt.IssueChangelogDebtCalculator; import org.sonar.batch.debt.NewDebtDecorator; diff --git a/sonar-batch/src/test/java/org/sonar/batch/debt/SqaleRatingDecoratorTest.java b/sonar-batch/src/test/java/org/sonar/batch/debt/SqaleRatingDecoratorTest.java index 0caa8cf219e..79ce075a097 100644 --- a/sonar-batch/src/test/java/org/sonar/batch/debt/SqaleRatingDecoratorTest.java +++ b/sonar-batch/src/test/java/org/sonar/batch/debt/SqaleRatingDecoratorTest.java @@ -73,10 +73,9 @@ public class SqaleRatingDecoratorTest { public void setUp() throws Exception { settings = new Settings(); - fs = new DefaultFileSystem(temp.newFolder()); + fs = new DefaultFileSystem(temp.newFolder().toPath()); fs.add(new DefaultInputFile("foo", file.getPath()) - .setLanguage("java") - .setFile(temp.newFile("Foo.java"))); + .setLanguage("java")); decorator = new SqaleRatingDecorator(new SqaleRatingSettings(settings), metrics, fs); } diff --git a/sonar-batch/src/test/java/org/sonar/batch/ResourceFiltersTest.java b/sonar-batch/src/test/java/org/sonar/batch/deprecated/ResourceFiltersTest.java index 602b6c7dd42..c93334474b2 100644 --- a/sonar-batch/src/test/java/org/sonar/batch/ResourceFiltersTest.java +++ b/sonar-batch/src/test/java/org/sonar/batch/deprecated/ResourceFiltersTest.java @@ -17,7 +17,7 @@ * along with this program; if not, write to the Free Software Foundation, * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ -package org.sonar.batch; +package org.sonar.batch.deprecated; import org.junit.Test; import org.slf4j.Logger; diff --git a/sonar-batch/src/test/java/org/sonar/batch/components/PastSnapshotFinderByDateTest.java b/sonar-batch/src/test/java/org/sonar/batch/deprecated/components/PastSnapshotFinderByDateTest.java index 7abd043f62b..2cf8b317531 100644 --- a/sonar-batch/src/test/java/org/sonar/batch/components/PastSnapshotFinderByDateTest.java +++ b/sonar-batch/src/test/java/org/sonar/batch/deprecated/components/PastSnapshotFinderByDateTest.java @@ -17,8 +17,11 @@ * along with this program; if not, write to the Free Software Foundation, * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ -package org.sonar.batch.components; +package org.sonar.batch.deprecated.components; +import org.sonar.batch.components.PastSnapshot; + +import org.sonar.batch.deprecated.components.PastSnapshotFinderByDate; import org.junit.Test; import org.sonar.api.database.model.Snapshot; import org.sonar.jpa.test.AbstractDbUnitTestCase; diff --git a/sonar-batch/src/test/java/org/sonar/batch/components/PastSnapshotFinderByDaysTest.java b/sonar-batch/src/test/java/org/sonar/batch/deprecated/components/PastSnapshotFinderByDaysTest.java index 1b136e9ae72..0515b30673d 100644 --- a/sonar-batch/src/test/java/org/sonar/batch/components/PastSnapshotFinderByDaysTest.java +++ b/sonar-batch/src/test/java/org/sonar/batch/deprecated/components/PastSnapshotFinderByDaysTest.java @@ -17,7 +17,9 @@ * along with this program; if not, write to the Free Software Foundation, * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ -package org.sonar.batch.components; +package org.sonar.batch.deprecated.components; + +import org.sonar.batch.deprecated.components.PastSnapshotFinderByDays; import org.hamcrest.core.IsNull; import org.junit.Test; diff --git a/sonar-batch/src/test/java/org/sonar/batch/components/PastSnapshotFinderByPreviousAnalysisTest.java b/sonar-batch/src/test/java/org/sonar/batch/deprecated/components/PastSnapshotFinderByPreviousAnalysisTest.java index a2c0d82e301..9ec2024b7d4 100644 --- a/sonar-batch/src/test/java/org/sonar/batch/components/PastSnapshotFinderByPreviousAnalysisTest.java +++ b/sonar-batch/src/test/java/org/sonar/batch/deprecated/components/PastSnapshotFinderByPreviousAnalysisTest.java @@ -17,12 +17,14 @@ * along with this program; if not, write to the Free Software Foundation, * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ -package org.sonar.batch.components; +package org.sonar.batch.deprecated.components; +import org.sonar.batch.components.PastSnapshot; + +import org.sonar.batch.deprecated.components.PastSnapshotFinderByPreviousAnalysis; import org.junit.Test; import org.sonar.api.database.model.Snapshot; import org.sonar.jpa.test.AbstractDbUnitTestCase; - import static org.hamcrest.Matchers.is; import static org.hamcrest.core.IsNull.nullValue; import static org.junit.Assert.assertThat; diff --git a/sonar-batch/src/test/java/org/sonar/batch/components/PastSnapshotFinderByPreviousVersionTest.java b/sonar-batch/src/test/java/org/sonar/batch/deprecated/components/PastSnapshotFinderByPreviousVersionTest.java index da160c87a4f..d932060914a 100644 --- a/sonar-batch/src/test/java/org/sonar/batch/components/PastSnapshotFinderByPreviousVersionTest.java +++ b/sonar-batch/src/test/java/org/sonar/batch/deprecated/components/PastSnapshotFinderByPreviousVersionTest.java @@ -17,13 +17,15 @@ * along with this program; if not, write to the Free Software Foundation, * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ -package org.sonar.batch.components; +package org.sonar.batch.deprecated.components; +import org.sonar.batch.components.PastSnapshot; + +import org.sonar.batch.deprecated.components.PastSnapshotFinderByPreviousVersion; import org.junit.Test; import org.sonar.api.CoreProperties; import org.sonar.api.database.model.Snapshot; import org.sonar.jpa.test.AbstractDbUnitTestCase; - import static org.assertj.core.api.Assertions.assertThat; public class PastSnapshotFinderByPreviousVersionTest extends AbstractDbUnitTestCase { diff --git a/sonar-batch/src/test/java/org/sonar/batch/components/PastSnapshotFinderByVersionTest.java b/sonar-batch/src/test/java/org/sonar/batch/deprecated/components/PastSnapshotFinderByVersionTest.java index b35f4b8990b..5d8c87ad7f0 100644 --- a/sonar-batch/src/test/java/org/sonar/batch/components/PastSnapshotFinderByVersionTest.java +++ b/sonar-batch/src/test/java/org/sonar/batch/deprecated/components/PastSnapshotFinderByVersionTest.java @@ -17,13 +17,15 @@ * along with this program; if not, write to the Free Software Foundation, * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ -package org.sonar.batch.components; +package org.sonar.batch.deprecated.components; +import org.sonar.batch.components.PastSnapshot; + +import org.sonar.batch.deprecated.components.PastSnapshotFinderByVersion; import org.junit.Test; import org.sonar.api.CoreProperties; import org.sonar.api.database.model.Snapshot; import org.sonar.jpa.test.AbstractDbUnitTestCase; - import static org.assertj.core.api.Assertions.assertThat; public class PastSnapshotFinderByVersionTest extends AbstractDbUnitTestCase { diff --git a/sonar-batch/src/test/java/org/sonar/batch/components/PeriodsDefinitionTest.java b/sonar-batch/src/test/java/org/sonar/batch/deprecated/components/PeriodsDefinitionTest.java index 7483d54cf23..425ce9e4e89 100644 --- a/sonar-batch/src/test/java/org/sonar/batch/components/PeriodsDefinitionTest.java +++ b/sonar-batch/src/test/java/org/sonar/batch/deprecated/components/PeriodsDefinitionTest.java @@ -18,8 +18,11 @@ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ -package org.sonar.batch.components; +package org.sonar.batch.deprecated.components; +import org.sonar.batch.components.PastSnapshotFinder; + +import org.sonar.batch.deprecated.components.PeriodsDefinition; import org.junit.Before; import org.junit.Test; import org.mockito.ArgumentMatcher; @@ -28,7 +31,6 @@ import org.sonar.api.database.model.Snapshot; import org.sonar.api.resources.Project; import org.sonar.batch.ProjectTree; import org.sonar.jpa.test.AbstractDbUnitTestCase; - import static org.mockito.Matchers.anyString; import static org.mockito.Matchers.argThat; import static org.mockito.Matchers.eq; diff --git a/sonar-batch/src/test/java/org/sonar/batch/DecoratorsSelectorTest.java b/sonar-batch/src/test/java/org/sonar/batch/deprecated/decorator/DecoratorsSelectorTest.java index 8a0e9a24764..f469d6b52e9 100644 --- a/sonar-batch/src/test/java/org/sonar/batch/DecoratorsSelectorTest.java +++ b/sonar-batch/src/test/java/org/sonar/batch/deprecated/decorator/DecoratorsSelectorTest.java @@ -17,7 +17,7 @@ * along with this program; if not, write to the Free Software Foundation, * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ -package org.sonar.batch; +package org.sonar.batch.deprecated.decorator; import com.google.common.collect.Iterables; import org.junit.Test; diff --git a/sonar-batch/src/test/java/org/sonar/batch/FormulaDecoratorTest.java b/sonar-batch/src/test/java/org/sonar/batch/deprecated/decorator/FormulaDecoratorTest.java index ff5fdc5d159..4507ab8cbc0 100644 --- a/sonar-batch/src/test/java/org/sonar/batch/FormulaDecoratorTest.java +++ b/sonar-batch/src/test/java/org/sonar/batch/deprecated/decorator/FormulaDecoratorTest.java @@ -17,7 +17,9 @@ * along with this program; if not, write to the Free Software Foundation, * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ -package org.sonar.batch; +package org.sonar.batch.deprecated.decorator; + +import org.sonar.batch.deprecated.decorator.FormulaDecorator; import org.junit.Test; import org.sonar.api.batch.DecoratorContext; diff --git a/sonar-batch/src/test/java/org/sonar/batch/tasks/ListTaskTest.java b/sonar-batch/src/test/java/org/sonar/batch/deprecated/tasks/ListTaskTest.java index 923af5177e5..2812b4d28cf 100644 --- a/sonar-batch/src/test/java/org/sonar/batch/tasks/ListTaskTest.java +++ b/sonar-batch/src/test/java/org/sonar/batch/deprecated/tasks/ListTaskTest.java @@ -17,7 +17,10 @@ * along with this program; if not, write to the Free Software Foundation, * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ -package org.sonar.batch.tasks; +package org.sonar.batch.deprecated.tasks; + +import org.sonar.batch.deprecated.tasks.ListTask; +import org.sonar.batch.deprecated.tasks.Tasks; import org.junit.Test; import org.sonar.api.task.Task; diff --git a/sonar-batch/src/test/java/org/sonar/batch/tasks/TasksTest.java b/sonar-batch/src/test/java/org/sonar/batch/deprecated/tasks/TasksTest.java index 5c4315890c2..51f6eb1c53b 100644 --- a/sonar-batch/src/test/java/org/sonar/batch/tasks/TasksTest.java +++ b/sonar-batch/src/test/java/org/sonar/batch/deprecated/tasks/TasksTest.java @@ -17,7 +17,7 @@ * along with this program; if not, write to the Free Software Foundation, * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ -package org.sonar.batch.tasks; +package org.sonar.batch.deprecated.tasks; import org.junit.Rule; import org.junit.Test; @@ -36,20 +36,20 @@ public class TasksTest { @Test public void should_get_definitions() { - Tasks tasks = new Tasks(new TaskDefinition[]{ScanTask.DEFINITION, ListTask.DEFINITION}); + Tasks tasks = new Tasks(new TaskDefinition[] {ScanTask.DEFINITION, ListTask.DEFINITION}); assertThat(tasks.definitions()).hasSize(2); } @Test public void should_get_definition_by_key() { - Tasks tasks = new Tasks(new TaskDefinition[]{ScanTask.DEFINITION, ListTask.DEFINITION}); + Tasks tasks = new Tasks(new TaskDefinition[] {ScanTask.DEFINITION, ListTask.DEFINITION}); tasks.start(); assertThat(tasks.definition(ListTask.DEFINITION.key())).isEqualTo(ListTask.DEFINITION); } @Test public void should_return_null_if_task_not_found() { - Tasks tasks = new Tasks(new TaskDefinition[]{ScanTask.DEFINITION, ListTask.DEFINITION}); + Tasks tasks = new Tasks(new TaskDefinition[] {ScanTask.DEFINITION, ListTask.DEFINITION}); assertThat(tasks.definition("not-exists")).isNull(); } @@ -59,7 +59,7 @@ public class TasksTest { thrown.expect(SonarException.class); thrown.expectMessage("Task 'foo' is declared twice"); - new Tasks(new TaskDefinition[]{ + new Tasks(new TaskDefinition[] { TaskDefinition.builder().key("foo").taskClass(FakeTask1.class).description("foo1").build(), TaskDefinition.builder().key("foo").taskClass(FakeTask2.class).description("foo2").build() }); @@ -67,13 +67,13 @@ public class TasksTest { @Test public void should_fail_on_duplicated_class() { - Tasks tasks = new Tasks(new TaskDefinition[]{ + Tasks tasks = new Tasks(new TaskDefinition[] { TaskDefinition.builder().key("foo1").taskClass(FakeTask1.class).description("foo1").build(), TaskDefinition.builder().key("foo2").taskClass(FakeTask1.class).description("foo1").build() }); thrown.expect(SonarException.class); - thrown.expectMessage("Task 'org.sonar.batch.tasks.TasksTest$FakeTask1' is defined twice: first by 'foo1' and then by 'foo2'"); + thrown.expectMessage("Task 'org.sonar.batch.deprecated.tasks.TasksTest$FakeTask1' is defined twice: first by 'foo1' and then by 'foo2'"); tasks.start(); } diff --git a/sonar-batch/src/test/java/org/sonar/batch/design/DirectoryDsmDecoratorTest.java b/sonar-batch/src/test/java/org/sonar/batch/design/DirectoryDsmDecoratorTest.java index 598bf4d6f88..fa3ceecc3a5 100644 --- a/sonar-batch/src/test/java/org/sonar/batch/design/DirectoryDsmDecoratorTest.java +++ b/sonar-batch/src/test/java/org/sonar/batch/design/DirectoryDsmDecoratorTest.java @@ -65,9 +65,9 @@ public class DirectoryDsmDecoratorTest { dir = Directory.create("src"); dirContext = mock(DecoratorContext.class); - file1 = File.create("src/Foo1.java", "Foo1.java", null, false); + file1 = File.create("src/Foo1.java", null, false); file1.setId(1); - file2 = File.create("src/Foo2.java", "Foo2.java", null, false); + file2 = File.create("src/Foo2.java", null, false); file2.setId(2); file1Context = mock(DecoratorContext.class); diff --git a/sonar-batch/src/test/java/org/sonar/batch/design/DsmSerializerTest.java b/sonar-batch/src/test/java/org/sonar/batch/design/DsmSerializerTest.java index 24d949d000c..5d9b0b508ef 100644 --- a/sonar-batch/src/test/java/org/sonar/batch/design/DsmSerializerTest.java +++ b/sonar-batch/src/test/java/org/sonar/batch/design/DsmSerializerTest.java @@ -43,8 +43,8 @@ public class DsmSerializerTest { @Test public void serialize() throws IOException { - Resource foo = Directory.create("src/org/foo", "org/foo").setId(7); - Resource bar = Directory.create("src/org/bar", "org/bar").setId(8); + Resource foo = Directory.create("src/org/foo").setId(7); + Resource bar = Directory.create("src/org/bar").setId(8); Dependency dep = new Dependency(foo, bar).setId(30l).setWeight(1); DirectedGraph<Resource, Dependency> graph = new DirectedGraph<Resource, Dependency>(); diff --git a/sonar-batch/src/test/java/org/sonar/batch/design/SubProjectDsmDecoratorTest.java b/sonar-batch/src/test/java/org/sonar/batch/design/SubProjectDsmDecoratorTest.java index 94d7d621108..a9a41264adf 100644 --- a/sonar-batch/src/test/java/org/sonar/batch/design/SubProjectDsmDecoratorTest.java +++ b/sonar-batch/src/test/java/org/sonar/batch/design/SubProjectDsmDecoratorTest.java @@ -60,9 +60,9 @@ public class SubProjectDsmDecoratorTest { module = new Project("foo"); moduleContext = mock(DecoratorContext.class); - dir1 = Directory.create("src/foo1", "foo1"); + dir1 = Directory.create("src/foo1"); dir1.setId(1); - dir2 = Directory.create("src/foo2", "foo2"); + dir2 = Directory.create("src/foo2"); dir2.setId(2); DecoratorContext dir1Context = mock(DecoratorContext.class); diff --git a/sonar-batch/src/test/java/org/sonar/batch/index/BucketTest.java b/sonar-batch/src/test/java/org/sonar/batch/index/BucketTest.java index 51a9c0269c9..97bdb61d75e 100644 --- a/sonar-batch/src/test/java/org/sonar/batch/index/BucketTest.java +++ b/sonar-batch/src/test/java/org/sonar/batch/index/BucketTest.java @@ -24,17 +24,17 @@ import org.sonar.api.measures.Metric; import org.sonar.api.resources.Directory; import org.sonar.api.resources.File; +import static org.hamcrest.Matchers.hasItem; import static org.hamcrest.Matchers.is; import static org.hamcrest.core.IsNot.not; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertThat; -import static org.hamcrest.Matchers.hasItem; public class BucketTest { - Directory directory = new Directory("org/foo"); - File javaFile = new File("org/foo/Bar.java"); + Directory directory = Directory.create("org/foo"); + File javaFile = File.create("org/foo/Bar.java"); Metric ncloc = new Metric("ncloc"); @Test diff --git a/sonar-batch/src/test/java/org/sonar/batch/index/DefaultIndexTest.java b/sonar-batch/src/test/java/org/sonar/batch/index/DefaultIndexTest.java index ca7a86e791c..fe541281e05 100644 --- a/sonar-batch/src/test/java/org/sonar/batch/index/DefaultIndexTest.java +++ b/sonar-batch/src/test/java/org/sonar/batch/index/DefaultIndexTest.java @@ -95,10 +95,10 @@ public class DefaultIndexTest { @Test public void shouldIndexParentOfDeprecatedFiles() { - File file = File.create("src/org/foo/Bar.java", "org/foo/Bar.java", null, false); + File file = File.create("src/org/foo/Bar.java", null, false); assertThat(index.index(file)).isTrue(); - Directory reference = Directory.create("src/org/foo", "org/foo"); + Directory reference = Directory.create("src/org/foo"); assertThat(index.getResource(reference).getName()).isEqualTo("src/org/foo"); assertThat(index.isIndexed(reference, true)).isTrue(); assertThat(index.isExcluded(reference)).isFalse(); @@ -108,15 +108,14 @@ public class DefaultIndexTest { @Test public void shouldIndexTreeOfResources() { - Directory directory = Directory.create("src/org/foo", "org/foo"); - File file = File.create("src/org/foo/Bar.java", "org/foo/Bar.java", Java.INSTANCE, false); + Directory directory = Directory.create("src/org/foo"); + File file = File.create("src/org/foo/Bar.java", Java.INSTANCE, false); assertThat(index.index(directory)).isTrue(); assertThat(index.index(file, directory)).isTrue(); - File fileRef = File.create("src/org/foo/Bar.java", "org/foo/Bar.java", null, false); + File fileRef = File.create("src/org/foo/Bar.java", null, false); assertThat(index.getResource(fileRef).getKey()).isEqualTo("src/org/foo/Bar.java"); - assertThat(index.getResource(fileRef).getDeprecatedKey()).isEqualTo("org/foo/Bar.java"); assertThat(index.getResource(fileRef).getLanguage().getKey()).isEqualTo("java"); assertThat(index.isIndexed(fileRef, true)).isTrue(); assertThat(index.isExcluded(fileRef)).isFalse(); @@ -126,14 +125,14 @@ public class DefaultIndexTest { @Test public void shouldGetSource() throws Exception { - Directory directory = Directory.create("src/org/foo", "org/foo"); - File file = File.create("src/org/foo/Bar.java", "org/foo/Bar.java", Java.INSTANCE, false); + Directory directory = Directory.create("src/org/foo"); + File file = File.create("src/org/foo/Bar.java", Java.INSTANCE, false); FileUtils.write(new java.io.File(baseDir, "src/org/foo/Bar.java"), "Foo bar"); assertThat(index.index(directory)).isTrue(); assertThat(index.index(file, directory)).isTrue(); - File fileRef = File.create("src/org/foo/Bar.java", "org/foo/Bar.java", null, false); + File fileRef = File.create("src/org/foo/Bar.java", null, false); assertThat(index.getSource(fileRef)).isEqualTo("Foo bar"); } @@ -150,12 +149,12 @@ public class DefaultIndexTest { @Test public void shouldNotIndexResourceIfParentNotIndexed() { - Directory directory = Directory.create("src/org/other", "org/other"); - File file = File.create("src/org/foo/Bar.java", "org/foo/Bar.java", null, false); + Directory directory = Directory.create("src/org/other"); + File file = File.create("src/org/foo/Bar.java", null, false); assertThat(index.index(file, directory)).isFalse(); - File fileRef = File.create("src/org/foo/Bar.java", "org/foo/Bar.java", null, false); + File fileRef = File.create("src/org/foo/Bar.java", null, false); assertThat(index.isIndexed(directory, true)).isFalse(); assertThat(index.isIndexed(fileRef, true)).isFalse(); assertThat(index.isExcluded(fileRef)).isFalse(); @@ -165,7 +164,7 @@ public class DefaultIndexTest { @Test public void shouldNotIndexResourceWhenAddingMeasure() { - Resource dir = Directory.create("src/org/foo", "org/foo"); + Resource dir = Directory.create("src/org/foo"); index.addMeasure(dir, new Measure("ncloc").setValue(50.0)); assertThat(index.isIndexed(dir, true)).isFalse(); diff --git a/sonar-batch/src/test/java/org/sonar/batch/index/DuplicationPersisterTest.java b/sonar-batch/src/test/java/org/sonar/batch/index/DuplicationPersisterTest.java index 3517b28789f..a62dd075bb5 100644 --- a/sonar-batch/src/test/java/org/sonar/batch/index/DuplicationPersisterTest.java +++ b/sonar-batch/src/test/java/org/sonar/batch/index/DuplicationPersisterTest.java @@ -46,7 +46,7 @@ public class DuplicationPersisterTest extends AbstractDaoTestCase { DuplicationPersister duplicationPersister; RuleFinder ruleFinder = mock(RuleFinder.class); - File aFile = new File("org/foo/Bar.java"); + File aFile = File.create("org/foo/Bar.java"); Snapshot fileSnapshot = snapshot(FILE_SNAPSHOT_ID); private DuplicationCache duplicationCache; diff --git a/sonar-batch/src/test/java/org/sonar/batch/index/MeasurePersisterTest.java b/sonar-batch/src/test/java/org/sonar/batch/index/MeasurePersisterTest.java index b5cfb38c063..fb59aa4d0a5 100644 --- a/sonar-batch/src/test/java/org/sonar/batch/index/MeasurePersisterTest.java +++ b/sonar-batch/src/test/java/org/sonar/batch/index/MeasurePersisterTest.java @@ -61,8 +61,8 @@ public class MeasurePersisterTest extends AbstractDaoTestCase { MeasurePersister measurePersister; RuleFinder ruleFinder = mock(RuleFinder.class); Project project = new Project("foo"); - Directory aDirectory = new Directory("org/foo"); - File aFile = new File("org/foo/Bar.java"); + Directory aDirectory = Directory.create("org/foo"); + File aFile = File.create("org/foo/Bar.java"); BatchResource projectResource = batchResource(project, PROJECT_SNAPSHOT_ID); BatchResource dirResource = batchResource(aDirectory, PACKAGE_SNAPSHOT_ID); BatchResource fileResource = batchResource(aFile, FILE_SNAPSHOT_ID); diff --git a/sonar-batch/src/test/java/org/sonar/batch/index/ResourceCacheTest.java b/sonar-batch/src/test/java/org/sonar/batch/index/ResourceCacheTest.java index 33eb06086d0..bd250b544dd 100644 --- a/sonar-batch/src/test/java/org/sonar/batch/index/ResourceCacheTest.java +++ b/sonar-batch/src/test/java/org/sonar/batch/index/ResourceCacheTest.java @@ -31,7 +31,7 @@ public class ResourceCacheTest { public void should_cache_resource() throws Exception { ResourceCache cache = new ResourceCache(); String componentKey = "struts:src/org/struts/Action.java"; - Resource resource = new File("org/struts/Action.java").setEffectiveKey(componentKey); + Resource resource = File.create("org/struts/Action.java").setEffectiveKey(componentKey); cache.add(resource, null); assertThat(cache.get(componentKey).resource()).isSameAs(resource); @@ -41,7 +41,7 @@ public class ResourceCacheTest { @Test public void should_fail_if_missing_component_key() throws Exception { ResourceCache cache = new ResourceCache(); - Resource resource = new File("org/struts/Action.java").setEffectiveKey(null); + Resource resource = File.create("org/struts/Action.java").setEffectiveKey(null); try { cache.add(resource, null); fail(); diff --git a/sonar-batch/src/test/java/org/sonar/batch/index/ResourceKeyMigrationTest.java b/sonar-batch/src/test/java/org/sonar/batch/index/ResourceKeyMigrationTest.java index e91b5596101..1d3d227a4d4 100644 --- a/sonar-batch/src/test/java/org/sonar/batch/index/ResourceKeyMigrationTest.java +++ b/sonar-batch/src/test/java/org/sonar/batch/index/ResourceKeyMigrationTest.java @@ -31,6 +31,8 @@ import org.sonar.api.batch.fs.internal.DefaultInputFile; import org.sonar.api.batch.fs.internal.DeprecatedDefaultInputFile; import org.sonar.api.config.Settings; import org.sonar.api.resources.Project; +import org.sonar.api.scan.filesystem.PathResolver; +import org.sonar.batch.scan.filesystem.DefaultModuleFileSystem; import org.sonar.jpa.test.AbstractDbUnitTestCase; import java.io.File; @@ -39,6 +41,7 @@ import java.util.Arrays; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; public class ResourceKeyMigrationTest extends AbstractDbUnitTestCase { @@ -73,23 +76,21 @@ public class ResourceKeyMigrationTest extends AbstractDbUnitTestCase { baseDir = temp.newFolder(); javaInputFiles = (Iterable) Arrays.asList( - newInputFile(javaModule, "src/main/java/org/foo/Bar.java", "org.foo.Bar", false), - newInputFile(javaModule, "src/main/java/RootBar.java", "[default].RootBar", false), - newInputFile(javaModule, "src/test/java/org/foo/BarTest.java", "org.foo.BarTest", true)); + newInputFile(javaModule, "src/main/java/org/foo/Bar.java", false, "java"), + newInputFile(javaModule, "src/main/java/RootBar.java", false, "java"), + newInputFile(javaModule, "src/test/java/org/foo/BarTest.java", true, "java")); phpInputFiles = (Iterable) Arrays.asList( - newInputFile(phpModule, "org/foo/Bar.php", "org/foo/Bar.php", false), - newInputFile(phpModule, "RootBar.php", "RootBar.php", false), - newInputFile(phpModule, "test/org/foo/BarTest.php", "org/foo/BarTest.php", true)); + newInputFile(phpModule, "org/foo/Bar.php", false, "php"), + newInputFile(phpModule, "RootBar.php", false, "php"), + newInputFile(phpModule, "test/org/foo/BarTest.php", true, "php")); } - private DefaultInputFile newInputFile(Project module, String path, String deprecatedKey, boolean isTest) { - File file = new File(baseDir, path); - String deprecatedEffectiveKey = module.getKey() + ":" + deprecatedKey; + private DefaultInputFile newInputFile(Project module, String path, boolean isTest, String language) { return new DeprecatedDefaultInputFile(module.getKey(), path) - .setDeprecatedKey(deprecatedEffectiveKey) - .setFile(file) + .setModuleBaseDir(baseDir.toPath()) + .setLanguage(language) .setType(isTest ? InputFile.Type.TEST : InputFile.Type.MAIN); } @@ -98,11 +99,17 @@ public class ResourceKeyMigrationTest extends AbstractDbUnitTestCase { setupData("shouldMigrateResourceKeys"); Logger logger = mock(Logger.class); - ResourceKeyMigration migration = new ResourceKeyMigration(getSession(), logger); + ResourceKeyMigration migration = new ResourceKeyMigration(getSession(), new PathResolver(), logger); migration.checkIfMigrationNeeded(multiModuleProject); - migration.migrateIfNeeded(javaModule, javaInputFiles); - migration.migrateIfNeeded(phpModule, phpInputFiles); + DefaultModuleFileSystem fs = mock(DefaultModuleFileSystem.class); + when(fs.sourceDirs()).thenReturn(Arrays.asList(new File(baseDir, "src/main/java"))); + when(fs.testDirs()).thenReturn(Arrays.asList(new File(baseDir, "src/test/java"))); + migration.migrateIfNeeded(javaModule, javaInputFiles, fs); + + when(fs.sourceDirs()).thenReturn(Arrays.asList(new File(baseDir, "."))); + when(fs.testDirs()).thenReturn(Arrays.asList(new File(baseDir, "test"))); + migration.migrateIfNeeded(phpModule, phpInputFiles, fs); verify(logger).info("Component {} changed to {}", "b:org.foo.Bar", "b:src/main/java/org/foo/Bar.java"); verify(logger).warn("Directory with key b:org/foo matches both b:src/main/java/org/foo and b:src/test/java/org/foo. First match is arbitrary chosen."); diff --git a/sonar-batch/src/test/java/org/sonar/batch/index/ResourcePersisterTest.java b/sonar-batch/src/test/java/org/sonar/batch/index/ResourcePersisterTest.java index 6ec57439787..6a4506273b4 100644 --- a/sonar-batch/src/test/java/org/sonar/batch/index/ResourcePersisterTest.java +++ b/sonar-batch/src/test/java/org/sonar/batch/index/ResourcePersisterTest.java @@ -290,7 +290,7 @@ public class ResourcePersisterTest extends AbstractDbUnitTestCase { setupData("shared"); resourceCache.add(singleProject, null).setSnapshot(persister.persist(null, singleProject, null)); - persister.persist(singleProject, Directory.create("src/main/java/org/foo", "org.foo").setEffectiveKey("foo:src/main/java/org/foo"), null); + persister.persist(singleProject, Directory.create("src/main/java/org/foo").setEffectiveKey("foo:src/main/java/org/foo"), null); // check that the directory is attached to the project checkTables("shouldSaveNewDirectory", new String[] {"build_date", "created_at", "authorization_updated_at", "uuid", "project_uuid", "module_uuid", "module_uuid_path"}, "projects", "snapshots"); diff --git a/sonar-batch/src/test/java/org/sonar/batch/index/SourceDataFactoryTest.java b/sonar-batch/src/test/java/org/sonar/batch/index/SourceDataFactoryTest.java index 821cb735756..2c510d62aac 100644 --- a/sonar-batch/src/test/java/org/sonar/batch/index/SourceDataFactoryTest.java +++ b/sonar-batch/src/test/java/org/sonar/batch/index/SourceDataFactoryTest.java @@ -26,6 +26,7 @@ import org.junit.Before; import org.junit.Rule; import org.junit.Test; import org.junit.rules.TemporaryFolder; +import org.sonar.api.batch.fs.internal.DefaultFileSystem; import org.sonar.api.batch.fs.internal.DefaultInputFile; import org.sonar.api.batch.sensor.duplication.DuplicationGroup; import org.sonar.api.batch.sensor.highlighting.TypeOfText; @@ -35,6 +36,7 @@ import org.sonar.api.measures.Metric; import org.sonar.batch.duplication.DuplicationCache; import org.sonar.batch.highlighting.SyntaxHighlightingData; import org.sonar.batch.highlighting.SyntaxHighlightingDataBuilder; +import org.sonar.batch.scan.filesystem.InputFileMetadata; import org.sonar.batch.scan.measure.MeasureCache; import org.sonar.batch.source.CodeColorizers; import org.sonar.batch.symbol.DefaultSymbolTableBuilder; @@ -58,18 +60,21 @@ public class SourceDataFactoryTest { DuplicationCache duplicationCache = mock(DuplicationCache.class); CodeColorizers colorizers = mock(CodeColorizers.class); DefaultInputFile inputFile; + InputFileMetadata metadata; SourceDataFactory sut = new SourceDataFactory(measureCache, componentDataCache, duplicationCache, colorizers); FileSourceDb.Data.Builder output; @Before public void setUp() throws Exception { // generate a file with 3 lines - File file = temp.newFile(); + File baseDir = temp.newFolder(); + DefaultFileSystem fs = new DefaultFileSystem(baseDir.toPath()); inputFile = new DefaultInputFile("module_key", "src/Foo.java") .setLines(3) - .setEncoding(Charsets.UTF_8.name()) - .setFile(file); - FileUtils.write(file, "one\ntwo\nthree\n"); + .setCharset(Charsets.UTF_8); + fs.add(inputFile); + metadata = new InputFileMetadata(); + FileUtils.write(inputFile.file(), "one\ntwo\nthree\n"); output = sut.createForSource(inputFile); } @@ -84,7 +89,7 @@ public class SourceDataFactoryTest { @Test public void consolidateData() throws Exception { - byte[] bytes = sut.consolidateData(inputFile); + byte[] bytes = sut.consolidateData(inputFile, metadata); assertThat(bytes).isNotEmpty(); } @@ -145,7 +150,6 @@ public class SourceDataFactoryTest { Arrays.asList(new Measure().setData(dataPerLine).setMetric(metric))); } - @Test public void applyDuplications() throws Exception { DuplicationGroup group1 = new DuplicationGroup(new DuplicationGroup.Block(inputFile.key(), 1, 1)) @@ -169,7 +173,7 @@ public class SourceDataFactoryTest { public void applyHighlighting_missing() throws Exception { when(componentDataCache.getData(inputFile.key(), SnapshotDataTypes.SYNTAX_HIGHLIGHTING)).thenReturn(null); - sut.applyHighlighting(inputFile, output); + sut.applyHighlighting(inputFile, metadata, output); FileSourceDb.Data data = output.build(); assertThat(data.getLines(0).hasHighlighting()).isFalse(); @@ -185,9 +189,9 @@ public class SourceDataFactoryTest { .registerHighlightingRule(7, 16, TypeOfText.CONSTANT) .build(); when(componentDataCache.getData(inputFile.key(), SnapshotDataTypes.SYNTAX_HIGHLIGHTING)).thenReturn(highlighting); - inputFile.setOriginalLineOffsets(new long[] {0, 4, 7}); + metadata.setOriginalLineOffsets(new int[] {0, 4, 7}); - sut.applyHighlighting(inputFile, output); + sut.applyHighlighting(inputFile, metadata, output); FileSourceDb.Data data = output.build(); assertThat(data.getLines(0).getHighlighting()).isEqualTo("0,4,a"); @@ -203,9 +207,9 @@ public class SourceDataFactoryTest { .registerHighlightingRule(10, 16, TypeOfText.CONSTANT) .build(); when(componentDataCache.getData(inputFile.key(), SnapshotDataTypes.SYNTAX_HIGHLIGHTING)).thenReturn(highlighting); - inputFile.setOriginalLineOffsets(new long[] {0, 4, 7}); + metadata.setOriginalLineOffsets(new int[] {0, 4, 7}); - sut.applyHighlighting(inputFile, output); + sut.applyHighlighting(inputFile, metadata, output); FileSourceDb.Data data = output.build(); assertThat(data.getLines(0).getHighlighting()).isEqualTo("0,3,a"); @@ -222,9 +226,9 @@ public class SourceDataFactoryTest { .registerHighlightingRule(8, 15, TypeOfText.KEYWORD) .build(); when(componentDataCache.getData(inputFile.key(), SnapshotDataTypes.SYNTAX_HIGHLIGHTING)).thenReturn(highlighting); - inputFile.setOriginalLineOffsets(new long[] {0, 4, 7}); + metadata.setOriginalLineOffsets(new int[] {0, 4, 7}); - sut.applyHighlighting(inputFile, output); + sut.applyHighlighting(inputFile, metadata, output); FileSourceDb.Data data = output.build(); assertThat(data.getLines(0).getHighlighting()).isEqualTo("0,3,a"); @@ -241,9 +245,9 @@ public class SourceDataFactoryTest { .registerHighlightingRule(8, 15, TypeOfText.KEYWORD) .build(); when(componentDataCache.getData(inputFile.key(), SnapshotDataTypes.SYNTAX_HIGHLIGHTING)).thenReturn(highlighting); - inputFile.setOriginalLineOffsets(new long[] {0, 4, 7}); + metadata.setOriginalLineOffsets(new int[] {0, 4, 7}); - sut.applyHighlighting(inputFile, output); + sut.applyHighlighting(inputFile, metadata, output); FileSourceDb.Data data = output.build(); assertThat(data.getLines(0).getHighlighting()).isEqualTo("0,3,a"); @@ -255,7 +259,7 @@ public class SourceDataFactoryTest { public void applySymbolReferences_missing() throws Exception { when(componentDataCache.getData(inputFile.key(), SnapshotDataTypes.SYMBOL_HIGHLIGHTING)).thenReturn(null); - sut.applySymbolReferences(inputFile, output); + sut.applySymbolReferences(inputFile, metadata, output); FileSourceDb.Data data = output.build(); assertThat(data.getLines(0).hasSymbols()).isFalse(); @@ -273,9 +277,9 @@ public class SourceDataFactoryTest { symbolBuilder.newReference(s2, 0); symbolBuilder.newReference(s2, 7); when(componentDataCache.getData(inputFile.key(), SnapshotDataTypes.SYMBOL_HIGHLIGHTING)).thenReturn(symbolBuilder.build()); - inputFile.setOriginalLineOffsets(new long[] {0, 4, 7}); + metadata.setOriginalLineOffsets(new int[] {0, 4, 7}); - sut.applySymbolReferences(inputFile, output); + sut.applySymbolReferences(inputFile, metadata, output); FileSourceDb.Data data = output.build(); assertThat(data.getLines(0).getSymbols()).isEqualTo("1,2,1;0,2,2"); @@ -293,9 +297,9 @@ public class SourceDataFactoryTest { symbolBuilder.newReference(s1, 11); symbolBuilder.newReference(s1, 4); when(componentDataCache.getData(inputFile.key(), SnapshotDataTypes.SYMBOL_HIGHLIGHTING)).thenReturn(symbolBuilder.build()); - inputFile.setOriginalLineOffsets(new long[] {0, 4, 7}); + metadata.setOriginalLineOffsets(new int[] {0, 4, 7}); - sut.applySymbolReferences(inputFile, output); + sut.applySymbolReferences(inputFile, metadata, output); FileSourceDb.Data data = output.build(); assertThat(data.getLines(0).getSymbols()).isEqualTo("1,2,1;0,2,2"); diff --git a/sonar-batch/src/test/java/org/sonar/batch/issue/IssuableFactoryTest.java b/sonar-batch/src/test/java/org/sonar/batch/issue/IssuableFactoryTest.java index c24e04a1ded..514a6d05a1b 100644 --- a/sonar-batch/src/test/java/org/sonar/batch/issue/IssuableFactoryTest.java +++ b/sonar-batch/src/test/java/org/sonar/batch/issue/IssuableFactoryTest.java @@ -40,7 +40,7 @@ public class IssuableFactoryTest { @Test public void file_should_be_issuable() throws Exception { IssuableFactory factory = new IssuableFactory(moduleIssues, cache, projectTree); - Component component = new ResourceComponent(new File("foo/bar.c").setEffectiveKey("foo/bar.c")); + Component component = new ResourceComponent(File.create("foo/bar.c").setEffectiveKey("foo/bar.c")); Issuable issuable = factory.loadPerspective(Issuable.class, component); assertThat(issuable).isNotNull(); 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 0594cb16234..7ffa9905721 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 @@ -207,7 +207,7 @@ public class ModuleIssuesTest { initModuleIssues(); org.sonar.api.rules.Rule rule = org.sonar.api.rules.Rule.create("squid", "AvoidCycle", "Avoid Cycle"); - Resource resource = new File("org/struts/Action.java").setEffectiveKey("struts:src/org/struts/Action.java"); + Resource resource = File.create("org/struts/Action.java").setEffectiveKey("struts:src/org/struts/Action.java"); Violation violation = new Violation(rule, resource); violation.setLineId(42); violation.setSeverity(RulePriority.CRITICAL); diff --git a/sonar-batch/src/test/java/org/sonar/batch/issue/ignore/scanner/IssueExclusionsLoaderTest.java b/sonar-batch/src/test/java/org/sonar/batch/issue/ignore/scanner/IssueExclusionsLoaderTest.java index 9fd36ece0b7..3cca58ac2b2 100644 --- a/sonar-batch/src/test/java/org/sonar/batch/issue/ignore/scanner/IssueExclusionsLoaderTest.java +++ b/sonar-batch/src/test/java/org/sonar/batch/issue/ignore/scanner/IssueExclusionsLoaderTest.java @@ -72,7 +72,7 @@ public class IssueExclusionsLoaderTest { @Before public void before() throws Exception { baseDir = temp.newFolder(); - fs = new DefaultFileSystem(baseDir).setEncoding(UTF_8); + fs = new DefaultFileSystem(baseDir.toPath()).setEncoding(UTF_8); MockitoAnnotations.initMocks(this); scanner = new IssueExclusionsLoader(regexpScanner, exclusionPatternInitializer, inclusionPatternInitializer, fs); } @@ -106,11 +106,9 @@ public class IssueExclusionsLoaderTest { public void shouldAnalyzeProject() throws IOException { File javaFile1 = new File(baseDir, "src/main/java/Foo.java"); fs.add(new DeprecatedDefaultInputFile("polop", "src/main/java/Foo.java") - .setFile(javaFile1) .setType(InputFile.Type.MAIN)); File javaTestFile1 = new File(baseDir, "src/test/java/FooTest.java"); fs.add(new DeprecatedDefaultInputFile("polop", "src/test/java/FooTest.java") - .setFile(javaTestFile1) .setType(InputFile.Type.TEST)); when(exclusionPatternInitializer.hasFileContentPattern()).thenReturn(true); @@ -129,11 +127,9 @@ public class IssueExclusionsLoaderTest { public void shouldAnalyseFilesOnlyWhenRegexConfigured() throws IOException { File javaFile1 = new File(baseDir, "src/main/java/Foo.java"); fs.add(new DeprecatedDefaultInputFile("polop", "src/main/java/Foo.java") - .setFile(javaFile1) .setType(InputFile.Type.MAIN)); File javaTestFile1 = new File(baseDir, "src/test/java/FooTest.java"); fs.add(new DeprecatedDefaultInputFile("polop", "src/test/java/FooTest.java") - .setFile(javaTestFile1) .setType(InputFile.Type.TEST)); when(exclusionPatternInitializer.hasFileContentPattern()).thenReturn(false); @@ -150,7 +146,6 @@ public class IssueExclusionsLoaderTest { public void shouldReportFailure() throws IOException { File phpFile1 = new File(baseDir, "src/Foo.php"); fs.add(new DeprecatedDefaultInputFile("polop", "src/Foo.php") - .setFile(phpFile1) .setType(InputFile.Type.MAIN)); when(exclusionPatternInitializer.hasFileContentPattern()).thenReturn(true); diff --git a/sonar-batch/src/test/java/org/sonar/batch/issue/tracking/IssueTrackingDecoratorTest.java b/sonar-batch/src/test/java/org/sonar/batch/issue/tracking/IssueTrackingDecoratorTest.java index 7691dbf6538..1c5e080cd06 100644 --- a/sonar-batch/src/test/java/org/sonar/batch/issue/tracking/IssueTrackingDecoratorTest.java +++ b/sonar-batch/src/test/java/org/sonar/batch/issue/tracking/IssueTrackingDecoratorTest.java @@ -19,9 +19,12 @@ */ package org.sonar.batch.issue.tracking; +import com.google.common.base.Charsets; import org.apache.commons.codec.digest.DigestUtils; +import org.apache.commons.io.FileUtils; import org.junit.Before; import org.junit.Test; +import org.junit.rules.TemporaryFolder; import org.mockito.ArgumentCaptor; import org.mockito.ArgumentMatcher; import org.sonar.api.batch.DecoratorContext; @@ -41,6 +44,7 @@ import org.sonar.api.utils.Duration; import org.sonar.api.utils.System2; import org.sonar.batch.issue.IssueCache; import org.sonar.batch.scan.LastLineHashes; +import org.sonar.batch.scan.filesystem.InputFileMetadata; import org.sonar.batch.scan.filesystem.InputPathCache; import org.sonar.core.issue.IssueUpdater; import org.sonar.core.issue.db.IssueChangeDto; @@ -48,6 +52,7 @@ import org.sonar.core.issue.db.IssueDto; import org.sonar.core.issue.workflow.IssueWorkflow; import org.sonar.java.api.JavaClass; +import java.io.IOException; import java.util.Arrays; import java.util.Collection; import java.util.Collections; @@ -71,6 +76,9 @@ import static org.mockito.Mockito.when; public class IssueTrackingDecoratorTest { + @org.junit.Rule + public TemporaryFolder temp = new TemporaryFolder(); + IssueTrackingDecorator decorator; IssueCache issueCache = mock(IssueCache.class, RETURNS_MOCKS); InitialOpenIssuesStack initialOpenIssues = mock(InitialOpenIssuesStack.class); @@ -124,6 +132,7 @@ public class IssueTrackingDecoratorTest { List<PreviousIssue> dbIssues = Collections.emptyList(); when(initialOpenIssues.selectAndRemoveIssues("struts:Action.java")).thenReturn(dbIssues); when(inputPathCache.getFile("foo", "Action.java")).thenReturn(mock(DefaultInputFile.class)); + when(inputPathCache.getFileMetadata("foo", "Action.java")).thenReturn(new InputFileMetadata()); decorator.doDecorate(file); // Apply filters, track, apply transitions, notify extensions then update cache @@ -152,6 +161,7 @@ public class IssueTrackingDecoratorTest { when(tracking.track(isA(SourceHashHolder.class), anyCollection(), anyCollection())).thenReturn(trackingResult); when(inputPathCache.getFile("foo", "Action.java")).thenReturn(mock(DefaultInputFile.class)); + when(inputPathCache.getFileMetadata("foo", "Action.java")).thenReturn(new InputFileMetadata()); decorator.doDecorate(file); @@ -210,10 +220,13 @@ public class IssueTrackingDecoratorTest { assertThat(issue.isOnDisabledRule()).isFalse(); } - private Resource mockHashes(String originalSource, String newSource) { + private Resource mockHashes(String originalSource, String newSource) throws IOException { DefaultInputFile inputFile = mock(DefaultInputFile.class); - byte[][] hashes = computeHashes(newSource); - when(inputFile.lineHashes()).thenReturn(hashes); + java.io.File f = temp.newFile(); + when(inputFile.path()).thenReturn(f.toPath()); + when(inputFile.charset()).thenReturn(Charsets.UTF_8); + when(inputFile.lines()).thenReturn(newSource.split("\n").length); + FileUtils.write(f, newSource, Charsets.UTF_8); when(inputFile.key()).thenReturn("foo:Action.java"); when(inputPathCache.getFile("foo", "Action.java")).thenReturn(inputFile); when(lastSnapshots.getLineHashes("foo:Action.java")).thenReturn(computeHexHashes(originalSource)); @@ -561,15 +574,6 @@ public class IssueTrackingDecoratorTest { assertThat(issue.changes()).hasSize(1); } - private byte[][] computeHashes(String source) { - String[] lines = source.split("\n"); - byte[][] hashes = new byte[lines.length][]; - for (int i = 0; i < lines.length; i++) { - hashes[i] = DigestUtils.md5(lines[i].replaceAll("[\t ]", "")); - } - return hashes; - } - private String[] computeHexHashes(String source) { String[] lines = source.split("\n"); String[] hashes = new String[lines.length]; diff --git a/sonar-batch/src/test/java/org/sonar/batch/issue/tracking/IssueTrackingTest.java b/sonar-batch/src/test/java/org/sonar/batch/issue/tracking/IssueTrackingTest.java index 2efb24c13eb..bcc25ac598c 100644 --- a/sonar-batch/src/test/java/org/sonar/batch/issue/tracking/IssueTrackingTest.java +++ b/sonar-batch/src/test/java/org/sonar/batch/issue/tracking/IssueTrackingTest.java @@ -24,8 +24,11 @@ import com.google.common.base.Charsets; import com.google.common.collect.Lists; import com.google.common.io.Resources; import org.apache.commons.codec.digest.DigestUtils; +import org.apache.commons.io.FileUtils; 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.issue.Issue; import org.sonar.api.issue.internal.DefaultIssue; @@ -35,6 +38,7 @@ import org.sonar.api.rule.RuleKey; import org.sonar.batch.scan.LastLineHashes; import org.sonar.core.issue.db.IssueDto; +import java.io.File; import java.io.IOException; import java.util.Arrays; import java.util.Collections; @@ -47,6 +51,9 @@ import static org.mockito.Mockito.when; public class IssueTrackingTest { + @Rule + public TemporaryFolder temp = new TemporaryFolder(); + IssueTracking tracking; Resource project; SourceHashHolder sourceHashHolder; @@ -345,22 +352,17 @@ public class IssueTrackingTest { private void initLastHashes(String reference, String newSource) throws IOException { DefaultInputFile inputFile = mock(DefaultInputFile.class); - byte[][] hashes = computeHashes(load(newSource)); - when(inputFile.lineHashes()).thenReturn(hashes); + File f = temp.newFile(); + when(inputFile.path()).thenReturn(f.toPath()); + when(inputFile.charset()).thenReturn(Charsets.UTF_8); + String data = load(newSource); + when(inputFile.lines()).thenReturn(data.split("\n").length); + FileUtils.write(f, data, Charsets.UTF_8); when(inputFile.key()).thenReturn("foo:Action.java"); when(lastSnapshots.getLineHashes("foo:Action.java")).thenReturn(computeHexHashes(load(reference))); sourceHashHolder = new SourceHashHolder(inputFile, lastSnapshots); } - private byte[][] computeHashes(String source) { - String[] lines = source.split("\n"); - byte[][] hashes = new byte[lines.length][]; - for (int i = 0; i < lines.length; i++) { - hashes[i] = DigestUtils.md5(lines[i].replaceAll("[\t ]", "")); - } - return hashes; - } - private String[] computeHexHashes(String source) { String[] lines = source.split("\n"); String[] hashes = new String[lines.length]; diff --git a/sonar-batch/src/test/java/org/sonar/batch/issue/tracking/SourceHashHolderTest.java b/sonar-batch/src/test/java/org/sonar/batch/issue/tracking/SourceHashHolderTest.java index 6ac6645bbae..59371ca4947 100644 --- a/sonar-batch/src/test/java/org/sonar/batch/issue/tracking/SourceHashHolderTest.java +++ b/sonar-batch/src/test/java/org/sonar/batch/issue/tracking/SourceHashHolderTest.java @@ -19,14 +19,19 @@ */ package org.sonar.batch.issue.tracking; +import com.google.common.base.Charsets; +import org.apache.commons.io.FileUtils; import org.junit.Before; +import org.junit.Rule; import org.junit.Test; +import org.junit.rules.TemporaryFolder; import org.mockito.Mockito; import org.sonar.api.batch.fs.InputFile; import org.sonar.api.batch.fs.internal.DefaultInputFile; import org.sonar.batch.scan.LastLineHashes; -import static org.apache.commons.codec.digest.DigestUtils.md5; +import java.io.File; + import static org.apache.commons.codec.digest.DigestUtils.md5Hex; import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.Mockito.mock; @@ -35,39 +40,48 @@ import static org.mockito.Mockito.when; public class SourceHashHolderTest { + @Rule + public TemporaryFolder temp = new TemporaryFolder(); + SourceHashHolder sourceHashHolder; LastLineHashes lastSnapshots; DefaultInputFile file; + private File ioFile; + @Before - public void setUp() { + public void setUp() throws Exception { lastSnapshots = mock(LastLineHashes.class); file = mock(DefaultInputFile.class); + ioFile = temp.newFile(); + when(file.file()).thenReturn(ioFile); + when(file.path()).thenReturn(ioFile.toPath()); + when(file.lines()).thenReturn(1); + when(file.charset()).thenReturn(Charsets.UTF_8); sourceHashHolder = new SourceHashHolder(file, lastSnapshots); } @Test - public void should_lazy_load_line_hashes() { + public void should_lazy_load_line_hashes() throws Exception { final String source = "source"; - when(file.lineHashes()).thenReturn(new byte[][] {md5(source), null}); + FileUtils.write(ioFile, source + "\n", Charsets.UTF_8); + when(file.lines()).thenReturn(2); assertThat(sourceHashHolder.getHashedSource().getHash(1)).isEqualTo(md5Hex(source)); assertThat(sourceHashHolder.getHashedSource().getHash(2)).isEqualTo(""); - verify(file).lineHashes(); verify(file).key(); verify(file).status(); assertThat(sourceHashHolder.getHashedSource().getHash(1)).isEqualTo(md5Hex(source)); - Mockito.verifyNoMoreInteractions(file); } @Test - public void should_lazy_load_reference_hashes_when_status_changed() { + public void should_lazy_load_reference_hashes_when_status_changed() throws Exception { final String source = "source"; String key = "foo:src/Foo.java"; - when(file.lineHashes()).thenReturn(new byte[][] {md5(source)}); + FileUtils.write(ioFile, source, Charsets.UTF_8); when(file.key()).thenReturn(key); when(file.status()).thenReturn(InputFile.Status.CHANGED); when(lastSnapshots.getLineHashes(key)).thenReturn(new String[] {md5Hex(source)}); @@ -80,23 +94,22 @@ public class SourceHashHolderTest { } @Test - public void should_not_load_reference_hashes_when_status_same() { + public void should_not_load_reference_hashes_when_status_same() throws Exception { final String source = "source"; String key = "foo:src/Foo.java"; - when(file.lineHashes()).thenReturn(new byte[][] {md5(source)}); + FileUtils.write(ioFile, source, Charsets.UTF_8); when(file.key()).thenReturn(key); when(file.status()).thenReturn(InputFile.Status.SAME); assertThat(sourceHashHolder.getHashedReference().getHash(1)).isEqualTo(md5Hex(source)); - assertThat(sourceHashHolder.getHashedReference().getHash(1)).isEqualTo(md5Hex(source)); Mockito.verifyNoMoreInteractions(lastSnapshots); } @Test - public void no_reference_hashes_when_status_added() { + public void no_reference_hashes_when_status_added() throws Exception { final String source = "source"; String key = "foo:src/Foo.java"; - when(file.lineHashes()).thenReturn(new byte[][] {md5(source)}); + FileUtils.write(ioFile, source, Charsets.UTF_8); when(file.key()).thenReturn(key); when(file.status()).thenReturn(InputFile.Status.ADDED); diff --git a/sonar-batch/src/test/java/org/sonar/batch/phases/DecoratorsExecutorTest.java b/sonar-batch/src/test/java/org/sonar/batch/phases/DecoratorsExecutorTest.java index 45774d11f95..7b644d27530 100644 --- a/sonar-batch/src/test/java/org/sonar/batch/phases/DecoratorsExecutorTest.java +++ b/sonar-batch/src/test/java/org/sonar/batch/phases/DecoratorsExecutorTest.java @@ -28,8 +28,8 @@ import org.sonar.api.resources.File; import org.sonar.api.resources.Project; import org.sonar.api.resources.Resource; import org.sonar.api.utils.SonarException; -import org.sonar.batch.DefaultDecoratorContext; import org.sonar.batch.bootstrap.BatchExtensionDictionnary; +import org.sonar.batch.deprecated.decorator.DefaultDecoratorContext; import org.sonar.batch.duplication.DuplicationCache; import org.sonar.batch.events.EventBus; import org.sonar.batch.scan.measure.MeasureCache; @@ -69,7 +69,7 @@ public class DecoratorsExecutorTest { DecoratorsExecutor executor = new DecoratorsExecutor(mock(BatchExtensionDictionnary.class), new Project("key"), mock(SonarIndex.class), mock(EventBus.class), mock(CoverageExclusions.class), mock(MeasureCache.class), mock(MetricFinder.class), mock(DuplicationCache.class)); try { - executor.executeDecorator(decorator, mock(DefaultDecoratorContext.class), File.create("src/org/foo/Bar.java", "org/foo/Bar.java", null, false)); + executor.executeDecorator(decorator, mock(DefaultDecoratorContext.class), File.create("src/org/foo/Bar.java", null, false)); fail("Exception has not been thrown"); } catch (SonarException e) { diff --git a/sonar-batch/src/test/java/org/sonar/batch/qualitygate/GenerateQualityGateEventsTest.java b/sonar-batch/src/test/java/org/sonar/batch/qualitygate/GenerateQualityGateEventsTest.java index 83cab61793e..e7e2c332838 100644 --- a/sonar-batch/src/test/java/org/sonar/batch/qualitygate/GenerateQualityGateEventsTest.java +++ b/sonar-batch/src/test/java/org/sonar/batch/qualitygate/GenerateQualityGateEventsTest.java @@ -19,8 +19,6 @@ */ package org.sonar.batch.qualitygate; -import org.sonar.batch.qualitygate.GenerateQualityGateEvents; - import org.junit.Before; import org.junit.Test; import org.sonar.api.batch.DecoratorContext; @@ -35,14 +33,20 @@ import org.sonar.api.notifications.NotificationManager; import org.sonar.api.resources.File; import org.sonar.api.resources.Project; import org.sonar.api.test.ProjectTestBuilder; -import org.sonar.batch.qualitygate.QualityGate; import java.util.Arrays; import java.util.Date; import static org.assertj.core.api.Assertions.assertThat; -import static org.mockito.Matchers.*; -import static org.mockito.Mockito.*; +import static org.mockito.Matchers.any; +import static org.mockito.Matchers.anyString; +import static org.mockito.Matchers.eq; +import static org.mockito.Matchers.isNull; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.never; +import static org.mockito.Mockito.times; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; public class GenerateQualityGateEventsTest { private GenerateQualityGateEvents decorator; @@ -80,7 +84,7 @@ public class GenerateQualityGateEventsTest { @Test public void shouldNotDecorateIfNotRootProject() { - decorator.decorate(new File("Foo"), context); + decorator.decorate(File.create("Foo"), context); verify(context, never()).createEvent(anyString(), anyString(), anyString(), (Date) isNull()); } 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 87a72c6c057..30f56d3a46e 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 @@ -62,17 +62,17 @@ public class ComponentsPublisherTest { dir.setId(3).setUuid("DIR_UUID"); resourceCache.add(dir, module1).setSnapshot(new Snapshot().setId(13)); - org.sonar.api.resources.File file = org.sonar.api.resources.File.create("src/Foo.java", "Foo.java", Java.INSTANCE, false); + org.sonar.api.resources.File file = org.sonar.api.resources.File.create("src/Foo.java", Java.INSTANCE, false); file.setEffectiveKey("foo:src/Foo.java"); file.setId(4).setUuid("FILE_UUID"); resourceCache.add(file, dir).setSnapshot(new Snapshot().setId(14)); - org.sonar.api.resources.File fileWithoutLang = org.sonar.api.resources.File.create("src/make", "make", null, false); + org.sonar.api.resources.File fileWithoutLang = org.sonar.api.resources.File.create("src/make", null, false); fileWithoutLang.setEffectiveKey("foo:src/make"); fileWithoutLang.setId(5).setUuid("FILE_WITHOUT_LANG_UUID"); resourceCache.add(fileWithoutLang, dir).setSnapshot(new Snapshot().setId(15)); - org.sonar.api.resources.File testFile = org.sonar.api.resources.File.create("test/FooTest.java", "FooTest.java", Java.INSTANCE, true); + org.sonar.api.resources.File testFile = org.sonar.api.resources.File.create("test/FooTest.java", Java.INSTANCE, true); testFile.setEffectiveKey("foo:test/FooTest.java"); testFile.setId(6).setUuid("TEST_FILE_UUID"); resourceCache.add(testFile, dir).setSnapshot(new Snapshot().setId(16)); diff --git a/sonar-batch/src/test/java/org/sonar/batch/user/UserRepositoryTest.java b/sonar-batch/src/test/java/org/sonar/batch/repository/user/UserRepositoryTest.java index 7191d185fa3..ad8c954e98f 100644 --- a/sonar-batch/src/test/java/org/sonar/batch/user/UserRepositoryTest.java +++ b/sonar-batch/src/test/java/org/sonar/batch/repository/user/UserRepositoryTest.java @@ -17,7 +17,7 @@ * along with this program; if not, write to the Free Software Foundation, * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ -package org.sonar.batch.user; +package org.sonar.batch.repository.user; import org.junit.Test; import org.sonar.batch.bootstrap.ServerClient; diff --git a/sonar-batch/src/test/java/org/sonar/batch/rule/QProfileSensorTest.java b/sonar-batch/src/test/java/org/sonar/batch/rule/QProfileSensorTest.java index c9e6deabcaf..7c83baad914 100644 --- a/sonar-batch/src/test/java/org/sonar/batch/rule/QProfileSensorTest.java +++ b/sonar-batch/src/test/java/org/sonar/batch/rule/QProfileSensorTest.java @@ -23,6 +23,7 @@ import org.junit.Before; import org.junit.Rule; import org.junit.Test; import org.junit.rules.TemporaryFolder; +import org.sonar.api.batch.AnalysisMode; import org.sonar.api.batch.SensorContext; import org.sonar.api.batch.fs.internal.DefaultFileSystem; import org.sonar.api.measures.CoreMetrics; @@ -57,20 +58,29 @@ public class QProfileSensorTest { @Before public void prepare() throws Exception { - fs = new DefaultFileSystem(temp.newFolder()); + fs = new DefaultFileSystem(temp.newFolder().toPath()); } @Test public void to_string() throws Exception { - QProfileSensor sensor = new QProfileSensor(moduleQProfiles, fs); + QProfileSensor sensor = new QProfileSensor(moduleQProfiles, fs, mock(AnalysisMode.class)); assertThat(sensor.toString()).isEqualTo("QProfileSensor"); } @Test + public void no_execution_in_preview() throws Exception { + AnalysisMode analysisMode = mock(AnalysisMode.class); + when(analysisMode.isPreview()).thenReturn(true); + QProfileSensor sensor = new QProfileSensor(moduleQProfiles, fs, analysisMode); + assertThat(sensor.shouldExecuteOnProject(project)).isFalse(); + + } + + @Test public void no_qprofiles() throws Exception { when(moduleQProfiles.findAll()).thenReturn(Collections.<QProfile>emptyList()); - QProfileSensor sensor = new QProfileSensor(moduleQProfiles, fs); + QProfileSensor sensor = new QProfileSensor(moduleQProfiles, fs, mock(AnalysisMode.class)); assertThat(sensor.shouldExecuteOnProject(project)).isTrue(); sensor.analyse(project, sensorContext); @@ -85,7 +95,7 @@ public class QProfileSensorTest { when(moduleQProfiles.findByLanguage("abap")).thenReturn(null); fs.addLanguages("java", "php", "abap"); - QProfileSensor sensor = new QProfileSensor(moduleQProfiles, fs); + QProfileSensor sensor = new QProfileSensor(moduleQProfiles, fs, mock(AnalysisMode.class)); assertThat(sensor.shouldExecuteOnProject(project)).isTrue(); sensor.analyse(project, sensorContext); } @@ -97,7 +107,7 @@ public class QProfileSensorTest { when(moduleQProfiles.findByLanguage("abap")).thenReturn(null); fs.addLanguages("java"); - QProfileSensor sensor = new QProfileSensor(moduleQProfiles, fs); + QProfileSensor sensor = new QProfileSensor(moduleQProfiles, fs, mock(AnalysisMode.class)); assertThat(sensor.shouldExecuteOnProject(project)).isTrue(); sensor.analyse(project, sensorContext); @@ -113,7 +123,7 @@ public class QProfileSensorTest { when(moduleQProfiles.findByLanguage("abap")).thenReturn(null); fs.addLanguages("java", "php"); - QProfileSensor sensor = new QProfileSensor(moduleQProfiles, fs); + QProfileSensor sensor = new QProfileSensor(moduleQProfiles, fs, mock(AnalysisMode.class)); assertThat(sensor.shouldExecuteOnProject(project)).isTrue(); sensor.analyse(project, sensorContext); diff --git a/sonar-batch/src/test/java/org/sonar/batch/rule/QProfileVerifierTest.java b/sonar-batch/src/test/java/org/sonar/batch/rule/QProfileVerifierTest.java index 9c5db0f6d6a..61463ae5742 100644 --- a/sonar-batch/src/test/java/org/sonar/batch/rule/QProfileVerifierTest.java +++ b/sonar-batch/src/test/java/org/sonar/batch/rule/QProfileVerifierTest.java @@ -47,7 +47,7 @@ public class QProfileVerifierTest { @Before public void before() throws Exception { - fs = new DefaultFileSystem(temp.newFolder()); + fs = new DefaultFileSystem(temp.newFolder().toPath()); profiles = mock(ModuleQProfiles.class); QProfile javaProfile = new QProfile().setKey("p1").setName("My Java profile").setLanguage("java"); when(profiles.findByLanguage("java")).thenReturn(javaProfile); diff --git a/sonar-batch/src/test/java/org/sonar/batch/scan/LanguageVerifierTest.java b/sonar-batch/src/test/java/org/sonar/batch/scan/LanguageVerifierTest.java index a60fd596e53..420d0641c36 100644 --- a/sonar-batch/src/test/java/org/sonar/batch/scan/LanguageVerifierTest.java +++ b/sonar-batch/src/test/java/org/sonar/batch/scan/LanguageVerifierTest.java @@ -29,8 +29,8 @@ import org.sonar.api.config.Settings; import org.sonar.api.resources.Java; import org.sonar.api.resources.Languages; import org.sonar.api.utils.MessageException; -import org.sonar.batch.languages.DefaultLanguagesReferential; -import org.sonar.batch.languages.LanguagesReferential; +import org.sonar.batch.repository.language.DefaultLanguagesRepository; +import org.sonar.batch.repository.language.LanguagesRepository; import static org.assertj.core.api.Assertions.assertThat; @@ -43,12 +43,12 @@ public class LanguageVerifierTest { public ExpectedException thrown = ExpectedException.none(); private Settings settings = new Settings(); - private LanguagesReferential languages = new DefaultLanguagesReferential(new Languages(Java.INSTANCE)); + private LanguagesRepository languages = new DefaultLanguagesRepository(new Languages(Java.INSTANCE)); private DefaultFileSystem fs; @Before public void prepare() throws Exception { - fs = new DefaultFileSystem(temp.newFolder()); + fs = new DefaultFileSystem(temp.newFolder().toPath()); } @Test diff --git a/sonar-batch/src/test/java/org/sonar/batch/scan/filesystem/AdditionalFilePredicatesTest.java b/sonar-batch/src/test/java/org/sonar/batch/scan/filesystem/AdditionalFilePredicatesTest.java index ff6e76e0857..ad3dfffc491 100644 --- a/sonar-batch/src/test/java/org/sonar/batch/scan/filesystem/AdditionalFilePredicatesTest.java +++ b/sonar-batch/src/test/java/org/sonar/batch/scan/filesystem/AdditionalFilePredicatesTest.java @@ -26,8 +26,6 @@ import org.sonar.api.batch.fs.FilePredicate; import org.sonar.api.batch.fs.internal.DefaultInputFile; import org.sonar.api.batch.fs.internal.DeprecatedDefaultInputFile; -import java.io.File; - import static org.assertj.core.api.Assertions.assertThat; public class AdditionalFilePredicatesTest { @@ -45,38 +43,4 @@ public class AdditionalFilePredicatesTest { inputFile = new DeprecatedDefaultInputFile("struts", "Filter.java"); assertThat(predicate.apply(inputFile)).isFalse(); } - - @Test - public void deprecated_key() throws Exception { - FilePredicate predicate = new AdditionalFilePredicates.DeprecatedKeyPredicate("struts:Action.java"); - - DeprecatedDefaultInputFile inputFile = new DeprecatedDefaultInputFile("struts", "Action.java").setDeprecatedKey("struts:Action.java"); - assertThat(predicate.apply(inputFile)).isTrue(); - - inputFile = new DeprecatedDefaultInputFile("struts", "Filter.java").setDeprecatedKey("struts:Filter.java"); - assertThat(predicate.apply(inputFile)).isFalse(); - } - - @Test - public void absolute_path_of_source_dir() throws Exception { - File dir = temp.newFolder(); - FilePredicate predicate = new AdditionalFilePredicates.SourceDirPredicate(dir.getAbsolutePath()); - - DeprecatedDefaultInputFile inputFile = new DeprecatedDefaultInputFile("struts", "Action.java").setSourceDirAbsolutePath(dir.getAbsolutePath()); - assertThat(predicate.apply(inputFile)).isTrue(); - - inputFile = new DeprecatedDefaultInputFile("struts", "Filter.java").setSourceDirAbsolutePath(temp.newFolder().getAbsolutePath()); - assertThat(predicate.apply(inputFile)).isFalse(); - } - - @Test - public void path_relative_to_source_dir() throws Exception { - FilePredicate predicate = new AdditionalFilePredicates.SourceRelativePathPredicate("foo/Bar.php"); - - DeprecatedDefaultInputFile inputFile = new DeprecatedDefaultInputFile("foo", "src/php/foo/Bar.php").setPathRelativeToSourceDir("foo/Bar.php"); - assertThat(predicate.apply(inputFile)).isTrue(); - - inputFile = new DeprecatedDefaultInputFile("foo", "foo/Bar.php").setPathRelativeToSourceDir("Bar.php"); - assertThat(predicate.apply(inputFile)).isFalse(); - } } diff --git a/sonar-batch/src/test/java/org/sonar/batch/scan/filesystem/ComponentIndexerTest.java b/sonar-batch/src/test/java/org/sonar/batch/scan/filesystem/ComponentIndexerTest.java index 702aa2fb068..5960fab5c2d 100644 --- a/sonar-batch/src/test/java/org/sonar/batch/scan/filesystem/ComponentIndexerTest.java +++ b/sonar-batch/src/test/java/org/sonar/batch/scan/filesystem/ComponentIndexerTest.java @@ -42,6 +42,7 @@ import java.io.IOException; import static org.mockito.Matchers.argThat; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; public class ComponentIndexerTest { @@ -52,13 +53,17 @@ public class ComponentIndexerTest { private SonarIndex sonarIndex; private AbstractLanguage cobolLanguage; private Project project; + private ModuleFileSystemInitializer initializer; @Before public void prepare() throws IOException { baseDir = temp.newFolder(); - fs = new DefaultFileSystem(baseDir); + fs = new DefaultFileSystem(baseDir.toPath()); sonarIndex = mock(SonarIndex.class); project = new Project("myProject"); + initializer = mock(ModuleFileSystemInitializer.class); + when(initializer.baseDir()).thenReturn(baseDir); + when(initializer.workingDir()).thenReturn(temp.newFolder()); cobolLanguage = new AbstractLanguage("cobol") { @Override public String[] getFileSuffixes() { @@ -69,15 +74,17 @@ public class ComponentIndexerTest { @Test public void should_index_java_files() throws IOException { + Languages languages = new Languages(Java.INSTANCE); + ComponentIndexer indexer = createIndexer(languages); + DefaultModuleFileSystem fs = new DefaultModuleFileSystem(project, null, mock(FileIndexer.class), initializer, indexer); fs.add(newInputFile("src/main/java/foo/bar/Foo.java", "", "foo/bar/Foo.java", "java", false)); fs.add(newInputFile("src/main/java2/foo/bar/Foo.java", "", "foo/bar/Foo.java", "java", false)); fs.add(newInputFile("src/test/java/foo/bar/FooTest.java", "", "foo/bar/FooTest.java", "java", true)); - Languages languages = new Languages(Java.INSTANCE); - ComponentIndexer indexer = createIndexer(languages); - indexer.execute(fs); - verify(sonarIndex).index(org.sonar.api.resources.File.create("src/main/java/foo/bar/Foo.java", "foo/bar/Foo.java", Java.INSTANCE, false)); - verify(sonarIndex).index(org.sonar.api.resources.File.create("src/main/java2/foo/bar/Foo.java", "foo/bar/Foo.java", Java.INSTANCE, false)); + fs.index(); + + verify(sonarIndex).index(org.sonar.api.resources.File.create("src/main/java/foo/bar/Foo.java", Java.INSTANCE, false)); + verify(sonarIndex).index(org.sonar.api.resources.File.create("src/main/java2/foo/bar/Foo.java", Java.INSTANCE, false)); verify(sonarIndex).index(argThat(new ArgumentMatcher<org.sonar.api.resources.File>() { @Override public boolean matches(Object arg0) { @@ -95,25 +102,24 @@ public class ComponentIndexerTest { @Test public void should_index_cobol_files() throws IOException { + Languages languages = new Languages(cobolLanguage); + ComponentIndexer indexer = createIndexer(languages); + DefaultModuleFileSystem fs = new DefaultModuleFileSystem(project, null, mock(FileIndexer.class), initializer, indexer); fs.add(newInputFile("src/foo/bar/Foo.cbl", "", "foo/bar/Foo.cbl", "cobol", false)); fs.add(newInputFile("src2/foo/bar/Foo.cbl", "", "foo/bar/Foo.cbl", "cobol", false)); fs.add(newInputFile("src/test/foo/bar/FooTest.cbl", "", "foo/bar/FooTest.cbl", "cobol", true)); - Languages languages = new Languages(cobolLanguage); - ComponentIndexer indexer = createIndexer(languages); - indexer.execute(fs); + fs.index(); - verify(sonarIndex).index(org.sonar.api.resources.File.create("/src/foo/bar/Foo.cbl", "foo/bar/Foo.cbl", cobolLanguage, false)); - verify(sonarIndex).index(org.sonar.api.resources.File.create("/src2/foo/bar/Foo.cbl", "foo/bar/Foo.cbl", cobolLanguage, false)); - verify(sonarIndex).index(org.sonar.api.resources.File.create("/src/test/foo/bar/FooTest.cbl", "foo/bar/FooTest.cbl", cobolLanguage, true)); + verify(sonarIndex).index(org.sonar.api.resources.File.create("/src/foo/bar/Foo.cbl", cobolLanguage, false)); + verify(sonarIndex).index(org.sonar.api.resources.File.create("/src2/foo/bar/Foo.cbl", cobolLanguage, false)); + verify(sonarIndex).index(org.sonar.api.resources.File.create("/src/test/foo/bar/FooTest.cbl", cobolLanguage, true)); } private DefaultInputFile newInputFile(String path, String content, String sourceRelativePath, String languageKey, boolean unitTest) throws IOException { File file = new File(baseDir, path); FileUtils.write(file, content); return new DeprecatedDefaultInputFile("foo", path) - .setPathRelativeToSourceDir(sourceRelativePath) - .setFile(file) .setLanguage(languageKey) .setType(unitTest ? InputFile.Type.TEST : InputFile.Type.MAIN); } diff --git a/sonar-batch/src/test/java/org/sonar/batch/scan/filesystem/DefaultModuleFileSystemTest.java b/sonar-batch/src/test/java/org/sonar/batch/scan/filesystem/DefaultModuleFileSystemTest.java index 12be0438530..7f954c405a2 100644 --- a/sonar-batch/src/test/java/org/sonar/batch/scan/filesystem/DefaultModuleFileSystemTest.java +++ b/sonar-batch/src/test/java/org/sonar/batch/scan/filesystem/DefaultModuleFileSystemTest.java @@ -135,9 +135,9 @@ public class DefaultModuleFileSystemTest { DefaultModuleFileSystem fs = new DefaultModuleFileSystem(moduleInputFileCache, new Project("foo"), settings, fileIndexer, initializer, componentIndexer); - File mainFile = temp.newFile(); - InputFile mainInput = new DeprecatedDefaultInputFile("foo", "Main.java").setFile(mainFile).setType(InputFile.Type.MAIN); - InputFile testInput = new DeprecatedDefaultInputFile("foo", "Test.java").setFile(temp.newFile()).setType(InputFile.Type.TEST); + File baseDir = temp.newFile(); + InputFile mainInput = new DeprecatedDefaultInputFile("foo", "Main.java").setModuleBaseDir(baseDir.toPath()).setType(InputFile.Type.MAIN); + InputFile testInput = new DeprecatedDefaultInputFile("foo", "Test.java").setModuleBaseDir(baseDir.toPath()).setType(InputFile.Type.TEST); when(moduleInputFileCache.inputFiles()).thenReturn(Lists.newArrayList(mainInput, testInput)); fs.index(); @@ -145,7 +145,7 @@ public class DefaultModuleFileSystemTest { assertThat(inputFiles).containsOnly(mainInput); Iterable<File> files = fs.files(fs.predicates().hasType(InputFile.Type.MAIN)); - assertThat(files).containsOnly(mainFile); + assertThat(files).containsOnly(new File(baseDir, "Main.java")); } @Test diff --git a/sonar-batch/src/test/java/org/sonar/batch/scan/filesystem/DeprecatedFileFiltersTest.java b/sonar-batch/src/test/java/org/sonar/batch/scan/filesystem/DeprecatedFileFiltersTest.java index 4066080360b..3235301f031 100644 --- a/sonar-batch/src/test/java/org/sonar/batch/scan/filesystem/DeprecatedFileFiltersTest.java +++ b/sonar-batch/src/test/java/org/sonar/batch/scan/filesystem/DeprecatedFileFiltersTest.java @@ -49,7 +49,7 @@ public class DeprecatedFileFiltersTest { public void no_filters() throws Exception { DeprecatedFileFilters filters = new DeprecatedFileFilters(); - InputFile inputFile = new DeprecatedDefaultInputFile("foo", "src/main/java/Foo.java").setFile(temp.newFile()); + InputFile inputFile = new DeprecatedDefaultInputFile("foo", "src/main/java/Foo.java"); assertThat(filters.accept(inputFile)).isTrue(); } @@ -58,11 +58,9 @@ public class DeprecatedFileFiltersTest { DeprecatedFileFilters filters = new DeprecatedFileFilters(new FileSystemFilter[] {filter}); File basedir = temp.newFolder(); - File file = temp.newFile(); + File file = new File(basedir, "src/main/java/Foo.java"); InputFile inputFile = new DeprecatedDefaultInputFile("foo", "src/main/java/Foo.java") - .setSourceDirAbsolutePath(new File(basedir, "src/main/java").getAbsolutePath()) - .setPathRelativeToSourceDir("Foo.java") - .setFile(file) + .setModuleBaseDir(basedir.toPath()) .setType(InputFile.Type.MAIN); when(filter.accept(eq(file), any(DeprecatedFileFilters.DeprecatedContext.class))).thenReturn(false); @@ -73,8 +71,7 @@ public class DeprecatedFileFiltersTest { DeprecatedFileFilters.DeprecatedContext context = argument.getValue(); assertThat(context.canonicalPath()).isEqualTo(FilenameUtils.separatorsToUnix(file.getAbsolutePath())); - assertThat(context.relativeDir()).isEqualTo(new File(basedir, "src/main/java")); - assertThat(context.relativePath()).isEqualTo("Foo.java"); + assertThat(context.relativePath()).isEqualTo("src/main/java/Foo.java"); assertThat(context.type()).isEqualTo(FileType.MAIN); } } diff --git a/sonar-batch/src/test/java/org/sonar/batch/scan/filesystem/ExclusionFiltersTest.java b/sonar-batch/src/test/java/org/sonar/batch/scan/filesystem/ExclusionFiltersTest.java index 02478075c9c..c5bd36cddf5 100644 --- a/sonar-batch/src/test/java/org/sonar/batch/scan/filesystem/ExclusionFiltersTest.java +++ b/sonar-batch/src/test/java/org/sonar/batch/scan/filesystem/ExclusionFiltersTest.java @@ -28,6 +28,7 @@ import org.sonar.api.batch.fs.internal.DefaultInputFile; import org.sonar.api.config.Settings; import org.sonar.api.scan.filesystem.FileExclusions; +import java.io.File; import java.io.IOException; import static org.assertj.core.api.Assertions.assertThat; @@ -43,7 +44,7 @@ public class ExclusionFiltersTest { filter.prepare(); java.io.File file = temp.newFile(); - DefaultInputFile inputFile = new DefaultInputFile("foo", "src/main/java/com/mycompany/FooDao.java").setFile(file); + DefaultInputFile inputFile = new DefaultInputFile("foo", "src/main/java/com/mycompany/FooDao.java").setModuleBaseDir(temp.newFolder().toPath()); assertThat(filter.accept(inputFile, InputFile.Type.MAIN)).isTrue(); assertThat(filter.accept(inputFile, InputFile.Type.TEST)).isTrue(); } @@ -56,10 +57,10 @@ public class ExclusionFiltersTest { filter.prepare(); java.io.File file = temp.newFile(); - DefaultInputFile inputFile = new DefaultInputFile("foo", "src/main/java/com/mycompany/FooDao.java").setFile(file); + DefaultInputFile inputFile = new DefaultInputFile("foo", "src/main/java/com/mycompany/FooDao.java").setModuleBaseDir(temp.newFolder().toPath()); assertThat(filter.accept(inputFile, InputFile.Type.MAIN)).isTrue(); - inputFile = new DefaultInputFile("foo", "src/main/java/com/mycompany/Foo.java").setFile(file); + inputFile = new DefaultInputFile("foo", "src/main/java/com/mycompany/Foo.java").setModuleBaseDir(temp.newFolder().toPath()); assertThat(filter.accept(inputFile, InputFile.Type.MAIN)).isFalse(); } @@ -73,10 +74,10 @@ public class ExclusionFiltersTest { java.io.File file = temp.newFile(); - DefaultInputFile inputFile = new DefaultInputFile("foo", "src/main/java/com/mycompany/Foo.java").setFile(file); + DefaultInputFile inputFile = new DefaultInputFile("foo", "src/main/java/com/mycompany/Foo.java").setModuleBaseDir(temp.newFolder().toPath()); assertThat(filter.accept(inputFile, InputFile.Type.MAIN)).isFalse(); - inputFile = new DefaultInputFile("foo", "src/main/java/com/mycompany/FooDto.java").setFile(file); + inputFile = new DefaultInputFile("foo", "src/main/java/com/mycompany/FooDto.java").setModuleBaseDir(temp.newFolder().toPath()); assertThat(filter.accept(inputFile, InputFile.Type.MAIN)).isTrue(); } @@ -91,21 +92,21 @@ public class ExclusionFiltersTest { filter.prepare(); java.io.File file = temp.newFile(); - DefaultInputFile inputFile = new DefaultInputFile("foo", "src/main/java/com/mycompany/FooDao.java").setFile(file); + DefaultInputFile inputFile = new DefaultInputFile("foo", "src/main/java/com/mycompany/FooDao.java").setModuleBaseDir(temp.newFolder().toPath()); assertThat(filter.accept(inputFile, InputFile.Type.MAIN)).isFalse(); - inputFile = new DefaultInputFile("foo", "src/main/java/com/mycompany/Foo.java").setFile(file); + inputFile = new DefaultInputFile("foo", "src/main/java/com/mycompany/Foo.java").setModuleBaseDir(temp.newFolder().toPath()); assertThat(filter.accept(inputFile, InputFile.Type.MAIN)).isTrue(); // source exclusions do not apply to tests - inputFile = new DefaultInputFile("foo", "src/test/java/com/mycompany/FooDao.java").setFile(file); + inputFile = new DefaultInputFile("foo", "src/test/java/com/mycompany/FooDao.java").setModuleBaseDir(temp.newFolder().toPath()); assertThat(filter.accept(inputFile, InputFile.Type.TEST)).isTrue(); } @Test public void match_exclusion_by_absolute_path() throws IOException { - java.io.File includedFile = temp.newFile("Foo.java"); - java.io.File excludedFile = temp.newFile("Bar.java"); + File baseDir = temp.newFile(); + File excludedFile = new File(baseDir, "src/main/java/org/bar/Bar.java"); Settings settings = new Settings(); settings.setProperty(CoreProperties.PROJECT_INCLUSIONS_PROPERTY, "src/main/java/**/*"); @@ -114,10 +115,10 @@ public class ExclusionFiltersTest { filter.prepare(); - DefaultInputFile inputFile = new DefaultInputFile("foo", "src/main/java/org/bar/Foo.java").setFile(includedFile); + DefaultInputFile inputFile = new DefaultInputFile("foo", "src/main/java/org/bar/Foo.java").setModuleBaseDir(baseDir.toPath()); assertThat(filter.accept(inputFile, InputFile.Type.MAIN)).isTrue(); - inputFile = new DefaultInputFile("foo", "src/main/java/org/bar/Bar.java").setFile(excludedFile); + inputFile = new DefaultInputFile("foo", "src/main/java/org/bar/Bar.java").setModuleBaseDir(baseDir.toPath()); assertThat(filter.accept(inputFile, InputFile.Type.MAIN)).isFalse(); } diff --git a/sonar-batch/src/test/java/org/sonar/batch/scan/filesystem/FileMetadataTest.java b/sonar-batch/src/test/java/org/sonar/batch/scan/filesystem/FileMetadataTest.java index cbfcb03242b..b34c5d50271 100644 --- a/sonar-batch/src/test/java/org/sonar/batch/scan/filesystem/FileMetadataTest.java +++ b/sonar-batch/src/test/java/org/sonar/batch/scan/filesystem/FileMetadataTest.java @@ -25,12 +25,13 @@ import org.junit.Rule; import org.junit.Test; import org.junit.rules.ExpectedException; import org.junit.rules.TemporaryFolder; +import org.sonar.api.batch.AnalysisMode; import java.io.File; -import static org.apache.commons.codec.digest.DigestUtils.md5; import static org.apache.commons.codec.digest.DigestUtils.md5Hex; import static org.assertj.core.api.Assertions.assertThat; +import static org.mockito.Mockito.mock; public class FileMetadataTest { @@ -40,17 +41,18 @@ public class FileMetadataTest { @Rule public TemporaryFolder temp = new TemporaryFolder(); + private AnalysisMode mode = mock(AnalysisMode.class); + @Test public void empty_file() throws Exception { File tempFile = temp.newFile(); FileUtils.touch(tempFile); - FileMetadata.Metadata metadata = new FileMetadata().read(tempFile, Charsets.UTF_8); + FileMetadata.Metadata metadata = new FileMetadata(mode).read(tempFile, Charsets.UTF_8); assertThat(metadata.lines).isEqualTo(1); assertThat(metadata.nonBlankLines).isEqualTo(0); assertThat(metadata.hash).isNotEmpty(); assertThat(metadata.originalLineOffsets).containsOnly(0); - assertThat(metadata.lineHashes[0]).isNull(); assertThat(metadata.empty).isTrue(); } @@ -59,14 +61,11 @@ public class FileMetadataTest { File tempFile = temp.newFile(); FileUtils.write(tempFile, "foo\r\nbar\r\nbaz", Charsets.UTF_8, true); - FileMetadata.Metadata metadata = new FileMetadata().read(tempFile, Charsets.UTF_8); + FileMetadata.Metadata metadata = new FileMetadata(mode).read(tempFile, Charsets.UTF_8); assertThat(metadata.lines).isEqualTo(3); assertThat(metadata.nonBlankLines).isEqualTo(3); assertThat(metadata.hash).isEqualTo(md5Hex("foo\nbar\nbaz")); assertThat(metadata.originalLineOffsets).containsOnly(0, 5, 10); - assertThat(metadata.lineHashes[0]).containsOnly(md5("foo")); - assertThat(metadata.lineHashes[1]).containsOnly(md5("bar")); - assertThat(metadata.lineHashes[2]).containsOnly(md5("baz")); assertThat(metadata.empty).isFalse(); } @@ -75,15 +74,11 @@ public class FileMetadataTest { File tempFile = temp.newFile(); FileUtils.write(tempFile, "föo\r\nbà r\r\n\u1D11Ebaßz\r\n", Charsets.UTF_8, true); - FileMetadata.Metadata metadata = new FileMetadata().read(tempFile, Charsets.UTF_8); + FileMetadata.Metadata metadata = new FileMetadata(mode).read(tempFile, Charsets.UTF_8); assertThat(metadata.lines).isEqualTo(4); assertThat(metadata.nonBlankLines).isEqualTo(3); assertThat(metadata.hash).isEqualTo(md5Hex("föo\nbà r\n\u1D11Ebaßz\n")); assertThat(metadata.originalLineOffsets).containsOnly(0, 5, 10, 18); - assertThat(metadata.lineHashes[0]).containsExactly(md5("föo")); - assertThat(metadata.lineHashes[1]).containsExactly(md5("bà r")); - assertThat(metadata.lineHashes[2]).containsExactly(md5("\u1D11Ebaßz")); - assertThat(metadata.lineHashes[3]).isNull(); } @Test @@ -91,15 +86,11 @@ public class FileMetadataTest { File tempFile = temp.newFile(); FileUtils.write(tempFile, "föo\r\nbà r\r\n\u1D11Ebaßz\r\n", Charsets.UTF_16, true); - FileMetadata.Metadata metadata = new FileMetadata().read(tempFile, Charsets.UTF_16); + FileMetadata.Metadata metadata = new FileMetadata(mode).read(tempFile, Charsets.UTF_16); assertThat(metadata.lines).isEqualTo(4); assertThat(metadata.nonBlankLines).isEqualTo(3); assertThat(metadata.hash).isEqualTo(md5Hex("föo\nbà r\n\u1D11Ebaßz\n")); assertThat(metadata.originalLineOffsets).containsOnly(0, 5, 10, 18); - assertThat(metadata.lineHashes[0]).containsExactly(md5("föo")); - assertThat(metadata.lineHashes[1]).containsExactly(md5("bà r")); - assertThat(metadata.lineHashes[2]).containsExactly(md5("\u1D11Ebaßz")); - assertThat(metadata.lineHashes[3]).isNull(); } @Test @@ -107,14 +98,11 @@ public class FileMetadataTest { File tempFile = temp.newFile(); FileUtils.write(tempFile, "foo\nbar\nbaz", Charsets.UTF_8, true); - FileMetadata.Metadata metadata = new FileMetadata().read(tempFile, Charsets.UTF_8); + FileMetadata.Metadata metadata = new FileMetadata(mode).read(tempFile, Charsets.UTF_8); assertThat(metadata.lines).isEqualTo(3); assertThat(metadata.nonBlankLines).isEqualTo(3); assertThat(metadata.hash).isEqualTo(md5Hex("foo\nbar\nbaz")); assertThat(metadata.originalLineOffsets).containsOnly(0, 4, 8); - assertThat(metadata.lineHashes[0]).containsOnly(md5("foo")); - assertThat(metadata.lineHashes[1]).containsOnly(md5("bar")); - assertThat(metadata.lineHashes[2]).containsOnly(md5("baz")); } @Test @@ -122,15 +110,11 @@ public class FileMetadataTest { File tempFile = temp.newFile(); FileUtils.write(tempFile, "foo\nbar\nbaz\n", Charsets.UTF_8, true); - FileMetadata.Metadata metadata = new FileMetadata().read(tempFile, Charsets.UTF_8); + FileMetadata.Metadata metadata = new FileMetadata(mode).read(tempFile, Charsets.UTF_8); assertThat(metadata.lines).isEqualTo(4); assertThat(metadata.nonBlankLines).isEqualTo(3); assertThat(metadata.hash).isEqualTo(md5Hex("foo\nbar\nbaz\n")); assertThat(metadata.originalLineOffsets).containsOnly(0, 4, 8, 12); - assertThat(metadata.lineHashes[0]).containsOnly(md5("foo")); - assertThat(metadata.lineHashes[1]).containsOnly(md5("bar")); - assertThat(metadata.lineHashes[2]).containsOnly(md5("baz")); - assertThat(metadata.lineHashes[3]).isNull(); } @Test @@ -138,15 +122,11 @@ public class FileMetadataTest { File tempFile = temp.newFile(); FileUtils.write(tempFile, "foo\nbar\r\nbaz\n", Charsets.UTF_8, true); - FileMetadata.Metadata metadata = new FileMetadata().read(tempFile, Charsets.UTF_8); + FileMetadata.Metadata metadata = new FileMetadata(mode).read(tempFile, Charsets.UTF_8); assertThat(metadata.lines).isEqualTo(4); assertThat(metadata.nonBlankLines).isEqualTo(3); assertThat(metadata.hash).isEqualTo(md5Hex("foo\nbar\nbaz\n")); assertThat(metadata.originalLineOffsets).containsOnly(0, 4, 9, 13); - assertThat(metadata.lineHashes[0]).containsOnly(md5("foo")); - assertThat(metadata.lineHashes[1]).containsOnly(md5("bar")); - assertThat(metadata.lineHashes[2]).containsOnly(md5("baz")); - assertThat(metadata.lineHashes[3]).isNull(); } @Test @@ -154,15 +134,11 @@ public class FileMetadataTest { File tempFile = temp.newFile(); FileUtils.write(tempFile, "foo\n\n\nbar", Charsets.UTF_8, true); - FileMetadata.Metadata metadata = new FileMetadata().read(tempFile, Charsets.UTF_8); + FileMetadata.Metadata metadata = new FileMetadata(mode).read(tempFile, Charsets.UTF_8); assertThat(metadata.lines).isEqualTo(4); assertThat(metadata.nonBlankLines).isEqualTo(2); assertThat(metadata.hash).isEqualTo(md5Hex("foo\n\n\nbar")); assertThat(metadata.originalLineOffsets).containsOnly(0, 4, 5, 6); - assertThat(metadata.lineHashes[0]).containsOnly(md5("foo")); - assertThat(metadata.lineHashes[1]).isNull(); - assertThat(metadata.lineHashes[2]).isNull(); - assertThat(metadata.lineHashes[3]).containsOnly(md5("bar")); } @Test @@ -170,14 +146,11 @@ public class FileMetadataTest { File tempFile = temp.newFile(); FileUtils.write(tempFile, "foo\nbar\r\nbaz", Charsets.UTF_8, true); - FileMetadata.Metadata metadata = new FileMetadata().read(tempFile, Charsets.UTF_8); + FileMetadata.Metadata metadata = new FileMetadata(mode).read(tempFile, Charsets.UTF_8); assertThat(metadata.lines).isEqualTo(3); assertThat(metadata.nonBlankLines).isEqualTo(3); assertThat(metadata.hash).isEqualTo(md5Hex("foo\nbar\nbaz")); assertThat(metadata.originalLineOffsets).containsOnly(0, 4, 9); - assertThat(metadata.lineHashes[0]).containsOnly(md5("foo")); - assertThat(metadata.lineHashes[1]).containsOnly(md5("bar")); - assertThat(metadata.lineHashes[2]).containsOnly(md5("baz")); } @Test @@ -185,15 +158,11 @@ public class FileMetadataTest { File tempFile = temp.newFile(); FileUtils.write(tempFile, "\nfoo\nbar\r\nbaz", Charsets.UTF_8, true); - FileMetadata.Metadata metadata = new FileMetadata().read(tempFile, Charsets.UTF_8); + FileMetadata.Metadata metadata = new FileMetadata(mode).read(tempFile, Charsets.UTF_8); assertThat(metadata.lines).isEqualTo(4); assertThat(metadata.nonBlankLines).isEqualTo(3); assertThat(metadata.hash).isEqualTo(md5Hex("\nfoo\nbar\nbaz")); assertThat(metadata.originalLineOffsets).containsOnly(0, 1, 5, 10); - assertThat(metadata.lineHashes[0]).isNull(); - assertThat(metadata.lineHashes[1]).containsOnly(md5("foo")); - assertThat(metadata.lineHashes[2]).containsOnly(md5("bar")); - assertThat(metadata.lineHashes[3]).containsOnly(md5("baz")); } @Test @@ -201,14 +170,11 @@ public class FileMetadataTest { File tempFile = temp.newFile(); FileUtils.write(tempFile, "\uFEFFfoo\nbar\r\nbaz", Charsets.UTF_8, true); - FileMetadata.Metadata metadata = new FileMetadata().read(tempFile, Charsets.UTF_8); + FileMetadata.Metadata metadata = new FileMetadata(mode).read(tempFile, Charsets.UTF_8); assertThat(metadata.lines).isEqualTo(3); assertThat(metadata.nonBlankLines).isEqualTo(3); assertThat(metadata.hash).isEqualTo(md5Hex("foo\nbar\nbaz")); assertThat(metadata.originalLineOffsets).containsOnly(0, 4, 9); - assertThat(metadata.lineHashes[0]).containsOnly(md5("foo")); - assertThat(metadata.lineHashes[1]).containsOnly(md5("bar")); - assertThat(metadata.lineHashes[2]).containsOnly(md5("baz")); } @Test @@ -216,13 +182,10 @@ public class FileMetadataTest { File tempFile = temp.newFile(); FileUtils.write(tempFile, " foo\nb ar\r\nbaz \t", Charsets.UTF_8, true); - FileMetadata.Metadata metadata = new FileMetadata().read(tempFile, Charsets.UTF_8); + FileMetadata.Metadata metadata = new FileMetadata(mode).read(tempFile, Charsets.UTF_8); assertThat(metadata.lines).isEqualTo(3); assertThat(metadata.nonBlankLines).isEqualTo(3); assertThat(metadata.hash).isEqualTo(md5Hex(" foo\nb ar\nbaz \t")); - assertThat(metadata.lineHashes[0]).containsOnly(md5("foo")); - assertThat(metadata.lineHashes[1]).containsOnly(md5("bar")); - assertThat(metadata.lineHashes[2]).containsOnly(md5("baz")); } @Test @@ -233,7 +196,7 @@ public class FileMetadataTest { thrown.expect(IllegalStateException.class); thrown.expectMessage("Fail to read file '" + file.getAbsolutePath() + "' with encoding 'UTF-8'"); - new FileMetadata().read(file, Charsets.UTF_8); + new FileMetadata(mode).read(file, Charsets.UTF_8); } @Test @@ -248,9 +211,9 @@ public class FileMetadataTest { File file2 = temp.newFile(); FileUtils.write(file2, "foo\nbar", Charsets.UTF_8, true); - String hash1 = new FileMetadata().read(file1, Charsets.UTF_8).hash; - String hash1a = new FileMetadata().read(file1a, Charsets.UTF_8).hash; - String hash2 = new FileMetadata().read(file2, Charsets.UTF_8).hash; + String hash1 = new FileMetadata(mode).read(file1, Charsets.UTF_8).hash; + String hash1a = new FileMetadata(mode).read(file1a, Charsets.UTF_8).hash; + String hash2 = new FileMetadata(mode).read(file2, Charsets.UTF_8).hash; assertThat(hash1).isEqualTo(hash1a); assertThat(hash1).isNotEqualTo(hash2); } diff --git a/sonar-batch/src/test/java/org/sonar/batch/scan/filesystem/InputFileBuilderFactoryTest.java b/sonar-batch/src/test/java/org/sonar/batch/scan/filesystem/InputFileBuilderFactoryTest.java index e702dbbfa81..2b5b1f4bcca 100644 --- a/sonar-batch/src/test/java/org/sonar/batch/scan/filesystem/InputFileBuilderFactoryTest.java +++ b/sonar-batch/src/test/java/org/sonar/batch/scan/filesystem/InputFileBuilderFactoryTest.java @@ -39,7 +39,7 @@ public class InputFileBuilderFactoryTest { DefaultAnalysisMode analysisMode = mock(DefaultAnalysisMode.class); InputFileBuilderFactory factory = new InputFileBuilderFactory(ProjectDefinition.create().setKey("struts"), pathResolver, langDetectionFactory, - statusDetectionFactory, analysisMode, new Settings()); + statusDetectionFactory, analysisMode, new Settings(), new FileMetadata(analysisMode)); InputFileBuilder builder = factory.create(fs); assertThat(builder.langDetection()).isNotNull(); diff --git a/sonar-batch/src/test/java/org/sonar/batch/scan/filesystem/InputFileBuilderTest.java b/sonar-batch/src/test/java/org/sonar/batch/scan/filesystem/InputFileBuilderTest.java index 36682184b37..df058f13c8f 100644 --- a/sonar-batch/src/test/java/org/sonar/batch/scan/filesystem/InputFileBuilderTest.java +++ b/sonar-batch/src/test/java/org/sonar/batch/scan/filesystem/InputFileBuilderTest.java @@ -32,7 +32,6 @@ import org.sonar.api.utils.PathUtils; import org.sonar.batch.bootstrap.DefaultAnalysisMode; import java.io.File; -import java.util.Arrays; import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.Matchers.any; @@ -67,9 +66,9 @@ public class InputFileBuilderTest { .thenReturn(InputFile.Status.ADDED); InputFileBuilder builder = new InputFileBuilder("struts", new PathResolver(), - langDetection, statusDetection, fs, analysisMode, new Settings()); + langDetection, statusDetection, fs, analysisMode, new Settings(), new FileMetadata(analysisMode)); DeprecatedDefaultInputFile inputFile = builder.create(srcFile); - inputFile = builder.complete(inputFile, InputFile.Type.MAIN); + builder.completeAndComputeMetadata(inputFile, InputFile.Type.MAIN); assertThat(inputFile.type()).isEqualTo(InputFile.Type.MAIN); assertThat(inputFile.file()).isEqualTo(srcFile.getAbsoluteFile()); @@ -78,9 +77,6 @@ public class InputFileBuilderTest { assertThat(inputFile.key()).isEqualTo("struts:src/main/java/foo/Bar.java"); assertThat(inputFile.relativePath()).isEqualTo("src/main/java/foo/Bar.java"); assertThat(inputFile.lines()).isEqualTo(1); - assertThat(inputFile.sourceDirAbsolutePath()).isNull(); - assertThat(inputFile.pathRelativeToSourceDir()).isNull(); - assertThat(inputFile.deprecatedKey()).isNull(); } @Test @@ -93,7 +89,7 @@ public class InputFileBuilderTest { when(fs.baseDir()).thenReturn(basedir); InputFileBuilder builder = new InputFileBuilder("struts", new PathResolver(), - langDetection, statusDetection, fs, analysisMode, new Settings()); + langDetection, statusDetection, fs, analysisMode, new Settings(), new FileMetadata(analysisMode)); DeprecatedDefaultInputFile inputFile = builder.create(srcFile); assertThat(inputFile).isNull(); @@ -113,69 +109,11 @@ public class InputFileBuilderTest { when(langDetection.language(any(InputFile.class))).thenReturn(null); InputFileBuilder builder = new InputFileBuilder("struts", new PathResolver(), - langDetection, statusDetection, fs, analysisMode, new Settings()); + langDetection, statusDetection, fs, analysisMode, new Settings(), new FileMetadata(analysisMode)); DeprecatedDefaultInputFile inputFile = builder.create(srcFile); - inputFile = builder.complete(inputFile, InputFile.Type.MAIN); + InputFileMetadata metadata = builder.completeAndComputeMetadata(inputFile, InputFile.Type.MAIN); - assertThat(inputFile).isNull(); - } - - @Test - public void fill_deprecated_data_of_java_file() throws Exception { - // file system - File basedir = temp.newFolder(); - File srcFile = new File(basedir, "src/main/java/foo/Bar.java"); - FileUtils.touch(srcFile); - FileUtils.write(srcFile, "single line"); - when(fs.baseDir()).thenReturn(basedir); - when(fs.encoding()).thenReturn(Charsets.UTF_8); - File sourceDir = new File(basedir, "src/main/java"); - when(fs.sourceDirs()).thenReturn(Arrays.asList(sourceDir)); - - // lang - when(langDetection.language(any(InputFile.class))).thenReturn("java"); - - // status - when(statusDetection.status("foo", "src/main/java/foo/Bar.java", "6c1d64c0b3555892fe7273e954f6fb5a")) - .thenReturn(InputFile.Status.ADDED); - - InputFileBuilder builder = new InputFileBuilder("struts", new PathResolver(), - langDetection, statusDetection, fs, analysisMode, new Settings()); - DeprecatedDefaultInputFile inputFile = builder.create(srcFile); - inputFile = builder.complete(inputFile, InputFile.Type.MAIN); - - assertThat(inputFile.pathRelativeToSourceDir()).isEqualTo("foo/Bar.java"); - assertThat(inputFile.sourceDirAbsolutePath()).isEqualTo(PathUtils.sanitize(sourceDir.getAbsolutePath())); - assertThat(inputFile.deprecatedKey()).isEqualTo("struts:foo.Bar"); + assertThat(metadata).isNull(); } - @Test - public void fill_deprecated_data_of_non_java_file() throws Exception { - // file system - File basedir = temp.newFolder(); - File srcFile = new File(basedir, "src/foo/Bar.php"); - FileUtils.touch(srcFile); - FileUtils.write(srcFile, "single line"); - when(fs.baseDir()).thenReturn(basedir); - when(fs.encoding()).thenReturn(Charsets.UTF_8); - File sourceDir = new File(basedir, "src"); - when(fs.sourceDirs()).thenReturn(Arrays.asList(sourceDir)); - - // lang - when(langDetection.language(any(InputFile.class))).thenReturn("php"); - - // status - when(statusDetection.status("foo", "src/Bar.php", "6c1d64c0b3555892fe7273e954f6fb5a")) - .thenReturn(InputFile.Status.ADDED); - - InputFileBuilder builder = new InputFileBuilder("struts", new PathResolver(), - langDetection, statusDetection, fs, analysisMode, new Settings()); - DeprecatedDefaultInputFile inputFile = builder.create(srcFile); - inputFile = builder.complete(inputFile, InputFile.Type.MAIN); - - assertThat(inputFile.pathRelativeToSourceDir()).isEqualTo("foo/Bar.php"); - assertThat(inputFile.sourceDirAbsolutePath()).isEqualTo(PathUtils.sanitize(sourceDir.getAbsolutePath())); - assertThat(inputFile.deprecatedKey()).isEqualTo("struts:foo/Bar.php"); - - } } diff --git a/sonar-batch/src/test/java/org/sonar/batch/scan/filesystem/InputPathCacheTest.java b/sonar-batch/src/test/java/org/sonar/batch/scan/filesystem/InputPathCacheTest.java index 1a38d6e998c..7c943e06f66 100644 --- a/sonar-batch/src/test/java/org/sonar/batch/scan/filesystem/InputPathCacheTest.java +++ b/sonar-batch/src/test/java/org/sonar/batch/scan/filesystem/InputPathCacheTest.java @@ -19,7 +19,7 @@ */ package org.sonar.batch.scan.filesystem; -import org.apache.commons.codec.digest.DigestUtils; +import com.google.common.base.Charsets; import org.junit.After; import org.junit.Before; import org.junit.Rule; @@ -30,8 +30,6 @@ import org.sonar.api.batch.fs.InputFile.Type; import org.sonar.api.batch.fs.InputPath; import org.sonar.api.batch.fs.internal.DefaultInputFile; import org.sonar.api.batch.fs.internal.DeprecatedDefaultInputFile; -import org.sonar.batch.index.Caches; -import org.sonar.batch.index.CachesTest; import static org.assertj.core.api.Assertions.assertThat; @@ -40,59 +38,61 @@ public class InputPathCacheTest { @Rule public TemporaryFolder temp = new TemporaryFolder(); - Caches caches; - @Before public void start() throws Exception { - caches = CachesTest.createCacheOnTemp(temp); - caches.start(); } @After public void stop() { - caches.stop(); } @Test public void should_add_input_file() throws Exception { - InputPathCache cache = new InputPathCache(caches); - DefaultInputFile fooFile = new DefaultInputFile("foo", "src/main/java/Foo.java").setFile(temp.newFile("Foo.java")); + InputPathCache cache = new InputPathCache(); + DefaultInputFile fooFile = new DefaultInputFile("foo", "src/main/java/Foo.java").setModuleBaseDir(temp.newFolder().toPath()); cache.put("struts", fooFile); cache.put("struts-core", new DeprecatedDefaultInputFile("foo", "src/main/java/Bar.java") - .setBasedir(temp.newFolder()) - .setDeprecatedKey("foo") - .setSourceDirAbsolutePath("foo") - .setPathRelativeToSourceDir("foo") .setLanguage("bla") .setType(Type.MAIN) .setStatus(Status.ADDED) - .setHash("xyz") .setLines(2) - .setEncoding("UTF-8") - .setOriginalLineOffsets(new long[] {0, 4}) - .setLineHashes(new byte[][] {DigestUtils.md5("foo"), DigestUtils.md5("bar")}) - .setFile(temp.newFile("Bar.java"))); + .setCharset(Charsets.UTF_8) + .setModuleBaseDir(temp.newFolder().toPath())); DefaultInputFile loadedFile = (DefaultInputFile) cache.getFile("struts-core", "src/main/java/Bar.java"); assertThat(loadedFile.relativePath()).isEqualTo("src/main/java/Bar.java"); - assertThat(loadedFile.encoding()).isEqualTo("UTF-8"); - assertThat(loadedFile.originalLineOffsets()).containsOnly(0, 4); - assertThat(loadedFile.lineHashes()[0]).containsOnly(DigestUtils.md5("foo")); - assertThat(loadedFile.lineHashes()[1]).containsOnly(DigestUtils.md5("bar")); + assertThat(loadedFile.charset()).isEqualTo(Charsets.UTF_8); assertThat(cache.filesByModule("struts")).hasSize(1); assertThat(cache.filesByModule("struts-core")).hasSize(1); - assertThat(cache.all()).hasSize(2); - for (InputPath inputPath : cache.all()) { + assertThat(cache.allFiles()).hasSize(2); + for (InputPath inputPath : cache.allFiles()) { assertThat(inputPath.relativePath()).startsWith("src/main/java/"); } cache.remove("struts", fooFile); - assertThat(cache.all()).hasSize(1); + assertThat(cache.allFiles()).hasSize(1); cache.removeModule("struts"); assertThat(cache.filesByModule("struts")).hasSize(0); assertThat(cache.filesByModule("struts-core")).hasSize(1); - assertThat(cache.all()).hasSize(1); + assertThat(cache.allFiles()).hasSize(1); + } + + @Test + public void should_add_input_file_metadata() throws Exception { + InputPathCache cache = new InputPathCache(); + cache.put("struts-core", "src/main/java/Bar.java", new InputFileMetadata() + .setHash("xyz") + .setNonBlankLines(2) + .setEmpty(true) + .setOriginalLineOffsets(new int[] {0, 4})); + + InputFileMetadata loadedFileMetadata = cache.getFileMetadata("struts-core", "src/main/java/Bar.java"); + assertThat(loadedFileMetadata.originalLineOffsets()).containsOnly(0, 4); + assertThat(loadedFileMetadata.hash()).isEqualTo("xyz"); + assertThat(loadedFileMetadata.nonBlankLines()).isEqualTo(2); + assertThat(loadedFileMetadata.isEmpty()).isTrue(); + } } diff --git a/sonar-batch/src/test/java/org/sonar/batch/scan/filesystem/LanguageDetectionFactoryTest.java b/sonar-batch/src/test/java/org/sonar/batch/scan/filesystem/LanguageDetectionFactoryTest.java index af30dcfc706..93b4d05145a 100644 --- a/sonar-batch/src/test/java/org/sonar/batch/scan/filesystem/LanguageDetectionFactoryTest.java +++ b/sonar-batch/src/test/java/org/sonar/batch/scan/filesystem/LanguageDetectionFactoryTest.java @@ -19,19 +19,19 @@ */ package org.sonar.batch.scan.filesystem; +import org.sonar.batch.repository.language.DefaultLanguagesRepository; +import org.sonar.batch.repository.language.LanguagesRepository; + import org.junit.Test; import org.sonar.api.config.Settings; import org.sonar.api.resources.Java; import org.sonar.api.resources.Languages; -import org.sonar.batch.languages.DefaultLanguagesReferential; -import org.sonar.batch.languages.LanguagesReferential; - import static org.assertj.core.api.Assertions.assertThat; public class LanguageDetectionFactoryTest { @Test public void testCreate() throws Exception { - LanguagesReferential languages = new DefaultLanguagesReferential(new Languages(Java.INSTANCE)); + LanguagesRepository languages = new DefaultLanguagesRepository(new Languages(Java.INSTANCE)); LanguageDetectionFactory factory = new LanguageDetectionFactory(new Settings(), languages); LanguageDetection languageDetection = factory.create(); assertThat(languageDetection).isNotNull(); diff --git a/sonar-batch/src/test/java/org/sonar/batch/scan/filesystem/LanguageDetectionTest.java b/sonar-batch/src/test/java/org/sonar/batch/scan/filesystem/LanguageDetectionTest.java index e9155fd9c8a..95d3631eaa5 100644 --- a/sonar-batch/src/test/java/org/sonar/batch/scan/filesystem/LanguageDetectionTest.java +++ b/sonar-batch/src/test/java/org/sonar/batch/scan/filesystem/LanguageDetectionTest.java @@ -30,8 +30,8 @@ import org.sonar.api.config.Settings; import org.sonar.api.resources.Language; import org.sonar.api.resources.Languages; import org.sonar.api.utils.MessageException; -import org.sonar.batch.languages.DefaultLanguagesReferential; -import org.sonar.batch.languages.LanguagesReferential; +import org.sonar.batch.repository.language.DefaultLanguagesRepository; +import org.sonar.batch.repository.language.LanguagesRepository; import java.io.File; import java.io.IOException; @@ -58,7 +58,7 @@ public class LanguageDetectionTest { @Test public void search_by_file_extension() throws Exception { - LanguagesReferential languages = new DefaultLanguagesReferential(new Languages(new MockLanguage("java", "java", "jav"), new MockLanguage("cobol", "cbl", "cob"))); + LanguagesRepository languages = new DefaultLanguagesRepository(new Languages(new MockLanguage("java", "java", "jav"), new MockLanguage("cobol", "cbl", "cob"))); LanguageDetection detection = new LanguageDetection(new Settings(), languages); assertThat(detection.language(newInputFile("Foo.java"))).isEqualTo("java"); @@ -76,13 +76,13 @@ public class LanguageDetectionTest { @Test public void should_not_fail_if_no_language() throws Exception { - LanguageDetection detection = spy(new LanguageDetection(new Settings(), new DefaultLanguagesReferential(new Languages()))); + LanguageDetection detection = spy(new LanguageDetection(new Settings(), new DefaultLanguagesRepository(new Languages()))); assertThat(detection.language(newInputFile("Foo.java"))).isNull(); } @Test public void plugin_can_declare_a_file_extension_twice_for_case_sensitivity() throws Exception { - LanguagesReferential languages = new DefaultLanguagesReferential(new Languages(new MockLanguage("abap", "abap", "ABAP"))); + LanguagesRepository languages = new DefaultLanguagesRepository(new Languages(new MockLanguage("abap", "abap", "ABAP"))); LanguageDetection detection = new LanguageDetection(new Settings(), languages); assertThat(detection.language(newInputFile("abc.abap"))).isEqualTo("abap"); @@ -92,7 +92,7 @@ public class LanguageDetectionTest { public void language_with_no_extension() throws Exception { // abap does not declare any file extensions. // When analyzing an ABAP project, then all source files must be parsed. - LanguagesReferential languages = new DefaultLanguagesReferential(new Languages(new MockLanguage("java", "java"), new MockLanguage("abap"))); + LanguagesRepository languages = new DefaultLanguagesRepository(new Languages(new MockLanguage("java", "java"), new MockLanguage("abap"))); // No side-effect on non-ABAP projects LanguageDetection detection = new LanguageDetection(new Settings(), languages); @@ -110,7 +110,7 @@ public class LanguageDetectionTest { @Test public void force_language_using_deprecated_property() throws Exception { - LanguagesReferential languages = new DefaultLanguagesReferential(new Languages(new MockLanguage("java", "java"), new MockLanguage("php", "php"))); + LanguagesRepository languages = new DefaultLanguagesRepository(new Languages(new MockLanguage("java", "java"), new MockLanguage("php", "php"))); Settings settings = new Settings(); settings.setProperty(CoreProperties.PROJECT_LANGUAGE_PROPERTY, "java"); @@ -126,7 +126,7 @@ public class LanguageDetectionTest { thrown.expect(MessageException.class); thrown.expectMessage("No language is installed with key 'unknown'. Please update property 'sonar.language'"); - LanguagesReferential languages = new DefaultLanguagesReferential(new Languages(new MockLanguage("java", "java"), new MockLanguage("php", "php"))); + LanguagesRepository languages = new DefaultLanguagesRepository(new Languages(new MockLanguage("java", "java"), new MockLanguage("php", "php"))); Settings settings = new Settings(); settings.setProperty(CoreProperties.PROJECT_LANGUAGE_PROPERTY, "unknown"); new LanguageDetection(settings, languages); @@ -134,7 +134,7 @@ public class LanguageDetectionTest { @Test public void fail_if_conflicting_language_suffix() throws Exception { - LanguagesReferential languages = new DefaultLanguagesReferential(new Languages(new MockLanguage("xml", "xhtml"), new MockLanguage("web", "xhtml"))); + LanguagesRepository languages = new DefaultLanguagesRepository(new Languages(new MockLanguage("xml", "xhtml"), new MockLanguage("web", "xhtml"))); LanguageDetection detection = new LanguageDetection(new Settings(), languages); try { detection.language(newInputFile("abc.xhtml")); @@ -149,7 +149,7 @@ public class LanguageDetectionTest { @Test public void solve_conflict_using_filepattern() throws Exception { - LanguagesReferential languages = new DefaultLanguagesReferential(new Languages(new MockLanguage("xml", "xhtml"), new MockLanguage("web", "xhtml"))); + LanguagesRepository languages = new DefaultLanguagesRepository(new Languages(new MockLanguage("xml", "xhtml"), new MockLanguage("web", "xhtml"))); Settings settings = new Settings(); settings.setProperty("sonar.lang.patterns.xml", "xml/**"); @@ -161,7 +161,7 @@ public class LanguageDetectionTest { @Test public void fail_if_conflicting_filepattern() throws Exception { - LanguagesReferential languages = new DefaultLanguagesReferential(new Languages(new MockLanguage("abap", "abap"), new MockLanguage("cobol", "cobol"))); + LanguagesRepository languages = new DefaultLanguagesRepository(new Languages(new MockLanguage("abap", "abap"), new MockLanguage("cobol", "cobol"))); Settings settings = new Settings(); settings.setProperty("sonar.lang.patterns.abap", "*.abap,*.txt"); settings.setProperty("sonar.lang.patterns.cobol", "*.cobol,*.txt"); @@ -183,7 +183,7 @@ public class LanguageDetectionTest { private InputFile newInputFile(String path) throws IOException { File basedir = temp.newFolder(); - return new DefaultInputFile("foo", path).setFile(new File(basedir, path)); + return new DefaultInputFile("foo", path).setModuleBaseDir(basedir.toPath()); } static class MockLanguage implements Language { diff --git a/sonar-batch/src/test/java/org/sonar/batch/scan/measure/MeasureCacheTest.java b/sonar-batch/src/test/java/org/sonar/batch/scan/measure/MeasureCacheTest.java index ebb97af6492..7aa5c49856d 100644 --- a/sonar-batch/src/test/java/org/sonar/batch/scan/measure/MeasureCacheTest.java +++ b/sonar-batch/src/test/java/org/sonar/batch/scan/measure/MeasureCacheTest.java @@ -233,9 +233,9 @@ public class MeasureCacheTest { @Test public void should_get_measures() throws Exception { Project p = new Project("struts"); - Resource dir = new Directory("foo/bar").setEffectiveKey("struts:foo/bar"); - Resource file1 = new File("foo/bar/File1.txt").setEffectiveKey("struts:foo/bar/File1.txt"); - Resource file2 = new File("foo/bar/File2.txt").setEffectiveKey("struts:foo/bar/File2.txt"); + Resource dir = Directory.create("foo/bar").setEffectiveKey("struts:foo/bar"); + Resource file1 = Directory.create("foo/bar/File1.txt").setEffectiveKey("struts:foo/bar/File1.txt"); + Resource file2 = Directory.create("foo/bar/File2.txt").setEffectiveKey("struts:foo/bar/File2.txt"); assertThat(cache.entries()).hasSize(0); @@ -271,7 +271,7 @@ public class MeasureCacheTest { @Test public void test_measure_coder() throws Exception { - Resource file1 = new File("foo/bar/File1.txt").setEffectiveKey("struts:foo/bar/File1.txt"); + Resource file1 = File.create("foo/bar/File1.txt").setEffectiveKey("struts:foo/bar/File1.txt"); Measure measure = new Measure(CoreMetrics.NCLOC, 1.786, 5); cache.put(file1, measure); diff --git a/sonar-batch/src/test/java/org/sonar/batch/scan/report/JSONReportTest.java b/sonar-batch/src/test/java/org/sonar/batch/scan/report/JSONReportTest.java index 786d5a7f040..1e61491a8c1 100644 --- a/sonar-batch/src/test/java/org/sonar/batch/scan/report/JSONReportTest.java +++ b/sonar-batch/src/test/java/org/sonar/batch/scan/report/JSONReportTest.java @@ -27,8 +27,8 @@ import org.junit.Before; import org.junit.Test; import org.junit.rules.TemporaryFolder; import org.skyscreamer.jsonassert.JSONAssert; +import org.sonar.api.batch.fs.InputDir; import org.sonar.api.batch.fs.InputFile; -import org.sonar.api.batch.fs.InputPath; import org.sonar.api.batch.fs.internal.DefaultFileSystem; import org.sonar.api.batch.fs.internal.DefaultInputDir; import org.sonar.api.batch.fs.internal.DeprecatedDefaultInputFile; @@ -42,9 +42,9 @@ import org.sonar.api.resources.Project; import org.sonar.api.resources.Resource; import org.sonar.api.rule.RuleKey; import org.sonar.batch.issue.IssueCache; +import org.sonar.batch.repository.user.User; +import org.sonar.batch.repository.user.UserRepository; import org.sonar.batch.scan.filesystem.InputPathCache; -import org.sonar.batch.user.User; -import org.sonar.batch.user.UserRepository; import java.io.File; import java.io.IOException; @@ -77,7 +77,7 @@ public class JSONReportTest { @Before public void before() throws Exception { - fs = new DefaultFileSystem(temp.newFolder()); + fs = new DefaultFileSystem(temp.newFolder().toPath()); SIMPLE_DATE_FORMAT.setTimeZone(TimeZone.getTimeZone("GMT+02:00")); when(resource.getEffectiveKey()).thenReturn("Action.java"); when(server.getVersion()).thenReturn("3.6"); @@ -86,7 +86,8 @@ public class JSONReportTest { DeprecatedDefaultInputFile inputFile = new DeprecatedDefaultInputFile("struts", "src/main/java/org/apache/struts/Action.java"); inputFile.setStatus(InputFile.Status.CHANGED); InputPathCache fileCache = mock(InputPathCache.class); - when(fileCache.all()).thenReturn(Arrays.<InputPath>asList(inputDir, inputFile)); + when(fileCache.allFiles()).thenReturn(Arrays.<InputFile>asList(inputFile)); + when(fileCache.allDirs()).thenReturn(Arrays.<InputDir>asList(inputDir)); Project rootModule = new Project("struts"); Project moduleA = new Project("struts-core"); moduleA.setParent(rootModule).setPath("core"); diff --git a/sonar-batch/src/test/java/org/sonar/batch/sensor/AnalyzerOptimizerTest.java b/sonar-batch/src/test/java/org/sonar/batch/sensor/AnalyzerOptimizerTest.java index d0cf02f65a3..1850fe2b001 100644 --- a/sonar-batch/src/test/java/org/sonar/batch/sensor/AnalyzerOptimizerTest.java +++ b/sonar-batch/src/test/java/org/sonar/batch/sensor/AnalyzerOptimizerTest.java @@ -53,7 +53,7 @@ public class AnalyzerOptimizerTest { @Before public void prepare() throws Exception { - fs = new DefaultFileSystem(temp.newFolder()); + fs = new DefaultFileSystem(temp.newFolder().toPath()); settings = new Settings(); analysisMode = mock(AnalysisMode.class); optimizer = new AnalyzerOptimizer(fs, new ActiveRulesBuilder().build(), settings, analysisMode); diff --git a/sonar-batch/src/test/java/org/sonar/batch/sensor/DefaultSensorContextTest.java b/sonar-batch/src/test/java/org/sonar/batch/sensor/DefaultSensorContextTest.java index e6d24b0643f..1812fde5cf4 100644 --- a/sonar-batch/src/test/java/org/sonar/batch/sensor/DefaultSensorContextTest.java +++ b/sonar-batch/src/test/java/org/sonar/batch/sensor/DefaultSensorContextTest.java @@ -58,7 +58,7 @@ public class DefaultSensorContextTest { @Before public void prepare() throws Exception { activeRules = new ActiveRulesBuilder().build(); - fs = new DefaultFileSystem(temp.newFolder()); + fs = new DefaultFileSystem(temp.newFolder().toPath()); MetricFinder metricFinder = mock(MetricFinder.class); when(metricFinder.findByKey(CoreMetrics.NCLOC_KEY)).thenReturn(CoreMetrics.NCLOC); when(metricFinder.findByKey(CoreMetrics.FUNCTION_COMPLEXITY_DISTRIBUTION_KEY)).thenReturn(CoreMetrics.FUNCTION_COMPLEXITY_DISTRIBUTION); 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 658f48e41fd..506bcd328e1 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 @@ -84,7 +84,7 @@ public class DefaultSensorStorageTest { @Before public void prepare() throws Exception { activeRules = new ActiveRulesBuilder().build(); - fs = new DefaultFileSystem(temp.newFolder()); + fs = new DefaultFileSystem(temp.newFolder().toPath()); MetricFinder metricFinder = mock(MetricFinder.class); when(metricFinder.findByKey(CoreMetrics.NCLOC_KEY)).thenReturn(CoreMetrics.NCLOC); when(metricFinder.findByKey(CoreMetrics.FUNCTION_COMPLEXITY_DISTRIBUTION_KEY)).thenReturn(CoreMetrics.FUNCTION_COMPLEXITY_DISTRIBUTION); @@ -279,7 +279,7 @@ public class DefaultSensorStorageTest { when(sonarIndex.getEdge(foo, bar)).thenReturn(new Dependency(foo, bar)); thrown.expect(IllegalStateException.class); - thrown.expectMessage("Dependency between [moduleKey=foo, relative=src/Foo.java, abs=null] and [moduleKey=foo, relative=src/Bar.java, abs=null] was already saved."); + thrown.expectMessage("Dependency between [moduleKey=foo, relative=src/Foo.java, basedir=null] and [moduleKey=foo, relative=src/Bar.java, basedir=null] was already saved."); sensorStorage.store(new DefaultDependency() .from(new DefaultInputFile("foo", "src/Foo.java").setType(Type.MAIN)) diff --git a/sonar-batch/src/test/java/org/sonar/batch/sensor/coverage/CoverageExclusionsTest.java b/sonar-batch/src/test/java/org/sonar/batch/sensor/coverage/CoverageExclusionsTest.java index ec592a7962e..0e2efc2782a 100644 --- a/sonar-batch/src/test/java/org/sonar/batch/sensor/coverage/CoverageExclusionsTest.java +++ b/sonar-batch/src/test/java/org/sonar/batch/sensor/coverage/CoverageExclusionsTest.java @@ -54,7 +54,7 @@ public class CoverageExclusionsTest { @Test public void shouldFilterFileBasedOnPattern() { - Resource resource = File.create("src/org/polop/File.php", "org/polop/File.php", null, false); + Resource resource = File.create("src/org/polop/File.php", null, false); Measure coverageMeasure = mock(Measure.class); when(coverageMeasure.getMetric()).thenReturn(CoreMetrics.LINES_TO_COVER); @@ -65,7 +65,7 @@ public class CoverageExclusionsTest { @Test public void shouldNotFilterFileBasedOnPattern() { - Resource resource = File.create("src/org/polop/File.php", "org/polop/File.php", null, false); + Resource resource = File.create("src/org/polop/File.php", null, false); Measure coverageMeasure = mock(Measure.class); when(coverageMeasure.getMetric()).thenReturn(CoreMetrics.COVERAGE); diff --git a/sonar-batch/src/test/java/org/sonar/batch/source/CodeColorizersTest.java b/sonar-batch/src/test/java/org/sonar/batch/source/CodeColorizersTest.java index 58f1d3f86c8..a7486ad376b 100644 --- a/sonar-batch/src/test/java/org/sonar/batch/source/CodeColorizersTest.java +++ b/sonar-batch/src/test/java/org/sonar/batch/source/CodeColorizersTest.java @@ -19,6 +19,7 @@ */ package org.sonar.batch.source; +import com.google.common.base.Charsets; import com.google.common.collect.ImmutableList; import org.apache.commons.io.FileUtils; import org.junit.Rule; @@ -52,7 +53,7 @@ public class CodeColorizersTest { File jsFile = new File(this.getClass().getResource("CodeColorizersTest/Person.js").toURI()); - SyntaxHighlightingData syntaxHighlighting = codeColorizers.toSyntaxHighlighting(jsFile, "UTF-8", "js"); + SyntaxHighlightingData syntaxHighlighting = codeColorizers.toSyntaxHighlighting(jsFile, Charsets.UTF_8, "js"); assertThat(syntaxHighlighting.writeString()).isEqualTo(HIGHLIGHTING_JS); @@ -67,7 +68,7 @@ public class CodeColorizersTest { File jsFile = new File(this.getClass().getResource("CodeColorizersTest/Person.js").toURI()); FileUtils.write(fileWithBom, FileUtils.readFileToString(jsFile), "UTF-8", true); - SyntaxHighlightingData syntaxHighlighting = codeColorizers.toSyntaxHighlighting(fileWithBom, "UTF-8", "js"); + SyntaxHighlightingData syntaxHighlighting = codeColorizers.toSyntaxHighlighting(fileWithBom, Charsets.UTF_8, "js"); assertThat(syntaxHighlighting.writeString()).isEqualTo(HIGHLIGHTING_JS); } @@ -78,7 +79,7 @@ public class CodeColorizersTest { File javaFile = new File(this.getClass().getResource("CodeColorizersTest/Person.java").toURI()); - SyntaxHighlightingData syntaxHighlighting = codeColorizers.toSyntaxHighlighting(javaFile, "UTF-8", "java"); + SyntaxHighlightingData syntaxHighlighting = codeColorizers.toSyntaxHighlighting(javaFile, Charsets.UTF_8, "java"); assertThat(syntaxHighlighting.writeString()).isEqualTo(HIGHLIGHTING_JAVA); 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 4a26c3b4bbf..e2adf2dd0db 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 @@ -37,7 +37,7 @@ public class HighlightableBuilderTest { @Test public void should_load_default_perspective() throws Exception { - Resource file = new File("foo.c").setEffectiveKey("myproject:path/to/foo.c"); + Resource file = File.create("foo.c").setEffectiveKey("myproject:path/to/foo.c"); Component component = new ResourceComponent(file); HighlightableBuilder builder = new HighlightableBuilder(cache); diff --git a/sonar-batch/src/test/resources/org/sonar/batch/components/PastSnapshotFinderByDateTest/shared.xml b/sonar-batch/src/test/resources/org/sonar/batch/deprecated/components/PastSnapshotFinderByDateTest/shared.xml index d794c3a2422..d794c3a2422 100644 --- a/sonar-batch/src/test/resources/org/sonar/batch/components/PastSnapshotFinderByDateTest/shared.xml +++ b/sonar-batch/src/test/resources/org/sonar/batch/deprecated/components/PastSnapshotFinderByDateTest/shared.xml diff --git a/sonar-batch/src/test/resources/org/sonar/batch/components/PastSnapshotFinderByDaysTest/shared.xml b/sonar-batch/src/test/resources/org/sonar/batch/deprecated/components/PastSnapshotFinderByDaysTest/shared.xml index 119f7399b4d..119f7399b4d 100644 --- a/sonar-batch/src/test/resources/org/sonar/batch/components/PastSnapshotFinderByDaysTest/shared.xml +++ b/sonar-batch/src/test/resources/org/sonar/batch/deprecated/components/PastSnapshotFinderByDaysTest/shared.xml diff --git a/sonar-batch/src/test/resources/org/sonar/batch/components/PastSnapshotFinderByDaysTest/shouldNotFindSelf.xml b/sonar-batch/src/test/resources/org/sonar/batch/deprecated/components/PastSnapshotFinderByDaysTest/shouldNotFindSelf.xml index 166f7c18ea8..166f7c18ea8 100644 --- a/sonar-batch/src/test/resources/org/sonar/batch/components/PastSnapshotFinderByDaysTest/shouldNotFindSelf.xml +++ b/sonar-batch/src/test/resources/org/sonar/batch/deprecated/components/PastSnapshotFinderByDaysTest/shouldNotFindSelf.xml diff --git a/sonar-batch/src/test/resources/org/sonar/batch/components/PastSnapshotFinderByPreviousAnalysisTest/shouldFindPreviousAnalysis.xml b/sonar-batch/src/test/resources/org/sonar/batch/deprecated/components/PastSnapshotFinderByPreviousAnalysisTest/shouldFindPreviousAnalysis.xml index eb5136dc808..eb5136dc808 100644 --- a/sonar-batch/src/test/resources/org/sonar/batch/components/PastSnapshotFinderByPreviousAnalysisTest/shouldFindPreviousAnalysis.xml +++ b/sonar-batch/src/test/resources/org/sonar/batch/deprecated/components/PastSnapshotFinderByPreviousAnalysisTest/shouldFindPreviousAnalysis.xml diff --git a/sonar-batch/src/test/resources/org/sonar/batch/components/PastSnapshotFinderByPreviousAnalysisTest/shouldNotFindPreviousAnalysis.xml b/sonar-batch/src/test/resources/org/sonar/batch/deprecated/components/PastSnapshotFinderByPreviousAnalysisTest/shouldNotFindPreviousAnalysis.xml index 5809598e5d7..5809598e5d7 100644 --- a/sonar-batch/src/test/resources/org/sonar/batch/components/PastSnapshotFinderByPreviousAnalysisTest/shouldNotFindPreviousAnalysis.xml +++ b/sonar-batch/src/test/resources/org/sonar/batch/deprecated/components/PastSnapshotFinderByPreviousAnalysisTest/shouldNotFindPreviousAnalysis.xml diff --git a/sonar-batch/src/test/resources/org/sonar/batch/components/PastSnapshotFinderByPreviousVersionTest/no-previous-version.xml b/sonar-batch/src/test/resources/org/sonar/batch/deprecated/components/PastSnapshotFinderByPreviousVersionTest/no-previous-version.xml index 2f01f86b989..2f01f86b989 100644 --- a/sonar-batch/src/test/resources/org/sonar/batch/components/PastSnapshotFinderByPreviousVersionTest/no-previous-version.xml +++ b/sonar-batch/src/test/resources/org/sonar/batch/deprecated/components/PastSnapshotFinderByPreviousVersionTest/no-previous-version.xml diff --git a/sonar-batch/src/test/resources/org/sonar/batch/components/PastSnapshotFinderByPreviousVersionTest/with-previous-version-deleted.xml b/sonar-batch/src/test/resources/org/sonar/batch/deprecated/components/PastSnapshotFinderByPreviousVersionTest/with-previous-version-deleted.xml index d990e648414..d990e648414 100644 --- a/sonar-batch/src/test/resources/org/sonar/batch/components/PastSnapshotFinderByPreviousVersionTest/with-previous-version-deleted.xml +++ b/sonar-batch/src/test/resources/org/sonar/batch/deprecated/components/PastSnapshotFinderByPreviousVersionTest/with-previous-version-deleted.xml diff --git a/sonar-batch/src/test/resources/org/sonar/batch/components/PastSnapshotFinderByPreviousVersionTest/with-previous-version.xml b/sonar-batch/src/test/resources/org/sonar/batch/deprecated/components/PastSnapshotFinderByPreviousVersionTest/with-previous-version.xml index 5ecbc2fa959..5ecbc2fa959 100644 --- a/sonar-batch/src/test/resources/org/sonar/batch/components/PastSnapshotFinderByPreviousVersionTest/with-previous-version.xml +++ b/sonar-batch/src/test/resources/org/sonar/batch/deprecated/components/PastSnapshotFinderByPreviousVersionTest/with-previous-version.xml diff --git a/sonar-batch/src/test/resources/org/sonar/batch/components/PastSnapshotFinderByVersionTest/shared.xml b/sonar-batch/src/test/resources/org/sonar/batch/deprecated/components/PastSnapshotFinderByVersionTest/shared.xml index 289a362f781..289a362f781 100644 --- a/sonar-batch/src/test/resources/org/sonar/batch/components/PastSnapshotFinderByVersionTest/shared.xml +++ b/sonar-batch/src/test/resources/org/sonar/batch/deprecated/components/PastSnapshotFinderByVersionTest/shared.xml diff --git a/sonar-batch/src/test/resources/org/sonar/batch/components/PeriodsDefinitionTest/shared.xml b/sonar-batch/src/test/resources/org/sonar/batch/deprecated/components/PeriodsDefinitionTest/shared.xml index c8796e2bb80..c8796e2bb80 100644 --- a/sonar-batch/src/test/resources/org/sonar/batch/components/PeriodsDefinitionTest/shared.xml +++ b/sonar-batch/src/test/resources/org/sonar/batch/deprecated/components/PeriodsDefinitionTest/shared.xml diff --git a/sonar-batch/src/test/resources/org/sonar/batch/index/ResourcePersisterTest/shouldSaveNewMultiModulesProject-result.xml b/sonar-batch/src/test/resources/org/sonar/batch/index/ResourcePersisterTest/shouldSaveNewMultiModulesProject-result.xml index bed6ddbad3d..e168b6bc85d 100644 --- a/sonar-batch/src/test/resources/org/sonar/batch/index/ResourcePersisterTest/shouldSaveNewMultiModulesProject-result.xml +++ b/sonar-batch/src/test/resources/org/sonar/batch/index/ResourcePersisterTest/shouldSaveNewMultiModulesProject-result.xml @@ -31,7 +31,7 @@ enabled="true" language="[null]" copy_resource_id="[null]" person_id="[null]" path="src/main/java/org" deprecated_kee="[null]" /> <projects id="1006" scope="FIL" qualifier="FIL" kee="b1:src/main/java/org/Foo.java" root_id="1004" - name="src/main/java/org/Foo.java" long_name="src/main/java/org/Foo.java" description="[null]" + name="Foo.java" long_name="src/main/java/org/Foo.java" description="[null]" enabled="true" language="[null]" copy_resource_id="[null]" person_id="[null]" path="src/main/java/org/Foo.java" deprecated_kee="[null]" /> <snapshots purge_status="[null]" period1_mode="[null]" period1_param="[null]" period1_date="[null]" period2_mode="[null]" period2_param="[null]" period2_date="[null]" period3_mode="[null]" period3_param="[null]" period3_date="[null]" period4_mode="[null]" period4_param="[null]" period4_date="[null]" period5_mode="[null]" period5_param="[null]" period5_date="[null]" id="3001" project_id="1001" root_project_id="1001" parent_snapshot_id="[null]" root_snapshot_id="[null]" diff --git a/sonar-batch/src/test/resources/org/sonar/batch/index/ResourcePersisterTest/shouldSaveNewMultiModulesProjectAndLibrary-result.xml b/sonar-batch/src/test/resources/org/sonar/batch/index/ResourcePersisterTest/shouldSaveNewMultiModulesProjectAndLibrary-result.xml index 86b94e27622..f475284edcb 100644 --- a/sonar-batch/src/test/resources/org/sonar/batch/index/ResourcePersisterTest/shouldSaveNewMultiModulesProjectAndLibrary-result.xml +++ b/sonar-batch/src/test/resources/org/sonar/batch/index/ResourcePersisterTest/shouldSaveNewMultiModulesProjectAndLibrary-result.xml @@ -31,7 +31,7 @@ enabled="true" language="[null]" copy_resource_id="[null]" person_id="[null]" path="src/main/java/org" deprecated_kee="[null]" /> <projects id="1006" scope="FIL" qualifier="FIL" kee="b1:src/main/java/org/Foo.java" root_id="1004" - name="src/main/java/org/Foo.java" long_name="src/main/java/org/Foo.java" description="[null]" + name="Foo.java" long_name="src/main/java/org/Foo.java" description="[null]" enabled="true" language="[null]" copy_resource_id="[null]" person_id="[null]" path="src/main/java/org/Foo.java" deprecated_kee="[null]" /> <snapshots purge_status="[null]" period1_mode="[null]" period1_param="[null]" period1_date="[null]" period2_mode="[null]" period2_param="[null]" period2_date="[null]" period3_mode="[null]" period3_param="[null]" period3_date="[null]" period4_mode="[null]" period4_param="[null]" period4_date="[null]" period5_mode="[null]" period5_param="[null]" period5_date="[null]" id="3001" project_id="1001" root_project_id="1001" parent_snapshot_id="[null]" root_snapshot_id="[null]" |