+++ /dev/null
-/*
- * Sonar, open source software quality management tool.
- * Copyright (C) 2008-2011 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;
-
-import org.apache.commons.configuration.*;
-import org.sonar.api.batch.bootstrap.ProjectDefinition;
-import org.sonar.api.batch.bootstrap.ProjectReactor;
-import org.sonar.api.database.DatabaseSession;
-
-public class ProjectConfiguration extends CompositeConfiguration {
- private PropertiesConfiguration runtimeConfiguration;
-
- /**
- * Used during batch startup
- */
- public ProjectConfiguration(DatabaseSession session, ProjectReactor projectReactor) {
- this(session, projectReactor.getRoot());
- }
-
- public ProjectConfiguration(DatabaseSession session, ProjectDefinition project) {
- runtimeConfiguration = new PropertiesConfiguration();
- addConfiguration(runtimeConfiguration);
-
- loadSystemSettings();
- loadProjectDatabaseSettings(session, project);
- addConfiguration(new MapConfiguration(project.getProperties()));
- loadGlobalDatabaseSettings(session);
- }
-
- private void loadProjectDatabaseSettings(DatabaseSession session, ProjectDefinition project) {
- addConfiguration(new ResourceDatabaseConfiguration(session, project.getKey()));
-
- ProjectDefinition parent = project.getParent();
- while (parent != null && parent.getKey() != null) {
- addConfiguration(new ResourceDatabaseConfiguration(session, parent.getKey()));
- parent = parent.getParent();
- }
- }
-
- private void loadGlobalDatabaseSettings(DatabaseSession session) {
- addConfiguration(new org.sonar.api.database.configuration.DatabaseConfiguration(session));
- }
-
- private void loadSystemSettings() {
- addConfiguration(new SystemConfiguration());
- addConfiguration(new EnvironmentConfiguration());
- }
-
- @Override
- public void setProperty(String s, Object o) {
- runtimeConfiguration.setProperty(s, o);
- }
-}
+++ /dev/null
-/*
- * Sonar, open source software quality management tool.
- * Copyright (C) 2008-2011 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;
-
-import org.apache.maven.project.MavenProject;
-import org.junit.Test;
-import org.sonar.api.batch.bootstrap.ProjectDefinition;
-import org.sonar.api.resources.Project;
-import org.sonar.jpa.test.AbstractDbUnitTestCase;
-
-import java.util.Properties;
-
-import static org.hamcrest.CoreMatchers.is;
-import static org.junit.Assert.assertNull;
-import static org.junit.Assert.assertThat;
-
-public class ProjectConfigurationTest extends AbstractDbUnitTestCase {
-
- @Test
- public void loadSystemProperties() {
- System.setProperty("foo", "bar");
- setupData("global-properties");
-
- ProjectConfiguration config = new ProjectConfiguration(getSession(), newProject());
- assertThat(config.getString("foo"), is("bar"));
- assertNull(config.getString("unknown"));
- }
-
- @Test
- public void loadDatabaseProperties() {
- setupData("global-properties");
- ProjectConfiguration config = new ProjectConfiguration(getSession(), newProject());
- assertThat(config.getString("key1"), is("value1"));
- assertNull(config.getString("key3"));
- }
-
- @Test
- public void loadProjectDatabaseProperties() {
- setupData("project-properties");
- ProjectConfiguration config = new ProjectConfiguration(getSession(), newProject());
- assertThat(config.getString("key1"), is("overriden_value1"));
- assertThat(config.getString("key2"), is("value2"));
- assertThat(config.getString("key3"), is("value3"));
- }
-
- @Test
- public void loadModuleDatabaseProperties() {
- setupData("modules-properties");
- ProjectConfiguration moduleConfig = new ProjectConfiguration(getSession(), newModule());
-
- assertThat(moduleConfig.getString("key1"), is("project_value_1"));
- assertThat(moduleConfig.getString("key2"), is("value_2"));
- assertThat(moduleConfig.getString("key3"), is("module_value_3"));
- assertThat(moduleConfig.getString("key4"), is("module_value_4"));
- }
-
- @Test
- public void mavenSettingsLoadedBeforeGlobalSettings() {
- setupData("global-properties");
- ProjectDefinition project = newProject();
- project.setProperty("maven.foo", "bar");
- ProjectConfiguration config = new ProjectConfiguration(getSession(), project);
- assertThat(config.getString("maven.foo"), is("bar"));
- }
-
- @Test
- public void projectSettingsLoadedBeforeMavenSettings() {
- setupData("project-properties");
- ProjectDefinition project = newProject();
- project.setProperty("key1", "maven1");
- ProjectConfiguration config = new ProjectConfiguration(getSession(), project);
- assertThat(config.getString("key1"), is("overriden_value1"));
- }
-
- @Test
- public void addPropertyAtRuntime() {
- setupData("global-properties");
- ProjectConfiguration config = new ProjectConfiguration(getSession(), newProject());
-
- config.getInMemoryConfiguration().setProperty("new-key", "new-value");
- assertThat(config.getString("new-key"), is("new-value"));
- }
-
- @Test
- public void overridePropertyAtRuntime() {
- setupData("global-properties");
- ProjectConfiguration config = new ProjectConfiguration(getSession(), newProject());
-
- assertThat(config.getString("key1"), is("value1"));
- config.setProperty("key1", "new1");
- assertThat(config.getString("key1"), is("new1"));
- }
-
- private ProjectDefinition newProject() {
- return ProjectDefinition.create().setKey("mygroup:myproject");
- }
-
- private ProjectDefinition newModule() {
- ProjectDefinition module = ProjectDefinition.create().setKey("mygroup:mymodule");
- ProjectDefinition project = newProject();
- project.addSubProject(module);
- return module;
- }
-}
+++ /dev/null
-<dataset>
-
- <!-- another project -->
- <projects long_name="[null]" id="3333" scope="PRJ" qualifier="TRK" kee="mygroup:anotherproject" name="[null]"
- root_id="[null]"
- description="[null]"
- enabled="true" language="java" copy_resource_id="[null]"/>
-
- <!-- global properties -->
- <properties prop_key="key1" resource_id="[null]" text_value="value1"/>
- <properties prop_key="key2" resource_id="[null]" text_value="value2"/>
-
- <!-- another project properties -->
- <properties prop_key="key1" resource_id="3333" text_value="overriden value1"/>
- <properties prop_key="key3" resource_id="3333" text_value="value3"/>
-
-
-</dataset>
\ No newline at end of file
+++ /dev/null
-<dataset>
-
- <projects long_name="[null]" id="100" scope="PRJ" qualifier="TRK" kee="mygroup:myproject" name="[null]"
- root_id="[null]"
- description="[null]"
- enabled="true" language="java" copy_resource_id="[null]"/>
-
- <projects long_name="[null]" id="101" scope="PRJ" qualifier="BRC" kee="mygroup:mymodule" name="[null]"
- root_id="[null]"
- description="[null]"
- enabled="true" language="java" copy_resource_id="[null]"/>
-
- <!-- global properties -->
- <properties prop_key="key1" resource_id="[null]" text_value="value_1"/>
- <properties prop_key="key2" resource_id="[null]" text_value="value_2"/>
-
- <!-- project properties -->
- <properties prop_key="key1" resource_id="100" text_value="project_value_1"/>
- <properties prop_key="key3" resource_id="100" text_value="project_value_3"/>
-
- <!-- module properties -->
- <properties prop_key="key3" resource_id="101" text_value="module_value_3"/>
- <properties prop_key="key4" resource_id="101" text_value="module_value_4"/>
-
-
-</dataset>
\ No newline at end of file
+++ /dev/null
-<dataset>
-
- <projects long_name="[null]" id="100" scope="PRJ" qualifier="TRK" kee="mygroup:myproject" name="[null]"
- root_id="[null]"
- description="[null]"
- enabled="true" language="java" copy_resource_id="[null]"/>
-
- <!-- global properties -->
- <properties prop_key="key1" resource_id="[null]" text_value="value1"/>
- <properties prop_key="key2" resource_id="[null]" text_value="value2"/>
-
- <!-- specific properties -->
- <properties prop_key="key1" resource_id="100" text_value="overriden_value1"/>
- <properties prop_key="key3" resource_id="100" text_value="value3"/>
-
-
-</dataset>
\ No newline at end of file
+++ /dev/null
-/*
- * Sonar, open source software quality management tool.
- * Copyright (C) 2008-2011 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.api.database.configuration;
-
-import org.apache.commons.configuration.BaseConfiguration;
-import org.sonar.jpa.session.DatabaseSessionFactory;
-import org.sonar.api.database.model.ResourceModel;
-
-import java.util.List;
-
-/**
- *
- * IMPORTANT : This class can't be moved to org.sonar.jpa.dao for backward-compatibility reasons.
- * This class is still used in some plugins.
- *
- * @since 1.10
- */
-public class ResourceDatabaseConfiguration extends BaseConfiguration {
- private final DatabaseSessionFactory sessionFactory;
- private Integer resourceId = null;
-
- public ResourceDatabaseConfiguration(DatabaseSessionFactory sessionFactory, ResourceModel resource) {
- this.sessionFactory = sessionFactory;
- if (resource != null) {
- this.resourceId = resource.getId();
- }
- load();
- }
-
- public ResourceDatabaseConfiguration(DatabaseSessionFactory sessionFactory, Integer resourceId) {
- this.sessionFactory = sessionFactory;
- this.resourceId = resourceId;
- load();
- }
-
- public ResourceDatabaseConfiguration(DatabaseSessionFactory sessionFactory, String resourceKey) {
- this.sessionFactory = sessionFactory;
-
- ResourceModel resource = sessionFactory.getSession().getSingleResult(ResourceModel.class, "key", resourceKey);
- if (resource != null) {
- this.resourceId = resource.getId();
- }
- load();
- }
-
- public void load() {
- clear();
-
- loadResourceProperties();
- }
-
- private void loadResourceProperties() {
- if (resourceId != null) {
- List<Property> properties = sessionFactory.getSession()
- .createQuery("from " + Property.class.getSimpleName() + " p where p.resourceId=:resourceId and p.userId is null")
- .setParameter("resourceId", resourceId)
- .getResultList();
-
- registerProperties(properties);
- }
- }
-
- private void registerProperties(List<Property> properties) {
- if (properties != null) {
- for (Property property : properties) {
- setProperty(property.getKey(), property.getValue());
- }
- }
- }
-
-}
+++ /dev/null
-/*
- * Sonar, open source software quality management tool.
- * Copyright (C) 2008-2011 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.api.database.configuration;
-
-import org.apache.commons.collections.CollectionUtils;
-import org.junit.Test;
-import org.sonar.jpa.test.AbstractDbUnitTestCase;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNull;
-
-public class ResourceDatabaseConfigurationTest extends AbstractDbUnitTestCase {
-
- @Test
- public void shouldNotLoadGlobalProperties() {
- setupData("shouldNotLoadGlobalProperties");
-
- ResourceDatabaseConfiguration conf = new ResourceDatabaseConfiguration(getSessionFactory(), 100);
- assertEquals(2, CollectionUtils.size(conf.getKeys()));
- assertEquals("project_value1", conf.getString("key1"));
- assertNull(conf.getString("key2"));
- }
-
-}
+++ /dev/null
-<dataset>
-
- <projects long_name="[null]" id="100" scope="PRJ" qualifier="TRK" kee="myproject" name="[null]" root_id="[null]"
- description="[null]"
- enabled="true" language="java" copy_resource_id="[null]"/>
-
- <!-- global properties -->
- <properties prop_key="key1" resource_id="[null]" text_value="value1" user_id="[null]"/>
- <properties prop_key="key2" resource_id="[null]" text_value="value2" user_id="[null]"/>
-
- <!-- specific properties -->
- <properties prop_key="key1" resource_id="100" text_value="project_value1" user_id="[null]"/>
- <properties prop_key="key3" resource_id="100" text_value="project_value3" user_id="[null]"/>
-
-
-</dataset>
\ No newline at end of file
+++ /dev/null
-<dataset>
-
- <projects long_name="[null]" id="100" scope="PRJ" qualifier="TRK" kee="myproject" name="[null]" root_id="[null]"
- description="[null]"
- enabled="true" language="java" copy_resource_id="[null]"/>
-
- <!-- global properties -->
- <properties prop_key="key1" resource_id="[null]" text_value="value1" user_id="[null]"/>
- <properties prop_key="key2" resource_id="[null]" text_value="value2" user_id="[null]"/>
-
- <!-- specific properties -->
- <properties prop_key="key1" resource_id="100" text_value="overriden value1" user_id="[null]"/>
- <properties prop_key="key3" resource_id="100" text_value="value3" user_id="[null]"/>
-
-
-</dataset>
\ No newline at end of file