提交 5e00f237 编写于 作者: K kohsuke

Added a new CLI command to retrieve list of changes.

git-svn-id: https://hudson.dev.java.net/svn/hudson/trunk/hudson/main@24895 71c3de6d-444a-0410-be80-ed276b4c234a
上级 1e048c47
package hudson.cli;
import hudson.model.AbstractBuild;
import hudson.model.AbstractProject;
import hudson.model.Fingerprint.RangeSet;
import org.kohsuke.args4j.Argument;
import java.io.IOException;
import java.util.List;
/**
* {@link CLICommand} that acts on a series of {@link AbstractBuild}s.
*
* @author Kohsuke Kawaguchi
*/
public abstract class AbstractBuildRangeCommand extends CLICommand {
@Argument(metaVar="JOB",usage="Name of the job to build",required=true,index=0)
public AbstractProject<?,?> job;
@Argument(metaVar="RANGE",usage="Range of the build records to delete. 'N-M', 'N,M', or 'N'",required=true,index=1)
public String range;
protected int run() throws Exception {
RangeSet rs = RangeSet.fromString(range,false);
return act((List)job.getBuilds(rs));
}
protected abstract int act(List<AbstractBuild<?,?>> builds) throws IOException;
}
......@@ -23,12 +23,10 @@
*/
package hudson.cli;
import hudson.model.AbstractBuild;
import hudson.model.AbstractProject;
import hudson.model.Fingerprint.RangeSet;
import hudson.Extension;
import org.kohsuke.args4j.Argument;
import hudson.model.AbstractBuild;
import java.io.IOException;
import java.io.PrintStream;
import java.util.List;
......@@ -38,18 +36,12 @@ import java.util.List;
* @author Kohsuke Kawaguchi
*/
@Extension
public class DeleteBuildsCommand extends CLICommand {
public class DeleteBuildsCommand extends AbstractBuildRangeCommand {
@Override
public String getShortDescription() {
return "Deletes build record(s)";
}
@Argument(metaVar="JOB",usage="Name of the job to build",required=true,index=0)
public AbstractProject<?,?> job;
@Argument(metaVar="RANGE",usage="Range of the build records to delete. 'N-M', 'N,M', or 'N'",required=true,index=1)
public String range;
@Override
protected void printUsageSummary(PrintStream stderr) {
stderr.println(
......@@ -57,10 +49,8 @@ public class DeleteBuildsCommand extends CLICommand {
);
}
protected int run() throws Exception {
RangeSet rs = RangeSet.fromString(range,false);
List<? extends AbstractBuild> builds = job.getBuilds(rs);
@Override
protected int act(List<AbstractBuild<?, ?>> builds) throws IOException {
for (AbstractBuild build : builds)
build.delete();
......@@ -68,4 +58,5 @@ public class DeleteBuildsCommand extends CLICommand {
return 0;
}
}
package hudson.cli;
import hudson.Extension;
import hudson.model.AbstractBuild;
import hudson.scm.ChangeLogSet;
import hudson.scm.ChangeLogSet.Entry;
import hudson.util.QuotedStringTokenizer;
import org.kohsuke.args4j.Option;
import org.kohsuke.stapler.export.Flavor;
import org.kohsuke.stapler.export.Model;
import org.kohsuke.stapler.export.ModelBuilder;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.List;
/**
* Retrieves a change list for the specified builds.
*
* @author Kohsuke Kawaguchi
*/
@Extension
public class ListChangesCommand extends AbstractBuildRangeCommand {
@Override
public String getShortDescription() {
return "Dumps the changelog for the specified build(s)";
}
// @Override
// protected void printUsageSummary(PrintStream stderr) {
// TODO
// }
enum Format {
XML, CSV, PLAIN
}
@Option(name="-format",usage="Controls how the output from this command is printed.")
public Format format = Format.PLAIN;
@Override
protected int act(List<AbstractBuild<?, ?>> builds) throws IOException {
switch (format) {
case XML:
PrintWriter w = new PrintWriter(stdout);
w.println("<changes>");
for (AbstractBuild build : builds) {
w.println("<build number='"+build.getNumber()+"'>");
ChangeLogSet<?> cs = build.getChangeSet();
Model p = new ModelBuilder().get(cs.getClass());
p.writeTo(cs,Flavor.XML.createDataWriter(cs,w));
w.println("</build>");
}
w.println("</changes>");
w.flush();
break;
case CSV:
for (AbstractBuild build : builds) {
ChangeLogSet<?> cs = build.getChangeSet();
for (Entry e : cs) {
stdout.printf("%s,%s\n",
QuotedStringTokenizer.quote(e.getAuthor().getId()),
QuotedStringTokenizer.quote(e.getMsg()));
}
}
break;
case PLAIN:
for (AbstractBuild build : builds) {
ChangeLogSet<?> cs = build.getChangeSet();
for (Entry e : cs) {
stdout.printf("%s\t%s\n",e.getAuthor(),e.getMsg());
for (String p : e.getAffectedPaths())
stdout.println(" "+p);
}
}
break;
}
return 0;
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册