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

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 12, 2023
1 parent be1c8d3 commit 4e13566
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@
import org.apache.maven.project.MavenProject;
import org.apache.maven.project.ProjectBuilder;
import org.apache.maven.project.ProjectBuildingRequest;
import org.codehaus.plexus.util.StringUtils;
import org.codehaus.plexus.util.WriterFactory;
import org.eclipse.aether.RepositoryException;
import org.eclipse.aether.RepositorySystem;
Expand Down Expand Up @@ -129,7 +128,7 @@ protected static void writeFile(File output, String content) throws IOException
*/
protected org.eclipse.aether.artifact.Artifact getAetherArtifact(String artifactString, String type)
throws MojoExecutionException {
if (StringUtils.isEmpty(artifactString)) {
if (artifactString == null || artifactString.isEmpty()) {
throw new IllegalArgumentException("artifact parameter could not be empty");
}

Expand Down
40 changes: 20 additions & 20 deletions src/main/java/org/apache/maven/plugins/help/DescribeMojo.java
Original file line number Diff line number Diff line change
Expand Up @@ -213,14 +213,14 @@ public void execute() throws MojoExecutionException, MojoFailureException {
StringBuilder descriptionBuffer = new StringBuilder();

boolean describePlugin = true;
if (StringUtils.isNotEmpty(cmd)) {
if (cmd != null && !cmd.isEmpty()) {
describePlugin = describeCommand(descriptionBuffer);
}

if (describePlugin) {
PluginInfo pi = parsePluginLookupInfo();
PluginDescriptor descriptor = lookupPluginDescriptor(pi);
if (StringUtils.isNotEmpty(goal)) {
if (goal != null && !goal.isEmpty()) {
MojoDescriptor mojo = descriptor.getMojo(goal);
if (mojo == null) {
throw new MojoFailureException(
Expand Down Expand Up @@ -331,7 +331,7 @@ private PluginDescriptor lookupPluginDescriptor(PluginInfo pi) throws MojoExecut
*/
private PluginInfo parsePluginLookupInfo() throws MojoFailureException {
PluginInfo pi = new PluginInfo();
if (StringUtils.isNotEmpty(plugin)) {
if (plugin != null && !plugin.isEmpty()) {
if (plugin.indexOf(':') > -1) {
String[] pluginParts = plugin.split(":");

Expand Down Expand Up @@ -479,7 +479,7 @@ private void describeMojoGuts(MojoDescriptor md, StringBuilder buffer, boolean f
deprecation = NO_REASON;
}

if (StringUtils.isNotEmpty(deprecation)) {
if (deprecation != null && !deprecation.isEmpty()) {
append(
buffer,
MessageUtils.buffer().warning("Deprecated. " + deprecation).toString(),
Expand All @@ -498,25 +498,25 @@ private void describeMojoGuts(MojoDescriptor md, StringBuilder buffer, boolean f
append(buffer, "Language", md.getLanguage(), 1);

String phase = md.getPhase();
if (StringUtils.isNotEmpty(phase)) {
if (phase != null && !phase.isEmpty()) {
append(buffer, "Bound to phase", phase, 1);
}

String eGoal = md.getExecuteGoal();
String eLife = md.getExecuteLifecycle();
String ePhase = md.getExecutePhase();

if (StringUtils.isNotEmpty(eGoal) || StringUtils.isNotEmpty(ePhase)) {
if ((eGoal != null && !eGoal.isEmpty()) || (ePhase != null && !ePhase.isEmpty())) {
append(buffer, "Before this goal executes, it will call:", 1);

if (StringUtils.isNotEmpty(eGoal)) {
if (eGoal != null && !eGoal.isEmpty()) {
append(buffer, "Single goal", "'" + eGoal + "'", 2);
}

if (StringUtils.isNotEmpty(ePhase)) {
if (ePhase != null && !ePhase.isEmpty()) {
String s = "Phase: '" + ePhase + "'";

if (StringUtils.isNotEmpty(eLife)) {
if (eLife != null && !eLife.isEmpty()) {
s += " in Lifecycle Overlay: '" + eLife + "'";
}

Expand Down Expand Up @@ -568,15 +568,15 @@ private void describeMojoParameters(MojoDescriptor md, StringBuilder buffer)
md.getMojoConfiguration().getChild(parameter.getName()).getAttribute("default-value", null);
}

if (StringUtils.isNotEmpty(defaultVal)) {
if (defaultVal != null && !defaultVal.isEmpty()) {
defaultVal = " (Default: " + MessageUtils.buffer().strong(defaultVal) + ")";
} else {
defaultVal = "";
}
append(buffer, MessageUtils.buffer().strong(parameter.getName()) + defaultVal, 2);

String alias = parameter.getAlias();
if (!StringUtils.isEmpty(alias)) {
if (!(alias == null || alias.isEmpty())) {
append(buffer, "Alias", alias, 3);
}

Expand All @@ -585,13 +585,13 @@ private void describeMojoParameters(MojoDescriptor md, StringBuilder buffer)
}

String expression = parameter.getExpression();
if (StringUtils.isEmpty(expression)) {
if (expression == null || expression.isEmpty()) {
// expression is ALWAYS null, this is a bug in PluginDescriptorBuilder (cf. MNG-4941).
// Fixed with Maven-3.0.1
expression =
md.getMojoConfiguration().getChild(parameter.getName()).getValue(null);
}
if (StringUtils.isNotEmpty(expression)) {
if (expression != null && !expression.isEmpty()) {
Matcher matcher = EXPRESSION.matcher(expression);
if (matcher.matches()) {
append(buffer, "User property", matcher.group(1), 3);
Expand All @@ -607,7 +607,7 @@ private void describeMojoParameters(MojoDescriptor md, StringBuilder buffer)
deprecation = NO_REASON;
}

if (StringUtils.isNotEmpty(deprecation)) {
if (deprecation != null && !deprecation.isEmpty()) {
append(
buffer,
MessageUtils.buffer()
Expand Down Expand Up @@ -663,7 +663,7 @@ private boolean describeCommand(StringBuilder descriptionBuffer) throws MojoExec
for (String key : phases) {
descriptionBuffer.append("* ").append(key).append(": ");
String value = defaultLifecyclePhases.get(key);
if (StringUtils.isNotEmpty(value)) {
if (value != null && !value.isEmpty()) {
for (StringTokenizer tok = new StringTokenizer(value, ","); tok.hasMoreTokens(); ) {
descriptionBuffer.append(tok.nextToken().trim());

Expand Down Expand Up @@ -774,7 +774,7 @@ private static List<String> toLines(String text, int indent, int indentSize, int
*/
private static void append(StringBuilder sb, String description, int indent)
throws MojoFailureException, MojoExecutionException {
if (StringUtils.isEmpty(description)) {
if (description == null || description.isEmpty()) {
sb.append(UNKNOWN).append(LS);
return;
}
Expand All @@ -798,11 +798,11 @@ private static void append(StringBuilder sb, String description, int indent)
*/
private static void append(StringBuilder sb, String key, String value, int indent)
throws MojoFailureException, MojoExecutionException {
if (StringUtils.isEmpty(key)) {
if (key == null || key.isEmpty()) {
throw new IllegalArgumentException("Key is required!");
}

if (StringUtils.isEmpty(value)) {
if (value == null || value.isEmpty()) {
value = UNKNOWN;
}

Expand All @@ -827,7 +827,7 @@ private static void append(StringBuilder sb, String key, String value, int inden
*/
private static void appendAsParagraph(StringBuilder sb, String key, String value, int indent)
throws MojoFailureException, MojoExecutionException {
if (StringUtils.isEmpty(value)) {
if (value == null || value.isEmpty()) {
value = UNKNOWN;
}

Expand Down Expand Up @@ -891,7 +891,7 @@ private boolean isReportGoal(MojoDescriptor md) {
* @return The effective description string, never <code>null</code>.
*/
private static String toDescription(String description) {
if (StringUtils.isNotEmpty(description)) {
if (description != null && !description.isEmpty()) {
return new HtmlToPlainTextConverter().convert(description);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ public class EffectivePomMojo extends AbstractEffectiveMojo {

/** {@inheritDoc} */
public void execute() throws MojoExecutionException {
if (StringUtils.isNotEmpty(artifact)) {
if (artifact != null && !artifact.isEmpty()) {
project = getMavenProject(artifact);
projects = Collections.singletonList(project);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ private static String getHostName() {
*/
private static String getUserName() {
String userName = System.getProperty("user.name");
if (StringUtils.isEmpty(userName)) {
if (userName == null || userName.isEmpty()) {
return "unknown";
}

Expand Down
8 changes: 4 additions & 4 deletions src/main/java/org/apache/maven/plugins/help/EvaluateMojo.java
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ public void execute() throws MojoExecutionException, MojoFailureException {

validateParameters();

if (StringUtils.isNotEmpty(artifact)) {
if (artifact != null && !artifact.isEmpty()) {
project = getMavenProject(artifact);
}

Expand Down Expand Up @@ -453,8 +453,8 @@ private void addAlias(XStream xstreamObject, File jarFile, String packageFilter)
private File getArtifactFile(String artifactId) throws MojoExecutionException, RepositoryException {
List<Dependency> dependencies = getHelpPluginPom().getDependencies();
for (Dependency dependency : dependencies) {
if (("org.apache.maven".equals(dependency.getGroupId()))) {
if ((artifactId.equals(dependency.getArtifactId()))) {
if ("org.apache.maven".equals(dependency.getGroupId())) {
if (artifactId.equals(dependency.getArtifactId())) {
Artifact mavenArtifact = new DefaultArtifact(
dependency.getGroupId(), dependency.getArtifactId(), "jar", dependency.getVersion());

Expand Down Expand Up @@ -498,7 +498,7 @@ private MavenProject getHelpPluginPom() throws MojoExecutionException {
* @return the plural of the name
*/
private static String pluralize(String name) {
if (StringUtils.isEmpty(name)) {
if (name == null || name.isEmpty()) {
throw new IllegalArgumentException("name is required");
}

Expand Down

0 comments on commit 4e13566

Please sign in to comment.