Skip to content

Commit 636b2db

Browse files
Remove commons-lang3 (#481)
1 parent 44e4421 commit 636b2db

17 files changed

+495
-355
lines changed

pom.xml

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@
4747
<changelist>-SNAPSHOT</changelist>
4848
<spotless.check.skip>false</spotless.check.skip>
4949
<ban-junit4-imports.skip>false</ban-junit4-imports.skip>
50+
<hpi.strictBundledArtifacts>true</hpi.strictBundledArtifacts>
5051
</properties>
5152

5253
<dependencyManagement>
@@ -62,10 +63,6 @@
6263
</dependencyManagement>
6364

6465
<dependencies>
65-
<dependency>
66-
<groupId>io.jenkins.plugins</groupId>
67-
<artifactId>commons-lang3-api</artifactId>
68-
</dependency>
6966
<dependency>
7067
<groupId>io.jenkins.plugins</groupId>
7168
<artifactId>emoji-symbols-api</artifactId>

src/main/java/jenkins/plugins/foldericon/CustomFolderIcon.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
import java.util.stream.Collectors;
2323
import jenkins.model.Jenkins;
2424
import org.apache.commons.fileupload2.core.FileItem;
25-
import org.apache.commons.lang3.StringUtils;
2625
import org.kohsuke.stapler.AncestorInPath;
2726
import org.kohsuke.stapler.DataBoundConstructor;
2827
import org.kohsuke.stapler.HttpResponse;
@@ -100,7 +99,7 @@ public String getFoldericon() {
10099

101100
@Override
102101
public String getImageOf(String size) {
103-
if (StringUtils.isNotBlank(getFoldericon())) {
102+
if (getFoldericon() != null && !getFoldericon().isBlank()) {
104103
return Stapler.getCurrentRequest2().getContextPath() + Jenkins.RESOURCE_PATH + "/" + USER_CONTENT_PATH + "/"
105104
+ PLUGIN_PATH + "/" + getFoldericon();
106105
} else {
@@ -191,11 +190,11 @@ public void onDeleted(Item item) {
191190
FolderIcon icon = ((AbstractFolder<?>) item).getIcon();
192191
if (icon instanceof CustomFolderIcon customFolderIcon) {
193192
String foldericon = customFolderIcon.getFoldericon();
194-
if (StringUtils.isNotBlank(foldericon)) {
193+
if (foldericon != null && !foldericon.isBlank()) {
195194
// delete the icon only if there is no other usage
196195
boolean orphan = Jenkins.get().getAllItems(AbstractFolder.class).stream()
197196
.filter(folder -> folder.getIcon() instanceof CustomFolderIcon customIcon
198-
&& StringUtils.equals(foldericon, customIcon.getFoldericon()))
197+
&& foldericon.equals(customIcon.getFoldericon()))
199198
.limit(2)
200199
.count()
201200
<= 1;

src/main/java/jenkins/plugins/foldericon/UrlFolderIcon.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77
import hudson.Extension;
88
import hudson.model.Item;
99
import hudson.util.FormValidation;
10+
import java.util.Locale;
1011
import jenkins.model.Jenkins;
11-
import org.apache.commons.lang3.StringUtils;
1212
import org.kohsuke.stapler.AncestorInPath;
1313
import org.kohsuke.stapler.DataBoundConstructor;
1414
import org.kohsuke.stapler.QueryParameter;
@@ -49,7 +49,7 @@ public String getUrl() {
4949

5050
@Override
5151
public String getImageOf(String size) {
52-
if (StringUtils.isNotBlank(getUrl())) {
52+
if (getUrl() != null && !getUrl().isBlank()) {
5353
return getUrl();
5454
} else {
5555
return Jenkins.get().getRootUrl() + DEFAULT_ICON_PATH;
@@ -89,7 +89,9 @@ public FormValidation doCheckUrl(@AncestorInPath Item item, @QueryParameter Stri
8989
} else {
9090
Jenkins.get().checkPermission(Jenkins.ADMINISTER);
9191
}
92-
if (StringUtils.isNotBlank(value) && !StringUtils.startsWithIgnoreCase(value, "http")) {
92+
if (value != null
93+
&& !value.isBlank()
94+
&& !value.toLowerCase(Locale.ROOT).startsWith("http")) {
9395
return FormValidation.error(Messages.Url_invalidUrl());
9496
}
9597
return FormValidation.ok();

src/test/java/jenkins/plugins/foldericon/BuildStatusFolderIconTest.java

Lines changed: 25 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,13 @@
22

33
import static jenkins.plugins.foldericon.utils.TestUtils.mockStaplerRequest;
44
import static jenkins.plugins.foldericon.utils.TestUtils.validateSymbol;
5-
import static org.junit.jupiter.api.Assertions.*;
5+
import static org.hamcrest.MatcherAssert.assertThat;
6+
import static org.hamcrest.Matchers.contains;
7+
import static org.hamcrest.Matchers.empty;
8+
import static org.hamcrest.Matchers.hasSize;
9+
import static org.hamcrest.Matchers.instanceOf;
10+
import static org.hamcrest.Matchers.is;
11+
import static org.hamcrest.Matchers.startsWith;
612
import static org.mockito.Mockito.mockStatic;
713

814
import com.cloudbees.hudson.plugins.folder.Folder;
@@ -17,7 +23,6 @@
1723
import jenkins.plugins.foldericon.BuildStatusFolderIcon.DescriptorImpl;
1824
import jenkins.plugins.foldericon.utils.DelayBuilder;
1925
import jenkins.plugins.foldericon.utils.ResultBuilder;
20-
import org.apache.commons.lang3.StringUtils;
2126
import org.junit.jupiter.api.BeforeEach;
2227
import org.junit.jupiter.api.Test;
2328
import org.jvnet.hudson.test.JenkinsRule;
@@ -50,13 +55,13 @@ void getAvailableJobs() throws Exception {
5055
BuildStatusFolderIcon customIcon = new BuildStatusFolderIcon(null);
5156
project.setIcon(customIcon);
5257

53-
assertTrue(customIcon.getAvailableJobs().isEmpty());
58+
assertThat(customIcon.getAvailableJobs(), empty());
5459

5560
project.createProject(FreeStyleProject.class, "Success");
5661
project.createProject(FreeStyleProject.class, "Aborted");
5762

58-
assertEquals(2, customIcon.getAvailableJobs().size());
59-
assertEquals(Set.of("Aborted", "Success"), customIcon.getAvailableJobs());
63+
assertThat(customIcon.getAvailableJobs(), hasSize(2));
64+
assertThat(customIcon.getAvailableJobs(), contains("Aborted", "Success"));
6065
}
6166

6267
/**
@@ -127,14 +132,14 @@ void withConfiguredJobs() throws Exception {
127132
@Test
128133
void folder() throws Exception {
129134
BuildStatusFolderIcon customIcon = new BuildStatusFolderIcon(null);
130-
assertTrue(StringUtils.startsWith(customIcon.getDescription(), Messages.Folder_description()));
135+
assertThat(customIcon.getDescription(), startsWith(Messages.Folder_description()));
131136

132137
Folder project = r.jenkins.createProject(Folder.class, "folder");
133138
project.setIcon(customIcon);
134139
FolderIcon icon = project.getIcon();
135140

136-
assertInstanceOf(BuildStatusFolderIcon.class, icon);
137-
assertTrue(StringUtils.startsWith(icon.getDescription(), project.getPronoun()));
141+
assertThat(icon, instanceOf(BuildStatusFolderIcon.class));
142+
assertThat(icon.getDescription(), startsWith(project.getPronoun()));
138143
}
139144

140145
/**
@@ -145,14 +150,14 @@ void folder() throws Exception {
145150
@Test
146151
void organizationFolder() throws Exception {
147152
BuildStatusFolderIcon customIcon = new BuildStatusFolderIcon(null);
148-
assertTrue(StringUtils.startsWith(customIcon.getDescription(), Messages.Folder_description()));
153+
assertThat(customIcon.getDescription(), startsWith(Messages.Folder_description()));
149154

150155
OrganizationFolder project = r.jenkins.createProject(OrganizationFolder.class, "org");
151156
project.setIcon(customIcon);
152157
FolderIcon icon = project.getIcon();
153158

154-
assertInstanceOf(BuildStatusFolderIcon.class, icon);
155-
assertTrue(StringUtils.startsWith(icon.getDescription(), project.getPronoun()));
159+
assertThat(icon, instanceOf(BuildStatusFolderIcon.class));
160+
assertThat(icon.getDescription(), startsWith(project.getPronoun()));
156161
}
157162

158163
/**
@@ -162,8 +167,8 @@ void organizationFolder() throws Exception {
162167
void descriptor() {
163168
BuildStatusFolderIcon customIcon = new BuildStatusFolderIcon(null);
164169
DescriptorImpl descriptor = customIcon.getDescriptor();
165-
assertEquals(Messages.BuildStatusFolderIcon_description(), descriptor.getDisplayName());
166-
assertTrue(descriptor.isApplicable(null));
170+
assertThat(descriptor.getDisplayName(), is(Messages.BuildStatusFolderIcon_description()));
171+
assertThat(descriptor.isApplicable(null), is(true));
167172
}
168173

169174
/**
@@ -178,7 +183,7 @@ void finishedBuildStatusIcon() throws Exception {
178183
project.setIcon(customIcon);
179184
FolderIcon icon = project.getIcon();
180185

181-
assertInstanceOf(BuildStatusFolderIcon.class, icon);
186+
assertThat(icon, instanceOf(BuildStatusFolderIcon.class));
182187

183188
try (MockedStatic<Stapler> stapler = mockStatic(Stapler.class)) {
184189
mockStaplerRequest(stapler);
@@ -234,7 +239,7 @@ void runningBuildStatusIcon() throws Exception {
234239
project.setIcon(customIcon);
235240
FolderIcon icon = project.getIcon();
236241

237-
assertInstanceOf(BuildStatusFolderIcon.class, icon);
242+
assertThat(icon, instanceOf(BuildStatusFolderIcon.class));
238243

239244
try (MockedStatic<Stapler> stapler = mockStatic(Stapler.class)) {
240245
mockStaplerRequest(stapler);
@@ -271,7 +276,7 @@ void runningNoPreviousBuildStatusIcon() throws Exception {
271276
project.setIcon(customIcon);
272277
FolderIcon icon = project.getIcon();
273278

274-
assertInstanceOf(BuildStatusFolderIcon.class, icon);
279+
assertThat(icon, instanceOf(BuildStatusFolderIcon.class));
275280

276281
try (MockedStatic<Stapler> stapler = mockStatic(Stapler.class)) {
277282
mockStaplerRequest(stapler);
@@ -302,7 +307,7 @@ void disabledBuildStatusIcon() throws Exception {
302307
project.setIcon(customIcon);
303308
FolderIcon icon = project.getIcon();
304309

305-
assertInstanceOf(BuildStatusFolderIcon.class, icon);
310+
assertThat(icon, instanceOf(BuildStatusFolderIcon.class));
306311

307312
try (MockedStatic<Stapler> stapler = mockStatic(Stapler.class)) {
308313
mockStaplerRequest(stapler);
@@ -311,8 +316,8 @@ void disabledBuildStatusIcon() throws Exception {
311316
FreeStyleProject disabled = project.createProject(FreeStyleProject.class, "Disabled");
312317
disabled.setDisabled(true);
313318

314-
assertFalse(disabled.isBuildable());
315-
assertTrue(disabled.isDisabled());
319+
assertThat(disabled.isBuildable(), is(false));
320+
assertThat(disabled.isDisabled(), is(true));
316321
validateSymbol(icon, BallColor.DISABLED.getImage(), BallColor.DISABLED.getIconName());
317322
}
318323
}
@@ -329,7 +334,7 @@ void noBuildStatusIcon() throws Exception {
329334
project.setIcon(customIcon);
330335
FolderIcon icon = project.getIcon();
331336

332-
assertInstanceOf(BuildStatusFolderIcon.class, icon);
337+
assertThat(icon, instanceOf(BuildStatusFolderIcon.class));
333338

334339
try (MockedStatic<Stapler> stapler = mockStatic(Stapler.class)) {
335340
mockStaplerRequest(stapler);

0 commit comments

Comments
 (0)