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);
}
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");
}
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();
}
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());
}
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");
}
}
Aggregations