*/
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(
@SuppressWarnings("rawtypes")
@Override
public List getExtensions() {
- ImmutableList.Builder<Object> 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();
}
}
+++ /dev/null
-/*
- * 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();
- }
-}
+++ /dev/null
-/*
- * 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<Metric> getMetrics() {
- return ImmutableList.<Metric>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());
- }
-}
+++ /dev/null
-/*
- * 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;
+++ /dev/null
-/*
- * 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<String, NotificationChannel> subscribedRecipients = notifications.findSubscribedRecipientsForDispatcher(this, projectId);
-
- for (Map.Entry<String, Collection<NotificationChannel>> channelsByRecipients : subscribedRecipients.asMap().entrySet()) {
- String userLogin = channelsByRecipients.getKey();
- for (NotificationChannel channel : channelsByRecipients.getValue()) {
- context.addUser(userLogin, channel);
- }
- }
- }
- }
-}
+++ /dev/null
-/*
- * 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;
+++ /dev/null
-/*
- * 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;
+++ /dev/null
-/*
- * 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;
+++ /dev/null
-/*
- * 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);
- }
-}
+++ /dev/null
-/*
- * 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();
- }
-}
+++ /dev/null
-/*
- * 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<Metric> metrics = userManagedMetrics.getMetrics();
- assertThat(metrics.size()).isGreaterThan(2);
- for (Metric metric : metrics) {
- assertThat(metric.getUserManaged()).isTrue();
- assertThat(metric.getDomain()).isEqualTo("Management");
- }
- }
-}
+++ /dev/null
-/*
- * 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<String, NotificationChannel> 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<String, NotificationChannel> 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);
- }
-
-}
--- /dev/null
+/*
+ * 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<String, NotificationChannel> subscribedRecipients = notifications.findSubscribedRecipientsForDispatcher(this, projectId);
+
+ for (Map.Entry<String, Collection<NotificationChannel>> channelsByRecipients : subscribedRecipients.asMap().entrySet()) {
+ String userLogin = channelsByRecipients.getKey();
+ for (NotificationChannel channel : channelsByRecipients.getValue()) {
+ context.addUser(userLogin, channel);
+ }
+ }
+ }
+ }
+}
--- /dev/null
+/*
+ * 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;
--- /dev/null
+/*
+ * 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<Metric> getMetrics() {
+ return ImmutableList.<Metric>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());
+ }
+}
--- /dev/null
+/*
+ * 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;
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;
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;
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;
DistributionAreaChart.class,
Views.class,
ResourceTypes.class,
+ DefaultResourceTypes.class,
SettingsChangeNotifier.class,
PageDecorations.class,
DefaultResourcePermissions.class,
MeasureFilterEngine.class,
ProjectFilter.class,
MyFavouritesFilter.class,
+ CoreCustomMetrics.class,
DefaultMetricFinder.class,
ServerLifecycleNotifier.class,
TimeMachineWs.class,
org.sonar.server.component.ws.AppAction.class,
org.sonar.server.component.ws.SearchAction.class,
EventsWs.class,
+ NewAlerts.class,
ComponentCleanerService.class,
ProvisionedAction.class,
GhostsAction.class,
--- /dev/null
+/*
+ * 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<String, NotificationChannel> 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<String, NotificationChannel> 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);
+ }
+
+}
--- /dev/null
+/*
+ * 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<Metric> metrics = coreCustomMetrics.getMetrics();
+ assertThat(metrics.size()).isGreaterThan(2);
+ for (Metric metric : metrics) {
+ assertThat(metric.getUserManaged()).isTrue();
+ assertThat(metric.getDomain()).isEqualTo("Management");
+ }
+ }
+}
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() {
public static Collection all(DefaultAnalysisMode analysisMode) {
List components = Lists.newArrayList(
+ DefaultResourceTypes.class,
+
// Maven
MavenProjectBootstrapper.class, MavenProjectConverter.class, MavenProjectBuilder.class,
SourceProvider.class,
RuleNameProvider.class,
- QualityGateVerifier.class,
-
// language
LanguageDistributionDecorator.class,
// Quality Gate
GenerateQualityGateEvents.class,
+ QualityGateVerifier.class,
// Issue tracking
IssueTrackingDecorator.class,
--- /dev/null
+/*
+ * 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();
+ }
+}
--- /dev/null
+/*
+ * 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();
+ }
+}