Search in sources :

Example 1 with InputModuleHierarchy

use of org.sonar.scanner.fs.InputModuleHierarchy in project sonarqube by SonarSource.

the class SpringProjectScanContainer method doAfterStart.

@Override
protected void doAfterStart() {
    getComponentByType(ProjectLock.class).tryLock();
    GlobalAnalysisMode analysisMode = getComponentByType(GlobalAnalysisMode.class);
    InputModuleHierarchy tree = getComponentByType(InputModuleHierarchy.class);
    ScanProperties properties = getComponentByType(ScanProperties.class);
    properties.validate();
    properties.get("sonar.branch").ifPresent(deprecatedBranch -> {
        throw MessageException.of("The 'sonar.branch' parameter is no longer supported. You should stop using it. " + "Branch analysis is available in Developer Edition and above. See https://redirect.sonarsource.com/editions/developer.html for more information.");
    });
    BranchConfiguration branchConfig = getComponentByType(BranchConfiguration.class);
    if (branchConfig.branchType() == BranchType.PULL_REQUEST) {
        LOG.info("Pull request {} for merge into {} from {}", branchConfig.pullRequestKey(), pullRequestBaseToDisplayName(branchConfig.targetBranchName()), branchConfig.branchName());
    } else if (branchConfig.branchName() != null) {
        LOG.info("Branch name: {}", branchConfig.branchName());
    }
    getComponentByType(ProjectFileIndexer.class).index();
    // Log detected languages and their profiles after FS is indexed and languages detected
    getComponentByType(QProfileVerifier.class).execute();
    scanRecursively(tree, tree.root());
    LOG.info("------------- Run sensors on project");
    getComponentByType(ProjectSensorsExecutor.class).execute();
    getComponentByType(ScmPublisher.class).publish();
    getComponentByType(CpdExecutor.class).execute();
    getComponentByType(ReportPublisher.class).execute();
    if (properties.shouldWaitForQualityGate()) {
        LOG.info("------------- Check Quality Gate status");
        getComponentByType(QualityGateCheck.class).await();
    }
    getComponentByType(PostJobsExecutor.class).execute();
    if (analysisMode.isMediumTest()) {
        getComponentByType(AnalysisObservers.class).notifyEndOfScanTask();
    }
}
Also used : BranchConfiguration(org.sonar.scanner.scan.branch.BranchConfiguration) ProjectFileIndexer(org.sonar.scanner.scan.filesystem.ProjectFileIndexer) GlobalAnalysisMode(org.sonar.scanner.bootstrap.GlobalAnalysisMode) ProjectSensorsExecutor(org.sonar.scanner.sensor.ProjectSensorsExecutor) ReportPublisher(org.sonar.scanner.report.ReportPublisher) AnalysisContextReportPublisher(org.sonar.scanner.report.AnalysisContextReportPublisher) InputModuleHierarchy(org.sonar.scanner.fs.InputModuleHierarchy) QualityGateCheck(org.sonar.scanner.qualitygate.QualityGateCheck) QProfileVerifier(org.sonar.scanner.rule.QProfileVerifier) ScmPublisher(org.sonar.scanner.scm.ScmPublisher) CpdExecutor(org.sonar.scanner.cpd.CpdExecutor) PostJobsExecutor(org.sonar.scanner.postjob.PostJobsExecutor) AnalysisObservers(org.sonar.scanner.mediumtest.AnalysisObservers)

Example 2 with InputModuleHierarchy

use of org.sonar.scanner.fs.InputModuleHierarchy in project sonarqube by SonarSource.

the class MetadataPublisherTest method createPublisher.

private void createPublisher(ProjectDefinition def) throws IOException {
    Path rootBaseDir = temp.newFolder().toPath();
    Path moduleBaseDir = rootBaseDir.resolve("moduleDir");
    Files.createDirectory(moduleBaseDir);
    DefaultInputModule rootModule = new DefaultInputModule(def.setBaseDir(rootBaseDir.toFile()).setKey("root").setWorkDir(temp.newFolder()), TestInputFileBuilder.nextBatchId());
    InputModuleHierarchy inputModuleHierarchy = mock(InputModuleHierarchy.class);
    when(inputModuleHierarchy.root()).thenReturn(rootModule);
    DefaultInputModule child = new DefaultInputModule(ProjectDefinition.create().setKey("module").setBaseDir(moduleBaseDir.toFile()).setWorkDir(temp.newFolder()), TestInputFileBuilder.nextBatchId());
    when(inputModuleHierarchy.children(rootModule)).thenReturn(Collections.singletonList(child));
    when(inputModuleHierarchy.relativePathToRoot(child)).thenReturn("modulePath");
    when(inputModuleHierarchy.relativePathToRoot(rootModule)).thenReturn("");
    branches = mock(BranchConfiguration.class);
    scmConfiguration = mock(ScmConfiguration.class);
    when(scmConfiguration.provider()).thenReturn(scmProvider);
    underTest = new MetadataPublisher(projectInfo, inputModuleHierarchy, qProfiles, cpdSettings, pluginRepository, branches, scmRevision, componentStore, scmConfiguration);
}
Also used : Path(java.nio.file.Path) BranchConfiguration(org.sonar.scanner.scan.branch.BranchConfiguration) InputModuleHierarchy(org.sonar.scanner.fs.InputModuleHierarchy) DefaultInputModule(org.sonar.api.batch.fs.internal.DefaultInputModule) ScmConfiguration(org.sonar.scanner.scm.ScmConfiguration)

Example 3 with InputModuleHierarchy

use of org.sonar.scanner.fs.InputModuleHierarchy in project sonarqube by SonarSource.

the class ModuleSensorsExecutorTest method createModuleExecutor.

private ModuleSensorsExecutor createModuleExecutor(String sensorName) throws IOException {
    Sensor sensor = new TestSensor(sensorName);
    ModuleSensorWrapper sensorWrapper = new ModuleSensorWrapper(sensor, context, optimizer, fileSystem, branchConfiguration);
    ModuleSensorExtensionDictionary selector = mock(ModuleSensorExtensionDictionary.class);
    when(selector.selectSensors(false)).thenReturn(Collections.singleton(sensorWrapper));
    when(selector.selectSensors(true)).thenReturn(Collections.singleton(sensorWrapper));
    ProjectDefinition rootDef = ProjectDefinition.create().setKey("root").setBaseDir(temp.newFolder()).setWorkDir(temp.newFolder());
    DefaultInputModule rootModule = TestInputFileBuilder.newDefaultInputModule(rootDef);
    InputModuleHierarchy hierarchy = mock(InputModuleHierarchy.class);
    when(hierarchy.isRoot(rootModule)).thenReturn(true);
    return new ModuleSensorsExecutor(selector, rootModule, hierarchy, strategy, pluginRepo);
}
Also used : ModuleSensorWrapper(org.sonar.scanner.sensor.ModuleSensorWrapper) InputModuleHierarchy(org.sonar.scanner.fs.InputModuleHierarchy) ModuleSensorExtensionDictionary(org.sonar.scanner.sensor.ModuleSensorExtensionDictionary) ModuleSensorsExecutor(org.sonar.scanner.sensor.ModuleSensorsExecutor) DefaultInputModule(org.sonar.api.batch.fs.internal.DefaultInputModule) Sensor(org.sonar.api.batch.sensor.Sensor) ProjectDefinition(org.sonar.api.batch.bootstrap.ProjectDefinition)

Example 4 with InputModuleHierarchy

use of org.sonar.scanner.fs.InputModuleHierarchy in project sonarqube by SonarSource.

the class ScmRevisionImplTest method ignore_failure_if_scm_does_not_support_revisions.

@Test
public void ignore_failure_if_scm_does_not_support_revisions() {
    CiConfiguration ciConfiguration = mock(CiConfiguration.class);
    when(ciConfiguration.getScmRevision()).thenReturn(Optional.empty());
    Map<String, String> scannerConfiguration = new HashMap<>();
    ScmConfiguration scmConfiguration = mock(ScmConfiguration.class, RETURNS_DEEP_STUBS);
    when(scmConfiguration.provider().revisionId(any())).thenThrow(new UnsupportedOperationException("BOOM"));
    InputModuleHierarchy moduleHierarchy = mock(InputModuleHierarchy.class, RETURNS_DEEP_STUBS);
    ScmRevisionImpl underTest = new ScmRevisionImpl(ciConfiguration, new ScannerProperties(scannerConfiguration), scmConfiguration, moduleHierarchy);
    assertThat(underTest.get()).isEmpty();
}
Also used : InputModuleHierarchy(org.sonar.scanner.fs.InputModuleHierarchy) ScannerProperties(org.sonar.scanner.bootstrap.ScannerProperties) HashMap(java.util.HashMap) CiConfiguration(org.sonar.scanner.ci.CiConfiguration) Test(org.junit.Test)

Example 5 with InputModuleHierarchy

use of org.sonar.scanner.fs.InputModuleHierarchy in project sonarqube by SonarSource.

the class ScmRevisionImplTest method testGet.

private Optional<String> testGet(@Nullable String cliValue, @Nullable String ciValue, @Nullable String scmValue) {
    CiConfiguration ciConfiguration = mock(CiConfiguration.class);
    when(ciConfiguration.getScmRevision()).thenReturn(Optional.ofNullable(ciValue));
    Map<String, String> scannerConfiguration = new HashMap<>();
    scannerConfiguration.put("sonar.scm.revision", cliValue);
    ScmConfiguration scmConfiguration = mock(ScmConfiguration.class, RETURNS_DEEP_STUBS);
    when(scmConfiguration.provider().revisionId(any())).thenReturn(scmValue);
    InputModuleHierarchy moduleHierarchy = mock(InputModuleHierarchy.class, RETURNS_DEEP_STUBS);
    ScmRevisionImpl underTest = new ScmRevisionImpl(ciConfiguration, new ScannerProperties(scannerConfiguration), scmConfiguration, moduleHierarchy);
    return underTest.get();
}
Also used : InputModuleHierarchy(org.sonar.scanner.fs.InputModuleHierarchy) ScannerProperties(org.sonar.scanner.bootstrap.ScannerProperties) HashMap(java.util.HashMap) CiConfiguration(org.sonar.scanner.ci.CiConfiguration)

Aggregations

InputModuleHierarchy (org.sonar.scanner.fs.InputModuleHierarchy)6 DefaultInputModule (org.sonar.api.batch.fs.internal.DefaultInputModule)3 HashMap (java.util.HashMap)2 ProjectDefinition (org.sonar.api.batch.bootstrap.ProjectDefinition)2 Sensor (org.sonar.api.batch.sensor.Sensor)2 ScannerProperties (org.sonar.scanner.bootstrap.ScannerProperties)2 CiConfiguration (org.sonar.scanner.ci.CiConfiguration)2 BranchConfiguration (org.sonar.scanner.scan.branch.BranchConfiguration)2 ModuleSensorExtensionDictionary (org.sonar.scanner.sensor.ModuleSensorExtensionDictionary)2 ModuleSensorsExecutor (org.sonar.scanner.sensor.ModuleSensorsExecutor)2 Path (java.nio.file.Path)1 Before (org.junit.Before)1 Test (org.junit.Test)1 GlobalAnalysisMode (org.sonar.scanner.bootstrap.GlobalAnalysisMode)1 CpdExecutor (org.sonar.scanner.cpd.CpdExecutor)1 AnalysisObservers (org.sonar.scanner.mediumtest.AnalysisObservers)1 PostJobsExecutor (org.sonar.scanner.postjob.PostJobsExecutor)1 QualityGateCheck (org.sonar.scanner.qualitygate.QualityGateCheck)1 AnalysisContextReportPublisher (org.sonar.scanner.report.AnalysisContextReportPublisher)1 ReportPublisher (org.sonar.scanner.report.ReportPublisher)1