aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-batch/src/main/java/org
diff options
context:
space:
mode:
authorSimon Brandhof <simon.brandhof@gmail.com>2012-03-11 21:37:19 +0100
committerSimon Brandhof <simon.brandhof@gmail.com>2012-03-12 11:29:00 +0100
commitd129cbd866b0242ef6777bb6923d27c852ccf95f (patch)
tree3b678507e2836c31c30b97d9a16436163be5012e /sonar-batch/src/main/java/org
parent48ac6cdb612920154aa4bca46fb4f626173adcbc (diff)
downloadsonarqube-d129cbd866b0242ef6777bb6923d27c852ccf95f.tar.gz
sonarqube-d129cbd866b0242ef6777bb6923d27c852ccf95f.zip
Remove Hibernate from the component org.sonar.api.config.Settings
Diffstat (limited to 'sonar-batch/src/main/java/org')
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/bootstrap/BootstrapModule.java4
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/config/BatchDatabaseSettingsLoader.java (renamed from sonar-batch/src/main/java/org/sonar/batch/config/BatchSettingsEnhancer.java)27
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/config/ProjectSettings.java23
3 files changed, 32 insertions, 22 deletions
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/BatchSettingsEnhancer.java b/sonar-batch/src/main/java/org/sonar/batch/config/BatchDatabaseSettingsLoader.java
index dc605219b88..5f91446ddf7 100644
--- a/sonar-batch/src/main/java/org/sonar/batch/config/BatchSettingsEnhancer.java
+++ b/sonar-batch/src/main/java/org/sonar/batch/config/BatchDatabaseSettingsLoader.java
@@ -19,37 +19,42 @@
*/
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.api.database.configuration.Property;
-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;
/**
* @since 2.12
*/
-public final class BatchSettingsEnhancer {
+public final class BatchDatabaseSettingsLoader {
- private DatabaseSessionFactory dbFactory;
+ private PropertiesDao propertiesDao;
private BatchSettings settings;
private ProjectReactor reactor;
- public BatchSettingsEnhancer(DatabaseSessionFactory dbFactory, BatchSettings settings, ProjectReactor reactor) {
- this.dbFactory = dbFactory;
+ public BatchDatabaseSettingsLoader(PropertiesDao propertiesDao, BatchSettings settings, ProjectReactor reactor) {
+ this.propertiesDao = propertiesDao;
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));
+ 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<Property> dbProperties) {
- for (Property dbProperty : dbProperties) {
+ private void setIfNotDefined(List<PropertyDto> 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/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<Property> 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<PropertyDto> props = propertiesDao.selectProjectProperties(projectKey);
+ for (PropertyDto dbProperty : props) {
setProperty(dbProperty.getKey(), dbProperty.getValue());
}
}
private void loadDatabaseGlobalSettings() {
- List<Property> props = ConfigurationUtils.getGeneralProperties(dbFactory);
- for (Property dbProperty : props) {
+ List<PropertyDto> props = propertiesDao.selectGlobalProperties();
+ for (PropertyDto dbProperty : props) {
setProperty(dbProperty.getKey(), dbProperty.getValue());
}
}