private final GlobalAnalysisMode analysisMode;
private final BranchConfiguration branchConfig;
private final ProjectRepositories projectRepos;
- private final ValidateIncremental validateIncremental;
+ private final IncrementalScannerHandler validateIncremental;
private boolean scanAllFiles;
private boolean incremental;
}
public DefaultAnalysisMode(AnalysisProperties props, BranchConfiguration branchConfig,
- GlobalAnalysisMode analysisMode, ProjectRepositories projectRepos, @Nullable ValidateIncremental validateIncremental) {
+ GlobalAnalysisMode analysisMode, ProjectRepositories projectRepos, @Nullable IncrementalScannerHandler validateIncremental) {
this.branchConfig = branchConfig;
this.analysisMode = analysisMode;
this.projectRepos = projectRepos;
private boolean incremental() {
String inc = analysisProps.get(KEY_INCREMENTAL);
if ("true".equals(inc)) {
- if (validateIncremental == null || !validateIncremental.validate()) {
+ if (validateIncremental == null || !validateIncremental.execute()) {
throw MessageException.of("Incremental mode is not available. Please contact your administrator.");
}
if (!analysisMode.isPublish()) {
- throw new IllegalStateException("Incremental analysis is only available in publish mode");
+ throw MessageException.of("Incremental analysis is only available in publish mode");
}
if (branchConfig.branchName() != null) {
--- /dev/null
+/*
+ * SonarQube
+ * Copyright (C) 2009-2017 SonarSource SA
+ * mailto:info AT sonarsource DOT com
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+package org.sonar.scanner.analysis;
+
+public interface IncrementalScannerHandler {
+ boolean execute();
+}
+++ /dev/null
-/*
- * SonarQube
- * Copyright (C) 2009-2017 SonarSource SA
- * mailto:info AT sonarsource DOT com
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- */
-package org.sonar.scanner.analysis;
-
-public interface ValidateIncremental {
- boolean validate();
-}
import java.util.Map;
import org.picocontainer.injectors.ProviderAdapter;
import org.sonar.api.batch.bootstrap.ProjectReactor;
-import org.sonar.scanner.bootstrap.GlobalConfiguration;
import org.sonar.scanner.bootstrap.GlobalAnalysisMode;
+import org.sonar.scanner.bootstrap.GlobalConfiguration;
import org.sonar.scanner.repository.settings.SettingsLoader;
public class ProjectSettingsProvider extends ProviderAdapter {
Map<String, String> settings = new LinkedHashMap<>();
settings.putAll(globalSettings.getProperties());
- settings.putAll(loadProjectSettings(settingsLoader, reactor.getRoot().getKeyWithBranch()));
+ settings.putAll(settingsLoader.load(reactor.getRoot().getKeyWithBranch()));
settings.putAll(reactor.getRoot().properties());
projectSettings = new ProjectSettings(globalSettings.getDefinitions(), globalSettings.getEncryption(), mode, settings);
}
return projectSettings;
}
-
- private Map<String, String> loadProjectSettings(SettingsLoader settingsLoader, String projectKey) {
- return settingsLoader.load(projectKey);
- }
}
package org.sonar.scanner.analysis;
import java.util.Collections;
+import java.util.Date;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
+import org.sonar.api.utils.MessageException;
import org.sonar.scanner.bootstrap.GlobalAnalysisMode;
import org.sonar.scanner.repository.ProjectRepositories;
import org.sonar.scanner.scan.branch.BranchConfiguration;
private BranchConfiguration branchConfig;
private ProjectRepositories projectRepos;
private GlobalAnalysisMode globalMode;
- private ValidateIncremental validateIncremental;
+ private IncrementalScannerHandler validateIncremental;
@Before
public void setUp() {
branchConfig = mock(BranchConfiguration.class);
projectRepos = mock(ProjectRepositories.class);
globalMode = mock(GlobalAnalysisMode.class);
- validateIncremental = mock(ValidateIncremental.class);
+ validateIncremental = mock(IncrementalScannerHandler.class);
}
@Rule
assertThat(mode.isPreview()).isTrue();
}
+ @Test
+ public void incremental_not_found() {
+ AnalysisProperties analysisProps = new AnalysisProperties(Collections.singletonMap("sonar.incremental", "true"));
+ thrown.expect(MessageException.class);
+ thrown.expectMessage("Incremental mode is not available. Please contact your administrator.");
+ createmode(analysisProps);
+ }
+
+ @Test
+ public void no_incremental_if_not_publish() {
+ when(validateIncremental.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");
+ createmode(analysisProps);
+ }
+
+ @Test
+ public void no_incremental_mode_if_branches() {
+ when(globalMode.isPublish()).thenReturn(true);
+ when(validateIncremental.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();
+ }
+
+ @Test
+ public void no_incremental_mode_if_no_previous_analysis() {
+ when(validateIncremental.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();
+ }
+
+ @Test
+ public void incremental_mode() {
+ when(validateIncremental.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();
+ }
+
@Test
public void scan_all_if_publish() {
when(globalMode.isIssues()).thenReturn(false);
*/
package org.sonar.scanner.mediumtest.tasks;
-import static org.assertj.core.api.Assertions.assertThat;
-
-import java.io.File;
+import com.google.common.collect.ImmutableMap;
import java.util.Arrays;
import java.util.List;
-
import org.assertj.core.api.Condition;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
-import org.junit.rules.TemporaryFolder;
import org.sonar.api.SonarPlugin;
import org.sonar.api.task.Task;
import org.sonar.api.task.TaskDefinition;
import org.sonar.api.utils.log.LogTester;
import org.sonar.scanner.mediumtest.ScannerMediumTester;
-import com.google.common.collect.ImmutableMap;
+import static org.assertj.core.api.Assertions.assertThat;
public class TasksMediumTest {
@Rule
public LogTester logTester = new LogTester();
- @Rule
- public TemporaryFolder temp = new TemporaryFolder();
-
@Rule
public ScannerMediumTester tester = new ScannerMediumTester()
.registerPlugin("faketask", new FakeTaskPlugin());
.execute();
}
- @Test
- public void incrementalNotFound() throws Exception {
- File baseDir = temp.newFolder();
- thrown.expect(MessageException.class);
- thrown.expectMessage(
- "Incremental mode is not available. Please contact your administrator.");
-
- tester.newTask()
- .properties(ImmutableMap.<String, String>builder()
- .put("sonar.projectKey", "key")
- .put("sonar.projectBaseDir", baseDir.getAbsolutePath())
- .put("sonar.sources", ".")
- .put("sonar.incremental", "true").build())
- .execute();
- }
-
private static class FakeTaskPlugin extends SonarPlugin {
@Override