private final GlobalAnalysisMode analysisMode;
private final BranchConfiguration branchConfig;
private final ProjectRepositories projectRepos;
- private final IncrementalScannerHandler validateIncremental;
+ private final IncrementalScannerHandler incrementalScannerHandler;
private boolean scanAllFiles;
private boolean incremental;
}
public DefaultAnalysisMode(AnalysisProperties props, BranchConfiguration branchConfig,
- GlobalAnalysisMode analysisMode, ProjectRepositories projectRepos, @Nullable IncrementalScannerHandler validateIncremental) {
+ GlobalAnalysisMode analysisMode, ProjectRepositories projectRepos, @Nullable IncrementalScannerHandler incrementalScannerHandler) {
this.branchConfig = branchConfig;
this.analysisMode = analysisMode;
this.projectRepos = projectRepos;
- this.validateIncremental = validateIncremental;
+ this.incrementalScannerHandler = incrementalScannerHandler;
this.analysisProps = props.properties();
load();
+ printFlags();
}
@Override
return scanAllFiles;
}
- public void printFlags() {
+ private void printFlags() {
+ if (incremental) {
+ LOG.info("Incremental mode");
+ }
if (!scanAllFiles) {
LOG.info("Scanning only changed files");
}
private void load() {
String scanAllStr = analysisProps.get(KEY_SCAN_ALL);
- scanAllFiles = !branchConfig.isShortLivingBranch() && (!analysisMode.isIssues() || "true".equals(scanAllStr));
incremental = incremental();
+ scanAllFiles = !incremental && !branchConfig.isShortLivingBranch() && (!analysisMode.isIssues() || "true".equals(scanAllStr));
}
private boolean incremental() {
String inc = analysisProps.get(KEY_INCREMENTAL);
if ("true".equals(inc)) {
- if (validateIncremental == null || !validateIncremental.execute()) {
+ if (incrementalScannerHandler == null || !incrementalScannerHandler.execute()) {
throw MessageException.of("Incremental mode is not available. Please contact your administrator.");
}
protected boolean issues;
protected boolean mediumTestMode;
+ public GlobalAnalysisMode(GlobalProperties props) {
+ String mode = props.property(CoreProperties.ANALYSIS_MODE);
+ validate(mode);
+ issues = CoreProperties.ANALYSIS_MODE_ISSUES.equals(mode) || CoreProperties.ANALYSIS_MODE_PREVIEW.equals(mode);
+ mediumTestMode = "true".equals(props.property(MEDIUM_TEST_ENABLED));
+ if (preview) {
+ LOG.info("Preview mode");
+ } else if (issues) {
+ LOG.info("Issues mode");
+ } else {
+ LOG.info("Publish mode");
+ }
+ if (mediumTestMode) {
+ LOG.info("Medium test mode");
+ }
+ }
+
public boolean isPreview() {
return preview;
}
}
}
-
- public GlobalAnalysisMode(GlobalProperties props) {
- String mode = props.property(CoreProperties.ANALYSIS_MODE);
- validate(mode);
- issues = CoreProperties.ANALYSIS_MODE_ISSUES.equals(mode) || CoreProperties.ANALYSIS_MODE_PREVIEW.equals(mode);
- mediumTestMode = "true".equals(props.property(MEDIUM_TEST_ENABLED));
- if (preview) {
- LOG.debug("Preview mode");
- } else if (issues) {
- LOG.debug("Issues mode");
- } else {
- LOG.debug("Publish mode");
- }
- if (mediumTestMode) {
- LOG.info("Medium test mode");
- }
- }
}
private BranchConfiguration branchConfig;
private ProjectRepositories projectRepos;
private GlobalAnalysisMode globalMode;
- private IncrementalScannerHandler validateIncremental;
+ private IncrementalScannerHandler incrementalScannerHandler;
@Before
public void setUp() {
branchConfig = mock(BranchConfiguration.class);
projectRepos = mock(ProjectRepositories.class);
globalMode = mock(GlobalAnalysisMode.class);
- validateIncremental = mock(IncrementalScannerHandler.class);
+ incrementalScannerHandler = mock(IncrementalScannerHandler.class);
}
@Rule
@Test
public void no_incremental_if_not_publish() {
- when(validateIncremental.execute()).thenReturn(true);
+ when(incrementalScannerHandler.execute()).thenReturn(true);
AnalysisProperties analysisProps = new AnalysisProperties(Collections.singletonMap("sonar.incremental", "true"));
thrown.expect(MessageException.class);
thrown.expectMessage("Incremental analysis is only available in publish mode");
@Test
public void no_incremental_mode_if_branches() {
when(globalMode.isPublish()).thenReturn(true);
- when(validateIncremental.execute()).thenReturn(true);
+ when(incrementalScannerHandler.execute()).thenReturn(true);
when(branchConfig.branchName()).thenReturn("branch1");
AnalysisProperties analysisProps = new AnalysisProperties(Collections.singletonMap("sonar.incremental", "true"));
DefaultAnalysisMode analysisMode = createmode(analysisProps);
assertThat(analysisMode.isIncremental()).isFalse();
+ assertThat(analysisMode.scanAllFiles()).isTrue();
}
@Test
public void no_incremental_mode_if_no_previous_analysis() {
- when(validateIncremental.execute()).thenReturn(true);
+ when(incrementalScannerHandler.execute()).thenReturn(true);
when(globalMode.isPublish()).thenReturn(true);
AnalysisProperties analysisProps = new AnalysisProperties(Collections.singletonMap("sonar.incremental", "true"));
DefaultAnalysisMode analysisMode = createmode(analysisProps);
assertThat(analysisMode.isIncremental()).isFalse();
+ assertThat(analysisMode.scanAllFiles()).isTrue();
}
@Test
public void incremental_mode() {
- when(validateIncremental.execute()).thenReturn(true);
+ when(incrementalScannerHandler.execute()).thenReturn(true);
when(globalMode.isPublish()).thenReturn(true);
when(projectRepos.lastAnalysisDate()).thenReturn(new Date());
when(projectRepos.exists()).thenReturn(true);
AnalysisProperties analysisProps = new AnalysisProperties(Collections.singletonMap("sonar.incremental", "true"));
DefaultAnalysisMode analysisMode = createmode(analysisProps);
assertThat(analysisMode.isIncremental()).isTrue();
+ assertThat(analysisMode.scanAllFiles()).isFalse();
}
@Test
}
private DefaultAnalysisMode createmode(AnalysisProperties analysisProps) {
- return new DefaultAnalysisMode(analysisProps, branchConfig, globalMode, projectRepos, validateIncremental);
+ return new DefaultAnalysisMode(analysisProps, branchConfig, globalMode, projectRepos, incrementalScannerHandler);
}
}