1 package hudson.tasks; 2 3 import hudson.FilePath; 4 import hudson.Launcher; 5 import hudson.Util; 6 import hudson.model.Action; 7 import hudson.model.Build; 8 import hudson.model.BuildListener; 9 import hudson.model.Descriptor; 10 import hudson.model.DirectoryBrowserSupport; 11 import hudson.model.Project; 12 import hudson.model.ProminentProjectAction; 13 import hudson.model.Result; 14 import hudson.model.Actionable; 15 import hudson.model.AbstractItem; 16 import org.kohsuke.stapler.StaplerRequest; 17 import org.kohsuke.stapler.StaplerResponse; 18 19 import javax.servlet.ServletException ; 20 import java.io.File ; 21 import java.io.IOException ; 22 23 28 public class JavadocArchiver extends Publisher { 29 32 private final String javadocDir; 33 34 public JavadocArchiver(String javadocDir) { 35 this.javadocDir = javadocDir; 36 } 37 38 public String getJavadocDir() { 39 return javadocDir; 40 } 41 42 45 private static File getJavadocDir(AbstractItem project) { 46 return new File (project.getRootDir(),"javadoc"); 47 } 48 49 public boolean perform(Build build, Launcher launcher, BuildListener listener) throws InterruptedException { 50 listener.getLogger().println("Publishing Javadoc"); 51 52 FilePath javadoc = build.getParent().getWorkspace().child(javadocDir); 53 FilePath target = new FilePath(getJavadocDir(build.getParent())); 54 55 try { 56 javadoc.copyRecursiveTo("**/*",target); 57 } catch (IOException e) { 58 Util.displayIOException(e,listener); 59 e.printStackTrace(listener.fatalError("Unable to copy Javadoc from "+javadoc+" to "+target)); 60 build.setResult(Result.FAILURE); 61 } 62 63 return true; 64 } 65 66 public Action getProjectAction(Project project) { 67 return new JavadocAction(project); 68 } 69 70 public Descriptor<Publisher> getDescriptor() { 71 return DESCRIPTOR; 72 } 73 74 75 public static final Descriptor<Publisher> DESCRIPTOR = new Descriptor<Publisher>(JavadocArchiver.class) { 76 public String getDisplayName() { 77 return "Publish Javadoc"; 78 } 79 80 public Publisher newInstance(StaplerRequest req) { 81 return new JavadocArchiver(req.getParameter("javadoc_dir")); 82 } 83 }; 84 85 public static final class JavadocAction extends Actionable implements ProminentProjectAction { 86 private final AbstractItem project; 87 88 public JavadocAction(AbstractItem project) { 89 this.project = project; 90 } 91 92 public String getUrlName() { 93 return "javadoc"; 94 } 95 96 public String getDisplayName() { 97 return "Javadoc"; 98 } 99 100 public String getIconFileName() { 101 if(getJavadocDir(project).exists()) 102 return "help.gif"; 103 else 104 return null; 106 } 107 108 public void doDynamic(StaplerRequest req, StaplerResponse rsp) throws IOException , ServletException , InterruptedException { 109 new DirectoryBrowserSupport(this).serveFile(req, rsp, new FilePath(getJavadocDir(project)), "help.gif", false); 110 } 111 } 112 } 113 | Popular Tags |