Skip to content

Commit

Permalink
[MNG-6825] Get rid of commons-lang
Browse files Browse the repository at this point in the history
  • Loading branch information
gnodet committed Apr 5, 2023
1 parent aa2532a commit b3ee1a0
Show file tree
Hide file tree
Showing 23 changed files with 106 additions and 89 deletions.
7 changes: 1 addition & 6 deletions maven-artifact/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,7 @@ under the License.

<name>Maven Artifact</name>

<dependencies>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
</dependency>
</dependencies>
<dependencies />

<build>
<plugins>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
import java.util.Map;
import java.util.regex.Matcher;

import org.apache.commons.lang3.Validate;
import org.apache.maven.artifact.versioning.VersionRange;

/**
Expand Down Expand Up @@ -89,10 +88,15 @@ public static String key(String groupId, String artifactId, String version) {
}

private static void notBlank(String str, String message) {
int c = str != null && str.length() > 0 ? str.charAt(0) : 0;
if ((c < '0' || c > '9') && (c < 'a' || c > 'z')) {
Validate.notBlank(str, message);
final int strLen = str != null ? str.length() : 0;
if (strLen > 0) {
for (int i = 0; i < strLen; i++) {
if (!Character.isWhitespace(str.charAt(i))) {
return;
}
}
}
throw new IllegalArgumentException(message);
}

public static Map<String, Artifact> artifactMapByVersionlessId(Collection<Artifact> artifacts) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@

import java.util.StringTokenizer;

import static org.apache.commons.lang3.math.NumberUtils.isDigits;

/**
* Default implementation of artifact versioning.
*
Expand Down Expand Up @@ -168,6 +166,19 @@ public final void parseVersion(String version) {
}
}

private static boolean isDigits(String cs) {
if (cs == null || cs.isEmpty()) {
return false;
}
final int sz = cs.length();
for (int i = 0; i < sz; i++) {
if (!Character.isDigit(cs.charAt(i))) {
return false;
}
}
return true;
}

private static Integer getNextIntegerToken(StringTokenizer tok) {
String s = tok.nextToken();
if ((s.length() > 1) && s.startsWith("0")) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@
package org.apache.maven.artifact.repository.metadata;

import java.io.File;
import java.nio.file.Files;
import java.util.Collections;
import java.util.Map;

import org.apache.commons.io.FileUtils;
import org.apache.maven.artifact.metadata.ArtifactMetadata;
import org.apache.maven.artifact.repository.ArtifactRepository;
import org.apache.maven.artifact.repository.DefaultArtifactRepository;
Expand Down Expand Up @@ -50,7 +50,8 @@ public MetadataBridge(ArtifactMetadata metadata) {
public void merge(File current, File result) throws RepositoryException {
try {
if (current.exists()) {
FileUtils.copyFile(current, result);
Files.createDirectories(result.toPath().getParent());
Files.copy(current.toPath(), result.toPath());
}
ArtifactRepository localRepo = new MetadataRepository(result);
metadata.storeInLocalRepository(localRepo, localRepo);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,9 @@
import javax.inject.Inject;

import java.io.File;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;

import org.apache.commons.io.FileUtils;
import org.apache.maven.artifact.AbstractArtifactComponentTestCase;
import org.apache.maven.artifact.Artifact;
import org.apache.maven.artifact.repository.ArtifactRepository;
Expand Down Expand Up @@ -60,15 +61,14 @@ public void testArtifactInstallation() throws Exception {
Artifact artifact = createArtifact("artifact", "1.0");

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

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

ArtifactRepository remoteRepository = remoteRepository();
File deployedFile = new File(remoteRepository.getBasedir(), remoteRepository.pathOf(artifact));
assertTrue(deployedFile.exists());
assertEquals(
"dummy", FileUtils.readFileToString(deployedFile, "UTF-8").trim());
assertEquals("dummy", new String(Files.readAllBytes(deployedFile.toPath()), StandardCharsets.UTF_8).trim());
} finally {
sessionScope.exit();
}
Expand Down
13 changes: 5 additions & 8 deletions maven-core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -123,10 +123,6 @@ under the License.
<groupId>com.google.guava</groupId>
<artifactId>failureaccess</artifactId>
</dependency>
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
</dependency>
<dependency>
<groupId>javax.inject</groupId>
<artifactId>javax.inject</artifactId>
Expand All @@ -140,10 +136,6 @@ under the License.
<groupId>org.codehaus.plexus</groupId>
<artifactId>plexus-classworlds</artifactId>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
Expand All @@ -158,6 +150,11 @@ under the License.
<artifactId>commons-jxpath</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,11 @@
*/
package org.apache.maven.configuration;

import org.apache.commons.lang3.Validate;
import org.apache.maven.model.Build;
import org.apache.maven.model.Model;
import org.apache.maven.model.Plugin;
import org.apache.maven.model.PluginExecution;
import org.apache.maven.model.PluginManagement;
import org.codehaus.plexus.util.StringUtils;

/**
* A basic bean configuration request.
Expand Down Expand Up @@ -89,7 +87,7 @@ public DefaultBeanConfigurationRequest setConfiguration(
Model model, String pluginGroupId, String pluginArtifactId, String pluginExecutionId) {
Plugin plugin = findPlugin(model, pluginGroupId, pluginArtifactId);
if (plugin != null) {
if (StringUtils.isNotEmpty(pluginExecutionId)) {
if (pluginExecutionId != null && !pluginExecutionId.isEmpty()) {
for (PluginExecution execution : plugin.getExecutions()) {
if (pluginExecutionId.equals(execution.getId())) {
setConfiguration(execution.getConfiguration());
Expand All @@ -104,8 +102,12 @@ public DefaultBeanConfigurationRequest setConfiguration(
}

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 (!(groupId != null && !groupId.isEmpty())) {
throw new IllegalArgumentException("groupId can neither be null nor empty");
}
if (!(artifactId != null && !artifactId.isEmpty())) {
throw new IllegalArgumentException("artifactId can neither be null nor empty");
}

if (model != null) {
Build build = model.getBuild();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
import java.util.Properties;
import java.util.stream.Stream;

import org.apache.commons.lang3.StringUtils;
import org.apache.maven.project.MavenProject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand Down Expand Up @@ -109,10 +108,11 @@ private Properties loadResumptionFile(Path rootBuildDirectory) {

// This method is made package-private for testing purposes
void applyResumptionProperties(MavenExecutionRequest request, Properties properties) {
if (properties.containsKey(REMAINING_PROJECTS) && StringUtils.isEmpty(request.getResumeFrom())) {
String str1 = request.getResumeFrom();
if (properties.containsKey(REMAINING_PROJECTS) && !(str1 != null && !str1.isEmpty())) {
String propertyValue = properties.getProperty(REMAINING_PROJECTS);
Stream.of(propertyValue.split(PROPERTY_DELIMITER))
.filter(StringUtils::isNotEmpty)
.filter(str -> str != null && !str.isEmpty())
.forEach(request.getProjectActivation()::activateOptionalProject);
LOGGER.info("Resuming from {} due to the --resume / -r feature.", propertyValue);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
import javax.inject.Named;
import javax.inject.Singleton;

import org.apache.commons.lang3.StringUtils;
import org.apache.maven.api.ArtifactCoordinate;
import org.apache.maven.api.annotations.Nonnull;
import org.apache.maven.api.services.ArtifactCoordinateFactory;
Expand All @@ -43,12 +42,12 @@ public ArtifactCoordinate create(@Nonnull ArtifactCoordinateFactoryRequest reque
if (request.getType() != null) {
type = session.getSession().getArtifactTypeRegistry().get(request.getType());
}
String classifier = StringUtils.isNotEmpty(request.getClassifier())
? request.getClassifier()
: type != null ? type.getClassifier() : "";
String extension = StringUtils.isNotEmpty(request.getExtension())
? request.getExtension()
: type != null ? type.getExtension() : "";
String str1 = request.getClassifier();
String classifier =
str1 != null && !str1.isEmpty() ? request.getClassifier() : type != null ? type.getClassifier() : "";
String str = request.getExtension();
String extension =
str != null && !str.isEmpty() ? request.getExtension() : type != null ? type.getExtension() : "";
return new DefaultArtifactCoordinate(
session,
new org.eclipse.aether.artifact.DefaultArtifact(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
import javax.inject.Named;
import javax.inject.Singleton;

import org.apache.commons.lang3.StringUtils;
import org.apache.maven.api.Artifact;
import org.apache.maven.api.annotations.Nonnull;
import org.apache.maven.api.services.ArtifactFactory;
Expand All @@ -43,12 +42,12 @@ public Artifact create(@Nonnull ArtifactFactoryRequest request) {
if (request.getType() != null) {
type = session.getSession().getArtifactTypeRegistry().get(request.getType());
}
String classifier = StringUtils.isNotEmpty(request.getClassifier())
? request.getClassifier()
: type != null ? type.getClassifier() : null;
String extension = StringUtils.isNotEmpty(request.getExtension())
? request.getExtension()
: type != null ? type.getExtension() : null;
String str1 = request.getClassifier();
String classifier =
str1 != null && !str1.isEmpty() ? request.getClassifier() : type != null ? type.getClassifier() : null;
String str = request.getExtension();
String extension =
str != null && !str.isEmpty() ? request.getExtension() : type != null ? type.getExtension() : null;
return new DefaultArtifact(
session,
new org.eclipse.aether.artifact.DefaultArtifact(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@

import org.apache.maven.plugin.MavenPluginPrerequisitesChecker;
import org.apache.maven.plugin.descriptor.PluginDescriptor;
import org.codehaus.plexus.util.StringUtils;
import org.eclipse.aether.version.InvalidVersionSpecificationException;
import org.eclipse.aether.version.Version;
import org.eclipse.aether.version.VersionConstraint;
Expand All @@ -44,7 +43,7 @@ public MavenPluginJavaPrerequisiteChecker(final VersionScheme versionScheme) {
@Override
public void accept(PluginDescriptor pluginDescriptor) {
String requiredJavaVersion = pluginDescriptor.getRequiredJavaVersion();
if (StringUtils.isNotBlank(requiredJavaVersion)) {
if (requiredJavaVersion != null && !requiredJavaVersion.isEmpty()) {
String currentJavaVersion = System.getProperty("java.version");
if (!matchesVersion(requiredJavaVersion, currentJavaVersion)) {
throw new IllegalStateException("Required Java version " + requiredJavaVersion
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@

import java.io.File;
import java.io.IOException;
import java.nio.file.Files;

import org.apache.commons.io.FileUtils;
import org.apache.maven.artifact.Artifact;
import org.apache.maven.artifact.metadata.AbstractArtifactMetadata;
import org.apache.maven.artifact.metadata.ArtifactMetadata;
Expand Down Expand Up @@ -74,7 +74,8 @@ public void storeInLocalRepository(ArtifactRepository localRepository, ArtifactR
// ----------------------------------------------------------------------------

try {
FileUtils.copyFile(file, destination);
Files.createDirectories(destination.toPath().getParent());
Files.copy(file.toPath(), destination.toPath());
} catch (IOException e) {
throw new RepositoryMetadataStoreException("Error copying POM to the local repository.", e);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,6 @@
import java.io.InputStream;
import java.util.Properties;

import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.Validate;
import org.apache.maven.rtinfo.RuntimeInformation;
import org.eclipse.aether.version.InvalidVersionSpecificationException;
import org.eclipse.aether.version.Version;
Expand Down Expand Up @@ -90,7 +88,9 @@ private String loadMavenVersion() {

@Override
public boolean isMavenVersion(String versionRange) {
Validate.notBlank(versionRange, "versionRange can neither be null, empty nor blank");
if (!(versionRange != null && !versionRange.isEmpty())) {
throw new IllegalArgumentException("versionRange can neither be null nor empty");
}

VersionConstraint constraint;
try {
Expand All @@ -102,7 +102,9 @@ public boolean isMavenVersion(String versionRange) {
Version current;
try {
String mavenVersion = getMavenVersion();
Validate.validState(StringUtils.isNotEmpty(mavenVersion), "Could not determine current Maven version");
if (mavenVersion.isEmpty()) {
throw new IllegalArgumentException("Could not determine current Maven version");
}

current = versionScheme.parseVersion(mavenVersion);
} catch (InvalidVersionSpecificationException e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,11 @@
import javax.inject.Inject;

import java.io.File;
import java.nio.file.Files;
import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.Stream;

import org.apache.commons.io.FileUtils;
import org.codehaus.plexus.PlexusContainer;
import org.codehaus.plexus.testing.PlexusTest;
import org.junit.jupiter.api.Test;
Expand All @@ -40,7 +42,7 @@ public class ArtifactHandlerTest {
public void testAptConsistency() throws Exception {
File apt = getTestFile("src/site/apt/artifact-handlers.apt");

List<String> lines = FileUtils.readLines(apt);
List<String> lines = Files.readAllLines(apt.toPath());

for (String line : lines) {
if (line.startsWith("||")) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,12 @@

import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;

import org.apache.commons.io.FileUtils;
import org.apache.maven.api.model.Model;
import org.apache.maven.artifact.Artifact;
import org.apache.maven.artifact.DefaultArtifact;
Expand Down Expand Up @@ -274,7 +274,8 @@ private void resolve(Artifact artifact, ArtifactResolutionRequest request) throw

File remoteFile = new File(remoteRepo.getBasedir(), remoteRepo.pathOf(artifact));

FileUtils.copyFile(remoteFile, localFile);
Files.createDirectories(localFile.toPath().getParent());
Files.copy(remoteFile.toPath(), localFile.toPath());
}

artifact.setResolved(true);
Expand Down
Loading

0 comments on commit b3ee1a0

Please sign in to comment.