| 1 package hudson.maven.reporters; 2 3 import hudson.FilePath; 4 import hudson.Util; 5 import hudson.maven.MavenBuildProxy; 6 import hudson.maven.MavenModule; 7 import hudson.maven.MavenReporter; 8 import hudson.maven.MavenReporterDescriptor; 9 import hudson.maven.MojoInfo; 10 import hudson.model.Action; 11 import hudson.model.BuildListener; 12 import hudson.model.Result; 13 import hudson.tasks.JavadocArchiver.JavadocAction; 14 import org.apache.maven.project.MavenProject; 15 import org.codehaus.plexus.component.configurator.ComponentConfigurationException; 16 17 import java.io.File ; 18 import java.io.IOException ; 19 20 25 public class MavenJavadocArchiver extends MavenReporter { 26 27 public boolean postExecute(MavenBuildProxy build, MavenProject pom, MojoInfo mojo, BuildListener listener) throws InterruptedException , IOException { 28 if(!mojo.pluginName.matches("org.apache.maven.plugins","maven-javadoc-plugin")) 29 return true; 30 31 if(!mojo.getGoal().equals("javadoc")) 32 return true; 33 34 File destDir; 35 try { 36 destDir = mojo.getConfigurationValue("outputDirectory", File .class); 37 } catch (ComponentConfigurationException e) { 38 e.printStackTrace(listener.fatalError("Unable to obtain the destDir from javadoc mojo")); 39 build.setResult(Result.FAILURE); 40 return true; 41 } 42 43 if(destDir.exists()) { 44 FilePath target = build.getProjectRootDir().child("javadoc"); 46 47 try { 48 listener.getLogger().println("Archiving javadoc"); 49 new FilePath(destDir).copyRecursiveTo("**/*",target); 50 } catch (IOException e) { 51 Util.displayIOException(e,listener); 52 e.printStackTrace(listener.fatalError("Unable to copy Javadoc from "+destDir+" to "+target)); 53 build.setResult(Result.FAILURE); 54 } 55 56 build.registerAsProjectAction(this); 57 } 58 59 return true; 60 } 61 62 63 public Action getProjectAction(MavenModule project) { 64 return new JavadocAction(project); 65 } 66 67 public DescriptorImpl getDescriptor() { 68 return DescriptorImpl.DESCRIPTOR; 69 } 70 71 public static final class DescriptorImpl extends MavenReporterDescriptor { 72 public static final DescriptorImpl DESCRIPTOR = new DescriptorImpl(); 73 74 private DescriptorImpl() { 75 super(MavenJavadocArchiver.class); 76 } 77 78 public String getDisplayName() { 79 return "Publish javadoc"; 80 } 81 82 public MavenJavadocArchiver newAutoInstance(MavenModule module) { 83 return new MavenJavadocArchiver(); 84 } 85 } 86 87 private static final long serialVersionUID = 1L; 88 } 89 | Popular Tags |