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) #185

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 @@ -198,21 +198,21 @@ protected static String getVersionString(Version info, String buildSpecifier, St
sb.append(joinDigitString(info.digits));
}

if (StringUtils.isNotEmpty(info.annotation)) {
if (info.annotation != null && !info.annotation.isEmpty()) {
sb.append(StringUtils.defaultString(info.annotationSeparator));
sb.append(info.annotation);
}

if (StringUtils.isNotEmpty(info.annotationRevision)) {
if (StringUtils.isEmpty(info.annotation)) {
if (info.annotationRevision != null && !info.annotationRevision.isEmpty()) {
if (info.annotation == null || info.annotation.isEmpty()) {
sb.append(StringUtils.defaultString(info.annotationSeparator));
} else {
sb.append(StringUtils.defaultString(info.annotationRevSeparator));
}
sb.append(info.annotationRevision);
}

if (StringUtils.isNotEmpty(buildSpecifier)) {
if (buildSpecifier != null && !buildSpecifier.isEmpty()) {
sb.append(StringUtils.defaultString(buildSeparator));
sb.append(buildSpecifier);
}
Expand Down Expand Up @@ -240,7 +240,7 @@ private List<String> parseDigits(String strDigits) {
}

private static String nullIfEmpty(String s) {
return StringUtils.isEmpty(s) ? null : s;
return (s == null || s.isEmpty()) ? null : s;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@
import org.apache.maven.shared.release.phase.ReleasePhase;
import org.apache.maven.shared.release.phase.ResourceGenerator;
import org.apache.maven.shared.release.strategy.Strategy;
import org.codehaus.plexus.util.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand Down Expand Up @@ -459,7 +458,7 @@ public ReleaseDescriptorBuilder addReleaseVersion(String key, String value) {
* @return The working directory
*/
protected File determineWorkingDirectory(File checkoutDirectory, String relativePathProjectDirectory) {
if (StringUtils.isNotEmpty(relativePathProjectDirectory)) {
if (relativePathProjectDirectory != null && !relativePathProjectDirectory.isEmpty()) {
return new File(checkoutDirectory, relativePathProjectDirectory);
} else {
return checkoutDirectory;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@
import org.apache.maven.shared.release.ReleaseResult;
import org.apache.maven.shared.release.env.ReleaseEnvironment;
import org.apache.maven.shared.release.util.MavenCrypto;
import org.codehaus.plexus.util.StringUtils;
import org.codehaus.plexus.util.cli.CommandLineException;
import org.codehaus.plexus.util.cli.Commandline;

Expand Down Expand Up @@ -128,7 +127,7 @@ public void executeGoals(
cl.createArg().setValue("--batch-mode");
}

if (!StringUtils.isEmpty(additionalArguments)) {
if (!(additionalArguments == null || additionalArguments.isEmpty())) {
cl.createArg().setLine(additionalArguments);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@
import org.codehaus.plexus.interpolation.PrefixedPropertiesValueSource;
import org.codehaus.plexus.interpolation.RecursionInterceptor;
import org.codehaus.plexus.interpolation.StringSearchInterpolator;
import org.codehaus.plexus.util.StringUtils;

import static java.util.Objects.requireNonNull;
import static org.apache.maven.shared.utils.logging.MessageUtils.buffer;
Expand Down Expand Up @@ -201,7 +200,7 @@ public ReleaseResult execute(
tag = prompter.get()
.prompt("What is the branch name for \"" + project.getName() + "\"? ("
+ buffer().project(project.getArtifactId()) + ")");
if (StringUtils.isEmpty(tag)) {
if (tag == null || tag.isEmpty()) {
throw new ReleaseExecutionException("No branch name was given.");
}
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@
import org.apache.maven.shared.release.versions.VersionParseException;
import org.codehaus.plexus.components.interactivity.Prompter;
import org.codehaus.plexus.components.interactivity.PrompterException;
import org.codehaus.plexus.util.StringUtils;
import org.slf4j.Logger;

import static java.util.Objects.requireNonNull;
Expand Down Expand Up @@ -336,11 +335,11 @@ private String resolveSuggestedVersion(
private String getDevelopmentVersion(String projectId, ReleaseDescriptor releaseDescriptor) {
String projectVersion = releaseDescriptor.getProjectDevelopmentVersion(projectId);

if (StringUtils.isEmpty(projectVersion)) {
if (projectVersion == null || projectVersion.isEmpty()) {
projectVersion = releaseDescriptor.getDefaultDevelopmentVersion();
}

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

Expand All @@ -350,11 +349,11 @@ private String getDevelopmentVersion(String projectId, ReleaseDescriptor release
private String getReleaseVersion(String projectId, ReleaseDescriptor releaseDescriptor) {
String projectVersion = releaseDescriptor.getProjectReleaseVersion(projectId);

if (StringUtils.isEmpty(projectVersion)) {
if (projectVersion == null || projectVersion.isEmpty()) {
projectVersion = releaseDescriptor.getDefaultReleaseVersion();
}

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

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

private void rewriteBuildOutputTimestampProperty(Properties properties, ReleaseResult result) {
String buildOutputTimestamp = properties.getProperty("project.build.outputTimestamp");
if (buildOutputTimestamp == null || StringUtils.isEmpty(buildOutputTimestamp)) {
if (buildOutputTimestamp == null || (buildOutputTimestamp == null || buildOutputTimestamp.isEmpty())) {
// no Reproducible Builds output timestamp defined
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ protected ReleaseResult execute(

try {
String goals = getGoals(releaseDescriptor);
if (!StringUtils.isEmpty(goals)) {
if (!(goals == null || goals.isEmpty())) {
logInfo(result, "Executing goals '" + buffer().strong(goals) + "'...");
if (logArguments) {
// logging arguments may log secrets: should be activated only on dryRun
Expand Down Expand Up @@ -151,7 +151,7 @@ protected String getAdditionalArguments(ReleaseDescriptor releaseDescriptor) {
protected File determineWorkingDirectory(File checkoutDirectory, String relativePathProjectDirectory) {
File workingDirectory = checkoutDirectory;

if (StringUtils.isNotEmpty(relativePathProjectDirectory)) {
if (relativePathProjectDirectory != null && !relativePathProjectDirectory.isEmpty()) {
workingDirectory = new File(checkoutDirectory, relativePathProjectDirectory);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@
import org.apache.maven.shared.release.scm.ScmRepositoryConfigurator;
import org.apache.maven.shared.release.util.ReleaseUtil;
import org.codehaus.plexus.util.FileUtils;
import org.codehaus.plexus.util.StringUtils;

import static java.util.Objects.requireNonNull;
import static org.apache.maven.shared.utils.logging.MessageUtils.buffer;
Expand Down Expand Up @@ -208,7 +207,7 @@ private ReleaseResult performCheckout(
}

String scmRelativePathProjectDirectory = scmResult.getRelativePathProjectDirectory();
if (StringUtils.isEmpty(scmRelativePathProjectDirectory)) {
if (scmRelativePathProjectDirectory == null || scmRelativePathProjectDirectory.isEmpty()) {
Path workingDirectory = Paths.get(releaseDescriptor.getWorkingDirectory());

Path rootProjectBasedir;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ private ReleaseResult runLogic(
String additionalArguments = getAdditionalArguments(releaseDescriptor);

if (releaseDescriptor.isUseReleaseProfile()) {
if (!StringUtils.isEmpty(additionalArguments)) {
if (!(additionalArguments == null || additionalArguments.isEmpty())) {
additionalArguments = additionalArguments + " -DperformRelease=true";
} else {
additionalArguments = "-DperformRelease=true";
Expand All @@ -79,7 +79,7 @@ private ReleaseResult runLogic(

// ensure we don't use the release pom for the perform goals
// ^^ paranoia? A MavenExecutor has already access to this. Probably worth refactoring.
if (!StringUtils.isEmpty(additionalArguments)) {
if (!(additionalArguments == null || additionalArguments.isEmpty())) {
Copy link
Contributor

Choose a reason for hiding this comment

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

The recipe could be updated to rewrite this one as

additionalArguments != null &&  !additionalArguments.isEmpty()

additionalArguments = additionalArguments + " -f " + pomFileName;
} else {
additionalArguments = "-f " + pomFileName;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@
import org.apache.maven.shared.release.config.ReleaseDescriptor;
import org.apache.maven.shared.release.util.MavenCrypto;
import org.apache.maven.shared.release.util.MavenCrypto.MavenCryptoException;
import org.codehaus.plexus.util.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand Down Expand Up @@ -134,20 +133,20 @@ public ScmRepository getConfiguredRepository(String url, ReleaseDescriptor relea
}
}

if (!StringUtils.isEmpty(username)) {
if (!(username == null || username.isEmpty())) {
scmRepo.setUser(username);
}
if (!StringUtils.isEmpty(password)) {
if (!(password == null || password.isEmpty())) {
scmRepo.setPassword(password);
}

if (scmRepo instanceof ScmProviderRepositoryWithHost) {
ScmProviderRepositoryWithHost repositoryWithHost = (ScmProviderRepositoryWithHost) scmRepo;
if (!StringUtils.isEmpty(privateKey)) {
if (!(privateKey == null || privateKey.isEmpty())) {
repositoryWithHost.setPrivateKey(privateKey);
}

if (!StringUtils.isEmpty(passphrase)) {
if (!(passphrase == null || passphrase.isEmpty())) {
repositoryWithHost.setPassphrase(passphrase);
}
}
Expand All @@ -156,12 +155,12 @@ public ScmRepository getConfiguredRepository(String url, ReleaseDescriptor relea
SvnScmProviderRepository svnRepo = (SvnScmProviderRepository) repository.getProviderRepository();

String tagBase = releaseDescriptor.getScmTagBase();
if (!StringUtils.isEmpty(tagBase)) {
if (!(tagBase == null || tagBase.isEmpty())) {
svnRepo.setTagBase(tagBase);
}

String branchBase = releaseDescriptor.getScmBranchBase();
if (!StringUtils.isEmpty(branchBase)) {
if (!(branchBase == null || branchBase.isEmpty())) {
svnRepo.setBranchBase(branchBase);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
import java.util.Arrays;
import java.util.List;

import org.apache.commons.lang3.StringUtils;
import org.apache.maven.model.Model;
import org.apache.maven.project.MavenProject;
import org.apache.maven.shared.release.ReleaseExecutionException;
Expand Down Expand Up @@ -164,7 +163,7 @@ public static int getBaseWorkingDirectoryParentCount(final Path baseDirectory, f
}

public static String realignScmUrl(int parentLevels, String url) {
if (!StringUtils.isEmpty(url)) {
if (!(url == null || url.isEmpty())) {
// normalize
url = url.replaceAll("/\\./", "/")
.replaceAll("/\\.$", "")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -332,21 +332,21 @@ protected static String getVersionString(DefaultVersionInfo info, String buildSp
sb.append(joinDigitString(info.digits));
}

if (StringUtils.isNotEmpty(info.annotation)) {
if (info.annotation != null && !info.annotation.isEmpty()) {
sb.append(StringUtils.defaultString(info.annotationSeparator));
sb.append(info.annotation);
}

if (StringUtils.isNotEmpty(info.annotationRevision)) {
if (StringUtils.isEmpty(info.annotation)) {
if (info.annotationRevision != null && !info.annotationRevision.isEmpty()) {
if (info.annotation == null || info.annotation.isEmpty()) {
sb.append(StringUtils.defaultString(info.annotationSeparator));
} else {
sb.append(StringUtils.defaultString(info.annotationRevSeparator));
}
sb.append(info.annotationRevision);
}

if (StringUtils.isNotEmpty(buildSpecifier)) {
if (buildSpecifier != null && !buildSpecifier.isEmpty()) {
sb.append(StringUtils.defaultString(buildSeparator));
sb.append(buildSpecifier);
}
Expand Down Expand Up @@ -379,7 +379,7 @@ private List<String> parseDigits(String strDigits) {
// --------------------------------------------------

private static String nullIfEmpty(String s) {
return StringUtils.isEmpty(s) ? null : s;
return (s == null || s.isEmpty()) ? null : s;
}

/**
Expand Down