Package hudson.model
Class DependencyGraph
- java.lang.Object
-
- hudson.model.DependencyGraph
-
- All Implemented Interfaces:
Comparator<AbstractProject>
public class DependencyGraph extends Object implements Comparator<AbstractProject>
Maintains the build dependencies betweenAbstractProjects for efficient dependency computation.The "master" data of dependencies are owned/persisted/maintained by individual
AbstractProjects, but because of that, it's relatively slow to compute backward edges.This class builds the complete bi-directional dependency graph by collecting information from all
AbstractProjects.Once built,
DependencyGraphis immutable, and every time there's a change (which is relatively rare), a new instance will be created. This eliminates the need of synchronization.- Author:
- Kohsuke Kawaguchi
- See Also:
Jenkins.getDependencyGraph()
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classDependencyGraph.DependencyRepresents an edge in the dependency graph.
-
Field Summary
Fields Modifier and Type Field Description static DependencyGraphEMPTY
-
Constructor Summary
Constructors Constructor Description DependencyGraph()Builds the dependency graph.
-
Method Summary
All Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description voidaddDependency(AbstractProject upstream, AbstractProject downstream)Deprecated.since 1.341; useaddDependency(Dependency)voidaddDependency(AbstractProject upstream, Collection<? extends AbstractProject> downstream)Deprecated.since 1.341voidaddDependency(DependencyGraph.Dependency dep)Called during the dependency graph build phase to add a dependency edge.voidaddDependency(Collection<? extends AbstractProject> upstream, AbstractProject downstream)Deprecated.since 1.341voidaddDependencyDeclarers(AbstractProject upstream, Collection<?> possibleDependecyDeclarers)Lists upDependencyDeclarerfrom the collection and let them builds dependencies.voidbuild()intcompare(AbstractProject o1, AbstractProject o2)Compare two Projects based on the topological order defined by this Dependency Graph<T> TgetComputationalData(Class<T> key)Gets temporary data which is needed for building up the dependency graph.List<AbstractProject>getDownstream(AbstractProject p)Gets all the immediate downstream projects (IOW forward edges) of the given project.List<DependencyGraph.Dependency>getDownstreamDependencies(AbstractProject p)List<AbstractProject<?,?>>getTopologicallySorted()Returns all the projects in the topological order of the dependency.Set<AbstractProject>getTransitiveDownstream(AbstractProject src)Gets all the direct and indirect downstream dependencies of the given project.Set<AbstractProject>getTransitiveUpstream(AbstractProject src)Gets all the direct and indirect upstream dependencies of the given project.List<AbstractProject>getUpstream(AbstractProject p)Gets all the immediate upstream projects (IOW backward edges) of the given project.List<DependencyGraph.Dependency>getUpstreamDependencies(AbstractProject p)booleanhasIndirectDependencies(AbstractProject src, AbstractProject dst)Returns true if a project has a non-direct dependency to another project.<T> voidputComputationalData(Class<T> key, T value)Adds data which is useful for the time when the dependency graph is built up.-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface java.util.Comparator
equals, reversed, thenComparing, thenComparing, thenComparing, thenComparingDouble, thenComparingInt, thenComparingLong
-
-
-
-
Field Detail
-
EMPTY
public static final DependencyGraph EMPTY
-
-
Method Detail
-
build
public void build()
-
putComputationalData
public <T> void putComputationalData(Class<T> key, T value)
Adds data which is useful for the time when the dependency graph is built up. All this data will be cleaned once the dependency graph creation has finished.
-
getComputationalData
public <T> T getComputationalData(Class<T> key)
Gets temporary data which is needed for building up the dependency graph.
-
getDownstream
public List<AbstractProject> getDownstream(AbstractProject p)
Gets all the immediate downstream projects (IOW forward edges) of the given project.- Returns:
- can be empty but never null.
-
getUpstream
public List<AbstractProject> getUpstream(AbstractProject p)
Gets all the immediate upstream projects (IOW backward edges) of the given project.- Returns:
- can be empty but never null.
-
getDownstreamDependencies
public List<DependencyGraph.Dependency> getDownstreamDependencies(AbstractProject p)
- Since:
- 1.341
-
getUpstreamDependencies
public List<DependencyGraph.Dependency> getUpstreamDependencies(AbstractProject p)
- Since:
- 1.341
-
addDependency
@Deprecated public void addDependency(AbstractProject upstream, AbstractProject downstream)
Deprecated.since 1.341; useaddDependency(Dependency)
-
addDependency
public void addDependency(DependencyGraph.Dependency dep)
Called during the dependency graph build phase to add a dependency edge.
-
addDependency
@Deprecated public void addDependency(AbstractProject upstream, Collection<? extends AbstractProject> downstream)
Deprecated.since 1.341
-
addDependency
@Deprecated public void addDependency(Collection<? extends AbstractProject> upstream, AbstractProject downstream)
Deprecated.since 1.341
-
addDependencyDeclarers
public void addDependencyDeclarers(AbstractProject upstream, Collection<?> possibleDependecyDeclarers)
Lists upDependencyDeclarerfrom the collection and let them builds dependencies.
-
hasIndirectDependencies
public boolean hasIndirectDependencies(AbstractProject src, AbstractProject dst)
Returns true if a project has a non-direct dependency to another project.A non-direct dependency is a path of dependency "edge"s from the source to the destination, where the length is greater than 1.
-
getTransitiveUpstream
public Set<AbstractProject> getTransitiveUpstream(AbstractProject src)
Gets all the direct and indirect upstream dependencies of the given project.
-
getTransitiveDownstream
public Set<AbstractProject> getTransitiveDownstream(AbstractProject src)
Gets all the direct and indirect downstream dependencies of the given project.
-
compare
public int compare(AbstractProject o1, AbstractProject o2)
Compare two Projects based on the topological order defined by this Dependency Graph- Specified by:
comparein interfaceComparator<AbstractProject>
-
getTopologicallySorted
public List<AbstractProject<?,?>> getTopologicallySorted()
Returns all the projects in the topological order of the dependency. Intuitively speaking, the first one in the list is the source of the dependency graph, and the last one is the sink.- Since:
- 1.521
-
-