package org.sonar.plugins.core;
import com.google.common.collect.ImmutableList;
-import org.sonar.api.*;
+import org.sonar.api.CoreProperties;
+import org.sonar.api.Extension;
+import org.sonar.api.Properties;
+import org.sonar.api.Property;
+import org.sonar.api.PropertyField;
+import org.sonar.api.PropertyType;
+import org.sonar.api.SonarPlugin;
import org.sonar.api.checks.NoSonarFilter;
-import org.sonar.api.config.PropertySetDefinitions;
-import org.sonar.api.config.TestPropertySetTemplate;
import org.sonar.api.resources.Java;
import org.sonar.plugins.core.batch.ExcludedResourceFilter;
import org.sonar.plugins.core.batch.IndexProjectPostJob;
import org.sonar.plugins.core.charts.DistributionBarChart;
import org.sonar.plugins.core.charts.XradarChart;
import org.sonar.plugins.core.colorizers.JavaColorizerFormat;
-import org.sonar.plugins.core.dashboards.*;
+import org.sonar.plugins.core.dashboards.DefaultDashboard;
+import org.sonar.plugins.core.dashboards.HotspotsDashboard;
+import org.sonar.plugins.core.dashboards.MyFavouritesDashboard;
+import org.sonar.plugins.core.dashboards.ProjectsDashboard;
+import org.sonar.plugins.core.dashboards.ReviewsDashboard;
+import org.sonar.plugins.core.dashboards.TimeMachineDashboard;
+import org.sonar.plugins.core.dashboards.TreemapDashboard;
import org.sonar.plugins.core.filters.MyFavouritesFilter;
import org.sonar.plugins.core.filters.ProjectFilter;
import org.sonar.plugins.core.filters.TreeMapFilter;
import org.sonar.plugins.core.security.ApplyProjectRolesDecorator;
import org.sonar.plugins.core.security.DefaultResourcePermissions;
-import org.sonar.plugins.core.sensors.*;
+import org.sonar.plugins.core.sensors.BranchCoverageDecorator;
+import org.sonar.plugins.core.sensors.CheckAlertThresholds;
+import org.sonar.plugins.core.sensors.CommentDensityDecorator;
+import org.sonar.plugins.core.sensors.CoverageDecorator;
+import org.sonar.plugins.core.sensors.DirectoriesDecorator;
+import org.sonar.plugins.core.sensors.FilesDecorator;
+import org.sonar.plugins.core.sensors.GenerateAlertEvents;
+import org.sonar.plugins.core.sensors.ItBranchCoverageDecorator;
+import org.sonar.plugins.core.sensors.ItCoverageDecorator;
+import org.sonar.plugins.core.sensors.ItLineCoverageDecorator;
+import org.sonar.plugins.core.sensors.LineCoverageDecorator;
+import org.sonar.plugins.core.sensors.ManualMeasureDecorator;
+import org.sonar.plugins.core.sensors.ManualViolationInjector;
+import org.sonar.plugins.core.sensors.ProfileEventsSensor;
+import org.sonar.plugins.core.sensors.ProfileSensor;
+import org.sonar.plugins.core.sensors.ProjectLinksSensor;
+import org.sonar.plugins.core.sensors.ReviewNotifications;
+import org.sonar.plugins.core.sensors.ReviewWorkflowDecorator;
+import org.sonar.plugins.core.sensors.ReviewsMeasuresDecorator;
+import org.sonar.plugins.core.sensors.UnitTestDecorator;
+import org.sonar.plugins.core.sensors.VersionEventsSensor;
+import org.sonar.plugins.core.sensors.ViolationSeverityUpdater;
+import org.sonar.plugins.core.sensors.ViolationsDecorator;
+import org.sonar.plugins.core.sensors.ViolationsDensityDecorator;
+import org.sonar.plugins.core.sensors.WeightedViolationsDecorator;
import org.sonar.plugins.core.testdetailsviewer.TestsViewerDefinition;
-import org.sonar.plugins.core.timemachine.*;
+import org.sonar.plugins.core.timemachine.NewCoverageAggregator;
+import org.sonar.plugins.core.timemachine.NewCoverageFileAnalyzer;
+import org.sonar.plugins.core.timemachine.NewItCoverageFileAnalyzer;
+import org.sonar.plugins.core.timemachine.NewViolationsDecorator;
+import org.sonar.plugins.core.timemachine.ReferenceAnalysis;
+import org.sonar.plugins.core.timemachine.TendencyDecorator;
+import org.sonar.plugins.core.timemachine.TimeMachineConfigurationPersister;
+import org.sonar.plugins.core.timemachine.VariationDecorator;
+import org.sonar.plugins.core.timemachine.ViolationPersisterDecorator;
+import org.sonar.plugins.core.timemachine.ViolationTrackingDecorator;
import org.sonar.plugins.core.web.Lcom4Viewer;
-import org.sonar.plugins.core.widgets.*;
+import org.sonar.plugins.core.widgets.AlertsWidget;
+import org.sonar.plugins.core.widgets.CommentsDuplicationsWidget;
+import org.sonar.plugins.core.widgets.ComplexityWidget;
+import org.sonar.plugins.core.widgets.CoverageWidget;
+import org.sonar.plugins.core.widgets.CustomMeasuresWidget;
+import org.sonar.plugins.core.widgets.DescriptionWidget;
+import org.sonar.plugins.core.widgets.EventsWidget;
+import org.sonar.plugins.core.widgets.FilterWidget;
+import org.sonar.plugins.core.widgets.HotspotMetricWidget;
+import org.sonar.plugins.core.widgets.HotspotMostViolatedResourcesWidget;
+import org.sonar.plugins.core.widgets.HotspotMostViolatedRulesWidget;
+import org.sonar.plugins.core.widgets.ItCoverageWidget;
+import org.sonar.plugins.core.widgets.RulesWidget;
+import org.sonar.plugins.core.widgets.SizeWidget;
+import org.sonar.plugins.core.widgets.TimeMachineWidget;
+import org.sonar.plugins.core.widgets.TimelineWidget;
+import org.sonar.plugins.core.widgets.TreemapWidget;
import org.sonar.plugins.core.widgets.actionPlans.ActionPlansWidget;
-import org.sonar.plugins.core.widgets.reviews.*;
+import org.sonar.plugins.core.widgets.reviews.FalsePositiveReviewsWidget;
+import org.sonar.plugins.core.widgets.reviews.MyReviewsWidget;
+import org.sonar.plugins.core.widgets.reviews.PlannedReviewsWidget;
+import org.sonar.plugins.core.widgets.reviews.ProjectReviewsWidget;
+import org.sonar.plugins.core.widgets.reviews.ReviewsMetricsWidget;
+import org.sonar.plugins.core.widgets.reviews.ReviewsPerDeveloperWidget;
+import org.sonar.plugins.core.widgets.reviews.UnplannedReviewsWidget;
import java.util.List;
global = true,
category = CoreProperties.CATEGORY_GENERAL),
@Property(
- key = "toto",
- name = "Toto",
+ key = "sonar.test.jira.servers",
+ name = "Jira Servers",
global = true,
+ project = true,
+ category = "DEV",
+ fields = {
+ @PropertyField(
+ key = "url",
+ name = "Url",
+ type = PropertyType.STRING),
+ @PropertyField(
+ key = "port",
+ name = "Port",
+ type = PropertyType.INTEGER)}),
+ @Property(
+ key = "sonar.test.jira",
+ name = "Jira",
+ project = true,
+ category = "DEV",
type = PropertyType.PROPERTY_SET,
- propertySetName = "myset",
- category = CoreProperties.CATEGORY_GENERAL),
+ propertySetKey = "sonar.test.jira.servers"),
@Property(
key = CoreProperties.PROJECT_LANGUAGE_PROPERTY,
defaultValue = Java.KEY,
@SuppressWarnings("unchecked")
public List<Class<? extends Extension>> getExtensions() {
return ImmutableList.of(
- DefaultResourceTypes.class,
- UserManagedMetrics.class,
- ProjectFileSystemLogger.class,
-
- // maven
- MavenInitializer.class,
+ DefaultResourceTypes.class,
+ UserManagedMetrics.class,
+ ProjectFileSystemLogger.class,
- // languages
- Java.class,
+ // maven
+ MavenInitializer.class,
- // pages
- TestsViewerDefinition.class,
- Lcom4Viewer.class,
+ // languages
+ Java.class,
- // filters
- ProjectFilter.class,
- TreeMapFilter.class,
- MyFavouritesFilter.class,
+ // pages
+ TestsViewerDefinition.class,
+ Lcom4Viewer.class,
- // widgets
- AlertsWidget.class,
- CoverageWidget.class,
- ItCoverageWidget.class,
- CommentsDuplicationsWidget.class,
- DescriptionWidget.class,
- ComplexityWidget.class,
- RulesWidget.class,
- SizeWidget.class,
- EventsWidget.class,
- CustomMeasuresWidget.class,
- TimelineWidget.class,
- TimeMachineWidget.class,
- HotspotMetricWidget.class,
- HotspotMostViolatedResourcesWidget.class,
- HotspotMostViolatedRulesWidget.class,
- MyReviewsWidget.class,
- ProjectReviewsWidget.class,
- FalsePositiveReviewsWidget.class,
- ReviewsPerDeveloperWidget.class,
- PlannedReviewsWidget.class,
- UnplannedReviewsWidget.class,
- ActionPlansWidget.class,
- ReviewsMetricsWidget.class,
- TreemapWidget.class,
- FilterWidget.class,
+ // filters
+ ProjectFilter.class,
+ TreeMapFilter.class,
+ MyFavouritesFilter.class,
- // dashboards
- DefaultDashboard.class,
- HotspotsDashboard.class,
- ReviewsDashboard.class,
- TimeMachineDashboard.class,
- ProjectsDashboard.class,
- TreemapDashboard.class,
- MyFavouritesDashboard.class,
+ // widgets
+ AlertsWidget.class,
+ CoverageWidget.class,
+ ItCoverageWidget.class,
+ CommentsDuplicationsWidget.class,
+ DescriptionWidget.class,
+ ComplexityWidget.class,
+ RulesWidget.class,
+ SizeWidget.class,
+ EventsWidget.class,
+ CustomMeasuresWidget.class,
+ TimelineWidget.class,
+ TimeMachineWidget.class,
+ HotspotMetricWidget.class,
+ HotspotMostViolatedResourcesWidget.class,
+ HotspotMostViolatedRulesWidget.class,
+ MyReviewsWidget.class,
+ ProjectReviewsWidget.class,
+ FalsePositiveReviewsWidget.class,
+ ReviewsPerDeveloperWidget.class,
+ PlannedReviewsWidget.class,
+ UnplannedReviewsWidget.class,
+ ActionPlansWidget.class,
+ ReviewsMetricsWidget.class,
+ TreemapWidget.class,
+ FilterWidget.class,
- // Property sets
- PropertySetDefinitions.class,
- TestPropertySetTemplate.class,
+ // dashboards
+ DefaultDashboard.class,
+ HotspotsDashboard.class,
+ ReviewsDashboard.class,
+ TimeMachineDashboard.class,
+ ProjectsDashboard.class,
+ TreemapDashboard.class,
+ MyFavouritesDashboard.class,
- // chart
- XradarChart.class,
- DistributionBarChart.class,
- DistributionAreaChart.class,
+ // chart
+ XradarChart.class,
+ DistributionBarChart.class,
+ DistributionAreaChart.class,
- // colorizers
- JavaColorizerFormat.class,
+ // colorizers
+ JavaColorizerFormat.class,
- // batch
- ProfileSensor.class,
- ProfileEventsSensor.class,
- ProjectLinksSensor.class,
- UnitTestDecorator.class,
- VersionEventsSensor.class,
- CheckAlertThresholds.class,
- GenerateAlertEvents.class,
- ViolationsDecorator.class,
- WeightedViolationsDecorator.class,
- ViolationsDensityDecorator.class,
- LineCoverageDecorator.class,
- CoverageDecorator.class,
- BranchCoverageDecorator.class,
- ItLineCoverageDecorator.class,
- ItCoverageDecorator.class,
- ItBranchCoverageDecorator.class,
- DefaultResourcePermissions.class,
- ApplyProjectRolesDecorator.class,
- ExcludedResourceFilter.class,
- CommentDensityDecorator.class,
- NoSonarFilter.class,
- DirectoriesDecorator.class,
- FilesDecorator.class,
- ReviewNotifications.class,
- ReviewWorkflowDecorator.class,
- ReferenceAnalysis.class,
- ManualMeasureDecorator.class,
- ManualViolationInjector.class,
- ViolationSeverityUpdater.class,
- IndexProjectPostJob.class,
- ReviewsMeasuresDecorator.class,
+ // batch
+ ProfileSensor.class,
+ ProfileEventsSensor.class,
+ ProjectLinksSensor.class,
+ UnitTestDecorator.class,
+ VersionEventsSensor.class,
+ CheckAlertThresholds.class,
+ GenerateAlertEvents.class,
+ ViolationsDecorator.class,
+ WeightedViolationsDecorator.class,
+ ViolationsDensityDecorator.class,
+ LineCoverageDecorator.class,
+ CoverageDecorator.class,
+ BranchCoverageDecorator.class,
+ ItLineCoverageDecorator.class,
+ ItCoverageDecorator.class,
+ ItBranchCoverageDecorator.class,
+ DefaultResourcePermissions.class,
+ ApplyProjectRolesDecorator.class,
+ ExcludedResourceFilter.class,
+ CommentDensityDecorator.class,
+ NoSonarFilter.class,
+ DirectoriesDecorator.class,
+ FilesDecorator.class,
+ ReviewNotifications.class,
+ ReviewWorkflowDecorator.class,
+ ReferenceAnalysis.class,
+ ManualMeasureDecorator.class,
+ ManualViolationInjector.class,
+ ViolationSeverityUpdater.class,
+ IndexProjectPostJob.class,
+ ReviewsMeasuresDecorator.class,
- // time machine
- TendencyDecorator.class,
- VariationDecorator.class,
- ViolationTrackingDecorator.class,
- ViolationPersisterDecorator.class,
- NewViolationsDecorator.class,
- TimeMachineConfigurationPersister.class,
- NewCoverageFileAnalyzer.class,
- NewItCoverageFileAnalyzer.class,
- NewCoverageAggregator.class);
+ // time machine
+ TendencyDecorator.class,
+ VariationDecorator.class,
+ ViolationTrackingDecorator.class,
+ ViolationPersisterDecorator.class,
+ NewViolationsDecorator.class,
+ TimeMachineConfigurationPersister.class,
+ NewCoverageFileAnalyzer.class,
+ NewItCoverageFileAnalyzer.class,
+ NewCoverageAggregator.class);
}
}
*/
package org.sonar.batch;
-import java.util.Date;
-
import org.apache.commons.configuration.PropertiesConfiguration;
import org.apache.commons.lang.StringUtils;
import org.apache.maven.project.MavenProject;
import org.sonar.api.database.DatabaseSession;
import org.sonar.api.database.model.ResourceModel;
import org.sonar.api.database.model.Snapshot;
-import org.sonar.api.resources.Java;
import org.sonar.api.resources.Project;
import org.sonar.api.utils.SonarException;
+import java.util.Date;
+
public class ProjectConfigurator implements BatchComponent {
private DatabaseSession databaseSession;
import org.sonar.api.batch.bootstrap.ProjectDefinition;
import org.sonar.api.config.PropertyDefinitions;
import org.sonar.api.config.Settings;
-import org.sonar.api.resources.Java;
import org.sonar.api.resources.Project;
import org.sonar.batch.bootstrap.ProjectInitializer;
import org.sonar.core.config.ConfigurationUtils;
import org.junit.Test;
import org.sonar.api.CoreProperties;
import org.sonar.api.config.Settings;
-import org.sonar.api.resources.Java;
import org.sonar.api.resources.Project;
import org.sonar.jpa.test.AbstractDbUnitTestCase;
boolean multiValues() default false;
/**
- * Name of the property set. Used only when type = <code>PropertyType.PROPERTY_SET</code>.
+ * A Property of type <code>PropertyType.PROPERTY_SET</code> can reference a set of properties
+ * by its key.
*
* @since 3.3
*/
- String propertySetName() default "";
+ String propertySetKey() default "";
+
+ /**
+ * A Property with fields is considered a property set.
+ *
+ * @since 3.3
+ */
+ PropertyField[] fields() default {};
}
--- /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;
+
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+/**
+ * Property field.
+ *
+ * @since 3.3
+ */
+@Retention(RetentionPolicy.RUNTIME)
+@Target(ElementType.TYPE)
+public @interface PropertyField {
+ /**
+ * Unique key within a property.
+ */
+ String key();
+
+ /**
+ * The empty string "" is considered as null, so it's not possible to have empty strings for default values.
+ */
+ String defaultValue() default "";
+
+ String name();
+
+ String description() default "";
+
+ PropertyType type() default PropertyType.STRING;
+
+ /**
+ * Options for *_LIST types
+ */
+ String[] options() default {};
+}
private boolean onModule = false;
private boolean isGlobal = true;
private boolean multiValues;
- private String propertySetName;
+ private String propertySetKey;
+ private PropertyFieldDefinition[] fields;
private PropertyDefinition(Property annotation) {
this.key = annotation.key();
this.type = fixType(annotation.key(), annotation.type());
this.options = annotation.options();
this.multiValues = annotation.multiValues();
- this.propertySetName = annotation.propertySetName();
+ propertySetKey = annotation.propertySetKey();
+ this.fields = PropertyFieldDefinition.create(annotation.fields());
}
private static PropertyType fixType(String key, PropertyType type) {
/**
* @since 3.3
*/
- public String getPropertySetName() {
- return propertySetName;
+ public String getPropertySetKey() {
+ return propertySetKey;
+ }
+
+ /**
+ * @since 3.3
+ */
+ public PropertyFieldDefinition[] 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 org.sonar.api.PropertyField;
+import org.sonar.api.PropertyType;
+
+/**
+ * @since 3.3
+ */
+public final class PropertyFieldDefinition {
+ private String key;
+ private String defaultValue;
+ private String name;
+ private PropertyType type = PropertyType.STRING;
+ private String[] options;
+ private String description;
+
+ private PropertyFieldDefinition(PropertyField annotation) {
+ this.key = annotation.key();
+ this.name = annotation.name();
+ this.defaultValue = annotation.defaultValue();
+ this.description = annotation.description();
+ this.type = annotation.type();
+ this.options = annotation.options();
+ }
+
+ public static PropertyFieldDefinition create(PropertyField annotation) {
+ return new PropertyFieldDefinition(annotation);
+ }
+
+ public static PropertyFieldDefinition[] create(PropertyField[] fields) {
+ PropertyFieldDefinition[] definitions = new PropertyFieldDefinition[fields.length];
+
+ for (int i = 0; i < fields.length; i++) {
+ definitions[i] = create(fields[i]);
+ }
+
+ return definitions;
+ }
+
+
+ public String getKey() {
+ return key;
+ }
+
+ public String getDefaultValue() {
+ return defaultValue;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public PropertyType getType() {
+ return type;
+ }
+
+ public String[] getOptions() {
+ return options.clone();
+ }
+
+ public String getDescription() {
+ return 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 com.google.common.collect.Lists;
-
-import java.util.List;
-
-public class PropertySet {
- private final List<PropertySetField> fields = Lists.newArrayList();
-
- public PropertySet add(PropertySetField field) {
- fields.add(field);
- return this;
- }
-
- 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.ImmutableList;
-import com.google.common.collect.Maps;
-import org.sonar.api.ServerExtension;
-
-import java.util.List;
-import java.util.Map;
-import java.util.NoSuchElementException;
-
-public class PropertySetDefinitions implements ServerExtension {
- 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 List<PropertySet> findAll() {
- return ImmutableList.copyOf(index.values());
- }
-
- 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 com.google.common.base.Splitter;
-import com.google.common.collect.ImmutableMap;
-import com.google.common.collect.Lists;
-import org.apache.commons.lang.ArrayUtils;
-import org.sonar.api.utils.DateUtils;
-
-import java.util.Date;
-import java.util.List;
-import java.util.Map;
-
-/**
- * @since 3.3
- */
-public final class PropertySetValue {
- private final Map<String, String> keyValues;
-
- private PropertySetValue(Map<String, String> keyValues) {
- this.keyValues = ImmutableMap.copyOf(keyValues);
- }
-
- public static PropertySetValue create(Map<String, String> keyValues) {
- return new PropertySetValue(keyValues);
- }
-
- /**
- * @return the field as String. If the field does not exist, then an empty string is returned.
- */
- public String getString(String fieldName) {
- String value = keyValues.get(fieldName);
- return (value == null) ? "" : value;
- }
-
- /**
- * @return the field as int. If the field does not exist, then <code>0</code> is returned.
- */
- public int getInt(String fieldName) {
- String value = keyValues.get(fieldName);
- return (value == null) ? 0 : Integer.parseInt(value);
- }
-
- /**
- * @return the field as boolean. If the field does not exist, then <code>false</code> is returned.
- */
- public boolean getBoolean(String fieldName) {
- String value = keyValues.get(fieldName);
- return (value == null) ? false : Boolean.parseBoolean(value);
- }
-
- /**
- * @return the field as float. If the field does not exist, then <code>0.0</code> is returned.
- */
- public float getFloat(String fieldName) {
- String value = keyValues.get(fieldName);
- return (value == null) ? 0f : Float.parseFloat(value);
- }
-
- /**
- * @return the field as long. If the field does not exist, then <code>0L</code> is returned.
- */
- public long getLong(String fieldName) {
- String value = keyValues.get(fieldName);
- return (value == null) ? 0L : Long.parseLong(value);
- }
-
- /**
- * @return the field as Date. If the field does not exist, then <code>null</code> is returned.
- */
- public Date getDate(String fieldName) {
- String value = keyValues.get(fieldName);
- return (value == null) ? null : DateUtils.parseDate(value);
- }
-
- /**
- * @return the field as Date with time. If the field does not exist, then <code>null</code> is returned.
- */
- public Date getDateTime(String fieldName) {
- String value = keyValues.get(fieldName);
- return (value == null) ? null : DateUtils.parseDateTime(value);
- }
-
- /**
- * @return the field as an array of String. If the field does not exist, then an empty array is returned.
- */
- public String[] getStringArray(String fieldName) {
- String value = keyValues.get(fieldName);
- if (value == null) {
- return ArrayUtils.EMPTY_STRING_ARRAY;
- }
-
- List<String> values = Lists.newArrayList();
- for (String v : Splitter.on(",").trimResults().split(value)) {
- values.add(v.replace("%2C", ","));
- }
- return values.toArray(new String[values.size()]);
- }
-}
*/
package org.sonar.api.config;
-import com.google.common.collect.Iterables;
-
import com.google.common.base.Joiner;
import com.google.common.base.Splitter;
import com.google.common.base.Strings;
import org.apache.commons.lang.ArrayUtils;
import org.apache.commons.lang.StringUtils;
import org.sonar.api.BatchComponent;
-import org.sonar.api.PropertyType;
import org.sonar.api.ServerComponent;
import org.sonar.api.utils.DateUtils;
import javax.annotation.Nullable;
-import java.util.*;
-import java.util.regex.Matcher;
-import java.util.regex.Pattern;
+
+import java.util.Collections;
+import java.util.Date;
+import java.util.List;
+import java.util.Map;
+import java.util.Properties;
/**
* Project Settings on batch side, Global Settings on server side. This component does not access to database, so
return getStringArrayBySeparator(key, ",");
}
- public final PropertySetValue getPropertySetValue(String key) {
- PropertyDefinition property = getDefinitions().get(key);
- if ((null == property) || (property.getType() != PropertyType.PROPERTY_SET)) {
- throw new IllegalArgumentException("Property " + key + " is not of type PROPERTY_SET");
- }
-
- String propertySetName = property.getPropertySetName();
- String valueName = getString(key);
- String propertySetJson = getString("sonar.property_set." + propertySetName);
-
- return PropertySetValue.create(lowTechJsonParsing(valueName, propertySetJson));
- }
-
- private static Map<String, String> lowTechJsonParsing(String valueName, String json) {
- return Maps.newHashMap();
- }
-
/**
* Value is split by carriage returns.
*
+++ /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 class TestPropertySetTemplate extends PropertySetTemplate {
- public PropertySet createPropertySet() {
- return new PropertySet()
- .add(PropertySetField.create("firstName", PropertyType.TEXT))
- .add(PropertySetField.create("lastName", PropertyType.TEXT));
- }
-
- public String getName() {
- return "test";
- }
-}
import org.apache.commons.lang.StringUtils;
import org.apache.commons.lang.builder.EqualsBuilder;
import org.apache.commons.lang.builder.HashCodeBuilder;
-import org.sonar.api.database.model.ResourceModel;
import org.sonar.api.rules.ActiveRule;
import org.sonar.api.rules.Rule;
import org.sonar.api.rules.RulePriority;
-import javax.persistence.*;
+import javax.persistence.CascadeType;
+import javax.persistence.Column;
+import javax.persistence.Entity;
+import javax.persistence.FetchType;
+import javax.persistence.GeneratedValue;
+import javax.persistence.Id;
+import javax.persistence.OneToMany;
+import javax.persistence.Table;
+
import java.util.ArrayList;
import java.util.List;
*/
package org.sonar.api.config;
+import org.sonar.api.PropertyField;
+
import org.junit.Test;
import org.sonar.api.Properties;
import org.sonar.api.Property;
assertThat(def.isOnProject()).isTrue();
assertThat(def.isOnModule()).isTrue();
assertThat(def.isMultiValues()).isTrue();
- assertThat(def.getPropertySetName()).isEmpty();
+ assertThat(def.getPropertySetKey()).isEqualTo("set");
+ assertThat(def.getFields()).isEmpty();
}
@Properties(@Property(key = "hello", name = "Hello", defaultValue = "world", description = "desc",
- options = {"de", "en"}, category = "categ", type = PropertyType.FLOAT, global = false, project = true, module = true, multiValues = true))
+ options = {"de", "en"}, category = "categ", type = PropertyType.FLOAT, global = false, project = true, module = true, multiValues = true, propertySetKey = "set"))
static class Init {
}
assertThat(def.isOnProject()).isFalse();
assertThat(def.isOnModule()).isFalse();
assertThat(def.isMultiValues()).isFalse();
+ assertThat(def.getPropertySetKey()).isEmpty();
+ assertThat(def.getFields()).isEmpty();
}
- @Properties(@Property(key = "hello", name = "Hello", type = PropertyType.PROPERTY_SET, propertySetName = "set1"))
+ @Properties(@Property(key = "hello", name = "Hello", fields = {
+ @PropertyField(key = "first", name = "First"),
+ @PropertyField(key = "second", name = "Second", type = PropertyType.INTEGER)}))
static class WithPropertySet {
}
PropertyDefinition def = PropertyDefinition.create(prop);
- assertThat(def.getType()).isEqualTo(PropertyType.PROPERTY_SET);
- assertThat(def.getPropertySetName()).isEqualTo("set1");
+ assertThat(def.getFields()).hasSize(2);
+ assertThat(def.getFields()[0].getKey()).isEqualTo("first");
+ assertThat(def.getFields()[0].getName()).isEqualTo("First");
+ assertThat(def.getFields()[0].getType()).isEqualTo(PropertyType.STRING);
+ assertThat(def.getFields()[1].getKey()).isEqualTo("second");
+ assertThat(def.getFields()[1].getName()).isEqualTo("Second");
+ assertThat(def.getFields()[1].getType()).isEqualTo(PropertyType.INTEGER);
}
@Properties(@Property(key = "hello", name = "Hello"))
+++ /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);
- assertThat(definitions.findAll()).containsOnly(set, 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);
- }
-}
+++ /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.ImmutableMap;
-import com.google.common.collect.Maps;
-import org.junit.Test;
-
-import static org.fest.assertions.Assertions.assertThat;
-
-public class PropertySetValueTest {
- @Test
- public void should_get_default_values() {
- PropertySetValue value = PropertySetValue.create(Maps.<String, String>newHashMap());
-
- assertThat(value.getString("UNKNOWN")).isEmpty();
- assertThat(value.getInt("UNKNOWN")).isZero();
- assertThat(value.getFloat("UNKNOWN")).isZero();
- assertThat(value.getLong("UNKNOWN")).isZero();
- assertThat(value.getDate("UNKNOWN")).isNull();
- assertThat(value.getDateTime("UNKNOWN")).isNull();
- assertThat(value.getStringArray("UNKNOWN")).isEmpty();
- }
-
- @Test
- public void should_get_values() {
- PropertySetValue value = PropertySetValue.create(ImmutableMap.<String, String>builder()
- .put("age", "12")
- .put("child", "true")
- .put("size", "12.4")
- .put("distance", "1000000000")
- .put("array", "1,2,3,4,5")
- .put("birth", "1975-01-29")
- .put("now", "2012-09-25T10:08:30+0100")
- .build());
-
- assertThat(value.getString("age")).isEqualTo("12");
- assertThat(value.getInt("age")).isEqualTo(12);
- assertThat(value.getBoolean("child")).isTrue();
- assertThat(value.getFloat("size")).isEqualTo(12.4f);
- assertThat(value.getLong("distance")).isEqualTo(1000000000L);
- assertThat(value.getStringArray("array")).contains("1", "2", "3", "4", "5");
- assertThat(value.getDate("birth")).isNotNull();
- assertThat(value.getDateTime("now")).isNotNull();
- }
-}
*/
package org.sonar.api.config;
-import org.junit.Ignore;
-
import com.google.common.collect.ImmutableMap;
import org.junit.Before;
import org.junit.Rule;
@Property(key = "integer", name = "Integer", defaultValue = "12345"),
@Property(key = "array", name = "Array", defaultValue = "one,two,three"),
@Property(key = "multi_values", name = "Array", defaultValue = "1,2,3", multiValues = true),
- @Property(key = "sonar.jira", name = "Jira Server", type = PropertyType.PROPERTY_SET, propertySetName = "jira")
+ @Property(key = "sonar.jira", name = "Jira Server", type = PropertyType.PROPERTY_SET, propertySetKey = "jira")
})
static class Init {
}
public void getStringArray() {
Settings settings = new Settings(definitions);
String[] array = settings.getStringArray("array");
- assertThat(array).isEqualTo(new String[]{"one", "two", "three"});
+ assertThat(array).isEqualTo(new String[] {"one", "two", "three"});
}
@Test
public void setStringArray() {
Settings settings = new Settings(definitions);
- settings.setProperty("multi_values", new String[]{"A", "B"});
+ settings.setProperty("multi_values", new String[] {"A", "B"});
String[] array = settings.getStringArray("multi_values");
- assertThat(array).isEqualTo(new String[]{"A", "B"});
+ assertThat(array).isEqualTo(new String[] {"A", "B"});
}
@Test
public void setStringArrayTrimValues() {
Settings settings = new Settings(definitions);
- settings.setProperty("multi_values", new String[]{" A ", " B "});
+ settings.setProperty("multi_values", new String[] {" A ", " B "});
String[] array = settings.getStringArray("multi_values");
- assertThat(array).isEqualTo(new String[]{"A", "B"});
+ assertThat(array).isEqualTo(new String[] {"A", "B"});
}
@Test
public void setStringArrayEscapeCommas() {
Settings settings = new Settings(definitions);
- settings.setProperty("multi_values", new String[]{"A,B", "C,D"});
+ settings.setProperty("multi_values", new String[] {"A,B", "C,D"});
String[] array = settings.getStringArray("multi_values");
- assertThat(array).isEqualTo(new String[]{"A,B", "C,D"});
+ assertThat(array).isEqualTo(new String[] {"A,B", "C,D"});
}
@Test
public void setStringArrayWithEmptyValues() {
Settings settings = new Settings(definitions);
- settings.setProperty("multi_values", new String[]{"A,B", "", "C,D"});
+ settings.setProperty("multi_values", new String[] {"A,B", "", "C,D"});
String[] array = settings.getStringArray("multi_values");
- assertThat(array).isEqualTo(new String[]{"A,B", "", "C,D"});
+ assertThat(array).isEqualTo(new String[] {"A,B", "", "C,D"});
}
@Test
public void setStringArrayWithNullValues() {
Settings settings = new Settings(definitions);
- settings.setProperty("multi_values", new String[]{"A,B", null, "C,D"});
+ settings.setProperty("multi_values", new String[] {"A,B", null, "C,D"});
String[] array = settings.getStringArray("multi_values");
- assertThat(array).isEqualTo(new String[]{"A,B", "", "C,D"});
+ assertThat(array).isEqualTo(new String[] {"A,B", "", "C,D"});
}
@Test(expected = IllegalStateException.class)
public void shouldFailToSetArrayValueOnSingleValueProperty() {
Settings settings = new Settings(definitions);
- settings.setProperty("array", new String[]{"A", "B", "C"});
+ settings.setProperty("array", new String[] {"A", "B", "C"});
}
@Test
Settings settings = new Settings();
settings.setProperty("foo", " one, two, three ");
String[] array = settings.getStringArray("foo");
- assertThat(array).isEqualTo(new String[]{"one", "two", "three"});
+ assertThat(array).isEqualTo(new String[] {"one", "two", "three"});
}
@Test
Settings settings = new Settings();
settings.setProperty("foo", " one, , two");
String[] array = settings.getStringArray("foo");
- assertThat(array).isEqualTo(new String[]{"one", "", "two"});
+ assertThat(array).isEqualTo(new String[] {"one", "", "two"});
}
@Test
public void getStringLines_single_line() {
Settings settings = new Settings();
settings.setProperty("foo", "the line");
- assertThat(settings.getStringLines("foo")).isEqualTo(new String[]{"the line"});
+ assertThat(settings.getStringLines("foo")).isEqualTo(new String[] {"the line"});
}
@Test
public void getStringLines_linux() {
Settings settings = new Settings();
settings.setProperty("foo", "one\ntwo");
- assertThat(settings.getStringLines("foo")).isEqualTo(new String[]{"one", "two"});
+ assertThat(settings.getStringLines("foo")).isEqualTo(new String[] {"one", "two"});
settings.setProperty("foo", "one\ntwo\n");
- assertThat(settings.getStringLines("foo")).isEqualTo(new String[]{"one", "two"});
+ assertThat(settings.getStringLines("foo")).isEqualTo(new String[] {"one", "two"});
}
@Test
public void getStringLines_windows() {
Settings settings = new Settings();
settings.setProperty("foo", "one\r\ntwo");
- assertThat(settings.getStringLines("foo")).isEqualTo(new String[]{"one", "two"});
+ assertThat(settings.getStringLines("foo")).isEqualTo(new String[] {"one", "two"});
settings.setProperty("foo", "one\r\ntwo\r\n");
- assertThat(settings.getStringLines("foo")).isEqualTo(new String[]{"one", "two"});
+ assertThat(settings.getStringLines("foo")).isEqualTo(new String[] {"one", "two"});
}
@Test
public void getStringLines_mix() {
Settings settings = new Settings();
settings.setProperty("foo", "one\r\ntwo\nthree");
- assertThat(settings.getStringLines("foo")).isEqualTo(new String[]{"one", "two", "three"});
+ assertThat(settings.getStringLines("foo")).isEqualTo(new String[] {"one", "two", "three"});
}
@Test
assertThat(settings.getKeysStartingWith("sonar.jdbc")).containsOnly("sonar.jdbc.url", "sonar.jdbc.username");
assertThat(settings.getKeysStartingWith("other")).hasSize(0);
}
-
- @Test
- @Ignore
- public void should_get_property_set_value() {
- Settings settings = new Settings(definitions);
- settings.setProperty("sonar.property_set.jira",
- "[{\"set\": {\"name\": \"codehaus_jira\", \"values\": {\"key1\":\"value1\", \"key2\":\"value2\"}}},{\"set\": {\"name\": \"other\", \"values\": {\"key3\":\"value3\"}}}]");
-
- settings.setProperty("sonar.jira", "codehaus_jira");
- assertThat(settings.getPropertySetValue("sonar.jira").getString("key1")).isEqualTo("value1");
- assertThat(settings.getPropertySetValue("sonar.jira").getString("key2")).isEqualTo("value2");
-
- settings.setProperty("sonar.jira", "other");
- assertThat(settings.getPropertySetValue("sonar.jira").getString("key3")).isEqualTo("value3");
- }
}
import org.sonar.core.i18n.RuleI18nManager;
import org.sonar.core.metric.DefaultMetricFinder;
import org.sonar.core.notification.DefaultNotificationManager;
-import org.sonar.core.persistence.*;
+import org.sonar.core.persistence.DaoUtils;
+import org.sonar.core.persistence.DatabaseMigrator;
+import org.sonar.core.persistence.DatabaseVersion;
+import org.sonar.core.persistence.DefaultDatabase;
+import org.sonar.core.persistence.MyBatis;
import org.sonar.core.qualitymodel.DefaultModelFinder;
import org.sonar.core.rule.DefaultRuleFinder;
import org.sonar.core.user.DefaultUserFinder;
import org.sonar.server.filters.FilterExecutor;
import org.sonar.server.notifications.NotificationService;
import org.sonar.server.notifications.reviews.ReviewsNotificationManager;
-import org.sonar.server.plugins.*;
+import org.sonar.server.plugins.ApplicationDeployer;
+import org.sonar.server.plugins.DefaultServerPluginRepository;
+import org.sonar.server.plugins.PluginDeployer;
+import org.sonar.server.plugins.PluginDownloader;
+import org.sonar.server.plugins.ServerExtensionInstaller;
+import org.sonar.server.plugins.UpdateCenterClient;
+import org.sonar.server.plugins.UpdateCenterMatrixFactory;
import org.sonar.server.qualitymodel.DefaultModelManager;
import org.sonar.server.rules.ProfilesConsole;
import org.sonar.server.rules.RulesConsole;
-import org.sonar.server.startup.*;
-import org.sonar.server.ui.*;
+import org.sonar.server.startup.ActivateDefaultProfiles;
+import org.sonar.server.startup.DeleteDeprecatedMeasures;
+import org.sonar.server.startup.GeneratePluginIndex;
+import org.sonar.server.startup.GwtPublisher;
+import org.sonar.server.startup.JdbcDriverDeployer;
+import org.sonar.server.startup.RegisterMetrics;
+import org.sonar.server.startup.RegisterNewDashboards;
+import org.sonar.server.startup.RegisterNewFilters;
+import org.sonar.server.startup.RegisterProvidedProfiles;
+import org.sonar.server.startup.RegisterQualityModels;
+import org.sonar.server.startup.RegisterRules;
+import org.sonar.server.startup.ServerMetadataPersister;
+import org.sonar.server.ui.CodeColorizers;
+import org.sonar.server.ui.JRubyI18n;
+import org.sonar.server.ui.PageDecorations;
+import org.sonar.server.ui.SecurityRealmFactory;
+import org.sonar.server.ui.Views;
import javax.servlet.ServletContext;
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();
- }
-}
import com.google.common.collect.Lists;
import org.slf4j.LoggerFactory;
import org.sonar.api.CoreProperties;
-import org.sonar.api.config.*;
+import org.sonar.api.config.License;
+import org.sonar.api.config.PropertyDefinitions;
+import org.sonar.api.config.Settings;
import org.sonar.api.platform.ComponentContainer;
import org.sonar.api.platform.NewUserHandler;
import org.sonar.api.platform.PluginMetadata;
import org.sonar.api.rules.RulePriority;
import org.sonar.api.rules.RuleRepository;
import org.sonar.api.utils.ValidationMessages;
-import org.sonar.api.web.*;
+import org.sonar.api.web.Footer;
+import org.sonar.api.web.NavigationSection;
+import org.sonar.api.web.Page;
+import org.sonar.api.web.RubyRailsWebservice;
+import org.sonar.api.web.Widget;
import org.sonar.api.workflow.Review;
import org.sonar.api.workflow.internal.DefaultReview;
import org.sonar.api.workflow.internal.DefaultWorkflowContext;
import org.sonar.server.filters.FilterExecutor;
import org.sonar.server.filters.FilterResult;
import org.sonar.server.notifications.reviews.ReviewsNotificationManager;
-import org.sonar.server.platform.*;
-import org.sonar.server.plugins.*;
+import org.sonar.server.platform.NewUserNotifier;
+import org.sonar.server.platform.Platform;
+import org.sonar.server.platform.ServerIdGenerator;
+import org.sonar.server.platform.ServerSettings;
+import org.sonar.server.platform.SettingsChangeNotifier;
+import org.sonar.server.plugins.DefaultServerPluginRepository;
+import org.sonar.server.plugins.PluginDeployer;
+import org.sonar.server.plugins.PluginDownloader;
+import org.sonar.server.plugins.UpdateCenterMatrix;
+import org.sonar.server.plugins.UpdateCenterMatrixFactory;
import org.sonar.server.rules.ProfilesConsole;
import org.sonar.server.rules.RulesConsole;
import org.sonar.updatecenter.common.Version;
import javax.annotation.Nullable;
+
import java.net.InetAddress;
import java.sql.Connection;
import java.util.Collection;
public void ruleSeverityChanged(int parentProfileId, int activeRuleId, int oldSeverityId, int newSeverityId, String userName) {
getProfilesManager().ruleSeverityChanged(parentProfileId, activeRuleId, RulePriority.values()[oldSeverityId],
- RulePriority.values()[newSeverityId], userName);
+ RulePriority.values()[newSeverityId], userName);
}
public void ruleDeactivated(int parentProfileId, int deactivatedRuleId, String userName) {
// notifier is null when creating the administrator in the migration script 011.
if (notifier != null) {
notifier.onNewUser(NewUserHandler.Context.builder()
- .setLogin(fields.get("login"))
- .setName(fields.get("name"))
- .setEmail(fields.get("email"))
- .build());
+ .setLogin(fields.get("login"))
+ .setName(fields.get("name"))
+ .setEmail(fields.get("email"))
+ .build());
}
}
-
- public List<PropertySet> listPropertySets() {
- return get(PropertySetDefinitions.class).findAll();
- }
}
def input_name(property)
h(property.key) + (property.multi_values ? '[]' : '')
end
-
- def property_set_value_names(property)
- names = PropertySet.findAll(property.propertySetName).map(&:name);
- Api::Utils.insensitive_sort(names)
- end
end
+++ /dev/null
-#
-# Sonar, entreprise quality control 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 {library}; if not, write to the Free Software
-# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
-#
-class PropertySet < ActiveRecord::Base
- attr_accessor :name
-
- def self.columns
- @columns ||= [];
- end
-
- def self.column(name, sql_type = nil, default = nil, null = true)
- columns << ActiveRecord::ConnectionAdapters::Column.new(name.to_s, default, sql_type.to_s, null)
- end
-
- def self.findAll(set_name)
- ActiveSupport::JSON.decode(values_as_json(set_name)).map { |set| PropertySet.new(set) }
- end
-
- def save(validate = true)
- validate ? valid? : true
- end
-
- private
-
- def self.values_as_json(set_name)
- json = Property.value('sonar.property_set.' + set_name)
-
- #json || '[]'
- json || '[{"name":"set2"},{"name":"set1"}]'
- end
-end
<div class="multi_value marginbottom5">
- <%= render "settings/type_#{property_type(property, value)}", :property => property, :value => value -%>
+ <%= render "settings/single_value", :property => property, :value => value -%>
<% if delete_link -%>
<a href="#" class="delete link-action"><%= message('delete') -%></a>
<% end -%>
<button class="add_value"><%= message('settings.add') -%></button>
<br/>
<% else -%>
- <%= render "settings/type_#{property_type(property, value)}", :property => property, :value => value -%>
+ <%= render "settings/single_value", :property => property, :value => value -%>
<% end -%>
<% p = @updated_properties[property.key] if @updated_properties -%>
--- /dev/null
+<% if property.fields.blank? -%>
+ <%= render "settings/type_#{property_type(property, value)}", :property => property, :value => value -%>
+<% else -%>
+ <%= render "settings/type_PROPERTY_SET_DEFINITION", :property => property, :value => value -%>
+<% end -%>
\ No newline at end of file
-<select name="<%= input_name(property) -%>" id="input_<%= h property.key -%>">
+<select name="<%= input_name(property) -%>" id="input_<%= h property.getKey() -%>">
<option value=""><%= message('default') -%></option>
- <% property_set_value_names(property).each do |option| %>
- <option value="<%= h option -%>" <%= 'selected' if value && value==option -%>><%= h option -%></option>
- <% end %>
-</select>
-<a id="edit-set-<%= h property.key -%>" href="property_sets/index" class="open-modal link-action">Edit property set...</a>
+
+ <% Property.values(property.propertySetKey).reject(&:blank?).each do |set_key| -%>
+ <option value="<%= set_key -%>"><%= set_key -%></option>
+ <% end -%>
+</select>
\ No newline at end of file
--- /dev/null
+<% Property.set('sonar.test.jira.servers', 'jira1,jira2') -%>
+<% Property.set('sonar.test.jira.servers.jira1.url', 'http://url1') -%>
+<% Property.set('sonar.test.jira.servers.jira1.port', '1234') -%>
+<% Property.set('sonar.test.jira.servers.jira2.url', 'http://url2') -%>
+<% Property.set('sonar.test.jira.servers.jira2.port', '9999') -%>
+
+<% Property.values(property.key).reject(&:blank?).each do |set_key| -%>
+ <h3><%= set_key -%></h3>
+
+ <% property.fields.each do |field| -%>
+ <label><%= field.key -%>: </label><input type="text" value="<%= Property.value([property.key, set_key, field.key].join('.')) -%>"/><br/>
+ <% end -%>
+
+ <a href="#" class="delete link-action"><%= message('delete') -%></a>
+<% end -%>
+
+<button class="add_value"><%= message('settings.add') -%></button>
+++ /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);
- }
-}