Skip to content

Commit

Permalink
Upgrade to badge-plugin 2.x (#995)
Browse files Browse the repository at this point in the history
  • Loading branch information
strangelookingnerd authored Sep 25, 2024
1 parent 9354ebc commit 14b56ae
Show file tree
Hide file tree
Showing 8 changed files with 33 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,8 @@ public <T extends Actor> void performAs(T actor) {
actor.attemptsTo(
Scroll.to(FailureCauseManagementPage.Add_Indication),
Click.on(FailureCauseManagementPage.Add_Indication),
WaitUntil.the(
FailureCauseManagementPage.Build_Log_Indication_Link, WebElementStateMatchers.isVisible()),
Click.on(FailureCauseManagementPage.Build_Log_Indication_Link),
WaitUntil.the(FailureCauseManagementPage.Build_Log_Indication, WebElementStateMatchers.isVisible()),
Click.on(FailureCauseManagementPage.Build_Log_Indication),
Enter.theValue(pattern).into(FailureCauseManagementPage.Pattern_Field));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public class FailureCauseManagementPage {
Target.the("the description textarea").locatedBy("//textarea[@name='_.description']");
public static final Target Add_Indication = Button.called("Add Indication");

public static final Target Build_Log_Indication_Link = Link.called("Build Log Indication");
public static final Target Build_Log_Indication = Button.called("Build Log Indication");
public static final Target Pattern_Field = Input.named("pattern");

public static final Target Save = Button.called("Save");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import net.serenitybdd.screenplay.Actor;
import net.serenitybdd.screenplay.Task;
import net.serenitybdd.screenplay.actions.Click;
import net.serenitybdd.screenplay.jenkins.targets.Link;
import net.serenitybdd.screenplay.jenkins.targets.Button;
import net.serenitybdd.screenplay.jenkins.user_interface.ProjectConfigurationPage;

public class AddABuildStep implements Task {
Expand All @@ -22,7 +22,7 @@ public <T extends Actor> void performAs(final T actor) {
Click.on(ProjectConfigurationPage.Build_Steps),
Sleep.of(1, TimeUnit.SECONDS),
Click.on(ProjectConfigurationPage.Add_Build_Step),
Click.on(Link.called(buildStepName)));
Click.on(Button.called(buildStepName)));
}

public AddABuildStep(String buildStepName) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import net.serenitybdd.screenplay.Actor;
import net.serenitybdd.screenplay.Task;
import net.serenitybdd.screenplay.actions.Click;
import net.serenitybdd.screenplay.jenkins.targets.Link;
import net.serenitybdd.screenplay.jenkins.targets.Button;
import net.serenitybdd.screenplay.jenkins.user_interface.ProjectConfigurationPage;
import net.serenitybdd.screenplayx.actions.Scroll;

Expand All @@ -24,7 +24,7 @@ public <T extends Actor> void performAs(T actor) {
Sleep.of(1, TimeUnit.SECONDS),
Click.on(ProjectConfigurationPage.Add_Post_Build_Action),
Sleep.of(1, TimeUnit.SECONDS),
Click.on(Link.called(postBuildActionName)));
Click.on(Button.called(postBuildActionName)));
}

public AddAPostBuildAction(String postBuildActionName) {
Expand Down
6 changes: 3 additions & 3 deletions build-monitor-plugin/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@
<dependencies>
<dependency>
<groupId>io.jenkins.tools.bom</groupId>
<artifactId>bom-2.414.x</artifactId>
<version>2982.vdce2153031a_0</version>
<artifactId>bom-${jenkins.baseline}.x</artifactId>
<version>3387.v0f2773fa_3200</version>
<type>pom</type>
<scope>import</scope>
</dependency>
Expand All @@ -71,7 +71,7 @@
<dependency>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>badge</artifactId>
<version>1.9.1</version>
<version>2.1</version>
<optional>true</optional>
</dependency>
<dependency>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
import java.util.Iterator;
import java.util.List;
import java.util.function.Predicate;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
* @author Daniel Beland
Expand Down Expand Up @@ -57,6 +59,9 @@ public List<Badge> value() {

public static class Badge {
private final BadgeAction badge;
private static final Pattern BADGE_STYLE_PATTERN =
Pattern.compile("(border: (?<border>.*) solid (?<borderColor>.*);)?"
+ "(background: (?<background>.*);)?" + "(color: (?<color>.*);)?");

public Badge(BadgeAction badge) {
this.badge = badge;
Expand All @@ -69,29 +74,37 @@ public final String text() {

@JsonProperty
public final String color() {
return badge.getColor();
String style = badge.getStyle();
Matcher matcher = BADGE_STYLE_PATTERN.matcher(style);
return matcher.matches() ? matcher.group("color") : null;
}

@JsonProperty
public final String background() {
return badge.getBackground();
String style = badge.getStyle();
Matcher matcher = BADGE_STYLE_PATTERN.matcher(style);
return matcher.matches() ? matcher.group("background") : null;
}

@JsonProperty
public final String border() {
return badge.getBorder();
String style = badge.getStyle();
Matcher matcher = BADGE_STYLE_PATTERN.matcher(style);
return matcher.matches() ? matcher.group("border") : null;
}

@JsonProperty
public final String borderColor() {
return badge.getBorderColor();
String style = badge.getStyle();
Matcher matcher = BADGE_STYLE_PATTERN.matcher(style);
return matcher.matches() ? matcher.group("borderColor") : null;
}
}

private static class ActionFilter implements Predicate<BadgeAction> {
@Override
public boolean test(BadgeAction action) {
return action.getIconPath() == null;
return action.getIcon() == null;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,13 @@ public BadgeBadgePluginRecipe() {
}

public BadgeBadgePluginRecipe withText(String text) {
when(badge.getIconPath()).thenReturn(null);
when(badge.getIcon()).thenReturn(null);
lenient().when(badge.getText()).thenReturn(text);
return this;
}

public BadgeBadgePluginRecipe withIcon(String icon, String text) {
when(badge.getIconPath()).thenReturn(icon);
when(badge.getIcon()).thenReturn(icon);
lenient().when(badge.getText()).thenReturn(text);
return this;
}
Expand Down
4 changes: 3 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,9 @@
<properties>
<revision>1.14</revision>
<changelist>999999-SNAPSHOT</changelist>
<jenkins.version>2.414.3</jenkins.version>
<!-- https://www.jenkins.io/doc/developer/plugin-development/choosing-jenkins-baseline/ -->
<jenkins.baseline>2.440</jenkins.baseline>
<jenkins.version>${jenkins.baseline}.3</jenkins.version>
<gitHubRepo>jenkinsci/build-monitor-plugin</gitHubRepo>
<spotless.check.skip>false</spotless.check.skip>
</properties>
Expand Down

0 comments on commit 14b56ae

Please sign in to comment.