Search in sources :

Example 6 with ScmProvider

use of org.sonar.api.batch.scm.ScmProvider in project sonarqube by SonarSource.

the class ScmChangedFilesProviderTest method testLegacyScmProvider.

@Test
public void testLegacyScmProvider() {
    ScmProvider legacy = new ScmProvider() {

        @Override
        public String key() {
            return null;
        }
    };
    when(scmConfiguration.provider()).thenReturn(legacy);
    when(branchConfiguration.isPullRequest()).thenReturn(true);
    when(branchConfiguration.targetBranchName()).thenReturn("target");
    ScmChangedFiles scmChangedFiles = provider.provide(scmConfiguration, branchConfiguration, project);
    assertThat(scmChangedFiles.get()).isNull();
    verify(scmConfiguration).provider();
}
Also used : ScmProvider(org.sonar.api.batch.scm.ScmProvider) Test(org.junit.Test)

Example 7 with ScmProvider

use of org.sonar.api.batch.scm.ScmProvider in project sonarqube by SonarSource.

the class ScmPublisher method publish.

public void publish() {
    if (configuration.isDisabled()) {
        LOG.info("SCM Publisher is disabled");
        return;
    }
    ScmProvider provider = configuration.provider();
    if (provider == null) {
        LOG.info("SCM Publisher No SCM system was detected. You can use the '" + CoreProperties.SCM_PROVIDER_KEY + "' property to explicitly specify it.");
        return;
    }
    List<InputFile> filesToBlame = collectFilesToBlame(writer);
    if (!filesToBlame.isEmpty()) {
        String key = provider.key();
        LOG.info("SCM Publisher SCM provider for this project is: " + key);
        DefaultBlameOutput output = new DefaultBlameOutput(writer, analysisWarnings, filesToBlame);
        try {
            provider.blameCommand().blame(new DefaultBlameInput(fs, filesToBlame), output);
        } catch (Exception e) {
            output.finish(false);
            throw e;
        }
        output.finish(true);
    }
}
Also used : ScmProvider(org.sonar.api.batch.scm.ScmProvider) InputFile(org.sonar.api.batch.fs.InputFile) DefaultInputFile(org.sonar.api.batch.fs.internal.DefaultInputFile)

Example 8 with ScmProvider

use of org.sonar.api.batch.scm.ScmProvider in project sonarqube by SonarSource.

the class ScmRevisionImpl method get.

@Override
public Optional<String> get() {
    Optional<String> revision = Optional.ofNullable(scannerConfiguration.property(SCM_REVISION));
    if (isSet(revision)) {
        return revision;
    }
    revision = ciConfiguration.getScmRevision();
    if (isSet(revision)) {
        return revision;
    }
    ScmProvider scmProvider = scmConfiguration.provider();
    if (scmProvider != null) {
        try {
            revision = Optional.ofNullable(scmProvider.revisionId(moduleHierarchy.root().getBaseDir()));
        } catch (UnsupportedOperationException e) {
            LOG.debug(e.getMessage());
            revision = Optional.empty();
        }
    }
    if (isSet(revision)) {
        return revision;
    }
    return Optional.empty();
}
Also used : ScmProvider(org.sonar.api.batch.scm.ScmProvider)

Aggregations

ScmProvider (org.sonar.api.batch.scm.ScmProvider)8 Path (java.nio.file.Path)3 Test (org.junit.Test)3 File (java.io.File)2 DefaultInputFile (org.sonar.api.batch.fs.internal.DefaultInputFile)2 Profiler (org.sonar.api.utils.log.Profiler)2 ScannerReport (org.sonar.scanner.protocol.output.ScannerReport)2 ScannerReportWriter (org.sonar.scanner.protocol.output.ScannerReportWriter)2 Collections (java.util.Collections)1 LinkedList (java.util.LinkedList)1 Map (java.util.Map)1 Optional (java.util.Optional)1 Optional.empty (java.util.Optional.empty)1 Set (java.util.Set)1 Collectors (java.util.stream.Collectors)1 StreamSupport (java.util.stream.StreamSupport)1 CheckForNull (javax.annotation.CheckForNull)1 InputFile (org.sonar.api.batch.fs.InputFile)1 DefaultInputModule (org.sonar.api.batch.fs.internal.DefaultInputModule)1 DefaultInputProject (org.sonar.api.batch.fs.internal.DefaultInputProject)1