[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
This commit is contained in:
Tamas Cservenak 2024-06-06 20:49:34 +02:00 committed by GitHub
parent 200dc02da8
commit 741deac98f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
14 changed files with 92 additions and 75 deletions

View File

@ -35,10 +35,6 @@ under the License.
<groupId>org.codehaus.plexus</groupId>
<artifactId>plexus-utils</artifactId>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
</dependency>
</dependencies>
<build>

View File

@ -23,9 +23,9 @@ import java.util.Collection;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.regex.Matcher;
import org.apache.commons.lang3.Validate;
import org.apache.maven.artifact.versioning.VersionRange;
/**
@ -89,9 +89,11 @@ public final class ArtifactUtils {
}
private static void notBlank(String str, String message) {
int c = str != null && str.length() > 0 ? str.charAt(0) : 0;
int c = str != null && !str.isEmpty() ? str.charAt(0) : 0;
if ((c < '0' || c > '9') && (c < 'a' || c > 'z')) {
Validate.notBlank(str, message);
if (Objects.requireNonNull(str, message).trim().isEmpty()) {
throw new IllegalArgumentException(message);
}
}
}

View File

@ -20,8 +20,6 @@ package org.apache.maven.artifact.versioning;
import java.util.StringTokenizer;
import static org.apache.commons.lang3.math.NumberUtils.isDigits;
/**
* Default implementation of artifact versioning.
*
@ -176,6 +174,19 @@ public class DefaultArtifactVersion implements ArtifactVersion {
return tryParseInt(s);
}
private static boolean isDigits(String str) {
if (str == null || str.trim().isEmpty()) {
return false;
}
for (int i = 0; i < str.length(); i++) {
char c = str.charAt(i);
if (!(c >= '0' && c <= '9')) {
return false;
}
}
return true;
}
private static Integer tryParseInt(String s) {
// for performance, check digits instead of relying later on catching NumberFormatException
if (!isDigits(s)) {

View File

@ -80,6 +80,15 @@ public class DefaultArtifactVersionTest extends TestCase {
checkVersionParsing("1.2.3-200705301630", 1, 2, 3, 0, "200705301630");
}
public void testVersionParsingNot09() {
String ver = "१.२.३";
assertTrue(Character.isDigit(ver.charAt(0)));
assertTrue(Character.isDigit(ver.charAt(2)));
assertTrue(Character.isDigit(ver.charAt(4)));
ArtifactVersion version = newArtifactVersion(ver);
assertEquals(ver, version.getQualifier());
}
public void testVersionComparing() {
assertVersionEqual("1", "1");
assertVersionOlder("1", "2");

View File

@ -131,10 +131,6 @@ under the License.
<groupId>org.codehaus.plexus</groupId>
<artifactId>plexus-component-annotations</artifactId>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>

View File

@ -18,7 +18,8 @@
*/
package org.apache.maven.configuration;
import org.apache.commons.lang3.Validate;
import java.util.Objects;
import org.apache.maven.model.Build;
import org.apache.maven.model.Model;
import org.apache.maven.model.Plugin;
@ -103,9 +104,16 @@ public class DefaultBeanConfigurationRequest implements BeanConfigurationRequest
return this;
}
private static final String GROUP_ID_ERROR_MESSAGE = "groupId can neither be null, empty, nor blank";
private static final String ARTIFACT_ID_ERROR_MESSAGE = "artifactId can neither be null, empty, nor blank";
private Plugin findPlugin(Model model, String groupId, String artifactId) {
Validate.notBlank(groupId, "groupId can neither be null, empty nor blank");
Validate.notBlank(artifactId, "artifactId can neither be null, empty nor blank");
if (Objects.requireNonNull(groupId, GROUP_ID_ERROR_MESSAGE).trim().isEmpty()) {
throw new IllegalArgumentException(GROUP_ID_ERROR_MESSAGE);
}
if (Objects.requireNonNull(artifactId, ARTIFACT_ID_ERROR_MESSAGE).trim().isEmpty()) {
throw new IllegalArgumentException(ARTIFACT_ID_ERROR_MESSAGE);
}
if (model != null) {
Build build = model.getBuild();

View File

@ -20,10 +20,9 @@ package org.apache.maven.rtinfo.internal;
import java.io.IOException;
import java.io.InputStream;
import java.util.Objects;
import java.util.Properties;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.Validate;
import org.apache.maven.rtinfo.RuntimeInformation;
import org.codehaus.plexus.component.annotations.Component;
import org.codehaus.plexus.component.annotations.Requirement;
@ -79,10 +78,15 @@ public class DefaultRuntimeInformation implements RuntimeInformation {
return mavenVersion;
}
public boolean isMavenVersion(String versionRange) {
VersionScheme versionScheme = new GenericVersionScheme();
private static final String VERSION_RANGE_ERROR_MESSAGE = "versionRange can neither be null, empty, nor blank";
Validate.notBlank(versionRange, "versionRange can neither be null, empty nor blank");
public boolean isMavenVersion(String versionRange) {
if (Objects.requireNonNull(versionRange, VERSION_RANGE_ERROR_MESSAGE)
.trim()
.isEmpty()) {
throw new IllegalArgumentException(VERSION_RANGE_ERROR_MESSAGE);
}
VersionScheme versionScheme = new GenericVersionScheme();
VersionConstraint constraint;
try {
@ -94,7 +98,9 @@ public class DefaultRuntimeInformation implements RuntimeInformation {
Version current;
try {
String mavenVersion = getMavenVersion();
Validate.validState(StringUtils.isNotEmpty(mavenVersion), "Could not determine current Maven version");
if (mavenVersion == null || mavenVersion.trim().isEmpty()) {
throw new IllegalStateException("Could not determine current Maven version");
}
current = versionScheme.parseVersion(mavenVersion);
} catch (InvalidVersionSpecificationException e) {

View File

@ -148,10 +148,6 @@ under the License.
<artifactId>commons-io</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>

View File

@ -25,8 +25,8 @@ import java.util.Date;
import java.util.Locale;
import java.util.Properties;
import org.apache.commons.lang3.StringUtils;
import org.codehaus.plexus.util.Os;
import org.codehaus.plexus.util.StringUtils;
import org.slf4j.Logger;
import static org.apache.maven.shared.utils.logging.MessageUtils.buffer;

View File

@ -51,7 +51,6 @@ import org.apache.commons.cli.CommandLine;
import org.apache.commons.cli.Option;
import org.apache.commons.cli.ParseException;
import org.apache.commons.cli.UnrecognizedOptionException;
import org.apache.commons.lang3.math.NumberUtils;
import org.apache.maven.BuildAbort;
import org.apache.maven.InternalErrorException;
import org.apache.maven.Maven;
@ -1442,27 +1441,24 @@ public class MavenCli {
if (threadConfiguration.endsWith("C")) {
threadConfiguration = threadConfiguration.substring(0, threadConfiguration.length() - 1);
if (!NumberUtils.isParsable(threadConfiguration)) {
throw new IllegalArgumentException("Invalid threads core multiplier value: '" + threadConfiguration
+ "C'. Supported are int and float values ending with C.");
}
try {
float coreMultiplier = Float.parseFloat(threadConfiguration);
float coreMultiplier = Float.parseFloat(threadConfiguration);
if (coreMultiplier <= 0.0f) {
throw new IllegalArgumentException("Invalid threads core multiplier value: '" + threadConfiguration
+ "C'. Value must be positive.");
}
if (coreMultiplier <= 0.0f) {
throw new IllegalArgumentException("Invalid threads core multiplier value: '" + threadConfiguration
+ "C'. Value must be positive.");
}
int procs = Runtime.getRuntime().availableProcessors();
int threads = (int) (coreMultiplier * procs);
return threads == 0 ? 1 : threads;
} else {
if (!NumberUtils.isParsable(threadConfiguration)) {
int procs = Runtime.getRuntime().availableProcessors();
int threads = (int) (coreMultiplier * procs);
return threads == 0 ? 1 : threads;
} catch (NumberFormatException e) {
throw new IllegalArgumentException(
"Invalid threads value: '" + threadConfiguration + "'. Supported are int values.");
"Invalid threads core multiplier value: '" + threadConfiguration
+ "C'. Supported are int and float values ending with C.",
e);
}
} else {
try {
int threads = Integer.parseInt(threadConfiguration);

View File

@ -23,7 +23,6 @@ import java.text.DecimalFormat;
import java.text.DecimalFormatSymbols;
import java.util.Locale;
import org.apache.commons.lang3.Validate;
import org.apache.maven.shared.utils.logging.MessageUtils;
import org.eclipse.aether.transfer.AbstractTransferListener;
import org.eclipse.aether.transfer.TransferCancelledException;
@ -105,7 +104,9 @@ public abstract class AbstractMavenTransferListener extends AbstractTransferList
public abstract String symbol();
public static ScaleUnit getScaleUnit(long size) {
Validate.isTrue(size >= 0L, "file size cannot be negative: %s", size);
if (size < 0L) {
throw new IllegalArgumentException("file size cannot be negative: " + size);
}
if (size >= GIGABYTE.bytes()) {
return GIGABYTE;
@ -137,7 +138,9 @@ public abstract class AbstractMavenTransferListener extends AbstractTransferList
@SuppressWarnings("checkstyle:magicnumber")
public String format(long size, ScaleUnit unit, boolean omitSymbol) {
Validate.isTrue(size >= 0L, "file size cannot be negative: %s", size);
if (size < 0L) {
throw new IllegalArgumentException("file size cannot be negative: " + size);
}
if (unit == null) {
unit = ScaleUnit.getScaleUnit(size);
@ -162,12 +165,13 @@ public abstract class AbstractMavenTransferListener extends AbstractTransferList
}
public String formatProgress(long progressedSize, long size) {
Validate.isTrue(progressedSize >= 0L, "progressed file size cannot be negative: %s", progressedSize);
Validate.isTrue(
size >= 0L && progressedSize <= size || size < 0L,
"progressed file size cannot be greater than size: %s > %s",
progressedSize,
size);
if (progressedSize < 0L) {
throw new IllegalArgumentException("progressed file size cannot be negative: " + progressedSize);
}
if (size >= 0L && progressedSize > size) {
throw new IllegalArgumentException(
"progressed file size cannot be greater than size: " + progressedSize + " > " + size);
}
if (size >= 0L && progressedSize != size) {
ScaleUnit unit = ScaleUnit.getScaleUnit(size);

View File

@ -25,7 +25,6 @@ import java.util.LinkedHashMap;
import java.util.Locale;
import java.util.Map;
import org.apache.commons.lang3.StringUtils;
import org.eclipse.aether.transfer.TransferCancelledException;
import org.eclipse.aether.transfer.TransferEvent;
import org.eclipse.aether.transfer.TransferResource;
@ -37,10 +36,10 @@ import org.eclipse.aether.transfer.TransferResource;
*/
public class ConsoleMavenTransferListener extends AbstractMavenTransferListener {
private Map<TransferResource, Long> transfers =
private final Map<TransferResource, Long> transfers =
Collections.synchronizedMap(new LinkedHashMap<TransferResource, Long>());
private boolean printResourceNames;
private final boolean printResourceNames;
private int lastLength;
public ConsoleMavenTransferListener(PrintStream out, boolean printResourceNames) {
@ -97,7 +96,7 @@ public class ConsoleMavenTransferListener extends AbstractMavenTransferListener
StringBuilder status = new StringBuilder();
if (printResourceNames) {
status.append(StringUtils.substringAfterLast(resourceName, "/"));
status.append(resourceName(resourceName));
status.append(" (");
}
@ -110,6 +109,17 @@ public class ConsoleMavenTransferListener extends AbstractMavenTransferListener
return status.toString();
}
private String resourceName(String resourceName) {
if (resourceName == null || resourceName.trim().isEmpty()) {
return "";
}
final int pos = resourceName.lastIndexOf("/");
if (pos == -1 || pos == resourceName.length() - 1) {
return "";
}
return resourceName.substring(pos + 1);
}
private void pad(StringBuilder buffer, int spaces) {
String block = " ";
while (spaces > 0) {

View File

@ -89,7 +89,6 @@ public class MavenCliTest {
int cpus = Runtime.getRuntime().availableProcessors();
assertEquals((int) (cpus * 2.2), cli.calculateDegreeOfConcurrency("2.2C"));
assertEquals(1, cli.calculateDegreeOfConcurrency("0.0001C"));
assertThrows(IllegalArgumentException.class, new ConcurrencyCalculator("2.C"));
assertThrows(IllegalArgumentException.class, new ConcurrencyCalculator("-2.2C"));
assertThrows(IllegalArgumentException.class, new ConcurrencyCalculator("0C"));
}

16
pom.xml
View File

@ -129,7 +129,6 @@ under the License.
<classWorldsVersion>2.8.0</classWorldsVersion>
<commonsCliVersion>1.8.0</commonsCliVersion>
<commonsIoVersion>2.16.1</commonsIoVersion>
<commonsLangVersion>3.14.0</commonsLangVersion>
<junitVersion>4.13.2</junitVersion>
<hamcrestVersion>2.2</hamcrestVersion>
<mockitoVersion>4.11.0</mockitoVersion>
@ -442,16 +441,6 @@ under the License.
<groupId>commons-cli</groupId>
<artifactId>commons-cli</artifactId>
<version>${commonsCliVersion}</version>
<exclusions>
<exclusion>
<groupId>commons-lang</groupId>
<artifactId>commons-lang</artifactId>
</exclusion>
<exclusion>
<groupId>commons-logging</groupId>
<artifactId>commons-logging</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>commons-io</groupId>
@ -463,11 +452,6 @@ under the License.
<artifactId>commons-jxpath</artifactId>
<version>${jxpathVersion}</version>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>${commonsLangVersion}</version>
</dependency>
<dependency>
<groupId>org.codehaus.plexus</groupId>
<artifactId>plexus-sec-dispatcher</artifactId>