package hudson.plugins.cobertura;

import hudson.FilePath;
import hudson.model.Actionable;
import hudson.model.Build;
import hudson.model.DirectoryBrowserSupport;
import hudson.model.Project;
import hudson.model.ProminentProjectAction;
import hudson.model.Result;
import org.kohsuke.stapler.StaplerRequest;
import org.kohsuke.stapler.StaplerResponse;

import javax.servlet.ServletException;
import java.io.IOException;

/**
 * Project level action.
 *
 * @author Stephen Connolly
 */
public class CoberturaProjectAction extends Actionable implements ProminentProjectAction {

    private final Project<?, ?> project;

    public CoberturaProjectAction(Project project) {
        this.project = project;
    }

    public String getIconFileName() {
        return "graph.gif";
    }

    public String getDisplayName() {
        return "Coverage Report";
    }

    public String getUrlName() {
        return "cobertura";
    }

    public CoberturaBuildAction getLastResult() {
        for (Build<?, ?> b = project.getLastStableBuild(); b != null; b = b.getPreviousNotFailedBuild()) {
            if (b.getResult() == Result.FAILURE)
                continue;
            CoberturaBuildAction r = b.getAction(CoberturaBuildAction.class);
            if (r != null)
                return r;
        }
        return null;
    }

    public void doGraph(StaplerRequest req, StaplerResponse rsp) throws IOException {
        if (getLastResult() != null)
            getLastResult().getResult().doGraph(req, rsp);
    }

    public void doDynamic(StaplerRequest req, StaplerResponse rsp) throws IOException, ServletException,
            InterruptedException {
        new DirectoryBrowserSupport(this).serveFile(req, rsp,
                new FilePath(CoberturaPublisher.getCoberturaReportDir(project)), "graph.gif", false);
    }

    public void doIndex(StaplerRequest req, StaplerResponse rsp) throws IOException {
        rsp.sendRedirect2("../lastStableBuild/cobertura");
    }

    public String getSearchUrl() {
        return getUrlName();
    }
}

@@ -46,221 +46,15 @@
 son.
-FilePath;%0Aimport hudson.model.Actionable;%0Aimport hudson.model.Build;%0Aimport hudson.model.DirectoryBrowserSupport;%0Aimport hudson.model.Project;%0Aimport hudson.model.ProminentProjectAction;%0Aimport hudson.model.Result
+model.*
 ;%0Aim
@@ -143,47 +143,8 @@
 e;%0A%0A
-import javax.servlet.ServletException;%0A
 impo
@@ -1271,319 +1271,8 @@
  %7D%0A%0A
-    public void doDynamic(StaplerRequest req, StaplerResponse rsp) throws IOException, ServletException,%0A            InterruptedException %7B%0A        new DirectoryBrowserSupport(this).serveFile(req, rsp,%0A                new FilePath(CoberturaPublisher.getCoberturaReportDir(project)), %22graph.gif%22, false);%0A    %7D%0A%0A
     

Tidy up of some code that was left from copying clover plugin