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 any StringUtils#isEmpty(String) and #isNotEmpty(String) #1104

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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
import org.codehaus.plexus.component.annotations.Requirement;
import org.codehaus.plexus.personality.plexus.lifecycle.phase.Initializable;
import org.codehaus.plexus.personality.plexus.lifecycle.phase.InitializationException;
import org.codehaus.plexus.util.StringUtils;

/**
* Describes runtime information about the application.
Expand All @@ -47,7 +46,7 @@ public ArtifactVersion getApplicationVersion() {
public void initialize() throws InitializationException {
String mavenVersion = rtInfo.getMavenVersion();

if (StringUtils.isEmpty(mavenVersion)) {
if (mavenVersion == null || mavenVersion.isEmpty()) {
throw new InitializationException("Unable to read Maven version from maven-core");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,15 +61,15 @@ public boolean isActive(Profile profile) {
interpolator.addValueSource(new MapBasedValueSource(System.getProperties()));

try {
if (StringUtils.isNotEmpty(fileString)) {
if (fileString != null && !fileString.isEmpty()) {
fileString = StringUtils.replace(interpolator.interpolate(fileString, ""), "\\", "/");
return FileUtils.fileExists(fileString);
}

// check if the file is missing, if it is then the profile will be active
fileString = actFile.getMissing();

if (StringUtils.isNotEmpty(fileString)) {
if (fileString != null && !fileString.isEmpty()) {
fileString = StringUtils.replace(interpolator.interpolate(fileString, ""), "\\", "/");
return !FileUtils.fileExists(fileString);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
import org.codehaus.plexus.context.Context;
import org.codehaus.plexus.context.ContextException;
import org.codehaus.plexus.personality.plexus.lifecycle.phase.Contextualizable;
import org.codehaus.plexus.util.StringUtils;

/**
* SystemPropertyProfileActivator
Expand Down Expand Up @@ -65,7 +64,7 @@ public boolean isActive(Profile profile) throws ProfileActivationException {
String sysValue = properties.getProperty(name);

String propValue = property.getValue();
if (StringUtils.isNotEmpty(propValue)) {
if (propValue != null && !propValue.isEmpty()) {
boolean reverseValue = false;
if (propValue.startsWith("!")) {
reverseValue = true;
Expand All @@ -81,7 +80,7 @@ public boolean isActive(Profile profile) throws ProfileActivationException {
return result;
}
} else {
boolean result = StringUtils.isNotEmpty(sysValue);
boolean result = sysValue != null && !sysValue.isEmpty();

if (reverseName) {
return !result;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
import org.apache.maven.artifact.repository.ArtifactRepository;
import org.apache.maven.settings.Mirror;
import org.codehaus.plexus.component.annotations.Component;
import org.codehaus.plexus.util.StringUtils;

/**
* DefaultMirrorSelector
Expand Down Expand Up @@ -173,7 +172,7 @@ static boolean matchesLayout(String repoLayout, String mirrorLayout) {
boolean result = false;

// simple checks first to short circuit processing below.
if (StringUtils.isEmpty(mirrorLayout) || WILDCARD.equals(mirrorLayout)) {
if ((mirrorLayout == null || mirrorLayout.isEmpty()) || WILDCARD.equals(mirrorLayout)) {
result = true;
} else if (mirrorLayout.equals(repoLayout)) {
result = true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ public Artifact createParentArtifact(String groupId, String artifactId, String v

public Artifact createPluginArtifact(Plugin plugin) {
String version = plugin.getVersion();
if (StringUtils.isEmpty(version)) {
if (version == null || version.isEmpty()) {
version = "RELEASE";
}

Expand Down Expand Up @@ -683,13 +683,13 @@ public ArtifactRepository buildArtifactRepository(Repository repo) throws Invali
if (repo != null) {
String id = repo.getId();

if (StringUtils.isEmpty(id)) {
if (id == null || id.isEmpty()) {
throw new InvalidRepositoryException("Repository identifier missing", "");
}

String url = repo.getUrl();

if (StringUtils.isEmpty(url)) {
if (url == null || url.isEmpty()) {
throw new InvalidRepositoryException("URL missing for repository " + id, id);
}

Expand Down Expand Up @@ -738,7 +738,7 @@ private static String getMessage(Throwable error, String def) {
return def;
}
String msg = error.getMessage();
if (StringUtils.isNotEmpty(msg)) {
if (msg != null && !msg.isEmpty()) {
return msg;
}
return getMessage(error.getCause(), def);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ public Artifact createPluginArtifact(Plugin plugin) {
VersionRange versionRange;
try {
String version = plugin.getVersion();
if (StringUtils.isEmpty(version)) {
if (version == null || version.isEmpty()) {
version = "RELEASE";
}
versionRange = VersionRange.createFromVersionSpec(version);
Expand Down Expand Up @@ -323,13 +323,13 @@ public static ArtifactRepository buildArtifactRepository(org.apache.maven.model.
if (repo != null) {
String id = repo.getId();

if (StringUtils.isEmpty(id)) {
if (id == null || id.isEmpty()) {
throw new InvalidRepositoryException("Repository identifier missing", "");
}

String url = repo.getUrl();

if (StringUtils.isEmpty(url)) {
if (url == null || url.isEmpty()) {
throw new InvalidRepositoryException("URL missing for repository " + id, id);
}

Expand Down Expand Up @@ -787,7 +787,7 @@ static boolean matchesLayout(String repoLayout, String mirrorLayout) {
boolean result = false;

// simple checks first to short circuit processing below.
if (StringUtils.isEmpty(mirrorLayout) || WILDCARD.equals(mirrorLayout)) {
if ((mirrorLayout == null || mirrorLayout.isEmpty()) || WILDCARD.equals(mirrorLayout)) {
result = true;
} else if (mirrorLayout.equals(repoLayout)) {
result = true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@
import org.codehaus.plexus.classworlds.ClassWorld;
import org.codehaus.plexus.classworlds.realm.ClassRealm;
import org.codehaus.plexus.classworlds.realm.DuplicateRealmException;
import org.codehaus.plexus.util.StringUtils;
import org.eclipse.aether.artifact.Artifact;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand Down Expand Up @@ -272,7 +271,7 @@ private static String getId(ClassRealmConstituent constituent) {
}

private static String getId(String gid, String aid, String type, String cls, String ver) {
return gid + ':' + aid + ':' + type + (StringUtils.isNotEmpty(cls) ? ':' + cls : "") + ':' + ver;
return gid + ':' + aid + ':' + type + ((cls != null && !cls.isEmpty()) ? ':' + cls : "") + ':' + ver;
}

private void callDelegates(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@
import org.apache.maven.plugin.PluginExecutionException;
import org.apache.maven.project.ProjectBuildingException;
import org.apache.maven.project.ProjectBuildingResult;
import org.codehaus.plexus.util.StringUtils;

/*

Expand Down Expand Up @@ -190,11 +189,11 @@ private String getReference(Throwable exception) {
}
}

if (StringUtils.isEmpty(reference)) {
if (reference == null || reference.isEmpty()) {
reference = getReference(cause);
}

if (StringUtils.isEmpty(reference)) {
if (reference == null || reference.isEmpty()) {
reference = exception.getClass().getSimpleName();
}
} else if (exception instanceof LifecycleExecutionException) {
Expand All @@ -204,7 +203,7 @@ private String getReference(Throwable exception) {
}
}

if (StringUtils.isNotEmpty(reference) && !reference.startsWith("http:")) {
if ((reference != null && !reference.isEmpty()) && !reference.startsWith("http:")) {
reference = "http://cwiki.apache.org/confluence/display/MAVEN/" + reference;
}

Expand All @@ -231,16 +230,17 @@ private String getMessage(String message, Throwable exception) {

if (t instanceof AbstractMojoExecutionException) {
String longMessage = ((AbstractMojoExecutionException) t).getLongMessage();
if (StringUtils.isNotEmpty(longMessage)) {
if (StringUtils.isEmpty(exceptionMessage) || longMessage.contains(exceptionMessage)) {
if (longMessage != null && !longMessage.isEmpty()) {
if ((exceptionMessage == null || exceptionMessage.isEmpty())
|| longMessage.contains(exceptionMessage)) {
exceptionMessage = longMessage;
} else if (!exceptionMessage.contains(longMessage)) {
exceptionMessage = join(exceptionMessage, System.lineSeparator() + longMessage);
}
}
}

if (StringUtils.isEmpty(exceptionMessage)) {
if (exceptionMessage == null || exceptionMessage.isEmpty()) {
exceptionMessage = t.getClass().getSimpleName();
}

Expand All @@ -257,12 +257,12 @@ private String getMessage(String message, Throwable exception) {
private String join(String message1, String message2) {
String message = "";

if (StringUtils.isNotEmpty(message1)) {
if (message1 != null && !message1.isEmpty()) {
message = message1.trim();
}

if (StringUtils.isNotEmpty(message2)) {
if (StringUtils.isNotEmpty(message)) {
if (message2 != null && !message2.isEmpty()) {
if (message != null && !message.isEmpty()) {
if (message.endsWith(".") || message.endsWith("!") || message.endsWith(":")) {
message += " ";
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@
import org.apache.maven.settings.SettingsUtils;
import org.apache.maven.toolchain.model.PersistedToolchains;
import org.apache.maven.toolchain.model.ToolchainModel;
import org.codehaus.plexus.util.StringUtils;

/**
* Assists in populating an execution request for invocation of Maven.
Expand Down Expand Up @@ -157,7 +156,7 @@ private ArtifactRepository createLocalRepository(MavenExecutionRequest request)
localRepositoryPath = request.getLocalRepositoryPath().getAbsolutePath();
}

if (StringUtils.isEmpty(localRepositoryPath)) {
if (localRepositoryPath == null || localRepositoryPath.isEmpty()) {
localRepositoryPath = RepositorySystem.defaultUserLocalRepository.getAbsolutePath();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ private List<MavenProject> includeAlsoMakeTransitively(
boolean makeUpstream = makeBoth || MavenExecutionRequest.REACTOR_MAKE_UPSTREAM.equals(makeBehavior);
boolean makeDownstream = makeBoth || MavenExecutionRequest.REACTOR_MAKE_DOWNSTREAM.equals(makeBehavior);

if (StringUtils.isNotEmpty(makeBehavior) && !makeUpstream && !makeDownstream) {
if ((makeBehavior != null && !makeBehavior.isEmpty()) && !makeUpstream && !makeDownstream) {
throw new MavenExecutionException("Invalid reactor make behavior: " + makeBehavior, request.getPom());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -454,7 +454,7 @@ private void injectLifecycleOverlay(

String forkedLifecycle = mojoDescriptor.getExecuteLifecycle();

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@
import org.apache.maven.project.MavenProject;
import org.apache.maven.shared.utils.logging.MessageBuilder;
import org.apache.maven.shared.utils.logging.MessageUtils;
import org.codehaus.plexus.util.StringUtils;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, looks like it is sometimes removing an import. That's good.

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand Down Expand Up @@ -98,7 +97,7 @@ private Plugin findPlugin(String groupId, String artifactId, Collection<Plugin>
}

private PluginExecution findPluginExecution(String executionId, Collection<PluginExecution> executions) {
if (StringUtils.isNotEmpty(executionId)) {
if (executionId != null && !executionId.isEmpty()) {
for (PluginExecution execution : executions) {
if (executionId.equals(execution.getId())) {
return execution;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
import org.apache.maven.plugin.MojoExecution;
import org.apache.maven.plugin.descriptor.MojoDescriptor;
import org.apache.maven.project.MavenProject;
import org.codehaus.plexus.util.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand Down Expand Up @@ -137,12 +136,12 @@ private void debugDependencyRequirements(List<MojoExecution> mojoExecutions) {
MojoDescriptor mojoDescriptor = mojoExecution.getMojoDescriptor();

String scopeToCollect = mojoDescriptor.getDependencyCollectionRequired();
if (StringUtils.isNotEmpty(scopeToCollect)) {
if (scopeToCollect != null && !scopeToCollect.isEmpty()) {
scopesToCollect.add(scopeToCollect);
}

String scopeToResolve = mojoDescriptor.getDependencyResolutionRequired();
if (StringUtils.isNotEmpty(scopeToResolve)) {
if (scopeToResolve != null && !scopeToResolve.isEmpty()) {
scopesToResolve.add(scopeToResolve);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@
import org.apache.maven.plugin.PluginManagerException;
import org.apache.maven.plugin.descriptor.MojoDescriptor;
import org.apache.maven.project.MavenProject;
import org.codehaus.plexus.util.StringUtils;
import org.eclipse.aether.SessionData;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand Down Expand Up @@ -126,7 +125,7 @@ private void collectDependencyRequirements(
private Collection<String> toScopes(String classpath) {
Collection<String> scopes = Collections.emptyList();

if (StringUtils.isNotEmpty(classpath)) {
if (classpath != null && !classpath.isEmpty()) {
if (Artifact.SCOPE_COMPILE.equals(classpath)) {
scopes = Arrays.asList(Artifact.SCOPE_COMPILE, Artifact.SCOPE_SYSTEM, Artifact.SCOPE_PROVIDED);
} else if (Artifact.SCOPE_RUNTIME.equals(classpath)) {
Expand Down Expand Up @@ -398,10 +397,10 @@ private ArtifactFilter getArtifactFilter(MojoDescriptor mojoDescriptor) {
String scopeToCollect = mojoDescriptor.getDependencyCollectionRequired();

List<String> scopes = new ArrayList<>(2);
if (StringUtils.isNotEmpty(scopeToCollect)) {
if (scopeToCollect != null && !scopeToCollect.isEmpty()) {
scopes.add(scopeToCollect);
}
if (StringUtils.isNotEmpty(scopeToResolve)) {
if (scopeToResolve != null && !scopeToResolve.isEmpty()) {
scopes.add(scopeToResolve);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public void setMojos(List<LifecycleMojo> mojos) {
public void set(String goals) {
mojos = new ArrayList<>();

if (StringUtils.isNotEmpty(goals)) {
if (goals != null && !goals.isEmpty()) {
String[] mojoGoals = StringUtils.split(goals, ",");

for (String mojoGoal : mojoGoals) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@

import org.apache.maven.plugin.descriptor.MojoDescriptor;
import org.apache.maven.plugin.descriptor.Parameter;
import org.codehaus.plexus.util.StringUtils;

/**
* PluginParameterException
Expand Down Expand Up @@ -123,7 +122,7 @@ private static void decomposeParameterIntoUserInstructions(
messageBuffer.append("</configuration>");

String alias = param.getAlias();
if (StringUtils.isNotEmpty(alias) && !alias.equals(param.getName())) {
if ((alias != null && !alias.isEmpty()) && !alias.equals(param.getName())) {
messageBuffer.append(LS).append(LS).append("-OR-").append(LS).append(LS);
messageBuffer
.append("<configuration>")
Expand All @@ -142,7 +141,7 @@ private static void decomposeParameterIntoUserInstructions(
}
}

if (StringUtils.isEmpty(expression)) {
if (expression == null || expression.isEmpty()) {
messageBuffer.append('.');
} else {
if (param.isEditable()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -631,7 +631,7 @@ private void populateMojoExecutionFields(

String configuratorId = mojoDescriptor.getComponentConfigurator();

if (StringUtils.isEmpty(configuratorId)) {
if (configuratorId == null || configuratorId.isEmpty()) {
configuratorId = mojoDescriptor.isV4Api() ? "enhanced" : "basic";
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -169,10 +169,10 @@ private void selectVersion(DefaultPluginVersionResult result, PluginVersionReque
String version = null;
ArtifactRepository repo = null;

if (StringUtils.isNotEmpty(versions.releaseVersion)) {
if (versions.releaseVersion != null && !versions.releaseVersion.isEmpty()) {
version = versions.releaseVersion;
repo = versions.releaseRepository;
} else if (StringUtils.isNotEmpty(versions.latestVersion)) {
} else if (versions.latestVersion != null && !versions.latestVersion.isEmpty()) {
version = versions.latestVersion;
repo = versions.latestRepository;
}
Expand Down
Loading