-
Notifications
You must be signed in to change notification settings - Fork 273
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Diagnostics pages #275
Diagnostics pages #275
Changes from all commits
66460bc
f256ffe
79b5d1c
51ec324
e8fa096
21a8b13
14065c5
3eb4f64
4e35fe0
e6070bf
830d288
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,40 +24,28 @@ | |
*/ | ||
package com.sonyericsson.hudson.plugins.gerrit.trigger; | ||
|
||
import com.sonymobile.tools.gerrit.gerritevents.GerritSendCommandQueue; | ||
import com.sonyericsson.hudson.plugins.gerrit.trigger.config.Config; | ||
import com.sonyericsson.hudson.plugins.gerrit.trigger.config.IGerritHudsonTriggerConfig; | ||
import com.sonyericsson.hudson.plugins.gerrit.trigger.config.PluginConfig; | ||
import com.sonyericsson.hudson.plugins.gerrit.trigger.diagnostics.Diagnostics; | ||
import com.sonyericsson.hudson.plugins.gerrit.trigger.hudsontrigger.GerritAdministrativeMonitor; | ||
|
||
import com.sonymobile.tools.gerrit.gerritevents.GerritSendCommandQueue; | ||
import hudson.DescriptorExtensionList; | ||
import hudson.Extension; | ||
import hudson.Functions; | ||
import hudson.model.AdministrativeMonitor; | ||
import hudson.model.AutoCompletionCandidates; | ||
import hudson.model.Describable; | ||
import hudson.model.Failure; | ||
import hudson.model.Descriptor; | ||
import hudson.model.Failure; | ||
import hudson.model.Hudson; | ||
import hudson.model.ManagementLink; | ||
import hudson.model.Saveable; | ||
import hudson.util.FormValidation; | ||
|
||
import java.io.IOException; | ||
import java.net.URLDecoder; | ||
import java.net.URLEncoder; | ||
import java.util.Collections; | ||
import java.util.List; | ||
|
||
import javax.annotation.CheckForNull; | ||
import javax.servlet.ServletException; | ||
|
||
import jenkins.model.Jenkins; | ||
|
||
import jenkins.model.ModelObjectWithContextMenu; | ||
import net.sf.json.JSONArray; | ||
import net.sf.json.JSONObject; | ||
|
||
import org.apache.commons.lang.CharEncoding; | ||
import org.kohsuke.stapler.QueryParameter; | ||
import org.kohsuke.stapler.StaplerProxy; | ||
|
@@ -67,6 +55,14 @@ | |
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
import javax.annotation.CheckForNull; | ||
import javax.servlet.ServletException; | ||
import java.io.IOException; | ||
import java.net.URLDecoder; | ||
import java.net.URLEncoder; | ||
import java.util.Collections; | ||
import java.util.List; | ||
|
||
import static com.sonyericsson.hudson.plugins.gerrit.trigger.utils.StringUtil.PLUGIN_IMAGES_URL; | ||
|
||
/** | ||
|
@@ -86,6 +82,8 @@ public class GerritManagement extends ManagementLink implements StaplerProxy, De | |
|
||
private static final Logger logger = LoggerFactory.getLogger(GerritManagement.class); | ||
|
||
private static final Diagnostics DIAGNOSTICS = new Diagnostics(); | ||
|
||
|
||
@Override | ||
public String getIconFileName() { | ||
|
@@ -118,13 +116,28 @@ public ContextMenu doContextMenu(StaplerRequest request, StaplerResponse respons | |
assert jenkins != null; | ||
ContextMenu menu = new ContextMenu(); | ||
menu.add("newServer", Functions.joinPath(jenkins.getRootUrl(), Functions.getResourcePath(), | ||
"images", "24x24", "new-package.png"), Messages.AddNewServer()); | ||
"images", "24x24", "new-package.png"), Messages.AddNewServer()); | ||
for (GerritServer server : getServers()) { | ||
menu.add(server); | ||
} | ||
MenuItem item = new MenuItem() | ||
.withUrl("diagnostics") | ||
.withDisplayName(DIAGNOSTICS) | ||
.withStockIcon("folder.png"); | ||
item.subMenu = DIAGNOSTICS.getContextMenu("diagnostics"); | ||
menu.add(item); | ||
return menu; | ||
} | ||
|
||
/** | ||
* A sub page displaying some diagnostic views. | ||
* | ||
* @return the diagnostics page. | ||
*/ | ||
public Diagnostics getDiagnostics() { | ||
return DIAGNOSTICS; | ||
} | ||
|
||
/** | ||
* Descriptor is only used for UI form bindings. | ||
*/ | ||
|
@@ -170,10 +183,10 @@ public AutoCompletionCandidates doAutoCompleteCopyNewItemFrom(@QueryParameter fi | |
} | ||
|
||
/** | ||
* Gets the list of GerritServer. | ||
* | ||
* @return the list of GerritServer. | ||
*/ | ||
* Gets the list of GerritServer. | ||
* | ||
* @return the list of GerritServer. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Did you mean to go in and add a single additional space to all of these? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nope, see my comment above. |
||
*/ | ||
@SuppressWarnings("unused") //Called from Jelly | ||
public List<GerritServer> getServers() { | ||
PluginImpl plugin = PluginImpl.getInstance(); | ||
|
@@ -184,10 +197,11 @@ public List<GerritServer> getServers() { | |
} | ||
|
||
/** | ||
* Used when redirected to a server. | ||
* @param encodedServerName the server name encoded by URLEncoder.encode(name,"UTF-8"). | ||
* @return the GerritServer object. | ||
*/ | ||
* Used when redirected to a server. | ||
* | ||
* @param encodedServerName the server name encoded by URLEncoder.encode(name,"UTF-8"). | ||
* @return the GerritServer object. | ||
*/ | ||
@SuppressWarnings("unused") //Called from Jelly | ||
public GerritServer getServer(String encodedServerName) { | ||
String serverName; | ||
|
@@ -242,8 +256,8 @@ public JSONObject getServerStatuses() { | |
* | ||
* @param req the StaplerRequest | ||
* @param rsp the StaplerResponse | ||
* @throws IOException when error sending redirect back to the list of servers | ||
* @return the new GerritServer | ||
* @throws IOException when error sending redirect back to the list of servers | ||
*/ | ||
public GerritServer doAddNewServer(StaplerRequest req, StaplerResponse rsp) throws IOException { | ||
String serverName = req.getParameter("name"); | ||
|
@@ -281,7 +295,11 @@ public GerritServer doAddNewServer(StaplerRequest req, StaplerResponse rsp) thro | |
|
||
@Override | ||
public Object getTarget() { | ||
Hudson.getInstance().checkPermission(Jenkins.ADMINISTER); | ||
Jenkins jenkins = Jenkins.getInstance(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why did we switch from Hudson instance to Jenkins here? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Inherital sin |
||
if (jenkins == null) { | ||
throw new IllegalStateException("Jenkins is not alive."); | ||
} | ||
jenkins.checkPermission(Jenkins.ADMINISTER); | ||
return this; | ||
} | ||
|
||
|
@@ -292,6 +310,7 @@ public void save() throws IOException { | |
|
||
/** | ||
* Returns this singleton. | ||
* | ||
* @return the single loaded instance if this class. | ||
*/ | ||
public static GerritManagement get() { | ||
|
@@ -381,13 +400,13 @@ public FormValidation doNameFreeCheck(@QueryParameter("value") final String valu | |
* | ||
* @param req StaplerRequest | ||
* @param rsp StaplerResponse | ||
* @throws ServletException if something unfortunate happens. | ||
* @throws IOException if something unfortunate happens. | ||
* @throws ServletException if something unfortunate happens. | ||
* @throws IOException if something unfortunate happens. | ||
* @throws InterruptedException if something unfortunate happens. | ||
*/ | ||
public void doConfigSubmit(StaplerRequest req, StaplerResponse rsp) throws ServletException, | ||
IOException, | ||
InterruptedException { | ||
IOException, | ||
InterruptedException { | ||
if (logger.isDebugEnabled()) { | ||
logger.debug("submit {}", req.toString()); | ||
} | ||
|
@@ -402,4 +421,5 @@ public void doConfigSubmit(StaplerRequest req, StaplerResponse rsp) throws Servl | |
|
||
rsp.sendRedirect("."); | ||
} | ||
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
/* | ||
* The MIT License (MIT) | ||
* | ||
* Copyright (c) 2016 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 com.sonyericsson.hudson.plugins.gerrit.trigger; | ||
|
||
import com.sonymobile.tools.gerrit.gerritevents.GerritEventListener; | ||
|
||
/** | ||
* A {@link GerritEventListener} that can provide a display name. | ||
* Nice to have when displaying this on {@link com.sonyericsson.hudson.plugins.gerrit.trigger.diagnostics.Diagnostics}. | ||
* | ||
* @author Robert Sandell <rsandell@cloudbees.com>. | ||
*/ | ||
public interface NamedGerritEventListener extends GerritEventListener { | ||
|
||
/** | ||
* A possible more descriptive display name than the class name. | ||
* | ||
* @return the name | ||
*/ | ||
String getDisplayName(); //TODO Replace with a default method in GerritEventListener when moving to Java 8 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this allowed/intended to return null? This one would be very helpful to add the appropriate Findbugs annotation to. |
||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Darn! I never asked for these to be changed. must have been a slip when I optimized the imports.