Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[FIXED JENKINS-8866] Look for Descriptor.getId()==null and warn the a…
…dministrator
- Loading branch information
Showing
7 changed files
with
141 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
80 changes: 80 additions & 0 deletions
80
core/src/main/java/hudson/diagnosis/NullIdDescriptorMonitor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
/* | ||
* The MIT License | ||
* | ||
* Copyright (c) 2011, CloudBees, Inc. | ||
* | ||
* 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. | ||
*/ | ||
package hudson.diagnosis; | ||
|
||
import hudson.Extension; | ||
import hudson.PluginWrapper; | ||
import hudson.init.Initializer; | ||
import hudson.model.AdministrativeMonitor; | ||
import hudson.model.Descriptor; | ||
import hudson.model.Hudson; | ||
|
||
import java.text.MessageFormat; | ||
import java.util.ArrayList; | ||
import java.util.Collections; | ||
import java.util.List; | ||
import java.util.logging.Logger; | ||
|
||
import static hudson.init.InitMilestone.EXTENSIONS_AUGMENTED; | ||
|
||
/** | ||
* Some old descriptors apparently has the getId() method that's used in different ways | ||
* and that's causing errors like JENKINS-8866, so detect and report that. | ||
* | ||
* @author Kohsuke Kawaguchi | ||
* @since 1.402 | ||
*/ | ||
@Extension | ||
public class NullIdDescriptorMonitor extends AdministrativeMonitor { | ||
|
||
private final List<Descriptor> problems = new ArrayList<Descriptor>(); | ||
|
||
@Override | ||
public boolean isActivated() { | ||
return !problems.isEmpty(); | ||
} | ||
|
||
public List<Descriptor> getProblems() { | ||
return Collections.unmodifiableList(problems); | ||
} | ||
|
||
private void verify() { | ||
Hudson h = Hudson.getInstance(); | ||
for (Descriptor d : h.getExtensionList(Descriptor.class)) { | ||
if (d.getId()==null) { | ||
PluginWrapper p = h.getPluginManager().whichPlugin(d.getClass()); | ||
LOGGER.severe(MessageFormat.format("Descriptor {0} from plugin {1} with display name {2} has null ID", | ||
d, p==null?"???":p.getLongName(), d.getDisplayName())); | ||
problems.add(d); | ||
} | ||
} | ||
} | ||
|
||
@Initializer(after=EXTENSIONS_AUGMENTED) | ||
public static void verifyId() { | ||
AdministrativeMonitor.all().get(NullIdDescriptorMonitor.class).verify(); | ||
} | ||
|
||
private static final Logger LOGGER = Logger.getLogger(NullIdDescriptorMonitor.class.getName()); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
36 changes: 36 additions & 0 deletions
36
core/src/main/resources/hudson/diagnosis/NullIdDescriptorMonitor/message.jelly
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
<!-- | ||
The MIT License | ||
Copyright (c) 2011, CloudBees, Inc. | ||
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. | ||
--> | ||
|
||
<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"> | ||
${%blurb} | ||
<ul> | ||
<j:forEach var="d" items="${it.problems}"> | ||
<li> | ||
${%problem(d, d.displayName, app.pluginManager.whichPlugin(d.getClass()))} | ||
</li> | ||
</j:forEach> | ||
</ul> | ||
</div> | ||
</j:jelly> |
3 changes: 3 additions & 0 deletions
3
core/src/main/resources/hudson/diagnosis/NullIdDescriptorMonitor/message.properties
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
blurb=The following extensions have no ID value and therefore likely cause a problem. Please upgrade these plugins if they are not the latest, \ | ||
and if they are the latest, please file a bug so that we can fix them. | ||
problem=Descriptor {0} from plugin {2} with display name {1} |