File D:\maven-qcr-plugin-testsunitaires\qcr4java\jenkins-master\target\site\qc\core\src\main\java\hudson\cli\handlers\TopLevelItemOptionHandler.java.html

1 package hudson.cli.handlers;
2
3 import hudson.model.AbstractProject;
4 import jenkins.model.Jenkins;
5 import hudson.model.TopLevelItem;
6 import org.kohsuke.MetaInfServices;
7 import org.kohsuke.args4j.CmdLineException;
8 import org.kohsuke.args4j.CmdLineParser;
9 import org.kohsuke.args4j.OptionDef;
10 import org.kohsuke.args4j.spi.OptionHandler;
11 import org.kohsuke.args4j.spi.Parameters;
12 import org.kohsuke.args4j.spi.Setter;
13
14 /**
15 * Refers to {@link TopLevelItem} by its name.
16 *
17 * @author Kohsuke Kawaguchi
18 */
19 @MetaInfServices
20 public class TopLevelItemOptionHandler extends OptionHandler<TopLevelItem> {
21 public TopLevelItemOptionHandler(CmdLineParser parser, OptionDef option, Setter<TopLevelItem> setter) {
22 super(parser, option, setter);
23 }
24
25 @Override
26 @SuppressWarnings("rawtypes")
27 public int parseArguments(Parameters params) throws CmdLineException {
28 Jenkins h = Jenkins.getInstance();
29 String src = params.getParameter(0);
30
31 TopLevelItem s = h.getItemByFullName(src, TopLevelItem.class);
32 if (s==null) {
33 AbstractProject nearest = AbstractProject.findNearest(src);
34 if (nearest!=null)
35 throw new CmdLineException(owner, "No such job '"+src+"' perhaps you meant '"+ nearest.getFullName() +"'?");
36 else
37 throw new CmdLineException(owner, "No such job '"+src+"'");
38 }
39
40 setter.addValue(s);
41 return 1;
42 }
43
44 @Override
45 public String getDefaultMetaVariable() {
46 return "JOB";
47 }
48 }
49