Skip to content
Permalink
Browse files

JENKINS-17910 - groovy.lang.MissingMethodException

use proper class instead of inner class
  • Loading branch information
gcummings committed May 22, 2013
1 parent 9d37d81 commit 8677931891e10fc01a36e61dde0c3e8e36582f9f
@@ -0,0 +1,76 @@
package hudson.plugins.emailext.plugins.content;

import java.io.IOException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.jenkinsci.plugins.tokenmacro.MacroEvaluationException;
import org.jenkinsci.plugins.tokenmacro.TokenMacro;

import com.google.common.collect.ArrayListMultimap;
import com.google.common.collect.ListMultimap;

import groovy.lang.Script;
import hudson.model.AbstractBuild;
import hudson.model.TaskListener;
import hudson.plugins.emailext.plugins.ContentBuilder;

public abstract class EmailExtScript extends Script {

private void populateArgs(Object args, Map<String, String> map, ListMultimap<String, String> multiMap) {
if(args instanceof Object[]) {
Object[] argArray = (Object[])args;
if(argArray.length > 0) {
Map<String, Object> argMap = (Map<String, Object>)argArray[0];
for(Map.Entry<String, Object> entry : argMap.entrySet()) {
String value = entry.getValue().toString();
if(entry.getValue() instanceof List) {
List valueList = (List)entry.getValue();
for(Object v : valueList) {
multiMap.put(entry.getKey(), v.toString());
}
value = valueList.get(valueList.size() - 1).toString();
} else {
multiMap.put(entry.getKey(), value);
}
map.put(entry.getKey(), value);
}
}
}
}

public Object methodMissing(String name, Object args)
throws MacroEvaluationException, IOException, InterruptedException {

TokenMacro macro = null;
for(TokenMacro m : TokenMacro.all()) {
if(m.acceptsMacroName(name)) {
macro = m;
break;
}
}

if(macro == null) {
for(TokenMacro m : ContentBuilder.getPrivateMacros()) {
if(m.acceptsMacroName(name)) {
macro = m;
break;
}
}
}

if(macro != null) {
Map<String, String> argsMap = new HashMap<String, String>();
ListMultimap<String, String> argsMultimap = ArrayListMultimap.create();
populateArgs(args, argsMap, argsMultimap);

// Get the build and listener from the binding.
AbstractBuild<?, ?> build = (AbstractBuild<?, ?>)this.getBinding().getVariable("build");
TaskListener listener = (TaskListener)this.getBinding().getVariable("listener");

return macro.evaluate(build, listener, name, argsMap, argsMultimap);
}
return String.format("[Could not find content token (check your usage): %s]", name);
}
}
@@ -1,23 +1,15 @@
package hudson.plugins.emailext.plugins.content;

import com.google.common.collect.ArrayListMultimap;
import com.google.common.collect.ListMultimap;
import groovy.lang.Binding;
import groovy.lang.GroovyRuntimeException;
import groovy.lang.GroovyShell;
import groovy.lang.Script;
import groovy.text.SimpleTemplateEngine;
import hudson.model.TaskListener;
import hudson.model.AbstractBuild;
import hudson.model.Hudson;
import hudson.model.TaskListener;
import hudson.plugins.emailext.plugins.EmailToken;
import hudson.plugins.emailext.ExtendedEmailPublisher;
import hudson.plugins.emailext.ScriptSandbox;
import hudson.plugins.emailext.plugins.ContentBuilder;

import jenkins.model.Jenkins;

import org.apache.commons.io.IOUtils;
import hudson.plugins.emailext.plugins.EmailToken;

import java.io.File;
import java.io.FileInputStream;
@@ -27,18 +19,18 @@
import java.io.InputStreamReader;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.logging.Level;
import java.util.logging.Logger;

import jenkins.model.Jenkins;

import org.apache.commons.io.IOUtils;
import org.apache.commons.lang.StringUtils;
import org.codehaus.groovy.control.CompilerConfiguration;
import org.codehaus.groovy.control.customizers.ImportCustomizer;
import org.codehaus.groovy.runtime.InvokerHelper;
import org.jenkinsci.plugins.tokenmacro.DataBoundTokenMacro;
import org.jenkinsci.plugins.tokenmacro.DataBoundTokenMacro.Parameter;
import org.jenkinsci.plugins.tokenmacro.MacroEvaluationException;
import org.jenkinsci.plugins.tokenmacro.TokenMacro;
import org.kohsuke.groovy.sandbox.SandboxTransformer;

@EmailToken
@@ -214,63 +206,4 @@ private GroovyShell createEngine(Map<String, Object> variables)
public boolean hasNestedContent() {
return false;
}

public static abstract class EmailExtScript extends Script {

private void populateArgs(Object args, Map<String, String> map, ListMultimap<String, String> multiMap) {
if(args instanceof Object[]) {
Object[] argArray = (Object[])args;
if(argArray.length > 0) {
Map<String, Object> argMap = (Map<String, Object>)argArray[0];
for(Map.Entry<String, Object> entry : argMap.entrySet()) {
String value = entry.getValue().toString();
if(entry.getValue() instanceof List) {
List valueList = (List)entry.getValue();
for(Object v : valueList) {
multiMap.put(entry.getKey(), v.toString());
}
value = valueList.get(valueList.size() - 1).toString();
} else {
multiMap.put(entry.getKey(), value);
}
map.put(entry.getKey(), value);
}
}
}
}

public Object methodMissing(String name, Object args)
throws MacroEvaluationException, IOException, InterruptedException {

TokenMacro macro = null;
for(TokenMacro m : TokenMacro.all()) {
if(m.acceptsMacroName(name)) {
macro = m;
break;
}
}

if(macro == null) {
for(TokenMacro m : ContentBuilder.getPrivateMacros()) {
if(m.acceptsMacroName(name)) {
macro = m;
break;
}
}
}

if(macro != null) {
Map<String, String> argsMap = new HashMap<String, String>();
ListMultimap<String, String> argsMultimap = ArrayListMultimap.create();
populateArgs(args, argsMap, argsMultimap);

// Get the build and listener from the binding.
AbstractBuild<?, ?> build = (AbstractBuild<?, ?>)this.getBinding().getVariable("build");
TaskListener listener = (TaskListener)this.getBinding().getVariable("listener");

return macro.evaluate(build, listener, name, argsMap, argsMultimap);
}
return String.format("[Could not find content token (check your usage): %s]", name);
}
}
}

0 comments on commit 8677931

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