Search in sources :

Example 1 with DefaultInputProject

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);
}
Also used : DefaultInputProject(org.sonar.api.batch.fs.internal.DefaultInputProject) AbstractProjectOrModule(org.sonar.api.batch.fs.internal.AbstractProjectOrModule) File(java.io.File) ProjectDefinition(org.sonar.api.batch.bootstrap.ProjectDefinition) Test(org.junit.Test)

Example 2 with DefaultInputProject

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);
}
Also used : DefaultInputProject(org.sonar.api.batch.fs.internal.DefaultInputProject) AbstractProjectOrModule(org.sonar.api.batch.fs.internal.AbstractProjectOrModule) SensorStorage(org.sonar.api.batch.sensor.internal.SensorStorage) Test(org.junit.Test)

Example 3 with DefaultInputProject

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);
}
Also used : TestInputFileBuilder(org.sonar.api.batch.fs.internal.TestInputFileBuilder) BranchConfiguration(org.sonar.scanner.scan.branch.BranchConfiguration) DefaultInputProject(org.sonar.api.batch.fs.internal.DefaultInputProject) InputComponentStore(org.sonar.scanner.scan.filesystem.InputComponentStore) SonarRuntime(org.sonar.api.SonarRuntime) ScannerReportWriter(org.sonar.scanner.protocol.output.ScannerReportWriter) DefaultInputFile(org.sonar.api.batch.fs.internal.DefaultInputFile) File(java.io.File) Before(org.junit.Before)

Example 4 with DefaultInputProject

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();
}
Also used : ScannerReportReader(org.sonar.scanner.protocol.output.ScannerReportReader) DefaultInputProject(org.sonar.api.batch.fs.internal.DefaultInputProject) InputComponentStore(org.sonar.scanner.scan.filesystem.InputComponentStore) ProjectInfo(org.sonar.scanner.ProjectInfo) Component(org.sonar.scanner.protocol.output.ScannerReport.Component) ProjectDefinition(org.sonar.api.batch.bootstrap.ProjectDefinition) Test(org.junit.Test)

Example 5 with DefaultInputProject

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();
}
Also used : Path(java.nio.file.Path) TestInputFileBuilder(org.sonar.api.batch.fs.internal.TestInputFileBuilder) DefaultInputProject(org.sonar.api.batch.fs.internal.DefaultInputProject) DefaultInputFile(org.sonar.api.batch.fs.internal.DefaultInputFile) InputComponentStore(org.sonar.scanner.scan.filesystem.InputComponentStore) ProjectInfo(org.sonar.scanner.ProjectInfo) ProjectDefinition(org.sonar.api.batch.bootstrap.ProjectDefinition) Test(org.junit.Test)

Aggregations

DefaultInputProject (org.sonar.api.batch.fs.internal.DefaultInputProject)14 Test (org.junit.Test)8 File (java.io.File)7 ProjectDefinition (org.sonar.api.batch.bootstrap.ProjectDefinition)7 DefaultInputFile (org.sonar.api.batch.fs.internal.DefaultInputFile)6 InputComponentStore (org.sonar.scanner.scan.filesystem.InputComponentStore)6 Before (org.junit.Before)5 ScannerReportReader (org.sonar.scanner.protocol.output.ScannerReportReader)5 TestInputFileBuilder (org.sonar.api.batch.fs.internal.TestInputFileBuilder)4 ProjectInfo (org.sonar.scanner.ProjectInfo)4 AbstractProjectOrModule (org.sonar.api.batch.fs.internal.AbstractProjectOrModule)3 Component (org.sonar.scanner.protocol.output.ScannerReport.Component)3 ScannerReportWriter (org.sonar.scanner.protocol.output.ScannerReportWriter)3 BranchConfiguration (org.sonar.scanner.scan.branch.BranchConfiguration)3 Path (java.nio.file.Path)2 InputFile (org.sonar.api.batch.fs.InputFile)2 LinkedList (java.util.LinkedList)1 SonarRuntime (org.sonar.api.SonarRuntime)1 InputPath (org.sonar.api.batch.fs.InputPath)1 DefaultInputModule (org.sonar.api.batch.fs.internal.DefaultInputModule)1