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) (#214)

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 73791dd commit 1dcccaf
Show file tree
Hide file tree
Showing 15 changed files with 46 additions and 54 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -378,7 +378,7 @@ static class PluginOverviewRenderer extends AbstractMavenReportRenderer {

this.project = project;

this.requirements = (requirements == null ? new Requirements() : requirements);
this.requirements = requirements == null ? new Requirements() : requirements;

this.requirementsHistories = requirementsHistories;

Expand Down Expand Up @@ -496,15 +496,15 @@ public void renderBody() {
sink.tableRow_();

String memory = requirements.getMemory();
if (StringUtils.isNotEmpty(memory)) {
if (memory != null && !memory.isEmpty()) {
sink.tableRow();
tableCell(getBundle(locale).getString("report.plugin.systemrequirements.memory"));
tableCell(memory);
sink.tableRow_();
}

String diskSpace = requirements.getDiskSpace();
if (StringUtils.isNotEmpty(diskSpace)) {
if (diskSpace != null && !diskSpace.isEmpty()) {
sink.tableRow();
tableCell(getBundle(locale).getString("report.plugin.systemrequirements.diskspace"));
tableCell(diskSpace);
Expand Down Expand Up @@ -668,9 +668,9 @@ private void renderUsageSection(boolean hasMavenReport) {
private static String discoverMavenRequirement(MavenProject project, Requirements requirements) {
String maven = requirements.getMaven();
if (maven == null) {
maven = (project.getPrerequisites() != null
maven = project.getPrerequisites() != null
? project.getPrerequisites().getMaven()
: null);
: null;
}
if (maven == null) {
maven = "2.0";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -756,7 +756,7 @@ private List<MojoDescriptor> toMojoDescriptors(
+ "forbidden characters ${}: " + property,
null);
}
parameter.setExpression(StringUtils.isEmpty(property) ? "" : "${" + property + "}");
parameter.setExpression((property == null || property.isEmpty()) ? "" : "${" + property + "}");
StringBuilder type = new StringBuilder(parameterAnnotationContent.getClassName());
if (!parameterAnnotationContent.getTypeParameters().isEmpty()) {
type.append(parameterAnnotationContent.getTypeParameters().stream()
Expand Down Expand Up @@ -818,7 +818,7 @@ protected MojoAnnotatedClass findClassWithExecuteAnnotationInParentHierarchy(
return mojoAnnotatedClass;
}
String parentClassName = mojoAnnotatedClass.getParentClassName();
if (StringUtils.isEmpty(parentClassName)) {
if (parentClassName == null || parentClassName.isEmpty()) {
return null;
}
MojoAnnotatedClass parent = mojoAnnotatedClasses.get(parentClassName);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ public FieldVisitor visitField(int access, String name, String desc, String sign
* @return the list of type parameters (may be empty)
*/
private List<String> extractTypeParameters(int access, String signature, boolean isField) {
if (StringUtils.isEmpty(signature)) {
if (signature == null || signature.isEmpty()) {
return Collections.emptyList();
}
TraceSignatureVisitor traceSignatureVisitor = new TraceSignatureVisitor(access);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
import org.apache.maven.project.MavenProject;
import org.apache.maven.settings.Settings;
import org.codehaus.plexus.util.ReaderFactory;
import org.codehaus.plexus.util.StringUtils;
import org.eclipse.aether.RepositorySystemSession;

/**
Expand Down Expand Up @@ -119,7 +118,7 @@ public String getEncoding() {
*/
@Override
public PluginToolsRequest setEncoding(String encoding) {
if (StringUtils.isNotEmpty(encoding)) {
if (encoding != null && !encoding.isEmpty()) {
this.encoding = encoding;
} else {
this.encoding = DEFAULT_ENCODING;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@
import org.codehaus.plexus.logging.AbstractLogEnabled;
import org.codehaus.plexus.util.DirectoryScanner;
import org.codehaus.plexus.util.FileUtils;
import org.codehaus.plexus.util.StringUtils;

/**
* @deprecated Scripting support for Mojos is deprecated and is planned to be removed in Maven 4.0
Expand Down Expand Up @@ -62,7 +61,7 @@ public List<MojoDescriptor> execute(PluginToolsRequest request)
gatherFilesByBasedir(project.getBasedir(), project.getScriptSourceRoots(), scriptExtension, request);

List<MojoDescriptor> mojoDescriptors;
if (!StringUtils.isEmpty(metadataExtension)) {
if (!(metadataExtension == null || metadataExtension.isEmpty())) {
@SuppressWarnings("unchecked")
Map<String, Set<File>> metadataFilesKeyedByBasedir = gatherFilesByBasedir(
project.getBasedir(), project.getScriptSourceRoots(), metadataExtension, request);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import org.codehaus.plexus.util.StringUtils;

/**
* Describes a code reference used in javadoc tags {@code see}, {@code link} and {@code linkplain}.
* The format of the reference given as string is {@code module/package.class#member label}.
Expand Down Expand Up @@ -78,7 +76,7 @@ public static JavadocReference parse(String reference) {

private static Optional<String> getOptionalGroup(Matcher matcher, int index) {
String group = matcher.group(index);
if (StringUtils.isNotEmpty(group)) {
if (group != null && !group.isEmpty()) {
return Optional.of(group);
} else {
return Optional.empty();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@
import org.codehaus.plexus.logging.AbstractLogEnabled;
import org.codehaus.plexus.logging.Logger;
import org.codehaus.plexus.logging.console.ConsoleLogger;
import org.codehaus.plexus.util.StringUtils;

/**
* @author jdcasey
Expand Down Expand Up @@ -172,7 +171,7 @@ public void setActiveExtractors(Set<String> extractors) {
this.activeExtractors = new HashSet<>();

for (String extractor : extractors) {
if (StringUtils.isNotEmpty(extractor)) {
if (extractor != null && !extractor.isEmpty()) {
this.activeExtractors.add(extractor);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ public static String[] findSources(String basedir, String include, String exclud
DirectoryScanner scanner = new DirectoryScanner();
scanner.setBasedir(basedir);
scanner.setIncludes(new String[] {include});
if (!StringUtils.isEmpty(exclude)) {
if (!(exclude == null || exclude.isEmpty())) {
scanner.setExcludes(new String[] {exclude, StringUtils.join(FileUtils.getDefaultExcludes(), ",")});
} else {
scanner.setExcludes(FileUtils.getDefaultExcludes());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ private static String quoteReplacement(String s) {
*/
@Deprecated
static String decodeJavadocTags(String description) {
if (StringUtils.isEmpty(description)) {
if (description == null || description.isEmpty()) {
return "";
}

Expand All @@ -198,13 +198,13 @@ static String decodeJavadocTags(String description) {
Matcher link = Pattern.compile(pattern).matcher(text);
if (link.matches()) {
text = link.group(label);
if (StringUtils.isEmpty(text)) {
if (text == null || text.isEmpty()) {
text = link.group(clazz);
if (StringUtils.isEmpty(text)) {
if (text == null || text.isEmpty()) {
text = "";
}
if (StringUtils.isNotEmpty(link.group(member))) {
if (StringUtils.isNotEmpty(text)) {
if (text != null && !text.isEmpty()) {
text += '.';
}
text += link.group(member);
Expand Down Expand Up @@ -235,7 +235,7 @@ static String decodeJavadocTags(String description) {
@Deprecated
public static String makeHtmlValid(String description) {

if (StringUtils.isEmpty(description)) {
if (description == null || description.isEmpty()) {
return "";
}

Expand All @@ -258,7 +258,7 @@ public static String makeHtmlValid(String description) {
tidy.parse(new ByteArrayInputStream(commentCleaned.getBytes(StandardCharsets.UTF_8)), out);
commentCleaned = new String(out.toByteArray(), StandardCharsets.UTF_8);

if (StringUtils.isEmpty(commentCleaned)) {
if (commentCleaned == null || commentCleaned.isEmpty()) {
return "";
}

Expand Down Expand Up @@ -291,7 +291,7 @@ public static String makeHtmlValid(String description) {
*/
@Deprecated
public static String toText(String html) {
if (StringUtils.isEmpty(html)) {
if (html == null || html.isEmpty()) {
return "";
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ protected void processMojoDescriptor(

String description = mojoDescriptor.getDescription();

if (StringUtils.isNotEmpty(description)) {
if (description != null && !description.isEmpty()) {
w.startElement("description");
w.writeText(getTextValue(type, containsXhtmlTextValues, mojoDescriptor.getDescription()));
w.endElement();
Expand Down Expand Up @@ -438,7 +438,7 @@ protected void processMojoDescriptor(
for (Parameter parameter : parameters) {
String expression = getExpression(parameter);

if (StringUtils.isNotEmpty(expression) && expression.startsWith("${component.")) {
if ((expression != null && !expression.isEmpty()) && expression.startsWith("${component.")) {
// treat it as a component...a requirement, in other words.

// remove "component." plus expression delimiters
Expand Down Expand Up @@ -535,7 +535,7 @@ else if (type != DescriptorType.LIMITED_FOR_HELP_MOJO || parameter.isEditable())

// strip type by parameter type (generics) information
String parameterType = StringUtils.chomp(parameter.getType(), "<");
if (StringUtils.isNotEmpty(parameterType)) {
if (parameterType != null && !parameterType.isEmpty()) {
w.addAttribute("implementation", parameterType);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
import org.codehaus.plexus.logging.AbstractLogEnabled;
import org.codehaus.plexus.logging.Logger;
import org.codehaus.plexus.logging.console.ConsoleLogger;
import org.codehaus.plexus.util.StringUtils;
import org.codehaus.plexus.util.io.CachingOutputStream;
import org.codehaus.plexus.velocity.VelocityComponent;

Expand Down Expand Up @@ -146,7 +145,7 @@ private String getHelpClassSources(String pluginHelpPath) throws IOException {
* @return The implementation.
*/
private String getImplementation() {
return StringUtils.isEmpty(helpPackageName)
return (helpPackageName == null || helpPackageName.isEmpty())
? HELP_MOJO_CLASS_NAME
: helpPackageName + '.' + HELP_MOJO_CLASS_NAME;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,7 @@ private void writeGoalAttributes(MojoDescriptor mojoDescriptor, XMLWriter w) {
}

value = mojoDescriptor.isDependencyResolutionRequired();
if (StringUtils.isNotEmpty(value)) {
if (value != null && !value.isEmpty()) {
addedUl = addUl(w, addedUl);
w.startElement("li");
w.writeMarkup(format("pluginxdoc.mojodescriptor.dependencyResolutionRequired", value));
Expand All @@ -297,7 +297,7 @@ private void writeGoalAttributes(MojoDescriptor mojoDescriptor, XMLWriter w) {
ExtendedMojoDescriptor extendedMojoDescriptor = (ExtendedMojoDescriptor) mojoDescriptor;

value = extendedMojoDescriptor.getDependencyCollectionRequired();
if (StringUtils.isNotEmpty(value)) {
if (value != null && !value.isEmpty()) {
addedUl = addUl(w, addedUl);
w.startElement("li");
w.writeMarkup(format("pluginxdoc.mojodescriptor.dependencyCollectionRequired", value));
Expand All @@ -314,39 +314,39 @@ private void writeGoalAttributes(MojoDescriptor mojoDescriptor, XMLWriter w) {
w.endElement(); // li

value = mojoDescriptor.getSince();
if (StringUtils.isNotEmpty(value)) {
if (value != null && !value.isEmpty()) {
addedUl = addUl(w, addedUl);
w.startElement("li");
w.writeMarkup(format("pluginxdoc.mojodescriptor.since", value));
w.endElement(); // li
}

value = mojoDescriptor.getPhase();
if (StringUtils.isNotEmpty(value)) {
if (value != null && !value.isEmpty()) {
addedUl = addUl(w, addedUl);
w.startElement("li");
w.writeMarkup(format("pluginxdoc.mojodescriptor.phase", value));
w.endElement(); // li
}

value = mojoDescriptor.getExecutePhase();
if (StringUtils.isNotEmpty(value)) {
if (value != null && !value.isEmpty()) {
addedUl = addUl(w, addedUl);
w.startElement("li");
w.writeMarkup(format("pluginxdoc.mojodescriptor.executePhase", value));
w.endElement(); // li
}

value = mojoDescriptor.getExecuteGoal();
if (StringUtils.isNotEmpty(value)) {
if (value != null && !value.isEmpty()) {
addedUl = addUl(w, addedUl);
w.startElement("li");
w.writeMarkup(format("pluginxdoc.mojodescriptor.executeGoal", value));
w.endElement(); // li
}

value = mojoDescriptor.getExecuteLifecycle();
if (StringUtils.isNotEmpty(value)) {
if (value != null && !value.isEmpty()) {
addedUl = addUl(w, addedUl);
w.startElement("li");
w.writeMarkup(format("pluginxdoc.mojodescriptor.executeLifecycle", value));
Expand Down Expand Up @@ -565,7 +565,7 @@ private String getLinkedType(Parameter parameter, boolean isShortType) {
}

private boolean addUl(XMLWriter w, boolean addedUl, String content) {
if (StringUtils.isNotEmpty(content)) {
if (content != null && !content.isEmpty()) {
return addUl(w, addedUl);
}
return addedUl;
Expand All @@ -580,7 +580,7 @@ private boolean addUl(XMLWriter w, boolean addedUl) {
}

private String getPropertyFromExpression(String expression) {
if (StringUtils.isNotEmpty(expression)
if ((expression != null && !expression.isEmpty())
&& expression.startsWith("${")
&& expression.endsWith("}")
&& !expression.substring(2).contains("${")) {
Expand All @@ -597,7 +597,7 @@ private String getPropertyFromExpression(String expression) {
* @param w not null
*/
private void writeDetail(String param, String value, XMLWriter w) {
if (StringUtils.isNotEmpty(value)) {
if (value != null && !value.isEmpty()) {
w.startElement("li");
w.writeMarkup(format("pluginxdoc.detail", new String[] {param, value}));
w.endElement(); // li
Expand Down
Loading

0 comments on commit 1dcccaf

Please sign in to comment.