use of org.sonar.api.batch.fs.internal.DefaultInputModule in project sonarqube by SonarSource.
the class IssuableFactoryTest method project_should_be_issuable.
@Test
public void project_should_be_issuable() {
IssuableFactory factory = new IssuableFactory(mock(DefaultSensorContext.class));
Issuable issuable = factory.loadPerspective(Issuable.class, new DefaultInputModule("foo"));
assertThat(issuable).isNotNull();
assertThat(issuable.issues()).isEmpty();
}
use of org.sonar.api.batch.fs.internal.DefaultInputModule in project sonarqube by SonarSource.
the class ComponentsPublisherTest method add_components_to_report.
@Test
public void add_components_to_report() throws Exception {
ProjectAnalysisInfo projectAnalysisInfo = mock(ProjectAnalysisInfo.class);
when(projectAnalysisInfo.analysisDate()).thenReturn(DateUtils.parseDate("2012-12-12"));
ProjectDefinition rootDef = ProjectDefinition.create().setKey("foo").setProperty(CoreProperties.PROJECT_VERSION_PROPERTY, "1.0").setName("Root project").setDescription("Root description");
DefaultInputModule root = new DefaultInputModule(rootDef, 1);
ProjectDefinition module1Def = ProjectDefinition.create().setKey("module1").setName("Module1").setDescription("Module description");
rootDef.addSubProject(module1Def);
DefaultInputModule module1 = new DefaultInputModule(module1Def, 2);
moduleHierarchy = mock(InputModuleHierarchy.class);
when(moduleHierarchy.root()).thenReturn(root);
when(moduleHierarchy.children(root)).thenReturn(Collections.singleton(module1));
tree.index(module1, root);
DefaultInputDir dir = new DefaultInputDir("module1", "src", 3);
tree.index(dir, module1);
DefaultInputFile file = new TestInputFileBuilder("module1", "src/Foo.java", 4).setLines(2).build();
tree.index(file, dir);
DefaultInputFile file2 = new TestInputFileBuilder("module1", "src/Foo2.java", 5).setPublish(false).setLines(2).build();
tree.index(file2, dir);
DefaultInputFile fileWithoutLang = new TestInputFileBuilder("module1", "src/make", 6).setLines(10).build();
tree.index(fileWithoutLang, dir);
DefaultInputFile testFile = new TestInputFileBuilder("module1", "test/FooTest.java", 7).setType(Type.TEST).setLines(4).build();
tree.index(testFile, dir);
ComponentsPublisher publisher = new ComponentsPublisher(moduleHierarchy, tree);
publisher.publish(writer);
assertThat(writer.hasComponentData(FileStructure.Domain.COMPONENT, 1)).isTrue();
assertThat(writer.hasComponentData(FileStructure.Domain.COMPONENT, 2)).isTrue();
assertThat(writer.hasComponentData(FileStructure.Domain.COMPONENT, 3)).isTrue();
assertThat(writer.hasComponentData(FileStructure.Domain.COMPONENT, 4)).isTrue();
assertThat(writer.hasComponentData(FileStructure.Domain.COMPONENT, 6)).isTrue();
assertThat(writer.hasComponentData(FileStructure.Domain.COMPONENT, 7)).isTrue();
// not marked for publishing
assertThat(writer.hasComponentData(FileStructure.Domain.COMPONENT, 5)).isFalse();
// no such reference
assertThat(writer.hasComponentData(FileStructure.Domain.COMPONENT, 8)).isFalse();
ScannerReportReader reader = new ScannerReportReader(outputDir);
Component rootProtobuf = reader.readComponent(1);
assertThat(rootProtobuf.getKey()).isEqualTo("foo");
assertThat(rootProtobuf.getDescription()).isEqualTo("Root description");
assertThat(rootProtobuf.getVersion()).isEqualTo("1.0");
assertThat(rootProtobuf.getLinkCount()).isEqualTo(0);
Component module1Protobuf = reader.readComponent(2);
assertThat(module1Protobuf.getKey()).isEqualTo("module1");
assertThat(module1Protobuf.getDescription()).isEqualTo("Module description");
assertThat(module1Protobuf.getVersion()).isEqualTo("1.0");
}
use of org.sonar.api.batch.fs.internal.DefaultInputModule in project sonarqube by SonarSource.
the class MetadataPublisherTest method prepare.
@Before
public void prepare() {
projectDef = ProjectDefinition.create().setKey("foo");
rootModule = new DefaultInputModule(projectDef, TestInputFileBuilder.nextBatchId());
projectAnalysisInfo = mock(ProjectAnalysisInfo.class);
when(projectAnalysisInfo.analysisDate()).thenReturn(new Date(1234567L));
inputModuleHierarchy = mock(InputModuleHierarchy.class);
when(inputModuleHierarchy.root()).thenReturn(rootModule);
settings = new MapSettings();
qProfiles = mock(ModuleQProfiles.class);
underTest = new MetadataPublisher(projectAnalysisInfo, inputModuleHierarchy, settings, qProfiles);
}
use of org.sonar.api.batch.fs.internal.DefaultInputModule in project sonarqube by SonarSource.
the class DefaultSensorStorageTest method shouldSaveProjectMeasureToSensorContext.
@Test
public void shouldSaveProjectMeasureToSensorContext() {
String projectKey = "myProject";
DefaultInputModule module = new DefaultInputModule(projectKey);
ArgumentCaptor<DefaultMeasure> argumentCaptor = ArgumentCaptor.forClass(DefaultMeasure.class);
when(measureCache.put(eq(module.key()), eq(CoreMetrics.NCLOC_KEY), argumentCaptor.capture())).thenReturn(null);
underTest.store(new DefaultMeasure().on(module).forMetric(CoreMetrics.NCLOC).withValue(10));
DefaultMeasure m = argumentCaptor.getValue();
assertThat(m.value()).isEqualTo(10);
assertThat(m.metric()).isEqualTo(CoreMetrics.NCLOC);
}
use of org.sonar.api.batch.fs.internal.DefaultInputModule in project sonarqube by SonarSource.
the class InputComponentStoreTest method should_add_input_file.
@Test
public void should_add_input_file() throws Exception {
InputComponentStore cache = new InputComponentStore(new PathResolver());
String rootModuleKey = "struts";
File rootBaseDir = temp.newFolder();
DefaultInputModule rootModule = TestInputFileBuilder.newDefaultInputModule(rootModuleKey, rootBaseDir);
cache.put(rootModule);
String subModuleKey = "struts-core";
DefaultInputModule subModule = TestInputFileBuilder.newDefaultInputModule(subModuleKey, temp.newFolder());
rootModule.definition().addSubProject(subModule.definition());
cache.put(subModule);
DefaultInputFile fooFile = new TestInputFileBuilder(rootModuleKey, "src/main/java/Foo.java").setModuleBaseDir(rootBaseDir.toPath()).setPublish(true).build();
cache.put(fooFile);
cache.put(new TestInputFileBuilder(subModuleKey, "src/main/java/Bar.java").setLanguage("bla").setPublish(false).setType(Type.MAIN).setStatus(Status.ADDED).setLines(2).setCharset(StandardCharsets.UTF_8).setModuleBaseDir(temp.newFolder().toPath()).build());
DefaultInputFile loadedFile = (DefaultInputFile) cache.getFile(subModuleKey, "src/main/java/Bar.java");
assertThat(loadedFile.relativePath()).isEqualTo("src/main/java/Bar.java");
assertThat(loadedFile.charset()).isEqualTo(StandardCharsets.UTF_8);
assertThat(cache.filesByModule(rootModuleKey)).hasSize(1);
assertThat(cache.filesByModule(subModuleKey)).hasSize(1);
assertThat(cache.allFiles()).hasSize(2);
for (InputPath inputPath : cache.allFiles()) {
assertThat(inputPath.relativePath()).startsWith("src/main/java/");
}
List<InputFile> toPublish = new LinkedList<>();
cache.allFilesToPublish().forEach(toPublish::add);
assertThat(toPublish).containsExactly(fooFile);
cache.remove(fooFile);
assertThat(cache.allFiles()).hasSize(1);
cache.removeModule(rootModuleKey);
assertThat(cache.filesByModule(rootModuleKey)).hasSize(0);
assertThat(cache.filesByModule(subModuleKey)).hasSize(1);
assertThat(cache.allFiles()).hasSize(1);
}
Aggregations