use of org.sonar.api.batch.fs.internal.DefaultInputProject in project sonarqube by SonarSource.
the class DefaultInputProjectTest method testEncoding.
@Test
public void testEncoding() throws IOException {
ProjectDefinition def = ProjectDefinition.create();
def.setKey("projectKey");
def.setName("projectName");
File baseDir = temp.newFolder();
def.setBaseDir(baseDir);
def.setProjectVersion("version");
def.setDescription("desc");
File workDir = temp.newFolder();
def.setWorkDir(workDir);
def.setSources("file1");
def.setProperty("sonar.sourceEncoding", "UTF-16");
AbstractProjectOrModule project = new DefaultInputProject(def);
assertThat(project.getEncoding()).isEqualTo(StandardCharsets.UTF_16);
}
use of org.sonar.api.batch.fs.internal.DefaultInputProject in project sonarqube by SonarSource.
the class DefaultMeasureTest method build_project_measure.
@Test
public void build_project_measure() throws IOException {
SensorStorage storage = Mockito.mock(SensorStorage.class);
AbstractProjectOrModule module = new DefaultInputProject(ProjectDefinition.create().setKey("foo").setBaseDir(temp.newFolder()).setWorkDir(temp.newFolder()));
DefaultMeasure<Integer> newMeasure = new DefaultMeasure<Integer>(storage).forMetric(CoreMetrics.LINES).on(module).withValue(3);
Assertions.assertThat(newMeasure.inputComponent()).isEqualTo(module);
Assertions.assertThat(newMeasure.metric()).isEqualTo(CoreMetrics.LINES);
Assertions.assertThat(newMeasure.value()).isEqualTo(3);
newMeasure.save();
Mockito.verify(storage).store(newMeasure);
}
use of org.sonar.api.batch.fs.internal.DefaultInputProject in project sonarqube by SonarSource.
the class SourcePublisherTest method prepare.
@Before
public void prepare() throws IOException {
File baseDir = temp.newFolder();
sourceFile = new File(baseDir, "src/Foo.php");
String moduleKey = "foo";
inputFile = new TestInputFileBuilder(moduleKey, "src/Foo.php").setLines(5).setModuleBaseDir(baseDir.toPath()).setCharset(StandardCharsets.ISO_8859_1).build();
DefaultInputProject rootProject = TestInputFileBuilder.newDefaultInputProject(moduleKey, baseDir);
InputComponentStore componentStore = new InputComponentStore(mock(BranchConfiguration.class), mock(SonarRuntime.class));
componentStore.put(moduleKey, inputFile);
publisher = new SourcePublisher(componentStore);
File outputDir = temp.newFolder();
writer = new ScannerReportWriter(outputDir);
}
use of org.sonar.api.batch.fs.internal.DefaultInputProject in project sonarqube by SonarSource.
the class ComponentsPublisherTest method publish_project_without_version_and_name.
@Test
public void publish_project_without_version_and_name() throws IOException {
ProjectInfo projectInfo = mock(ProjectInfo.class);
when(projectInfo.getAnalysisDate()).thenReturn(DateUtils.parseDate("2012-12-12"));
ProjectDefinition rootDef = ProjectDefinition.create().setKey("foo").setDescription("Root description").setBaseDir(temp.newFolder()).setWorkDir(temp.newFolder());
DefaultInputProject project = new DefaultInputProject(rootDef, 1);
InputComponentStore store = new InputComponentStore(branchConfiguration, sonarRuntime);
ComponentsPublisher publisher = new ComponentsPublisher(project, store);
publisher.publish(writer);
assertThat(writer.hasComponentData(FileStructure.Domain.COMPONENT, 1)).isTrue();
ScannerReportReader reader = new ScannerReportReader(outputDir);
Component rootProtobuf = reader.readComponent(1);
assertThat(rootProtobuf.getKey()).isEqualTo("foo");
assertThat(rootProtobuf.getName()).isEmpty();
assertThat(rootProtobuf.getDescription()).isEqualTo("Root description");
assertThat(rootProtobuf.getLinkCount()).isZero();
}
use of org.sonar.api.batch.fs.internal.DefaultInputProject in project sonarqube by SonarSource.
the class ComponentsPublisherTest method publish_unchanged_components_even_in_prs.
@Test
public void publish_unchanged_components_even_in_prs() throws IOException {
when(branchConfiguration.isPullRequest()).thenReturn(true);
ProjectInfo projectInfo = mock(ProjectInfo.class);
when(projectInfo.getAnalysisDate()).thenReturn(DateUtils.parseDate("2012-12-12"));
Path baseDir = temp.newFolder().toPath();
ProjectDefinition rootDef = ProjectDefinition.create().setKey("foo").setProperty(CoreProperties.PROJECT_VERSION_PROPERTY, "1.0").setName("Root project").setDescription("Root description").setBaseDir(baseDir.toFile()).setWorkDir(temp.newFolder());
DefaultInputProject project = new DefaultInputProject(rootDef, 1);
InputComponentStore store = new InputComponentStore(branchConfiguration, sonarRuntime);
DefaultInputFile file = new TestInputFileBuilder("foo", "src/Foo.java", 5).setLines(2).setPublish(true).setStatus(InputFile.Status.ADDED).build();
store.put("foo", file);
DefaultInputFile file2 = new TestInputFileBuilder("foo", "src2/Foo2.java", 6).setPublish(true).setStatus(InputFile.Status.SAME).setLines(2).build();
store.put("foo", file2);
ComponentsPublisher publisher = new ComponentsPublisher(project, store);
publisher.publish(writer);
assertThat(writer.hasComponentData(FileStructure.Domain.COMPONENT, 5)).isTrue();
// do not skip, needed for computing overall coverage
assertThat(writer.hasComponentData(FileStructure.Domain.COMPONENT, 6)).isTrue();
}
Aggregations