Skip to content

Commit

Permalink
[MNG-6829] Replace any StringUtils#isEmpty(String) and #isNotEmpty(St…
Browse files Browse the repository at this point in the history
…ring) (#318)

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 committed May 15, 2023
1 parent abc76b5 commit 4c3568e
Show file tree
Hide file tree
Showing 8 changed files with 22 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
import java.util.List;
import java.util.Set;

import org.apache.commons.lang3.StringUtils;
import org.apache.maven.artifact.Artifact;
import org.apache.maven.artifact.ArtifactUtils;
import org.apache.maven.artifact.handler.manager.ArtifactHandlerManager;
Expand Down Expand Up @@ -298,7 +297,7 @@ public void execute() throws MojoExecutionException, MojoFailureException {
return;
}

if (!StringUtils.isEmpty(manualInclude)) {
if (!(manualInclude == null || manualInclude.isEmpty())) {
manualIncludes = this.parseIncludes(manualInclude);
}
// If it's a manual purge, the only step is to delete from the local repo
Expand Down Expand Up @@ -382,13 +381,13 @@ private void manualPurge(List<String> theIncludes) throws MojoExecutionException
.toString());

for (String gavPattern : theIncludes) {
if (StringUtils.isEmpty(gavPattern)) {
if (gavPattern == null || gavPattern.isEmpty()) {
getLog().debug("Skipping empty gav pattern");
continue;
}

String relativePath = gavToPath(gavPattern);
if (StringUtils.isEmpty(relativePath)) {
if (relativePath == null || relativePath.isEmpty()) {
getLog().debug("Skipping empty relative path for gav pattern: " + gavPattern);
continue;
}
Expand All @@ -414,7 +413,7 @@ private void manualPurge(List<String> theIncludes) throws MojoExecutionException
* @return the corresponding path
*/
private String gavToPath(String gav) {
if (StringUtils.isEmpty(gav)) {
if (gav == null || gav.isEmpty()) {
return null;
}

Expand Down Expand Up @@ -450,14 +449,14 @@ private TransformableFilter createPurgeArtifactsFilter(
}

// The CLI includes/excludes overrides configuration in the pom
if (!StringUtils.isEmpty(this.include)) {
if (!(this.include == null || this.include.isEmpty())) {
this.includes = parseIncludes(this.include);
}
if (this.includes != null) {
subFilters.add(new PatternInclusionsFilter(includes));
}

if (!StringUtils.isEmpty(this.exclude)) {
if (!(this.exclude == null || this.exclude.isEmpty())) {
this.excludes = parseIncludes(this.exclude);
}
if (this.excludes != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
import java.util.LinkedHashSet;
import java.util.Set;

import org.apache.commons.lang3.StringUtils;
import org.apache.maven.artifact.Artifact;
import org.apache.maven.artifact.handler.manager.ArtifactHandlerManager;
import org.apache.maven.plugin.MojoExecutionException;
Expand Down Expand Up @@ -337,7 +336,7 @@ protected DependencyStatusSets getDependencySets(boolean stopOnFailure, boolean

// transform artifacts if classifier is set
DependencyStatusSets status;
if (StringUtils.isNotEmpty(classifier)) {
if (classifier != null && !classifier.isEmpty()) {
status = getClassifierTranslatedDependencies(artifacts, stopOnFailure);
} else {
status = filterMarkedDependencies(artifacts);
Expand Down Expand Up @@ -395,7 +394,7 @@ protected DependencyStatusSets getClassifierTranslatedDependencies(Set<Artifact>
// possibly translate artifacts into a new set of artifacts based on the
// classifier and type
// if this did something, we need to resolve the new artifacts
if (StringUtils.isNotEmpty(classifier)) {
if (classifier != null && !classifier.isEmpty()) {
ArtifactTranslator translator =
new ClassifierTypeTranslator(artifactHandlerManager, this.classifier, this.type);
Collection<ArtifactCoordinate> coordinates = translator.translate(artifacts, getLog());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -178,11 +178,11 @@ public class BuildClasspathMojo extends AbstractDependencyFilterMojo implements
@Override
protected void doExecute() throws MojoExecutionException {
// initialize the separators.
boolean isFileSepSet = StringUtils.isNotEmpty(fileSeparator);
boolean isPathSepSet = StringUtils.isNotEmpty(pathSeparator);
boolean isFileSepSet = fileSeparator != null && !fileSeparator.isEmpty();
boolean isPathSepSet = pathSeparator != null && !pathSeparator.isEmpty();

// don't allow them to have absolute paths when they attach.
if (attach && StringUtils.isEmpty(localRepoProperty)) {
if (attach && (localRepoProperty == null || localRepoProperty.isEmpty())) {
localRepoProperty = "${M2_REPO}";
}

Expand Down Expand Up @@ -264,7 +264,7 @@ protected void appendArtifactPath(Artifact art, StringBuilder sb) {
if (prefix == null) {
String file = art.getFile().getPath();
// substitute the property for the local repo path to make the classpath file portable.
if (StringUtils.isNotEmpty(localRepoProperty)) {
if (localRepoProperty != null && !localRepoProperty.isEmpty()) {
ProjectBuildingRequest projectBuildingRequest = session.getProjectBuildingRequest();
File localBasedir = repositoryManager.getLocalRepositoryBasedir(projectBuildingRequest);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,7 @@ public static String[] tokenizer(String str) {
*/
public static String cleanToBeTokenizedString(String str) {
String ret = "";
if (!StringUtils.isEmpty(str)) {
if (!(str == null || str.isEmpty())) {
// remove initial and ending spaces, plus all spaces next to commas
ret = str.trim().replaceAll("[\\s]*,[\\s]*", ",");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@

import java.io.File;

import org.apache.commons.lang3.StringUtils;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugin.logging.Log;
import org.codehaus.plexus.archiver.ArchiverException;
Expand Down Expand Up @@ -127,18 +126,18 @@ public void unpack(

unArchiver.setDestDirectory(location);

if (StringUtils.isNotEmpty(excludes) || StringUtils.isNotEmpty(includes)) {
if ((excludes != null && !excludes.isEmpty()) || (includes != null && !includes.isEmpty())) {
// Create the selectors that will filter
// based on include/exclude parameters
// MDEP-47
IncludeExcludeFileSelector[] selectors =
new IncludeExcludeFileSelector[] {new IncludeExcludeFileSelector()};

if (StringUtils.isNotEmpty(excludes)) {
if (excludes != null && !excludes.isEmpty()) {
selectors[0].setExcludes(excludes.split(","));
}

if (StringUtils.isNotEmpty(includes)) {
if (includes != null && !includes.isEmpty()) {
selectors[0].setIncludes(includes.split(","));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
import java.util.LinkedHashSet;
import java.util.Set;

import org.apache.commons.lang3.StringUtils;
import org.apache.maven.artifact.Artifact;
import org.apache.maven.artifact.handler.ArtifactHandler;
import org.apache.maven.artifact.handler.manager.ArtifactHandlerManager;
Expand Down Expand Up @@ -67,7 +66,7 @@ public Set<ArtifactCoordinate> translate(Set<Artifact> artifacts, Log log) {
// will use the
// base artifact value if null comes in
final String useType;
if (StringUtils.isNotEmpty(this.type)) {
if (this.type != null && !this.type.isEmpty()) {
useType = this.type;
} else {
useType = artifact.getType();
Expand All @@ -83,7 +82,7 @@ public Set<ArtifactCoordinate> translate(Set<Artifact> artifacts, Log log) {
}

String useClassifier;
if (StringUtils.isNotEmpty(this.classifier)) {
if (this.classifier != null && !this.classifier.isEmpty()) {
useClassifier = this.classifier;
} else {
useClassifier = artifact.getClassifier();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
import java.util.HashSet;
import java.util.Set;

import org.apache.commons.lang3.StringUtils;
import org.apache.maven.artifact.Artifact;
import org.apache.maven.artifact.handler.manager.ArtifactHandlerManager;
import org.apache.maven.artifact.resolver.filter.ScopeArtifactFilter;
Expand Down Expand Up @@ -390,10 +389,10 @@ public void dotestClassifierType(String testClassifier, String testType) throws
String useClassifier = artifact.getClassifier();
String useType = artifact.getType();

if (StringUtils.isNotEmpty(testClassifier)) {
if (testClassifier != null && !testClassifier.isEmpty()) {
useClassifier = "-" + testClassifier;
// type is only used if classifier is used.
if (StringUtils.isNotEmpty(testType)) {
if (testType != null && !testType.isEmpty()) {
useType = testType;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
import java.util.Iterator;
import java.util.Set;

import org.apache.commons.lang3.StringUtils;
import org.apache.maven.artifact.Artifact;
import org.apache.maven.artifact.handler.manager.ArtifactHandlerManager;
import org.apache.maven.artifact.resolver.filter.ScopeArtifactFilter;
Expand Down Expand Up @@ -465,10 +464,10 @@ public void dotestClassifierType(String testClassifier, String testType) throws
String useClassifier = artifact.getClassifier();
String useType = artifact.getType();

if (StringUtils.isNotEmpty(testClassifier)) {
if (testClassifier != null && !testClassifier.isEmpty()) {
useClassifier = testClassifier;
// type is only used if classifier is used.
if (StringUtils.isNotEmpty(testType)) {
if (testType != null && !testType.isEmpty()) {
useType = testType;
}
}
Expand Down

0 comments on commit 4c3568e

Please sign in to comment.