Skip to content

Commit 3cb4a73

Browse files
refactor: Replace any StringUtils#isEmpty(String) and #isNotEmpty(String) (#50)
Use this link to re-run the recipe: https://public.moderne.io/recipes/org.openrewrite.java.migrate.apache.commons.lang.IsNotEmptyToJdk?organizationId=QXBhY2hlIE1hdmVu Co-authored-by: Moderne <[email protected]>
1 parent cb8c257 commit 3cb4a73

11 files changed

+40
-44
lines changed

src/main/java/org/apache/maven/report/projectinfo/AbstractProjectInfoRenderer.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424
import org.apache.maven.doxia.sink.Sink;
2525
import org.apache.maven.reporting.AbstractMavenReportRenderer;
2626
import org.codehaus.plexus.i18n.I18N;
27-
import org.codehaus.plexus.util.StringUtils;
2827

2928
/**
3029
* @author Hervé Boutemy
@@ -78,7 +77,7 @@ protected String getI18nString(String section, String key) {
7877

7978
@Override
8079
protected void text(String text) {
81-
if (StringUtils.isEmpty(text)) // Take care of spaces
80+
if (text == null || text.isEmpty()) // Take care of spaces
8281
{
8382
sink.text("-");
8483
} else {
@@ -112,7 +111,7 @@ protected void verbatimText(String text) {
112111
*/
113112
@Override
114113
protected void verbatimLink(String text, String href) {
115-
if (StringUtils.isEmpty(href)) {
114+
if (href == null || href.isEmpty()) {
116115
verbatimText(text);
117116
} else {
118117
sink.verbatim(null);

src/main/java/org/apache/maven/report/projectinfo/CiManagementReport.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@
3030
import org.apache.maven.model.Notifier;
3131
import org.apache.maven.plugins.annotations.Mojo;
3232
import org.codehaus.plexus.i18n.I18N;
33-
import org.codehaus.plexus.util.StringUtils;
3433

3534
/**
3635
* Generates the Project Continuous Integration Management report.
@@ -137,7 +136,7 @@ public void renderBody() {
137136
// Access
138137
startSection(getI18nString("access"));
139138

140-
if (!StringUtils.isEmpty(url)) {
139+
if (!(url == null || url.isEmpty())) {
141140
paragraph(getI18nString("url"));
142141

143142
verbatimLink(url, url);
@@ -186,7 +185,7 @@ public void renderBody() {
186185
* @return system description from properties
187186
*/
188187
private String getIntroForCiManagementSystem(String system) {
189-
if (StringUtils.isEmpty(system)) {
188+
if (system == null || system.isEmpty()) {
190189
return getI18nString("general.intro");
191190
}
192191

src/main/java/org/apache/maven/report/projectinfo/DistributionManagementReport.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ public void renderBody() {
165165
}
166166

167167
private void internalLink(String url) {
168-
if (StringUtils.isEmpty(url)) {
168+
if (url == null || url.isEmpty()) {
169169
return;
170170
}
171171

@@ -178,7 +178,7 @@ private void internalLink(String url) {
178178
}
179179

180180
private String getRepoName(String name) {
181-
if (StringUtils.isNotEmpty(name)) {
181+
if (name != null && !name.isEmpty()) {
182182
return " - " + name;
183183
}
184184

src/main/java/org/apache/maven/report/projectinfo/IssueManagementReport.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525
import org.apache.maven.model.Model;
2626
import org.apache.maven.plugins.annotations.Mojo;
2727
import org.codehaus.plexus.i18n.I18N;
28-
import org.codehaus.plexus.util.StringUtils;
2928

3029
/**
3130
* Generates the Project Issue Management report.
@@ -145,11 +144,11 @@ public void renderBody() {
145144
* @return true if the issue management system is Jira, bugzilla, false otherwise.
146145
*/
147146
private boolean isIssueManagementSystem(String system, String actual) {
148-
if (StringUtils.isEmpty(system)) {
147+
if (system == null || system.isEmpty()) {
149148
return false;
150149
}
151150

152-
if (StringUtils.isEmpty(actual)) {
151+
if (actual == null || actual.isEmpty()) {
153152
return false;
154153
}
155154

src/main/java/org/apache/maven/report/projectinfo/LicensesReport.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,7 @@ public void renderBody() {
250250
sink.list();
251251
for (License license : licenses) {
252252
String name = license.getName();
253-
if (StringUtils.isEmpty(name)) {
253+
if (name == null || name.isEmpty()) {
254254
name = getI18nString("unnamed");
255255
}
256256

@@ -264,7 +264,7 @@ public void renderBody() {
264264

265265
for (License license : licenses) {
266266
String name = license.getName();
267-
if (StringUtils.isEmpty(name)) {
267+
if (name == null || name.isEmpty()) {
268268
name = getI18nString("unnamed");
269269
}
270270

@@ -273,7 +273,7 @@ public void renderBody() {
273273

274274
startSection(name);
275275

276-
if (!StringUtils.isEmpty(comments)) {
276+
if (!(comments == null || comments.isEmpty())) {
277277
paragraph(comments);
278278
}
279279

src/main/java/org/apache/maven/report/projectinfo/ProjectInfoReportUtils.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ public static String getContent(URL url, MavenProject project, Settings settings
114114
throws IOException {
115115
String scheme = url.getProtocol();
116116

117-
if (StringUtils.isEmpty(encoding)) {
117+
if (encoding == null || encoding.isEmpty()) {
118118
encoding = DEFAULT_ENCODING;
119119
}
120120

@@ -144,7 +144,7 @@ public static String getContent(URL url, MavenProject project, Settings settings
144144
}
145145

146146
String host = proxy.getHost();
147-
if (!StringUtils.isEmpty(host)) {
147+
if (!(host == null || host.isEmpty())) {
148148
Properties p = System.getProperties();
149149
p.setProperty(scheme + "proxySet", "true");
150150
p.setProperty(scheme + "proxyHost", host);
@@ -154,7 +154,7 @@ public static String getContent(URL url, MavenProject project, Settings settings
154154
}
155155

156156
final String userName = proxy.getUsername();
157-
if (!StringUtils.isEmpty(userName)) {
157+
if (!(userName == null || userName.isEmpty())) {
158158
final String pwd = StringUtils.isEmpty(proxy.getPassword()) ? "" : proxy.getPassword();
159159
Authenticator.setDefault(new Authenticator() {
160160
/** {@inheritDoc} */
@@ -225,7 +225,7 @@ public static String getArtifactUrl(
225225
* @see AbstractMavenReportRenderer#linkPatternedText(String)
226226
*/
227227
public static String getArtifactIdCell(String artifactId, String link) {
228-
if (StringUtils.isEmpty(link)) {
228+
if (link == null || link.isEmpty()) {
229229
return artifactId;
230230
}
231231

@@ -237,7 +237,7 @@ public static String getArtifactIdCell(String artifactId, String link) {
237237
* @return <code>true</code> if the url is valid, <code>false</code> otherwise.
238238
*/
239239
public static boolean isArtifactUrlValid(String url) {
240-
if (StringUtils.isEmpty(url)) {
240+
if (url == null || url.isEmpty()) {
241241
return false;
242242
}
243243

src/main/java/org/apache/maven/report/projectinfo/ScmReport.java

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -110,8 +110,8 @@ public boolean canGenerateReport() {
110110
result = scm != null;
111111

112112
if (result
113-
&& StringUtils.isEmpty(anonymousConnection)
114-
&& StringUtils.isEmpty(developerConnection)
113+
&& (anonymousConnection == null || anonymousConnection.isEmpty())
114+
&& (developerConnection == null || developerConnection.isEmpty())
115115
&& StringUtils.isEmpty(scm.getUrl())) {
116116
result = false;
117117
}
@@ -217,8 +217,8 @@ protected String getI18Nsection() {
217217
public void renderBody() {
218218
Scm scm = model.getScm();
219219
if (scm == null
220-
|| StringUtils.isEmpty(anonymousConnection)
221-
&& StringUtils.isEmpty(devConnection)
220+
|| (anonymousConnection == null || anonymousConnection.isEmpty())
221+
&& (devConnection == null || devConnection.isEmpty())
222222
&& StringUtils.isEmpty(scm.getUrl())) {
223223
startSection(getTitle());
224224

@@ -303,7 +303,7 @@ private void renderOverviewSection(ScmRepository anonymousRepository, ScmReposit
303303
private void renderWebAccessSection(String scmUrl) {
304304
startSection(getI18nString("webaccess.title"));
305305

306-
if (StringUtils.isEmpty(scmUrl)) {
306+
if (scmUrl == null || scmUrl.isEmpty()) {
307307
paragraph(getI18nString("webaccess.nourl"));
308308
} else {
309309
paragraph(getI18nString("webaccess.url"));
@@ -326,7 +326,7 @@ private void renderAnonymousAccessSection(ScmRepository anonymousRepository) {
326326
if (isScmSystem(anonymousRepository, "clearcase")
327327
|| isScmSystem(anonymousRepository, "perforce")
328328
|| isScmSystem(anonymousRepository, "starteam")
329-
|| StringUtils.isEmpty(anonymousConnection)) {
329+
|| (anonymousConnection == null || anonymousConnection.isEmpty())) {
330330
return;
331331
}
332332

@@ -366,7 +366,7 @@ private void renderAnonymousAccessSection(ScmRepository anonymousRepository) {
366366
* @param devRepository the dev repository
367367
*/
368368
private void renderDeveloperAccessSection(ScmRepository devRepository) {
369-
if (StringUtils.isEmpty(devConnection)) {
369+
if (devConnection == null || devConnection.isEmpty()) {
370370
return;
371371
}
372372

@@ -503,7 +503,7 @@ private void gitClone(String url) {
503503
url = url.substring(0, index + 4);
504504
}
505505

506-
boolean head = StringUtils.isEmpty(scmTag) || "HEAD".equals(scmTag);
506+
boolean head = (scmTag == null || scmTag.isEmpty()) || "HEAD".equals(scmTag);
507507
verbatimText("$ git clone " + (head ? "" : ("--branch " + scmTag + ' ')) + url);
508508
}
509509

@@ -747,7 +747,7 @@ private void developerAccessSubversion(SvnScmProviderRepository svnRepo) {
747747
* @return a valid SCM repository or null
748748
*/
749749
public ScmRepository getScmRepository(String scmUrl) {
750-
if (StringUtils.isEmpty(scmUrl)) {
750+
if (scmUrl == null || scmUrl.isEmpty()) {
751751
return null;
752752
}
753753

@@ -814,7 +814,7 @@ public ScmRepository getScmRepository(String scmUrl) {
814814
* @see <a href="http://svn.apache.org/repos/asf/maven/scm/trunk/maven-scm-providers/">maven-scm-providers</a>
815815
*/
816816
private static boolean isScmSystem(ScmRepository scmRepository, String scmProvider) {
817-
if (StringUtils.isEmpty(scmProvider)) {
817+
if (scmProvider == null || scmProvider.isEmpty()) {
818818
return false;
819819
}
820820

src/main/java/org/apache/maven/report/projectinfo/SummaryReport.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ private void tableRowWithLink(String[] content) {
170170

171171
sink.tableCell();
172172

173-
if (StringUtils.isEmpty(cell)) {
173+
if (cell == null || cell.isEmpty()) {
174174
sink.text("-");
175175
} else if (ctr == content.length - 1 && cell.length() > 0) {
176176
sink.link(cell);

src/main/java/org/apache/maven/report/projectinfo/TeamReport.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -215,10 +215,10 @@ private void renderTeamMember(Contributor member, Map<String, Boolean> headersMa
215215
if (headersMap.get(IMAGE) == Boolean.TRUE && showAvatarImages) {
216216
Properties properties = member.getProperties();
217217
String picUrl = properties.getProperty("picUrl");
218-
if (StringUtils.isEmpty(picUrl)) {
218+
if (picUrl == null || picUrl.isEmpty()) {
219219
picUrl = getGravatarUrl(member.getEmail());
220220
}
221-
if (StringUtils.isEmpty(picUrl)) {
221+
if (picUrl == null || picUrl.isEmpty()) {
222222
picUrl = getSpacerGravatarUrl();
223223
}
224224
sink.tableCell();
@@ -498,7 +498,7 @@ private static Map<String, Boolean> checkRequiredHeaders(List<? extends Contribu
498498
private void tableCellForUrl(String url) {
499499
sink.tableCell();
500500

501-
if (StringUtils.isEmpty(url)) {
501+
if (url == null || url.isEmpty()) {
502502
text(url);
503503
} else {
504504
link(url, url);

src/main/java/org/apache/maven/report/projectinfo/dependencies/renderer/DependenciesRenderer.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -695,9 +695,9 @@ private void renderDependenciesForScope(String scope, List<Artifact> artifacts,
695695
// can't use straight artifact comparison because we want optional last
696696
Collections.sort(artifacts, getArtifactComparator());
697697

698-
String anchorByScope = (isTransitive
698+
String anchorByScope = isTransitive
699699
? getI18nString("transitive.title") + "_" + scope
700-
: getI18nString("title") + "_" + scope);
700+
: getI18nString("title") + "_" + scope;
701701
startSection(scope, anchorByScope);
702702

703703
paragraph(getI18nString("intro." + scope));
@@ -861,14 +861,14 @@ private void printDescriptionsAndURLs(DependencyNode node, String uid) {
861861
sink.bold();
862862
sink.text(getI18nString("column.description") + ": ");
863863
sink.bold_();
864-
if (StringUtils.isNotEmpty(artifactDescription)) {
864+
if (artifactDescription != null && !artifactDescription.isEmpty()) {
865865
sink.text(artifactDescription);
866866
} else {
867867
sink.text(getI18nString("index", "nodescription"));
868868
}
869869
sink.paragraph_();
870870

871-
if (StringUtils.isNotEmpty(artifactUrl)) {
871+
if (artifactUrl != null && !artifactUrl.isEmpty()) {
872872
sink.paragraph();
873873
sink.bold();
874874
sink.text(getI18nString("column.url") + ": ");
@@ -896,7 +896,7 @@ private void printDescriptionsAndURLs(DependencyNode node, String uid) {
896896
if (licenseMappings != null && licenseMappings.containsKey(licenseName)) {
897897
licenseName = licenseMappings.get(licenseName);
898898
}
899-
if (StringUtils.isEmpty(licenseName)) {
899+
if (licenseName == null || licenseName.isEmpty()) {
900900
licenseName = getI18nString("unnamed");
901901
}
902902

@@ -979,7 +979,7 @@ private void printDescriptionsAndURLs(DependencyNode node, String uid) {
979979
private void printGroupedLicenses() {
980980
for (Map.Entry<String, Object> entry : licenseMap.entrySet()) {
981981
String licenseName = entry.getKey();
982-
if (StringUtils.isEmpty(licenseName)) {
982+
if (licenseName == null || licenseName.isEmpty()) {
983983
licenseName = getI18nString("unnamed");
984984
}
985985

@@ -1127,7 +1127,7 @@ public StringBuffer format(long fs, StringBuffer result, FieldPosition fieldPosi
11271127
return result;
11281128
}
11291129

1130-
result = super.format((float) fs / (1000), result, fieldPosition);
1130+
result = super.format((float) fs / 1000, result, fieldPosition);
11311131
result.append(" ").append(getString("report.dependencies.file.details.column.size.kb"));
11321132
return result;
11331133
}

src/test/java/org/apache/maven/report/projectinfo/AbstractProjectInfoTestCase.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@
3232
import org.apache.maven.project.ProjectBuildingRequest;
3333
import org.apache.maven.report.projectinfo.stubs.DependencyArtifactStubFactory;
3434
import org.codehaus.plexus.i18n.I18N;
35-
import org.codehaus.plexus.util.StringUtils;
3635
import org.eclipse.aether.DefaultRepositorySystemSession;
3736
import org.eclipse.aether.internal.impl.SimpleLocalRepositoryManagerFactory;
3837
import org.eclipse.aether.repository.LocalRepository;
@@ -89,7 +88,7 @@ protected void tearDown() throws Exception {
8988
* @return the string for the given key
9089
*/
9190
protected String getString(String key) {
92-
if (StringUtils.isEmpty(key)) {
91+
if (key == null || key.isEmpty()) {
9392
throw new IllegalArgumentException("The key cannot be empty");
9493
}
9594

@@ -105,11 +104,11 @@ protected String getString(String key) {
105104
* @since 2.8
106105
*/
107106
protected String prepareTitle(String name, String title) {
108-
if (StringUtils.isEmpty(name)) {
107+
if (name == null || name.isEmpty()) {
109108
throw new IllegalArgumentException("The name cannot be empty");
110109
}
111110

112-
if (StringUtils.isEmpty(title)) {
111+
if (title == null || title.isEmpty()) {
113112
throw new IllegalArgumentException("The title cannot be empty");
114113
}
115114

0 commit comments

Comments
 (0)