diff --git a/maven-core/src/main/java/org/apache/maven/configuration/DefaultBeanConfigurationRequest.java b/maven-core/src/main/java/org/apache/maven/configuration/DefaultBeanConfigurationRequest.java index cefb8d129c21..a50212890430 100644 --- a/maven-core/src/main/java/org/apache/maven/configuration/DefaultBeanConfigurationRequest.java +++ b/maven-core/src/main/java/org/apache/maven/configuration/DefaultBeanConfigurationRequest.java @@ -18,7 +18,6 @@ */ package org.apache.maven.configuration; -import org.apache.maven.internal.StringUtils; import org.apache.maven.model.Build; import org.apache.maven.model.Model; import org.apache.maven.model.Plugin; @@ -88,7 +87,7 @@ public DefaultBeanConfigurationRequest setConfiguration( Model model, String pluginGroupId, String pluginArtifactId, String pluginExecutionId) { Plugin plugin = findPlugin(model, pluginGroupId, pluginArtifactId); if (plugin != null) { - if (StringUtils.isNotEmpty(pluginExecutionId)) { + if (pluginExecutionId != null && !pluginExecutionId.isEmpty()) { for (PluginExecution execution : plugin.getExecutions()) { if (pluginExecutionId.equals(execution.getId())) { setConfiguration(execution.getConfiguration()); @@ -103,8 +102,12 @@ public DefaultBeanConfigurationRequest setConfiguration( } private Plugin findPlugin(Model model, String groupId, String artifactId) { - StringUtils.notBlank(groupId, "groupId can neither be null, empty nor blank"); - StringUtils.notBlank(artifactId, "artifactId can neither be null, empty nor blank"); + if (!(groupId != null && !groupId.isEmpty())) { + throw new IllegalArgumentException("groupId can neither be null nor empty"); + } + if (!(artifactId != null && !artifactId.isEmpty())) { + throw new IllegalArgumentException("artifactId can neither be null nor empty"); + } if (model != null) { Build build = model.getBuild(); diff --git a/maven-core/src/main/java/org/apache/maven/execution/DefaultBuildResumptionDataRepository.java b/maven-core/src/main/java/org/apache/maven/execution/DefaultBuildResumptionDataRepository.java index 47f092ce7b90..8a4ded84fbcb 100644 --- a/maven-core/src/main/java/org/apache/maven/execution/DefaultBuildResumptionDataRepository.java +++ b/maven-core/src/main/java/org/apache/maven/execution/DefaultBuildResumptionDataRepository.java @@ -30,7 +30,6 @@ import java.util.Properties; import java.util.stream.Stream; -import org.apache.maven.internal.StringUtils; import org.apache.maven.project.MavenProject; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -109,10 +108,11 @@ private Properties loadResumptionFile(Path rootBuildDirectory) { // This method is made package-private for testing purposes void applyResumptionProperties(MavenExecutionRequest request, Properties properties) { - if (properties.containsKey(REMAINING_PROJECTS) && StringUtils.isEmpty(request.getResumeFrom())) { + String str1 = request.getResumeFrom(); + if (properties.containsKey(REMAINING_PROJECTS) && !(str1 != null && !str1.isEmpty())) { String propertyValue = properties.getProperty(REMAINING_PROJECTS); Stream.of(propertyValue.split(PROPERTY_DELIMITER)) - .filter(StringUtils::isNotEmpty) + .filter(str -> str != null && !str.isEmpty()) .forEach(request.getProjectActivation()::activateOptionalProject); LOGGER.info("Resuming from {} due to the --resume / -r feature.", propertyValue); } diff --git a/maven-core/src/main/java/org/apache/maven/internal/StringUtils.java b/maven-core/src/main/java/org/apache/maven/internal/StringUtils.java deleted file mode 100644 index a71fac0b5c63..000000000000 --- a/maven-core/src/main/java/org/apache/maven/internal/StringUtils.java +++ /dev/null @@ -1,48 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.apache.maven.internal; - -public class StringUtils { - - public static void notBlank(String str, String message) { - if (!isNotBlank(str)) { - throw new IllegalArgumentException(message); - } - } - - public static boolean isNotBlank(String str) { - final int strLen = str != null ? str.length() : 0; - if (strLen > 0) { - for (int i = 0; i < strLen; i++) { - if (!Character.isWhitespace(str.charAt(i))) { - return true; - } - } - } - return false; - } - - public static boolean isNotEmpty(String str) { - return str != null && !str.isEmpty(); - } - - public static boolean isEmpty(String str) { - return !isNotEmpty(str); - } -} diff --git a/maven-core/src/main/java/org/apache/maven/internal/impl/DefaultArtifactCoordinateFactory.java b/maven-core/src/main/java/org/apache/maven/internal/impl/DefaultArtifactCoordinateFactory.java index dc17b50ed1e5..fa2ec1e4aa39 100644 --- a/maven-core/src/main/java/org/apache/maven/internal/impl/DefaultArtifactCoordinateFactory.java +++ b/maven-core/src/main/java/org/apache/maven/internal/impl/DefaultArtifactCoordinateFactory.java @@ -25,7 +25,6 @@ import org.apache.maven.api.annotations.Nonnull; import org.apache.maven.api.services.ArtifactCoordinateFactory; import org.apache.maven.api.services.ArtifactCoordinateFactoryRequest; -import org.apache.maven.internal.StringUtils; import org.eclipse.aether.artifact.ArtifactType; import static org.apache.maven.internal.impl.Utils.cast; @@ -43,10 +42,12 @@ public ArtifactCoordinate create(@Nonnull ArtifactCoordinateFactoryRequest reque if (request.getType() != null) { type = session.getSession().getArtifactTypeRegistry().get(request.getType()); } - String classifier = StringUtils.isNotEmpty(request.getClassifier()) + String str1 = request.getClassifier(); + String classifier = str1 != null && !str1.isEmpty() ? request.getClassifier() : type != null ? type.getClassifier() : ""; - String extension = StringUtils.isNotEmpty(request.getExtension()) + String str = request.getExtension(); + String extension = str != null && !str.isEmpty() ? request.getExtension() : type != null ? type.getExtension() : ""; return new DefaultArtifactCoordinate( diff --git a/maven-core/src/main/java/org/apache/maven/internal/impl/DefaultArtifactFactory.java b/maven-core/src/main/java/org/apache/maven/internal/impl/DefaultArtifactFactory.java index 265be25aba5a..c7d23fade6e5 100644 --- a/maven-core/src/main/java/org/apache/maven/internal/impl/DefaultArtifactFactory.java +++ b/maven-core/src/main/java/org/apache/maven/internal/impl/DefaultArtifactFactory.java @@ -25,7 +25,6 @@ import org.apache.maven.api.annotations.Nonnull; import org.apache.maven.api.services.ArtifactFactory; import org.apache.maven.api.services.ArtifactFactoryRequest; -import org.apache.maven.internal.StringUtils; import org.eclipse.aether.artifact.ArtifactType; import static org.apache.maven.internal.impl.Utils.cast; @@ -43,10 +42,12 @@ public Artifact create(@Nonnull ArtifactFactoryRequest request) { if (request.getType() != null) { type = session.getSession().getArtifactTypeRegistry().get(request.getType()); } - String classifier = StringUtils.isNotEmpty(request.getClassifier()) + String str1 = request.getClassifier(); + String classifier = str1 != null && !str1.isEmpty() ? request.getClassifier() : type != null ? type.getClassifier() : null; - String extension = StringUtils.isNotEmpty(request.getExtension()) + String str = request.getExtension(); + String extension = str != null && !str.isEmpty() ? request.getExtension() : type != null ? type.getExtension() : null; return new DefaultArtifact( diff --git a/maven-core/src/main/java/org/apache/maven/plugin/internal/MavenPluginJavaPrerequisiteChecker.java b/maven-core/src/main/java/org/apache/maven/plugin/internal/MavenPluginJavaPrerequisiteChecker.java index c7332805bfd2..a100c349a0f8 100644 --- a/maven-core/src/main/java/org/apache/maven/plugin/internal/MavenPluginJavaPrerequisiteChecker.java +++ b/maven-core/src/main/java/org/apache/maven/plugin/internal/MavenPluginJavaPrerequisiteChecker.java @@ -22,7 +22,6 @@ import javax.inject.Named; import javax.inject.Singleton; -import org.apache.maven.internal.StringUtils; import org.apache.maven.plugin.MavenPluginPrerequisitesChecker; import org.apache.maven.plugin.descriptor.PluginDescriptor; import org.eclipse.aether.version.InvalidVersionSpecificationException; @@ -44,7 +43,7 @@ public MavenPluginJavaPrerequisiteChecker(final VersionScheme versionScheme) { @Override public void accept(PluginDescriptor pluginDescriptor) { String requiredJavaVersion = pluginDescriptor.getRequiredJavaVersion(); - if (StringUtils.isNotBlank(requiredJavaVersion)) { + if (requiredJavaVersion != null && !requiredJavaVersion.isEmpty()) { String currentJavaVersion = System.getProperty("java.version"); if (!matchesVersion(requiredJavaVersion, currentJavaVersion)) { throw new IllegalStateException("Required Java version " + requiredJavaVersion diff --git a/maven-core/src/main/java/org/apache/maven/rtinfo/internal/DefaultRuntimeInformation.java b/maven-core/src/main/java/org/apache/maven/rtinfo/internal/DefaultRuntimeInformation.java index d88eb78602b7..ce583e7cf8a4 100644 --- a/maven-core/src/main/java/org/apache/maven/rtinfo/internal/DefaultRuntimeInformation.java +++ b/maven-core/src/main/java/org/apache/maven/rtinfo/internal/DefaultRuntimeInformation.java @@ -26,7 +26,6 @@ import java.io.InputStream; import java.util.Properties; -import org.apache.maven.internal.StringUtils; import org.apache.maven.rtinfo.RuntimeInformation; import org.eclipse.aether.version.InvalidVersionSpecificationException; import org.eclipse.aether.version.Version; @@ -89,7 +88,9 @@ private String loadMavenVersion() { @Override public boolean isMavenVersion(String versionRange) { - StringUtils.notBlank(versionRange, "versionRange can neither be null, empty nor blank"); + if (!(versionRange != null && !versionRange.isEmpty())) { + throw new IllegalArgumentException("versionRange can neither be null nor empty"); + } VersionConstraint constraint; try { @@ -101,7 +102,9 @@ public boolean isMavenVersion(String versionRange) { Version current; try { String mavenVersion = getMavenVersion(); - StringUtils.notBlank(mavenVersion, "Could not determine current Maven version"); + if (!(mavenVersion != null && !mavenVersion.isEmpty())) { + throw new IllegalArgumentException("Could not determine current Maven version"); + } current = versionScheme.parseVersion(mavenVersion); } catch (InvalidVersionSpecificationException e) { diff --git a/maven-embedder/src/main/java/org/apache/maven/cli/CLIReportingUtils.java b/maven-embedder/src/main/java/org/apache/maven/cli/CLIReportingUtils.java index 9462bb5397af..bc879c640913 100644 --- a/maven-embedder/src/main/java/org/apache/maven/cli/CLIReportingUtils.java +++ b/maven-embedder/src/main/java/org/apache/maven/cli/CLIReportingUtils.java @@ -25,7 +25,6 @@ import java.util.Locale; import java.util.Properties; -import org.apache.maven.internal.StringUtils; import org.codehaus.plexus.util.Os; import org.slf4j.Logger; @@ -106,7 +105,7 @@ static String createMavenVersionString(Properties buildProperties) { if (rev != null || timestamp != null) { msg += " ("; msg += (rev != null ? rev : ""); - if (StringUtils.isNotBlank(timestamp)) { + if (timestamp != null && !timestamp.isEmpty()) { String ts = formatTimestamp(Long.parseLong(timestamp)); msg += (rev != null ? "; " : "") + ts; }