From: Simon Brandhof Date: Wed, 27 May 2015 10:11:02 +0000 (+0200) Subject: SONAR-6370 move the remaining extensions out of core plugin X-Git-Tag: 5.2-RC1~1803 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=9c1417ee34fcf0f4da7553baa6f9d6a1657d7157;p=sonarqube.git SONAR-6370 move the remaining extensions out of core plugin --- 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 cd0b8687a3c..289cb0a9ccd 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 @@ -19,14 +19,13 @@ */ package org.sonar.plugins.core; -import com.google.common.collect.ImmutableList; +import java.util.Collections; import java.util.List; import org.sonar.api.CoreProperties; import org.sonar.api.Properties; import org.sonar.api.Property; import org.sonar.api.PropertyType; import org.sonar.api.SonarPlugin; -import org.sonar.plugins.core.notifications.alerts.NewAlerts; @Properties({ @Property( @@ -190,17 +189,7 @@ public final class CorePlugin extends SonarPlugin { @SuppressWarnings("rawtypes") @Override public List getExtensions() { - ImmutableList.Builder extensions = ImmutableList.builder(); - - extensions.add( - DefaultResourceTypes.class, - UserManagedMetrics.class, - - // Notify alerts on my favourite projects - NewAlerts.class, - NewAlerts.newMetadata()); - - return extensions.build(); + return Collections.emptyList(); } } diff --git a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/DefaultResourceTypes.java b/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/DefaultResourceTypes.java deleted file mode 100644 index dcb0f91f6e0..00000000000 --- a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/DefaultResourceTypes.java +++ /dev/null @@ -1,82 +0,0 @@ -/* - * SonarQube, open source software quality management tool. - * Copyright (C) 2008-2014 SonarSource - * mailto:contact AT sonarsource DOT com - * - * SonarQube 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. - * - * SonarQube 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 this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -package org.sonar.plugins.core; - -import org.sonar.api.batch.BatchSide; -import org.sonar.api.ExtensionProvider; -import org.sonar.api.server.ServerSide; -import org.sonar.api.batch.InstantiationStrategy; -import org.sonar.api.resources.Qualifiers; -import org.sonar.api.resources.ResourceType; -import org.sonar.api.resources.ResourceTypeTree; - -@BatchSide -@ServerSide -@InstantiationStrategy(InstantiationStrategy.PER_BATCH) -public final class DefaultResourceTypes extends ExtensionProvider { - - private static final String SUPPORTS_MEASURE_FILTERS = "supportsMeasureFilters"; - private static final String CONFIGURABLE = "configurable"; - private static final String UPDATABLE_KEY = "updatable_key"; - - @Override - public ResourceTypeTree provide() { - - return ResourceTypeTree.builder() - .addType(ResourceType.builder(Qualifiers.PROJECT) - .setProperty("deletable", true) - .setProperty("supportsGlobalDashboards", true) - .setProperty("modifiable_history", true) - .setProperty("hasRolePolicy", true) - .setProperty(UPDATABLE_KEY, true) - .setProperty(SUPPORTS_MEASURE_FILTERS, true) - .setProperty("comparable", true) - .setProperty(CONFIGURABLE, true) - .build()) - .addType(ResourceType.builder(Qualifiers.MODULE) - .setProperty(UPDATABLE_KEY, true) - .setProperty(SUPPORTS_MEASURE_FILTERS, true) - .setProperty(CONFIGURABLE, true) - .build()) - .addType(ResourceType.builder(Qualifiers.DIRECTORY) - .setProperty(SUPPORTS_MEASURE_FILTERS, true) - .build()) - .addType(ResourceType.builder(Qualifiers.PACKAGE) - .build()) - .addType(ResourceType.builder(Qualifiers.FILE) - .hasSourceCode() - .setProperty(SUPPORTS_MEASURE_FILTERS, true) - .build()) - .addType(ResourceType.builder(Qualifiers.CLASS) - .hasSourceCode() - .build()) - .addType(ResourceType.builder(Qualifiers.UNIT_TEST_FILE) - .hasSourceCode() - .setProperty(SUPPORTS_MEASURE_FILTERS, true) - .build()) - - .addRelations(Qualifiers.PROJECT, Qualifiers.MODULE) - .addRelations(Qualifiers.MODULE, Qualifiers.DIRECTORY, Qualifiers.PACKAGE) - .addRelations(Qualifiers.DIRECTORY, Qualifiers.FILE, Qualifiers.UNIT_TEST_FILE) - .addRelations(Qualifiers.PACKAGE, Qualifiers.CLASS, Qualifiers.UNIT_TEST_FILE) - - .build(); - } -} diff --git a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/UserManagedMetrics.java b/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/UserManagedMetrics.java deleted file mode 100644 index 4014e515c44..00000000000 --- a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/UserManagedMetrics.java +++ /dev/null @@ -1,53 +0,0 @@ -/* - * SonarQube, open source software quality management tool. - * Copyright (C) 2008-2014 SonarSource - * mailto:contact AT sonarsource DOT com - * - * SonarQube 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. - * - * SonarQube 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 this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -package org.sonar.plugins.core; - -import com.google.common.collect.ImmutableList; -import org.sonar.api.measures.Metric; -import org.sonar.api.measures.Metrics; - -import java.util.List; - -public final class UserManagedMetrics implements Metrics { - private static final String DOMAIN = "Management"; - - @Override - public List getMetrics() { - return ImmutableList.of( - new Metric.Builder("burned_budget", "Burned budget", Metric.ValueType.FLOAT) - .setDirection(Metric.DIRECTION_NONE) - .setQualitative(false) - .setDomain(DOMAIN) - .setUserManaged(true) - .create(), - new Metric.Builder("business_value", "Business value", Metric.ValueType.FLOAT) - .setDirection(Metric.DIRECTION_BETTER) - .setQualitative(true) - .setDomain(DOMAIN) - .setUserManaged(true) - .create(), - new Metric.Builder("team_size", "Team size", Metric.ValueType.INT) - .setDirection(Metric.DIRECTION_NONE) - .setQualitative(false) - .setDomain(DOMAIN) - .setUserManaged(true) - .create()); - } -} diff --git a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/issue/package-info.java b/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/issue/package-info.java deleted file mode 100644 index 3fd527aef96..00000000000 --- a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/issue/package-info.java +++ /dev/null @@ -1,23 +0,0 @@ -/* - * SonarQube, open source software quality management tool. - * Copyright (C) 2008-2014 SonarSource - * mailto:contact AT sonarsource DOT com - * - * SonarQube 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. - * - * SonarQube 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 this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -@ParametersAreNonnullByDefault -package org.sonar.plugins.core.issue; - -import javax.annotation.ParametersAreNonnullByDefault; diff --git a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/notifications/alerts/NewAlerts.java b/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/notifications/alerts/NewAlerts.java deleted file mode 100644 index b6c4bd93d1a..00000000000 --- a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/notifications/alerts/NewAlerts.java +++ /dev/null @@ -1,72 +0,0 @@ -/* - * SonarQube, open source software quality management tool. - * Copyright (C) 2008-2014 SonarSource - * mailto:contact AT sonarsource DOT com - * - * SonarQube 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. - * - * SonarQube 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 this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -package org.sonar.plugins.core.notifications.alerts; - -import com.google.common.collect.Multimap; -import org.sonar.api.notifications.*; - -import java.util.Collection; -import java.util.Map; -import org.sonar.core.notification.NotificationDispatcher; -import org.sonar.core.notification.NotificationDispatcherMetadata; -import org.sonar.core.notification.NotificationManager; - -/** - * This dispatcher means: "notify me each new alert event". - * - * @since 3.5 - */ -public class NewAlerts extends NotificationDispatcher { - - public static final String KEY = "NewAlerts"; - private final NotificationManager notifications; - - public NewAlerts(NotificationManager notifications) { - super("alerts"); - this.notifications = notifications; - } - - @Override - public String getKey() { - return KEY; - } - - public static NotificationDispatcherMetadata newMetadata() { - return NotificationDispatcherMetadata.create(KEY) - .setProperty(NotificationDispatcherMetadata.GLOBAL_NOTIFICATION, String.valueOf(true)) - .setProperty(NotificationDispatcherMetadata.PER_PROJECT_NOTIFICATION, String.valueOf(true)); - } - - @Override - public void dispatch(Notification notification, Context context) { - String projectIdString = notification.getFieldValue("projectId"); - if (projectIdString != null) { - int projectId = Integer.parseInt(projectIdString); - Multimap subscribedRecipients = notifications.findSubscribedRecipientsForDispatcher(this, projectId); - - for (Map.Entry> channelsByRecipients : subscribedRecipients.asMap().entrySet()) { - String userLogin = channelsByRecipients.getKey(); - for (NotificationChannel channel : channelsByRecipients.getValue()) { - context.addUser(userLogin, channel); - } - } - } - } -} diff --git a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/notifications/alerts/package-info.java b/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/notifications/alerts/package-info.java deleted file mode 100644 index 5e28de8ee2c..00000000000 --- a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/notifications/alerts/package-info.java +++ /dev/null @@ -1,23 +0,0 @@ -/* - * SonarQube, open source software quality management tool. - * Copyright (C) 2008-2014 SonarSource - * mailto:contact AT sonarsource DOT com - * - * SonarQube 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. - * - * SonarQube 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 this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -@ParametersAreNonnullByDefault -package org.sonar.plugins.core.notifications.alerts; - -import javax.annotation.ParametersAreNonnullByDefault; diff --git a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/security/package-info.java b/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/security/package-info.java deleted file mode 100644 index df9ccea5073..00000000000 --- a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/security/package-info.java +++ /dev/null @@ -1,23 +0,0 @@ -/* - * SonarQube, open source software quality management tool. - * Copyright (C) 2008-2014 SonarSource - * mailto:contact AT sonarsource DOT com - * - * SonarQube 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. - * - * SonarQube 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 this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -@ParametersAreNonnullByDefault -package org.sonar.plugins.core.security; - -import javax.annotation.ParametersAreNonnullByDefault; diff --git a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/sensors/package-info.java b/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/sensors/package-info.java deleted file mode 100644 index 145b58bdc95..00000000000 --- a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/sensors/package-info.java +++ /dev/null @@ -1,21 +0,0 @@ -/* - * SonarQube, open source software quality management tool. - * Copyright (C) 2008-2014 SonarSource - * mailto:contact AT sonarsource DOT com - * - * SonarQube 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. - * - * SonarQube 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 this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -@javax.annotation.ParametersAreNonnullByDefault -package org.sonar.plugins.core.sensors; diff --git a/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/CorePluginTest.java b/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/CorePluginTest.java deleted file mode 100644 index f21fb3bbaca..00000000000 --- a/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/CorePluginTest.java +++ /dev/null @@ -1,31 +0,0 @@ -/* - * SonarQube, open source software quality management tool. - * Copyright (C) 2008-2014 SonarSource - * mailto:contact AT sonarsource DOT com - * - * SonarQube 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. - * - * SonarQube 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 this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -package org.sonar.plugins.core; - -import org.junit.Test; - -import static org.assertj.core.api.Assertions.assertThat; - -public class CorePluginTest { - @Test - public void should_define_extensions() { - assertThat(new CorePlugin().getExtensions().size()).isGreaterThan(2); - } -} diff --git a/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/DefaultResourceTypesTest.java b/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/DefaultResourceTypesTest.java deleted file mode 100644 index 55817f9baeb..00000000000 --- a/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/DefaultResourceTypesTest.java +++ /dev/null @@ -1,48 +0,0 @@ -/* - * SonarQube, open source software quality management tool. - * Copyright (C) 2008-2014 SonarSource - * mailto:contact AT sonarsource DOT com - * - * SonarQube 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. - * - * SonarQube 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 this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -package org.sonar.plugins.core; - -import org.sonar.api.resources.ResourceType; - -import org.junit.Test; -import org.sonar.api.resources.Qualifiers; -import org.sonar.api.resources.ResourceTypeTree; - -import static org.assertj.core.api.Assertions.assertThat; - -public class DefaultResourceTypesTest { - @Test - public void provide_types() { - ResourceTypeTree tree = new DefaultResourceTypes().provide(); - - assertThat(tree.getTypes()).hasSize(7); - assertThat(tree.getChildren(Qualifiers.PROJECT)).containsExactly(Qualifiers.MODULE); - } - - @Test - public void projects_should_be_available_for_global_widgets() { - ResourceTypeTree tree = new DefaultResourceTypes().provide(); - - ResourceType projectResourceType = tree.getTypes().get(0); - - assertThat(projectResourceType.getQualifier()).isEqualTo(Qualifiers.PROJECT); - assertThat(projectResourceType.getBooleanProperty("supportsGlobalDashboards")).isTrue(); - } -} diff --git a/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/UserManagedMetricsTest.java b/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/UserManagedMetricsTest.java deleted file mode 100644 index 97a9e218b74..00000000000 --- a/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/UserManagedMetricsTest.java +++ /dev/null @@ -1,41 +0,0 @@ -/* - * SonarQube, open source software quality management tool. - * Copyright (C) 2008-2014 SonarSource - * mailto:contact AT sonarsource DOT com - * - * SonarQube 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. - * - * SonarQube 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 this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -package org.sonar.plugins.core; - -import org.junit.Test; -import org.sonar.api.measures.Metric; - -import java.util.List; - -import static org.assertj.core.api.Assertions.assertThat; - -public class UserManagedMetricsTest { - - @Test - public void checkDefinitions() { - UserManagedMetrics userManagedMetrics = new UserManagedMetrics(); - List metrics = userManagedMetrics.getMetrics(); - assertThat(metrics.size()).isGreaterThan(2); - for (Metric metric : metrics) { - assertThat(metric.getUserManaged()).isTrue(); - assertThat(metric.getDomain()).isEqualTo("Management"); - } - } -} diff --git a/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/notifications/alerts/NewAlertsTest.java b/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/notifications/alerts/NewAlertsTest.java deleted file mode 100644 index 6a65353af0a..00000000000 --- a/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/notifications/alerts/NewAlertsTest.java +++ /dev/null @@ -1,76 +0,0 @@ -/* - * SonarQube, open source software quality management tool. - * Copyright (C) 2008-2014 SonarSource - * mailto:contact AT sonarsource DOT com - * - * SonarQube 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. - * - * SonarQube 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 this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -package org.sonar.plugins.core.notifications.alerts; - -import com.google.common.collect.HashMultimap; -import com.google.common.collect.Multimap; -import org.junit.Test; -import org.sonar.api.notifications.Notification; -import org.sonar.api.notifications.NotificationChannel; -import org.sonar.core.notification.NotificationDispatcher; -import org.sonar.core.notification.NotificationManager; - -import static org.mockito.Mockito.*; - -public class NewAlertsTest { - - NotificationManager notificationManager = mock(NotificationManager.class); - NotificationDispatcher.Context context = mock(NotificationDispatcher.Context.class); - NotificationChannel emailChannel = mock(NotificationChannel.class); - NotificationChannel twitterChannel = mock(NotificationChannel.class); - NewAlerts dispatcher = new NewAlerts(notificationManager); - - @Test - public void should_not_dispatch_if_not_alerts_notification() { - Notification notification = new Notification("other-notif"); - dispatcher.performDispatch(notification, context); - - verify(context, never()).addUser(any(String.class), any(NotificationChannel.class)); - } - - @Test - public void should_dispatch_to_users_who_have_subscribed() { - Multimap recipients = HashMultimap.create(); - recipients.put("user1", emailChannel); - recipients.put("user2", twitterChannel); - when(notificationManager.findSubscribedRecipientsForDispatcher(dispatcher, 34)).thenReturn(recipients); - - Notification notification = new Notification("alerts").setFieldValue("projectId", "34"); - dispatcher.performDispatch(notification, context); - - verify(context).addUser("user1", emailChannel); - verify(context).addUser("user2", twitterChannel); - verifyNoMoreInteractions(context); - } - - @Test - public void should_not_dispatch_if_missing_project_id() { - Multimap recipients = HashMultimap.create(); - recipients.put("user1", emailChannel); - recipients.put("user2", twitterChannel); - when(notificationManager.findSubscribedRecipientsForDispatcher(dispatcher, 34)).thenReturn(recipients); - - Notification notification = new Notification("alerts"); - dispatcher.performDispatch(notification, context); - - verifyNoMoreInteractions(context); - } - -} diff --git a/server/sonar-server/src/main/java/org/sonar/server/event/NewAlerts.java b/server/sonar-server/src/main/java/org/sonar/server/event/NewAlerts.java new file mode 100644 index 00000000000..cf4c219e848 --- /dev/null +++ b/server/sonar-server/src/main/java/org/sonar/server/event/NewAlerts.java @@ -0,0 +1,72 @@ +/* + * SonarQube, open source software quality management tool. + * Copyright (C) 2008-2014 SonarSource + * mailto:contact AT sonarsource DOT com + * + * SonarQube 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. + * + * SonarQube 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 this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ +package org.sonar.server.event; + +import com.google.common.collect.Multimap; +import org.sonar.api.notifications.*; + +import java.util.Collection; +import java.util.Map; +import org.sonar.core.notification.NotificationDispatcher; +import org.sonar.core.notification.NotificationDispatcherMetadata; +import org.sonar.core.notification.NotificationManager; + +/** + * This dispatcher means: "notify me each new alert event". + * + * @since 3.5 + */ +public class NewAlerts extends NotificationDispatcher { + + public static final String KEY = "NewAlerts"; + private final NotificationManager notifications; + + public NewAlerts(NotificationManager notifications) { + super("alerts"); + this.notifications = notifications; + } + + @Override + public String getKey() { + return KEY; + } + + public static NotificationDispatcherMetadata newMetadata() { + return NotificationDispatcherMetadata.create(KEY) + .setProperty(NotificationDispatcherMetadata.GLOBAL_NOTIFICATION, String.valueOf(true)) + .setProperty(NotificationDispatcherMetadata.PER_PROJECT_NOTIFICATION, String.valueOf(true)); + } + + @Override + public void dispatch(Notification notification, Context context) { + String projectIdString = notification.getFieldValue("projectId"); + if (projectIdString != null) { + int projectId = Integer.parseInt(projectIdString); + Multimap subscribedRecipients = notifications.findSubscribedRecipientsForDispatcher(this, projectId); + + for (Map.Entry> channelsByRecipients : subscribedRecipients.asMap().entrySet()) { + String userLogin = channelsByRecipients.getKey(); + for (NotificationChannel channel : channelsByRecipients.getValue()) { + context.addUser(userLogin, channel); + } + } + } + } +} diff --git a/server/sonar-server/src/main/java/org/sonar/server/event/package-info.java b/server/sonar-server/src/main/java/org/sonar/server/event/package-info.java new file mode 100644 index 00000000000..0bc35a2f8f5 --- /dev/null +++ b/server/sonar-server/src/main/java/org/sonar/server/event/package-info.java @@ -0,0 +1,24 @@ +/* + * SonarQube, open source software quality management tool. + * Copyright (C) 2008-2014 SonarSource + * mailto:contact AT sonarsource DOT com + * + * SonarQube 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. + * + * SonarQube 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 this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ + +@ParametersAreNonnullByDefault +package org.sonar.server.event; + +import javax.annotation.ParametersAreNonnullByDefault; diff --git a/server/sonar-server/src/main/java/org/sonar/server/metric/CoreCustomMetrics.java b/server/sonar-server/src/main/java/org/sonar/server/metric/CoreCustomMetrics.java new file mode 100644 index 00000000000..8d600ea8583 --- /dev/null +++ b/server/sonar-server/src/main/java/org/sonar/server/metric/CoreCustomMetrics.java @@ -0,0 +1,53 @@ +/* + * SonarQube, open source software quality management tool. + * Copyright (C) 2008-2014 SonarSource + * mailto:contact AT sonarsource DOT com + * + * SonarQube 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. + * + * SonarQube 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 this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ +package org.sonar.server.metric; + +import com.google.common.collect.ImmutableList; +import org.sonar.api.measures.Metric; +import org.sonar.api.measures.Metrics; + +import java.util.List; + +public final class CoreCustomMetrics implements Metrics { + private static final String DOMAIN = "Management"; + + @Override + public List getMetrics() { + return ImmutableList.of( + new Metric.Builder("burned_budget", "Burned budget", Metric.ValueType.FLOAT) + .setDirection(Metric.DIRECTION_NONE) + .setQualitative(false) + .setDomain(DOMAIN) + .setUserManaged(true) + .create(), + new Metric.Builder("business_value", "Business value", Metric.ValueType.FLOAT) + .setDirection(Metric.DIRECTION_BETTER) + .setQualitative(true) + .setDomain(DOMAIN) + .setUserManaged(true) + .create(), + new Metric.Builder("team_size", "Team size", Metric.ValueType.INT) + .setDirection(Metric.DIRECTION_NONE) + .setQualitative(false) + .setDomain(DOMAIN) + .setUserManaged(true) + .create()); + } +} diff --git a/server/sonar-server/src/main/java/org/sonar/server/metric/package-info.java b/server/sonar-server/src/main/java/org/sonar/server/metric/package-info.java new file mode 100644 index 00000000000..820edea547b --- /dev/null +++ b/server/sonar-server/src/main/java/org/sonar/server/metric/package-info.java @@ -0,0 +1,24 @@ +/* + * SonarQube, open source software quality management tool. + * Copyright (C) 2008-2014 SonarSource + * mailto:contact AT sonarsource DOT com + * + * SonarQube 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. + * + * SonarQube 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 this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ + +@ParametersAreNonnullByDefault +package org.sonar.server.metric; + +import javax.annotation.ParametersAreNonnullByDefault; diff --git a/server/sonar-server/src/main/java/org/sonar/server/platform/platformlevel/PlatformLevel4.java b/server/sonar-server/src/main/java/org/sonar/server/platform/platformlevel/PlatformLevel4.java index 59f0cc900fc..847b5234a22 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/platform/platformlevel/PlatformLevel4.java +++ b/server/sonar-server/src/main/java/org/sonar/server/platform/platformlevel/PlatformLevel4.java @@ -44,6 +44,7 @@ import org.sonar.core.qualitygate.db.ProjectQgateAssociationDao; import org.sonar.core.qualitygate.db.QualityGateConditionDao; import org.sonar.core.qualitygate.db.QualityGateDao; import org.sonar.core.resource.DefaultResourcePermissions; +import org.sonar.core.resource.DefaultResourceTypes; import org.sonar.core.timemachine.Periods; import org.sonar.core.user.DefaultUserFinder; import org.sonar.core.user.HibernateUserFinder; @@ -122,6 +123,7 @@ import org.sonar.server.duplication.ws.DuplicationsParser; import org.sonar.server.duplication.ws.DuplicationsWs; import org.sonar.server.es.IndexCreator; import org.sonar.server.es.IndexDefinitions; +import org.sonar.server.event.NewAlerts; import org.sonar.server.issue.ActionService; import org.sonar.server.issue.AddTagsAction; import org.sonar.server.issue.AssignAction; @@ -166,6 +168,7 @@ import org.sonar.server.measure.template.MyFavouritesFilter; import org.sonar.server.measure.template.ProjectFilter; import org.sonar.server.measure.ws.ManualMeasuresWs; import org.sonar.server.measure.ws.TimeMachineWs; +import org.sonar.server.metric.CoreCustomMetrics; import org.sonar.server.metric.ws.MetricsWs; import org.sonar.server.notifications.NotificationCenter; import org.sonar.server.notifications.NotificationService; @@ -340,6 +343,7 @@ public class PlatformLevel4 extends PlatformLevel { DistributionAreaChart.class, Views.class, ResourceTypes.class, + DefaultResourceTypes.class, SettingsChangeNotifier.class, PageDecorations.class, DefaultResourcePermissions.class, @@ -488,6 +492,7 @@ public class PlatformLevel4 extends PlatformLevel { MeasureFilterEngine.class, ProjectFilter.class, MyFavouritesFilter.class, + CoreCustomMetrics.class, DefaultMetricFinder.class, ServerLifecycleNotifier.class, TimeMachineWs.class, @@ -579,6 +584,7 @@ public class PlatformLevel4 extends PlatformLevel { org.sonar.server.component.ws.AppAction.class, org.sonar.server.component.ws.SearchAction.class, EventsWs.class, + NewAlerts.class, ComponentCleanerService.class, ProvisionedAction.class, GhostsAction.class, diff --git a/server/sonar-server/src/test/java/org/sonar/server/event/NewAlertsTest.java b/server/sonar-server/src/test/java/org/sonar/server/event/NewAlertsTest.java new file mode 100644 index 00000000000..49bb6f7e6f0 --- /dev/null +++ b/server/sonar-server/src/test/java/org/sonar/server/event/NewAlertsTest.java @@ -0,0 +1,76 @@ +/* + * SonarQube, open source software quality management tool. + * Copyright (C) 2008-2014 SonarSource + * mailto:contact AT sonarsource DOT com + * + * SonarQube 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. + * + * SonarQube 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 this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ +package org.sonar.server.event; + +import com.google.common.collect.HashMultimap; +import com.google.common.collect.Multimap; +import org.junit.Test; +import org.sonar.api.notifications.Notification; +import org.sonar.api.notifications.NotificationChannel; +import org.sonar.core.notification.NotificationDispatcher; +import org.sonar.core.notification.NotificationManager; + +import static org.mockito.Mockito.*; + +public class NewAlertsTest { + + NotificationManager notificationManager = mock(NotificationManager.class); + NotificationDispatcher.Context context = mock(NotificationDispatcher.Context.class); + NotificationChannel emailChannel = mock(NotificationChannel.class); + NotificationChannel twitterChannel = mock(NotificationChannel.class); + NewAlerts dispatcher = new NewAlerts(notificationManager); + + @Test + public void should_not_dispatch_if_not_alerts_notification() { + Notification notification = new Notification("other-notif"); + dispatcher.performDispatch(notification, context); + + verify(context, never()).addUser(any(String.class), any(NotificationChannel.class)); + } + + @Test + public void should_dispatch_to_users_who_have_subscribed() { + Multimap recipients = HashMultimap.create(); + recipients.put("user1", emailChannel); + recipients.put("user2", twitterChannel); + when(notificationManager.findSubscribedRecipientsForDispatcher(dispatcher, 34)).thenReturn(recipients); + + Notification notification = new Notification("alerts").setFieldValue("projectId", "34"); + dispatcher.performDispatch(notification, context); + + verify(context).addUser("user1", emailChannel); + verify(context).addUser("user2", twitterChannel); + verifyNoMoreInteractions(context); + } + + @Test + public void should_not_dispatch_if_missing_project_id() { + Multimap recipients = HashMultimap.create(); + recipients.put("user1", emailChannel); + recipients.put("user2", twitterChannel); + when(notificationManager.findSubscribedRecipientsForDispatcher(dispatcher, 34)).thenReturn(recipients); + + Notification notification = new Notification("alerts"); + dispatcher.performDispatch(notification, context); + + verifyNoMoreInteractions(context); + } + +} diff --git a/server/sonar-server/src/test/java/org/sonar/server/metric/CoreCustomMetricsTest.java b/server/sonar-server/src/test/java/org/sonar/server/metric/CoreCustomMetricsTest.java new file mode 100644 index 00000000000..9871f918b33 --- /dev/null +++ b/server/sonar-server/src/test/java/org/sonar/server/metric/CoreCustomMetricsTest.java @@ -0,0 +1,41 @@ +/* + * SonarQube, open source software quality management tool. + * Copyright (C) 2008-2014 SonarSource + * mailto:contact AT sonarsource DOT com + * + * SonarQube 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. + * + * SonarQube 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 this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ +package org.sonar.server.metric; + +import org.junit.Test; +import org.sonar.api.measures.Metric; + +import java.util.List; + +import static org.assertj.core.api.Assertions.assertThat; + +public class CoreCustomMetricsTest { + + @Test + public void checkDefinitions() { + CoreCustomMetrics coreCustomMetrics = new CoreCustomMetrics(); + List metrics = coreCustomMetrics.getMetrics(); + assertThat(metrics.size()).isGreaterThan(2); + for (Metric metric : metrics) { + assertThat(metric.getUserManaged()).isTrue(); + assertThat(metric.getDomain()).isEqualTo("Management"); + } + } +} diff --git a/sonar-batch/src/main/java/org/sonar/batch/bootstrap/BatchComponents.java b/sonar-batch/src/main/java/org/sonar/batch/bootstrap/BatchComponents.java index ba42319b7bd..f679ae3f8ce 100644 --- a/sonar-batch/src/main/java/org/sonar/batch/bootstrap/BatchComponents.java +++ b/sonar-batch/src/main/java/org/sonar/batch/bootstrap/BatchComponents.java @@ -75,6 +75,7 @@ import org.sonar.batch.source.CodeColorizerSensor; import org.sonar.batch.source.LinesSensor; import org.sonar.core.config.CorePropertyDefinitions; import org.sonar.core.notification.DefaultNotificationManager; +import org.sonar.core.resource.DefaultResourceTypes; public class BatchComponents { private BatchComponents() { @@ -83,6 +84,8 @@ public class BatchComponents { public static Collection all(DefaultAnalysisMode analysisMode) { List components = Lists.newArrayList( + DefaultResourceTypes.class, + // Maven MavenProjectBootstrapper.class, MavenProjectConverter.class, MavenProjectBuilder.class, @@ -104,8 +107,6 @@ public class BatchComponents { SourceProvider.class, RuleNameProvider.class, - QualityGateVerifier.class, - // language LanguageDistributionDecorator.class, @@ -120,6 +121,7 @@ public class BatchComponents { // Quality Gate GenerateQualityGateEvents.class, + QualityGateVerifier.class, // Issue tracking IssueTrackingDecorator.class, diff --git a/sonar-core/src/main/java/org/sonar/core/resource/DefaultResourceTypes.java b/sonar-core/src/main/java/org/sonar/core/resource/DefaultResourceTypes.java new file mode 100644 index 00000000000..76e88053609 --- /dev/null +++ b/sonar-core/src/main/java/org/sonar/core/resource/DefaultResourceTypes.java @@ -0,0 +1,82 @@ +/* + * SonarQube, open source software quality management tool. + * Copyright (C) 2008-2014 SonarSource + * mailto:contact AT sonarsource DOT com + * + * SonarQube 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. + * + * SonarQube 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 this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ +package org.sonar.core.resource; + +import org.sonar.api.ExtensionProvider; +import org.sonar.api.batch.BatchSide; +import org.sonar.api.batch.InstantiationStrategy; +import org.sonar.api.resources.Qualifiers; +import org.sonar.api.resources.ResourceType; +import org.sonar.api.resources.ResourceTypeTree; +import org.sonar.api.server.ServerSide; + +@BatchSide +@ServerSide +@InstantiationStrategy(InstantiationStrategy.PER_BATCH) +public final class DefaultResourceTypes extends ExtensionProvider { + + private static final String SUPPORTS_MEASURE_FILTERS = "supportsMeasureFilters"; + private static final String CONFIGURABLE = "configurable"; + private static final String UPDATABLE_KEY = "updatable_key"; + + @Override + public ResourceTypeTree provide() { + + return ResourceTypeTree.builder() + .addType(ResourceType.builder(Qualifiers.PROJECT) + .setProperty("deletable", true) + .setProperty("supportsGlobalDashboards", true) + .setProperty("modifiable_history", true) + .setProperty("hasRolePolicy", true) + .setProperty(UPDATABLE_KEY, true) + .setProperty(SUPPORTS_MEASURE_FILTERS, true) + .setProperty("comparable", true) + .setProperty(CONFIGURABLE, true) + .build()) + .addType(ResourceType.builder(Qualifiers.MODULE) + .setProperty(UPDATABLE_KEY, true) + .setProperty(SUPPORTS_MEASURE_FILTERS, true) + .setProperty(CONFIGURABLE, true) + .build()) + .addType(ResourceType.builder(Qualifiers.DIRECTORY) + .setProperty(SUPPORTS_MEASURE_FILTERS, true) + .build()) + .addType(ResourceType.builder(Qualifiers.PACKAGE) + .build()) + .addType(ResourceType.builder(Qualifiers.FILE) + .hasSourceCode() + .setProperty(SUPPORTS_MEASURE_FILTERS, true) + .build()) + .addType(ResourceType.builder(Qualifiers.CLASS) + .hasSourceCode() + .build()) + .addType(ResourceType.builder(Qualifiers.UNIT_TEST_FILE) + .hasSourceCode() + .setProperty(SUPPORTS_MEASURE_FILTERS, true) + .build()) + + .addRelations(Qualifiers.PROJECT, Qualifiers.MODULE) + .addRelations(Qualifiers.MODULE, Qualifiers.DIRECTORY, Qualifiers.PACKAGE) + .addRelations(Qualifiers.DIRECTORY, Qualifiers.FILE, Qualifiers.UNIT_TEST_FILE) + .addRelations(Qualifiers.PACKAGE, Qualifiers.CLASS, Qualifiers.UNIT_TEST_FILE) + + .build(); + } +} diff --git a/sonar-core/src/test/java/org/sonar/core/resource/DefaultResourceTypesTest.java b/sonar-core/src/test/java/org/sonar/core/resource/DefaultResourceTypesTest.java new file mode 100644 index 00000000000..ed418b96709 --- /dev/null +++ b/sonar-core/src/test/java/org/sonar/core/resource/DefaultResourceTypesTest.java @@ -0,0 +1,47 @@ +/* + * SonarQube, open source software quality management tool. + * Copyright (C) 2008-2014 SonarSource + * mailto:contact AT sonarsource DOT com + * + * SonarQube 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. + * + * SonarQube 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 this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ +package org.sonar.core.resource; + +import org.junit.Test; +import org.sonar.api.resources.Qualifiers; +import org.sonar.api.resources.ResourceType; +import org.sonar.api.resources.ResourceTypeTree; + +import static org.assertj.core.api.Assertions.assertThat; + +public class DefaultResourceTypesTest { + @Test + public void provide_types() { + ResourceTypeTree tree = new DefaultResourceTypes().provide(); + + assertThat(tree.getTypes()).hasSize(7); + assertThat(tree.getChildren(Qualifiers.PROJECT)).containsExactly(Qualifiers.MODULE); + } + + @Test + public void projects_should_be_available_for_global_widgets() { + ResourceTypeTree tree = new DefaultResourceTypes().provide(); + + ResourceType projectResourceType = tree.getTypes().get(0); + + assertThat(projectResourceType.getQualifier()).isEqualTo(Qualifiers.PROJECT); + assertThat(projectResourceType.getBooleanProperty("supportsGlobalDashboards")).isTrue(); + } +}