use of org.sonar.ce.task.projectanalysis.component.Component in project sonarqube by SonarSource.
the class ElementsAndCoveredElementsCounter method initialize.
@Override
public void initialize(CounterInitializationContext context) {
Component component = context.getLeaf();
if (component.getType() == Component.Type.FILE && component.getFileAttributes().isUnitTest()) {
return;
}
initializeForSupportedLeaf(context);
}
use of org.sonar.ce.task.projectanalysis.component.Component in project sonarqube by SonarSource.
the class PersistProjectLinksStep method execute.
@Override
public void execute(ComputationStep.Context context) {
if (!analysisMetadataHolder.getBranch().isMain()) {
return;
}
try (DbSession session = dbClient.openSession(false)) {
Component project = treeRootHolder.getRoot();
ScannerReport.Component batchComponent = reportReader.readComponent(project.getReportAttributes().getRef());
List<ProjectLinkDto> previousLinks = dbClient.projectLinkDao().selectByProjectUuid(session, project.getUuid());
mergeLinks(session, project.getUuid(), batchComponent.getLinkList(), previousLinks);
session.commit();
}
}
use of org.sonar.ce.task.projectanalysis.component.Component in project sonarqube by SonarSource.
the class PersistProjectLinksStep method mergeLinks.
private void mergeLinks(DbSession session, String componentUuid, List<ScannerReport.ComponentLink> links, List<ProjectLinkDto> previousLinks) {
Set<String> linkType = new HashSet<>();
links.forEach(link -> {
String type = convertType(link.getType());
checkArgument(!linkType.contains(type), "Link of type '%s' has already been declared on component '%s'", type, componentUuid);
linkType.add(type);
Optional<ProjectLinkDto> previousLink = previousLinks.stream().filter(input -> input != null && input.getType().equals(convertType(link.getType()))).findFirst();
if (previousLink.isPresent()) {
previousLink.get().setHref(link.getHref());
dbClient.projectLinkDao().update(session, previousLink.get());
} else {
dbClient.projectLinkDao().insert(session, new ProjectLinkDto().setUuid(uuidFactory.create()).setProjectUuid(componentUuid).setType(type).setHref(link.getHref()));
}
});
previousLinks.stream().filter(dto -> !linkType.contains(dto.getType())).filter(dto -> ProjectLinkDto.PROVIDED_TYPES.contains(dto.getType())).forEach(dto -> dbClient.projectLinkDao().delete(session, dto.getUuid()));
}
use of org.sonar.ce.task.projectanalysis.component.Component in project sonarqube by SonarSource.
the class UpdateNeedIssueSyncStep method execute.
@Override
public void execute(ComputationStep.Context context) {
try (DbSession dbSession = dbClient.openSession(false)) {
Component project = treeRootHolder.getRoot();
dbClient.branchDao().updateNeedIssueSync(dbSession, project.getUuid(), false);
dbSession.commit();
}
}
use of org.sonar.ce.task.projectanalysis.component.Component in project sonarqube by SonarSource.
the class ValidateProjectStep method execute.
@Override
public void execute(ComputationStep.Context context) {
try (DbSession dbSession = dbClient.openSession(false)) {
validateTargetBranch(dbSession);
Component root = treeRootHolder.getRoot();
// FIXME if module have really be dropped, no more need to load them
List<ComponentDto> baseModules = dbClient.componentDao().selectEnabledModulesFromProjectKey(dbSession, root.getDbKey());
Map<String, ComponentDto> baseModulesByKey = baseModules.stream().collect(Collectors.toMap(ComponentDto::getDbKey, x -> x));
ValidateProjectsVisitor visitor = new ValidateProjectsVisitor(dbSession, dbClient.componentDao(), baseModulesByKey);
new DepthTraversalTypeAwareCrawler(visitor).visit(root);
if (!visitor.validationMessages.isEmpty()) {
throw MessageException.of("Validation of project failed:\n o " + MESSAGES_JOINER.join(visitor.validationMessages));
}
}
}
Aggregations