Search in sources :

Example 21 with ProjectDefinition

use of org.sonar.api.batch.bootstrap.ProjectDefinition in project sonarqube by SonarSource.

the class XooProjectBuilder method build.

@Override
public void build(Context context) {
    if (!settings.getBoolean("sonar.xoo.enableProjectBuilder")) {
        return;
    }
    ProjectDefinition root = context.projectReactor().getRoot();
    ProjectDefinition module = ProjectDefinition.create().setKey(root.getKey() + ":module1").setName("Module 1");
    module.setBaseDir(new File(root.getBaseDir(), "module1"));
    module.setWorkDir(new File(root.getWorkDir(), "module1"));
    module.setSources("src");
    root.addSubProject(module);
}
Also used : File(java.io.File) ProjectDefinition(org.sonar.api.batch.bootstrap.ProjectDefinition)

Example 22 with ProjectDefinition

use of org.sonar.api.batch.bootstrap.ProjectDefinition in project sonarqube by SonarSource.

the class ProjectTest method setNameWithoutBranch.

@Test
public void setNameWithoutBranch() {
    ProjectDefinition definition = ProjectDefinition.create().setKey("key").setName("name");
    Project project = new Project(definition);
    assertThat(project.getName()).isEqualTo("name");
    assertThat(project.getOriginalName()).isEqualTo("name");
}
Also used : ProjectDefinition(org.sonar.api.batch.bootstrap.ProjectDefinition) Test(org.junit.Test)

Example 23 with ProjectDefinition

use of org.sonar.api.batch.bootstrap.ProjectDefinition in project sonarqube by SonarSource.

the class QualifiersTest method testModule.

@Test
public void testModule() {
    ProjectDefinition rootDef = ProjectDefinition.create();
    ProjectDefinition moduleDef = ProjectDefinition.create();
    rootDef.addSubProject(moduleDef);
    Resource sub = new Project(moduleDef);
    assertThat(Qualifiers.isView(sub, true)).isFalse();
    assertThat(Qualifiers.isView(sub, false)).isFalse();
    assertThat(Qualifiers.isProject(sub, true)).isTrue();
    assertThat(Qualifiers.isProject(sub, false)).isFalse();
}
Also used : ProjectDefinition(org.sonar.api.batch.bootstrap.ProjectDefinition) Test(org.junit.Test)

Example 24 with ProjectDefinition

use of org.sonar.api.batch.bootstrap.ProjectDefinition in project sonarqube by SonarSource.

the class MetadataPublisher method publish.

@Override
public void publish(ScannerReportWriter writer) {
    DefaultInputModule rootProject = moduleHierarchy.root();
    ProjectDefinition rootDef = rootProject.definition();
    ScannerReport.Metadata.Builder builder = ScannerReport.Metadata.newBuilder().setAnalysisDate(projectAnalysisInfo.analysisDate().getTime()).setProjectKey(rootDef.getKey()).setCrossProjectDuplicationActivated(SonarCpdBlockIndex.isCrossProjectDuplicationEnabled(settings)).setRootComponentRef(rootProject.batchId());
    String organization = settings.getString(CoreProperties.PROJECT_ORGANIZATION_PROPERTY);
    if (organization != null) {
        builder.setOrganizationKey(organization);
    }
    String branch = rootDef.getBranch();
    if (branch != null) {
        builder.setBranch(branch);
    }
    for (QProfile qp : qProfiles.findAll()) {
        builder.getMutableQprofilesPerLanguage().put(qp.getLanguage(), ScannerReport.Metadata.QProfile.newBuilder().setKey(qp.getKey()).setLanguage(qp.getLanguage()).setName(qp.getName()).setRulesUpdatedAt(qp.getRulesUpdatedAt().getTime()).build());
    }
    writer.writeMetadata(builder.build());
}
Also used : DefaultInputModule(org.sonar.api.batch.fs.internal.DefaultInputModule) QProfile(org.sonar.scanner.rule.QProfile) ProjectDefinition(org.sonar.api.batch.bootstrap.ProjectDefinition)

Example 25 with ProjectDefinition

use of org.sonar.api.batch.bootstrap.ProjectDefinition in project sonarqube by SonarSource.

the class ReportPublisher method upload.

/**
   * Uploads the report file to server and returns the generated task id
   */
@VisibleForTesting
String upload(File report) {
    LOG.debug("Upload report");
    long startTime = System.currentTimeMillis();
    ProjectDefinition projectDefinition = projectReactor.getRoot();
    PostRequest.Part filePart = new PostRequest.Part(MediaTypes.ZIP, report);
    PostRequest post = new PostRequest("api/ce/submit").setMediaType(MediaTypes.PROTOBUF).setParam("organization", settings.getString(CoreProperties.PROJECT_ORGANIZATION_PROPERTY)).setParam("projectKey", projectDefinition.getKey()).setParam("projectName", projectDefinition.getOriginalName()).setParam("projectBranch", projectDefinition.getBranch()).setPart("report", filePart);
    WsResponse response;
    try {
        response = wsClient.call(post).failIfNotSuccessful();
    } catch (HttpException e) {
        throw MessageException.of(String.format("Failed to upload report - %d: %s", e.code(), ScannerWsClient.tryParseAsJsonError(e.content())));
    }
    try (InputStream protobuf = response.contentStream()) {
        return WsCe.SubmitResponse.parser().parseFrom(protobuf).getTaskId();
    } catch (Exception e) {
        throw Throwables.propagate(e);
    } finally {
        long stopTime = System.currentTimeMillis();
        LOG.info("Analysis report uploaded in " + (stopTime - startTime) + "ms");
    }
}
Also used : PostRequest(org.sonarqube.ws.client.PostRequest) InputStream(java.io.InputStream) WsResponse(org.sonarqube.ws.client.WsResponse) HttpException(org.sonarqube.ws.client.HttpException) MessageException(org.sonar.api.utils.MessageException) HttpException(org.sonarqube.ws.client.HttpException) IOException(java.io.IOException) ProjectDefinition(org.sonar.api.batch.bootstrap.ProjectDefinition) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Aggregations

ProjectDefinition (org.sonar.api.batch.bootstrap.ProjectDefinition)52 Test (org.junit.Test)29 File (java.io.File)10 DefaultInputModule (org.sonar.api.batch.fs.internal.DefaultInputModule)8 ProjectReactor (org.sonar.api.batch.bootstrap.ProjectReactor)5 DefaultInputDir (org.sonar.api.batch.fs.internal.DefaultInputDir)4 DefaultInputFile (org.sonar.api.batch.fs.internal.DefaultInputFile)4 InputModuleHierarchy (org.sonar.api.batch.fs.internal.InputModuleHierarchy)4 TestInputFileBuilder (org.sonar.api.batch.fs.internal.TestInputFileBuilder)4 ProjectAnalysisInfo (org.sonar.scanner.ProjectAnalysisInfo)4 GlobalSettings (org.sonar.scanner.bootstrap.GlobalSettings)4 AnalysisContextReportPublisher (org.sonar.scanner.report.AnalysisContextReportPublisher)4 ComponentsPublisher (org.sonar.scanner.report.ComponentsPublisher)4 ProjectRepositories (org.sonar.scanner.repository.ProjectRepositories)4 HashMap (java.util.HashMap)3 Before (org.junit.Before)3 Component (org.sonar.scanner.protocol.output.ScannerReport.Component)3 ScannerReportReader (org.sonar.scanner.protocol.output.ScannerReportReader)3 ArrayList (java.util.ArrayList)2 Map (java.util.Map)2