*/
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;
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;
})
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);
}
}
+++ /dev/null
-/*
- * Sonar, open source software quality management tool.
- * Copyright (C) 2008-2012 SonarSource
- * mailto:contact AT sonarsource DOT com
- *
- * Sonar is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or (at your option) any later version.
- *
- * Sonar is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with Sonar; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
- */
-package org.sonar.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);
- }
-
-}
*/
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;
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>
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;
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);
}
-
}
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;
*/
public class NewViolationsEmailTemplate extends EmailTemplate {
- private EmailConfiguration configuration;
+ private EmailSettings configuration;
- public NewViolationsEmailTemplate(EmailConfiguration configuration) {
+ public NewViolationsEmailTemplate(EmailSettings configuration) {
this.configuration = configuration;
}
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;
*/
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;
}
+++ /dev/null
-/*
- * Sonar, open source software quality management tool.
- * Copyright (C) 2008-2012 SonarSource
- * mailto:contact AT sonarsource DOT com
- *
- * Sonar is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or (at your option) any later version.
- *
- * Sonar is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with Sonar; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
- */
-package org.sonar.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));
- }
-
-}
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;
private int port;
private Wiser server;
- private EmailConfiguration configuration;
+ private EmailSettings configuration;
private EmailNotificationChannel channel;
private static int getNextAvailablePort() {
server.setPort(port);
server.start();
- configuration = mock(EmailConfiguration.class);
+ configuration = mock(EmailSettings.class);
channel = new EmailNotificationChannel(configuration, null, null);
}
*/
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);
}
-
}
*/
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);
}
*/
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"));
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;
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.
--- /dev/null
+/*
+ * Sonar, open source software quality management tool.
+ * Copyright (C) 2008-2012 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * Sonar is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * Sonar is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with Sonar; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
+ */
+package org.sonar.api.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);
+ }
+}
--- /dev/null
+/*
+ * Sonar, open source software quality management tool.
+ * Copyright (C) 2008-2012 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * Sonar is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * Sonar is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with Sonar; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
+ */
+package org.sonar.api.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);
+ }
+}
*/
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;
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;
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;
servicesContainer.addSingleton(ResourceTypes.class);
// Notifications
+ servicesContainer.addSingleton(EmailSettings.class);
servicesContainer.addSingleton(NotificationService.class);
servicesContainer.addSingleton(DefaultNotificationManager.class);
servicesContainer.addSingleton(ReviewsNotificationManager.class);
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