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

[FIXED JENKINS-9960]

We weren't actually enforcing the initialization order at all, as
sorting was based on the plugin name.
上级 01696a8e
......@@ -71,6 +71,9 @@ Upcoming changes</a>
<li class=bug>
Fixed timeline on build trend page.
(<a href="http://issues.jenkins-ci.org/browse/JENKINS-6439">issue 6439</a>)
<li class=bug>
Fixed the initialization order of plugins
(<a href="http://issues.jenkins-ci.org/browse/JENKINS-9960">issue 9960</a>)
<li class=rfe>
<tt>LDAPBindSecurityRealm.groovy</tt> can be now overridden in <tt>$JENKINS_HOME</tt> if it exists.
<li class=rfe>
......
......@@ -69,6 +69,7 @@ import java.util.Enumeration;
import java.util.HashSet;
import java.util.Hashtable;
import java.util.List;
import java.util.ListIterator;
import java.util.Set;
import java.util.Map;
import java.util.HashMap;
......@@ -188,8 +189,6 @@ public abstract class PluginManager extends AbstractModelObject {
p.isBundled = bundledPlugins.contains(arc.getName());
plugins.add(p);
if(p.isActive())
activePlugins.add(p);
} catch (IOException e) {
failedPlugins.add(new FailedPlugin(arc.getName(),e));
throw e;
......@@ -213,34 +212,43 @@ public abstract class PluginManager extends AbstractModelObject {
});
}
g.requires(PLUGINS_PREPARED).add("Checking cyclic dependencies",new Executable() {
g.followedBy().attains(PLUGINS_LISTED).add("Checking cyclic dependencies", new Executable() {
/**
* Makes sure there's no cycle in dependencies.
*/
public void run(Reactor reactor) throws Exception {
try {
new CyclicGraphDetector<PluginWrapper>() {
CyclicGraphDetector<PluginWrapper> cgd = new CyclicGraphDetector<PluginWrapper>() {
@Override
protected List<PluginWrapper> getEdges(PluginWrapper p) {
List<PluginWrapper> next = new ArrayList<PluginWrapper>();
addTo(p.getDependencies(),next);
addTo(p.getOptionalDependencies(),next);
addTo(p.getDependencies(), next);
addTo(p.getOptionalDependencies(), next);
return next;
}
private void addTo(List<Dependency> dependencies, List<PluginWrapper> r) {
for (Dependency d : dependencies) {
PluginWrapper p = getPlugin(d.shortName);
if (p!=null)
if (p != null)
r.add(p);
}
}
}.run(getPlugins());
};
cgd.run(getPlugins());
// obtain topologically sorted list and overwrite the list
ListIterator<PluginWrapper> litr = plugins.listIterator();
for (PluginWrapper p : cgd.getSorted()) {
litr.next();
litr.set(p);
if(p.isActive())
activePlugins.add(p);
}
} catch (CycleDetectedException e) {
stop(); // disable all plugins since classloading from them can lead to StackOverflow
throw e; // let Hudson fail
}
Collections.sort(plugins);
}
});
......
......@@ -2,7 +2,10 @@ package hudson.util;
import hudson.Util;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashSet;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Set;
import java.util.Stack;
......@@ -17,11 +20,21 @@ public abstract class CyclicGraphDetector<N> {
private final Set<N> visiting = new HashSet<N>();
private final Stack<N> path = new Stack<N>();
private final List<N> topologicalOrder = new ArrayList<N>();
public void run(Iterable<? extends N> allNodes) throws CycleDetectedException {
for (N n : allNodes)
visit(n);
}
/**
* Returns all the nodes in the topologically sorted order.
* That is, if there's an edge a->b, b always come earlier than a.
*/
public List<N> getSorted() {
return topologicalOrder;
}
/**
* List up edges from the given node (by listing nodes that those edges point to.)
*
......@@ -43,6 +56,7 @@ public abstract class CyclicGraphDetector<N> {
}
visiting.remove(p);
path.pop();
topologicalOrder.add(p);
}
private void detectedCycle(N q) throws CycleDetectedException {
......
......@@ -4,7 +4,7 @@
<parent>
<groupId>org.jenkins-ci</groupId>
<artifactId>jenkins</artifactId>
<version>1.18</version>
<version>1.21</version>
</parent>
<groupId>org.jenkins-ci.plugins</groupId>
......@@ -155,7 +155,7 @@
<!-- version specified in parent pom -->
</plugin>
<plugin>
<groupId>org.codehaus.groovy.maven</groupId>
<groupId>org.codehaus.gmaven</groupId>
<artifactId>gmaven-plugin</artifactId>
<!-- version specified in grandparent pom -->
<executions>
......
......@@ -27,7 +27,7 @@ THE SOFTWARE.
<parent>
<groupId>org.jenkins-ci</groupId>
<artifactId>jenkins</artifactId>
<version>1.18</version>
<version>1.21</version>
</parent>
<groupId>org.jenkins-ci.main</groupId>
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册