package it;
import com.sonar.orchestrator.Orchestrator;
-import it.analysis.*;
+import it.analysis.BatchTest;
+import it.analysis.ExtensionLifecycleTest;
+import it.analysis.IssueJsonReportTest;
+import it.analysis.IssuesModeTest;
+import it.analysis.LinksTest;
+import it.analysis.MavenTest;
+import it.analysis.MultiLanguageTest;
+import it.analysis.ProjectBuilderTest;
+import it.analysis.ProjectProvisioningTest;
+import it.analysis.ReportDumpTest;
+import it.analysis.SettingsEncryptionTest;
+import it.analysis.TempFolderTest;
import it.measure.DecimalScaleMetricTest;
import org.junit.ClassRule;
import org.junit.runner.RunWith;
LinksTest.class,
MavenTest.class,
ProjectBuilderTest.class,
- ProjectExclusionsTest.class,
TempFolderTest.class,
MultiLanguageTest.class,
IssueJsonReportTest.class,
package it.analysis;
import com.sonar.orchestrator.Orchestrator;
-import com.sonar.orchestrator.build.BuildFailureException;
import com.sonar.orchestrator.build.BuildResult;
import com.sonar.orchestrator.build.SonarRunner;
import com.sonar.orchestrator.locator.FileLocation;
import it.Category3Suite;
+import java.io.File;
+import java.io.IOException;
+import java.util.Date;
import org.apache.commons.io.FileUtils;
-import org.junit.*;
+import org.junit.Assume;
+import org.junit.Before;
+import org.junit.ClassRule;
+import org.junit.Ignore;
+import org.junit.Rule;
+import org.junit.Test;
import org.junit.experimental.categories.Category;
import org.junit.rules.ExpectedException;
import org.junit.rules.TemporaryFolder;
import org.sonar.wsclient.services.Resource;
import org.sonar.wsclient.services.ResourceQuery;
import util.ItUtils;
-
-import java.io.File;
-import java.io.IOException;
-import java.util.Date;
import util.QaOnly;
import static org.assertj.core.api.Assertions.assertThat;
assertThat(r.getMeasureIntValue("violations")).isEqualTo(61);
}
- /**
- * SONAR-2907
- */
- @Test
- public void branch_should_load_own_settings_from_database() {
- orchestrator.getServer().provisionProject("com.sonarsource.it.samples:multi-modules-sample", "Sonar :: Integration Tests :: Multi-modules Sample");
- orchestrator.getServer().associateProjectToQualityProfile("com.sonarsource.it.samples:multi-modules-sample", "xoo", "one-issue-per-line");
- scan("shared/xoo-multi-modules-sample");
- assertThat(getResource("com.sonarsource.it.samples:multi-modules-sample:module_b")).isNotNull();
-
- Sonar sonar = orchestrator.getServer().getAdminWsClient();
- // The parameter skippedModule considers key after first colon
- sonar.update(new PropertyUpdateQuery("sonar.skippedModules", "multi-modules-sample:module_b",
- "com.sonarsource.it.samples:multi-modules-sample"));
-
- try {
- scan("shared/xoo-multi-modules-sample");
- assertThat(getResource("com.sonarsource.it.samples:multi-modules-sample:module_b")).isNull();
-
- scan("shared/xoo-multi-modules-sample",
- "sonar.branch", "mybranch");
-
- assertThat(getResource("com.sonarsource.it.samples:multi-modules-sample:module_b:mybranch")).isNotNull();
- } finally {
- sonar.delete(new PropertyDeleteQuery("sonar.skippedModules", "com.sonarsource.it.samples:multi-modules-sample"));
- }
- }
-
// SONAR-4680
@Test
public void module_should_load_own_settings_from_database() {
assertThat(result.getLogs()).contains(moduleBKey + ":" + propKey + " = project");
}
- /**
- * SONAR-3116
- */
- @Test
- @Category(QaOnly.class)
- public void should_not_exclude_root_module() {
- orchestrator.getServer().provisionProject("com.sonarsource.it.samples:multi-modules-sample", "Sonar :: Integration Tests :: Multi-modules Sample");
- orchestrator.getServer().associateProjectToQualityProfile("com.sonarsource.it.samples:multi-modules-sample", "xoo", "one-issue-per-line");
-
- thrown.expect(BuildFailureException.class);
- scan("shared/xoo-multi-modules-sample",
- "sonar.skippedModules", "multi-modules-sample");
- }
-
/**
* SONAR-3024
*/
File cache = new File(userHome, "cache");
assertThat(cache).exists().isDirectory();
- int cachedFiles = FileUtils.listFiles(cache, new String[]{"jar"}, true).size();
+ int cachedFiles = FileUtils.listFiles(cache, new String[] {"jar"}, true).size();
assertThat(cachedFiles).isGreaterThan(5);
assertThat(result.getLogs()).contains("User cache: " + cache.getAbsolutePath());
assertThat(result.getLogs()).contains("Download sonar-xoo-plugin-");
+++ /dev/null
-/*
- * SonarQube
- * Copyright (C) 2009-2016 SonarSource SA
- * mailto:contact 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 it.analysis;
-
-import com.sonar.orchestrator.Orchestrator;
-import com.sonar.orchestrator.build.MavenBuild;
-import it.Category3Suite;
-import org.junit.Before;
-import org.junit.ClassRule;
-import org.junit.Test;
-import org.junit.experimental.categories.Category;
-import org.sonar.wsclient.services.Resource;
-import org.sonar.wsclient.services.ResourceQuery;
-import util.ItUtils;
-import util.QaOnly;
-
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertNull;
-
-@Category(QaOnly.class)
-public class ProjectExclusionsTest {
- @ClassRule
- public static Orchestrator orchestrator = Category3Suite.ORCHESTRATOR;
-
- @Before
- public void deleteProjectData() {
- orchestrator.resetData();
- }
-
- /**
- * This use-case was a bug in 2.8-RC2. It failed when both the properties sonar.branch and sonar.skippedModules
- * were set on the same multi-modules project.
- */
- @Test
- public void shouldSupportMixOfBranchAndSkippedModules() {
- MavenBuild build = MavenBuild.create(ItUtils.projectPom("shared/multi-modules-sample"))
- .setGoals("clean verify", "sonar:sonar")
- .setProperty("sonar.dynamicAnalysis", "false")
- .setProperty("sonar.branch", "mybranch")
- .setProperty("sonar.skippedModules", "module_b");
-
- orchestrator.executeBuild(build);
-
- assertNotNull(getResource("com.sonarsource.it.samples:multi-modules-sample:mybranch"));
- assertNotNull(getResource("com.sonarsource.it.samples:module_a:mybranch").getId());
- assertNotNull(getResource("com.sonarsource.it.samples:module_a1:mybranch").getId());
- assertNotNull(getResource("com.sonarsource.it.samples:module_a2:mybranch").getId());
-
- assertNull(getResource("com.sonarsource.it.samples:module_b:mybranch"));
- assertNull(getResource("com.sonarsource.it.samples:module_b1:mybranch"));
- assertNull(getResource("com.sonarsource.it.samples:module_b2:mybranch"));
- }
-
- /**
- * Black list
- */
- @Test
- public void shouldExcludeModuleAndItsChildren() {
- MavenBuild build = MavenBuild.create(ItUtils.projectPom("shared/multi-modules-sample"))
- .setGoals("clean verify", "sonar:sonar")
- .setProperty("sonar.dynamicAnalysis", "false")
- .setProperty("sonar.skippedModules", "module_b");
-
- orchestrator.executeBuild(build);
-
- assertNotNull(getResource("com.sonarsource.it.samples:multi-modules-sample"));
- assertNotNull(getResource("com.sonarsource.it.samples:module_a"));
- assertNotNull(getResource("com.sonarsource.it.samples:module_a1"));
- assertNotNull(getResource("com.sonarsource.it.samples:module_a2"));
-
- // excluded project and its children
- assertNull(getResource("com.sonarsource.it.samples:module_b"));
- assertNull(getResource("com.sonarsource.it.samples:module_b1"));
- assertNull(getResource("com.sonarsource.it.samples:module_b2"));
- }
-
- /**
- * Exhaustive white list
- */
- @Test
- public void shouldIncludeModules() {
- MavenBuild build = MavenBuild.create(ItUtils.projectPom("shared/multi-modules-sample"))
- .setGoals("clean verify", "sonar:sonar")
- .setProperty("sonar.dynamicAnalysis", "false")
- .setProperty("sonar.includedModules", "multi-modules-sample,module_a,module_a1");
-
- orchestrator.executeBuild(build);
-
- assertNotNull(getResource("com.sonarsource.it.samples:multi-modules-sample"));
- assertNotNull(getResource("com.sonarsource.it.samples:module_a"));
- assertNotNull(getResource("com.sonarsource.it.samples:module_a1"));
-
- assertNull(getResource("com.sonarsource.it.samples:module_a2"));
- assertNull(getResource("com.sonarsource.it.samples:module_b"));
- assertNull(getResource("com.sonarsource.it.samples:module_b1"));
- assertNull(getResource("com.sonarsource.it.samples:module_b2"));
- }
-
- @Test
- public void rootModuleShouldBeOptionalInListOfIncludedModules() {
- MavenBuild build = MavenBuild.create(ItUtils.projectPom("shared/multi-modules-sample"))
- .setCleanSonarGoals()
- .setProperty("sonar.dynamicAnalysis", "false")
- // the root module 'multi-modules-sample' is not declared
- .setProperty("sonar.includedModules", "module_a,module_a1");
-
- orchestrator.executeBuild(build);
-
- assertNotNull(getResource("com.sonarsource.it.samples:multi-modules-sample"));
- assertNotNull(getResource("com.sonarsource.it.samples:module_a"));
- assertNotNull(getResource("com.sonarsource.it.samples:module_a1"));
-
- assertNull(getResource("com.sonarsource.it.samples:module_a2"));
- assertNull(getResource("com.sonarsource.it.samples:module_b"));
- assertNull(getResource("com.sonarsource.it.samples:module_b1"));
- assertNull(getResource("com.sonarsource.it.samples:module_b2"));
- }
-
- private Resource getResource(String key) {
- return orchestrator.getServer().getWsClient().find(ResourceQuery.create(key));
- }
-}
.index(1)
.build(),
- PropertyDefinition.builder(CoreProperties.CORE_SKIPPED_MODULES_PROPERTY)
- .name("Exclude Modules")
- .description("Maven artifact ids of modules to exclude.")
- .multiValues(true)
- .category(CoreProperties.CATEGORY_EXCLUSIONS)
- .subCategory(CoreProperties.SUBCATEGORY_FILES_EXCLUSIONS)
- .onlyOnQualifiers(Qualifiers.PROJECT)
- .index(0)
- .build(),
- PropertyDefinition.builder(CoreProperties.CORE_INCLUDED_MODULES_PROPERTY)
- .name("Include Modules")
- .description("Maven artifact ids of modules to include.")
- .multiValues(true)
- .category(CoreProperties.CATEGORY_EXCLUSIONS)
- .subCategory(CoreProperties.SUBCATEGORY_FILES_EXCLUSIONS)
- .onlyOnQualifiers(Qualifiers.PROJECT)
- .index(1)
- .build(),
PropertyDefinition.builder(CoreProperties.PROJECT_EXCLUSIONS_PROPERTY)
.name("Source File Exclusions")
.multiValues(true)
.category(CoreProperties.CATEGORY_EXCLUSIONS)
.subCategory(CoreProperties.SUBCATEGORY_FILES_EXCLUSIONS)
.onQualifiers(Qualifiers.PROJECT)
- .index(2)
+ .index(0)
.build(),
PropertyDefinition.builder(CoreProperties.PROJECT_INCLUSIONS_PROPERTY)
.category(CoreProperties.CATEGORY_EXCLUSIONS)
.subCategory(CoreProperties.SUBCATEGORY_FILES_EXCLUSIONS)
.onQualifiers(Qualifiers.PROJECT)
- .index(3)
+ .index(1)
.build(),
PropertyDefinition.builder(CoreProperties.PROJECT_TEST_EXCLUSIONS_PROPERTY)
.name("Test File Exclusions")
.category(CoreProperties.CATEGORY_EXCLUSIONS)
.subCategory(CoreProperties.SUBCATEGORY_FILES_EXCLUSIONS)
.onQualifiers(Qualifiers.PROJECT)
- .index(4)
+ .index(2)
.build(),
PropertyDefinition.builder(CoreProperties.PROJECT_TEST_INCLUSIONS_PROPERTY)
.name("Test File Inclusions")
.category(CoreProperties.CATEGORY_EXCLUSIONS)
.subCategory(CoreProperties.SUBCATEGORY_FILES_EXCLUSIONS)
.onQualifiers(Qualifiers.PROJECT)
- .index(5)
+ .index(3)
.build()
- );
+ );
}
}
String CORE_VIOLATION_LOCALE_DEFAULT_VALUE = "en";
- /**
- * @deprecated since 4.3. See http://jira.sonarsource.com/browse/SONAR-5109
- */
- @Deprecated
- String CORE_SKIPPED_MODULES_PROPERTY = "sonar.skippedModules";
-
- /**
- * @since 4.0
- * @deprecated since 4.3. See http://jira.sonarsource.com/browse/SONAR-5109
- */
- @Deprecated
- String CORE_INCLUDED_MODULES_PROPERTY = "sonar.includedModules";
-
String CORE_FORCE_AUTHENTICATION_PROPERTY = "sonar.forceAuthentication";
boolean CORE_FORCE_AUTHENTICATION_DEFAULT_VALUE = false;
String CORE_ALLOW_USERS_TO_SIGNUP_PROPERTY = "sonar.allowUsersToSignUp";
private ImmutableProjectReactor singleton;
- public ImmutableProjectReactor provide(ProjectReactor reactor, ProjectBuildersExecutor projectBuildersExecutor, ProjectExclusions exclusions, ProjectReactorValidator validator) {
+ public ImmutableProjectReactor provide(ProjectReactor reactor, ProjectBuildersExecutor projectBuildersExecutor, ProjectReactorValidator validator) {
if (singleton == null) {
// 1 Apply project builders
projectBuildersExecutor.execute(reactor);
- // 2 Apply project exclusions
- exclusions.apply(reactor);
-
- // 3 Validate final reactor
+ // 2 Validate final reactor
validator.validate(reactor);
singleton = new ImmutableProjectReactor(reactor.getRoot());
+++ /dev/null
-/*
- * SonarQube
- * Copyright (C) 2009-2016 SonarSource SA
- * mailto:contact 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.batch.scan;
-
-import org.apache.commons.lang.ArrayUtils;
-import org.apache.commons.lang.StringUtils;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import org.sonar.api.CoreProperties;
-import org.sonar.api.batch.bootstrap.ProjectDefinition;
-import org.sonar.api.batch.bootstrap.ProjectReactor;
-import org.sonar.api.config.Settings;
-
-/**
- * Exclude the sub-projects as defined by the properties sonar.skippedModules and sonar.includedModules
- *
- * @since 2.12
- */
-public class ProjectExclusions {
-
- private static final Logger LOG = LoggerFactory.getLogger(ProjectExclusions.class);
-
- private Settings settings;
-
- public ProjectExclusions(Settings settings) {
- this.settings = settings;
- }
-
- public void apply(ProjectReactor reactor) {
- if (!reactor.getProjects().isEmpty() && StringUtils.isNotBlank(reactor.getProjects().get(0).getKey())) {
- LOG.info("Apply project exclusions");
-
- if (settings.hasKey(CoreProperties.CORE_INCLUDED_MODULES_PROPERTY)) {
- LOG.warn("'sonar.includedModules' property is deprecated since version 4.3 and should not be used anymore.");
- }
- if (settings.hasKey(CoreProperties.CORE_SKIPPED_MODULES_PROPERTY)) {
- LOG.warn("'sonar.skippedModules' property is deprecated since version 4.3 and should not be used anymore.");
- }
-
- for (ProjectDefinition project : reactor.getProjects()) {
- if (isExcluded(key(project), project == reactor.getRoot())) {
- exclude(project);
- }
- }
- }
- }
-
- private boolean isExcluded(String projectKey, boolean isRoot) {
- String[] includedKeys = settings.getStringArray(CoreProperties.CORE_INCLUDED_MODULES_PROPERTY);
- boolean excluded = false;
- if (!isRoot && includedKeys.length > 0) {
- excluded = !ArrayUtils.contains(includedKeys, projectKey);
- }
- String skippedModulesProperty = CoreProperties.CORE_SKIPPED_MODULES_PROPERTY;
- if (!excluded) {
- String[] excludedKeys = settings.getStringArray(skippedModulesProperty);
- excluded = ArrayUtils.contains(excludedKeys, projectKey);
- }
- if (excluded && isRoot) {
- throw new IllegalArgumentException("The root project can't be excluded. Please check the parameters " + skippedModulesProperty + " and sonar.includedModules.");
- }
- return excluded;
- }
-
- private void exclude(ProjectDefinition project) {
- LOG.info(String.format("Exclude project: %s [%s]", project.getName(), project.getKey()));
- project.remove();
- }
-
- static String key(ProjectDefinition project) {
- String key = project.getKey();
- if (key.contains(":")) {
- return StringUtils.substringAfter(key, ":");
- }
- return key;
- }
-}
PhasesTimeProfiler.class,
ResourceTypes.class,
DefaultProjectTree.class,
- ProjectExclusions.class,
ProjectReactorValidator.class,
new AnalysisWSLoaderProvider(),
CodeColorizers.class,
+++ /dev/null
-/*
- * SonarQube
- * Copyright (C) 2009-2016 SonarSource SA
- * mailto:contact 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.batch.scan;
-
-import org.junit.Test;
-import org.sonar.api.batch.bootstrap.ProjectDefinition;
-import org.sonar.api.batch.bootstrap.ProjectReactor;
-import org.sonar.api.config.Settings;
-
-import static org.assertj.core.api.Assertions.assertThat;
-
-public class ProjectExclusionsTest {
-
- ProjectReactor newReactor(String rootKey, String... moduleKeys) {
- ProjectDefinition root = ProjectDefinition.create().setKey(rootKey);
- for (String moduleKey : moduleKeys) {
- ProjectDefinition module = ProjectDefinition.create().setKey(moduleKey);
- root.addSubProject(module);
- }
- return new ProjectReactor(root);
- }
-
- @Test
- public void testSkippedModules() {
- Settings settings = new Settings();
- settings.setProperty("sonar.skippedModules", "sub1,sub3");
-
- ProjectReactor reactor = newReactor("root", "sub1", "sub2");
-
- ProjectExclusions exclusions = new ProjectExclusions(settings);
- exclusions.apply(reactor);
-
- assertThat(reactor.getProject("root")).isNotNull();
- assertThat(reactor.getProject("sub1")).isNull();
- assertThat(reactor.getProject("sub2")).isNotNull();
- }
-
- @Test
- public void testNoSkippedModules() {
- Settings settings = new Settings();
- ProjectReactor reactor = newReactor("root", "sub1", "sub2");
- ProjectExclusions exclusions = new ProjectExclusions(settings);
- exclusions.apply(reactor);
-
- assertThat(reactor.getProject("root")).isNotNull();
- assertThat(reactor.getProject("sub1")).isNotNull();
- assertThat(reactor.getProject("sub2")).isNotNull();
- }
-
- @Test
- public void testIncludedModules() {
- Settings settings = new Settings();
- settings.setProperty("sonar.includedModules", "sub1");
- ProjectReactor reactor = newReactor("root", "sub1", "sub2");
- ProjectExclusions exclusions = new ProjectExclusions(settings);
- exclusions.apply(reactor);
-
- assertThat(reactor.getProject("root")).isNotNull();
- assertThat(reactor.getProject("sub1")).isNotNull();
- assertThat(reactor.getProject("sub2")).isNull();
- }
-
- @Test
- public void shouldBeExcludedIfParentIsExcluded() {
- ProjectDefinition sub11 = ProjectDefinition.create().setKey("sub11");
- ProjectDefinition sub1 = ProjectDefinition.create().setKey("sub1").addSubProject(sub11);
- ProjectDefinition root = ProjectDefinition.create().setKey("root").addSubProject(sub1);
-
- Settings settings = new Settings();
- settings.setProperty("sonar.skippedModules", "sub1");
-
- ProjectReactor reactor = new ProjectReactor(root);
- ProjectExclusions exclusions = new ProjectExclusions(settings);
- exclusions.apply(reactor);
-
- assertThat(reactor.getProject("root")).isNotNull();
- assertThat(reactor.getProject("sub1")).isNull();
- assertThat(reactor.getProject("sub11")).isNull();
- }
-
- @Test(expected = IllegalArgumentException.class)
- public void shouldFailIfExcludingRoot() {
- Settings settings = new Settings();
- settings.setProperty("sonar.skippedModules", "sub1,root");
-
- ProjectReactor reactor = newReactor("root", "sub1", "sub2");
- ProjectExclusions exclusions = new ProjectExclusions(settings);
- exclusions.apply(reactor);
- }
-
- @Test
- public void shouldIgnoreMavenGroupId() {
- ProjectReactor reactor = newReactor("org.apache.struts:struts", "org.apache.struts:struts-core", "org.apache.struts:struts-taglib");
-
- Settings settings = new Settings();
- settings.setProperty("sonar.skippedModules", "struts-taglib");
-
- ProjectExclusions exclusions = new ProjectExclusions(settings);
- exclusions.apply(reactor);
-
- assertThat(reactor.getProject("org.apache.struts:struts")).isNotNull();
- assertThat(reactor.getProject("org.apache.struts:struts-core")).isNotNull();
- assertThat(reactor.getProject("org.apache.struts:struts-taglib")).isNull();
- }
-}