mirror of
https://github.com/jenkinsci/jenkins.git
synced 2026-11-10 18:46:41 +00:00
[FIXED HUDSON-1947] Merged the branch from Peter Hayes, with a few additional changes to retain the original behavior whenever possble.
People often downgrade Hudson, so it's normally better to be compatible with the old way of storing data, provided that it's not too hard. git-svn-id: https://hudson.dev.java.net/svn/hudson/trunk/hudson/main@10469 71c3de6d-444a-0410-be80-ed276b4c234a
This commit is contained in:
1 parent
adbccfee4f
commit
cff9cde5ec
5 files changed
+103
-23
No files matched your search
@@ -3,7 +3,6 @@ package hudson.tasks;
|
||||
import hudson.FilePath;
|
||||
import hudson.Launcher;
|
||||
import hudson.Util;
|
||||
import hudson.maven.MavenModuleSet;
|
||||
import hudson.maven.AbstractMavenProject;
|
||||
import hudson.model.*;
|
||||
import hudson.util.FormFieldValidator;
|
||||
@@ -26,16 +25,25 @@ public class JavadocArchiver extends Publisher {
|
||||
* Path to the Javadoc directory in the workspace.
|
||||
*/
|
||||
private final String javadocDir;
|
||||
/**
|
||||
* If true, retain javadoc for all the successful builds.
|
||||
*/
|
||||
private final boolean keepAll;
|
||||
|
||||
@DataBoundConstructor
|
||||
public JavadocArchiver(String javadoc_dir) {
|
||||
public JavadocArchiver(String javadoc_dir, boolean keep_all) {
|
||||
this.javadocDir = javadoc_dir;
|
||||
this.keepAll = keep_all;
|
||||
}
|
||||
|
||||
public String getJavadocDir() {
|
||||
return javadocDir;
|
||||
}
|
||||
|
||||
public boolean isKeepAll() {
|
||||
return keepAll;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the directory where the Javadoc is stored for the given project.
|
||||
*/
|
||||
@@ -43,26 +51,40 @@ public class JavadocArchiver extends Publisher {
|
||||
return new File(project.getRootDir(),"javadoc");
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the directory where the Javadoc is stored for the given build.
|
||||
*/
|
||||
private static File getJavadocDir(Run run) {
|
||||
return new File(run.getRootDir(),"javadoc");
|
||||
}
|
||||
|
||||
public boolean perform(AbstractBuild<?,?> build, Launcher launcher, BuildListener listener) throws InterruptedException {
|
||||
listener.getLogger().println(Messages.JavadocArchiver_Publishing());
|
||||
|
||||
FilePath javadoc = build.getParent().getWorkspace().child(javadocDir);
|
||||
FilePath target = new FilePath(getJavadocDir(build.getParent()));
|
||||
FilePath target = new FilePath(keepAll ? getJavadocDir(build) : getJavadocDir(build.getProject()));
|
||||
|
||||
try {
|
||||
// if the build has failed, then there's not much point in reporting an error
|
||||
// saying javadoc directory doesn't exist. We want the user to focus on the real error,
|
||||
// which is the build failure.
|
||||
if(build.getResult().isWorseOrEqualTo(Result.FAILURE) && !javadoc.exists())
|
||||
if (javadoc.copyRecursiveTo("**/*",target)==0) {
|
||||
if(build.getResult().isBetterOrEqualTo(Result.UNSTABLE)) {
|
||||
// If the build failed, don't complain that there was no javadoc.
|
||||
// The build probably didn't even get to the point where it produces javadoc.
|
||||
listener.error(Messages.JavadocArchiver_NoMatchFound(javadoc));
|
||||
}
|
||||
build.setResult(Result.FAILURE);
|
||||
return true;
|
||||
|
||||
javadoc.copyRecursiveTo("**/*",target);
|
||||
}
|
||||
} catch (IOException e) {
|
||||
Util.displayIOException(e,listener);
|
||||
e.printStackTrace(listener.fatalError(Messages.JavadocArchiver_UnableToCopy(javadoc,target)));
|
||||
build.setResult(Result.FAILURE);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
// add build action, if javadoc is recorded for each build
|
||||
if(keepAll)
|
||||
build.addAction(new JavadocBuildAction(build));
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -74,29 +96,22 @@ public class JavadocArchiver extends Publisher {
|
||||
return DESCRIPTOR;
|
||||
}
|
||||
|
||||
|
||||
public static final Descriptor<Publisher> DESCRIPTOR = new DescriptorImpl();
|
||||
|
||||
public static class JavadocAction implements ProminentProjectAction {
|
||||
private final AbstractItem project;
|
||||
|
||||
public JavadocAction(AbstractItem project) {
|
||||
this.project = project;
|
||||
}
|
||||
|
||||
protected static abstract class BaseJavadocAction implements Action {
|
||||
public String getUrlName() {
|
||||
return "javadoc";
|
||||
}
|
||||
|
||||
public String getDisplayName() {
|
||||
if(new File(getJavadocDir(project),"help-doc.html").exists())
|
||||
if (new File(dir(), "help-doc.html").exists())
|
||||
return Messages.JavadocArchiver_DisplayName_Javadoc();
|
||||
else
|
||||
return Messages.JavadocArchiver_DisplayName_Generic();
|
||||
}
|
||||
|
||||
public String getIconFileName() {
|
||||
if(getJavadocDir(project).exists())
|
||||
if(dir().exists())
|
||||
return "help.gif";
|
||||
else
|
||||
// hide it since we don't have javadoc yet.
|
||||
@@ -104,8 +119,58 @@ public class JavadocArchiver extends Publisher {
|
||||
}
|
||||
|
||||
public void doDynamic(StaplerRequest req, StaplerResponse rsp) throws IOException, ServletException, InterruptedException {
|
||||
new DirectoryBrowserSupport(this,project.getDisplayName()+" javadoc")
|
||||
.serveFile(req, rsp, new FilePath(getJavadocDir(project)), "help.gif", false);
|
||||
new DirectoryBrowserSupport(this, getTitle())
|
||||
.serveFile(req, rsp, new FilePath(dir()), "help.gif", false);
|
||||
}
|
||||
|
||||
protected abstract String getTitle();
|
||||
|
||||
protected abstract File dir();
|
||||
}
|
||||
|
||||
public static class JavadocAction extends BaseJavadocAction implements ProminentProjectAction {
|
||||
private final AbstractItem project;
|
||||
|
||||
public JavadocAction(AbstractItem project) {
|
||||
this.project = project;
|
||||
}
|
||||
|
||||
protected File dir() {
|
||||
// Would like to change AbstractItem to AbstractProject, but is
|
||||
// that a backwards compatible change?
|
||||
if (project instanceof AbstractProject) {
|
||||
AbstractProject abstractProject = (AbstractProject) project;
|
||||
|
||||
Run run = abstractProject.getLastSuccessfulBuild();
|
||||
if (run != null) {
|
||||
File javadocDir = getJavadocDir(run);
|
||||
|
||||
if (javadocDir.exists())
|
||||
return javadocDir;
|
||||
}
|
||||
}
|
||||
|
||||
return getJavadocDir(project);
|
||||
}
|
||||
|
||||
protected String getTitle() {
|
||||
return project.getDisplayName()+" javadoc";
|
||||
}
|
||||
}
|
||||
|
||||
public static class JavadocBuildAction extends BaseJavadocAction {
|
||||
private final AbstractBuild<?,?> build;
|
||||
|
||||
public JavadocBuildAction(AbstractBuild<?,?> build) {
|
||||
this.build = build;
|
||||
}
|
||||
|
||||
protected String getTitle() {
|
||||
return build.getDisplayName()+" javadoc";
|
||||
}
|
||||
|
||||
protected File dir() {
|
||||
return getJavadocDir(build);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -4,4 +4,8 @@
|
||||
<f:textbox name="javadoc_dir" value="${instance.javadocDir}"
|
||||
checkUrl="'${rootURL}/publisher/JavadocArchiver/check?job=${it.fullName}&value='+escape(this.value)"/>
|
||||
</f:entry>
|
||||
<f:entry help="/help/project-config/javadoc-keep-all.html">
|
||||
<f:checkbox name="keep_all" checked="${instance.keepAll}" />
|
||||
<label class="attach-previous">${%Retain javadoc for each successful build}</label>
|
||||
</f:entry>
|
||||
</j:jelly>
|
||||
@@ -1 +1,2 @@
|
||||
description=Directory relative to the root of the workspace, such as 'myproject/build/javadoc'
|
||||
description=Directory relative to the root of the workspace, such as 'myproject/build/javadoc'
|
||||
keepAll=Keep javadoc output for all successful builds
|
||||
@@ -40,6 +40,7 @@ Fingerprinter.Recording=Recording fingerprints
|
||||
JavadocArchiver.DisplayName=Publish Javadoc
|
||||
JavadocArchiver.DisplayName.Generic=Document
|
||||
JavadocArchiver.DisplayName.Javadoc=Javadoc
|
||||
JavadocArchiver.NoMatchFound=No javadoc found in {0}
|
||||
JavadocArchiver.Publishing=Publishing Javadoc
|
||||
JavadocArchiver.UnableToCopy=Unable to copy Javadoc from {0} to {1}
|
||||
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
<div>
|
||||
If you check this option, Hudson will retain javadoc for each successful build.
|
||||
This allows you to browser javadoc for older builds, at the expense of additional
|
||||
disk space requirement.
|
||||
|
||||
<p>
|
||||
If you leave this optoin unchecked, Hudson will only keep the latest javadoc,
|
||||
so older javadoc will be overwritten as new builds succeed.
|
||||
</div>
|
||||
Reference in new issue
Block a user