I meant it did not work properly.

here is what I tried in the script console:

import org.kohsuke.args4j.Argument;
import org.kohsuke.args4j.CmdLineException;
import org.kohsuke.args4j.CmdLineParser;
import org.kohsuke.args4j.Option;
import org.kohsuke.args4j.spi.BooleanOptionHandler;

import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

import java.util.Map.Entry;
import java.util.Map;
import java.util.HashMap;

public class SampleMain {
    @Option(name="-p",usage="Specify the build parameters in the key=value format.")
    Map<String,String> parameters = new HashMap<String, String>();

    Map<String,String> parameters2 = new HashMap<String, String>();
    @Option(name="-P",usage="Specify the build parameters in the key=value format.")
    protected void setParameter(final String property)  {
        int eqIndex =  property.indexOf("=");
        if (eqIndex == -1) {
            throw new IllegalArgumentException("build parameters must be specified in the form: <key>=<value>");
        }
        parameters2.put(property.substring(0,eqIndex), property.substring(eqIndex+1));
    }

}

def test(String[] args) {
    println("test with args: " + args)
    main = new SampleMain()
    CmdLineParser parser = new CmdLineParser(main);
    parser.parseArgument(args)
    for (Entry<String, String> e : main.parameters.entrySet()) {
         String name = e.getKey();
         String value = e.getValue();
         println("[parameters]  " + name + ' := ' + value);
    }
    for (Entry<String, String> e : main.parameters2.entrySet()) {
         String name = e.getKey();
         String value = e.getValue();
         println("[parameters2] " + name + ' := ' + value);
    }
}

// test('-p', 'key=value', '-P', 'key=value')
test('-p', 'key=value=more', '-P', 'key=value=more')

even though it shows

args4j:args4j:2.0.23
in the "about" form.

This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators.
For more information on JIRA, see: http://www.atlassian.com/software/jira

--
You received this message because you are subscribed to the Google Groups "Jenkins Issues" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to