提交 a42bda7e 编写于 作者: K kohsuke

started writing code to watch out for MavenReport execution and collect them.


git-svn-id: https://hudson.dev.java.net/svn/hudson/trunk/hudson/main@6348 71c3de6d-444a-0410-be80-ed276b4c234a
上级 bcaa4656
package hudson.maven.reporters;
import hudson.model.Action;
import org.apache.maven.reporting.MavenReport;
import java.util.List;
import java.util.ArrayList;
/**
* {@link Action} to display links to the generated {@link MavenReport Maven reports}.
* @author Kohsuke Kawaguchi
*/
public final class ReportAction implements Action {
private final List<Entry> entries = new ArrayList<Entry>();
public static final class Entry {
/**
* Relative path to the top of the report withtin the project reporting directory.
*/
public final String path;
public final String title;
public Entry(String path, String title) {
this.path = path;
this.title = title;
}
}
public ReportAction() {
}
protected void add(Entry e) {
entries.add(e);
}
public String getIconFileName() {
// TODO
return "n/a.gif";
}
public String getDisplayName() {
return "Maven reports";
}
public String getUrlName() {
return "mavenReports";
}
}
package hudson.maven.reporters;
import hudson.maven.MavenModule;
import hudson.maven.MavenReporter;
import hudson.maven.MavenReporterDescriptor;
import hudson.maven.MavenBuildProxy;
import hudson.maven.MojoInfo;
import hudson.maven.MavenBuild;
import hudson.model.BuildListener;
import org.apache.maven.project.MavenProject;
import org.apache.maven.reporting.MavenReport;
import java.io.IOException;
import java.io.File;
import java.util.Locale;
/**
* Watches out for executions of {@link MavenReport} mojos and record its output.
*
* @author Kohsuke Kawaguchi
*/
public class ReportCollector extends MavenReporter {
private transient ReportAction action;
public boolean postExecute(MavenBuildProxy build, MavenProject pom, MojoInfo mojo, BuildListener listener, Throwable error) throws InterruptedException, IOException {
if(!(mojo.mojo instanceof MavenReport))
return true; // not a maven report
MavenReport report = (MavenReport)mojo.mojo;
String reportPath = report.getReportOutputDirectory().getPath();
String projectReportPath = pom.getReporting().getOutputDirectory();
if(!reportPath.startsWith(projectReportPath)) {
// report is placed outside site. Can't record it.
listener.getLogger().println("Maven report output goes to "+reportPath+", which is outside project reporting path"+projectReportPath);
return true;
}
if(action==null)
action = new ReportAction();
// this is the entry point to the report
File top = new File(report.getReportOutputDirectory(),report.getOutputName()+".html");
String relPath = top.getPath().substring(projectReportPath.length());
action.add(new ReportAction.Entry(relPath,report.getName(Locale.getDefault())));
return true;
}
public boolean leaveModule(MavenBuildProxy build, MavenProject pom, BuildListener listener) throws InterruptedException, IOException {
if(action!=null) {
// TODO: archive pom.getReporting().getOutputDirectory()
build.execute(new AddActionTask(action));
}
action = null;
return super.leaveModule(build, pom, listener);
}
private static final class AddActionTask implements MavenBuildProxy.BuildCallable<Void,IOException> {
private final ReportAction action;
public AddActionTask(ReportAction action) {
this.action = action;
}
public Void call(MavenBuild build) throws IOException, InterruptedException {
build.addAction(action);
return null;
}
private static final long serialVersionUID = 1L;
}
public DescriptorImpl getDescriptor() {
return DescriptorImpl.DESCRIPTOR;
}
public static final class DescriptorImpl extends MavenReporterDescriptor {
public static final DescriptorImpl DESCRIPTOR = new DescriptorImpl();
private DescriptorImpl() {
super(ReportCollector.class);
}
public String getDisplayName() {
return "Record Maven reports";
}
public ReportCollector newAutoInstance(MavenModule module) {
return new ReportCollector();
}
}
private static final long serialVersionUID = 1L;
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册