From d129cbd866b0242ef6777bb6923d27c852ccf95f Mon Sep 17 00:00:00 2001 From: Simon Brandhof Date: Sun, 11 Mar 2012 21:37:19 +0100 Subject: Remove Hibernate from the component org.sonar.api.config.Settings --- .../org/sonar/batch/bootstrap/BootstrapModule.java | 4 +- .../batch/config/BatchDatabaseSettingsLoader.java | 63 ++++++++++++++++++++++ .../sonar/batch/config/BatchSettingsEnhancer.java | 58 -------------------- .../org/sonar/batch/config/ProjectSettings.java | 23 ++++---- 4 files changed, 79 insertions(+), 69 deletions(-) create mode 100644 sonar-batch/src/main/java/org/sonar/batch/config/BatchDatabaseSettingsLoader.java delete mode 100644 sonar-batch/src/main/java/org/sonar/batch/config/BatchSettingsEnhancer.java (limited to 'sonar-batch/src/main/java/org') diff --git a/sonar-batch/src/main/java/org/sonar/batch/bootstrap/BootstrapModule.java b/sonar-batch/src/main/java/org/sonar/batch/bootstrap/BootstrapModule.java index 8ca3fe2a087..ced7e8a4d34 100644 --- a/sonar-batch/src/main/java/org/sonar/batch/bootstrap/BootstrapModule.java +++ b/sonar-batch/src/main/java/org/sonar/batch/bootstrap/BootstrapModule.java @@ -26,7 +26,7 @@ import org.sonar.batch.FakeMavenPluginExecutor; import org.sonar.batch.MavenPluginExecutor; import org.sonar.batch.ServerMetadata; import org.sonar.batch.config.BatchSettings; -import org.sonar.batch.config.BatchSettingsEnhancer; +import org.sonar.batch.config.BatchDatabaseSettingsLoader; import org.sonar.core.persistence.DatabaseVersion; import org.sonar.jpa.session.DatabaseSessionProvider; import org.sonar.jpa.session.DefaultDatabaseConnector; @@ -88,7 +88,7 @@ public class BootstrapModule extends Module { addCoreSingleton(BatchPluginRepository.class); addCoreSingleton(BatchExtensionInstaller.class); - addCoreSingleton(BatchSettingsEnhancer.class); + addCoreSingleton(BatchDatabaseSettingsLoader.class); } boolean isMavenPluginExecutorRegistered() { diff --git a/sonar-batch/src/main/java/org/sonar/batch/config/BatchDatabaseSettingsLoader.java b/sonar-batch/src/main/java/org/sonar/batch/config/BatchDatabaseSettingsLoader.java new file mode 100644 index 00000000000..5f91446ddf7 --- /dev/null +++ b/sonar-batch/src/main/java/org/sonar/batch/config/BatchDatabaseSettingsLoader.java @@ -0,0 +1,63 @@ +/* + * Sonar, open source software quality management tool. + * Copyright (C) 2008-2012 SonarSource + * mailto:contact AT sonarsource DOT com + * + * Sonar 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. + * + * Sonar 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 Sonar; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02 + */ +package org.sonar.batch.config; + +import org.apache.commons.lang.StringUtils; +import org.sonar.api.CoreProperties; +import org.sonar.api.batch.bootstrap.ProjectReactor; +import org.sonar.core.properties.PropertiesDao; +import org.sonar.core.properties.PropertyDto; + +import java.util.List; + +/** + * @since 2.12 + */ +public final class BatchDatabaseSettingsLoader { + + private PropertiesDao propertiesDao; + private BatchSettings settings; + private ProjectReactor reactor; + + public BatchDatabaseSettingsLoader(PropertiesDao propertiesDao, BatchSettings settings, ProjectReactor reactor) { + this.propertiesDao = propertiesDao; + this.settings = settings; + this.reactor = reactor; + } + + public void start() { + String branch = settings.getString(CoreProperties.PROJECT_BRANCH_PROPERTY); + String projectKey = reactor.getRoot().getKey(); + if (StringUtils.isNotBlank(branch)) { + projectKey = String.format("%s:%s", projectKey, branch); + } + setIfNotDefined(propertiesDao.selectProjectProperties(projectKey)); + setIfNotDefined(propertiesDao.selectGlobalProperties()); + settings.updateDeprecatedCommonsConfiguration(); + } + + private void setIfNotDefined(List dbProperties) { + for (PropertyDto dbProperty : dbProperties) { + if (!settings.hasKey(dbProperty.getKey())) { + settings.setProperty(dbProperty.getKey(), dbProperty.getValue()); + } + } + } +} diff --git a/sonar-batch/src/main/java/org/sonar/batch/config/BatchSettingsEnhancer.java b/sonar-batch/src/main/java/org/sonar/batch/config/BatchSettingsEnhancer.java deleted file mode 100644 index dc605219b88..00000000000 --- a/sonar-batch/src/main/java/org/sonar/batch/config/BatchSettingsEnhancer.java +++ /dev/null @@ -1,58 +0,0 @@ -/* - * Sonar, open source software quality management tool. - * Copyright (C) 2008-2012 SonarSource - * mailto:contact AT sonarsource DOT com - * - * Sonar 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. - * - * Sonar 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 Sonar; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02 - */ -package org.sonar.batch.config; - -import org.sonar.api.CoreProperties; -import org.sonar.api.batch.bootstrap.ProjectReactor; -import org.sonar.api.database.configuration.Property; -import org.sonar.core.config.ConfigurationUtils; -import org.sonar.jpa.session.DatabaseSessionFactory; - -import java.util.List; - -/** - * @since 2.12 - */ -public final class BatchSettingsEnhancer { - - private DatabaseSessionFactory dbFactory; - private BatchSettings settings; - private ProjectReactor reactor; - - public BatchSettingsEnhancer(DatabaseSessionFactory dbFactory, BatchSettings settings, ProjectReactor reactor) { - this.dbFactory = dbFactory; - this.settings = settings; - this.reactor = reactor; - } - - public void start() { - setIfNotDefined(ConfigurationUtils.getProjectProperties(dbFactory, reactor.getRoot().getKey(), settings.getString(CoreProperties.PROJECT_BRANCH_PROPERTY))); - setIfNotDefined(ConfigurationUtils.getGeneralProperties(dbFactory)); - settings.updateDeprecatedCommonsConfiguration(); - } - - private void setIfNotDefined(List dbProperties) { - for (Property dbProperty : dbProperties) { - if (!settings.hasKey(dbProperty.getKey())) { - settings.setProperty(dbProperty.getKey(), dbProperty.getValue()); - } - } - } -} diff --git a/sonar-batch/src/main/java/org/sonar/batch/config/ProjectSettings.java b/sonar-batch/src/main/java/org/sonar/batch/config/ProjectSettings.java index 31c668a8cd4..d470a9cdb02 100644 --- a/sonar-batch/src/main/java/org/sonar/batch/config/ProjectSettings.java +++ b/sonar-batch/src/main/java/org/sonar/batch/config/ProjectSettings.java @@ -21,14 +21,15 @@ package org.sonar.batch.config; import com.google.common.collect.Lists; import org.apache.commons.configuration.Configuration; +import org.apache.commons.lang.StringUtils; import org.sonar.api.CoreProperties; import org.sonar.api.batch.bootstrap.ProjectDefinition; import org.sonar.api.config.PropertyDefinitions; import org.sonar.api.config.Settings; -import org.sonar.api.database.configuration.Property; import org.sonar.api.resources.Project; import org.sonar.core.config.ConfigurationUtils; -import org.sonar.jpa.session.DatabaseSessionFactory; +import org.sonar.core.properties.PropertiesDao; +import org.sonar.core.properties.PropertyDto; import java.util.List; @@ -39,13 +40,13 @@ public class ProjectSettings extends Settings { private Configuration deprecatedCommonsConf; private ProjectDefinition projectDefinition; - private DatabaseSessionFactory dbFactory; + private PropertiesDao propertiesDao; - public ProjectSettings(PropertyDefinitions definitions, ProjectDefinition projectDefinition, DatabaseSessionFactory dbFactory, Project project) { + public ProjectSettings(PropertyDefinitions definitions, ProjectDefinition projectDefinition, PropertiesDao propertiesDao, Project project) { super(definitions); this.deprecatedCommonsConf = project.getConfiguration(); // Configuration is not a parameter to be sure that the project conf is used, not the global one this.projectDefinition = projectDefinition; - this.dbFactory = dbFactory; + this.propertiesDao = propertiesDao; load(); } @@ -82,15 +83,19 @@ public class ProjectSettings extends Settings { if (projectDef.getParent() != null) { loadDatabaseProjectSettings(projectDef.getParent(), branch); } - List props = ConfigurationUtils.getProjectProperties(dbFactory, projectDef.getKey(), branch); - for (Property dbProperty : props) { + String projectKey = projectDef.getKey(); + if (StringUtils.isNotBlank(branch)) { + projectKey = String.format("%s:%s", projectKey, branch); + } + List props = propertiesDao.selectProjectProperties(projectKey); + for (PropertyDto dbProperty : props) { setProperty(dbProperty.getKey(), dbProperty.getValue()); } } private void loadDatabaseGlobalSettings() { - List props = ConfigurationUtils.getGeneralProperties(dbFactory); - for (Property dbProperty : props) { + List props = propertiesDao.selectGlobalProperties(); + for (PropertyDto dbProperty : props) { setProperty(dbProperty.getKey(), dbProperty.getValue()); } } -- cgit v1.2.3