Skip to content

Commit bb53cea

Browse files
committed
[MNG-6825] Get rid of commons-lang
1 parent 8421a36 commit bb53cea

File tree

26 files changed

+148
-92
lines changed

26 files changed

+148
-92
lines changed

maven-artifact/pom.xml

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,7 @@ under the License.
3030

3131
<name>Maven Artifact</name>
3232

33-
<dependencies>
34-
<dependency>
35-
<groupId>org.apache.commons</groupId>
36-
<artifactId>commons-lang3</artifactId>
37-
</dependency>
38-
</dependencies>
33+
<dependencies />
3934

4035
<build>
4136
<plugins>

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

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525
import java.util.Map;
2626
import java.util.regex.Matcher;
2727

28-
import org.apache.commons.lang3.Validate;
2928
import org.apache.maven.artifact.versioning.VersionRange;
3029

3130
/**
@@ -89,10 +88,15 @@ public static String key(String groupId, String artifactId, String version) {
8988
}
9089

9190
private static void notBlank(String str, String message) {
92-
int c = str != null && str.length() > 0 ? str.charAt(0) : 0;
93-
if ((c < '0' || c > '9') && (c < 'a' || c > 'z')) {
94-
Validate.notBlank(str, message);
91+
final int strLen = str != null ? str.length() : 0;
92+
if (strLen > 0) {
93+
for (int i = 0; i < strLen; i++) {
94+
if (!Character.isWhitespace(str.charAt(i))) {
95+
return;
96+
}
97+
}
9598
}
99+
throw new IllegalArgumentException(message);
96100
}
97101

98102
public static Map<String, Artifact> artifactMapByVersionlessId(Collection<Artifact> artifacts) {

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

Lines changed: 13 additions & 2 deletions
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
*
@@ -168,6 +166,19 @@ public final void parseVersion(String version) {
168166
}
169167
}
170168

169+
private static boolean isDigits(String cs) {
170+
if (cs == null || cs.isEmpty()) {
171+
return false;
172+
}
173+
final int sz = cs.length();
174+
for (int i = 0; i < sz; i++) {
175+
if (!Character.isDigit(cs.charAt(i))) {
176+
return false;
177+
}
178+
}
179+
return true;
180+
}
181+
171182
private static Integer getNextIntegerToken(StringTokenizer tok) {
172183
String s = tok.nextToken();
173184
if ((s.length() > 1) && s.startsWith("0")) {

maven-compat/src/main/java/org/apache/maven/artifact/repository/metadata/MetadataBridge.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,10 @@
1919
package org.apache.maven.artifact.repository.metadata;
2020

2121
import java.io.File;
22+
import java.nio.file.Files;
2223
import java.util.Collections;
2324
import java.util.Map;
2425

25-
import org.apache.commons.io.FileUtils;
2626
import org.apache.maven.artifact.metadata.ArtifactMetadata;
2727
import org.apache.maven.artifact.repository.ArtifactRepository;
2828
import org.apache.maven.artifact.repository.DefaultArtifactRepository;
@@ -50,7 +50,7 @@ public MetadataBridge(ArtifactMetadata metadata) {
5050
public void merge(File current, File result) throws RepositoryException {
5151
try {
5252
if (current.exists()) {
53-
FileUtils.copyFile(current, result);
53+
Files.copy(current.toPath(), result.toPath());
5454
}
5555
ArtifactRepository localRepo = new MetadataRepository(result);
5656
metadata.storeInLocalRepository(localRepo, localRepo);

maven-compat/src/test/java/org/apache/maven/artifact/deployer/ArtifactDeployerTest.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,9 @@
2121
import javax.inject.Inject;
2222

2323
import java.io.File;
24+
import java.nio.charset.StandardCharsets;
25+
import java.nio.file.Files;
2426

25-
import org.apache.commons.io.FileUtils;
2627
import org.apache.maven.artifact.AbstractArtifactComponentTestCase;
2728
import org.apache.maven.artifact.Artifact;
2829
import org.apache.maven.artifact.repository.ArtifactRepository;
@@ -60,15 +61,14 @@ public void testArtifactInstallation() throws Exception {
6061
Artifact artifact = createArtifact("artifact", "1.0");
6162

6263
File file = new File(artifactBasedir, "artifact-1.0.jar");
63-
assertEquals("dummy", FileUtils.readFileToString(file, "UTF-8").trim());
64+
assertEquals("dummy", new String(Files.readAllBytes(file.toPath()), StandardCharsets.UTF_8).trim());
6465

6566
artifactDeployer.deploy(file, artifact, remoteRepository(), localRepository());
6667

6768
ArtifactRepository remoteRepository = remoteRepository();
6869
File deployedFile = new File(remoteRepository.getBasedir(), remoteRepository.pathOf(artifact));
6970
assertTrue(deployedFile.exists());
70-
assertEquals(
71-
"dummy", FileUtils.readFileToString(deployedFile, "UTF-8").trim());
71+
assertEquals("dummy", new String(Files.readAllBytes(deployedFile.toPath()), StandardCharsets.UTF_8).trim());
7272
} finally {
7373
sessionScope.exit();
7474
}

maven-core/pom.xml

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -123,10 +123,6 @@ under the License.
123123
<groupId>com.google.guava</groupId>
124124
<artifactId>failureaccess</artifactId>
125125
</dependency>
126-
<dependency>
127-
<groupId>commons-io</groupId>
128-
<artifactId>commons-io</artifactId>
129-
</dependency>
130126
<dependency>
131127
<groupId>javax.inject</groupId>
132128
<artifactId>javax.inject</artifactId>
@@ -140,10 +136,6 @@ under the License.
140136
<groupId>org.codehaus.plexus</groupId>
141137
<artifactId>plexus-classworlds</artifactId>
142138
</dependency>
143-
<dependency>
144-
<groupId>org.apache.commons</groupId>
145-
<artifactId>commons-lang3</artifactId>
146-
</dependency>
147139
<dependency>
148140
<groupId>org.slf4j</groupId>
149141
<artifactId>slf4j-api</artifactId>
@@ -158,6 +150,11 @@ under the License.
158150
<artifactId>commons-jxpath</artifactId>
159151
<scope>test</scope>
160152
</dependency>
153+
<dependency>
154+
<groupId>commons-io</groupId>
155+
<artifactId>commons-io</artifactId>
156+
<scope>test</scope>
157+
</dependency>
161158
<dependency>
162159
<groupId>org.mockito</groupId>
163160
<artifactId>mockito-core</artifactId>

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

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,12 @@
1818
*/
1919
package org.apache.maven.configuration;
2020

21-
import org.apache.commons.lang3.Validate;
21+
import org.apache.maven.internal.StringUtils;
2222
import org.apache.maven.model.Build;
2323
import org.apache.maven.model.Model;
2424
import org.apache.maven.model.Plugin;
2525
import org.apache.maven.model.PluginExecution;
2626
import org.apache.maven.model.PluginManagement;
27-
import org.codehaus.plexus.util.StringUtils;
2827

2928
/**
3029
* A basic bean configuration request.
@@ -104,8 +103,8 @@ public DefaultBeanConfigurationRequest setConfiguration(
104103
}
105104

106105
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");
106+
StringUtils.notBlank(groupId, "groupId can neither be null, empty nor blank");
107+
StringUtils.notBlank(artifactId, "artifactId can neither be null, empty nor blank");
109108

110109
if (model != null) {
111110
Build build = model.getBuild();

maven-core/src/main/java/org/apache/maven/execution/DefaultBuildResumptionDataRepository.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
import java.util.Properties;
3131
import java.util.stream.Stream;
3232

33-
import org.apache.commons.lang3.StringUtils;
33+
import org.apache.maven.internal.StringUtils;
3434
import org.apache.maven.project.MavenProject;
3535
import org.slf4j.Logger;
3636
import org.slf4j.LoggerFactory;
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
package org.apache.maven.internal;
20+
21+
public class StringUtils {
22+
23+
public static void notBlank(String str, String message) {
24+
if (!isNotBlank(str)) {
25+
throw new IllegalArgumentException(message);
26+
}
27+
}
28+
29+
public static boolean isNotBlank(String str) {
30+
final int strLen = str != null ? str.length() : 0;
31+
if (strLen > 0) {
32+
for (int i = 0; i < strLen; i++) {
33+
if (!Character.isWhitespace(str.charAt(i))) {
34+
return true;
35+
}
36+
}
37+
}
38+
return false;
39+
}
40+
41+
public static boolean isNotEmpty(String str) {
42+
return str != null && !str.isEmpty();
43+
}
44+
45+
public static boolean isEmpty(String str) {
46+
return !isNotEmpty(str);
47+
}
48+
}

maven-core/src/main/java/org/apache/maven/internal/impl/DefaultArtifactCoordinateFactory.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,11 @@
2121
import javax.inject.Named;
2222
import javax.inject.Singleton;
2323

24-
import org.apache.commons.lang3.StringUtils;
2524
import org.apache.maven.api.ArtifactCoordinate;
2625
import org.apache.maven.api.annotations.Nonnull;
2726
import org.apache.maven.api.services.ArtifactCoordinateFactory;
2827
import org.apache.maven.api.services.ArtifactCoordinateFactoryRequest;
28+
import org.apache.maven.internal.StringUtils;
2929
import org.eclipse.aether.artifact.ArtifactType;
3030

3131
import static org.apache.maven.internal.impl.Utils.cast;

0 commit comments

Comments
 (0)