Search in sources :

Example 26 with ProjectDefinition

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

the class AnalysisContextReportPublisher method collectModuleSpecificProps.

/**
   * Only keep props that are not in parent
   */
private Map<String, String> collectModuleSpecificProps(ProjectDefinition moduleDefinition) {
    Map<String, String> moduleSpecificProps = new HashMap<>();
    if (projectRepos.moduleExists(moduleDefinition.getKeyWithBranch())) {
        moduleSpecificProps.putAll(projectRepos.settings(moduleDefinition.getKeyWithBranch()));
    }
    ProjectDefinition parent = moduleDefinition.getParent();
    if (parent == null) {
        moduleSpecificProps.putAll(moduleDefinition.properties());
    } else {
        Map<String, String> parentProps = parent.properties();
        for (Map.Entry<String, String> entry : moduleDefinition.properties().entrySet()) {
            if (!parentProps.containsKey(entry.getKey()) || !parentProps.get(entry.getKey()).equals(entry.getValue())) {
                moduleSpecificProps.put(entry.getKey(), entry.getValue());
            }
        }
    }
    return moduleSpecificProps;
}
Also used : HashMap(java.util.HashMap) HashMap(java.util.HashMap) Map(java.util.Map) ProjectDefinition(org.sonar.api.batch.bootstrap.ProjectDefinition)

Example 27 with ProjectDefinition

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

the class ComponentsPublisher method writeVersion.

private static void writeVersion(DefaultInputModule module, ScannerReport.Component.Builder builder) {
    ProjectDefinition def = module.definition();
    String version = getVersion(def);
    if (version != null) {
        builder.setVersion(version);
    }
}
Also used : ProjectDefinition(org.sonar.api.batch.bootstrap.ProjectDefinition)

Example 28 with ProjectDefinition

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

the class ProjectReactorBuilder method defineChildren.

private void defineChildren(ProjectDefinition parentProject, Map<String, Map<String, String>> propertiesByModuleIdPath, String parentModuleIdPath) {
    Map<String, String> parentProps = parentProject.properties();
    if (parentProps.containsKey(PROPERTY_MODULES)) {
        for (String moduleId : getListFromProperty(parentProps, PROPERTY_MODULES)) {
            String moduleIdPath = parentModuleIdPath.isEmpty() ? moduleId : (parentModuleIdPath + "." + moduleId);
            Map<String, String> moduleProps = propertiesByModuleIdPath.get(moduleIdPath);
            ProjectDefinition childProject = loadChildProject(parentProject, moduleProps, moduleId);
            // check the uniqueness of the child key
            checkUniquenessOfChildKey(childProject, parentProject);
            // the child project may have children as well
            defineChildren(childProject, propertiesByModuleIdPath, moduleIdPath);
            // and finally add this child project to its parent
            parentProject.addSubProject(childProject);
        }
    }
}
Also used : ProjectDefinition(org.sonar.api.batch.bootstrap.ProjectDefinition)

Example 29 with ProjectDefinition

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

the class DefaultInputModuleHierarchy method relativePath.

@Override
@CheckForNull
public String relativePath(InputModule module) {
    DefaultInputModule parent = parent(module);
    if (parent == null) {
        return null;
    }
    DefaultInputModule inputModule = (DefaultInputModule) module;
    ProjectDefinition parentDefinition = parent.definition();
    Path parentBaseDir = parentDefinition.getBaseDir().toPath();
    ProjectDefinition moduleDefinition = inputModule.definition();
    Path moduleBaseDir = moduleDefinition.getBaseDir().toPath();
    return pathResolver.relativePath(parentBaseDir, moduleBaseDir);
}
Also used : Path(java.nio.file.Path) DefaultInputModule(org.sonar.api.batch.fs.internal.DefaultInputModule) ProjectDefinition(org.sonar.api.batch.bootstrap.ProjectDefinition) CheckForNull(javax.annotation.CheckForNull)

Example 30 with ProjectDefinition

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

the class ModuleIndexer method createChildren.

private void createChildren(DefaultInputModule parent) {
    for (ProjectDefinition def : parent.definition().getSubProjects()) {
        DefaultInputModule child = new DefaultInputModule(def, batchIdGenerator.get());
        moduleHierarchy.index(child, parent);
        componentTree.index(child, parent);
        componentStore.put(child);
        createChildren(child);
    }
}
Also used : DefaultInputModule(org.sonar.api.batch.fs.internal.DefaultInputModule) ProjectDefinition(org.sonar.api.batch.bootstrap.ProjectDefinition)

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