*/
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;
}
public void start() {
- String projectKey = reactor.getRoot().getKey();
- setIfNotDefined(ConfigurationUtils.getProjectProperties(dbFactory, projectKey));
+ setIfNotDefined(ConfigurationUtils.getProjectProperties(dbFactory, reactor.getRoot().getKey(), settings.getString(CoreProperties.PROJECT_BRANCH_PROPERTY)));
setIfNotDefined(ConfigurationUtils.getGeneralProperties(dbFactory));
settings.updateDeprecatedCommonsConfiguration();
}
import com.google.common.collect.Lists;
import org.apache.commons.configuration.Configuration;
+import org.sonar.api.CoreProperties;
import org.sonar.api.batch.bootstrap.ProjectDefinition;
import org.sonar.api.config.PropertyDefinitions;
import org.sonar.api.config.Settings;
public ProjectSettings load() {
clear();
+ // hack to obtain "sonar.branch" before loading settings from database
+ loadBuildProperties();
+ addEnvironmentVariables();
+ addSystemProperties();
+ String branch = getString(CoreProperties.PROJECT_BRANCH_PROPERTY);
+ clear();
+
// order is important -> bottom-up. The last one overrides all the others.
loadDatabaseGlobalSettings();
- loadDatabaseProjectSettings(projectDefinition);
+ loadDatabaseProjectSettings(projectDefinition, branch);
loadBuildProperties();
addEnvironmentVariables();
addSystemProperties();
}
}
- private void loadDatabaseProjectSettings(ProjectDefinition projectDef) {
+ private void loadDatabaseProjectSettings(ProjectDefinition projectDef, String branch) {
if (projectDef.getParent() != null) {
- loadDatabaseProjectSettings(projectDef.getParent());
+ loadDatabaseProjectSettings(projectDef.getParent(), branch);
}
- List<Property> props = ConfigurationUtils.getProjectProperties(dbFactory, projectDef.getKey());
+ List<Property> props = ConfigurationUtils.getProjectProperties(dbFactory, projectDef.getKey(), branch);
for (Property dbProperty : props) {
setProperty(dbProperty.getKey(), dbProperty.getValue());
}
import org.apache.commons.configuration.Configuration;
import org.apache.commons.io.FileUtils;
import org.apache.commons.io.IOUtils;
+import org.apache.commons.lang.StringUtils;
import org.apache.commons.lang.text.StrSubstitutor;
import org.sonar.api.database.DatabaseSession;
import org.sonar.api.database.configuration.Property;
return result;
}
- public static List<Property> getProjectProperties(DatabaseSessionFactory dbFactory, String moduleKey) {
+ public static List<Property> getProjectProperties(DatabaseSessionFactory dbFactory, String moduleKey, String branch) {
+ final String completeKey;
+ if (StringUtils.isNotBlank(branch)) {
+ completeKey = String.format("%s:%s", moduleKey, branch);
+ } else {
+ completeKey = moduleKey;
+ }
DatabaseSession session = prepareDbSession(dbFactory);
- ResourceModel resource = session.getSingleResult(ResourceModel.class, "key", moduleKey);
+ ResourceModel resource = session.getSingleResult(ResourceModel.class, "key", completeKey);
if (resource != null) {
return session
.createQuery("from " + Property.class.getSimpleName() + " p where p.resourceId=:resourceId and p.userId is null")