diff --git a/src/main/java/hudson/plugins/emailext/EmailExtRecipientStep.java b/src/main/java/hudson/plugins/emailext/EmailExtRecipientStep.java index b0d5bc672..97f7b793d 100644 --- a/src/main/java/hudson/plugins/emailext/EmailExtRecipientStep.java +++ b/src/main/java/hudson/plugins/emailext/EmailExtRecipientStep.java @@ -98,6 +98,7 @@ public String getFunctionName() { return "emailextrecipients"; } + @NonNull @Override public String getDisplayName() { return "Extended Email Recipients"; diff --git a/src/main/java/hudson/plugins/emailext/EmailExtStep.java b/src/main/java/hudson/plugins/emailext/EmailExtStep.java index dd7a330e5..535380934 100644 --- a/src/main/java/hudson/plugins/emailext/EmailExtStep.java +++ b/src/main/java/hudson/plugins/emailext/EmailExtStep.java @@ -270,6 +270,7 @@ public String getFunctionName() { return "emailext"; } + @NonNull @Override public String getDisplayName() { return "Extended Email"; diff --git a/src/main/java/hudson/plugins/emailext/ExtendedEmailPublisher.java b/src/main/java/hudson/plugins/emailext/ExtendedEmailPublisher.java index 87444e4c8..dd53778d4 100644 --- a/src/main/java/hudson/plugins/emailext/ExtendedEmailPublisher.java +++ b/src/main/java/hudson/plugins/emailext/ExtendedEmailPublisher.java @@ -327,6 +327,7 @@ public void setMatrixTriggerMode(MatrixTriggerMode matrixTriggerMode) { this.matrixTriggerMode = matrixTriggerMode; } + @NonNull @Override public Collection getProjectActions(AbstractProject project) { return Collections.singletonList(new EmailExtWatchAction(project)); @@ -347,7 +348,7 @@ public boolean prebuild(AbstractBuild build, BuildListener listener) { } @Override - public boolean perform(AbstractBuild build, Launcher launcher, BuildListener listener) throws InterruptedException, IOException { + public boolean perform(AbstractBuild build, Launcher launcher, BuildListener listener) { debug(listener.getLogger(), "Checking for post-build"); if (!(build instanceof MatrixRun) || isExecuteOnMatrixNodes()) { debug(listener.getLogger(), "Performing post-build step"); @@ -713,7 +714,7 @@ private boolean executeScript(String rawScript, String scriptName, ExtendedEmail throw e; } catch (Throwable t) { Functions.printStackTrace(t, pw); - logger.println(out.toString()); + logger.println(out); // should we cancel the sending of the email??? } debug(logger, out.toString()); @@ -873,7 +874,7 @@ MailAccount getMailAccount(ExtendedEmailPublisherContext context) throws Address private MimeMessage createMail( ExtendedEmailPublisherContext context, InternetAddress fromAddress, Session session) - throws MessagingException, UnsupportedEncodingException, InterruptedException { + throws MessagingException, UnsupportedEncodingException { ExtendedEmailPublisherDescriptor descriptor = getDescriptor(); String charset = descriptor.getCharset(); @@ -1142,7 +1143,7 @@ public MatrixAggregator createAggregator(MatrixBuild matrixbuild, Launcher launcher, BuildListener buildlistener) { return new MatrixAggregator(matrixbuild, launcher, buildlistener) { @Override - public boolean endBuild() throws InterruptedException, IOException { + public boolean endBuild() { LOGGER.log(Level.FINER, "end build of {0}", this.build.getDisplayName()); // Will be run by parent so we check if needed to be executed by parent @@ -1153,7 +1154,7 @@ public boolean endBuild() throws InterruptedException, IOException { } @Override - public boolean startBuild() throws InterruptedException, IOException { + public boolean startBuild() { LOGGER.log(Level.FINER, "end build of {0}", this.build.getDisplayName()); // Will be run by parent so we check if needed to be executed by parent if (getMatrixTriggerMode().forParent) { diff --git a/src/main/java/hudson/plugins/emailext/ExtendedEmailPublisherContext.java b/src/main/java/hudson/plugins/emailext/ExtendedEmailPublisherContext.java index b0adc80d2..ea4f0a026 100644 --- a/src/main/java/hudson/plugins/emailext/ExtendedEmailPublisherContext.java +++ b/src/main/java/hudson/plugins/emailext/ExtendedEmailPublisherContext.java @@ -49,7 +49,7 @@ protected void setPublisher(ExtendedEmailPublisher publisher) { @Deprecated public AbstractBuild getBuild() { if(run instanceof AbstractBuild) { - return (AbstractBuild)run; + return (AbstractBuild)run; } return null; } diff --git a/src/main/java/hudson/plugins/emailext/ExtendedEmailPublisherDescriptor.java b/src/main/java/hudson/plugins/emailext/ExtendedEmailPublisherDescriptor.java index 2f57ea2c9..87c668efd 100644 --- a/src/main/java/hudson/plugins/emailext/ExtendedEmailPublisherDescriptor.java +++ b/src/main/java/hudson/plugins/emailext/ExtendedEmailPublisherDescriptor.java @@ -36,7 +36,6 @@ import javax.mail.Session; import javax.mail.internet.AddressException; import javax.mail.internet.InternetAddress; -import javax.servlet.ServletException; import java.io.IOException; import java.io.PrintStream; import java.io.StringReader; @@ -260,6 +259,7 @@ public static void autoConfigure() { } } + @NonNull @Override public String getDisplayName() { return Messages.ExtendedEmailPublisherDescriptor_DisplayName(); @@ -720,7 +720,6 @@ public void setDefaultClasspath(List defaultClasspath) throws public List getDefaultTriggerIds() { if (defaultTriggerIds.isEmpty()) { if (!defaultTriggers.isEmpty()) { - defaultTriggerIds.clear(); for (EmailTriggerDescriptor t : this.defaultTriggers) { // we have to do the below because a bunch of stuff is not serialized for the Descriptor EmailTriggerDescriptor d = Jenkins.get().getDescriptorByType(t.getClass()); @@ -772,8 +771,7 @@ public String getHelpFile() { return "/plugin/email-ext/help/main.html"; } - public FormValidation doAddressCheck(@QueryParameter final String value) - throws IOException, ServletException { + public FormValidation doAddressCheck(@QueryParameter final String value) { try { new InternetAddress(value); return FormValidation.ok(); @@ -782,13 +780,11 @@ public FormValidation doAddressCheck(@QueryParameter final String value) } } - public FormValidation doRecipientListRecipientsCheck(@QueryParameter final String value) - throws IOException, ServletException { + public FormValidation doRecipientListRecipientsCheck(@QueryParameter final String value) { return new EmailRecipientUtils().validateFormRecipientList(value); } - public FormValidation doMaxAttachmentSizeCheck(@QueryParameter final String value) - throws IOException, ServletException { + public FormValidation doMaxAttachmentSizeCheck(@QueryParameter final String value) { try { String testValue = value.trim(); // we support an empty value (which means default) diff --git a/src/main/java/hudson/plugins/emailext/GroovyScriptPath.java b/src/main/java/hudson/plugins/emailext/GroovyScriptPath.java index 6594ee402..b4fa333b3 100644 --- a/src/main/java/hudson/plugins/emailext/GroovyScriptPath.java +++ b/src/main/java/hudson/plugins/emailext/GroovyScriptPath.java @@ -1,5 +1,6 @@ package hudson.plugins.emailext; +import edu.umd.cs.findbugs.annotations.NonNull; import hudson.Extension; import hudson.model.AbstractDescribableImpl; import hudson.model.Descriptor; @@ -49,6 +50,7 @@ public URL asURL() { @Extension public static class GroovyScriptPathDescriptor extends Descriptor { + @NonNull @Override public String getDisplayName() { return ""; diff --git a/src/main/java/hudson/plugins/emailext/GroovyTemplateConfig.java b/src/main/java/hudson/plugins/emailext/GroovyTemplateConfig.java index 06423b923..04b74206b 100644 --- a/src/main/java/hudson/plugins/emailext/GroovyTemplateConfig.java +++ b/src/main/java/hudson/plugins/emailext/GroovyTemplateConfig.java @@ -41,6 +41,7 @@ public ContentType getContentType() { return ContentType.DefinedType.GROOVY; } + @NonNull @Override public String getDisplayName() { return Messages.GroovyTemplateConfigProvider_DisplayName(); diff --git a/src/main/java/hudson/plugins/emailext/JellyTemplateConfig.java b/src/main/java/hudson/plugins/emailext/JellyTemplateConfig.java index 84e14e4ec..8f4cd2d24 100644 --- a/src/main/java/hudson/plugins/emailext/JellyTemplateConfig.java +++ b/src/main/java/hudson/plugins/emailext/JellyTemplateConfig.java @@ -40,6 +40,7 @@ public ContentType getContentType() { return ContentType.DefinedType.XML; } + @NonNull @Override public String getDisplayName() { return Messages.JellyTemplateConfigProvider_DisplayName(); diff --git a/src/main/java/hudson/plugins/emailext/MailAccount.java b/src/main/java/hudson/plugins/emailext/MailAccount.java index ee65056cf..12735bc89 100644 --- a/src/main/java/hudson/plugins/emailext/MailAccount.java +++ b/src/main/java/hudson/plugins/emailext/MailAccount.java @@ -1,5 +1,6 @@ package hudson.plugins.emailext; +import edu.umd.cs.findbugs.annotations.NonNull; import hudson.Extension; import hudson.model.AbstractDescribableImpl; import hudson.model.Descriptor; @@ -73,6 +74,7 @@ void setDefaultAccount(boolean defaultAccount) { @Extension public static class MailAccountDescriptor extends Descriptor{ + @NonNull @Override public String getDisplayName(){ return ""; diff --git a/src/main/java/hudson/plugins/emailext/RecipientListStringAnalyser.java b/src/main/java/hudson/plugins/emailext/RecipientListStringAnalyser.java index e6ee53df5..b0f116e3f 100644 --- a/src/main/java/hudson/plugins/emailext/RecipientListStringAnalyser.java +++ b/src/main/java/hudson/plugins/emailext/RecipientListStringAnalyser.java @@ -65,14 +65,14 @@ private int findFirst(InternetAddress address) { int firstIdx = Integer.MAX_VALUE; if (address.getPersonal() != null) { firstIdx = findFirst(firstIdx, "bcc:" + address.getPersonal()); - firstIdx = findFirst(firstIdx, "bcc:\"" + address.toString() + "\""); + firstIdx = findFirst(firstIdx, "bcc:\"" + address + "\""); firstIdx = findFirst(firstIdx, "cc:" + address.getPersonal()); - firstIdx = findFirst(firstIdx, "cc:\"" + address.toString() + "\""); + firstIdx = findFirst(firstIdx, "cc:\"" + address + "\""); firstIdx = findFirst(firstIdx, address.getPersonal()); - firstIdx = findFirst(firstIdx, "\"" + address.toString() + "\""); + firstIdx = findFirst(firstIdx, "\"" + address + "\""); } else { - firstIdx = findFirst(firstIdx, "bcc:" + address.toString()); - firstIdx = findFirst(firstIdx, "cc:" + address.toString()); + firstIdx = findFirst(firstIdx, "bcc:" + address); + firstIdx = findFirst(firstIdx, "cc:" + address); firstIdx = findFirst(firstIdx, address.toString()); } return firstIdx; diff --git a/src/main/java/hudson/plugins/emailext/groovy/sandbox/ObjectInstanceWhitelist.java b/src/main/java/hudson/plugins/emailext/groovy/sandbox/ObjectInstanceWhitelist.java index 35b9266f8..828d95368 100644 --- a/src/main/java/hudson/plugins/emailext/groovy/sandbox/ObjectInstanceWhitelist.java +++ b/src/main/java/hudson/plugins/emailext/groovy/sandbox/ObjectInstanceWhitelist.java @@ -23,7 +23,7 @@ protected synchronized boolean permitsInstance(@CheckForNull Object instance) { protected boolean isClass(Class declaringClass) { T t = instance.get(); if (t != null) { - Class c = t.getClass(); + Class c = t.getClass(); while (c != null && c != Object.class) { if (declaringClass == c) { return true; @@ -38,8 +38,8 @@ protected boolean isClass(Class declaringClass) { return false; } - private boolean isInterface(Class declaringClass, Class[] interfaces) { - for (Class interf : interfaces) { + private boolean isInterface(Class declaringClass, Class[] interfaces) { + for (Class interf : interfaces) { if (declaringClass == interf) { return true; } diff --git a/src/main/java/hudson/plugins/emailext/plugins/EmailTrigger.java b/src/main/java/hudson/plugins/emailext/plugins/EmailTrigger.java index 3a77bd957..aaae70473 100644 --- a/src/main/java/hudson/plugins/emailext/plugins/EmailTrigger.java +++ b/src/main/java/hudson/plugins/emailext/plugins/EmailTrigger.java @@ -152,7 +152,7 @@ protected EmailType createMailType(StaplerRequest req, JSONObject formData) { * @return The number of test failures for the Run */ protected int getNumFailures(Run build) { - AbstractTestResultAction a = build.getAction(AbstractTestResultAction.class); + AbstractTestResultAction> a = build.getAction(AbstractTestResultAction.class); if (a instanceof AggregatedTestResultAction) { int result = 0; AggregatedTestResultAction action = (AggregatedTestResultAction) a; diff --git a/src/main/java/hudson/plugins/emailext/plugins/EmailTriggerDescriptor.java b/src/main/java/hudson/plugins/emailext/plugins/EmailTriggerDescriptor.java index 73ef2ac33..758a23660 100644 --- a/src/main/java/hudson/plugins/emailext/plugins/EmailTriggerDescriptor.java +++ b/src/main/java/hudson/plugins/emailext/plugins/EmailTriggerDescriptor.java @@ -43,8 +43,8 @@ public List getDefaultRecipientProviders() { protected EmailTrigger _createDefault() { EmailTrigger trigger; try { - Constructor ctor = clazz.getConstructor(List.class, String.class, String.class, String.class, String.class, String.class, int.class, String.class); - trigger = (EmailTrigger)ctor.newInstance(defaultRecipientProviders, "", "$PROJECT_DEFAULT_REPLYTO", "$PROJECT_DEFAULT_SUBJECT", "$PROJECT_DEFAULT_CONTENT", "", 0, "project"); + Constructor ctor = clazz.getConstructor(List.class, String.class, String.class, String.class, String.class, String.class, int.class, String.class); + trigger = ctor.newInstance(defaultRecipientProviders, "", "$PROJECT_DEFAULT_REPLYTO", "$PROJECT_DEFAULT_SUBJECT", "$PROJECT_DEFAULT_CONTENT", "", 0, "project"); } catch(Exception e) { trigger = null; } diff --git a/src/main/java/hudson/plugins/emailext/plugins/RecipientProvider.java b/src/main/java/hudson/plugins/emailext/plugins/RecipientProvider.java index 1d1132875..ab7ddc41a 100644 --- a/src/main/java/hudson/plugins/emailext/plugins/RecipientProvider.java +++ b/src/main/java/hudson/plugins/emailext/plugins/RecipientProvider.java @@ -29,7 +29,7 @@ public static DescriptorExtensionList allSupporting(Class clazz) { + public static List allSupporting(Class> clazz) { List rt = new ArrayList<>(); for (RecipientProviderDescriptor recipientProviderDescriptor : all()) { try { diff --git a/src/main/java/hudson/plugins/emailext/plugins/ZipDataSource.java b/src/main/java/hudson/plugins/emailext/plugins/ZipDataSource.java index 150d05af0..d70518bfc 100644 --- a/src/main/java/hudson/plugins/emailext/plugins/ZipDataSource.java +++ b/src/main/java/hudson/plugins/emailext/plugins/ZipDataSource.java @@ -48,7 +48,7 @@ public String getContentType() { return MIME_TYPE; } - public InputStream getInputStream() throws IOException { + public InputStream getInputStream() { return new ByteArrayInputStream(contents); } diff --git a/src/main/java/hudson/plugins/emailext/plugins/content/AbstractEvalContent.java b/src/main/java/hudson/plugins/emailext/plugins/content/AbstractEvalContent.java index 5c87c9066..2c0085415 100644 --- a/src/main/java/hudson/plugins/emailext/plugins/content/AbstractEvalContent.java +++ b/src/main/java/hudson/plugins/emailext/plugins/content/AbstractEvalContent.java @@ -53,7 +53,6 @@ import java.io.FileNotFoundException; import java.io.IOException; import java.io.InputStream; -import java.io.UnsupportedEncodingException; import java.nio.charset.StandardCharsets; import java.util.List; import java.util.logging.Level; @@ -161,7 +160,7 @@ public static boolean isChildOf(final FilePath potentialChild, final FilePath pa return parent.act(new IsChildFileCallable(potentialChild)); } - private InputStream getManagedFile(Run run, String fileName) throws UnsupportedEncodingException { + private InputStream getManagedFile(Run run, String fileName) { InputStream stream = null; Plugin plugin = Jenkins.get().getPlugin("config-file-provider"); if (plugin != null) { @@ -196,7 +195,7 @@ public static boolean isApprovedScript(final String script, final Language langu //checking doesn't check if we are system or not since it assumed being called from doCheckField return ACL.impersonate(Jenkins.ANONYMOUS, new NotReallyRoleSensitiveCallable() { @Override - public Boolean call() throws Exception { + public Boolean call() { return approval.checking(script, language).kind == FormValidation.Kind.OK; } }); @@ -214,7 +213,7 @@ private IsChildFileCallable(FilePath potentialChild) { } @Override - public Boolean invoke(File parent, VirtualChannel channel) throws IOException, InterruptedException { + public Boolean invoke(File parent, VirtualChannel channel) { if (potentialChild.isRemote()) { //Not on the same machine so can't be a child of the local file return false; diff --git a/src/main/java/hudson/plugins/emailext/plugins/content/EmailExtScript.java b/src/main/java/hudson/plugins/emailext/plugins/content/EmailExtScript.java index d3da2787a..51cfa2cb1 100644 --- a/src/main/java/hudson/plugins/emailext/plugins/content/EmailExtScript.java +++ b/src/main/java/hudson/plugins/emailext/plugins/content/EmailExtScript.java @@ -30,7 +30,7 @@ private void populateArgs(Object args, Map map, ListMultimap entry : argMap.entrySet()) { String value = entry.getValue().toString(); if(entry.getValue() instanceof List) { - List valueList = (List)entry.getValue(); + List valueList = (List)entry.getValue(); for(Object v : valueList) { multiMap.put(entry.getKey(), v.toString()); } diff --git a/src/main/java/hudson/plugins/emailext/plugins/content/FailedTestsContent.java b/src/main/java/hudson/plugins/emailext/plugins/content/FailedTestsContent.java index 9b7cca2de..89ca2da96 100644 --- a/src/main/java/hudson/plugins/emailext/plugins/content/FailedTestsContent.java +++ b/src/main/java/hudson/plugins/emailext/plugins/content/FailedTestsContent.java @@ -229,7 +229,7 @@ private void outputTest(StringBuilder buffer, String lineBreak, FailedTest faile if (failedTest.stackTrace != null || failedTest.errorMessage != null) { local.append(lineBreak); } - buffer.append(local.toString()); + buffer.append(local); } } diff --git a/src/main/java/hudson/plugins/emailext/plugins/content/ScriptContent.java b/src/main/java/hudson/plugins/emailext/plugins/content/ScriptContent.java index 4cbf4c586..f1bf70ec3 100644 --- a/src/main/java/hudson/plugins/emailext/plugins/content/ScriptContent.java +++ b/src/main/java/hudson/plugins/emailext/plugins/content/ScriptContent.java @@ -43,7 +43,6 @@ import java.util.Collections; import java.util.HashMap; import java.util.Map; -import java.util.concurrent.Callable; import java.util.logging.Level; import java.util.logging.Logger; @@ -91,7 +90,7 @@ public String evaluate(Run run, FilePath workspace, TaskListener listener, LOGGER.log(Level.SEVERE, missingScriptError); result = missingScriptError; } catch (GroovyRuntimeException e) { - result = "Error in script or template: " + e.toString(); + result = "Error in script or template: " + e; } finally { IOUtils.closeQuietly(inputStream); } @@ -110,8 +109,7 @@ protected Class getProviderClass () { * @param templateStream the template file stream * @return the rendered template content */ - private String renderTemplate(Run build, FilePath workspace, TaskListener listener, InputStream templateStream) - throws IOException { + private String renderTemplate(Run build, FilePath workspace, TaskListener listener, InputStream templateStream) { String result; @@ -152,11 +150,8 @@ private String renderTemplate(Run build, FilePath workspace, TaskListener } else { //unapproved script, so run in sandbox StaticProxyInstanceWhitelist whitelist = new StaticProxyInstanceWhitelist(build, "templates-instances.whitelist"); - result = GroovySandbox.runInSandbox(new Callable() { - @Override - public String call() throws Exception { - return tmplR.make(binding).toString(); //TODO there is a PrintWriter instance created in make and bound to out - } + result = GroovySandbox.runInSandbox(() -> { + return tmplR.make(binding).toString(); //TODO there is a PrintWriter instance created in make and bound to out }, new ProxyWhitelist( Whitelist.all(), new TaskListenerInstanceWhitelist(listener), @@ -169,7 +164,7 @@ public String call() throws Exception { StringWriter sw = new StringWriter(); PrintWriter pw = new PrintWriter(sw); Functions.printStackTrace(e, pw); - result = "Exception raised during template rendering: " + e.getMessage() + "\n\n" + sw.toString(); + result = "Exception raised during template rendering: " + e.getMessage() + "\n\n" + sw; } return result; } @@ -236,8 +231,7 @@ private String executeScript(Run build, FilePath workspace, TaskListener l * @param variables user variables to be added to the Groovy context * @return a GroovyShell instance */ - private GroovyShell createEngine(ExtendedEmailPublisherDescriptor descriptor, Map variables, boolean secure) - throws IOException { + private GroovyShell createEngine(ExtendedEmailPublisherDescriptor descriptor, Map variables, boolean secure) { ClassLoader cl; CompilerConfiguration cc; diff --git a/src/main/java/hudson/plugins/emailext/plugins/content/ScriptContentBuildWrapper.java b/src/main/java/hudson/plugins/emailext/plugins/content/ScriptContentBuildWrapper.java index 03ab491d8..e55c57861 100644 --- a/src/main/java/hudson/plugins/emailext/plugins/content/ScriptContentBuildWrapper.java +++ b/src/main/java/hudson/plugins/emailext/plugins/content/ScriptContentBuildWrapper.java @@ -42,10 +42,9 @@ public Action getCoberturaAction() { public List getJUnitTestResult() { List result = new ArrayList<>(); List actions = build.getActions(AggregatedTestResultAction.class); - for (Action action : actions) { + for (AggregatedTestResultAction action : actions) { /* Maven Project */ - List reportList = - ((AggregatedTestResultAction) action).getChildReports(); + List reportList = action.getChildReports(); for (AggregatedTestResultAction.ChildReport report : reportList) { if (report.result instanceof hudson.tasks.junit.TestResult) { result.add((TestResult) report.result); diff --git a/src/main/java/hudson/plugins/emailext/plugins/content/UserProvidedContentInputStream.java b/src/main/java/hudson/plugins/emailext/plugins/content/UserProvidedContentInputStream.java index f7e7b09b8..d2a266999 100644 --- a/src/main/java/hudson/plugins/emailext/plugins/content/UserProvidedContentInputStream.java +++ b/src/main/java/hudson/plugins/emailext/plugins/content/UserProvidedContentInputStream.java @@ -23,6 +23,8 @@ */ package hudson.plugins.emailext.plugins.content; +import edu.umd.cs.findbugs.annotations.NonNull; + import java.io.IOException; import java.io.InputStream; @@ -38,12 +40,12 @@ public UserProvidedContentInputStream(InputStream delegate) { } @Override - public int read(byte[] b) throws IOException { + public int read(@NonNull byte[] b) throws IOException { return delegate.read(b); } @Override - public int read(byte[] b, int off, int len) throws IOException { + public int read(@NonNull byte[] b, int off, int len) throws IOException { return delegate.read(b, off, len); } diff --git a/src/main/java/hudson/plugins/emailext/plugins/recipients/BuildUserRecipientProvider.java b/src/main/java/hudson/plugins/emailext/plugins/recipients/BuildUserRecipientProvider.java index b2931f95d..6911c6c6f 100644 --- a/src/main/java/hudson/plugins/emailext/plugins/recipients/BuildUserRecipientProvider.java +++ b/src/main/java/hudson/plugins/emailext/plugins/recipients/BuildUserRecipientProvider.java @@ -1,5 +1,6 @@ package hudson.plugins.emailext.plugins.recipients; +import edu.umd.cs.findbugs.annotations.NonNull; import hudson.EnvVars; import hudson.Extension; import hudson.model.Cause; @@ -69,6 +70,7 @@ private static void addUserTriggeringTheBuild(Run run, Set run, Set triggers = req != null ? req.bindJSONToList(EmailTrigger.class, json) : Collections.emptyList(); @@ -75,7 +77,7 @@ public UserProperty newInstance(StaplerRequest req, JSONObject json) throws Form private AbstractProject project; - public EmailExtWatchAction(AbstractProject project) { + public EmailExtWatchAction(AbstractProject project) { this.project = project; } @@ -144,7 +146,7 @@ public ExtendedEmailPublisher getPublisher() { return p; } - public void doStopWatching(StaplerRequest req, StaplerResponse rsp) throws IOException, ServletException, FormException { + public void doStopWatching(StaplerRequest req, StaplerResponse rsp) throws IOException { User user = User.current(); if(user != null) { stopWatching(); @@ -159,7 +161,7 @@ public void doStopWatching(StaplerRequest req, StaplerResponse rsp) throws IOExc } @RequirePOST - public void doConfigSubmit(StaplerRequest req, StaplerResponse rsp) throws IOException, ServletException, FormException { + public void doConfigSubmit(StaplerRequest req, StaplerResponse rsp) throws IOException, ServletException { User user = User.current(); if(user != null) { Object json = req.getSubmittedForm().get("triggers"); diff --git a/src/main/java/hudson/plugins/emailext/watching/EmailExtWatchJobProperty.java b/src/main/java/hudson/plugins/emailext/watching/EmailExtWatchJobProperty.java index 7882ad965..a2e3cfe42 100644 --- a/src/main/java/hudson/plugins/emailext/watching/EmailExtWatchJobProperty.java +++ b/src/main/java/hudson/plugins/emailext/watching/EmailExtWatchJobProperty.java @@ -1,5 +1,6 @@ package hudson.plugins.emailext.watching; +import edu.umd.cs.findbugs.annotations.NonNull; import hudson.Extension; import hudson.model.Action; import hudson.model.Job; @@ -21,6 +22,7 @@ public class EmailExtWatchJobProperty extends JobProperty> { final List watchers = new ArrayList<>(); + @NonNull @Override public Collection getJobActions(Job job) { return Collections.emptyList(); @@ -80,6 +82,7 @@ public JobProperty newInstance(StaplerRequest req, return null; } + @NonNull @Override public String getDisplayName() { return ""; diff --git a/src/test/java/hudson/plugins/emailext/AttachmentUtilsTest.java b/src/test/java/hudson/plugins/emailext/AttachmentUtilsTest.java index cb2c52a99..e669777ee 100644 --- a/src/test/java/hudson/plugins/emailext/AttachmentUtilsTest.java +++ b/src/test/java/hudson/plugins/emailext/AttachmentUtilsTest.java @@ -121,7 +121,7 @@ public boolean perform(AbstractBuild build, Launcher launcher, BuildListen BodyPart attach = part.getBodyPart(1); assertThat(attach.getSize(), allOf(greaterThan(0), - lessThanOrEqualTo((new Long(b.getLogFile().length()).intValue())))); + lessThanOrEqualTo((Long.valueOf(b.getLogFile().length()).intValue())))); assertEquals("build.zip", attach.getFileName()); assertThat(IOUtils.toString(attach.getInputStream()), containsString("build.log")); // zips have plain text filename in them } diff --git a/src/test/java/hudson/plugins/emailext/EmailExtStepTest.java b/src/test/java/hudson/plugins/emailext/EmailExtStepTest.java index e1c96dd58..6ece410aa 100644 --- a/src/test/java/hudson/plugins/emailext/EmailExtStepTest.java +++ b/src/test/java/hudson/plugins/emailext/EmailExtStepTest.java @@ -164,7 +164,9 @@ public Set> getRequiredContext() { return "fileCopy"; } - @Override public String getDisplayName() { + @NonNull + @Override + public String getDisplayName() { return "Copy a file into the workspace"; } diff --git a/src/test/java/hudson/plugins/emailext/ExtendedEmailPublisherTest.java b/src/test/java/hudson/plugins/emailext/ExtendedEmailPublisherTest.java index 55d36a761..eaa1d95ad 100644 --- a/src/test/java/hudson/plugins/emailext/ExtendedEmailPublisherTest.java +++ b/src/test/java/hudson/plugins/emailext/ExtendedEmailPublisherTest.java @@ -2,6 +2,7 @@ import com.gargoylesoftware.htmlunit.html.HtmlPage; import com.gargoylesoftware.htmlunit.html.HtmlTextArea; +import edu.umd.cs.findbugs.annotations.NonNull; import hudson.Launcher; import hudson.model.AbstractBuild; import hudson.model.BuildListener; @@ -66,7 +67,6 @@ import java.util.ArrayList; import java.util.Collections; import java.util.List; -import java.util.concurrent.Callable; import java.util.concurrent.TimeUnit; import static org.hamcrest.Matchers.containsString; @@ -978,31 +978,29 @@ public void testNoReplyTo() throws Exception { @Test public void testNewInstance_shouldGetBasicInformation() throws Exception { - j.createWebClient().executeOnServer(new Callable() { - public Void call() throws Exception { - JSONObject form = new JSONObject(); - form.put("project_content_type", "default"); - form.put("project_recipient_list", "ashlux@gmail.com"); - form.put("project_default_subject", "Make millions in Nigeria"); - form.put("project_default_content", "Give me a $1000 check and I'll mail you back $5000!!!"); - form.put("project_attachments", ""); - form.put("project_presend_script", ""); - form.put("postsendScript", "println 1"); - form.put("project_replyto", ""); - - ExtendedEmailPublisherDescriptor descriptor = new ExtendedEmailPublisherDescriptor(); - publisher = (ExtendedEmailPublisher) descriptor.newInstance(Stapler.getCurrentRequest(), form); - - assertEquals("default", publisher.contentType); - assertEquals("ashlux@gmail.com", publisher.recipientList); - assertEquals("Make millions in Nigeria", publisher.defaultSubject); - assertEquals("Give me a $1000 check and I'll mail you back $5000!!!", publisher.defaultContent); - assertEquals("", publisher.attachmentsPattern); - assertEquals("", publisher.replyTo); - assertEquals("println 1", publisher.getPostsendScript()); - - return null; - } + j.createWebClient().executeOnServer(() -> { + JSONObject form = new JSONObject(); + form.put("project_content_type", "default"); + form.put("project_recipient_list", "ashlux@gmail.com"); + form.put("project_default_subject", "Make millions in Nigeria"); + form.put("project_default_content", "Give me a $1000 check and I'll mail you back $5000!!!"); + form.put("project_attachments", ""); + form.put("project_presend_script", ""); + form.put("postsendScript", "println 1"); + form.put("project_replyto", ""); + + ExtendedEmailPublisherDescriptor descriptor = new ExtendedEmailPublisherDescriptor(); + publisher = (ExtendedEmailPublisher) descriptor.newInstance(Stapler.getCurrentRequest(), form); + + assertEquals("default", publisher.contentType); + assertEquals("ashlux@gmail.com", publisher.recipientList); + assertEquals("Make millions in Nigeria", publisher.defaultSubject); + assertEquals("Give me a $1000 check and I'll mail you back $5000!!!", publisher.defaultContent); + assertEquals("", publisher.attachmentsPattern); + assertEquals("", publisher.replyTo); + assertEquals("println 1", publisher.getPostsendScript()); + + return null; }); } @@ -1155,55 +1153,53 @@ public void testAttachBuildLog() throws Exception { @Test public void testAdditionalAccounts() throws Exception { - j.createWebClient().executeOnServer(new Callable() { - public Void call() throws Exception { - ExtendedEmailPublisherDescriptor descriptor = ExtendedEmailPublisher.descriptor(); - descriptor.getMailAccount().setSmtpHost("smtp.test0.com"); - descriptor.getMailAccount().setSmtpPort("587"); - descriptor.getMailAccount().setAdvProperties("mail.smtp.ssl.trust=test0.com"); - - JSONObject form = new JSONObject(); - form.put("project_from", "mail@test1.com"); - publisher = (ExtendedEmailPublisher) descriptor.newInstance(Stapler.getCurrentRequest(), form); - assertEquals("mail@test1.com", publisher.from); - ExtendedEmailPublisherContext context = - new ExtendedEmailPublisherContext(publisher, null, null, null, TaskListener.NULL); - Session session = descriptor.createSession(publisher.getMailAccount(context)); - assertEquals("smtp.test0.com", session.getProperty("mail.smtp.host")); - assertEquals("587", session.getProperty("mail.smtp.port")); - assertEquals("test0.com", session.getProperty("mail.smtp.ssl.trust")); - - List addaccs = new ArrayList<>(); - JSONObject dform = new JSONObject(); - dform.put("address", "mail@test1.com"); - dform.put("smtpHost", "smtp.test1.com"); - dform.put("smtpPort", "25"); - dform.put("advProperties", "mail.smtp.ssl.trust=test1.com"); - addaccs.add(new MailAccount(dform)); - dform.put("address", "mail@test2.com"); - dform.put("smtpHost", "smtp.test2.com"); - dform.put("smtpPort", "465"); - dform.put("advProperties", "mail.smtp.ssl.trust=test2.com"); - addaccs.add(new MailAccount(dform)); - descriptor.setAddAccounts(addaccs); - - publisher = (ExtendedEmailPublisher) descriptor.newInstance(Stapler.getCurrentRequest(), form); - assertEquals("mail@test1.com", publisher.from); - session = descriptor.createSession(publisher.getMailAccount(context)); - assertEquals("smtp.test1.com", session.getProperty("mail.smtp.host")); - assertEquals("25", session.getProperty("mail.smtp.port")); - assertEquals("test1.com", session.getProperty("mail.smtp.ssl.trust")); - - form.put("project_from", "mail@test2.com"); - publisher = (ExtendedEmailPublisher) descriptor.newInstance(Stapler.getCurrentRequest(), form); - assertEquals("mail@test2.com", publisher.from); - session = descriptor.createSession(publisher.getMailAccount(context)); - assertEquals("smtp.test2.com", session.getProperty("mail.smtp.host")); - assertEquals("465", session.getProperty("mail.smtp.port")); - assertEquals("test2.com", session.getProperty("mail.smtp.ssl.trust")); - - return null; - } + j.createWebClient().executeOnServer(() -> { + ExtendedEmailPublisherDescriptor descriptor = ExtendedEmailPublisher.descriptor(); + descriptor.getMailAccount().setSmtpHost("smtp.test0.com"); + descriptor.getMailAccount().setSmtpPort("587"); + descriptor.getMailAccount().setAdvProperties("mail.smtp.ssl.trust=test0.com"); + + JSONObject form = new JSONObject(); + form.put("project_from", "mail@test1.com"); + publisher = (ExtendedEmailPublisher) descriptor.newInstance(Stapler.getCurrentRequest(), form); + assertEquals("mail@test1.com", publisher.from); + ExtendedEmailPublisherContext context = + new ExtendedEmailPublisherContext(publisher, null, null, null, TaskListener.NULL); + Session session = descriptor.createSession(publisher.getMailAccount(context)); + assertEquals("smtp.test0.com", session.getProperty("mail.smtp.host")); + assertEquals("587", session.getProperty("mail.smtp.port")); + assertEquals("test0.com", session.getProperty("mail.smtp.ssl.trust")); + + List addaccs = new ArrayList<>(); + JSONObject dform = new JSONObject(); + dform.put("address", "mail@test1.com"); + dform.put("smtpHost", "smtp.test1.com"); + dform.put("smtpPort", "25"); + dform.put("advProperties", "mail.smtp.ssl.trust=test1.com"); + addaccs.add(new MailAccount(dform)); + dform.put("address", "mail@test2.com"); + dform.put("smtpHost", "smtp.test2.com"); + dform.put("smtpPort", "465"); + dform.put("advProperties", "mail.smtp.ssl.trust=test2.com"); + addaccs.add(new MailAccount(dform)); + descriptor.setAddAccounts(addaccs); + + publisher = (ExtendedEmailPublisher) descriptor.newInstance(Stapler.getCurrentRequest(), form); + assertEquals("mail@test1.com", publisher.from); + session = descriptor.createSession(publisher.getMailAccount(context)); + assertEquals("smtp.test1.com", session.getProperty("mail.smtp.host")); + assertEquals("25", session.getProperty("mail.smtp.port")); + assertEquals("test1.com", session.getProperty("mail.smtp.ssl.trust")); + + form.put("project_from", "mail@test2.com"); + publisher = (ExtendedEmailPublisher) descriptor.newInstance(Stapler.getCurrentRequest(), form); + assertEquals("mail@test2.com", publisher.from); + session = descriptor.createSession(publisher.getMailAccount(context)); + assertEquals("smtp.test2.com", session.getProperty("mail.smtp.host")); + assertEquals("465", session.getProperty("mail.smtp.port")); + assertEquals("test2.com", session.getProperty("mail.smtp.ssl.trust")); + + return null; }); } @@ -1380,6 +1376,7 @@ public boolean perform(AbstractBuild build, Launcher launcher, BuildListen public static final class DescriptorImpl extends Descriptor { + @NonNull @Override public String getDisplayName() { return "Sleep once"; diff --git a/src/test/java/hudson/plugins/emailext/plugins/content/FailedTestsContentTest.java b/src/test/java/hudson/plugins/emailext/plugins/content/FailedTestsContentTest.java index b6f4582f4..16d9a109c 100644 --- a/src/test/java/hudson/plugins/emailext/plugins/content/FailedTestsContentTest.java +++ b/src/test/java/hudson/plugins/emailext/plugins/content/FailedTestsContentTest.java @@ -33,7 +33,7 @@ public class FailedTestsContentTest { private FailedTestsContent failedTestContent; - private AbstractBuild build; + private AbstractBuild build; private TaskListener listener; @@ -66,7 +66,7 @@ public void testGetContent_withWorkspaceAndNoTestsRanShouldGiveAMeaningfulMessag @Test public void testGetContent_whenAllTestsPassedShouldGiveMeaningfulMessage() throws Exception { - AbstractTestResultAction testResults = mock(AbstractTestResultAction.class); + AbstractTestResultAction testResults = mock(AbstractTestResultAction.class); when(testResults.getFailCount()).thenReturn(0); when(build.getAction(AbstractTestResultAction.class)).thenReturn(testResults); diff --git a/src/test/java/hudson/plugins/emailext/plugins/content/JellyScriptContentTest.java b/src/test/java/hudson/plugins/emailext/plugins/content/JellyScriptContentTest.java index 586f09200..7ada3083a 100644 --- a/src/test/java/hudson/plugins/emailext/plugins/content/JellyScriptContentTest.java +++ b/src/test/java/hudson/plugins/emailext/plugins/content/JellyScriptContentTest.java @@ -52,7 +52,7 @@ public void before() throws Throwable { f.set(publisher.getDescriptor(), "http://localhost/"); build = mock(AbstractBuild.class); - AbstractProject project = mock(AbstractProject.class); + AbstractProject project = mock(AbstractProject.class); DescribableList publishers = mock(DescribableList.class); when(publishers.get(ExtendedEmailPublisher.class)).thenReturn(publisher); when(project.getPublishersList()).thenReturn(publishers); diff --git a/src/test/java/hudson/plugins/emailext/plugins/content/ScriptContentBuildWrapperTest.java b/src/test/java/hudson/plugins/emailext/plugins/content/ScriptContentBuildWrapperTest.java index 39e78ddf9..7c81014fa 100644 --- a/src/test/java/hudson/plugins/emailext/plugins/content/ScriptContentBuildWrapperTest.java +++ b/src/test/java/hudson/plugins/emailext/plugins/content/ScriptContentBuildWrapperTest.java @@ -99,7 +99,7 @@ public void testGetJUnitTestResult_whenMavenProjectUseMavenPluginsSurefireAggreg private ChildReport mockChildReport() { - final AbstractTestResultAction testResultAction1 = mock( AbstractTestResultAction.class ); + final AbstractTestResultAction testResultAction1 = mock( AbstractTestResultAction.class ); when( testResultAction1.getResult() ).thenReturn( new TestResult() ); return new ChildReport( mockBuild, testResultAction1 ); } diff --git a/src/test/java/hudson/plugins/emailext/plugins/content/ScriptContentTest.java b/src/test/java/hudson/plugins/emailext/plugins/content/ScriptContentTest.java index 6100e12b5..e354fdcb0 100644 --- a/src/test/java/hudson/plugins/emailext/plugins/content/ScriptContentTest.java +++ b/src/test/java/hudson/plugins/emailext/plugins/content/ScriptContentTest.java @@ -87,7 +87,7 @@ public void before() throws Throwable { f.set( publisher.getDescriptor(), "ashlux@gmail.com" ); build = mock(AbstractBuild.class); - AbstractProject project = mock(AbstractProject.class); + AbstractProject project = mock(AbstractProject.class); DescribableList publishers = mock(DescribableList.class); when(publishers.get(ExtendedEmailPublisher.class)).thenReturn(publisher); when(project.getPublishersList()).thenReturn(publishers); diff --git a/src/test/java/hudson/plugins/emailext/plugins/recipients/MockUtilities.java b/src/test/java/hudson/plugins/emailext/plugins/recipients/MockUtilities.java index 43b9201b8..f3b8ec155 100644 --- a/src/test/java/hudson/plugins/emailext/plugins/recipients/MockUtilities.java +++ b/src/test/java/hudson/plugins/emailext/plugins/recipients/MockUtilities.java @@ -32,11 +32,9 @@ import hudson.tasks.junit.CaseResult; import hudson.tasks.junit.TestResultAction; import hudson.tasks.test.AbstractTestResultAction; -import org.apache.commons.collections.Transformer; import org.apache.commons.collections.iterators.TransformIterator; import org.jenkinsci.plugins.workflow.job.WorkflowRun; import org.mockito.Mockito; -import org.mockito.invocation.InvocationOnMock; import org.mockito.stubbing.Answer; import org.powermock.api.mockito.PowerMockito; @@ -76,37 +74,31 @@ public boolean isEmptySet() { } public Iterator iterator() { - return new TransformIterator(Arrays.asList(authors).iterator(), new Transformer() { + return new TransformIterator(Arrays.asList(authors).iterator(), inAuthor -> new Entry() { @Override - public Object transform(final Object inAuthor) { - return new ChangeLogSet.Entry() { - @Override - public String getMsg() { - return "COMMIT MESSAGE"; - } - - @Override - public User getAuthor() { - return getUser((String) inAuthor); - } - - @Override - public Collection getAffectedPaths() { - return Collections.emptySet(); - } - - @Override - public String getMsgAnnotated() { - return getMsg(); - } - - @Override - public Collection getAffectedFiles() { - return Collections.emptySet(); - } - }; + public String getMsg() { + return "COMMIT MESSAGE"; } + @Override + public User getAuthor() { + return getUser((String) inAuthor); + } + + @Override + public Collection getAffectedPaths() { + return Collections.emptySet(); + } + + @Override + public String getMsgAnnotated() { + return getMsg(); + } + + @Override + public Collection getAffectedFiles() { + return Collections.emptySet(); + } }); } @@ -128,12 +120,9 @@ public static void addChangeSet(final AbstractBuild build, final String... public static void addRequestor(final AbstractBuild build, final String requestor) throws Exception { PowerMockito.spy(User.class); - PowerMockito.doAnswer(new Answer() { - @Override - public User answer(InvocationOnMock invocation) { - Object[] args = invocation.getArguments(); - return getUser((String) args[0]); - } + PowerMockito.doAnswer((Answer) invocation -> { + Object[] args = invocation.getArguments(); + return getUser((String) args[0]); }).when(User.class, "get", Mockito.anyString(), Mockito.anyBoolean(), Mockito.any()); final Cause.UserIdCause cause = PowerMockito.mock(Cause.UserIdCause.class); PowerMockito.when(cause.getUserId()).thenReturn(requestor);