Search in sources :

Example 1 with BranchConfiguration

use of org.sonar.scanner.scan.branch.BranchConfiguration 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 BranchConfiguration

use of org.sonar.scanner.scan.branch.BranchConfiguration in project sonarqube by SonarSource.

the class DefaultSensorStorageTest method prepare.

@Before
public void prepare() throws Exception {
    MetricFinder metricFinder = mock(MetricFinder.class);
    when(metricFinder.<Integer>findByKey(CoreMetrics.NCLOC_KEY)).thenReturn(CoreMetrics.NCLOC);
    when(metricFinder.<String>findByKey(CoreMetrics.FUNCTION_COMPLEXITY_DISTRIBUTION_KEY)).thenReturn(CoreMetrics.FUNCTION_COMPLEXITY_DISTRIBUTION);
    when(metricFinder.<Integer>findByKey(CoreMetrics.LINES_TO_COVER_KEY)).thenReturn(CoreMetrics.LINES_TO_COVER);
    settings = new MapSettings();
    moduleIssues = mock(IssuePublisher.class);
    reportPublisher = mock(ReportPublisher.class);
    final File reportDir = temp.newFolder();
    reportWriter = new ScannerReportWriter(reportDir);
    reportReader = new ScannerReportReader(reportDir);
    when(reportPublisher.getWriter()).thenReturn(reportWriter);
    when(reportPublisher.getReader()).thenReturn(reportReader);
    branchConfiguration = mock(BranchConfiguration.class);
    underTest = new DefaultSensorStorage(metricFinder, moduleIssues, settings.asConfig(), reportPublisher, mock(SonarCpdBlockIndex.class), contextPropertiesCache, new ScannerMetrics(), branchConfiguration);
    project = new DefaultInputProject(ProjectDefinition.create().setKey("foo").setBaseDir(temp.newFolder()).setWorkDir(temp.newFolder()));
}
Also used : BranchConfiguration(org.sonar.scanner.scan.branch.BranchConfiguration) MetricFinder(org.sonar.api.batch.measure.MetricFinder) ScannerMetrics(org.sonar.core.metric.ScannerMetrics) ScannerReportWriter(org.sonar.scanner.protocol.output.ScannerReportWriter) ReportPublisher(org.sonar.scanner.report.ReportPublisher) ScannerReportReader(org.sonar.scanner.protocol.output.ScannerReportReader) DefaultInputProject(org.sonar.api.batch.fs.internal.DefaultInputProject) MapSettings(org.sonar.api.config.internal.MapSettings) IssuePublisher(org.sonar.scanner.issue.IssuePublisher) InputFile(org.sonar.api.batch.fs.InputFile) DefaultInputFile(org.sonar.api.batch.fs.internal.DefaultInputFile) File(java.io.File) Before(org.junit.Before)

Example 3 with BranchConfiguration

use of org.sonar.scanner.scan.branch.BranchConfiguration in project sonarqube by SonarSource.

the class ModuleSensorContextTest method prepare.

@Before
public void prepare() throws Exception {
    activeRules = new ActiveRulesBuilder().build();
    fs = new DefaultFileSystem(temp.newFolder().toPath());
    MetricFinder metricFinder = mock(MetricFinder.class);
    when(metricFinder.<Integer>findByKey(CoreMetrics.NCLOC_KEY)).thenReturn(CoreMetrics.NCLOC);
    when(metricFinder.<String>findByKey(CoreMetrics.FUNCTION_COMPLEXITY_DISTRIBUTION_KEY)).thenReturn(CoreMetrics.FUNCTION_COMPLEXITY_DISTRIBUTION);
    settings = new MapSettings();
    sensorStorage = mock(SensorStorage.class);
    branchConfiguration = mock(BranchConfiguration.class);
    runtime = SonarRuntimeImpl.forSonarQube(Version.parse("5.5"), SonarQubeSide.SCANNER, SonarEdition.COMMUNITY);
}
Also used : ActiveRulesBuilder(org.sonar.api.batch.rule.internal.ActiveRulesBuilder) BranchConfiguration(org.sonar.scanner.scan.branch.BranchConfiguration) MapSettings(org.sonar.api.config.internal.MapSettings) MetricFinder(org.sonar.api.batch.measure.MetricFinder) DefaultFileSystem(org.sonar.api.batch.fs.internal.DefaultFileSystem) SensorStorage(org.sonar.api.batch.sensor.internal.SensorStorage) Before(org.junit.Before)

Example 4 with BranchConfiguration

use of org.sonar.scanner.scan.branch.BranchConfiguration in project sonarqube by SonarSource.

the class ComponentsPublisherTest method setUp.

@Before
public void setUp() throws IOException {
    branchConfiguration = mock(BranchConfiguration.class);
    outputDir = temp.newFolder();
    writer = new ScannerReportWriter(outputDir);
}
Also used : BranchConfiguration(org.sonar.scanner.scan.branch.BranchConfiguration) ScannerReportWriter(org.sonar.scanner.protocol.output.ScannerReportWriter) Before(org.junit.Before)

Example 5 with BranchConfiguration

use of org.sonar.scanner.scan.branch.BranchConfiguration in project sonarqube by SonarSource.

the class DefaultActiveRulesLoaderTest method setUp.

@Before
public void setUp() {
    wsClient = mock(DefaultScannerWsClient.class);
    BranchConfiguration branchConfig = mock(BranchConfiguration.class);
    when(branchConfig.isPullRequest()).thenReturn(false);
    loader = new DefaultActiveRulesLoader(wsClient);
}
Also used : BranchConfiguration(org.sonar.scanner.scan.branch.BranchConfiguration) DefaultScannerWsClient(org.sonar.scanner.bootstrap.DefaultScannerWsClient) Before(org.junit.Before)

Aggregations

BranchConfiguration (org.sonar.scanner.scan.branch.BranchConfiguration)5 Before (org.junit.Before)4 MetricFinder (org.sonar.api.batch.measure.MetricFinder)2 MapSettings (org.sonar.api.config.internal.MapSettings)2 ScannerReportWriter (org.sonar.scanner.protocol.output.ScannerReportWriter)2 ReportPublisher (org.sonar.scanner.report.ReportPublisher)2 File (java.io.File)1 InputFile (org.sonar.api.batch.fs.InputFile)1 DefaultFileSystem (org.sonar.api.batch.fs.internal.DefaultFileSystem)1 DefaultInputFile (org.sonar.api.batch.fs.internal.DefaultInputFile)1 DefaultInputProject (org.sonar.api.batch.fs.internal.DefaultInputProject)1 ActiveRulesBuilder (org.sonar.api.batch.rule.internal.ActiveRulesBuilder)1 SensorStorage (org.sonar.api.batch.sensor.internal.SensorStorage)1 ScannerMetrics (org.sonar.core.metric.ScannerMetrics)1 DefaultScannerWsClient (org.sonar.scanner.bootstrap.DefaultScannerWsClient)1 GlobalAnalysisMode (org.sonar.scanner.bootstrap.GlobalAnalysisMode)1 CpdExecutor (org.sonar.scanner.cpd.CpdExecutor)1 InputModuleHierarchy (org.sonar.scanner.fs.InputModuleHierarchy)1 IssuePublisher (org.sonar.scanner.issue.IssuePublisher)1 AnalysisObservers (org.sonar.scanner.mediumtest.AnalysisObservers)1