1 package hudson.tasks.test; 2 3 import hudson.model.AbstractBuild; 4 import hudson.model.AbstractProject; 5 import hudson.model.Action; 6 import hudson.tasks.junit.JUnitResultArchiver; 7 import org.kohsuke.stapler.Ancestor; 8 import org.kohsuke.stapler.StaplerRequest; 9 import org.kohsuke.stapler.StaplerResponse; 10 11 import javax.servlet.ServletException ; 12 import javax.servlet.http.Cookie ; 13 import javax.servlet.http.HttpServletResponse ; 14 import java.io.IOException ; 15 import java.util.List ; 16 17 26 public class TestResultProjectAction implements Action { 27 30 public final AbstractProject<?,?> project; 31 32 public TestResultProjectAction(AbstractProject<?,?> project) { 33 this.project = project; 34 } 35 36 39 public String getIconFileName() { 40 return null; 41 } 42 43 public String getDisplayName() { 44 return "Test Report"; 45 } 46 47 public String getUrlName() { 48 return "test"; 49 } 50 51 protected AbstractTestResultAction getLastTestResultAction() { 52 AbstractBuild<?,?> b = project.getLastSuccessfulBuild(); 53 if(b!=null) { 54 AbstractTestResultAction a = b.getTestResultAction(); 55 if(a!=null) return a; 56 } 57 return null; 58 } 59 60 63 public void doTrend( StaplerRequest req, StaplerResponse rsp ) throws IOException , ServletException { 64 AbstractTestResultAction a = getLastTestResultAction(); 65 if(a!=null) 66 a.doGraph(req,rsp); 67 else 68 rsp.setStatus(HttpServletResponse.SC_NOT_FOUND); 69 } 70 71 74 public void doTrendMap( StaplerRequest req, StaplerResponse rsp ) throws IOException , ServletException { 75 AbstractTestResultAction a = getLastTestResultAction(); 76 if(a!=null) 77 a.doGraphMap(req,rsp); 78 else 79 rsp.setStatus(HttpServletResponse.SC_NOT_FOUND); 80 } 81 82 85 public void doFlipTrend( StaplerRequest req, StaplerResponse rsp ) throws IOException , ServletException { 86 boolean failureOnly = false; 87 88 Cookie [] cookies = req.getCookies(); 90 if(cookies!=null) { 91 for (Cookie cookie : cookies) { 92 if(cookie.getName().equals(FAILURE_ONLY_COOKIE)) 93 failureOnly = Boolean.parseBoolean(cookie.getValue()); 94 } 95 } 96 97 failureOnly = !failureOnly; 99 100 Cookie cookie = new Cookie (FAILURE_ONLY_COOKIE,String.valueOf(failureOnly)); 102 List anc = req.getAncestors(); 103 Ancestor a = (Ancestor) anc.get(anc.size()-1); cookie.setPath(a.getUrl()); cookie.setMaxAge(Integer.MAX_VALUE); 106 rsp.addCookie(cookie); 107 108 rsp.sendRedirect(".."); 110 } 111 112 private static final String FAILURE_ONLY_COOKIE = "TestResultAction_failureOnly"; 113 } 114 | Popular Tags |