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();
}
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);
}
}
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();
}
Aggregations