Search in sources :

Example 46 with ComponentDto

use of org.sonar.db.component.ComponentDto in project sonarqube by SonarSource.

the class ProjectDataLoader method addFileData.

private static void addFileData(ProjectRepositories data, List<ComponentDto> moduleChildren, List<FilePathWithHashDto> files) {
    Map<String, String> moduleKeysByUuid = newHashMap();
    for (ComponentDto module : moduleChildren) {
        moduleKeysByUuid.put(module.uuid(), module.key());
    }
    for (FilePathWithHashDto file : files) {
        FileData fileData = new FileData(file.getSrcHash(), file.getRevision());
        data.addFileData(moduleKeysByUuid.get(file.getModuleUuid()), file.getPath(), fileData);
    }
}
Also used : ComponentDto(org.sonar.db.component.ComponentDto) FilePathWithHashDto(org.sonar.db.component.FilePathWithHashDto) FileData(org.sonar.scanner.protocol.input.FileData)

Example 47 with ComponentDto

use of org.sonar.db.component.ComponentDto in project sonarqube by SonarSource.

the class ProjectDataLoader method load.

public ProjectRepositories load(ProjectDataQuery query) {
    try (DbSession session = dbClient.openSession(false)) {
        ProjectRepositories data = new ProjectRepositories();
        ComponentDto module = checkFoundWithOptional(dbClient.componentDao().selectByKey(session, query.getModuleKey()), "Project or module with key '%s' is not found", query.getModuleKey());
        checkRequest(isProjectOrModule(module), "Key '%s' belongs to a component which is not a Project", query.getModuleKey());
        boolean hasScanPerm = userSession.hasComponentPermission(SCAN_EXECUTION, module) || userSession.hasPermission(OrganizationPermission.SCAN, module.getOrganizationUuid());
        boolean hasBrowsePerm = userSession.hasComponentPermission(USER, module);
        checkPermission(query.isIssuesMode(), hasScanPerm, hasBrowsePerm);
        ComponentDto project = getProject(module, session);
        if (!project.key().equals(module.key())) {
            addSettings(data, module.getKey(), getSettingsFromParents(module, hasScanPerm, session));
        }
        List<ComponentDto> modulesTree = dbClient.componentDao().selectEnabledDescendantModules(session, module.uuid());
        Map<String, String> moduleUuidsByKey = moduleUuidsByKey(modulesTree);
        Map<String, Long> moduleIdsByKey = moduleIdsByKey(modulesTree);
        List<PropertyDto> modulesTreeSettings = dbClient.propertiesDao().selectEnabledDescendantModuleProperties(module.uuid(), session);
        TreeModuleSettings treeModuleSettings = new TreeModuleSettings(moduleUuidsByKey, moduleIdsByKey, modulesTree, modulesTreeSettings);
        addSettingsToChildrenModules(data, query.getModuleKey(), Maps.<String, String>newHashMap(), treeModuleSettings, hasScanPerm);
        List<FilePathWithHashDto> files = searchFilesWithHashAndRevision(session, module);
        addFileData(data, modulesTree, files);
        // FIXME need real value but actually only used to know if there is a previous analysis in local issue tracking mode so any value is
        // ok
        data.setLastAnalysisDate(new Date());
        return data;
    }
}
Also used : ComponentDto(org.sonar.db.component.ComponentDto) FilePathWithHashDto(org.sonar.db.component.FilePathWithHashDto) Date(java.util.Date) DbSession(org.sonar.db.DbSession) ProjectRepositories(org.sonar.scanner.protocol.input.ProjectRepositories) PropertyDto(org.sonar.db.property.PropertyDto)

Example 48 with ComponentDto

use of org.sonar.db.component.ComponentDto in project sonarqube by SonarSource.

the class ProjectDataLoader method getSettingsFromParents.

private Map<String, String> getSettingsFromParents(ComponentDto module, boolean hasScanPerm, DbSession session) {
    List<ComponentDto> parents = newArrayList();
    aggregateParentModules(module, parents, session);
    Collections.reverse(parents);
    Map<String, String> parentProperties = newHashMap();
    for (ComponentDto parent : parents) {
        parentProperties.putAll(getPropertiesMap(dbClient.propertiesDao().selectProjectProperties(session, parent.key()), hasScanPerm));
    }
    return parentProperties;
}
Also used : ComponentDto(org.sonar.db.component.ComponentDto)

Example 49 with ComponentDto

use of org.sonar.db.component.ComponentDto in project sonarqube by SonarSource.

the class ProjectDataLoader method addSettingsToChildrenModules.

private static void addSettingsToChildrenModules(ProjectRepositories ref, String moduleKey, Map<String, String> parentProperties, TreeModuleSettings treeModuleSettings, boolean hasScanPerm) {
    Map<String, String> currentParentProperties = newHashMap();
    currentParentProperties.putAll(parentProperties);
    currentParentProperties.putAll(getPropertiesMap(treeModuleSettings.findModuleSettings(moduleKey), hasScanPerm));
    addSettings(ref, moduleKey, currentParentProperties);
    for (ComponentDto childModule : treeModuleSettings.findChildrenModule(moduleKey)) {
        addSettings(ref, childModule.getKey(), currentParentProperties);
        addSettingsToChildrenModules(ref, childModule.getKey(), currentParentProperties, treeModuleSettings, hasScanPerm);
    }
}
Also used : ComponentDto(org.sonar.db.component.ComponentDto)

Example 50 with ComponentDto

use of org.sonar.db.component.ComponentDto in project sonarqube by SonarSource.

the class ProjectDataLoader method aggregateParentModules.

private void aggregateParentModules(ComponentDto component, List<ComponentDto> parents, DbSession session) {
    String moduleUuid = component.moduleUuid();
    if (moduleUuid != null) {
        ComponentDto parent = dbClient.componentDao().selectOrFailByUuid(session, moduleUuid);
        if (parent != null) {
            parents.add(parent);
            aggregateParentModules(parent, parents, session);
        }
    }
}
Also used : ComponentDto(org.sonar.db.component.ComponentDto)

Aggregations

ComponentDto (org.sonar.db.component.ComponentDto)836 Test (org.junit.Test)661 OrganizationDto (org.sonar.db.organization.OrganizationDto)151 SnapshotDto (org.sonar.db.component.SnapshotDto)94 DbSession (org.sonar.db.DbSession)70 SearchOptions (org.sonar.server.es.SearchOptions)62 MetricDto (org.sonar.db.metric.MetricDto)49 IssueDto (org.sonar.db.issue.IssueDto)48 RuleDto (org.sonar.db.rule.RuleDto)47 GroupDto (org.sonar.db.user.GroupDto)39 UserDto (org.sonar.db.user.UserDto)38 WsTester (org.sonar.server.ws.WsTester)33 MetricTesting.newMetricDto (org.sonar.db.metric.MetricTesting.newMetricDto)25 PropertyDto (org.sonar.db.property.PropertyDto)23 IssueIndexer (org.sonar.server.issue.index.IssueIndexer)21 ProjectRepositories (org.sonar.scanner.protocol.input.ProjectRepositories)18 Date (java.util.Date)16 ComponentLinkDto (org.sonar.db.component.ComponentLinkDto)14 RuleTesting.newRuleDto (org.sonar.db.rule.RuleTesting.newRuleDto)14 ComponentTreeWsResponse (org.sonarqube.ws.WsMeasures.ComponentTreeWsResponse)13