Skip to content

Commit

Permalink
[MINVOKER-352] - Remove usage commons-lang3
Browse files Browse the repository at this point in the history
  • Loading branch information
khmarbaise committed Jan 1, 2024
1 parent cb814ee commit f61e240
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 24 deletions.
5 changes: 0 additions & 5 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -206,11 +206,6 @@ under the License.
<scope>runtime</scope>
</dependency>

<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>3.12.0</version>
</dependency>
<dependency>
<groupId>org.codehaus.plexus</groupId>
<artifactId>plexus-utils</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand All @@ -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.
Expand Down Expand Up @@ -2031,7 +2034,7 @@ private void verify(

private List<String> calculateIncludes() {
if (invokerTest != null) {
String[] testRegexes = StringUtils.split(invokerTest, ",");
String[] testRegexes = invokerTest.split(",+");
return Arrays.stream(testRegexes)
.map(String::trim)
.filter(s -> !s.isEmpty())
Expand All @@ -2049,7 +2052,7 @@ private List<String> calculateExcludes() throws IOException {
List<String> excludes;

if (invokerTest != null) {
String[] testRegexes = StringUtils.split(invokerTest, ",");
String[] testRegexes = invokerTest.split(",+");
excludes = Arrays.stream(testRegexes)
.map(String::trim)
.filter(s -> !s.isEmpty())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/**
Expand All @@ -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;
Expand Down Expand Up @@ -154,7 +153,7 @@ public void setDefaultProfiles(List<String> 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);
}
}
Expand Down Expand Up @@ -397,15 +396,15 @@ 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));

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));
Expand Down
25 changes: 16 additions & 9 deletions src/main/java/org/apache/maven/plugins/invoker/SelectorUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -47,7 +47,11 @@
class SelectorUtils {

static void parseList(String list, Collection<String> includes, Collection<String> 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();
Expand Down Expand Up @@ -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;
}
Expand All @@ -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;
}
Expand Down Expand Up @@ -201,13 +207,14 @@ static boolean isJreVersion(List<Integer> jreVersion, String versionPattern) {
}

static List<Integer> parseVersion(String version) {
version = version.replaceAll("[^0-9]", ".");

String[] tokens = StringUtils.split(version, ".");
version = version.replaceAll("\\D", ".");

List<Integer> 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<Integer> version1, List<Integer> version2) {
Expand Down

0 comments on commit f61e240

Please sign in to comment.