提交 3a753c56 编写于 作者: A Andrew Bayer

Merge pull request #379 from imod/deactivate-cycles

Deactivate plugins with cyclic dependencies
......@@ -28,10 +28,12 @@ import hudson.init.InitMilestone;
import hudson.init.InitStrategy;
import hudson.init.InitializerFinder;
import hudson.model.AbstractModelObject;
import hudson.model.AdministrativeMonitor;
import hudson.model.Descriptor;
import hudson.model.Failure;
import hudson.model.UpdateCenter;
import hudson.model.UpdateSite;
import hudson.model.UpdateSite.Data;
import hudson.util.CyclicGraphDetector;
import hudson.util.CyclicGraphDetector.CycleDetectedException;
import hudson.util.FormValidation;
......@@ -243,6 +245,18 @@ public abstract class PluginManager extends AbstractModelObject {
r.add(p);
}
}
@Override
protected void reactOnCycle(PluginWrapper q, List<PluginWrapper> cycle)
throws hudson.util.CyclicGraphDetector.CycleDetectedException {
LOGGER.log(Level.SEVERE, "found cycle in plugin dependencies: (root="+q+", deactivating all involved) "+Util.join(cycle," -> "));
for (PluginWrapper pluginWrapper : cycle) {
pluginWrapper.setHasCycleDependency(true);
failedPlugins.add(new FailedPlugin(pluginWrapper.getShortName(), new CycleDetectedException(cycle)));
}
}
};
cgd.run(getPlugins());
......@@ -810,4 +824,32 @@ public abstract class PluginManager extends AbstractModelObject {
/*package*/ static final class PluginInstanceStore {
final Map<PluginWrapper,Plugin> store = new Hashtable<PluginWrapper,Plugin>();
}
/**
* {@link AdministrativeMonitor} that checks if there are any plugins with cycle dependencies.
*/
@Extension
public static final class PluginCycleDependenciesMonitor extends AdministrativeMonitor {
private transient volatile boolean isActive = false;
private transient volatile List<String> pluginsWithCycle;
public boolean isActivated() {
if(pluginsWithCycle == null){
pluginsWithCycle = new ArrayList<String>();
for (PluginWrapper p : Jenkins.getInstance().getPluginManager().getPlugins()) {
if(p.hasCycleDependency()){
pluginsWithCycle.add(p.getShortName());
isActive = true;
}
}
}
return true;
}
public List<String> getPluginsWithCycle() {
return pluginsWithCycle;
}
}
}
......@@ -126,6 +126,8 @@ public class PluginWrapper implements Comparable<PluginWrapper> {
*/
private final boolean active;
private boolean hasCycleDependency = false;
private final List<Dependency> dependencies;
private final List<Dependency> optionalDependencies;
......@@ -277,6 +279,8 @@ public class PluginWrapper implements Comparable<PluginWrapper> {
return null;
}
@Override
public String toString() {
return "Plugin:" + getShortName();
......@@ -379,7 +383,15 @@ public class PluginWrapper implements Comparable<PluginWrapper> {
* Returns true if this plugin is enabled for this session.
*/
public boolean isActive() {
return active;
return active && !hasCycleDependency();
}
public boolean hasCycleDependency(){
return hasCycleDependency;
}
public void setHasCycleDependency(boolean hasCycle){
hasCycleDependency = hasCycle;
}
public boolean isBundled() {
......
......@@ -23,9 +23,10 @@ public abstract class CyclicGraphDetector<N> {
private final List<N> topologicalOrder = new ArrayList<N>();
public void run(Iterable<? extends N> allNodes) throws CycleDetectedException {
for (N n : allNodes)
for (N n : allNodes){
visit(n);
}
}
/**
* Returns all the nodes in the topologically sorted order.
......@@ -62,7 +63,17 @@ public abstract class CyclicGraphDetector<N> {
private void detectedCycle(N q) throws CycleDetectedException {
int i = path.indexOf(q);
path.push(q);
throw new CycleDetectedException(path.subList(i, path.size()));
reactOnCycle(q, path.subList(i, path.size()));
}
/**
* React on detected cycles - default implementation throws an exception.
* @param q
* @param cycle
* @throws CycleDetectedException
*/
protected void reactOnCycle(N q, List<N> cycle) throws CycleDetectedException{
throw new CycleDetectedException(cycle);
}
public static final class CycleDetectedException extends Exception {
......
<!--
The MIT License
Copyright (c) 2012, Dominik Bartholdi
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
-->
<?jelly escape-by-default='true'?>
<j:jelly xmlns:j="jelly:core" xmlns:st="jelly:stapler" xmlns:d="jelly:define" xmlns:l="/lib/layout" xmlns:t="/lib/hudson" xmlns:f="/lib/form">
<div class="error">
${%PluginCycles}
<ul>
<j:forEach var="p" items="${it.pluginsWithCycle}">
<li><j:out value="${p}"/></li>
</j:forEach>
</ul>
</div>
</j:jelly>
# The MIT License
#
# Copyright (c) 2004-2012, Dominik Bartholdi
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.
PluginCycles=The following plugins are deactivated because of cyclic dependencies, most likely you can resolve the issue by updating these to a newer version.
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册