Search in sources :

Example 6 with AbstractProjectOrModule

use of org.sonar.api.batch.fs.internal.AbstractProjectOrModule in project sonarqube by SonarSource.

the class MetadataPublisher method publish.

@Override
public void publish(ScannerReportWriter writer) {
    AbstractProjectOrModule rootProject = moduleHierarchy.root();
    ScannerReport.Metadata.Builder builder = ScannerReport.Metadata.newBuilder().setAnalysisDate(projectInfo.getAnalysisDate().getTime()).setProjectKey(rootProject.key()).setCrossProjectDuplicationActivated(cpdSettings.isCrossProjectDuplicationEnabled()).setRootComponentRef(rootProject.scannerId());
    projectInfo.getProjectVersion().ifPresent(builder::setProjectVersion);
    projectInfo.getBuildString().ifPresent(builder::setBuildString);
    if (branchConfiguration.branchName() != null) {
        addBranchInformation(builder);
    }
    addScmInformation(builder);
    addNotAnalyzedFileCountsByLanguage(builder);
    for (QProfile qp : qProfiles.findAll()) {
        builder.putQprofilesPerLanguage(qp.getLanguage(), ScannerReport.Metadata.QProfile.newBuilder().setKey(qp.getKey()).setLanguage(qp.getLanguage()).setName(qp.getName()).setRulesUpdatedAt(qp.getRulesUpdatedAt().getTime()).build());
    }
    for (Entry<String, ScannerPlugin> pluginEntry : pluginRepository.getPluginsByKey().entrySet()) {
        builder.putPluginsByKey(pluginEntry.getKey(), ScannerReport.Metadata.Plugin.newBuilder().setKey(pluginEntry.getKey()).setUpdatedAt(pluginEntry.getValue().getUpdatedAt()).build());
    }
    addModulesRelativePaths(builder);
    writer.writeMetadata(builder.build());
}
Also used : ScannerPlugin(org.sonar.scanner.bootstrap.ScannerPlugin) AbstractProjectOrModule(org.sonar.api.batch.fs.internal.AbstractProjectOrModule) QProfile(org.sonar.scanner.rule.QProfile)

Example 7 with AbstractProjectOrModule

use of org.sonar.api.batch.fs.internal.AbstractProjectOrModule in project sonarqube by SonarSource.

the class DefaultInputProjectTest method testGetters.

@Test
public void testGetters() throws IOException {
    ProjectDefinition def = ProjectDefinition.create();
    def.setKey("projectKey");
    def.setName("projectName");
    File baseDir = temp.newFolder();
    def.setBaseDir(baseDir);
    def.setDescription("desc");
    File workDir = temp.newFolder();
    def.setWorkDir(workDir);
    def.setSources("file1");
    def.setTests("test1");
    AbstractProjectOrModule project = new DefaultInputProject(def);
    assertThat(project.key()).isEqualTo("projectKey");
    assertThat(project.getName()).isEqualTo("projectName");
    assertThat(project.getOriginalName()).isEqualTo("projectName");
    assertThat(project.definition()).isEqualTo(def);
    assertThat(project.getBaseDir()).isEqualTo(baseDir.toPath().toRealPath(LinkOption.NOFOLLOW_LINKS));
    assertThat(project.getDescription()).isEqualTo("desc");
    assertThat(project.getWorkDir()).isEqualTo(workDir.toPath());
    assertThat(project.getEncoding()).isEqualTo(Charset.defaultCharset());
    assertThat(project.properties()).hasSize(5);
    assertThat(project.isFile()).isFalse();
}
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)

Aggregations

AbstractProjectOrModule (org.sonar.api.batch.fs.internal.AbstractProjectOrModule)7 Test (org.junit.Test)4 File (java.io.File)3 DefaultInputProject (org.sonar.api.batch.fs.internal.DefaultInputProject)3 ProjectDefinition (org.sonar.api.batch.bootstrap.ProjectDefinition)2 Path (java.nio.file.Path)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 CheckForNull (javax.annotation.CheckForNull)1 DefaultInputFile (org.sonar.api.batch.fs.internal.DefaultInputFile)1 SensorStorage (org.sonar.api.batch.sensor.internal.SensorStorage)1 ScannerPlugin (org.sonar.scanner.bootstrap.ScannerPlugin)1 QProfile (org.sonar.scanner.rule.QProfile)1