Skip to content

Commit

Permalink
Working build
Browse files Browse the repository at this point in the history
  • Loading branch information
janfaracik committed Jan 15, 2022
1 parent 586c22a commit 88b61aa
Show file tree
Hide file tree
Showing 34 changed files with 119 additions and 124 deletions.
3 changes: 1 addition & 2 deletions core/src/main/java/hudson/AboutJenkins.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import java.net.URL;
import jenkins.model.Jenkins;
import org.jenkins.ui.icon.Icon;
import org.jenkins.ui.icon.IconSet;
import org.jenkinsci.Symbol;
import org.kohsuke.accmod.Restricted;
import org.kohsuke.accmod.restrictions.NoExternalUse;
Expand All @@ -20,7 +19,7 @@
public class AboutJenkins extends ManagementLink {
@Override
public Icon getIcon() {
return Icon.fromSvg(IconSet.getScalableIcon("help-circle-outline", null));
return Icon.fromSymbol("help-circle-outline");
}

@Override
Expand Down
6 changes: 6 additions & 0 deletions core/src/main/java/hudson/Functions.java
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,7 @@
import org.apache.commons.jexl.parser.ASTSizeFunction;
import org.apache.commons.jexl.util.Introspector;
import org.apache.commons.lang.StringUtils;
import org.jenkins.ui.icon.Icon;
import org.jenkins.ui.icon.IconSet;
import org.jvnet.tiger_types.Types;
import org.kohsuke.accmod.Restricted;
Expand Down Expand Up @@ -2289,4 +2290,9 @@ public static boolean isContextMenuVisible(Action a) {
return true;
}
}

@Restricted(NoExternalUse.class) // for actions.jelly and ContextMenu.add
public static boolean isIcon(Object o) {
return o instanceof Icon;
}
}
3 changes: 1 addition & 2 deletions core/src/main/java/hudson/model/ManageJenkinsAction.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
import hudson.Extension;
import jenkins.model.Jenkins;
import org.jenkins.ui.icon.Icon;
import org.jenkins.ui.icon.IconSet;
import org.jenkinsci.Symbol;

/**
Expand All @@ -40,7 +39,7 @@ public class ManageJenkinsAction implements RootAction {
@Override
public Icon getIcon() {
if (Jenkins.get().hasAnyPermission(Jenkins.MANAGE, Jenkins.SYSTEM_READ))
return Icon.fromSvg(IconSet.getScalableIcon("settings-outline", null));
return Icon.fromSymbol("settings-outline");
else
return null;
}
Expand Down
3 changes: 1 addition & 2 deletions core/src/main/java/jenkins/management/ConfigureLink.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
import hudson.security.Permission;
import jenkins.model.Jenkins;
import org.jenkins.ui.icon.Icon;
import org.jenkins.ui.icon.IconSet;
import org.jenkinsci.Symbol;

/**
Expand All @@ -40,7 +39,7 @@
public class ConfigureLink extends ManagementLink {
@Override
public Icon getIcon() {
return Icon.fromSvg(IconSet.getScalableIcon("settings-outline", null));
return Icon.fromSymbol("settings-outline");
}

@Override
Expand Down
1 change: 1 addition & 0 deletions core/src/main/java/jenkins/model/Jenkins.java
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,7 @@
import org.apache.commons.jelly.JellyException;
import org.apache.commons.jelly.Script;
import org.apache.commons.logging.LogFactory;
import org.jenkins.ui.icon.Icon;
import org.jvnet.hudson.reactor.Executable;
import org.jvnet.hudson.reactor.Milestone;
import org.jvnet.hudson.reactor.Reactor;
Expand Down
31 changes: 17 additions & 14 deletions core/src/main/java/org/jenkins/ui/icon/Icon.java
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,8 @@ public class Icon {
private final String normalizedSelector;
private final String url;
private final String style;
private String xml;
private String bitmap;
private String symbol;
private IconType iconType;
private IconFormat iconFormat;

Expand Down Expand Up @@ -136,19 +137,17 @@ public Icon(String classSpec, String url, String style, IconType iconType, IconF
this.iconFormat = iconFormat;
}

/**
* @param xml The XML of the SVG image you want to use
* You can use icon sources such as Ionicon eg
* 'Icon.fromSvg(IconSet.getIonicon("terminal-outline", null))' to get SVG data
* @return an Icon object with the svg field set
*/
public static Icon fromSvg(String xml) {
if (xml == null) {
return null;
}
// TODO
public static Icon fromBitmap(String bitmap) {
Icon icon = new Icon("", "", "", IconFormat.EXTERNAL_SVG_SPRITE);
icon.bitmap = bitmap;
return icon;
}

// TODO
public static Icon fromSymbol(String symbol) {
Icon icon = new Icon("", "", "", IconFormat.EXTERNAL_SVG_SPRITE);
icon.xml = xml;
icon.symbol = symbol;
return icon;
}

Expand Down Expand Up @@ -228,8 +227,12 @@ public String getStyle() {
return style;
}

public String getXml() {
return xml;
public String getBitmap() {
return bitmap;
}

public String getSymbol() {
return symbol;
}

/**
Expand Down
36 changes: 20 additions & 16 deletions core/src/main/java/org/jenkins/ui/icon/IconSet.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@
import org.apache.commons.io.IOUtils;
import org.apache.commons.jelly.JellyContext;
import org.apache.commons.lang.StringUtils;
import org.kohsuke.accmod.Restricted;
import org.kohsuke.accmod.restrictions.NoExternalUse;

/**
* An icon set.
Expand All @@ -45,7 +47,7 @@ public class IconSet {


public static final IconSet icons = new IconSet();
private static final Map<String, String> SCALABLE_ICONS = new ConcurrentHashMap<>();
private static final Map<String, String> SYMBOLS = new ConcurrentHashMap<>();

private Map<String, Icon> iconsByCSSSelector = new ConcurrentHashMap<>();
private Map<String, Icon> iconsByUrl = new ConcurrentHashMap<>();
Expand Down Expand Up @@ -73,34 +75,36 @@ private static String prependTitleIfRequired(String icon, String title) {
return icon;
}

public static String getScalableIcon(String name, String title) {
if (SCALABLE_ICONS.containsKey(name)) {
String icon = SCALABLE_ICONS.get(name);
return prependTitleIfRequired(icon, title);
// for Jelly
@Restricted(NoExternalUse.class)
public static String getSymbol(String name, String title) {
if (SYMBOLS.containsKey(name)) {
String symbol = SYMBOLS.get(name);
return prependTitleIfRequired(symbol, title);
}

// Load icon if it exists
InputStream inputStream = IconSet.class.getResourceAsStream("/images/scalable/" + name + ".svg");
String scalableIcon = null;
// Load symbol if it exists
InputStream inputStream = IconSet.class.getResourceAsStream("/images/symbols/" + name + ".svg");
String symbol = null;

try {
if (inputStream != null) {
scalableIcon = IOUtils.toString(inputStream, StandardCharsets.UTF_8);
symbol = IOUtils.toString(inputStream, StandardCharsets.UTF_8);
}
} catch (IOException e) {
// ignored
}
if (scalableIcon == null) {
scalableIcon = PLACEHOLDER_SVG;
if (symbol == null) {
symbol = PLACEHOLDER_SVG;
}

scalableIcon = scalableIcon.replaceAll("(<title>)[^&]*(</title>)", "$1$2");
scalableIcon = scalableIcon.replaceAll("<svg", "<svg aria-hidden=\"true\"");
scalableIcon = scalableIcon.replace("stroke:#000", "stroke:currentColor");
symbol = symbol.replaceAll("(<title>)[^&]*(</title>)", "$1$2");
symbol = symbol.replaceAll("<svg", "<svg aria-hidden=\"true\"");
symbol = symbol.replace("stroke:#000", "stroke:currentColor");

SCALABLE_ICONS.put(name, scalableIcon);
SYMBOLS.put(name, symbol);

return prependTitleIfRequired(scalableIcon, title);
return prependTitleIfRequired(symbol, title);
}

public IconSet addIcon(Icon icon) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ THE SOFTWARE.
<l:task href=".." icon="icon-up icon-md" title="${%Back to Loggers}"/>
<l:task href="." icon="icon-notepad icon-md" title="${%Log records}"/>
<l:isAdmin>
<l:task href="configure" scalableIcon="settings-outline" title="${%Configure}"/>
<l:task href="configure" icon="settings-outline" title="${%Configure}"/>
<l:task href="delete" icon="icon-edit-delete icon-md" title="${%Delete}"/>
</l:isAdmin>
</l:tasks>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,14 @@ THE SOFTWARE.
<l:side-panel>
<l:tasks>
<l:task href="${rootURL}/" icon="icon-up icon-md" title="${%Back to Dashboard}"/>
<l:task href="${rootURL}/manage" scalableIcon="settings-outline" title="${%Manage Jenkins}"/>
<l:task href="${rootURL}/manage" icon="settings-outline" title="${%Manage Jenkins}"/>
<l:task href="." icon="icon-clipboard icon-md" title="${%Log Recorders}">
<l:isAdmin>
<l:task href="new" icon="icon-new-package icon-md" title="${%New Log Recorder}"/>
</l:isAdmin>
</l:task>
<l:task href="all" icon="icon-notepad icon-md" title="${%All Log Messages}"/>
<l:task href="levels" scalableIcon="settings-outline" title="${%Log Levels}"/>
<l:task href="levels" icon="settings-outline" title="${%Log Levels}"/>
</l:tasks>
</l:side-panel>
</j:jelly>
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,5 @@ THE SOFTWARE.
<l:task contextMenu="false" href="${buildUrl.baseUrl}/" icon="icon-search icon-md" title="${%Status}"/>
<l:task href="${buildUrl.baseUrl}/changes" icon="icon-notepad icon-md" title="${%Changes}"/>
<p:console-link/>
<l:task href="${buildUrl.baseUrl}/configure" scalableIcon="settings-outline" title="${h.hasPermission(it,it.UPDATE)?'%Edit Build Information':'%View Build Information'}"/>
<l:task href="${buildUrl.baseUrl}/configure" icon="settings-outline" title="${h.hasPermission(it,it.UPDATE)?'%Edit Build Information':'%View Build Information'}"/>
</j:jelly>
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,11 @@ THE SOFTWARE.
<j:getStatic var="createPermission" className="hudson.model.Computer" field="CREATE"/>
<l:tasks>
<l:task href="${rootURL}/" icon="icon-up icon-md" title="${%Back to Dashboard}"/>
<l:task href="${rootURL}/manage" scalableIcon="settings-outline" permissions="${app.MANAGE_AND_SYSTEM_READ}" title="${%Manage Jenkins}"/>
<l:task href="${rootURL}/manage" icon="settings-outline" permissions="${app.MANAGE_AND_SYSTEM_READ}" title="${%Manage Jenkins}"/>
<l:task href="new" icon="icon-new-computer icon-md" permission="${createPermission}" title="${%New Node}"/>
<l:task href="${rootURL}/configureClouds" icon="icon-health-40to59 icon-md" permission="${app.SYSTEM_READ}"
title="${app.hasPermission(app.ADMINISTER) ? '%Configure Clouds' : '%View Clouds'}"/>
<l:task href="configure" scalableIcon="settings-outline" permissions="${app.MANAGE_AND_SYSTEM_READ}" title="${%Node Monitoring}"/>
<l:task href="configure" icon="settings-outline" permissions="${app.MANAGE_AND_SYSTEM_READ}" title="${%Node Monitoring}"/>
</l:tasks>
<t:queue items="${app.queue.items}" />
<t:executors />
Expand Down
2 changes: 1 addition & 1 deletion core/src/main/resources/hudson/model/Label/sidepanel.jelly
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ THE SOFTWARE.
<l:task contextMenu="false" href="${rootURL}/" icon="icon-up icon-md" title="${%Back to Dashboard}"/>
<l:task contextMenu="false" href="${url}" icon="icon-attribute icon-md" title="${%Overview}"/>
<j:if test="${it.atom}">
<l:task href="${url}/configure" scalableIcon="settings-outline" title="${%Configure}" permission="${app.ADMINISTER}" />
<l:task href="${url}/configure" icon="settings-outline" title="${%Configure}" permission="${app.ADMINISTER}" />
</j:if>
<l:task href="${url}/load-statistics" icon="icon-monitor icon-md" title="${%Load Statistics}"/>
<st:include page="actions.jelly" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ THE SOFTWARE.
<l:side-panel>
<l:tasks>
<l:task href="${rootURL}/" icon="icon-up icon-md" title="${%Back to Dashboard}"/>
<l:task href="${rootURL}/manage" scalableIcon="settings-outline" title="${%Manage Jenkins}"/>
<l:task href="${rootURL}/manage" icon="settings-outline" title="${%Manage Jenkins}"/>
<l:task href="${rootURL}/pluginManager/" icon="icon-plugin icon-lg" title="${%Manage Plugins}"/>
</l:tasks>
</l:side-panel>
Expand Down
2 changes: 1 addition & 1 deletion core/src/main/resources/hudson/model/User/sidepanel.jelly
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ THE SOFTWARE.
<l:task contextMenu="false" href="${rootURL}/asynchPeople/" icon="icon-up icon-md" title="${%People}"/>
<l:task contextMenu="false" href="${rootURL}/${it.url}/" icon="icon-search icon-md" title="${%Status}"/>
<l:task href="${rootURL}/${it.url}/builds" icon="icon-notepad icon-md" title="${%Builds}"/>
<l:task href="${rootURL}/${it.url}/configure" scalableIcon="settings-outline" permission="${app.ADMINISTER}" title="${%Configure}"/>
<l:task href="${rootURL}/${it.url}/configure" icon="settings-outline" permission="${app.ADMINISTER}" title="${%Configure}"/>
<t:actions actions="${it.propertyActions}"/>
<t:actions actions="${it.transientActions}"/>
<j:if test="${it.canDelete()}">
Expand Down
2 changes: 1 addition & 1 deletion core/src/main/resources/hudson/model/View/sidepanel.jelly
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ THE SOFTWARE.
<l:task href="${rootURL}/${it.viewUrl}builds" icon="icon-notepad icon-md" title="${%Build History}"/>
<j:if test="${it.isEditable()}">
<!-- /configure URL on Jenkins object is overloaded with Jenkins's system config, so always use the explicit name. -->
<l:task href="${rootURL}/${it.viewUrl}configure" scalableIcon="settings-outline" permission="${it.CONFIGURE}" title="${%Edit View}"/>
<l:task href="${rootURL}/${it.viewUrl}configure" icon="settings-outline" permission="${it.CONFIGURE}" title="${%Edit View}"/>
</j:if>
<j:if test="${it.owner.canDelete(it)}">
<l:task href="delete" icon="icon-edit-delete icon-md" permission="${it.DELETE}" title="${%Delete View}"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ THE SOFTWARE.
<l:side-panel>
<l:tasks>
<l:task href="${rootURL}/" icon="icon-up icon-md" title="${%Back to Dashboard}" />
<l:task href="${rootURL}/manage" scalableIcon="settings-outline" permission="${app.MANAGE}" title="${%Manage Jenkins}" />
<l:task href="${rootURL}/manage" icon="settings-outline" permission="${app.MANAGE}" title="${%Manage Jenkins}" />
<l:task href="." icon="icon-new-user icon-md" permission="${app.ADMINISTER}" title="${%Users}" />
<l:task href="addUser" icon="icon-new-user icon-md" permission="${app.ADMINISTER}" title="${%Create User}" />
</l:tasks>
Expand Down
21 changes: 5 additions & 16 deletions core/src/main/resources/jenkins/model/Jenkins/manage.jelly
Original file line number Diff line number Diff line change
Expand Up @@ -54,25 +54,14 @@ THE SOFTWARE.
${taskTags!=null and attrs.contextMenu!='false' ? taskTags.addHeader(category.key.label) : null}
<div class="jenkins-section__items">
<j:forEach var="m" items="${category.value}">
<j:set var="icon" value="${m.iconClassName != null ? m.iconClassName : m.icon}" />
<!-- <j:set var="iconMetadata" value="${icons.getIconByClassSpec(icon + ' icon-xlg')}"/>-->
<!-- <j:if test="${iconMetadata == null}">-->
<!-- &lt;!&ndash; Icon could be provided as a simple iconFileName e.g. "settings.png" &ndash;&gt;-->
<!-- <j:set var="iconMetadata" value="${icons.getIconByClassSpec(icons.toNormalizedIconNameClass(icon) + ' icon-xlg')}"/>-->
<!-- </j:if>-->
<!-- <j:if test="${iconMetadata == null}">-->
<!-- <j:set var="iconMetadata" value="${icons.getIconByUrl(icon)}"/>-->
<!-- </j:if>-->

<j:if test="${icon!=null}">
<j:if test="${m.icon != null}">
<div class="jenkins-section__item">
<j:set var="iconUrl" value="${icon.startsWith('/') ? resURL+icon : imagesURL + '/48x48/' + icon}" />
<j:set var="alt" value="${icon.replaceAll('\\d*\\.[^.]+$', '')}"/>
${taskTags!=null and attrs.contextMenu!='false' ? taskTags.add(m.urlName, iconUrl, m.displayName, m.requiresPOST, m.requiresConfirmation) : null}
${taskTags!=null and attrs.contextMenu!='false' ? taskTags.add(m.urlName, m.icon.url, m.displayName, m.requiresPOST, m.requiresConfirmation) : null}
<j:choose>
<j:when test="${m.requiresConfirmation}">
<l:confirmationLink href="${m.urlName}" post="${m.requiresPOST}" message="${%are.you.sure(m.displayName)}">
<l:icon src="${rootURL + '/images/' + icon.url}" svg="${icon.svg}" xml="${icon.xml}" class="icon" />
<l:icon src="${m.icon.url}" symbol="${m.icon.symbol}" class="icon" />
<dl>
<dt>${m.displayName}</dt>
<dd><j:out value="${m.description}"/></dd>
Expand All @@ -82,7 +71,7 @@ THE SOFTWARE.
</j:when>
<j:when test="${m.requiresPOST}">
<f:link href="${m.urlName}" post="${m.requiresPOST}">
<l:icon src="${rootURL + '/images/' + icon.url}" svg="${icon.svg}" xml="${icon.xml}" class="icon" />
<l:icon src="${m.icon.url}" symbol="${m.icon.symbol}" class="icon" />
<dl>
<dt>${m.displayName}</dt>
<dd><j:out value="${m.description}"/></dd>
Expand All @@ -92,7 +81,7 @@ THE SOFTWARE.
</j:when>
<j:otherwise>
<a href="${m.urlName}">
<l:icon src="${rootURL + '/images/' + icon.url}" svg="${icon.svg}" xml="${icon.xml}" class="icon" />
<l:icon src="${m.icon.url}" symbol="${m.icon.symbol}" class="icon" />
<dl>
<dt>${m.displayName}</dt>
<dd><j:out value="${m.description}"/></dd>
Expand Down
5 changes: 2 additions & 3 deletions core/src/main/resources/lib/hudson/actions.jelly
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,8 @@ THE SOFTWARE.
the action object itself is available in the 'action' variable
-->
<st:include page="action.jelly" from="${action}" optional="true">
<j:set var="icon" value="${action.iconClassName != null ? action.iconClassName + ' icon-md' : action.icon}"/>
<j:if test="${icon!=null}">
<l:task icon="${icon.url}" xml="${icon.xml}" title="${action.displayName}"
<j:if test="${action.icon != null}">
<l:task icon="${action.icon}" title="${action.displayName}"
href="${h.getActionUrl(it.url,action)}" contextMenu="${h.isContextMenuVisible(action)}"/>
</j:if>
</st:include>
Expand Down
4 changes: 2 additions & 2 deletions core/src/main/resources/lib/hudson/project/configurable.jelly
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,10 @@ THE SOFTWARE.
</j:if>
<j:choose>
<j:when test="${h.hasPermission(it,it.CONFIGURE)}">
<l:task href="${url}/configure" scalableIcon="settings-outline" title="${%Configure}"/>
<l:task href="${url}/configure" icon="settings-outline" title="${%Configure}"/>
</j:when>
<j:when test="${h.hasPermission(it,it.EXTENDED_READ)}">
<l:task href="${url}/configure" scalableIcon="settings-outline" title="${%View Configuration}"/>
<l:task href="${url}/configure" icon="settings-outline" title="${%View Configuration}"/>
</j:when>
</j:choose>
<l:task confirmationMessage="${%delete.confirm(it.pronoun, it.displayName)}" href="${url}/doDelete" icon="icon-edit-delete icon-md" permission="${it.DELETE}" post="true" requiresConfirmation="true" title="${%delete(it.pronoun)}"/>
Expand Down
Loading

0 comments on commit 88b61aa

Please sign in to comment.