Skip to content

Commit

Permalink
Reset files
Browse files Browse the repository at this point in the history
  • Loading branch information
janfaracik committed Apr 7, 2024
1 parent 143373f commit ca9ade7
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 25 deletions.
6 changes: 1 addition & 5 deletions core/src/main/java/hudson/model/ComputerSet.java
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@
import javax.servlet.ServletException;
import jenkins.model.Jenkins;
import jenkins.model.ModelObjectWithChildren;
import jenkins.model.ModelObjectWithContextMenu;
import jenkins.model.ModelObjectWithContextMenu.ContextMenu;
import jenkins.util.Timer;
import jenkins.widgets.HasWidgets;
Expand Down Expand Up @@ -116,10 +115,7 @@ public Computer[] get_all() {
public ContextMenu doChildrenContextMenu(StaplerRequest request, StaplerResponse response) throws Exception {
ContextMenu m = new ContextMenu();
for (Computer c : get_all()) {
m.add(new ModelObjectWithContextMenu.MenuItem()
.withDisplayName(c.getDisplayName())
.withIconClass(c.getIconClassName())
.withContextRelativeUrl(c.getUrl()));
m.add(c);
}
return m;
}
Expand Down
6 changes: 1 addition & 5 deletions core/src/main/java/hudson/model/Label.java
Original file line number Diff line number Diff line change
Expand Up @@ -551,11 +551,7 @@ public String toString() {
public ContextMenu doChildrenContextMenu(StaplerRequest request, StaplerResponse response) throws Exception {
ContextMenu menu = new ContextMenu();
for (Node node : getNodes()) {
Computer c = node.toComputer();
menu.add(new MenuItem()
.withDisplayName(node.getDisplayName())
.withStockIcon(c == null ? "computer.svg" : c.getIcon())
.withContextRelativeUrl(node.getSearchUrl()));
menu.add(node);
}
return menu;
}
Expand Down
9 changes: 2 additions & 7 deletions core/src/main/java/hudson/model/ManageJenkinsAction.java
Original file line number Diff line number Diff line change
Expand Up @@ -82,15 +82,10 @@ public ContextMenu doContextMenu(StaplerRequest request, StaplerResponse respons
public void addContextMenuItem(ContextMenu menu, String url, String icon, String iconXml, String text, boolean post, boolean requiresConfirmation, Badge badge, String message) {
if (Stapler.getCurrentRequest().findAncestorObject(this.getClass()) != null || !Util.isSafeToRedirectTo(url)) {
// Default behavior if the URL is absolute or scheme-relative, or the current object is an ancestor (i.e. would resolve correctly)
// menu.add(url, icon, iconXml, text, post, requiresConfirmation, badge, message);

menu.add(new MenuItem().withUrl(url).withIcon(icon).withIconXml(iconXml).withDisplayName(text));

menu.add(url, icon, iconXml, text, post, requiresConfirmation, badge, message);
return;
}

// If neither is the case, rewrite the relative URL to point to inside the /manage/ URL space
// menu.add("manage/" + url, icon, iconXml, text, post, requiresConfirmation, badge, message);
menu.add(new MenuItem().withUrl("manage/" + url).withIcon(icon).withIconXml(iconXml).withDisplayName(text));
menu.add("manage/" + url, icon, iconXml, text, post, requiresConfirmation, badge, message);
}
}
5 changes: 1 addition & 4 deletions core/src/main/java/jenkins/agents/CloudSet.java
Original file line number Diff line number Diff line change
Expand Up @@ -131,10 +131,7 @@ public String getCloudUpdateCenterCategoryLabel() {
@Override
public ModelObjectWithContextMenu.ContextMenu doChildrenContextMenu(StaplerRequest request, StaplerResponse response) throws Exception {
ModelObjectWithContextMenu.ContextMenu m = new ModelObjectWithContextMenu.ContextMenu();
Jenkins.get().clouds.stream().forEach(c -> m.add(new ModelObjectWithContextMenu.MenuItem()
.withDisplayName(c.getDisplayName())
.withIconClass(c.getIconClassName())
.withContextRelativeUrl(c.getUrl())));
Jenkins.get().clouds.stream().forEach(c -> m.add(c));
return m;
}

Expand Down
50 changes: 46 additions & 4 deletions core/src/main/java/jenkins/model/ModelObjectWithContextMenu.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,8 @@

import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
import hudson.Functions;
import hudson.model.Action;
import hudson.model.Actionable;
import hudson.model.Job;
import hudson.model.ModelObject;
import hudson.model.*;
import hudson.slaves.Cloud;
import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;
Expand Down Expand Up @@ -154,6 +152,50 @@ public ContextMenu add(MenuItem item) {
return this;
}

/**
* Adds a node
*
* @since 1.513
*/
public ContextMenu add(Node n) {
Computer c = n.toComputer();
return add(new MenuItem()
.withDisplayName(n.getDisplayName())
.withStockIcon(c == null ? "computer.svg" : c.getIcon())
.withContextRelativeUrl(n.getSearchUrl()));
}

/**
* Adds a computer
*
* @since 1.513
*/
public ContextMenu add(Computer c) {
return add(new MenuItem()
.withDisplayName(c.getDisplayName())
.withIconClass(c.getIconClassName())
.withContextRelativeUrl(c.getUrl()));
}

public ContextMenu add(Cloud c) {
return add(new MenuItem()
.withDisplayName(c.getDisplayName())
.withIconClass(c.getIconClassName())
.withContextRelativeUrl(c.getUrl()));
}

/**
* Adds a child item when rendering context menu of its parent.
*
* @since 1.513
*/
public ContextMenu add(Job job) {
return add(new MenuItem()
.withDisplayName(job.getDisplayName())
.withIcon(job.getIconColor().getImage())
.withUrl(job.getSearchUrl()));
}

// Used in Jelly! - task.jelly
public ContextMenu add(String url, String icon, String iconXml, String text, boolean post, boolean requiresConfirmation, Badge badge, String message) {
if (text != null && icon != null && url != null) {
Expand Down

0 comments on commit ca9ade7

Please sign in to comment.