Skip to content

Commit

Permalink
[FIXED JENKINS-21045] Hacks used by MavenMailer to load config.jelly …
Browse files Browse the repository at this point in the history
…from plain Mailer broke in mailer 1.6.

Fixing to use its own copy of the configuration page.
Also simplifying handling of perModuleEmail (this should be part of MavenMailer, not MavenModuleSet);
and generally normalizing and simplifying form databinding.
  • Loading branch information
jglick authored and olivergondza committed Dec 31, 2013
1 parent b28d95f commit 4cceffb
Show file tree
Hide file tree
Showing 5 changed files with 69 additions and 47 deletions.
9 changes: 7 additions & 2 deletions pom.xml
Expand Up @@ -55,7 +55,12 @@ THE SOFTWARE.
<system>jira</system>
<url>https://issues.jenkins-ci.org/browse/JENKINS/component/15487</url>
</issueManagement>

<licenses>
<license>
<name>MIT License</name>
<url>http://www.opensource.org/licenses/mit-license.php</url>
</license>
</licenses>
<dependencies>
<dependency>
<groupId>org.jenkins-ci.plugins</groupId>
Expand All @@ -65,7 +70,7 @@ THE SOFTWARE.
<dependency>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>mailer</artifactId>
<version>1.5</version>
<version>1.7</version>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
Expand Down
25 changes: 8 additions & 17 deletions src/main/java/hudson/maven/MavenModuleSet.java
Expand Up @@ -36,6 +36,7 @@
import hudson.maven.local_repo.DefaultLocalRepositoryLocator;
import hudson.maven.local_repo.LocalRepositoryLocator;
import hudson.maven.local_repo.PerJobLocalRepositoryLocator;
import hudson.maven.reporters.MavenMailer;
import hudson.model.AbstractProject;
import hudson.model.Action;
import hudson.model.BuildableItemWithBuildWrappers;
Expand Down Expand Up @@ -90,9 +91,6 @@
import javax.servlet.ServletException;

import jenkins.model.Jenkins;
import jenkins.model.ModelObjectWithChildren;
import jenkins.mvn.DefaultGlobalSettingsProvider;
import jenkins.mvn.DefaultSettingsProvider;
import jenkins.mvn.FilePathSettingsProvider;
import jenkins.mvn.GlobalMavenConfig;
import jenkins.mvn.GlobalSettingsProvider;
Expand Down Expand Up @@ -217,14 +215,6 @@ public class MavenModuleSet extends AbstractMavenProject<MavenModuleSet,MavenMod
*/
private LocalRepositoryLocator localRepository = null;

/**
* If true, the build will send a failure e-mail for each failing maven module.
* Defaults to <code>true</code> to simulate old behavior.
* <p>
* see JENKINS-5695.
*/
private Boolean perModuleEmail = Boolean.TRUE;

/**
* If true, do not automatically schedule a build when one of the project dependencies is built.
* <p>
Expand Down Expand Up @@ -562,8 +552,11 @@ public boolean usesPrivateRepository() {
return !(getLocalRepository() instanceof DefaultLocalRepositoryLocator);
}

/** @deprecated see {@link MavenMailer#perModuleEmail} */
@Deprecated
public boolean isPerModuleEmail() {
return perModuleEmail;
MavenMailer m = reporters.get(MavenMailer.class);
return m != null ? m.perModuleEmail : true;
}

public boolean ignoreUpstremChanges() {
Expand Down Expand Up @@ -814,10 +807,6 @@ public ModuleName call(MavenModule module) {
}
postbuilders.setOwner(this);

if(perModuleEmail == null){
perModuleEmail = Boolean.TRUE;
}

if (Boolean.TRUE.equals(usePrivateRepository)) {
this.localRepository = new PerJobLocalRepositoryLocator();
usePrivateRepository = null;
Expand Down Expand Up @@ -1165,7 +1154,6 @@ protected void submit(StaplerRequest req, StaplerResponse rsp) throws IOExceptio
localRepository = req.bindJSON(LocalRepositoryLocator.class,json.getJSONObject("explicitLocalRepository"));
else
localRepository = null;
perModuleEmail = req.hasParameter("maven.perModuleEmail");
ignoreUpstremChanges = !json.has("triggerByDependency");
runHeadless = req.hasParameter("maven.runHeadless");
incrementalBuild = req.hasParameter("maven.incrementalBuild");
Expand Down Expand Up @@ -1258,6 +1246,9 @@ public DescriptorImpl() {
public String getHelpFile(String fieldName) {
String v = super.getHelpFile(fieldName);
if (v!=null) return v;
if (fieldName == null) {
return null;
}
return Jenkins.getInstance().getDescriptor(Maven.class).getHelpFile(fieldName);
}

Expand Down
41 changes: 15 additions & 26 deletions src/main/java/hudson/maven/reporters/MavenMailer.java
Expand Up @@ -26,32 +26,38 @@
import hudson.Launcher;
import hudson.Extension;
import hudson.maven.MavenBuild;
import hudson.maven.MavenModule;
import hudson.maven.MavenReporter;
import hudson.maven.MavenReporterDescriptor;
import hudson.model.BuildListener;
import hudson.tasks.MailSender;
import hudson.tasks.Mailer;

import org.kohsuke.stapler.StaplerRequest;

import java.io.IOException;

import net.sf.json.JSONObject;
import org.kohsuke.stapler.DataBoundConstructor;

/**
* Sends out an e-mail notification for Maven build result.
* @author Kohsuke Kawaguchi
*/
public class MavenMailer extends MavenReporter {
/**
* @see Mailer
*/
public String recipients;
/** not data-bound; set by {@link MavenModule} */
public String mavenRecipients;
/** negative sense is historical */
public boolean dontNotifyEveryUnstableBuild;
public boolean sendToIndividuals;
public boolean perModuleEmail;

@DataBoundConstructor public MavenMailer(String recipients, boolean notifyEveryUnstableBuild, boolean sendToIndividuals, boolean perModuleEmail) {
this.recipients = recipients;
this.dontNotifyEveryUnstableBuild = !notifyEveryUnstableBuild;
this.sendToIndividuals = sendToIndividuals;
this.perModuleEmail = perModuleEmail;
}

public boolean isNotifyEveryUnstableBuild() {
return !dontNotifyEveryUnstableBuild;
}

public boolean end(MavenBuild build, Launcher launcher, BuildListener listener) throws InterruptedException, IOException {
if(perModuleEmail) {
new MailSender(getAllRecipients(),dontNotifyEveryUnstableBuild,sendToIndividuals).execute(build,listener);
Expand Down Expand Up @@ -79,23 +85,6 @@ public String getDisplayName() {
return Messages.MavenMailer_DisplayName();
}

public String getHelpFile() {
return "/help/project-config/mailer.html";
}

// reuse the config from the mailer.
@Override
public String getConfigPage() {
return getViewPage(Mailer.class,"config.jelly");
}

public MavenReporter newInstance(StaplerRequest req, JSONObject formData) throws FormException {
MavenMailer m = new MavenMailer();
req.bindParameters(m,"mailer_");
m.dontNotifyEveryUnstableBuild = req.getParameter("mailer_notifyEveryUnstableBuild")==null;
m.perModuleEmail = req.hasParameter("maven.perModuleEmail");
return m;
}
}

private static final long serialVersionUID = 1L;
Expand Down
Expand Up @@ -100,8 +100,6 @@ THE SOFTWARE.
checked="${it.getExplicitLocalRepository()!=null}" inline="true">
<f:dropdownDescriptorSelector title="${%Strategy}" field="explicitLocalRepository" />
</f:optionalBlock>
<f:optionalBlock name="maven.perModuleEmail" title="${%Send e-mail for each failed module}" help="/plugin/maven-plugin/per-module-email.html"
checked="${it.isPerModuleEmail()}" />
<f:optionalBlock name="maven.resolveDependencies" title="${%Resolve Dependencies during Pom parsing}"
checked="${it.isResolveDependencies()}" />
<f:optionalBlock name="maven.runHeadless" title="${%Run Headless}" help="/plugin/maven-plugin/run-headless.html"
Expand Down
39 changes: 39 additions & 0 deletions src/main/resources/hudson/maven/reporters/MavenMailer/config.jelly
@@ -0,0 +1,39 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
The MIT License
Copyright 2013 Jesse Glick.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
-->
<?jelly escape-by-default='true'?>
<j:jelly xmlns:j="jelly:core" xmlns:f="/lib/form">
<f:entry field="recipients" title="${%Recipients}">
<f:textbox/>
</f:entry>
<f:entry field="notifyEveryUnstableBuild" title="${%Send e-mail for every unstable build}">
<f:checkbox default="true"/>
</f:entry>
<f:entry field="sendToIndividuals" title="${%Send separate e-mails to individuals who broke the build}">
<f:checkbox/>
</f:entry>
<f:entry field="perModuleEmail" title="${%Send e-mail for each failed module}" help="/plugin/maven-plugin/per-module-email.html">
<f:checkbox default="true"/>
</f:entry>
</j:jelly>

0 comments on commit 4cceffb

Please sign in to comment.