Skip to content

Commit 741deac

Browse files
authored
[MNG-8146] Drop commons-lang (#1564)
For start, keeping almost same LOC but the distro zip lost almost 1 MB (was 10MB now is 9MB). Second, am really unsure why it was introduced in the first place, as it merely caused confusion, over StringUtils for example. --- https://issues.apache.org/jira/browse/MNG-8146
1 parent 200dc02 commit 741deac

File tree

14 files changed

+91
-74
lines changed

14 files changed

+91
-74
lines changed

maven-artifact/pom.xml

-4
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,6 @@ under the License.
3535
<groupId>org.codehaus.plexus</groupId>
3636
<artifactId>plexus-utils</artifactId>
3737
</dependency>
38-
<dependency>
39-
<groupId>org.apache.commons</groupId>
40-
<artifactId>commons-lang3</artifactId>
41-
</dependency>
4238
</dependencies>
4339

4440
<build>

maven-artifact/src/main/java/org/apache/maven/artifact/ArtifactUtils.java

+5-3
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,9 @@
2323
import java.util.LinkedHashMap;
2424
import java.util.List;
2525
import java.util.Map;
26+
import java.util.Objects;
2627
import java.util.regex.Matcher;
2728

28-
import org.apache.commons.lang3.Validate;
2929
import org.apache.maven.artifact.versioning.VersionRange;
3030

3131
/**
@@ -89,9 +89,11 @@ public static String key(String groupId, String artifactId, String version) {
8989
}
9090

9191
private static void notBlank(String str, String message) {
92-
int c = str != null && str.length() > 0 ? str.charAt(0) : 0;
92+
int c = str != null && !str.isEmpty() ? str.charAt(0) : 0;
9393
if ((c < '0' || c > '9') && (c < 'a' || c > 'z')) {
94-
Validate.notBlank(str, message);
94+
if (Objects.requireNonNull(str, message).trim().isEmpty()) {
95+
throw new IllegalArgumentException(message);
96+
}
9597
}
9698
}
9799

maven-artifact/src/main/java/org/apache/maven/artifact/versioning/DefaultArtifactVersion.java

+13-2
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,6 @@
2020

2121
import java.util.StringTokenizer;
2222

23-
import static org.apache.commons.lang3.math.NumberUtils.isDigits;
24-
2523
/**
2624
* Default implementation of artifact versioning.
2725
*
@@ -176,6 +174,19 @@ private static Integer getNextIntegerToken(StringTokenizer tok) {
176174
return tryParseInt(s);
177175
}
178176

177+
private static boolean isDigits(String str) {
178+
if (str == null || str.trim().isEmpty()) {
179+
return false;
180+
}
181+
for (int i = 0; i < str.length(); i++) {
182+
char c = str.charAt(i);
183+
if (!(c >= '0' && c <= '9')) {
184+
return false;
185+
}
186+
}
187+
return true;
188+
}
189+
179190
private static Integer tryParseInt(String s) {
180191
// for performance, check digits instead of relying later on catching NumberFormatException
181192
if (!isDigits(s)) {

maven-artifact/src/test/java/org/apache/maven/artifact/versioning/DefaultArtifactVersionTest.java

+9
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,15 @@ public void testVersionParsing() {
8080
checkVersionParsing("1.2.3-200705301630", 1, 2, 3, 0, "200705301630");
8181
}
8282

83+
public void testVersionParsingNot09() {
84+
String ver = "१.२.३";
85+
assertTrue(Character.isDigit(ver.charAt(0)));
86+
assertTrue(Character.isDigit(ver.charAt(2)));
87+
assertTrue(Character.isDigit(ver.charAt(4)));
88+
ArtifactVersion version = newArtifactVersion(ver);
89+
assertEquals(ver, version.getQualifier());
90+
}
91+
8392
public void testVersionComparing() {
8493
assertVersionEqual("1", "1");
8594
assertVersionOlder("1", "2");

maven-core/pom.xml

-4
Original file line numberDiff line numberDiff line change
@@ -131,10 +131,6 @@ under the License.
131131
<groupId>org.codehaus.plexus</groupId>
132132
<artifactId>plexus-component-annotations</artifactId>
133133
</dependency>
134-
<dependency>
135-
<groupId>org.apache.commons</groupId>
136-
<artifactId>commons-lang3</artifactId>
137-
</dependency>
138134
<dependency>
139135
<groupId>org.slf4j</groupId>
140136
<artifactId>slf4j-api</artifactId>

maven-core/src/main/java/org/apache/maven/configuration/DefaultBeanConfigurationRequest.java

+11-3
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@
1818
*/
1919
package org.apache.maven.configuration;
2020

21-
import org.apache.commons.lang3.Validate;
21+
import java.util.Objects;
22+
2223
import org.apache.maven.model.Build;
2324
import org.apache.maven.model.Model;
2425
import org.apache.maven.model.Plugin;
@@ -103,9 +104,16 @@ public DefaultBeanConfigurationRequest setConfiguration(
103104
return this;
104105
}
105106

107+
private static final String GROUP_ID_ERROR_MESSAGE = "groupId can neither be null, empty, nor blank";
108+
private static final String ARTIFACT_ID_ERROR_MESSAGE = "artifactId can neither be null, empty, nor blank";
109+
106110
private Plugin findPlugin(Model model, String groupId, String artifactId) {
107-
Validate.notBlank(groupId, "groupId can neither be null, empty nor blank");
108-
Validate.notBlank(artifactId, "artifactId can neither be null, empty nor blank");
111+
if (Objects.requireNonNull(groupId, GROUP_ID_ERROR_MESSAGE).trim().isEmpty()) {
112+
throw new IllegalArgumentException(GROUP_ID_ERROR_MESSAGE);
113+
}
114+
if (Objects.requireNonNull(artifactId, ARTIFACT_ID_ERROR_MESSAGE).trim().isEmpty()) {
115+
throw new IllegalArgumentException(ARTIFACT_ID_ERROR_MESSAGE);
116+
}
109117

110118
if (model != null) {
111119
Build build = model.getBuild();

maven-core/src/main/java/org/apache/maven/rtinfo/internal/DefaultRuntimeInformation.java

+11-5
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,9 @@
2020

2121
import java.io.IOException;
2222
import java.io.InputStream;
23+
import java.util.Objects;
2324
import java.util.Properties;
2425

25-
import org.apache.commons.lang3.StringUtils;
26-
import org.apache.commons.lang3.Validate;
2726
import org.apache.maven.rtinfo.RuntimeInformation;
2827
import org.codehaus.plexus.component.annotations.Component;
2928
import org.codehaus.plexus.component.annotations.Requirement;
@@ -79,11 +78,16 @@ public String getMavenVersion() {
7978
return mavenVersion;
8079
}
8180

81+
private static final String VERSION_RANGE_ERROR_MESSAGE = "versionRange can neither be null, empty, nor blank";
82+
8283
public boolean isMavenVersion(String versionRange) {
84+
if (Objects.requireNonNull(versionRange, VERSION_RANGE_ERROR_MESSAGE)
85+
.trim()
86+
.isEmpty()) {
87+
throw new IllegalArgumentException(VERSION_RANGE_ERROR_MESSAGE);
88+
}
8389
VersionScheme versionScheme = new GenericVersionScheme();
8490

85-
Validate.notBlank(versionRange, "versionRange can neither be null, empty nor blank");
86-
8791
VersionConstraint constraint;
8892
try {
8993
constraint = versionScheme.parseVersionConstraint(versionRange);
@@ -94,7 +98,9 @@ public boolean isMavenVersion(String versionRange) {
9498
Version current;
9599
try {
96100
String mavenVersion = getMavenVersion();
97-
Validate.validState(StringUtils.isNotEmpty(mavenVersion), "Could not determine current Maven version");
101+
if (mavenVersion == null || mavenVersion.trim().isEmpty()) {
102+
throw new IllegalStateException("Could not determine current Maven version");
103+
}
98104

99105
current = versionScheme.parseVersion(mavenVersion);
100106
} catch (InvalidVersionSpecificationException e) {

maven-embedder/pom.xml

-4
Original file line numberDiff line numberDiff line change
@@ -148,10 +148,6 @@ under the License.
148148
<artifactId>commons-io</artifactId>
149149
<scope>test</scope>
150150
</dependency>
151-
<dependency>
152-
<groupId>org.apache.commons</groupId>
153-
<artifactId>commons-lang3</artifactId>
154-
</dependency>
155151
<dependency>
156152
<groupId>org.mockito</groupId>
157153
<artifactId>mockito-core</artifactId>

maven-embedder/src/main/java/org/apache/maven/cli/CLIReportingUtils.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@
2525
import java.util.Locale;
2626
import java.util.Properties;
2727

28-
import org.apache.commons.lang3.StringUtils;
2928
import org.codehaus.plexus.util.Os;
29+
import org.codehaus.plexus.util.StringUtils;
3030
import org.slf4j.Logger;
3131

3232
import static org.apache.maven.shared.utils.logging.MessageUtils.buffer;

maven-embedder/src/main/java/org/apache/maven/cli/MavenCli.java

+14-18
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,6 @@
5151
import org.apache.commons.cli.Option;
5252
import org.apache.commons.cli.ParseException;
5353
import org.apache.commons.cli.UnrecognizedOptionException;
54-
import org.apache.commons.lang3.math.NumberUtils;
5554
import org.apache.maven.BuildAbort;
5655
import org.apache.maven.InternalErrorException;
5756
import org.apache.maven.Maven;
@@ -1442,27 +1441,24 @@ int calculateDegreeOfConcurrency(String threadConfiguration) {
14421441
if (threadConfiguration.endsWith("C")) {
14431442
threadConfiguration = threadConfiguration.substring(0, threadConfiguration.length() - 1);
14441443

1445-
if (!NumberUtils.isParsable(threadConfiguration)) {
1446-
throw new IllegalArgumentException("Invalid threads core multiplier value: '" + threadConfiguration
1447-
+ "C'. Supported are int and float values ending with C.");
1448-
}
1449-
1450-
float coreMultiplier = Float.parseFloat(threadConfiguration);
1444+
try {
1445+
float coreMultiplier = Float.parseFloat(threadConfiguration);
14511446

1452-
if (coreMultiplier <= 0.0f) {
1453-
throw new IllegalArgumentException("Invalid threads core multiplier value: '" + threadConfiguration
1454-
+ "C'. Value must be positive.");
1455-
}
1447+
if (coreMultiplier <= 0.0f) {
1448+
throw new IllegalArgumentException("Invalid threads core multiplier value: '" + threadConfiguration
1449+
+ "C'. Value must be positive.");
1450+
}
14561451

1457-
int procs = Runtime.getRuntime().availableProcessors();
1458-
int threads = (int) (coreMultiplier * procs);
1459-
return threads == 0 ? 1 : threads;
1460-
} else {
1461-
if (!NumberUtils.isParsable(threadConfiguration)) {
1452+
int procs = Runtime.getRuntime().availableProcessors();
1453+
int threads = (int) (coreMultiplier * procs);
1454+
return threads == 0 ? 1 : threads;
1455+
} catch (NumberFormatException e) {
14621456
throw new IllegalArgumentException(
1463-
"Invalid threads value: '" + threadConfiguration + "'. Supported are int values.");
1457+
"Invalid threads core multiplier value: '" + threadConfiguration
1458+
+ "C'. Supported are int and float values ending with C.",
1459+
e);
14641460
}
1465-
1461+
} else {
14661462
try {
14671463
int threads = Integer.parseInt(threadConfiguration);
14681464

maven-embedder/src/main/java/org/apache/maven/cli/transfer/AbstractMavenTransferListener.java

+13-9
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
import java.text.DecimalFormatSymbols;
2424
import java.util.Locale;
2525

26-
import org.apache.commons.lang3.Validate;
2726
import org.apache.maven.shared.utils.logging.MessageUtils;
2827
import org.eclipse.aether.transfer.AbstractTransferListener;
2928
import org.eclipse.aether.transfer.TransferCancelledException;
@@ -105,7 +104,9 @@ public String symbol() {
105104
public abstract String symbol();
106105

107106
public static ScaleUnit getScaleUnit(long size) {
108-
Validate.isTrue(size >= 0L, "file size cannot be negative: %s", size);
107+
if (size < 0L) {
108+
throw new IllegalArgumentException("file size cannot be negative: " + size);
109+
}
109110

110111
if (size >= GIGABYTE.bytes()) {
111112
return GIGABYTE;
@@ -137,7 +138,9 @@ public String format(long size, ScaleUnit unit) {
137138

138139
@SuppressWarnings("checkstyle:magicnumber")
139140
public String format(long size, ScaleUnit unit, boolean omitSymbol) {
140-
Validate.isTrue(size >= 0L, "file size cannot be negative: %s", size);
141+
if (size < 0L) {
142+
throw new IllegalArgumentException("file size cannot be negative: " + size);
143+
}
141144

142145
if (unit == null) {
143146
unit = ScaleUnit.getScaleUnit(size);
@@ -162,12 +165,13 @@ public String format(long size, ScaleUnit unit, boolean omitSymbol) {
162165
}
163166

164167
public String formatProgress(long progressedSize, long size) {
165-
Validate.isTrue(progressedSize >= 0L, "progressed file size cannot be negative: %s", progressedSize);
166-
Validate.isTrue(
167-
size >= 0L && progressedSize <= size || size < 0L,
168-
"progressed file size cannot be greater than size: %s > %s",
169-
progressedSize,
170-
size);
168+
if (progressedSize < 0L) {
169+
throw new IllegalArgumentException("progressed file size cannot be negative: " + progressedSize);
170+
}
171+
if (size >= 0L && progressedSize > size) {
172+
throw new IllegalArgumentException(
173+
"progressed file size cannot be greater than size: " + progressedSize + " > " + size);
174+
}
171175

172176
if (size >= 0L && progressedSize != size) {
173177
ScaleUnit unit = ScaleUnit.getScaleUnit(size);

maven-embedder/src/main/java/org/apache/maven/cli/transfer/ConsoleMavenTransferListener.java

+14-4
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525
import java.util.Locale;
2626
import java.util.Map;
2727

28-
import org.apache.commons.lang3.StringUtils;
2928
import org.eclipse.aether.transfer.TransferCancelledException;
3029
import org.eclipse.aether.transfer.TransferEvent;
3130
import org.eclipse.aether.transfer.TransferResource;
@@ -37,10 +36,10 @@
3736
*/
3837
public class ConsoleMavenTransferListener extends AbstractMavenTransferListener {
3938

40-
private Map<TransferResource, Long> transfers =
39+
private final Map<TransferResource, Long> transfers =
4140
Collections.synchronizedMap(new LinkedHashMap<TransferResource, Long>());
4241

43-
private boolean printResourceNames;
42+
private final boolean printResourceNames;
4443
private int lastLength;
4544

4645
public ConsoleMavenTransferListener(PrintStream out, boolean printResourceNames) {
@@ -97,7 +96,7 @@ private String getStatus(String resourceName, long complete, long total) {
9796
StringBuilder status = new StringBuilder();
9897

9998
if (printResourceNames) {
100-
status.append(StringUtils.substringAfterLast(resourceName, "/"));
99+
status.append(resourceName(resourceName));
101100
status.append(" (");
102101
}
103102

@@ -110,6 +109,17 @@ private String getStatus(String resourceName, long complete, long total) {
110109
return status.toString();
111110
}
112111

112+
private String resourceName(String resourceName) {
113+
if (resourceName == null || resourceName.trim().isEmpty()) {
114+
return "";
115+
}
116+
final int pos = resourceName.lastIndexOf("/");
117+
if (pos == -1 || pos == resourceName.length() - 1) {
118+
return "";
119+
}
120+
return resourceName.substring(pos + 1);
121+
}
122+
113123
private void pad(StringBuilder buffer, int spaces) {
114124
String block = " ";
115125
while (spaces > 0) {

maven-embedder/src/test/java/org/apache/maven/cli/MavenCliTest.java

-1
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,6 @@ public void testCalculateDegreeOfConcurrency() {
8989
int cpus = Runtime.getRuntime().availableProcessors();
9090
assertEquals((int) (cpus * 2.2), cli.calculateDegreeOfConcurrency("2.2C"));
9191
assertEquals(1, cli.calculateDegreeOfConcurrency("0.0001C"));
92-
assertThrows(IllegalArgumentException.class, new ConcurrencyCalculator("2.C"));
9392
assertThrows(IllegalArgumentException.class, new ConcurrencyCalculator("-2.2C"));
9493
assertThrows(IllegalArgumentException.class, new ConcurrencyCalculator("0C"));
9594
}

pom.xml

-16
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,6 @@ under the License.
129129
<classWorldsVersion>2.8.0</classWorldsVersion>
130130
<commonsCliVersion>1.8.0</commonsCliVersion>
131131
<commonsIoVersion>2.16.1</commonsIoVersion>
132-
<commonsLangVersion>3.14.0</commonsLangVersion>
133132
<junitVersion>4.13.2</junitVersion>
134133
<hamcrestVersion>2.2</hamcrestVersion>
135134
<mockitoVersion>4.11.0</mockitoVersion>
@@ -442,16 +441,6 @@ under the License.
442441
<groupId>commons-cli</groupId>
443442
<artifactId>commons-cli</artifactId>
444443
<version>${commonsCliVersion}</version>
445-
<exclusions>
446-
<exclusion>
447-
<groupId>commons-lang</groupId>
448-
<artifactId>commons-lang</artifactId>
449-
</exclusion>
450-
<exclusion>
451-
<groupId>commons-logging</groupId>
452-
<artifactId>commons-logging</artifactId>
453-
</exclusion>
454-
</exclusions>
455444
</dependency>
456445
<dependency>
457446
<groupId>commons-io</groupId>
@@ -463,11 +452,6 @@ under the License.
463452
<artifactId>commons-jxpath</artifactId>
464453
<version>${jxpathVersion}</version>
465454
</dependency>
466-
<dependency>
467-
<groupId>org.apache.commons</groupId>
468-
<artifactId>commons-lang3</artifactId>
469-
<version>${commonsLangVersion}</version>
470-
</dependency>
471455
<dependency>
472456
<groupId>org.codehaus.plexus</groupId>
473457
<artifactId>plexus-sec-dispatcher</artifactId>

0 commit comments

Comments
 (0)