From b7e73ea7bd925ade9625a97c1a1419c1cee6ccd6 Mon Sep 17 00:00:00 2001 From: Simon Brandhof Date: Fri, 18 Sep 2015 00:14:11 +0200 Subject: [PATCH] SONAR-6861 Drop the property "sonar.preventAutoProjectCreation" --- .../batch/suite/ProjectProvisioningTest.java | 1 + .../computation/step/ValidateProjectStep.java | 15 +----- .../step/ValidateProjectStepTest.java | 51 ------------------- ...935_add_provisioning_permission_to_scan.rb | 1 + ..._property_prevent_auto_project_creation.rb | 35 +++++++++++++ .../sonar/core/config/SecurityProperties.java | 8 --- .../org/sonar/db/version/DatabaseVersion.java | 2 +- .../org/sonar/db/version/rows-h2.sql | 1 + .../java/org/sonar/api/CoreProperties.java | 2 + 9 files changed, 43 insertions(+), 73 deletions(-) create mode 100644 server/sonar-web/src/main/webapp/WEB-INF/db/migrate/936_delete_property_prevent_auto_project_creation.rb diff --git a/it/it-tests/src/test/java/batch/suite/ProjectProvisioningTest.java b/it/it-tests/src/test/java/batch/suite/ProjectProvisioningTest.java index e4212590134..b928e4939db 100644 --- a/it/it-tests/src/test/java/batch/suite/ProjectProvisioningTest.java +++ b/it/it-tests/src/test/java/batch/suite/ProjectProvisioningTest.java @@ -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 diff --git a/server/sonar-server/src/main/java/org/sonar/server/computation/step/ValidateProjectStep.java b/server/sonar-server/src/main/java/org/sonar/server/computation/step/ValidateProjectStep.java index a6eeea2e770..5e06c59522e 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/computation/step/ValidateProjectStep.java +++ b/server/sonar-server/src/main/java/org/sonar/server/computation/step/ValidateProjectStep.java @@ -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 : *
    - *
  1. property {@link org.sonar.api.CoreProperties#CORE_PREVENT_AUTOMATIC_PROJECT_CREATION} is set to true and project does not exists
  2. *
  3. branch is not valid
  4. *
  5. project or module key is not valid
  6. *
  7. module key already exists in another project (same module key cannot exists in different projects)
  8. @@ -83,7 +81,7 @@ public class ValidateProjectStep implements ComputationStep { List baseModules = dbClient.componentDao().selectEnabledModulesFromProjectKey(session, treeRootHolder.getRoot().getKey()); Map 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 baseModulesByKey; private final List validationMessages = new ArrayList<>(); private Component rawProject; - public ValidateProjectsVisitor(DbSession session, ComponentDao componentDao, boolean preventAutomaticProjectCreation, Map baseModulesByKey) { + public ValidateProjectsVisitor(DbSession session, ComponentDao componentDao, Map 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 baseProject = loadBaseComponent(rawProjectKey); - validateWhenProvisioningEnforced(baseProject, rawProjectKey); validateProjectKey(baseProject, rawProjectKey); validateAnalysisDate(baseProject); } - private void validateWhenProvisioningEnforced(Optional baseProject, String rawProjectKey) { - if (!baseProject.isPresent() && preventAutomaticProjectCreation) { - validationMessages.add(String.format("Unable to scan non-existing project '%s'", rawProjectKey)); - } - } - private void validateProjectKey(Optional baseProject, String rawProjectKey) { if (baseProject.isPresent() && !baseProject.get().projectUuid().equals(baseProject.get().uuid())) { // Project key is already used as a module of another project diff --git a/server/sonar-server/src/test/java/org/sonar/server/computation/step/ValidateProjectStepTest.java b/server/sonar-server/src/test/java/org/sonar/server/computation/step/ValidateProjectStepTest.java index 379d7046e67..512e5a9819b 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/computation/step/ValidateProjectStepTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/computation/step/ValidateProjectStepTest.java @@ -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() diff --git a/server/sonar-web/src/main/webapp/WEB-INF/db/migrate/935_add_provisioning_permission_to_scan.rb b/server/sonar-web/src/main/webapp/WEB-INF/db/migrate/935_add_provisioning_permission_to_scan.rb index 9d67ea61c2f..63671ef1b80 100644 --- a/server/sonar-web/src/main/webapp/WEB-INF/db/migrate/935_add_provisioning_permission_to_scan.rb +++ b/server/sonar-web/src/main/webapp/WEB-INF/db/migrate/935_add_provisioning_permission_to_scan.rb @@ -28,6 +28,7 @@ class AddProvisioningPermissionToScan < ActiveRecord::Migration class Property < ActiveRecord::Base + set_table_name 'properties' end class GroupRole < ActiveRecord::Base diff --git a/server/sonar-web/src/main/webapp/WEB-INF/db/migrate/936_delete_property_prevent_auto_project_creation.rb b/server/sonar-web/src/main/webapp/WEB-INF/db/migrate/936_delete_property_prevent_auto_project_creation.rb new file mode 100644 index 00000000000..14df4d0823e --- /dev/null +++ b/server/sonar-web/src/main/webapp/WEB-INF/db/migrate/936_delete_property_prevent_auto_project_creation.rb @@ -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 diff --git a/sonar-core/src/main/java/org/sonar/core/config/SecurityProperties.java b/sonar-core/src/main/java/org/sonar/core/config/SecurityProperties.java index 5c40e31aa1c..83db2ed80dd 100644 --- a/sonar-core/src/main/java/org/sonar/core/config/SecurityProperties.java +++ b/sonar-core/src/main/java/org/sonar/core/config/SecurityProperties.java @@ -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() ); diff --git a/sonar-db/src/main/java/org/sonar/db/version/DatabaseVersion.java b/sonar-db/src/main/java/org/sonar/db/version/DatabaseVersion.java index f6ab58c5a8b..bc7cfd3c9fa 100644 --- a/sonar-db/src/main/java/org/sonar/db/version/DatabaseVersion.java +++ b/sonar-db/src/main/java/org/sonar/db/version/DatabaseVersion.java @@ -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 diff --git a/sonar-db/src/main/resources/org/sonar/db/version/rows-h2.sql b/sonar-db/src/main/resources/org/sonar/db/version/rows-h2.sql index f985a934d64..1f670faabea 100644 --- a/sonar-db/src/main/resources/org/sonar/db/version/rows-h2.sql +++ b/sonar-db/src/main/resources/org/sonar/db/version/rows-h2.sql @@ -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; diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/CoreProperties.java b/sonar-plugin-api/src/main/java/org/sonar/api/CoreProperties.java index 51b49b34089..a7ecf44637c 100644 --- a/sonar-plugin-api/src/main/java/org/sonar/api/CoreProperties.java +++ b/sonar-plugin-api/src/main/java/org/sonar/api/CoreProperties.java @@ -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"; /**