From 4beff81ee4fac226c2813e41b27c920d65accbd4 Mon Sep 17 00:00:00 2001 From: David Gageot Date: Mon, 24 Sep 2012 15:38:40 +0200 Subject: [PATCH] SONAR-3529 API: ability to define property sets. Fix server startup --- .../org/sonar/plugins/core/CorePlugin.java | 282 +++++++----------- .../main/java/org/sonar/api/PropertyType.java | 9 +- .../api/config/TestPropertySetTemplate.java | 34 +++ .../controllers/property_sets_controller.rb | 29 ++ .../app/views/property_sets/index.html.erb | 6 + .../settings/_type_PROPERTY_SET.html.erb | 1 + 6 files changed, 192 insertions(+), 169 deletions(-) create mode 100644 sonar-plugin-api/src/main/java/org/sonar/api/config/TestPropertySetTemplate.java create mode 100644 sonar-server/src/main/webapp/WEB-INF/app/controllers/property_sets_controller.rb create mode 100644 sonar-server/src/main/webapp/WEB-INF/app/views/property_sets/index.html.erb create mode 100644 sonar-server/src/main/webapp/WEB-INF/app/views/settings/_type_PROPERTY_SET.html.erb diff --git a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/CorePlugin.java b/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/CorePlugin.java index f13c9e1b275..710fdd66929 100644 --- a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/CorePlugin.java +++ b/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/CorePlugin.java @@ -20,13 +20,10 @@ package org.sonar.plugins.core; import com.google.common.collect.ImmutableList; -import org.sonar.api.CoreProperties; -import org.sonar.api.Extension; -import org.sonar.api.Properties; -import org.sonar.api.Property; -import org.sonar.api.PropertyType; -import org.sonar.api.SonarPlugin; +import org.sonar.api.*; 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; @@ -36,80 +33,19 @@ import org.sonar.plugins.core.charts.DistributionAreaChart; 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.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.dashboards.*; 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.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.sensors.*; import org.sonar.plugins.core.testdetailsviewer.TestsViewerDefinition; -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.timemachine.*; import org.sonar.plugins.core.web.Lcom4Viewer; -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.*; import org.sonar.plugins.core.widgets.actionPlans.ActionPlansWidget; -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 org.sonar.plugins.core.widgets.reviews.*; import java.util.List; @@ -122,6 +58,12 @@ import java.util.List; project = false, global = true, category = CoreProperties.CATEGORY_GENERAL), + @Property( + key = "toto", + name = "Toto", + global = true, + type = PropertyType.PROPERTY_SET, + category = CoreProperties.CATEGORY_GENERAL), @Property( key = CoreProperties.PROJECT_LANGUAGE_PROPERTY, defaultValue = Java.KEY, @@ -311,111 +253,115 @@ public final class CorePlugin extends SonarPlugin { @SuppressWarnings("unchecked") public List> getExtensions() { return ImmutableList.of( - DefaultResourceTypes.class, - UserManagedMetrics.class, - ProjectFileSystemLogger.class, + DefaultResourceTypes.class, + UserManagedMetrics.class, + ProjectFileSystemLogger.class, + + // maven + MavenInitializer.class, - // maven - MavenInitializer.class, + // languages + Java.class, - // languages - Java.class, + // pages + TestsViewerDefinition.class, + Lcom4Viewer.class, - // pages - TestsViewerDefinition.class, - Lcom4Viewer.class, + // filters + ProjectFilter.class, + TreeMapFilter.class, + MyFavouritesFilter.class, - // filters - ProjectFilter.class, - TreeMapFilter.class, - MyFavouritesFilter.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, - // 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, + // dashboards + DefaultDashboard.class, + HotspotsDashboard.class, + ReviewsDashboard.class, + TimeMachineDashboard.class, + ProjectsDashboard.class, + TreemapDashboard.class, + MyFavouritesDashboard.class, - // dashboards - DefaultDashboard.class, - HotspotsDashboard.class, - ReviewsDashboard.class, - TimeMachineDashboard.class, - ProjectsDashboard.class, - TreemapDashboard.class, - MyFavouritesDashboard.class, + // Property sets + PropertySetDefinitions.class, + TestPropertySetTemplate.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); } } diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/PropertyType.java b/sonar-plugin-api/src/main/java/org/sonar/api/PropertyType.java index 39d0bb63b54..ceb0c274d51 100644 --- a/sonar-plugin-api/src/main/java/org/sonar/api/PropertyType.java +++ b/sonar-plugin-api/src/main/java/org/sonar/api/PropertyType.java @@ -73,5 +73,12 @@ public enum PropertyType { * * @since 3.2 */ - REGULAR_EXPRESSION + REGULAR_EXPRESSION, + + /** + * Property set instance + * + * @since 3.3 + */ + PROPERTY_SET } diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/config/TestPropertySetTemplate.java b/sonar-plugin-api/src/main/java/org/sonar/api/config/TestPropertySetTemplate.java new file mode 100644 index 00000000000..fdc53be8a2a --- /dev/null +++ b/sonar-plugin-api/src/main/java/org/sonar/api/config/TestPropertySetTemplate.java @@ -0,0 +1,34 @@ +/* + * 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"; + } +} diff --git a/sonar-server/src/main/webapp/WEB-INF/app/controllers/property_sets_controller.rb b/sonar-server/src/main/webapp/WEB-INF/app/controllers/property_sets_controller.rb new file mode 100644 index 00000000000..185a439e758 --- /dev/null +++ b/sonar-server/src/main/webapp/WEB-INF/app/controllers/property_sets_controller.rb @@ -0,0 +1,29 @@ +# +# 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 Sonar; if not, write to the Free Software +# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02 +# +class PropertySetsController < ApplicationController + + SECTION=Navigation::SECTION_CONFIGURATION + before_filter :admin_required + + def index + @property_sets = java_facade.listPropertySets() + end + +end diff --git a/sonar-server/src/main/webapp/WEB-INF/app/views/property_sets/index.html.erb b/sonar-server/src/main/webapp/WEB-INF/app/views/property_sets/index.html.erb new file mode 100644 index 00000000000..37f9e572498 --- /dev/null +++ b/sonar-server/src/main/webapp/WEB-INF/app/views/property_sets/index.html.erb @@ -0,0 +1,6 @@ +<% @property_sets.each do |property_set| -%> + <% property_set.fields.each do |field| -%> + <%= field.name %> + <%= field.type %> + <% end -%> +<% end -%> \ No newline at end of file diff --git a/sonar-server/src/main/webapp/WEB-INF/app/views/settings/_type_PROPERTY_SET.html.erb b/sonar-server/src/main/webapp/WEB-INF/app/views/settings/_type_PROPERTY_SET.html.erb new file mode 100644 index 00000000000..a27d0b0dc2c --- /dev/null +++ b/sonar-server/src/main/webapp/WEB-INF/app/views/settings/_type_PROPERTY_SET.html.erb @@ -0,0 +1 @@ +NOT IMPLEMENTED YET \ No newline at end of file -- 2.39.5