summaryrefslogtreecommitdiffstats
path: root/server
diff options
context:
space:
mode:
authorSimon Brandhof <simon.brandhof@sonarsource.com>2015-09-18 00:14:11 +0200
committerSimon Brandhof <simon.brandhof@sonarsource.com>2015-09-18 23:48:48 +0200
commitb7e73ea7bd925ade9625a97c1a1419c1cee6ccd6 (patch)
treeb98d5cbab17656ff4857b165df6b87aec602a789 /server
parent72a150316849ace24c1564824b3ac2d48ca3a5bf (diff)
downloadsonarqube-b7e73ea7bd925ade9625a97c1a1419c1cee6ccd6.tar.gz
sonarqube-b7e73ea7bd925ade9625a97c1a1419c1cee6ccd6.zip
SONAR-6861 Drop the property "sonar.preventAutoProjectCreation"
Diffstat (limited to 'server')
-rw-r--r--server/sonar-server/src/main/java/org/sonar/server/computation/step/ValidateProjectStep.java15
-rw-r--r--server/sonar-server/src/test/java/org/sonar/server/computation/step/ValidateProjectStepTest.java51
-rw-r--r--server/sonar-web/src/main/webapp/WEB-INF/db/migrate/935_add_provisioning_permission_to_scan.rb1
-rw-r--r--server/sonar-web/src/main/webapp/WEB-INF/db/migrate/936_delete_property_prevent_auto_project_creation.rb35
4 files changed, 38 insertions, 64 deletions
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 :
* <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
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;
@@ -76,56 +75,6 @@ public class ValidateProjectStepTest {
}
@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()
.setAnalysisDate(DEFAULT_ANALYSIS_TIME)
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