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

1 package hudson.cli;
2
3 import hudson.Extension;
4 import hudson.model.AbstractBuild;
5 import hudson.scm.ChangeLogSet;
6 import hudson.scm.ChangeLogSet.Entry;
7 import hudson.util.QuotedStringTokenizer;
8 import org.kohsuke.args4j.Option;
9 import org.kohsuke.stapler.export.Flavor;
10 import org.kohsuke.stapler.export.Model;
11 import org.kohsuke.stapler.export.ModelBuilder;
12
13 import java.io.IOException;
14 import java.io.PrintWriter;
15 import java.util.List;
16
17 /**
18 * Retrieves a change list for the specified builds.
19 *
20 * @author Kohsuke Kawaguchi
21 */
22 @Extension
23 public class ListChangesCommand extends AbstractBuildRangeCommand {
24 @Override
25 public String getShortDescription() {
26 return Messages.ListChangesCommand_ShortDescription();
27 }
28
29 // @Override
30 // protected void printUsageSummary(PrintStream stderr) {
31 // TODO
32 // }
33
34 enum Format {
35 XML, CSV, PLAIN
36 }
37
38 @Option(name="-format",usage="Controls how the output from this command is printed.")
39 public Format format = Format.PLAIN;
40
41 @Override
42 protected int act(List<AbstractBuild<?, ?>> builds) throws IOException {
43 // Loading job for this CLI command requires Item.READ permission.
44 // No other permission check needed.
45 switch (format) {
46 case XML:
47 PrintWriter w = new PrintWriter(stdout);
48 w.println("<changes>");
49 for (AbstractBuild build : builds) {
50 w.println("<build number='"+build.getNumber()+"'>");
51 ChangeLogSet<?> cs = build.getChangeSet();
52 Model p = new ModelBuilder().get(cs.getClass());
53 p.writeTo(cs,Flavor.XML.createDataWriter(cs,w));
54 w.println("</build>");
55 }
56 w.println("</changes>");
57 w.flush();
58 break;
59 case CSV:
60 for (AbstractBuild build : builds) {
61 ChangeLogSet<?> cs = build.getChangeSet();
62 for (Entry e : cs) {
63 stdout.printf("%s,%s%n",
64 QuotedStringTokenizer.quote(e.getAuthor().getId()),
65 QuotedStringTokenizer.quote(e.getMsg()));
66 }
67 }
68 break;
69 case PLAIN:
70 for (AbstractBuild build : builds) {
71 ChangeLogSet<?> cs = build.getChangeSet();
72 for (Entry e : cs) {
73 stdout.printf("%s\t%s%n",e.getAuthor(),e.getMsg());
74 for (String p : e.getAffectedPaths())
75 stdout.println(" "+p);
76 }
77 }
78 break;
79 }
80
81 return 0;
82 }
83
84 }
85