SONAR-6861 Drop the property "sonar.preventAutoProjectCreation"

This commit is contained in:
Simon Brandhof 2015-09-18 00:14:11 +02:00
parent 72a1503168
commit b7e73ea7bd
9 changed files with 43 additions and 73 deletions

View File

@ -21,6 +21,7 @@ import org.sonar.wsclient.SonarClient;
import org.sonar.wsclient.project.NewProject;
import org.sonar.wsclient.services.PropertyUpdateQuery;
@Ignore
public class ProjectProvisioningTest {
@ClassRule

View File

@ -28,7 +28,6 @@ import java.util.Date;
import java.util.List;
import java.util.Map;
import javax.annotation.CheckForNull;
import org.sonar.api.CoreProperties;
import org.sonar.api.config.Settings;
import org.sonar.api.utils.MessageException;
import org.sonar.batch.protocol.output.BatchReport;
@ -52,7 +51,6 @@ import static org.sonar.db.component.ComponentDtoFunctions.toKey;
/**
* Validate project and modules. It will fail in the following cases :
* <ol>
* <li>property {@link org.sonar.api.CoreProperties#CORE_PREVENT_AUTOMATIC_PROJECT_CREATION} is set to true and project does not exists</li>
* <li>branch is not valid</li>
* <li>project or module key is not valid</li>
* <li>module key already exists in another project (same module key cannot exists in different projects)</li>
@ -83,7 +81,7 @@ public class ValidateProjectStep implements ComputationStep {
List<ComponentDto> baseModules = dbClient.componentDao().selectEnabledModulesFromProjectKey(session, treeRootHolder.getRoot().getKey());
Map<String, ComponentDto> baseModulesByKey = FluentIterable.from(baseModules).uniqueIndex(toKey());
ValidateProjectsVisitor visitor = new ValidateProjectsVisitor(session, dbClient.componentDao(),
settings.getBoolean(CoreProperties.CORE_PREVENT_AUTOMATIC_PROJECT_CREATION), baseModulesByKey);
baseModulesByKey);
new DepthTraversalTypeAwareCrawler(visitor).visit(treeRootHolder.getRoot());
if (!visitor.validationMessages.isEmpty()) {
@ -102,18 +100,16 @@ public class ValidateProjectStep implements ComputationStep {
private class ValidateProjectsVisitor extends TypeAwareVisitorAdapter {
private final DbSession session;
private final ComponentDao componentDao;
private final boolean preventAutomaticProjectCreation;
private final Map<String, ComponentDto> baseModulesByKey;
private final List<String> validationMessages = new ArrayList<>();
private Component rawProject;
public ValidateProjectsVisitor(DbSession session, ComponentDao componentDao, boolean preventAutomaticProjectCreation, Map<String, ComponentDto> baseModulesByKey) {
public ValidateProjectsVisitor(DbSession session, ComponentDao componentDao, Map<String, ComponentDto> baseModulesByKey) {
super(CrawlerDepthLimit.MODULE, ComponentVisitor.Order.PRE_ORDER);
this.session = session;
this.componentDao = componentDao;
this.preventAutomaticProjectCreation = preventAutomaticProjectCreation;
this.baseModulesByKey = baseModulesByKey;
}
@ -125,17 +121,10 @@ public class ValidateProjectStep implements ComputationStep {
String rawProjectKey = rawProject.getKey();
Optional<ComponentDto> baseProject = loadBaseComponent(rawProjectKey);
validateWhenProvisioningEnforced(baseProject, rawProjectKey);
validateProjectKey(baseProject, rawProjectKey);
validateAnalysisDate(baseProject);
}
private void validateWhenProvisioningEnforced(Optional<ComponentDto> baseProject, String rawProjectKey) {
if (!baseProject.isPresent() && preventAutomaticProjectCreation) {
validationMessages.add(String.format("Unable to scan non-existing project '%s'", rawProjectKey));
}
}
private void validateProjectKey(Optional<ComponentDto> baseProject, String rawProjectKey) {
if (baseProject.isPresent() && !baseProject.get().projectUuid().equals(baseProject.get().uuid())) {
// Project key is already used as a module of another project

View File

@ -25,7 +25,6 @@ import org.junit.Rule;
import org.junit.Test;
import org.junit.experimental.categories.Category;
import org.junit.rules.ExpectedException;
import org.sonar.api.CoreProperties;
import org.sonar.api.config.Settings;
import org.sonar.api.utils.MessageException;
import org.sonar.api.utils.System2;
@ -75,56 +74,6 @@ public class ValidateProjectStepTest {
underTest = new ValidateProjectStep(dbClient, settings, reportReader, treeRootHolder);
}
@Test
public void not_fail_if_provisioning_enforced_and_project_exists() {
reportReader.setMetadata(BatchReport.Metadata.newBuilder().setAnalysisDate(DEFAULT_ANALYSIS_TIME).build());
reportReader.putComponent(BatchReport.Component.newBuilder()
.setRef(1)
.setType(Constants.ComponentType.PROJECT)
.setKey(PROJECT_KEY)
.build());
settings.appendProperty(CoreProperties.CORE_PREVENT_AUTOMATIC_PROJECT_CREATION, "true");
dbClient.componentDao().insert(dbTester.getSession(), ComponentTesting.newProjectDto("ABCD").setKey(PROJECT_KEY));
dbTester.getSession().commit();
treeRootHolder.setRoot(ReportComponent.builder(Component.Type.PROJECT, 1).setUuid("ABCD").setKey(PROJECT_KEY).build());
underTest.execute();
}
@Test
public void fail_if_provisioning_enforced_and_project_does_not_exists() {
thrown.expect(MessageException.class);
thrown.expectMessage("Unable to scan non-existing project '" + PROJECT_KEY + "'");
reportReader.setMetadata(BatchReport.Metadata.newBuilder().setAnalysisDate(DEFAULT_ANALYSIS_TIME).build());
reportReader.putComponent(BatchReport.Component.newBuilder()
.setRef(1)
.setType(Constants.ComponentType.PROJECT)
.setKey(PROJECT_KEY)
.build());
settings.appendProperty(CoreProperties.CORE_PREVENT_AUTOMATIC_PROJECT_CREATION, "true");
treeRootHolder.setRoot(ReportComponent.builder(Component.Type.PROJECT, 1).setUuid("ABCD").setKey(PROJECT_KEY).build());
underTest.execute();
}
@Test
public void fail_if_provisioning_not_enforced_and_project_does_not_exists() {
reportReader.setMetadata(BatchReport.Metadata.newBuilder().setAnalysisDate(DEFAULT_ANALYSIS_TIME).build());
reportReader.putComponent(BatchReport.Component.newBuilder()
.setRef(1)
.setType(Constants.ComponentType.PROJECT)
.setKey(PROJECT_KEY)
.build());
settings.appendProperty(CoreProperties.CORE_PREVENT_AUTOMATIC_PROJECT_CREATION, "false");
treeRootHolder.setRoot(ReportComponent.builder(Component.Type.PROJECT, 1).setUuid("ABCD").setKey(PROJECT_KEY).build());
underTest.execute();
}
@Test
public void not_fail_on_valid_branch() {
reportReader.setMetadata(BatchReport.Metadata.newBuilder()

View File

@ -28,6 +28,7 @@
class AddProvisioningPermissionToScan < ActiveRecord::Migration
class Property < ActiveRecord::Base
set_table_name 'properties'
end
class GroupRole < ActiveRecord::Base

View File

@ -0,0 +1,35 @@
#
# SonarQube, open source software quality management tool.
# Copyright (C) 2008-2014 SonarSource
# mailto:contact AT sonarsource DOT com
#
# SonarQube 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.
#
# SonarQube 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.
#
#
# SonarQube 5.2
# SONAR-6861
#
class DeletePropertyPreventAutoProjectCreation < ActiveRecord::Migration
class Property < ActiveRecord::Base
set_table_name 'properties'
end
def self.up
Property.delete_all(['prop_key=?', 'sonar.preventAutoProjectCreation'])
end
end

View File

@ -55,14 +55,6 @@ class SecurityProperties {
.description("Forcing user authentication stops un-logged users to access SonarQube.")
.type(PropertyType.BOOLEAN)
.category(CoreProperties.CATEGORY_SECURITY)
.build(),
PropertyDefinition.builder(CoreProperties.CORE_PREVENT_AUTOMATIC_PROJECT_CREATION)
.defaultValue(Boolean.toString(false))
.name("Prevent automatic project creation")
.description("Set to true to prevent automatic project creation at first analysis and force project provisioning.")
.type(PropertyType.BOOLEAN)
.category(CoreProperties.CATEGORY_SECURITY)
.build()
);

View File

@ -29,7 +29,7 @@ import org.sonar.db.MyBatis;
public class DatabaseVersion {
public static final int LAST_VERSION = 935;
public static final int LAST_VERSION = 936;
/**
* The minimum supported version which can be upgraded. Lower

View File

@ -354,6 +354,7 @@ INSERT INTO SCHEMA_MIGRATIONS(VERSION) VALUES ('932');
INSERT INTO SCHEMA_MIGRATIONS(VERSION) VALUES ('933');
INSERT INTO SCHEMA_MIGRATIONS(VERSION) VALUES ('934');
INSERT INTO SCHEMA_MIGRATIONS(VERSION) VALUES ('935');
INSERT INTO SCHEMA_MIGRATIONS(VERSION) VALUES ('936');
INSERT INTO USERS(ID, LOGIN, NAME, EMAIL, CRYPTED_PASSWORD, SALT, CREATED_AT, UPDATED_AT, REMEMBER_TOKEN, REMEMBER_TOKEN_EXPIRES_AT) VALUES (1, 'admin', 'Administrator', '', 'a373a0e667abb2604c1fd571eb4ad47fe8cc0878', '48bc4b0d93179b5103fd3885ea9119498e9d161b', '1418215735482', '1418215735482', null, null);
ALTER TABLE USERS ALTER COLUMN ID RESTART WITH 2;

View File

@ -421,7 +421,9 @@ public interface CoreProperties {
/**
* @since 4.0
* @deprecated replaced in 5.2 by the permission 'provisioning'
*/
@Deprecated
String CORE_PREVENT_AUTOMATIC_PROJECT_CREATION = "sonar.preventAutoProjectCreation";
/**