--- /dev/null
+/*
+ * 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.api.config;
+
+import com.google.common.collect.Lists;
+
+import java.util.List;
+
+public class PropertySet {
+ private final List<PropertySetField> fields = Lists.newArrayList();
+
+ public void add(PropertySetField field) {
+ fields.add(field);
+ }
+
+ public List<PropertySetField> getFields() {
+ return fields;
+ }
+}
--- /dev/null
+/*
+ * 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.api.config;
+
+import com.google.common.collect.Maps;
+
+import java.util.Map;
+import java.util.NoSuchElementException;
+
+public class PropertySetDefinitions {
+ private final Map<String, PropertySet> index = Maps.newHashMap();
+
+ public void register(String name, PropertySet propertySet) {
+ if (null != index.put(name, propertySet)) {
+ throw new IllegalStateException("Unable to register two property sets with same name " + name);
+ }
+ }
+
+ public PropertySet findByName(String name) {
+ PropertySet propertySet = index.get(name);
+ if (propertySet == null) {
+ throw new NoSuchElementException("Property set not found " + name);
+ }
+ return propertySet;
+ }
+}
--- /dev/null
+/*
+ * 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.api.config;
+
+import org.sonar.api.PropertyType;
+
+public final class PropertySetField {
+ private final String name;
+ private final PropertyType type;
+ private String description = "";
+ private String defaultValue = "";
+
+ private PropertySetField(String name, PropertyType type) {
+ this.name = name;
+ this.type = type;
+ }
+
+ public static PropertySetField create(String name, PropertyType type) {
+ return new PropertySetField(name, type);
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public PropertyType getType() {
+ return type;
+ }
+
+ public String getDescription() {
+ return description;
+ }
+
+ public PropertySetField setDescription(String description) {
+ this.description = description;
+ return this;
+ }
+
+ public String getDefaultValue() {
+ return defaultValue;
+ }
+
+ public PropertySetField setDefaultValue(String defaultValue) {
+ this.defaultValue = defaultValue;
+ return this;
+ }
+}
--- /dev/null
+/*
+ * 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.api.config;
+
+import org.sonar.api.ServerExtension;
+
+/**
+ * This extension point must be implemented to define a new property set.
+ *
+ * @since 3.3
+ */
+public abstract class PropertySetTemplate implements ServerExtension {
+ /**
+ * Returns the {@link org.sonar.api.config.PropertySet} object that a property set.
+ *
+ * @return the property set
+ */
+ public abstract PropertySet createPropertySet();
+
+ /**
+ * Property set unique name.
+ */
+ public abstract String getName();
+}
--- /dev/null
+/*
+ * 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.api.config;
+
+import org.junit.Test;
+
+import java.util.NoSuchElementException;
+
+import static org.fest.assertions.Assertions.assertThat;
+
+public class PropertySetDefinitionsTest {
+ PropertySetDefinitions definitions = new PropertySetDefinitions();
+
+ @Test
+ public void should_register_by_name() {
+ PropertySet set = new PropertySet();
+ PropertySet other = new PropertySet();
+
+ definitions.register("name", set);
+ definitions.register("other", other);
+
+ assertThat(definitions.findByName("name")).isSameAs(set);
+ assertThat(definitions.findByName("other")).isSameAs(other);
+ }
+
+ @Test(expected = IllegalStateException.class)
+ public void should_fail_to_register_twice() {
+ definitions.register("name", new PropertySet());
+ definitions.register("name", new PropertySet());
+ }
+
+ @Test(expected = NoSuchElementException.class)
+ public void should_fail_to_find_unknown_set() {
+ definitions.findByName("UNKNOWN");
+ }
+}
--- /dev/null
+/*
+ * 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.api.config;
+
+import org.junit.Test;
+import org.sonar.api.PropertyType;
+
+import static org.fest.assertions.Assertions.assertThat;
+
+public class PropertySetFieldTest {
+ @Test
+ public void should_set_name_and_type() {
+ PropertySetField field = PropertySetField.create("name", PropertyType.STRING);
+
+ assertThat(field.getName()).isEqualTo("name");
+ assertThat(field.getType()).isEqualTo(PropertyType.STRING);
+ assertThat(field.getDefaultValue()).isEmpty();
+ assertThat(field.getDescription()).isEmpty();
+ }
+
+ @Test
+ public void should_set_optional_characteristics() {
+ PropertySetField field = PropertySetField.create("name", PropertyType.STRING);
+
+ field.setDefaultValue("default");
+ field.setDescription("description");
+
+ assertThat(field.getDefaultValue()).isEqualTo("default");
+ assertThat(field.getDescription()).isEqualTo("description");
+ }
+}
--- /dev/null
+/*
+ * 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.api.config;
+
+import org.junit.Test;
+import org.sonar.api.PropertyType;
+
+import static org.fest.assertions.Assertions.assertThat;
+
+public class PropertySetTest {
+ @Test
+ public void should_add_fields() {
+ PropertySetField firstField = PropertySetField.create("first", PropertyType.STRING);
+ PropertySetField secondField = PropertySetField.create("second", PropertyType.STRING);
+
+ PropertySet set = new PropertySet();
+ set.add(firstField);
+ set.add(secondField);
+
+ assertThat(set.getFields()).containsExactly(firstField, secondField);
+ }
+}
startupContainer.addSingleton(GeneratePluginIndex.class);
startupContainer.addSingleton(RegisterNewFilters.class);
startupContainer.addSingleton(RegisterNewDashboards.class);
+ startupContainer.addSingleton(RegisterPropertySets.class);
startupContainer.startComponents();
startupContainer.getComponentByType(ServerLifecycleNotifier.class).notifyStart();
--- /dev/null
+/*
+ * 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.server.startup;
+
+import com.google.common.collect.ImmutableList;
+import org.sonar.api.config.PropertySetDefinitions;
+import org.sonar.api.config.PropertySetTemplate;
+import org.sonar.api.utils.TimeProfiler;
+
+import java.util.List;
+
+/**
+ * @since 3.3
+ */
+public final class RegisterPropertySets {
+ private final List<PropertySetTemplate> propertySetTemplates;
+ private final PropertySetDefinitions propertySetDefinitions;
+
+ public RegisterPropertySets(PropertySetTemplate[] propertySetTemplates, PropertySetDefinitions propertySetDefinitions) {
+ this.propertySetTemplates = ImmutableList.copyOf(propertySetTemplates);
+ this.propertySetDefinitions = propertySetDefinitions;
+ }
+
+ public void start() {
+ TimeProfiler profiler = new TimeProfiler().start("Register dashboards");
+
+ for (PropertySetTemplate template : propertySetTemplates) {
+ propertySetDefinitions.register(template.getName(), template.createPropertySet());
+ }
+
+ profiler.stop();
+ }
+}
--- /dev/null
+/*
+ * 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.server.startup;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.sonar.api.config.PropertySet;
+import org.sonar.api.config.PropertySetDefinitions;
+import org.sonar.api.config.PropertySetTemplate;
+
+import static org.mockito.Mockito.*;
+
+public class RegisterPropertySetsTest {
+ private RegisterPropertySets task;
+ private PropertySetDefinitions propertySetDefinitions = mock(PropertySetDefinitions.class);
+ private PropertySetTemplate firstTemplate = mock(PropertySetTemplate.class);
+ private PropertySetTemplate secondTemplate = mock(PropertySetTemplate.class);
+ private PropertySet firstPropertySet = mock(PropertySet.class);
+ private PropertySet secondPropertySet = mock(PropertySet.class);
+
+ @Before
+ public void init() {
+ task = new RegisterPropertySets(new PropertySetTemplate[]{firstTemplate, secondTemplate}, propertySetDefinitions);
+ }
+
+ @Test
+ public void should_register_on_startup() {
+ when(firstTemplate.getName()).thenReturn("first");
+ when(secondTemplate.getName()).thenReturn("second");
+ when(firstTemplate.createPropertySet()).thenReturn(firstPropertySet);
+ when(secondTemplate.createPropertySet()).thenReturn(secondPropertySet);
+
+ task.start();
+
+ verify(propertySetDefinitions).register("first", firstPropertySet);
+ verify(propertySetDefinitions).register("second", secondPropertySet);
+ }
+}