]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-6861 Drop the property "sonar.preventAutoProjectCreation"
authorSimon Brandhof <simon.brandhof@sonarsource.com>
Thu, 17 Sep 2015 22:14:11 +0000 (00:14 +0200)
committerSimon Brandhof <simon.brandhof@sonarsource.com>
Fri, 18 Sep 2015 21:48:48 +0000 (23:48 +0200)
it/it-tests/src/test/java/batch/suite/ProjectProvisioningTest.java
server/sonar-server/src/main/java/org/sonar/server/computation/step/ValidateProjectStep.java
server/sonar-server/src/test/java/org/sonar/server/computation/step/ValidateProjectStepTest.java
server/sonar-web/src/main/webapp/WEB-INF/db/migrate/935_add_provisioning_permission_to_scan.rb
server/sonar-web/src/main/webapp/WEB-INF/db/migrate/936_delete_property_prevent_auto_project_creation.rb [new file with mode: 0644]
sonar-core/src/main/java/org/sonar/core/config/SecurityProperties.java
sonar-db/src/main/java/org/sonar/db/version/DatabaseVersion.java
sonar-db/src/main/resources/org/sonar/db/version/rows-h2.sql
sonar-plugin-api/src/main/java/org/sonar/api/CoreProperties.java

index e4212590134c670f2bd1e44e5afd629608309e5e..b928e4939dbcf3f08e71764fcb40760dc775ebde 100644 (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
index a6eeea2e770b4214e164b8d596db24008ca77a92..5e06c59522e67ccadfe4f6747696837e7ae3c2b4 100644 (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
index 379d7046e676d811c10f754400d59a6f8e5ac793..512e5a9819bfd01a7f3d591dd5a972f6487883e6 100644 (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()
index 9d67ea61c2fb34aee6bc13bc50226735d46fe5c3..63671ef1b80a84a1b281ae4b510e9f755b2f68f0 100644 (file)
@@ -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 (file)
index 0000000..14df4d0
--- /dev/null
@@ -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
index 5c40e31aa1cec2e468cc8a7aa857a5a93e57000c..83db2ed80dd2c31f8e22b5686105919b9db4b2bc 100644 (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()
       );
 
index f6ab58c5a8be4ffb22f6d563e95220f9ea1ced31..bc7cfd3c9fa1a5579e457cbdb92cffedbfce1e6a 100644 (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
index f985a934d646fb4e101a114852834a4128b0e08a..1f670faabea2566a98c80a7defda922651aca0ca 100644 (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;
index 51b49b34089b12217a3f913497ff4ca67c20da98..a7ecf44637c0a3f72bd468a261fb56e62c1afd61 100644 (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";
 
   /**