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