Skip to content

Commit

Permalink
Lift constraint on icons to enable sources other than ionicons-api-pl…
Browse files Browse the repository at this point in the history
…ugin
  • Loading branch information
strangelookingnerd committed May 10, 2024
1 parent 4c8283f commit 6462329
Show file tree
Hide file tree
Showing 10 changed files with 57 additions and 82 deletions.
27 changes: 14 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,7 @@ addBadge(icon: <icon>, text: <text>)
* id: (optional) Badge identifier. Selectively delete badges by id.
* link: (optional) The link to be added to this badge
*/
addBadge(icon: <icon>, text: <text>, color: <color>,
id: <id>, link: <link>)
addBadge(icon: <icon>, text: <text>, color: <color>, id: <id>, link: <link>)
// addInfoBadge
Expand Down Expand Up @@ -207,9 +206,7 @@ addShortText(text: <text>)
* color: (optional) The color for this short text
* link: (optional) The link for this short text
*/
addShortText(text: <text>, background: <background>,
border: <border>, borderColor: <borderColor>,
color: <color>, link: <link>)
addShortText(text: <text>, background: <background>, border: <border>, borderColor: <borderColor>, color: <color>, link: <link>)
```

Expand Down Expand Up @@ -279,10 +276,14 @@ removeSummaries(id: <id>)

## Icons

Icons can reference [Jenkins Symbols](https://weekly.ci.jenkins.io/design-library/Symbols/), including all the [symbols provided by the ionicons-api-plugin](https://ionic.io/ionicons).
Icons can reference [Jenkins Symbols](https://weekly.ci.jenkins.io/design-library/Symbols/), including all the symbols provided by the [ionicons-api-plugin](https://plugins.jenkins.io/ionicons-api).

More symbols can be referenced by installing additional plugins, such as [font-awesome-api-plugin](https://plugins.jenkins.io/font-awesome-api) or [custom-folder-icon-plugin](https://plugins.jenkins.io/custom-folder-icon).

```groovy
addBadge(icon: 'symbol-star', text: 'a starred build')
addBadge(icon: 'symbol-cube', text: 'a cubed build')
addBadge(icon: 'symbol-star plugin-ionicons-api', text: 'a starred build')
addBadge(icon: 'symbol-symbolName plugin-yourArtifactId', text: 'another icon build')
```

In addition to the default [16x16](https://github.com/jenkinsci/jenkins/tree/master/war/src/main/webapp/images/16x16) icons offered by Jenkins, badge plugin provides the following icons:
Expand Down Expand Up @@ -317,14 +318,14 @@ Colors may reference [Jenkins palette colors or variables](https://weekly.ci.jen
`symbol` badges **must** reference a named color from the Jenkins palette.
```groovy
// jenkins palette colors
addBadge(icon: 'symbol-star', text: 'A star', color: 'yellow')
addBadge(icon: 'symbol-star', text: 'A star', color: 'dark-yellow')
addBadge(icon: 'symbol-star', text: 'A star', color: 'jenkins-!-color-yellow')
addBadge(icon: 'symbol-star plugin-ionicons-api', text: 'A star', color: 'yellow')
addBadge(icon: 'symbol-star plugin-ionicons-api', text: 'A star', color: 'dark-yellow')
addBadge(icon: 'symbol-star plugin-ionicons-api', text: 'A star', color: 'jenkins-!-color-yellow')
// jenkins semantic colors
addBadge(icon: 'symbol-star', text: 'A star', color: 'warning')
addBadge(icon: 'symbol-star', text: 'A star', color: 'success')
addBadge(icon: 'symbol-star', text: 'A star', color: 'jenkins-!-warning-color')
addBadge(icon: 'symbol-star plugin-ionicons-api', text: 'A star', color: 'warning')
addBadge(icon: 'symbol-star plugin-ionicons-api', text: 'A star', color: 'success')
addBadge(icon: 'symbol-star plugin-ionicons-api', text: 'A star', color: 'jenkins-!-warning-color')
```

Short text badges may use additional css color styles.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,21 +54,6 @@ static boolean isJenkinsSymbolRef(@Nullable String icon) {
return icon != null && icon.startsWith("symbol-");

Check warning on line 54 in src/main/java/com/jenkinsci/plugins/badge/action/AbstractAction.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Partially covered line

Line 54 is only partially covered, one branch is missing
}

/**
* If the given icon reference is a Jenkins symbol append the ionicons plugin class to the icon reference
* if not already included.
* @param icon icon reference
* @return icon reference with ionicons plugin class
*/
@CheckForNull
static String getJenkinsSymbolIconPath(@Nullable String icon) {
if (isJenkinsSymbolRef(icon) && !icon.contains("plugin-ionicons-api")) {
return icon + " plugin-ionicons-api";
}

return icon;
}

/**
* Get the Jenkins color class for the given color reference. Returns {@code null} if the color is not a
* known Jenkins palette color or semantic color.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import com.jenkinsci.plugins.badge.BadgePlugin;
import hudson.PluginWrapper;
import hudson.model.Hudson;
import io.jenkins.plugins.ionicons.Ionicons;
import jenkins.model.Jenkins;
import org.kohsuke.stapler.Stapler;
import org.kohsuke.stapler.StaplerRequest;
Expand Down Expand Up @@ -99,23 +100,23 @@ public static BadgeAction createInfoBadge(String text) throws IllegalArgumentExc
}

public static BadgeAction createInfoBadge(String text, String link) throws IllegalArgumentException {
return createBadge("symbol-information-circle", "jenkins-!-color-blue", text, link);
return createBadge(Ionicons.getIconClassName("information-circle"), "jenkins-!-color-blue", text, link);
}

public static BadgeAction createWarningBadge(String text) throws IllegalArgumentException {
return createWarningBadge(text, null);
}

public static BadgeAction createWarningBadge(String text, String link) throws IllegalArgumentException {
return createBadge("symbol-warning", "jenkins-!-warning-color", text, link);
return createBadge(Ionicons.getIconClassName("warning"), "jenkins-!-warning-color", text, link);
}

public static BadgeAction createErrorBadge(String text) throws IllegalArgumentException {
return createErrorBadge(text, null);
}

public static BadgeAction createErrorBadge(String text, String link) throws IllegalArgumentException {
return createBadge("symbol-remove-circle", "jenkins-!-error-color", text, link);
return createBadge(Ionicons.getIconClassName("remove-circle"), "jenkins-!-error-color", text, link);
}

protected void validate() throws IllegalArgumentException {
Expand Down Expand Up @@ -251,7 +252,7 @@ public static String getIconPath(String icon) {
}

if (isJenkinsSymbolRef(icon)) {
return getJenkinsSymbolIconPath(icon);
return icon;
}

Jenkins jenkins = Jenkins.getInstanceOrNull();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
import org.kohsuke.stapler.export.ExportedBean;

import java.io.IOException;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;

Expand Down Expand Up @@ -62,10 +61,6 @@ public String getIconFileName() {

@Exported
public String getIconPath() {
if (isJenkinsSymbolRef(this.iconPath)) {
return getJenkinsSymbolIconPath(iconPath);
}

return iconPath;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,18 @@
The plugin supports colors from the <a href="https://weekly.ci.jenkins.io/design-library/Colors/">Jenkins palette colors</a>.
For example, the following are all valid references to the Jenkins palette colors:
<ul>
<li><code>addBadge icon: 'symbol-star', text: 'A star', color: 'yellow'</code></li>
<li><code>addBadge icon: 'symbol-star', text: 'A star', color: 'dark-yellow'</code></li>
<li><code>addBadge icon: 'symbol-star', text: 'A star', color: 'jenkins-!-color-yellow'</code></li>
<li><code>addBadge icon: 'symbol-star plugin-ionicons-api', text: 'A star', color: 'yellow'</code></li>
<li><code>addBadge icon: 'symbol-star plugin-ionicons-api', text: 'A star', color: 'dark-yellow'</code></li>
<li><code>addBadge icon: 'symbol-star plugin-ionicons-api', text: 'A star', color: 'jenkins-!-color-yellow'</code></li>
</ul>
</p>

<p>
The plugin supports colors from the <a href="https://weekly.ci.jenkins.io/design-library/Colors/">Jenkins semantic colors</a>.
For example, the following are all valid references to the Jenkins semantic colors:
<ul>
<li><code>addBadge(icon: 'symbol-star', text: 'A star', color: 'warning')</code></li>
<li><code>addBadge(icon: 'symbol-star', text: 'A star', color: 'success')</code></li>
<li><code>addBadge(icon: 'symbol-star plugin-ionicons-api', text: 'A star', color: 'warning')</code></li>
<li><code>addBadge(icon: 'symbol-star plugin-ionicons-api', text: 'A star', color: 'success')</code></li>
</ul>
</p>

Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
<div>
<p>
The plugin supports symbols from the <a href="https://ionic.io/ionicons">ionicons library</a> through the <a href="https://plugins.jenkins.io/ionicons-api/">ionicons-api plugin</a>.
Symbols from the <a href="https://ionic.io/ionicons">ionicons library</a> are referenced as "symbol-<i>ionicon-name</i>".
The plugin supports symbols from the <a href="https://ionic.io/ionicons">ionicons library</a> through the <a href="https://plugins.jenkins.io/ionicons-api/">ionicons-api-plugin</a>.
More symbols can be added by installing additional plugins, such as <a href="https://plugins.jenkins.io/font-awesome-api">font-awesome-api-plugin</a> or <a href="https://plugins.jenkins.io/custom-folder-icon">custom-folder-icon-plugin</a>.
Symbols are referenced as "symbol-<i>icon-name</i> plugin-<i>plugin-name</i>".
For example, the following are all valid references to symbols from the ionicons library:
<ul>
<li><code>addBadge icon: 'symbol-alert-circle-outline', text: 'This is an alert symbol'</code></li>
<li><code>addBadge icon: 'symbol-bar-chart-filled', text: 'This is a bar chart symbol'</code></li>
<li><code>addBadge icon: 'symbol-battery-half-sharp', text: 'This is a half filled battery symbol'</code></li>
<li><code>addBadge icon: 'symbol-flag-outline', text: 'This is a flag symbol'</code></li>
<li><code>addBadge icon: 'symbol-mic', text: 'This is a microphone symbol'</code></li>
<li><code>addBadge icon: 'symbol-rocket-filled, text: 'This is a rocket'</code></li>
<li><code>addBadge icon: 'symbol-unlink-sharp, text: 'This is an unlink symbol'</code></li>
<li><code>addBadge icon: 'symbol-alert-circle-outline plugin-ionicons-api', text: 'This is an alert symbol'</code></li>
<li><code>addBadge icon: 'symbol-bar-chart-filled plugin-ionicons-api', text: 'This is a bar chart symbol'</code></li>
<li><code>addBadge icon: 'symbol-battery-half-sharp plugin-ionicons-api', text: 'This is a half filled battery symbol'</code></li>
<li><code>addBadge icon: 'symbol-flag-outline plugin-ionicons-api', text: 'This is a flag symbol'</code></li>
<li><code>addBadge icon: 'symbol-mic plugin-ionicons-api', text: 'This is a microphone symbol'</code></li>
<li><code>addBadge icon: 'symbol-rocket-filled plugin-ionicons-api', text: 'This is a rocket'</code></li>
<li><code>addBadge icon: 'symbol-unlink-sharp plugin-ionicons-api', text: 'This is an unlink symbol'</code></li>
</ul>
</p>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,18 @@
</p>

<p>
The plugin supports symbols from the <a href="https://ionic.io/ionicons">ionicons library</a> through the <a href="https://plugins.jenkins.io/ionicons-api/">ionicons-api plugin</a>.
Symbols from the <a href="https://ionic.io/ionicons">ionicons library</a> are referenced as "symbol-<i>ionicon-name</i>".
The plugin supports symbols from the <a href="https://ionic.io/ionicons">ionicons library</a> through the <a href="https://plugins.jenkins.io/ionicons-api/">ionicons-api-plugin</a>.
More symbols can be added by installing additional plugins, such as <a href="https://plugins.jenkins.io/font-awesome-api">font-awesome-api-plugin</a> or <a href="https://plugins.jenkins.io/custom-folder-icon">custom-folder-icon-plugin</a>.
Symbols are referenced as "symbol-<i>icon-name</i> plugin-<i>plugin-name</i>".
For example, the following are all valid references to symbols from the ionicons library:
<ul>
<li><code>addBadge icon: 'symbol-alert-circle-outline', text: 'This is an alert symbol'</code></li>
<li><code>addBadge icon: 'symbol-bar-chart-filled', text: 'This is a bar chart symbol'</code></li>
<li><code>addBadge icon: 'symbol-battery-half-sharp', text: 'This is a half filled battery symbol'</code></li>
<li><code>addBadge icon: 'symbol-flag-outline', text: 'This is a flag symbol'</code></li>
<li><code>addBadge icon: 'symbol-mic', text: 'This is a microphone symbol'</code></li>
<li><code>addBadge icon: 'symbol-rocket-filled, text: 'This is a rocket'</code></li>
<li><code>addBadge icon: 'symbol-unlink-sharp, text: 'This is an unlink symbol'</code></li>
<li><code>addBadge icon: 'symbol-alert-circle-outline plugin-ionicons-api', text: 'This is an alert symbol'</code></li>
<li><code>addBadge icon: 'symbol-bar-chart-filled plugin-ionicons-api', text: 'This is a bar chart symbol'</code></li>
<li><code>addBadge icon: 'symbol-battery-half-sharp plugin-ionicons-api', text: 'This is a half filled battery symbol'</code></li>
<li><code>addBadge icon: 'symbol-flag-outline plugin-ionicons-api', text: 'This is a flag symbol'</code></li>
<li><code>addBadge icon: 'symbol-mic plugin-ionicons-api', text: 'This is a microphone symbol'</code></li>
<li><code>addBadge icon: 'symbol-rocket-filled plugin-ionicons-api', text: 'This is a rocket'</code></li>
<li><code>addBadge icon: 'symbol-unlink-sharp plugin-ionicons-api', text: 'This is an unlink symbol'</code></li>
</ul>
</p>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,22 +8,10 @@ class AbstractActionTest {

@Test
void isJenkinsSymbolRef() {
assertTrue(AbstractAction.isJenkinsSymbolRef("symbol-information-circle-outline"));
assertTrue(AbstractAction.isJenkinsSymbolRef("symbol-cube"));
assertFalse(AbstractAction.isJenkinsSymbolRef("info.gif"));
}

@Test
void getJenkinsSymbolIconPath() {
assertNull(AbstractAction.getJenkinsSymbolIconPath(null));
assertEquals(
AbstractAction.getJenkinsSymbolIconPath("symbol-information-circle-outline"),
"symbol-information-circle-outline plugin-ionicons-api");
assertEquals(
AbstractAction.getJenkinsSymbolIconPath("symbol-information-circle-outline plugin-ionicons-api"),
"symbol-information-circle-outline plugin-ionicons-api");
assertEquals(AbstractAction.getJenkinsSymbolIconPath("info.gif"), "info.gif");
}

@Test
void getJenkinsColorClass() {
assertNull(AbstractAction.getJenkinsColorClass(null));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ public void getIconPath() {

assertEquals(Hudson.RESOURCE_PATH + "/images/16x16/http.png", BadgeAction.getIconPath("http.png"));

assertEquals("symbol-information-circle-outline plugin-ionicons-api", BadgeAction.getIconPath("symbol-information-circle-outline"));
assertEquals("symbol-information-circle-outline plugin-ionicons-api", BadgeAction.getIconPath("symbol-information-circle-outline plugin-ionicons-api"));
}

Expand Down
20 changes: 12 additions & 8 deletions src/test/resources/readme/README.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -101,10 +101,14 @@ Removes summaries

## Icons

Icons can reference [Jenkins Symbols](https://weekly.ci.jenkins.io/design-library/Symbols/), including all the [symbols provided by the ionicons-api-plugin](https://ionic.io/ionicons).
Icons can reference [Jenkins Symbols](https://weekly.ci.jenkins.io/design-library/Symbols/), including all the symbols provided by the [ionicons-api-plugin](https://plugins.jenkins.io/ionicons-api).

More symbols can be referenced by installing additional plugins, such as [font-awesome-api-plugin](https://plugins.jenkins.io/font-awesome-api) or [custom-folder-icon-plugin](https://plugins.jenkins.io/custom-folder-icon).

```groovy
addBadge(icon: 'symbol-star', text: 'a starred build')
addBadge(icon: 'symbol-cube', text: 'a cubed build')
addBadge(icon: 'symbol-star plugin-ionicons-api', text: 'a starred build')
addBadge(icon: 'symbol-symbolName plugin-yourArtifactId', text: 'another icon build')
```

In addition to the default [16x16](https://github.com/jenkinsci/jenkins/tree/master/war/src/main/webapp/images/16x16) icons offered by Jenkins, badge plugin provides the following icons:
Expand All @@ -126,14 +130,14 @@ Colors may reference [Jenkins palette colors or variables](https://weekly.ci.jen
`symbol` badges **must** reference a named color from the Jenkins palette.
```groovy
// jenkins palette colors
addBadge(icon: 'symbol-star', text: 'A star', color: 'yellow')
addBadge(icon: 'symbol-star', text: 'A star', color: 'dark-yellow')
addBadge(icon: 'symbol-star', text: 'A star', color: 'jenkins-!-color-yellow')
addBadge(icon: 'symbol-star plugin-ionicons-api', text: 'A star', color: 'yellow')
addBadge(icon: 'symbol-star plugin-ionicons-api', text: 'A star', color: 'dark-yellow')
addBadge(icon: 'symbol-star plugin-ionicons-api', text: 'A star', color: 'jenkins-!-color-yellow')

// jenkins semantic colors
addBadge(icon: 'symbol-star', text: 'A star', color: 'warning')
addBadge(icon: 'symbol-star', text: 'A star', color: 'success')
addBadge(icon: 'symbol-star', text: 'A star', color: 'jenkins-!-warning-color')
addBadge(icon: 'symbol-star plugin-ionicons-api', text: 'A star', color: 'warning')
addBadge(icon: 'symbol-star plugin-ionicons-api', text: 'A star', color: 'success')
addBadge(icon: 'symbol-star plugin-ionicons-api', text: 'A star', color: 'jenkins-!-warning-color')
```

Short text badges may use additional css color styles.
Expand Down

0 comments on commit 6462329

Please sign in to comment.