diff --git a/pom.xml b/pom.xml index 65120e41..c40407da 100644 --- a/pom.xml +++ b/pom.xml @@ -206,11 +206,6 @@ under the License. runtime - - org.apache.commons - commons-lang3 - 3.12.0 - org.codehaus.plexus plexus-utils diff --git a/src/main/java/org/apache/maven/plugins/invoker/AbstractInvokerMojo.java b/src/main/java/org/apache/maven/plugins/invoker/AbstractInvokerMojo.java index 26320208..14ddb735 100644 --- a/src/main/java/org/apache/maven/plugins/invoker/AbstractInvokerMojo.java +++ b/src/main/java/org/apache/maven/plugins/invoker/AbstractInvokerMojo.java @@ -43,12 +43,12 @@ import java.util.List; import java.util.Locale; import java.util.Map; +import java.util.Objects; import java.util.Properties; import java.util.Set; import java.util.TreeSet; import java.util.stream.Collectors; -import org.apache.commons.lang3.StringUtils; import org.apache.maven.artifact.Artifact; import org.apache.maven.execution.MavenSession; import org.apache.maven.model.Model; @@ -1020,8 +1020,7 @@ private void collectProjects( String projectDir = pomFile.getParent(); String parentPath = "../pom.xml"; - if (model.getParent() != null - && StringUtils.isNotEmpty(model.getParent().getRelativePath())) { + if (model.getParent() != null && isNotEmpty(model.getParent().getRelativePath())) { parentPath = model.getParent().getRelativePath(); } String parent = relativizePath(new File(projectDir, parentPath), projectsRoot); @@ -1044,6 +1043,10 @@ private void collectProjects( } } + private boolean isNotEmpty(String s) { + return Objects.nonNull(s) && !s.isEmpty(); + } + /** * Copies the specified projects to the directory given by {@link #cloneProjectsTo}. A project may either be denoted * by a path to a POM file or merely by a path to a base directory. During cloning, the POM files will be filtered. @@ -2031,7 +2034,7 @@ private void verify( private List calculateIncludes() { if (invokerTest != null) { - String[] testRegexes = StringUtils.split(invokerTest, ","); + String[] testRegexes = invokerTest.split(",+"); return Arrays.stream(testRegexes) .map(String::trim) .filter(s -> !s.isEmpty()) @@ -2049,7 +2052,7 @@ private List calculateExcludes() throws IOException { List excludes; if (invokerTest != null) { - String[] testRegexes = StringUtils.split(invokerTest, ","); + String[] testRegexes = invokerTest.split(",+"); excludes = Arrays.stream(testRegexes) .map(String::trim) .filter(s -> !s.isEmpty()) diff --git a/src/main/java/org/apache/maven/plugins/invoker/InvokerProperties.java b/src/main/java/org/apache/maven/plugins/invoker/InvokerProperties.java index a315c554..15e246d0 100644 --- a/src/main/java/org/apache/maven/plugins/invoker/InvokerProperties.java +++ b/src/main/java/org/apache/maven/plugins/invoker/InvokerProperties.java @@ -31,7 +31,6 @@ import java.util.regex.Matcher; import java.util.regex.Pattern; -import org.apache.commons.lang3.StringUtils; import org.apache.maven.shared.invoker.InvocationRequest; /** @@ -43,7 +42,7 @@ class InvokerProperties { private static final String SELECTOR_PREFIX = "selector."; private static final Pattern ENVIRONMENT_VARIABLES_PATTERN = - Pattern.compile("invoker\\.environmentVariables\\.([A-Za-z][^.]+)(\\.([0-9]+))?"); + Pattern.compile("invoker\\.environmentVariables\\.([A-Za-z][^.]+)(\\.(\\d+))?"); // default values from Mojo configuration private Boolean defaultDebug; @@ -154,7 +153,7 @@ public void setDefaultProfiles(List defaultProfiles) { * @param defaultMavenExecutable a default value */ public void setDefaultMavenExecutable(String defaultMavenExecutable) { - if (StringUtils.isNotBlank(defaultMavenExecutable)) { + if (Objects.nonNull(defaultMavenExecutable) && !defaultMavenExecutable.isEmpty()) { this.defaultMavenExecutable = new File(defaultMavenExecutable); } } @@ -397,7 +396,7 @@ public void configureInvocation(InvocationRequest request, int index) { setIfNotNull( request::setGoals, get(InvocationProperty.GOALS, index) - .map(s -> StringUtils.split(s, ", \t\n\r\f")) + .map(s -> s.trim().split("\\s*[ ,]+\\s*")) .map(Arrays::asList) .filter(l -> !l.isEmpty()) .orElse(defaultGoals)); @@ -405,7 +404,7 @@ public void configureInvocation(InvocationRequest request, int index) { setIfNotNull( request::setProfiles, get(InvocationProperty.PROFILES, index) - .map(s -> StringUtils.split(s, ", \t\n\r\f")) + .map(s -> s.trim().split("\\s*[ ,]+\\s*")) .map(Arrays::asList) .filter(l -> !l.isEmpty()) .orElse(defaultProfiles)); diff --git a/src/main/java/org/apache/maven/plugins/invoker/SelectorUtils.java b/src/main/java/org/apache/maven/plugins/invoker/SelectorUtils.java index 5cba3f4e..00b54005 100644 --- a/src/main/java/org/apache/maven/plugins/invoker/SelectorUtils.java +++ b/src/main/java/org/apache/maven/plugins/invoker/SelectorUtils.java @@ -29,10 +29,10 @@ import java.util.Collection; import java.util.Iterator; import java.util.List; +import java.util.Objects; import java.util.Properties; import java.util.stream.Collectors; -import org.apache.commons.lang3.StringUtils; import org.apache.maven.plugins.invoker.AbstractInvokerMojo.ToolchainPrivateManager; import org.apache.maven.project.MavenProject; import org.apache.maven.toolchain.MisconfiguredToolchainException; @@ -47,7 +47,11 @@ class SelectorUtils { static void parseList(String list, Collection includes, Collection excludes) { - String[] tokens = (list != null) ? StringUtils.split(list, ",") : new String[0]; + if (Objects.isNull(list)) { + return; + } + + String[] tokens = list.split(",+"); for (String token1 : tokens) { String token = token1.trim(); @@ -99,7 +103,8 @@ static String getMavenVersion() { .getClassLoader() .getResourceAsStream("META-INF/maven/org.apache.maven/maven-core/pom.properties")); // CHECKSTYLE_ON: LineLength - return StringUtils.trim(properties.getProperty("version")); + String str = properties.getProperty("version"); + return str == null ? null : str.trim(); } catch (Exception e) { return null; } @@ -121,7 +126,8 @@ static String getMavenVersion(File mavenHome) throws IOException { try (InputStream in = url.openStream()) { Properties properties = new Properties(); properties.load(in); - String version = StringUtils.trim(properties.getProperty("version")); + String str = properties.getProperty("version"); + String version = str == null ? null : str.trim(); if (version != null) { return version; } @@ -201,13 +207,14 @@ static boolean isJreVersion(List jreVersion, String versionPattern) { } static List parseVersion(String version) { - version = version.replaceAll("[^0-9]", "."); - - String[] tokens = StringUtils.split(version, "."); + version = version.replaceAll("\\D", "."); - List numbers = Arrays.stream(tokens).map(Integer::valueOf).collect(Collectors.toList()); + String[] tokens = version.split("\\s*\\.+\\s*"); - return numbers; + return Arrays.stream(tokens) + .filter(s -> !s.isEmpty()) + .map(Integer::valueOf) + .collect(Collectors.toList()); } static int compareVersions(List version1, List version2) {