Navigation Menu

Skip to content

Commit

Permalink
[JENKINS-21485] AdministrativeMonitor for PluginWrapper
Browse files Browse the repository at this point in the history
  • Loading branch information
fbelzunc authored and Vlatombe committed Jul 29, 2016
1 parent 646969b commit aeb6ad9
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 0 deletions.
40 changes: 40 additions & 0 deletions core/src/main/java/hudson/PluginWrapper.java
Expand Up @@ -26,6 +26,7 @@

import com.google.common.collect.ImmutableSet;
import hudson.PluginManager.PluginInstanceStore;
import hudson.model.AdministrativeMonitor;
import hudson.model.Api;
import hudson.model.ModelObject;
import jenkins.YesNoMaybe;
Expand Down Expand Up @@ -53,6 +54,8 @@
import org.apache.commons.logging.LogFactory;
import org.kohsuke.stapler.HttpResponse;
import org.kohsuke.stapler.HttpResponses;
import org.kohsuke.stapler.StaplerRequest;
import org.kohsuke.stapler.StaplerResponse;
import org.kohsuke.stapler.export.Exported;
import org.kohsuke.stapler.export.ExportedBean;
import org.kohsuke.stapler.interceptor.RequirePOST;
Expand Down Expand Up @@ -560,13 +563,16 @@ public boolean hasLicensesXml() {
PluginWrapper dependency = parent.getPlugin(d.shortName);
if (dependency == null) {
missingDependencies.add(d);
NOTICE.addErrorMessage(Messages.PluginWrapper_admonitor_MissingDependency(getLongName(), d.shortName));
} else {
if (dependency.isActive()) {
if (isDependencyObsolete(d, dependency)) {
obsoleteDependencies.add(d);
NOTICE.addErrorMessage(Messages.PluginWrapper_admonitor_ObsoleteDependency(getLongName(), dependency.getLongName(), d.version));
}
} else {
disabledDependencies.add(d);
NOTICE.addErrorMessage(Messages.PluginWrapper_admonitor_DisabledDependency(getLongName(), dependency.getLongName()));
}

}
Expand All @@ -577,6 +583,7 @@ public boolean hasLicensesXml() {
if (dependency != null && dependency.isActive()) {
if (isDependencyObsolete(d, dependency)) {
obsoleteDependencies.add(d);
NOTICE.addErrorMessage(Messages.PluginWrapper_admonitor_ObsoleteDependency(getLongName(), dependency.getLongName(), d.version));
} else {
dependencies.add(d);
}
Expand Down Expand Up @@ -612,6 +619,7 @@ public boolean hasLicensesXml() {

private void checkRequiredCoreVersion(String requiredCoreVersion) throws IOException {
if (Jenkins.getVersion().isOlderThan(new VersionNumber(requiredCoreVersion))) {
NOTICE.addErrorMessage(Messages.PluginWrapper_admonitor_OutdatedCoreVersion(getLongName(), requiredCoreVersion));
throw new IOException(shortName + " requires a more recent core version (" + requiredCoreVersion + ") than the current (" + Jenkins.getVersion() + ").");
}
}
Expand Down Expand Up @@ -725,6 +733,38 @@ public boolean isPinningForcingOldVersion() {
return false;
}

@Extension
public final static PluginWrapperAdministrativeMonitor NOTICE = new PluginWrapperAdministrativeMonitor();

/**
* Administrative Monitor for failed plugins
*/
public static final class PluginWrapperAdministrativeMonitor extends AdministrativeMonitor {
public final List<String> pluginError = new ArrayList<>();

void addErrorMessage(String error) {
pluginError.add(error);
}

public boolean isActivated() {
return !pluginError.isEmpty();
}

/**
* Depending on whether the user said "dismiss" or "correct", send him to the right place.
*/
public void doAct(StaplerRequest req, StaplerResponse rsp) throws IOException {
if(req.hasParameter("correct")) {
rsp.sendRedirect(req.getContextPath()+"/pluginManager");

}
}

public static PluginWrapperAdministrativeMonitor get() {
return AdministrativeMonitor.all().get(PluginWrapperAdministrativeMonitor.class);
}
}

//
//
// Action methods
Expand Down
4 changes: 4 additions & 0 deletions core/src/main/resources/hudson/Messages.properties
Expand Up @@ -73,4 +73,8 @@ ProxyConfiguration.Success=Success

Functions.NoExceptionDetails=No Exception details

PluginWrapper.admonitor.OutdatedCoreVersion=Plugin {0} requires Jenkins {1} or later
PluginWrapper.admonitor.MissingDependency=Plugin {0} requires the missing plugin {1}
PluginWrapper.admonitor.DisabledDependency=Plugin {0} depends on the disabled {1}
PluginWrapper.admonitor.ObsoleteDependency=Plugin {0} requires {1} {2} or later
TcpSlaveAgentListener.PingAgentProtocol.displayName=Ping protocol
@@ -0,0 +1,15 @@
<?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">
<form method="post" action="${rootURL}/${it.url}/act" name="${it.id}">
<div style="float:right">
<f:submit name="correct" value="${%Correct}"/>
</div>
</form>
<ul>
<j:forEach items="${it.pluginError}" var="pluginError">
<li>${pluginError}</li>
</j:forEach>
</ul>
</div>
</j:jelly>

0 comments on commit aeb6ad9

Please sign in to comment.