001 /* 002 * Sonar, open source software quality management tool. 003 * Copyright (C) 2009 SonarSource SA 004 * mailto:contact AT sonarsource DOT com 005 * 006 * Sonar is free software; you can redistribute it and/or 007 * modify it under the terms of the GNU Lesser General Public 008 * License as published by the Free Software Foundation; either 009 * version 3 of the License, or (at your option) any later version. 010 * 011 * Sonar is distributed in the hope that it will be useful, 012 * but WITHOUT ANY WARRANTY; without even the implied warranty of 013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 014 * Lesser General Public License for more details. 015 * 016 * You should have received a copy of the GNU Lesser General Public 017 * License along with Sonar; if not, write to the Free Software 018 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02 019 */ 020 package org.sonar.batch; 021 022 import org.apache.commons.configuration.*; 023 import org.apache.maven.project.MavenProject; 024 import org.sonar.api.database.DatabaseSession; 025 import org.sonar.api.database.configuration.DatabaseConfiguration; 026 import org.sonar.api.resources.Project; 027 028 public class ProjectConfiguration extends CompositeConfiguration { 029 private PropertiesConfiguration runtimeConfiguration; 030 031 public ProjectConfiguration(DatabaseSession session, Project project) { 032 runtimeConfiguration = new PropertiesConfiguration(); 033 addConfiguration(runtimeConfiguration); 034 035 loadSystemSettings(); 036 loadProjectDatabaseSettings(session, project); 037 loadMavenSettings(project.getPom()); 038 loadGlobalDatabaseSettings(session); 039 } 040 041 private void loadProjectDatabaseSettings(DatabaseSession session, Project project) { 042 addConfiguration(new ResourceDatabaseConfiguration(session, project.getKey())); 043 044 Project parent = project.getParent(); 045 while (parent != null && parent.getKey() != null) { 046 addConfiguration(new ResourceDatabaseConfiguration(session, parent.getKey())); 047 parent = parent.getParent(); 048 } 049 } 050 051 private void loadGlobalDatabaseSettings(DatabaseSession session) { 052 addConfiguration(new DatabaseConfiguration(session)); 053 } 054 055 private void loadSystemSettings() { 056 addConfiguration(new SystemConfiguration()); 057 addConfiguration(new EnvironmentConfiguration()); 058 } 059 060 private void loadMavenSettings(MavenProject pom) { 061 addConfiguration(new MapConfiguration(pom.getModel().getProperties())); 062 } 063 064 @Override 065 public void setProperty(String s, Object o) { 066 runtimeConfiguration.setProperty(s, o); 067 } 068 } 069