Skip to content

Commit

Permalink
refactor: Replace any StringUtils#isEmpty(String) and #isNotEmpty(Str…
Browse files Browse the repository at this point in the history
…ing) (#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 <team@moderne.io>
  • Loading branch information
timtebeek and TeamModerne authored May 12, 2023
1 parent cb8c257 commit 3cb4a73
Show file tree
Hide file tree
Showing 11 changed files with 40 additions and 44 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
import org.apache.maven.doxia.sink.Sink;
import org.apache.maven.reporting.AbstractMavenReportRenderer;
import org.codehaus.plexus.i18n.I18N;
import org.codehaus.plexus.util.StringUtils;

/**
* @author Hervé Boutemy
Expand Down Expand Up @@ -78,7 +77,7 @@ protected String getI18nString(String section, String key) {

@Override
protected void text(String text) {
if (StringUtils.isEmpty(text)) // Take care of spaces
if (text == null || text.isEmpty()) // Take care of spaces
{
sink.text("-");
} else {
Expand Down Expand Up @@ -112,7 +111,7 @@ protected void verbatimText(String text) {
*/
@Override
protected void verbatimLink(String text, String href) {
if (StringUtils.isEmpty(href)) {
if (href == null || href.isEmpty()) {
verbatimText(text);
} else {
sink.verbatim(null);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
import org.apache.maven.model.Notifier;
import org.apache.maven.plugins.annotations.Mojo;
import org.codehaus.plexus.i18n.I18N;
import org.codehaus.plexus.util.StringUtils;

/**
* Generates the Project Continuous Integration Management report.
Expand Down Expand Up @@ -137,7 +136,7 @@ public void renderBody() {
// Access
startSection(getI18nString("access"));

if (!StringUtils.isEmpty(url)) {
if (!(url == null || url.isEmpty())) {
paragraph(getI18nString("url"));

verbatimLink(url, url);
Expand Down Expand Up @@ -186,7 +185,7 @@ public void renderBody() {
* @return system description from properties
*/
private String getIntroForCiManagementSystem(String system) {
if (StringUtils.isEmpty(system)) {
if (system == null || system.isEmpty()) {
return getI18nString("general.intro");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ public void renderBody() {
}

private void internalLink(String url) {
if (StringUtils.isEmpty(url)) {
if (url == null || url.isEmpty()) {
return;
}

Expand All @@ -178,7 +178,7 @@ private void internalLink(String url) {
}

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
import org.apache.maven.model.Model;
import org.apache.maven.plugins.annotations.Mojo;
import org.codehaus.plexus.i18n.I18N;
import org.codehaus.plexus.util.StringUtils;

/**
* Generates the Project Issue Management report.
Expand Down Expand Up @@ -145,11 +144,11 @@ public void renderBody() {
* @return true if the issue management system is Jira, bugzilla, false otherwise.
*/
private boolean isIssueManagementSystem(String system, String actual) {
if (StringUtils.isEmpty(system)) {
if (system == null || system.isEmpty()) {
return false;
}

if (StringUtils.isEmpty(actual)) {
if (actual == null || actual.isEmpty()) {
return false;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ public void renderBody() {
sink.list();
for (License license : licenses) {
String name = license.getName();
if (StringUtils.isEmpty(name)) {
if (name == null || name.isEmpty()) {
name = getI18nString("unnamed");
}

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

for (License license : licenses) {
String name = license.getName();
if (StringUtils.isEmpty(name)) {
if (name == null || name.isEmpty()) {
name = getI18nString("unnamed");
}

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

startSection(name);

if (!StringUtils.isEmpty(comments)) {
if (!(comments == null || comments.isEmpty())) {
paragraph(comments);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ public static String getContent(URL url, MavenProject project, Settings settings
throws IOException {
String scheme = url.getProtocol();

if (StringUtils.isEmpty(encoding)) {
if (encoding == null || encoding.isEmpty()) {
encoding = DEFAULT_ENCODING;
}

Expand Down Expand Up @@ -144,7 +144,7 @@ public static String getContent(URL url, MavenProject project, Settings settings
}

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

final String userName = proxy.getUsername();
if (!StringUtils.isEmpty(userName)) {
if (!(userName == null || userName.isEmpty())) {
final String pwd = StringUtils.isEmpty(proxy.getPassword()) ? "" : proxy.getPassword();
Authenticator.setDefault(new Authenticator() {
/** {@inheritDoc} */
Expand Down Expand Up @@ -225,7 +225,7 @@ public static String getArtifactUrl(
* @see AbstractMavenReportRenderer#linkPatternedText(String)
*/
public static String getArtifactIdCell(String artifactId, String link) {
if (StringUtils.isEmpty(link)) {
if (link == null || link.isEmpty()) {
return artifactId;
}

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

Expand Down
20 changes: 10 additions & 10 deletions src/main/java/org/apache/maven/report/projectinfo/ScmReport.java
Original file line number Diff line number Diff line change
Expand Up @@ -110,8 +110,8 @@ public boolean canGenerateReport() {
result = scm != null;

if (result
&& StringUtils.isEmpty(anonymousConnection)
&& StringUtils.isEmpty(developerConnection)
&& (anonymousConnection == null || anonymousConnection.isEmpty())
&& (developerConnection == null || developerConnection.isEmpty())
&& StringUtils.isEmpty(scm.getUrl())) {
result = false;
}
Expand Down Expand Up @@ -217,8 +217,8 @@ protected String getI18Nsection() {
public void renderBody() {
Scm scm = model.getScm();
if (scm == null
|| StringUtils.isEmpty(anonymousConnection)
&& StringUtils.isEmpty(devConnection)
|| (anonymousConnection == null || anonymousConnection.isEmpty())
&& (devConnection == null || devConnection.isEmpty())
&& StringUtils.isEmpty(scm.getUrl())) {
startSection(getTitle());

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

if (StringUtils.isEmpty(scmUrl)) {
if (scmUrl == null || scmUrl.isEmpty()) {
paragraph(getI18nString("webaccess.nourl"));
} else {
paragraph(getI18nString("webaccess.url"));
Expand All @@ -326,7 +326,7 @@ private void renderAnonymousAccessSection(ScmRepository anonymousRepository) {
if (isScmSystem(anonymousRepository, "clearcase")
|| isScmSystem(anonymousRepository, "perforce")
|| isScmSystem(anonymousRepository, "starteam")
|| StringUtils.isEmpty(anonymousConnection)) {
|| (anonymousConnection == null || anonymousConnection.isEmpty())) {
return;
}

Expand Down Expand Up @@ -366,7 +366,7 @@ private void renderAnonymousAccessSection(ScmRepository anonymousRepository) {
* @param devRepository the dev repository
*/
private void renderDeveloperAccessSection(ScmRepository devRepository) {
if (StringUtils.isEmpty(devConnection)) {
if (devConnection == null || devConnection.isEmpty()) {
return;
}

Expand Down Expand Up @@ -503,7 +503,7 @@ private void gitClone(String url) {
url = url.substring(0, index + 4);
}

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

Expand Down Expand Up @@ -747,7 +747,7 @@ private void developerAccessSubversion(SvnScmProviderRepository svnRepo) {
* @return a valid SCM repository or null
*/
public ScmRepository getScmRepository(String scmUrl) {
if (StringUtils.isEmpty(scmUrl)) {
if (scmUrl == null || scmUrl.isEmpty()) {
return null;
}

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ private void tableRowWithLink(String[] content) {

sink.tableCell();

if (StringUtils.isEmpty(cell)) {
if (cell == null || cell.isEmpty()) {
sink.text("-");
} else if (ctr == content.length - 1 && cell.length() > 0) {
sink.link(cell);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -215,10 +215,10 @@ private void renderTeamMember(Contributor member, Map<String, Boolean> headersMa
if (headersMap.get(IMAGE) == Boolean.TRUE && showAvatarImages) {
Properties properties = member.getProperties();
String picUrl = properties.getProperty("picUrl");
if (StringUtils.isEmpty(picUrl)) {
if (picUrl == null || picUrl.isEmpty()) {
picUrl = getGravatarUrl(member.getEmail());
}
if (StringUtils.isEmpty(picUrl)) {
if (picUrl == null || picUrl.isEmpty()) {
picUrl = getSpacerGravatarUrl();
}
sink.tableCell();
Expand Down Expand Up @@ -498,7 +498,7 @@ private static Map<String, Boolean> checkRequiredHeaders(List<? extends Contribu
private void tableCellForUrl(String url) {
sink.tableCell();

if (StringUtils.isEmpty(url)) {
if (url == null || url.isEmpty()) {
text(url);
} else {
link(url, url);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -695,9 +695,9 @@ private void renderDependenciesForScope(String scope, List<Artifact> artifacts,
// can't use straight artifact comparison because we want optional last
Collections.sort(artifacts, getArtifactComparator());

String anchorByScope = (isTransitive
String anchorByScope = isTransitive
? getI18nString("transitive.title") + "_" + scope
: getI18nString("title") + "_" + scope);
: getI18nString("title") + "_" + scope;
startSection(scope, anchorByScope);

paragraph(getI18nString("intro." + scope));
Expand Down Expand Up @@ -861,14 +861,14 @@ private void printDescriptionsAndURLs(DependencyNode node, String uid) {
sink.bold();
sink.text(getI18nString("column.description") + ": ");
sink.bold_();
if (StringUtils.isNotEmpty(artifactDescription)) {
if (artifactDescription != null && !artifactDescription.isEmpty()) {
sink.text(artifactDescription);
} else {
sink.text(getI18nString("index", "nodescription"));
}
sink.paragraph_();

if (StringUtils.isNotEmpty(artifactUrl)) {
if (artifactUrl != null && !artifactUrl.isEmpty()) {
sink.paragraph();
sink.bold();
sink.text(getI18nString("column.url") + ": ");
Expand Down Expand Up @@ -896,7 +896,7 @@ private void printDescriptionsAndURLs(DependencyNode node, String uid) {
if (licenseMappings != null && licenseMappings.containsKey(licenseName)) {
licenseName = licenseMappings.get(licenseName);
}
if (StringUtils.isEmpty(licenseName)) {
if (licenseName == null || licenseName.isEmpty()) {
licenseName = getI18nString("unnamed");
}

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

Expand Down Expand Up @@ -1127,7 +1127,7 @@ public StringBuffer format(long fs, StringBuffer result, FieldPosition fieldPosi
return result;
}

result = super.format((float) fs / (1000), result, fieldPosition);
result = super.format((float) fs / 1000, result, fieldPosition);
result.append(" ").append(getString("report.dependencies.file.details.column.size.kb"));
return result;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
import org.apache.maven.project.ProjectBuildingRequest;
import org.apache.maven.report.projectinfo.stubs.DependencyArtifactStubFactory;
import org.codehaus.plexus.i18n.I18N;
import org.codehaus.plexus.util.StringUtils;
import org.eclipse.aether.DefaultRepositorySystemSession;
import org.eclipse.aether.internal.impl.SimpleLocalRepositoryManagerFactory;
import org.eclipse.aether.repository.LocalRepository;
Expand Down Expand Up @@ -89,7 +88,7 @@ protected void tearDown() throws Exception {
* @return the string for the given key
*/
protected String getString(String key) {
if (StringUtils.isEmpty(key)) {
if (key == null || key.isEmpty()) {
throw new IllegalArgumentException("The key cannot be empty");
}

Expand All @@ -105,11 +104,11 @@ protected String getString(String key) {
* @since 2.8
*/
protected String prepareTitle(String name, String title) {
if (StringUtils.isEmpty(name)) {
if (name == null || name.isEmpty()) {
throw new IllegalArgumentException("The name cannot be empty");
}

if (StringUtils.isEmpty(title)) {
if (title == null || title.isEmpty()) {
throw new IllegalArgumentException("The title cannot be empty");
}

Expand Down

0 comments on commit 3cb4a73

Please sign in to comment.