]> source.dussan.org Git - sonarqube.git/commitdiff
SONARPLUGINS-1948 Move EmailConfiguration to the core
authorDavid Gageot <david@gageot.net>
Tue, 19 Jun 2012 09:24:51 +0000 (11:24 +0200)
committerDavid Gageot <david@gageot.net>
Tue, 19 Jun 2012 11:59:19 +0000 (13:59 +0200)
+ Rename to EmailSettings
+ Use Settings instead of Configuration

16 files changed:
plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/CorePlugin.java
plugins/sonar-email-notifications-plugin/src/main/java/org/sonar/plugins/emailnotifications/EmailConfiguration.java [deleted file]
plugins/sonar-email-notifications-plugin/src/main/java/org/sonar/plugins/emailnotifications/EmailNotificationChannel.java
plugins/sonar-email-notifications-plugin/src/main/java/org/sonar/plugins/emailnotifications/EmailNotificationsPlugin.java
plugins/sonar-email-notifications-plugin/src/main/java/org/sonar/plugins/emailnotifications/newviolations/NewViolationsEmailTemplate.java
plugins/sonar-email-notifications-plugin/src/main/java/org/sonar/plugins/emailnotifications/reviews/ReviewEmailTemplate.java
plugins/sonar-email-notifications-plugin/src/test/java/org/sonar/plugins/emailnotifications/EmailConfigurationTest.java [deleted file]
plugins/sonar-email-notifications-plugin/src/test/java/org/sonar/plugins/emailnotifications/EmailNotificationChannelTest.java
plugins/sonar-email-notifications-plugin/src/test/java/org/sonar/plugins/emailnotifications/EmailNotificationsPluginTest.java
plugins/sonar-email-notifications-plugin/src/test/java/org/sonar/plugins/emailnotifications/newviolations/NewViolationsEmailTemplateTest.java
plugins/sonar-email-notifications-plugin/src/test/java/org/sonar/plugins/emailnotifications/reviews/ReviewEmailTemplateTest.java
sonar-batch/src/main/java/org/sonar/batch/bootstrap/BootstrapModule.java
sonar-plugin-api/src/main/java/org/sonar/api/platform/EmailSettings.java [new file with mode: 0644]
sonar-plugin-api/src/test/java/org/sonar/api/platform/EmailSettingsTest.java [new file with mode: 0644]
sonar-server/src/main/java/org/sonar/server/platform/Platform.java
sonar-server/src/main/webapp/WEB-INF/app/controllers/email_configuration_controller.rb

index b2d3748cff1c8a094e4012a8bf1bad60fba7972d..95896ed6c807c014aa6ab4323844b7e1abac1a56 100644 (file)
@@ -19,9 +19,7 @@
  */
 package org.sonar.plugins.core;
 
-import org.sonar.plugins.core.dashboards.MyFavouritesDashboard;
-
-import com.google.common.collect.Lists;
+import com.google.common.collect.ImmutableList;
 import org.sonar.api.CoreProperties;
 import org.sonar.api.Extension;
 import org.sonar.api.Properties;
@@ -40,6 +38,7 @@ 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;
@@ -289,116 +288,113 @@ import java.util.List;
 })
 public final class CorePlugin extends SonarPlugin {
 
-  @SuppressWarnings({"rawtypes", "unchecked"})
+  @SuppressWarnings("unchecked")
   public List<Class<? extends Extension>> getExtensions() {
-    List extensions = Lists.newLinkedList();
-
-    extensions.add(DefaultResourceTypes.class);
-    extensions.add(UserManagedMetrics.class);
-    extensions.add(ProjectFileSystemLogger.class);
-
-    // maven
-    extensions.add(MavenInitializer.class);
+    return ImmutableList.of(
+        DefaultResourceTypes.class,
+        UserManagedMetrics.class,
+        ProjectFileSystemLogger.class,
 
-    // languages
-    extensions.add(Java.class);
+        // maven
+        MavenInitializer.class,
 
-    // pages
-    extensions.add(TestsViewerDefinition.class);
-    extensions.add(Lcom4Viewer.class);
+        // languages
+        Java.class,
 
-    // filters
-    extensions.add(ProjectFilter.class);
-    extensions.add(TreeMapFilter.class);
-    extensions.add(MyFavouritesFilter.class);
+        // pages
+        TestsViewerDefinition.class,
+        Lcom4Viewer.class,
 
-    // widgets
-    extensions.add(AlertsWidget.class);
-    extensions.add(CoverageWidget.class);
-    extensions.add(ItCoverageWidget.class);
-    extensions.add(CommentsDuplicationsWidget.class);
-    extensions.add(DescriptionWidget.class);
-    extensions.add(ComplexityWidget.class);
-    extensions.add(RulesWidget.class);
-    extensions.add(SizeWidget.class);
-    extensions.add(EventsWidget.class);
-    extensions.add(CustomMeasuresWidget.class);
-    extensions.add(TimelineWidget.class);
-    extensions.add(TimeMachineWidget.class);
-    extensions.add(HotspotMetricWidget.class);
-    extensions.add(HotspotMostViolatedResourcesWidget.class);
-    extensions.add(HotspotMostViolatedRulesWidget.class);
-    extensions.add(MyReviewsWidget.class);
-    extensions.add(ProjectReviewsWidget.class);
-    extensions.add(FalsePositiveReviewsWidget.class);
-    extensions.add(ReviewsPerDeveloperWidget.class);
-    extensions.add(PlannedReviewsWidget.class);
-    extensions.add(UnplannedReviewsWidget.class);
-    extensions.add(ActionPlansWidget.class);
-    extensions.add(ReviewsMetricsWidget.class);
-    extensions.add(TreemapWidget.class);
-    extensions.add(FilterWidget.class);
+        // filters
+        ProjectFilter.class,
+        TreeMapFilter.class,
+        MyFavouritesFilter.class,
 
-    // dashboards
-    extensions.add(DefaultDashboard.class);
-    extensions.add(HotspotsDashboard.class);
-    extensions.add(ReviewsDashboard.class);
-    extensions.add(TimeMachineDashboard.class);
-    extensions.add(ProjectsDashboard.class);
-    extensions.add(TreemapDashboard.class);
-    extensions.add(MyFavouritesDashboard.class);
+        // widgets
+        AlertsWidget.class,
+        CoverageWidget.class,
+        ItCoverageWidget.class,
+        CommentsDuplicationsWidget.class,
+        DescriptionWidget.class,
+        ComplexityWidget.class,
+        RulesWidget.class,
+        SizeWidget.class,
+        EventsWidget.class,
+        CustomMeasuresWidget.class,
+        TimelineWidget.class,
+        TimeMachineWidget.class,
+        HotspotMetricWidget.class,
+        HotspotMostViolatedResourcesWidget.class,
+        HotspotMostViolatedRulesWidget.class,
+        MyReviewsWidget.class,
+        ProjectReviewsWidget.class,
+        FalsePositiveReviewsWidget.class,
+        ReviewsPerDeveloperWidget.class,
+        PlannedReviewsWidget.class,
+        UnplannedReviewsWidget.class,
+        ActionPlansWidget.class,
+        ReviewsMetricsWidget.class,
+        TreemapWidget.class,
+        FilterWidget.class,
 
-    // chart
-    extensions.add(XradarChart.class);
-    extensions.add(DistributionBarChart.class);
-    extensions.add(DistributionAreaChart.class);
+        // dashboards
+        DefaultDashboard.class,
+        HotspotsDashboard.class,
+        ReviewsDashboard.class,
+        TimeMachineDashboard.class,
+        ProjectsDashboard.class,
+        TreemapDashboard.class,
+        MyFavouritesDashboard.class,
 
-    // colorizers
-    extensions.add(JavaColorizerFormat.class);
+        // chart
+        XradarChart.class,
+        DistributionBarChart.class,
+        DistributionAreaChart.class,
 
-    // batch
-    extensions.add(ProfileSensor.class);
-    extensions.add(ProfileEventsSensor.class);
-    extensions.add(ProjectLinksSensor.class);
-    extensions.add(UnitTestDecorator.class);
-    extensions.add(VersionEventsSensor.class);
-    extensions.add(CheckAlertThresholds.class);
-    extensions.add(GenerateAlertEvents.class);
-    extensions.add(ViolationsDecorator.class);
-    extensions.add(WeightedViolationsDecorator.class);
-    extensions.add(ViolationsDensityDecorator.class);
-    extensions.add(LineCoverageDecorator.class);
-    extensions.add(CoverageDecorator.class);
-    extensions.add(BranchCoverageDecorator.class);
-    extensions.add(ItLineCoverageDecorator.class);
-    extensions.add(ItCoverageDecorator.class);
-    extensions.add(ItBranchCoverageDecorator.class);
-    extensions.add(ApplyProjectRolesDecorator.class);
-    extensions.add(ExcludedResourceFilter.class);
-    extensions.add(CommentDensityDecorator.class);
-    extensions.add(NoSonarFilter.class);
-    extensions.add(DirectoriesDecorator.class);
-    extensions.add(FilesDecorator.class);
-    extensions.add(ReviewNotifications.class);
-    extensions.add(ReviewWorkflowDecorator.class);
-    extensions.add(ReferenceAnalysis.class);
-    extensions.add(ManualMeasureDecorator.class);
-    extensions.add(ManualViolationInjector.class);
-    extensions.add(ViolationSeverityUpdater.class);
-    extensions.add(IndexProjectPostJob.class);
-    extensions.add(ReviewsMeasuresDecorator.class);
+        // colorizers
+        JavaColorizerFormat.class,
 
-    // time machine
-    extensions.add(TendencyDecorator.class);
-    extensions.add(VariationDecorator.class);
-    extensions.add(ViolationTrackingDecorator.class);
-    extensions.add(ViolationPersisterDecorator.class);
-    extensions.add(NewViolationsDecorator.class);
-    extensions.add(TimeMachineConfigurationPersister.class);
-    extensions.add(NewCoverageFileAnalyzer.class);
-    extensions.add(NewItCoverageFileAnalyzer.class);
-    extensions.add(NewCoverageAggregator.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,
+        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,
 
-    return extensions;
+        // time machine
+        TendencyDecorator.class,
+        VariationDecorator.class,
+        ViolationTrackingDecorator.class,
+        ViolationPersisterDecorator.class,
+        NewViolationsDecorator.class,
+        TimeMachineConfigurationPersister.class,
+        NewCoverageFileAnalyzer.class,
+        NewItCoverageFileAnalyzer.class,
+        NewCoverageAggregator.class);
   }
 }
diff --git a/plugins/sonar-email-notifications-plugin/src/main/java/org/sonar/plugins/emailnotifications/EmailConfiguration.java b/plugins/sonar-email-notifications-plugin/src/main/java/org/sonar/plugins/emailnotifications/EmailConfiguration.java
deleted file mode 100644 (file)
index 9c0b106..0000000
+++ /dev/null
@@ -1,86 +0,0 @@
-/*
- * 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.plugins.emailnotifications;
-
-import org.apache.commons.configuration.Configuration;
-import org.sonar.api.CoreProperties;
-import org.sonar.api.ServerExtension;
-
-/**
- * Ruby uses constants from this class.
- * 
- * @since 2.10
- */
-public class EmailConfiguration implements ServerExtension {
-
-  public static final String SMTP_HOST = "email.smtp_host.secured";
-  public static final String SMTP_HOST_DEFAULT = "";
-  public static final String SMTP_PORT = "email.smtp_port.secured";
-  public static final String SMTP_PORT_DEFAULT = "25";
-  public static final String SMTP_SECURE_CONNECTION = "email.smtp_secure_connection.secured";
-  public static final String SMTP_SECURE_CONNECTION_DEFAULT = "";
-  public static final String SMTP_USERNAME = "email.smtp_username.secured";
-  public static final String SMTP_USERNAME_DEFAULT = "";
-  public static final String SMTP_PASSWORD = "email.smtp_password.secured";
-  public static final String SMTP_PASSWORD_DEFAULT = "";
-  public static final String FROM = "email.from";
-  public static final String FROM_DEFAULT = "noreply@nowhere";
-  public static final String PREFIX = "email.prefix";
-  public static final String PREFIX_DEFAULT = "[SONAR]";
-
-  private Configuration configuration;
-
-  public EmailConfiguration(Configuration configuration) {
-    this.configuration = configuration;
-  }
-
-  public String getSmtpHost() {
-    return configuration.getString(SMTP_HOST, SMTP_HOST_DEFAULT);
-  }
-
-  public String getSmtpPort() {
-    return configuration.getString(SMTP_PORT, SMTP_PORT_DEFAULT);
-  }
-
-  public String getSecureConnection() {
-    return configuration.getString(SMTP_SECURE_CONNECTION, SMTP_SECURE_CONNECTION_DEFAULT);
-  }
-
-  public String getSmtpUsername() {
-    return configuration.getString(SMTP_USERNAME, SMTP_USERNAME_DEFAULT);
-  }
-
-  public String getSmtpPassword() {
-    return configuration.getString(SMTP_PASSWORD, SMTP_PASSWORD_DEFAULT);
-  }
-
-  public String getFrom() {
-    return configuration.getString(FROM, FROM_DEFAULT);
-  }
-
-  public String getPrefix() {
-    return configuration.getString(PREFIX, PREFIX_DEFAULT);
-  }
-
-  public String getServerBaseURL() {
-    return configuration.getString(CoreProperties.SERVER_BASE_URL, CoreProperties.SERVER_BASE_URL_DEFAULT_VALUE);
-  }
-
-}
index c397efc499637f2bb161ab557848738cdbc55c31..382e9ce4f95ddfb420691984664cb0299fb642a1 100644 (file)
@@ -19,9 +19,6 @@
  */
 package org.sonar.plugins.emailnotifications;
 
-import java.net.MalformedURLException;
-import java.net.URL;
-
 import org.apache.commons.lang.StringUtils;
 import org.apache.commons.mail.EmailException;
 import org.apache.commons.mail.SimpleEmail;
@@ -30,11 +27,15 @@ import org.slf4j.LoggerFactory;
 import org.sonar.api.database.model.User;
 import org.sonar.api.notifications.Notification;
 import org.sonar.api.notifications.NotificationChannel;
+import org.sonar.api.platform.EmailSettings;
 import org.sonar.api.security.UserFinder;
 import org.sonar.api.utils.SonarException;
 import org.sonar.plugins.emailnotifications.api.EmailMessage;
 import org.sonar.plugins.emailnotifications.api.EmailTemplate;
 
+import java.net.MalformedURLException;
+import java.net.URL;
+
 /**
  * References:
  * <ul>
@@ -82,11 +83,11 @@ public class EmailNotificationChannel extends NotificationChannel {
   private static final String FROM_NAME_DEFAULT = "Sonar";
   private static final String SUBJECT_DEFAULT = "Notification";
 
-  private EmailConfiguration configuration;
+  private EmailSettings configuration;
   private EmailTemplate[] templates;
   private UserFinder userFinder;
 
-  public EmailNotificationChannel(EmailConfiguration configuration, EmailTemplate[] templates, UserFinder userFinder) {
+  public EmailNotificationChannel(EmailSettings configuration, EmailTemplate[] templates, UserFinder userFinder) {
     this.configuration = configuration;
     this.templates = templates;
     this.userFinder = userFinder;
index 49e7befdf7933d24b9d265bd24d334707c56ebf2..bf46289eb474840623d2bd4acf4c179b84b6d6ea 100644 (file)
@@ -30,17 +30,12 @@ import org.sonar.plugins.emailnotifications.reviews.ReviewEmailTemplate;
 import java.util.List;
 
 public class EmailNotificationsPlugin extends SonarPlugin {
-
   public List<Class<? extends ServerExtension>> getExtensions() {
     return ImmutableList.of(
-        EmailConfiguration.class,
-        EmailNotificationChannel.class,
-
-        ReviewEmailTemplate.class,
         ChangesInReviewAssignedToMeOrCreatedByMe.class,
-
+        EmailNotificationChannel.class,
         NewViolationsEmailTemplate.class,
-        NewViolationsOnMyFavouriteProject.class);
+        NewViolationsOnMyFavouriteProject.class,
+        ReviewEmailTemplate.class);
   }
-
 }
index 690b60335b21539b25872874c135bc6430f5f373..8db4314562ccce8a4e057d6ec775fdeceed71f54 100644 (file)
@@ -20,7 +20,7 @@
 package org.sonar.plugins.emailnotifications.newviolations;
 
 import org.sonar.api.notifications.Notification;
-import org.sonar.plugins.emailnotifications.EmailConfiguration;
+import org.sonar.api.platform.EmailSettings;
 import org.sonar.plugins.emailnotifications.api.EmailMessage;
 import org.sonar.plugins.emailnotifications.api.EmailTemplate;
 
@@ -31,9 +31,9 @@ import org.sonar.plugins.emailnotifications.api.EmailTemplate;
  */
 public class NewViolationsEmailTemplate extends EmailTemplate {
 
-  private EmailConfiguration configuration;
+  private EmailSettings configuration;
 
-  public NewViolationsEmailTemplate(EmailConfiguration configuration) {
+  public NewViolationsEmailTemplate(EmailSettings configuration) {
     this.configuration = configuration;
   }
 
index 21f54d81387380ad90b66e34297312ee012feaa1..93a41c9b7c81be2787c4fe8f0622aed0c224e427 100644 (file)
@@ -22,8 +22,8 @@ package org.sonar.plugins.emailnotifications.reviews;
 import org.apache.commons.lang.StringUtils;
 import org.sonar.api.database.model.User;
 import org.sonar.api.notifications.Notification;
+import org.sonar.api.platform.EmailSettings;
 import org.sonar.api.security.UserFinder;
-import org.sonar.plugins.emailnotifications.EmailConfiguration;
 import org.sonar.plugins.emailnotifications.api.EmailMessage;
 import org.sonar.plugins.emailnotifications.api.EmailTemplate;
 
@@ -34,10 +34,10 @@ import org.sonar.plugins.emailnotifications.api.EmailTemplate;
  */
 public class ReviewEmailTemplate extends EmailTemplate {
 
-  private EmailConfiguration configuration;
+  private EmailSettings configuration;
   private UserFinder userFinder;
 
-  public ReviewEmailTemplate(EmailConfiguration configuration, UserFinder userFinder) {
+  public ReviewEmailTemplate(EmailSettings configuration, UserFinder userFinder) {
     this.configuration = configuration;
     this.userFinder = userFinder;
   }
diff --git a/plugins/sonar-email-notifications-plugin/src/test/java/org/sonar/plugins/emailnotifications/EmailConfigurationTest.java b/plugins/sonar-email-notifications-plugin/src/test/java/org/sonar/plugins/emailnotifications/EmailConfigurationTest.java
deleted file mode 100644 (file)
index c9474ec..0000000
+++ /dev/null
@@ -1,53 +0,0 @@
-/*
- * 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.plugins.emailnotifications;
-
-import static org.hamcrest.Matchers.is;
-import static org.junit.Assert.assertThat;
-
-import org.apache.commons.configuration.BaseConfiguration;
-import org.apache.commons.configuration.Configuration;
-import org.junit.Before;
-import org.junit.Test;
-import org.sonar.api.CoreProperties;
-
-public class EmailConfigurationTest {
-
-  private EmailConfiguration emailConfiguration;
-
-  @Before
-  public void setUp() {
-    Configuration configuration = new BaseConfiguration();
-    emailConfiguration = new EmailConfiguration(configuration);
-  }
-
-  @Test
-  public void shouldReturnDefaultValues() {
-    assertThat(emailConfiguration.getSmtpHost(), is(""));
-    assertThat(emailConfiguration.getSmtpPort(), is("25"));
-    assertThat(emailConfiguration.getSmtpUsername(), is(""));
-    assertThat(emailConfiguration.getSmtpPassword(), is(""));
-    assertThat(emailConfiguration.getSecureConnection(), is(""));
-    assertThat(emailConfiguration.getFrom(), is("noreply@nowhere"));
-    assertThat(emailConfiguration.getPrefix(), is("[SONAR]"));
-    assertThat(emailConfiguration.getServerBaseURL(), is(CoreProperties.SERVER_BASE_URL_DEFAULT_VALUE));
-  }
-
-}
index ed485db690fb0d19146c0ef2d4be5aabb6afaf01..3940b7d780966f47fcf61c615e8c9a901a0e7ab4 100644 (file)
@@ -23,16 +23,20 @@ import org.apache.commons.mail.EmailException;
 import org.junit.After;
 import org.junit.Before;
 import org.junit.Test;
+import org.sonar.api.platform.EmailSettings;
 import org.sonar.plugins.emailnotifications.api.EmailMessage;
 import org.subethamail.wiser.Wiser;
 import org.subethamail.wiser.WiserMessage;
 
 import javax.mail.internet.MimeMessage;
+
 import java.io.IOException;
 import java.net.ServerSocket;
 import java.util.List;
 
-import static org.hamcrest.Matchers.*;
+import static org.hamcrest.Matchers.is;
+import static org.hamcrest.Matchers.nullValue;
+import static org.hamcrest.Matchers.startsWith;
 import static org.junit.Assert.assertThat;
 import static org.junit.Assert.fail;
 import static org.mockito.Mockito.mock;
@@ -42,7 +46,7 @@ public class EmailNotificationChannelTest {
 
   private int port;
   private Wiser server;
-  private EmailConfiguration configuration;
+  private EmailSettings configuration;
   private EmailNotificationChannel channel;
 
   private static int getNextAvailablePort() {
@@ -63,7 +67,7 @@ public class EmailNotificationChannelTest {
     server.setPort(port);
     server.start();
 
-    configuration = mock(EmailConfiguration.class);
+    configuration = mock(EmailSettings.class);
     channel = new EmailNotificationChannel(configuration, null, null);
   }
 
index 4ee7d5f9d99d68f9be4340cf0df646bc3df252f3..eceb69f392ebfc064433680d860864a048c97d35 100644 (file)
  */
 package org.sonar.plugins.emailnotifications;
 
-import static org.hamcrest.Matchers.greaterThan;
-import static org.junit.Assert.assertThat;
-
 import org.junit.Test;
 
-public class EmailNotificationsPluginTest {
+import static org.fest.assertions.Assertions.assertThat;
 
+public class EmailNotificationsPluginTest {
   @Test
-  public void testGetExtensions() {
-    assertThat(new EmailNotificationsPlugin().getExtensions().size(), greaterThan(1));
+  public void should_get_extensions() {
+    assertThat(new EmailNotificationsPlugin().getExtensions()).hasSize(5);
   }
-
 }
index 3982ac4fd2a0aed90cbf2fe27180167edfe28309..43b0368e6368e35d9b8d501f214e4ba062ffdcce 100644 (file)
  */
 package org.sonar.plugins.emailnotifications.newviolations;
 
+import org.junit.Before;
+import org.junit.Test;
+import org.sonar.api.notifications.Notification;
+import org.sonar.api.platform.EmailSettings;
+import org.sonar.plugins.emailnotifications.api.EmailMessage;
+
 import static org.hamcrest.Matchers.is;
 import static org.hamcrest.Matchers.nullValue;
 import static org.junit.Assert.assertThat;
 import static org.mockito.Mockito.mock;
 import static org.mockito.Mockito.when;
 
-import org.junit.Before;
-import org.junit.Test;
-import org.sonar.api.notifications.Notification;
-import org.sonar.plugins.emailnotifications.EmailConfiguration;
-import org.sonar.plugins.emailnotifications.api.EmailMessage;
-
 public class NewViolationsEmailTemplateTest {
 
   private NewViolationsEmailTemplate template;
 
   @Before
   public void setUp() {
-    EmailConfiguration configuration = mock(EmailConfiguration.class);
+    EmailSettings configuration = mock(EmailSettings.class);
     when(configuration.getServerBaseURL()).thenReturn("http://nemo.sonarsource.org");
     template = new NewViolationsEmailTemplate(configuration);
   }
index a55bc3502e05021f033eb46bb0fd3f9dae252836..d9605a369355f56b3447ed53be68e0524c12e044 100644 (file)
  */
 package org.sonar.plugins.emailnotifications.reviews;
 
-import static org.hamcrest.Matchers.is;
-import static org.hamcrest.Matchers.nullValue;
-import static org.junit.Assert.assertThat;
-import static org.mockito.Matchers.eq;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.when;
-
 import org.junit.Before;
 import org.junit.Test;
 import org.sonar.api.database.model.User;
 import org.sonar.api.notifications.Notification;
+import org.sonar.api.platform.EmailSettings;
 import org.sonar.api.security.UserFinder;
-import org.sonar.plugins.emailnotifications.EmailConfiguration;
 import org.sonar.plugins.emailnotifications.api.EmailMessage;
 
+import static org.hamcrest.Matchers.is;
+import static org.hamcrest.Matchers.nullValue;
+import static org.junit.Assert.assertThat;
+import static org.mockito.Matchers.eq;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
 public class ReviewEmailTemplateTest {
 
   private ReviewEmailTemplate template;
 
   @Before
   public void setUp() {
-    EmailConfiguration configuration = mock(EmailConfiguration.class);
+    EmailSettings configuration = mock(EmailSettings.class);
     when(configuration.getServerBaseURL()).thenReturn("http://nemo.sonarsource.org");
     UserFinder userFinder = mock(UserFinder.class);
     when(userFinder.findByLogin(eq("freddy.mallet"))).thenReturn(new User().setName("Freddy Mallet"));
index c987c4d09c0e86544ad3c38ceba263f76f5837e7..7d50521b4e9842342b01451ed6825a64a38d86ff 100644 (file)
@@ -21,6 +21,7 @@ package org.sonar.batch.bootstrap;
 
 import org.apache.commons.configuration.PropertiesConfiguration;
 import org.sonar.api.batch.bootstrap.ProjectReactor;
+import org.sonar.api.platform.EmailSettings;
 import org.sonar.api.utils.HttpDownloader;
 import org.sonar.batch.FakeMavenPluginExecutor;
 import org.sonar.batch.MavenPluginExecutor;
@@ -61,6 +62,7 @@ public class BootstrapModule extends Module {
     addCoreSingleton(HttpDownloader.class);// registered here because used by BootstrapClassLoader
     addCoreSingleton(ArtifactDownloader.class);// registered here because used by BootstrapClassLoader
     addCoreSingleton(JdbcDriverHolder.class);
+    addCoreSingleton(EmailSettings.class);
 
     URLClassLoader bootstrapClassLoader = getComponentByType(JdbcDriverHolder.class).getClassLoader();
     // set as the current context classloader for hibernate, else it does not find the JDBC driver.
diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/platform/EmailSettings.java b/sonar-plugin-api/src/main/java/org/sonar/api/platform/EmailSettings.java
new file mode 100644 (file)
index 0000000..23eaac6
--- /dev/null
@@ -0,0 +1,90 @@
+/*
+ * 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.platform;
+
+import com.google.common.base.Objects;
+import org.sonar.api.BatchComponent;
+import org.sonar.api.CoreProperties;
+import org.sonar.api.ServerComponent;
+import org.sonar.api.config.Settings;
+
+/**
+ * Ruby uses constants from this class.
+ * 
+ * @since 3.2
+ */
+public class EmailSettings implements BatchComponent, ServerComponent {
+  public static final String SMTP_HOST = "email.smtp_host.secured";
+  public static final String SMTP_HOST_DEFAULT = "";
+  public static final String SMTP_PORT = "email.smtp_port.secured";
+  public static final String SMTP_PORT_DEFAULT = "25";
+  public static final String SMTP_SECURE_CONNECTION = "email.smtp_secure_connection.secured";
+  public static final String SMTP_SECURE_CONNECTION_DEFAULT = "";
+  public static final String SMTP_USERNAME = "email.smtp_username.secured";
+  public static final String SMTP_USERNAME_DEFAULT = "";
+  public static final String SMTP_PASSWORD = "email.smtp_password.secured";
+  public static final String SMTP_PASSWORD_DEFAULT = "";
+  public static final String FROM = "email.from";
+  public static final String FROM_DEFAULT = "noreply@nowhere";
+  public static final String PREFIX = "email.prefix";
+  public static final String PREFIX_DEFAULT = "[SONAR]";
+
+  private final Settings settings;
+
+  public EmailSettings(Settings settings) {
+    this.settings = settings;
+  }
+
+  public String getSmtpHost() {
+    return get(SMTP_HOST, SMTP_HOST_DEFAULT);
+  }
+
+  public String getSmtpPort() {
+    return get(SMTP_PORT, SMTP_PORT_DEFAULT);
+  }
+
+  public String getSecureConnection() {
+    return get(SMTP_SECURE_CONNECTION, SMTP_SECURE_CONNECTION_DEFAULT);
+  }
+
+  public String getSmtpUsername() {
+    return get(SMTP_USERNAME, SMTP_USERNAME_DEFAULT);
+  }
+
+  public String getSmtpPassword() {
+    return get(SMTP_PASSWORD, SMTP_PASSWORD_DEFAULT);
+  }
+
+  public String getFrom() {
+    return get(FROM, FROM_DEFAULT);
+  }
+
+  public String getPrefix() {
+    return get(PREFIX, PREFIX_DEFAULT);
+  }
+
+  public String getServerBaseURL() {
+    return get(CoreProperties.SERVER_BASE_URL, CoreProperties.SERVER_BASE_URL_DEFAULT_VALUE);
+  }
+
+  private String get(String key, String defaultValue) {
+    return Objects.firstNonNull(settings.getString(key), defaultValue);
+  }
+}
diff --git a/sonar-plugin-api/src/test/java/org/sonar/api/platform/EmailSettingsTest.java b/sonar-plugin-api/src/test/java/org/sonar/api/platform/EmailSettingsTest.java
new file mode 100644 (file)
index 0000000..f548b2f
--- /dev/null
@@ -0,0 +1,48 @@
+/*
+ * 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.platform;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.sonar.api.CoreProperties;
+import org.sonar.api.config.Settings;
+
+import static org.fest.assertions.Assertions.assertThat;
+
+public class EmailSettingsTest {
+  EmailSettings emailSettings;
+
+  @Before
+  public void setUp() {
+    emailSettings = new EmailSettings(new Settings());
+  }
+
+  @Test
+  public void should_return_default_values() {
+    assertThat(emailSettings.getSmtpHost()).isEqualTo("");
+    assertThat(emailSettings.getSmtpPort()).isEqualTo("25");
+    assertThat(emailSettings.getSmtpUsername()).isEmpty();
+    assertThat(emailSettings.getSmtpPassword()).isEmpty();
+    assertThat(emailSettings.getSecureConnection()).isEmpty();
+    assertThat(emailSettings.getFrom()).isEqualTo("noreply@nowhere");
+    assertThat(emailSettings.getPrefix()).isEqualTo("[SONAR]");
+    assertThat(emailSettings.getServerBaseURL()).isEqualTo(CoreProperties.SERVER_BASE_URL_DEFAULT_VALUE);
+  }
+}
index 26981427754be6f9273dafd8de6f6a8db7d1d249..e0d9f48858a8653ced5fb8cd554ba4a8b71d95c0 100644 (file)
@@ -19,8 +19,7 @@
  */
 package org.sonar.server.platform;
 
-import org.sonar.api.workflow.internal.DefaultWorkflow;
-import org.sonar.server.startup.RegisterNewFilters;
+import org.sonar.api.platform.EmailSettings;
 
 import org.apache.commons.configuration.BaseConfiguration;
 import org.slf4j.LoggerFactory;
@@ -37,18 +36,23 @@ import org.sonar.api.rules.XMLRuleParser;
 import org.sonar.api.utils.HttpDownloader;
 import org.sonar.api.utils.IocContainer;
 import org.sonar.api.utils.TimeProfiler;
+import org.sonar.api.workflow.internal.DefaultWorkflow;
 import org.sonar.core.PicoUtils;
 import org.sonar.core.i18n.GwtI18n;
 import org.sonar.core.i18n.I18nManager;
 import org.sonar.core.i18n.RuleI18nManager;
 import org.sonar.core.metric.DefaultMetricFinder;
 import org.sonar.core.notification.DefaultNotificationManager;
-import org.sonar.core.persistence.*;
+import org.sonar.core.persistence.DaoUtils;
+import org.sonar.core.persistence.DatabaseMigrator;
+import org.sonar.core.persistence.DatabaseVersion;
+import org.sonar.core.persistence.DefaultDatabase;
+import org.sonar.core.persistence.MyBatis;
 import org.sonar.core.qualitymodel.DefaultModelFinder;
-import org.sonar.core.workflow.ReviewDatabaseStore;
-import org.sonar.core.workflow.WorkflowEngine;
 import org.sonar.core.rule.DefaultRuleFinder;
 import org.sonar.core.user.DefaultUserFinder;
+import org.sonar.core.workflow.ReviewDatabaseStore;
+import org.sonar.core.workflow.WorkflowEngine;
 import org.sonar.jpa.dao.MeasuresDao;
 import org.sonar.jpa.dao.ProfilesDao;
 import org.sonar.jpa.dao.RulesDao;
@@ -63,11 +67,29 @@ import org.sonar.server.database.EmbeddedDatabaseFactory;
 import org.sonar.server.filters.FilterExecutor;
 import org.sonar.server.notifications.NotificationService;
 import org.sonar.server.notifications.reviews.ReviewsNotificationManager;
-import org.sonar.server.plugins.*;
+import org.sonar.server.plugins.ApplicationDeployer;
+import org.sonar.server.plugins.DefaultServerPluginRepository;
+import org.sonar.server.plugins.PluginDeployer;
+import org.sonar.server.plugins.PluginDownloader;
+import org.sonar.server.plugins.ServerExtensionInstaller;
+import org.sonar.server.plugins.UpdateCenterClient;
+import org.sonar.server.plugins.UpdateCenterMatrixFactory;
 import org.sonar.server.qualitymodel.DefaultModelManager;
 import org.sonar.server.rules.ProfilesConsole;
 import org.sonar.server.rules.RulesConsole;
-import org.sonar.server.startup.*;
+import org.sonar.server.startup.ActivateDefaultProfiles;
+import org.sonar.server.startup.DeleteDeprecatedMeasures;
+import org.sonar.server.startup.EnableProfiles;
+import org.sonar.server.startup.GeneratePluginIndex;
+import org.sonar.server.startup.GwtPublisher;
+import org.sonar.server.startup.JdbcDriverDeployer;
+import org.sonar.server.startup.RegisterMetrics;
+import org.sonar.server.startup.RegisterNewDashboards;
+import org.sonar.server.startup.RegisterNewFilters;
+import org.sonar.server.startup.RegisterProvidedProfiles;
+import org.sonar.server.startup.RegisterQualityModels;
+import org.sonar.server.startup.RegisterRules;
+import org.sonar.server.startup.ServerMetadataPersister;
 import org.sonar.server.ui.CodeColorizers;
 import org.sonar.server.ui.JRubyI18n;
 import org.sonar.server.ui.SecurityRealmFactory;
@@ -219,6 +241,7 @@ public final class Platform {
     servicesContainer.addSingleton(ResourceTypes.class);
 
     // Notifications
+    servicesContainer.addSingleton(EmailSettings.class);
     servicesContainer.addSingleton(NotificationService.class);
     servicesContainer.addSingleton(DefaultNotificationManager.class);
     servicesContainer.addSingleton(ReviewsNotificationManager.class);
index 8f4f2c74d52c41813f979d1b18ba7965dd7046ea..e5c77a7e50d53cd7c302c349f7c78d37b56241d8 100644 (file)
@@ -23,49 +23,49 @@ class EmailConfigurationController < ApplicationController
   before_filter :admin_required
 
   def index
-    @smtp_host = Property.value(configuration::SMTP_HOST, nil, configuration::SMTP_HOST_DEFAULT)
-    @smtp_port = Property.value(configuration::SMTP_PORT, nil, configuration::SMTP_PORT_DEFAULT)
-    @smtp_secure_connection = Property.value(configuration::SMTP_SECURE_CONNECTION, nil, configuration::SMTP_SECURE_CONNECTION)
-    @smtp_username = Property.value(configuration::SMTP_USERNAME, nil, configuration::SMTP_USERNAME_DEFAULT)
-    @smtp_password = Property.value(configuration::SMTP_PASSWORD, nil, configuration::SMTP_PASSWORD_DEFAULT)
-    @email_from = Property.value(configuration::FROM, nil, configuration::FROM_DEFAULT)
-    @email_prefix = Property.value(configuration::PREFIX, nil, configuration::PREFIX_DEFAULT)
-    params[:layout]='false'
+       @smtp_host = Property.value(configuration::SMTP_HOST, nil, configuration::SMTP_HOST_DEFAULT)
+       @smtp_port = Property.value(configuration::SMTP_PORT, nil, configuration::SMTP_PORT_DEFAULT)
+       @smtp_secure_connection = Property.value(configuration::SMTP_SECURE_CONNECTION, nil, configuration::SMTP_SECURE_CONNECTION)
+       @smtp_username = Property.value(configuration::SMTP_USERNAME, nil, configuration::SMTP_USERNAME_DEFAULT)
+       @smtp_password = Property.value(configuration::SMTP_PASSWORD, nil, configuration::SMTP_PASSWORD_DEFAULT)
+       @email_from = Property.value(configuration::FROM, nil, configuration::FROM_DEFAULT)
+       @email_prefix = Property.value(configuration::PREFIX, nil, configuration::PREFIX_DEFAULT)
+       params[:layout]='false'
   end
 
   def save
-    Property.set(configuration::SMTP_HOST, params[:smtp_host])
-    Property.set(configuration::SMTP_PORT, params[:smtp_port])
-    Property.set(configuration::SMTP_SECURE_CONNECTION, params[:smtp_secure_connection])
-    Property.set(configuration::SMTP_USERNAME, params[:smtp_username])
-    Property.set(configuration::SMTP_PASSWORD, params[:smtp_password])
-    Property.set(configuration::FROM, params[:email_from])
-    Property.set(configuration::PREFIX, params[:email_prefix])
-    flash[:notice] = message('email_configuration.settings_saved')
-    redirect_to :action => 'index'
+       Property.set(configuration::SMTP_HOST, params[:smtp_host])
+       Property.set(configuration::SMTP_PORT, params[:smtp_port])
+       Property.set(configuration::SMTP_SECURE_CONNECTION, params[:smtp_secure_connection])
+       Property.set(configuration::SMTP_USERNAME, params[:smtp_username])
+       Property.set(configuration::SMTP_PASSWORD, params[:smtp_password])
+       Property.set(configuration::FROM, params[:email_from])
+       Property.set(configuration::PREFIX, params[:email_prefix])
+       flash[:notice] = message('email_configuration.settings_saved')
+       redirect_to :action => 'index'
   end
 
   def send_test_email
-    to_address = params[:to_address]
-    subject = params[:subject]
-    message = params[:message]
-    if to_address.blank?
-      flash[:error] = message('email_configuration.test.to_address_required')
-    else
-      begin
-        java_facade.getComponentByClassname('emailnotifications', 'org.sonar.plugins.emailnotifications.EmailNotificationChannel').sendTestEmail(to_address, subject, message)
-        flash[:notice] = message('email_configuration.test.email_was_sent_to_x', :params => [to_address])
-      rescue Exception => e
-        flash[:error] = e.message
-      end
-    end
-    redirect_to :action => 'index'
+       to_address = params[:to_address]
+       subject = params[:subject]
+       message = params[:message]
+       if to_address.blank?
+         flash[:error] = message('email_configuration.test.to_address_required')
+       else
+         begin
+               java_facade.getComponentByClassname('emailnotifications', 'org.sonar.plugins.emailnotifications.EmailNotificationChannel').sendTestEmail(to_address, subject, message)
+               flash[:notice] = message('email_configuration.test.email_was_sent_to_x', :params => [to_address])
+         rescue Exception => e
+               flash[:error] = e.message
+         end
+       end
+       redirect_to :action => 'index'
   end
 
   private
 
   def configuration
-    java_facade.getComponentByClassname('emailnotifications', 'org.sonar.plugins.emailnotifications.EmailConfiguration').class
+       java_facade.getComponentByClassname('emailnotifications', 'org.sonar.api.platform.EmailSettings').class
   end
 
 end