提交 fe290d75 编写于 作者: K Kohsuke Kawaguchi

added AbstractBuild.getRootBuild() that matches up with AbstractProject.getRootProject()

上级 84ab5d81
......@@ -24,6 +24,7 @@
package hudson.matrix;
import hudson.FilePath;
import hudson.model.AbstractBuild;
import hudson.slaves.WorkspaceList;
import hudson.slaves.WorkspaceList.Lease;
import static hudson.matrix.MatrixConfiguration.useShortWorkspaceName;
......@@ -85,6 +86,14 @@ public class MatrixRun extends Build<MatrixConfiguration,MatrixRun> {
return getParent().getParent().getBuildByNumber(getNumber());
}
/**
* The same as {@link #getParentBuild()}.
*/
@Override
public AbstractBuild<?, ?> getRootBuild() {
return getParentBuild();
}
@Override
public String getDisplayName() {
StaplerRequest req = Stapler.getCurrentRequest();
......
......@@ -185,6 +185,24 @@ public abstract class AbstractBuild<P extends AbstractProject<P,R>,R extends Abs
return builtOn;
}
/**
* Gets the nearest ancestor {@link AbstractBuild} that belongs to
* {@linkplain AbstractProject#getRootProject() the root project of getProject()} that
* dominates/governs/encompasses this build.
*
* <p>
* Some projects (such as matrix projects, Maven projects, or promotion processes) form a tree of jobs,
* and still in some of them, builds of child projects are related/tied to that of the parent project.
* In such a case, this method returns the governing build.
*
* @return never null. In the worst case the build dominates itself.
* @since 1.421
* @see AbstractProject#getRootProject()
*/
public AbstractBuild<?,?> getRootBuild() {
return this;
}
/**
* Used to render the side panel "Back to project" link.
*
......
......@@ -368,15 +368,24 @@ public abstract class AbstractProject<P extends AbstractProject<P,R>,R extends A
}
/**
* Returns the root project value.
* Gets the nearest ancestor {@link TopLevelItem} that's also an {@link AbstractProject}.
*
* @return the root project value.
* <p>
* Some projects (such as matrix projects, Maven projects, or promotion processes) form a tree of jobs
* that acts as a single unit. This method can be used to find the top most dominating job that
* covers such a tree.
*
* @return never null.
* @see AbstractBuild#getRootBuild()
*/
public AbstractProject getRootProject() {
if (this.getParent() instanceof Jenkins) {
public AbstractProject<?,?> getRootProject() {
if (this instanceof TopLevelItem) {
return this;
} else {
return ((AbstractProject) this.getParent()).getRootProject();
ItemGroup p = this.getParent();
if (p instanceof AbstractProject)
return ((AbstractProject) p).getRootProject();
return this;
}
}
......
......@@ -178,6 +178,14 @@ public class MavenBuild extends AbstractMavenBuild<MavenModule,MavenBuild> {
return getParent().getParent().getBuildByNumber(getNumber());
}
/**
* The same as {@link #getParentBuild()}.
*/
@Override
public AbstractBuild<?, ?> getRootBuild() {
return getParentBuild();
}
/**
* Gets the "governing" {@link MavenModuleSet} that has set
* the workspace for this build.
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册