From a0deb8f43317d7fe4629b3666d117f8361e94dc2 Mon Sep 17 00:00:00 2001 From: Mark Waite Date: Mon, 13 May 2024 16:16:36 -0600 Subject: [PATCH 1/4] Set height and width for icons that are not symbols Symbols do not require height or width but icons without height and width will render at their original size instead of rendering at 16x16. Fixes https://github.com/jenkinsci/badge-plugin/issues/148 --- .../badge/action/BadgeAction/badge.jelly | 23 +++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/src/main/resources/com/jenkinsci/plugins/badge/action/BadgeAction/badge.jelly b/src/main/resources/com/jenkinsci/plugins/badge/action/BadgeAction/badge.jelly index 872d6ee..1750d9b 100644 --- a/src/main/resources/com/jenkinsci/plugins/badge/action/BadgeAction/badge.jelly +++ b/src/main/resources/com/jenkinsci/plugins/badge/action/BadgeAction/badge.jelly @@ -32,13 +32,28 @@ THE SOFTWARE. - - + + + + + + + + + - - + + + + + + + + + + From 98bf7f4c912fc55047f92927b69c71d87f51fef5 Mon Sep 17 00:00:00 2001 From: Mark Waite Date: Tue, 14 May 2024 04:18:54 -0600 Subject: [PATCH 2/4] Simplify expression using startsWith, not indexOf --- .../jenkinsci/plugins/badge/action/BadgeAction/badge.jelly | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/resources/com/jenkinsci/plugins/badge/action/BadgeAction/badge.jelly b/src/main/resources/com/jenkinsci/plugins/badge/action/BadgeAction/badge.jelly index 1750d9b..d255653 100644 --- a/src/main/resources/com/jenkinsci/plugins/badge/action/BadgeAction/badge.jelly +++ b/src/main/resources/com/jenkinsci/plugins/badge/action/BadgeAction/badge.jelly @@ -33,7 +33,7 @@ THE SOFTWARE. - + @@ -44,7 +44,7 @@ THE SOFTWARE. - + From d3399eaf8c063f70e2fda2a7c7b02f7c60ff3f8f Mon Sep 17 00:00:00 2001 From: Mark Waite Date: Tue, 14 May 2024 06:38:52 -0600 Subject: [PATCH 3/4] Use when/otherwise to simplify logic --- .../badge/action/BadgeAction/badge.jelly | 42 ++++++++++--------- 1 file changed, 23 insertions(+), 19 deletions(-) diff --git a/src/main/resources/com/jenkinsci/plugins/badge/action/BadgeAction/badge.jelly b/src/main/resources/com/jenkinsci/plugins/badge/action/BadgeAction/badge.jelly index d255653..a522d21 100644 --- a/src/main/resources/com/jenkinsci/plugins/badge/action/BadgeAction/badge.jelly +++ b/src/main/resources/com/jenkinsci/plugins/badge/action/BadgeAction/badge.jelly @@ -33,26 +33,30 @@ THE SOFTWARE. - - - - + + + + + + + + + + + - - - - - - - - - - - - - - - + + + + + + + + + + + + From 535e18f83ad3146471f7314ec03a8df948244fb7 Mon Sep 17 00:00:00 2001 From: Mark Waite Date: Fri, 17 May 2024 11:19:11 -0600 Subject: [PATCH 4/4] Use `icon-sm` for all sizes, not just for symbols Uses the common way of specifying sizes now instead of explicitly declaring height and width attributes of the image. Simplifies the code dramatically and avoids conditionals in the jelly file. --- .../plugins/badge/action/BadgeAction.java | 4 +-- .../badge/action/BadgeAction/badge.jelly | 31 ++++--------------- .../plugins/badge/action/BadgeActionTest.java | 4 +-- 3 files changed, 9 insertions(+), 30 deletions(-) diff --git a/src/main/java/com/jenkinsci/plugins/badge/action/BadgeAction.java b/src/main/java/com/jenkinsci/plugins/badge/action/BadgeAction.java index 38d49d4..852ed3e 100644 --- a/src/main/java/com/jenkinsci/plugins/badge/action/BadgeAction.java +++ b/src/main/java/com/jenkinsci/plugins/badge/action/BadgeAction.java @@ -200,9 +200,7 @@ public String getBorderColor() { */ public String getIconClass() { List classes = new LinkedList<>(); - if (isJenkinsSymbolRef(this.iconPath)) { - classes.add("icon-sm"); - } + classes.add("icon-sm"); // control icon image size if (this.color != null) { if (this.color.startsWith("jenkins-!-")) { diff --git a/src/main/resources/com/jenkinsci/plugins/badge/action/BadgeAction/badge.jelly b/src/main/resources/com/jenkinsci/plugins/badge/action/BadgeAction/badge.jelly index a522d21..872d6ee 100644 --- a/src/main/resources/com/jenkinsci/plugins/badge/action/BadgeAction/badge.jelly +++ b/src/main/resources/com/jenkinsci/plugins/badge/action/BadgeAction/badge.jelly @@ -32,32 +32,13 @@ THE SOFTWARE. - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + diff --git a/src/test/java/com/jenkinsci/plugins/badge/action/BadgeActionTest.java b/src/test/java/com/jenkinsci/plugins/badge/action/BadgeActionTest.java index 6a8eb0e..3b55c4f 100644 --- a/src/test/java/com/jenkinsci/plugins/badge/action/BadgeActionTest.java +++ b/src/test/java/com/jenkinsci/plugins/badge/action/BadgeActionTest.java @@ -55,7 +55,7 @@ void getIconPath(@SuppressWarnings("unused") JenkinsRule r) { @Test void getIconClass(@SuppressWarnings("unused") JenkinsRule r) { BadgeAction action = BadgeAction.createBadge("info.gif", "text"); - assertEquals("", action.getIconClass()); + assertEquals("icon-sm", action.getIconClass()); action = BadgeAction.createBadge("symbol-star plugin-ionicons-api", "text"); assertEquals("icon-sm", action.getIconClass()); action = BadgeAction.createBadge("symbol-star plugin-ionicons-api", "#000000", "", null); @@ -63,7 +63,7 @@ void getIconClass(@SuppressWarnings("unused") JenkinsRule r) { action = BadgeAction.createBadge("symbol-star plugin-ionicons-api", "blue", "", null); assertEquals("icon-sm jenkins-!-color-blue", action.getIconClass()); action = BadgeAction.createBadge("/foo/symbol-star.gif", "blue", "", null); - assertEquals("jenkins-!-color-blue", action.getIconClass()); + assertEquals("icon-sm jenkins-!-color-blue", action.getIconClass()); action = BadgeAction.createBadge("symbol-star plugin-ionicons-api", "jenkins-!-color-red", "", null); assertEquals("icon-sm jenkins-!-color-red", action.getIconClass()); // teal is not in the palette