Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[MNG-6829] Replace StringUtils#isEmpty(String) and #isNotEmpty(String) #272

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
import org.apache.maven.artifact.repository.ArtifactRepository;
import org.apache.maven.enforcer.rule.api.EnforcerRuleException;
import org.apache.maven.project.MavenProject;
import org.codehaus.plexus.util.StringUtils;

/**
* This rule checks that this project's maven session whether have banned repositories.
Expand Down Expand Up @@ -91,7 +90,7 @@ public void execute() throws EnforcerRuleException {

String errMsg = repoErrMsg + pluginRepoErrMsg;

if (errMsg != null && !StringUtils.isEmpty(errMsg)) {
if (errMsg != null && !errMsg.isEmpty()) {
throw new EnforcerRuleException(errMsg);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
import org.apache.maven.enforcer.rule.api.EnforcerRuleException;
import org.codehaus.plexus.component.configurator.expression.ExpressionEvaluationException;
import org.codehaus.plexus.component.configurator.expression.ExpressionEvaluator;
import org.codehaus.plexus.util.StringUtils;

/**
* Rule for Maven Enforcer using Beanshell to evaluate a conditional expression.
Expand Down Expand Up @@ -70,7 +69,7 @@ public void execute() throws EnforcerRuleException {
getLog().debug("Echo script : " + script);
if (!evaluateCondition(script)) {
String message = getMessage();
if (StringUtils.isEmpty(message)) {
if (message == null || message.isEmpty()) {
message = "The expression \"" + condition + "\" is not true.";
}
throw new EnforcerRuleException(message);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@

import org.apache.maven.enforcer.rule.api.EnforcerRuleException;
import org.apache.maven.project.MavenProject;
import org.codehaus.plexus.util.StringUtils;

/**
* This rule checks that some profiles are active.
Expand Down Expand Up @@ -72,7 +71,7 @@ public void setAll(boolean all) {
@Override
public void execute() throws EnforcerRuleException {
List<String> missingProfiles = new ArrayList<>();
if (StringUtils.isNotEmpty(profiles)) {
if (profiles != null && !profiles.isEmpty()) {
String[] profileIds = profiles.split(",");
for (String profileId : profileIds) {
if (!isProfileActive(project, profileId)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,16 +103,16 @@ public void execute() throws EnforcerRuleException {
if (isValidFamily(this.family)) {
if (!isAllowed()) {
String message = getMessage();
if (StringUtils.isEmpty(message)) {
if (message == null || message.isEmpty()) {
// @formatter:off
message = ("OS Arch: "
message = "OS Arch: "
+ Os.OS_ARCH + " Family: "
+ Os.OS_FAMILY + " Name: "
+ Os.OS_NAME + " Version: "
+ Os.OS_VERSION + " is not allowed by" + (arch != null ? " Arch=" + arch : "")
+ (family != null ? " Family=" + family : "")
+ (name != null ? " Name=" + name : "")
+ (version != null ? " Version=" + version : ""));
+ (version != null ? " Version=" + version : "");
// @formatter:on
}
throw new EnforcerRuleException(message);
Expand Down Expand Up @@ -152,10 +152,10 @@ public boolean isAllowed() {
* @return true if all parameters are empty.
*/
public boolean allParamsEmpty() {
return (StringUtils.isEmpty(family)
&& StringUtils.isEmpty(arch)
&& StringUtils.isEmpty(name)
&& StringUtils.isEmpty(version));
return (family == null || family.isEmpty())
&& (arch == null || arch.isEmpty())
&& (name == null || name.isEmpty())
&& (version == null || version.isEmpty());
}

/**
Expand Down Expand Up @@ -221,7 +221,8 @@ public boolean isValidFamily(String theFamily) {
// in case they are checking !family
theFamily = StringUtils.stripStart(theFamily, "!");

return (StringUtils.isEmpty(theFamily) || Os.getValidFamilies().contains(theFamily));
return (theFamily == null || theFamily.isEmpty())
|| Os.getValidFamilies().contains(theFamily);
}

/**
Expand Down Expand Up @@ -271,16 +272,16 @@ public void setDisplay(boolean display) {
public String getCacheId() {
// return the hashcodes of all the parameters
StringBuilder b = new StringBuilder();
if (StringUtils.isNotEmpty(version)) {
if (version != null && !version.isEmpty()) {
b.append(version.hashCode());
}
if (StringUtils.isNotEmpty(name)) {
if (name != null && !name.isEmpty()) {
b.append(name.hashCode());
}
if (StringUtils.isNotEmpty(arch)) {
if (arch != null && !arch.isEmpty()) {
b.append(arch.hashCode());
}
if (StringUtils.isNotEmpty(family)) {
if (family != null && !family.isEmpty()) {
b.append(family.hashCode());
}
return b.toString();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,7 @@ private void handleMessagesToTheUser(MavenProject project, List<Plugin> failures
newMsg.append(System.lineSeparator());
}
String message = getMessage();
if (StringUtils.isNotEmpty(message)) {
if (message != null && !message.isEmpty()) {
newMsg.append(message);
}

Expand Down Expand Up @@ -347,7 +347,7 @@ Set<Plugin> removeUncheckedPlugins(Collection<String> uncheckedPlugins, Set<Plug
public Collection<String> combineUncheckedPlugins(
Collection<String> uncheckedPlugins, String uncheckedPluginsList) {
// if the comma list is empty, then there's nothing to do here.
if (StringUtils.isNotEmpty(uncheckedPluginsList)) {
if (uncheckedPluginsList != null && !uncheckedPluginsList.isEmpty()) {
// make sure there is a collection to add to.
if (uncheckedPlugins == null) {
uncheckedPlugins = new HashSet<>();
Expand Down Expand Up @@ -489,7 +489,7 @@ private Set<Plugin> getBoundPlugins(MavenProject project, String thePhases)
String[] lifecyclePhases = thePhases.split(",");
for (int i = 0; i < lifecyclePhases.length; i++) {
String lifecyclePhase = lifecyclePhases[i];
if (StringUtils.isNotEmpty(lifecyclePhase)) {
if (lifecyclePhase != null && !lifecyclePhase.isEmpty()) {
try {
Lifecycle lifecycle = getLifecycleForPhase(lifecyclePhase);
getLog().debug("getBoundPlugins(): " + project.getId() + " " + lifecyclePhase + " "
Expand Down Expand Up @@ -561,7 +561,7 @@ public boolean hasValidVersionSpecified(Plugin source, List<PluginWrapper> plugi
}

private boolean isValidVersion(String version) {
return StringUtils.isNotEmpty(version) && !StringUtils.isWhitespace(version);
return (version != null && !version.isEmpty()) && !StringUtils.isWhitespace(version);
}

private boolean isMatchingPlugin(Plugin source, PluginWrapper plugin) {
Expand Down Expand Up @@ -610,7 +610,7 @@ private Set<Plugin> getAllPlugins(MavenProject project, Lifecycle lifecycle)
getLog().debug(" lifecycleMapping = " + entry.getKey());
String pluginsForLifecycle = (String) entry.getValue();
getLog().debug(" plugins = " + pluginsForLifecycle);
if (StringUtils.isNotEmpty(pluginsForLifecycle)) {
if (pluginsForLifecycle != null && !pluginsForLifecycle.isEmpty()) {
String pluginList[] = pluginsForLifecycle.split(",");
for (String plugin : pluginList) {
plugin = StringUtils.strip(plugin);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
import org.apache.maven.artifact.versioning.VersionRange;
import org.apache.maven.enforcer.rule.api.EnforcerRuleException;
import org.apache.maven.enforcer.rules.AbstractStandardEnforcerRule;
import org.codehaus.plexus.util.StringUtils;

import static org.apache.maven.enforcer.rules.utils.ArtifactMatcher.containsVersion;

Expand Down Expand Up @@ -62,7 +61,7 @@ public void enforceVersion(String variableName, String requiredVersionRange, Art
throws EnforcerRuleException
// CHECKSTYLE_ON: LineLength
{
if (StringUtils.isEmpty(requiredVersionRange)) {
if (requiredVersionRange == null || requiredVersionRange.isEmpty()) {
throw new EnforcerRuleException(variableName + " version can't be empty.");
} else {

Expand All @@ -81,7 +80,7 @@ public void enforceVersion(String variableName, String requiredVersionRange, Art
} else {
String message = getMessage();

if (StringUtils.isEmpty(message)) {
if (message == null || message.isEmpty()) {
message = msg + " is not in the allowed range " + toString(vr) + ".";
}

Expand All @@ -106,7 +105,7 @@ protected static String toString(VersionRange vr) {

@Override
public String getCacheId() {
if (StringUtils.isNotEmpty(version)) {
if (version != null && !version.isEmpty()) {
// return the hashcodes of the parameter that matters
return "" + version.hashCode();
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ public static String normalizeJDKVersion(String theJdkVersion) {
String section = iter.next();
section = section.replaceAll("[^0-9]", "");

if (StringUtils.isNotEmpty(section)) {
if (section != null && !section.isEmpty()) {
buffer.append(Integer.parseInt(section));

if (i != 2) {
Expand Down