Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Merge pull request #24 from andresrc/JENKINS-33266
[JENKINS-33266] Upgrade to new Parent POM
  • Loading branch information
jglick committed Mar 4, 2016
2 parents fc9e606 + b5149ed commit 8551722
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 90 deletions.
72 changes: 3 additions & 69 deletions pom.xml
Expand Up @@ -3,7 +3,7 @@
<parent>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>plugin</artifactId>
<version>1.580.1</version>
<version>2.3</version>
</parent>

<artifactId>mailer</artifactId>
Expand All @@ -21,17 +21,10 @@
</licenses>
<properties>
<powermock.version>1.6.2</powermock.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<findbugs-maven-plugin.version>3.0.2</findbugs-maven-plugin.version>
<findbugs.failOnError>true</findbugs.failOnError>
<jenkins.version>1.580.1</jenkins.version>
<java.level>6</java.level>
</properties>
<dependencies>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
<version>2.4</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>javax.mail</groupId>
<artifactId>mail</artifactId>
Expand Down Expand Up @@ -80,66 +73,7 @@
<version>${powermock.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.google.code.findbugs</groupId>
<artifactId>annotations</artifactId>
<version>3.0.0</version>
<scope>provided</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>1.6</source>
<target>1.6</target>
</configuration>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>findbugs-maven-plugin</artifactId>
<version>${findbugs-maven-plugin.version}</version>
<configuration>
<xmlOutput>true</xmlOutput>
<findbugsXmlWithMessages>true</findbugsXmlWithMessages>
<failOnError>${findbugs.failOnError}</failOnError>
</configuration>
<executions>
<execution>
<id>run-findbugs</id>
<phase>verify</phase>
<goals>
<goal>check</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>animal-sniffer-maven-plugin</artifactId>
<version>1.13</version>
<executions>
<execution>
<id>check-java-api</id>
<phase>test</phase>
<goals>
<goal>check</goal>
</goals>
<configuration>
<signature>
<groupId>org.codehaus.mojo.signature</groupId>
<artifactId>java16</artifactId>
<version>1.1</version>
</signature>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
<scm>
<connection>scm:git:git://github.com/jenkinsci/${project.artifactId}-plugin.git</connection>
<developerConnection>scm:git:git@github.com:jenkinsci/${project.artifactId}-plugin.git</developerConnection>
Expand Down
27 changes: 21 additions & 6 deletions src/main/java/hudson/tasks/Mailer.java
Expand Up @@ -407,20 +407,35 @@ public String getSmtpServer() {
return smtpHost;
}

/**
* Method added to pass findbugs verification when compiling against 1.642.1
* @return The JenkinsLocationConfiguration object.
* @throws IllegalStateException if the object is not available (e.g., Jenkins not fully initialized).
*/
@SuppressFBWarnings(value = "NP_NULL_ON_SOME_PATH_FROM_RETURN_VALUE",
justification = "False positive. See https://sourceforge.net/p/findbugs/bugs/1411/")
private JenkinsLocationConfiguration getJenkinsLocationConfiguration() {
final JenkinsLocationConfiguration jlc = JenkinsLocationConfiguration.get();
if (jlc == null) {
throw new IllegalStateException("JenkinsLocationConfiguration not available");
}
return jlc;
}

/**
* @deprecated as of 1.4
* Use {@link JenkinsLocationConfiguration}
*/
public String getAdminAddress() {
return JenkinsLocationConfiguration.get().getAdminAddress();
return getJenkinsLocationConfiguration().getAdminAddress();
}

/**
* @deprecated as of 1.4
* Use {@link JenkinsLocationConfiguration}
*/
public String getUrl() {
return JenkinsLocationConfiguration.get().getUrl();
return getJenkinsLocationConfiguration().getUrl();
}

public String getSmtpAuthUserName() {
Expand Down Expand Up @@ -459,15 +474,15 @@ public void setDefaultSuffix(String defaultSuffix) {
* Use {@link JenkinsLocationConfiguration}
*/
public void setHudsonUrl(String hudsonUrl) {
JenkinsLocationConfiguration.get().setUrl(hudsonUrl);
getJenkinsLocationConfiguration().setUrl(hudsonUrl);
}

/**
* @deprecated as of 1.4
* Use {@link JenkinsLocationConfiguration}
*/
public void setAdminAddress(String adminAddress) {
JenkinsLocationConfiguration.get().setAdminAddress(adminAddress);
getJenkinsLocationConfiguration().setAdminAddress(adminAddress);
}

public void setSmtpHost(String smtpHost) {
Expand Down Expand Up @@ -640,8 +655,8 @@ public UserProperty newInstance(User user) {
}

@Override
public UserProperty newInstance(StaplerRequest req, JSONObject formData) throws FormException {
return new UserProperty(req.getParameter("email.address"));
public UserProperty newInstance(@CheckForNull StaplerRequest req, JSONObject formData) throws FormException {
return new UserProperty(req != null ? req.getParameter("email.address") : null);
}
}
}
Expand Down
Expand Up @@ -78,9 +78,12 @@ public class MimeMessageBuilder {

public MimeMessageBuilder() {
if (Jenkins.getInstance() != null) {
defaultSuffix = Mailer.descriptor().getDefaultSuffix();
from = JenkinsLocationConfiguration.get().getAdminAddress();
replyTo = Mailer.descriptor().getReplyToAddress();
JenkinsLocationConfiguration jlc = JenkinsLocationConfiguration.get();
if (jlc != null) {
defaultSuffix = Mailer.descriptor().getDefaultSuffix();
from = jlc.getAdminAddress();
replyTo = Mailer.descriptor().getReplyToAddress();
}
}
}

Expand Down
39 changes: 27 additions & 12 deletions src/test/java/hudson/tasks/MailerTest.java
Expand Up @@ -26,23 +26,35 @@
import hudson.model.FreeStyleBuild;
import hudson.model.FreeStyleProject;
import hudson.tasks.Mailer.DescriptorImpl;
import org.junit.Rule;
import org.junit.Test;
import org.jvnet.hudson.test.Bug;
import org.jvnet.hudson.test.FailureBuilder;
import org.jvnet.hudson.test.HudsonTestCase;
import org.jvnet.hudson.test.Email;
import org.jvnet.hudson.test.JenkinsRule;
import org.jvnet.hudson.test.JenkinsRule.WebClient;
import org.jvnet.mock_javamail.Mailbox;

import javax.mail.Address;
import javax.mail.internet.InternetAddress;

import jenkins.model.JenkinsLocationConfiguration;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotSame;
import static org.junit.Assert.assertNull;


/**
* @author Kohsuke Kawaguchi
*/
public class MailerTest extends HudsonTestCase {
public class MailerTest {

@Rule
public JenkinsRule rule = new JenkinsRule();

@Bug(1566)
@Test
public void testSenderAddress() throws Exception {
// intentionally give the whole thin in a double quote
JenkinsLocationConfiguration.get().setAdminAddress("\"me <me@sun.com>\"");
Expand All @@ -52,20 +64,21 @@ public void testSenderAddress() throws Exception {
yourInbox.clear();

// create a project to simulate a build failure
FreeStyleProject project = createFreeStyleProject();
FreeStyleProject project = rule.createFreeStyleProject();
project.getBuildersList().add(new FailureBuilder());
Mailer m = new Mailer(recipient, false, false);
project.getPublishersList().add(m);

FreeStyleBuild b = project.scheduleBuild2(0).get();

assertEquals(getLog(b), 1, yourInbox.size());
assertEquals(rule.getLog(b), 1, yourInbox.size());
Address[] senders = yourInbox.get(0).getFrom();
assertEquals(1,senders.length);
assertEquals("me <me@sun.com>",senders[0].toString());
}

@Email("http://www.nabble.com/email-recipients-disappear-from-freestyle-job-config-on-save-to25479293.html")
@Test
public void testConfigRoundtrip() throws Exception {
Mailer m = new Mailer("kk@kohsuke.org", false, true);
verifyRoundtrip(m);
Expand All @@ -75,14 +88,15 @@ public void testConfigRoundtrip() throws Exception {
}

private void verifyRoundtrip(Mailer before) throws Exception {
FreeStyleProject p = createFreeStyleProject();
FreeStyleProject p = rule.createFreeStyleProject();
p.getPublishersList().add(before);
submit(new WebClient().getPage(p,"configure").getFormByName("config"));
rule.submit(rule.createWebClient().getPage(p,"configure").getFormByName("config"));
Mailer after = p.getPublishersList().get(Mailer.class);
assertNotSame(before,after);
assertEqualBeans(before,after,"recipients,dontNotifyEveryUnstableBuild,sendToIndividuals");
rule.assertEqualBeans(before,after,"recipients,dontNotifyEveryUnstableBuild,sendToIndividuals");
}

@Test
public void testGlobalConfigRoundtrip() throws Exception {
DescriptorImpl d = Mailer.descriptor();
JenkinsLocationConfiguration.get().setAdminAddress("admin@me");
Expand All @@ -93,7 +107,7 @@ public void testGlobalConfigRoundtrip() throws Exception {
d.setUseSsl(true);
d.setSmtpAuth("user","pass");

submit(new WebClient().goTo("configure").getFormByName("config"));
rule.submit(rule.createWebClient().goTo("configure").getFormByName("config"));

assertEquals("admin@me", JenkinsLocationConfiguration.get().getAdminAddress());
assertEquals("default-suffix",d.getDefaultSuffix());
Expand All @@ -106,7 +120,7 @@ public void testGlobalConfigRoundtrip() throws Exception {

d.setUseSsl(false);
d.setSmtpAuth(null,null);
submit(new WebClient().goTo("configure").getFormByName("config"));
rule.submit(rule.createWebClient().goTo("configure").getFormByName("config"));
assertEquals(false,d.getUseSsl());
assertNull("expected null, got: " + d.getSmtpAuthUserName(), d.getSmtpAuthUserName());
assertNull("expected null, got: " + d.getSmtpAuthPassword(), d.getSmtpAuthPassword());
Expand All @@ -126,15 +140,16 @@ public synchronized void load() {
/**
* Test {@link JenkinsLocationConfiguration} can load hudsonUrl.
*/
@Test
public void testHudsonUrlCompatibility() throws Exception {
// not configured.
assertNull(new CleanJenkinsLocationConfiguration().getUrl());

Mailer m = new Mailer("", true, false);
FreeStyleProject p = createFreeStyleProject();
FreeStyleProject p = rule.createFreeStyleProject();
p.getPublishersList().add(m);
WebClient wc = new WebClient();
submit(wc.getPage(p,"configure").getFormByName("config"));
WebClient wc = rule.createWebClient();
rule.submit(wc.getPage(p,"configure").getFormByName("config"));

// configured via the marshaled XML file of Mailer
assertEquals(wc.getContextPath(), new CleanJenkinsLocationConfiguration().getUrl());
Expand Down

0 comments on commit 8551722

Please sign in to comment.