Skip to content
Permalink
Browse files

Fix JENKINS-14224

- Added a catch for NoSuchMethodError which could occur if token-macro is too old.
  • Loading branch information
slide committed Jul 10, 2012
1 parent f60ae09 commit f4eff284765512889f34666c0d71887cbab0971e
@@ -1,5 +1,7 @@
package hudson.plugins.emailext;

import hudson.Plugin;
import hudson.PluginWrapper;
import hudson.matrix.MatrixProject;
import hudson.model.AbstractProject;
import hudson.model.Hudson;
@@ -8,6 +10,8 @@
import hudson.tasks.Publisher;
import hudson.util.FormValidation;
import hudson.util.Secret;
import hudson.util.VersionNumber;
import jenkins.model.Jenkins;
import net.sf.json.JSONObject;
import org.kohsuke.stapler.QueryParameter;
import org.kohsuke.stapler.StaplerRequest;
@@ -247,7 +251,12 @@ public boolean isApplicable(Class<? extends AbstractProject> jobType) {
}

public boolean isTokenMacroAvailable() {
return Hudson.getInstance().getPlugin("token-macro") != null;
boolean result = false;
Plugin tokenMacroPlugin = Jenkins.getInstance().getPlugin("token-macro");
if(tokenMacroPlugin != null) {
result = !tokenMacroPlugin.getWrapper().getVersionNumber().isOlderThan(new VersionNumber("1.5.1"));
}
return result;
}

@Override
@@ -319,7 +328,7 @@ public boolean configure(StaplerRequest req, JSONObject formData)
url += '/';
}
if (!overrideGlobalSettings || url == null) {
url = Hudson.getInstance().getRootUrl();
url = Jenkins.getInstance().getRootUrl();
}
hudsonUrl = url;

@@ -394,18 +403,18 @@ public FormValidation doRecipientListRecipientsCheck(@QueryParameter final Strin
}

public FormValidation doMaxAttachmentSizeCheck(@QueryParameter final String value)
throws IOException, ServletException {
try {
String testValue = value.trim();
// we support an empty value (which means default)
// or a number
if(testValue.length() > 0) {
Long.parseLong(testValue);
}
return FormValidation.ok();
} catch (Exception e) {
return FormValidation.error(e.getMessage());
}
throws IOException, ServletException {
try {
String testValue = value.trim();
// we support an empty value (which means default)
// or a number
if(testValue.length() > 0) {
Long.parseLong(testValue);
}
return FormValidation.ok();
} catch (Exception e) {
return FormValidation.error(e.getMessage());
}
}

public boolean isMatrixProject(AbstractProject<?, ?> project) {
@@ -91,8 +91,10 @@ public String transformText(String origText, ExtendedEmailPublisher publisher, E
if(tokenMacroPlugin != null) {
try {
newText = org.jenkinsci.plugins.tokenmacro.TokenMacro.expandAll(build, listener, newText);
} catch(NoSuchMethodError e) {
// this will happen if the wrong version of token macro is loaded
} catch(Exception e) {
// we don't do anything here...
// we don't do anything here
}
}
return newText;

0 comments on commit f4eff28

Please sign in to comment.
You can’t perform that action at this time.