[MNG-6825] Get rid of commons-lang

This commit is contained in:
Guillaume Nodet 2023-04-04 22:07:45 +02:00
parent 26056b9b20
commit b2ee29e03e
22 changed files with 105 additions and 89 deletions

View File

@ -30,13 +30,6 @@ under the License.
<name>Maven Artifact</name> <name>Maven Artifact</name>
<dependencies>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
</dependency>
</dependencies>
<build> <build>
<plugins> <plugins>
<plugin> <plugin>

View File

@ -25,7 +25,6 @@ import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.regex.Matcher; import java.util.regex.Matcher;
import org.apache.commons.lang3.Validate;
import org.apache.maven.artifact.versioning.VersionRange; import org.apache.maven.artifact.versioning.VersionRange;
/** /**
@ -89,11 +88,16 @@ public final class ArtifactUtils {
} }
private static void notBlank(String str, String message) { private static void notBlank(String str, String message) {
int c = str != null && str.length() > 0 ? str.charAt(0) : 0; final int strLen = str != null ? str.length() : 0;
if ((c < '0' || c > '9') && (c < 'a' || c > 'z')) { if (strLen > 0) {
Validate.notBlank(str, message); 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) { public static Map<String, Artifact> artifactMapByVersionlessId(Collection<Artifact> artifacts) {
Map<String, Artifact> artifactMap = new LinkedHashMap<>(); Map<String, Artifact> artifactMap = new LinkedHashMap<>();

View File

@ -20,8 +20,6 @@ package org.apache.maven.artifact.versioning;
import java.util.StringTokenizer; import java.util.StringTokenizer;
import static org.apache.commons.lang3.math.NumberUtils.isDigits;
/** /**
* Default implementation of artifact versioning. * Default implementation of artifact versioning.
* *
@ -168,6 +166,19 @@ public class DefaultArtifactVersion implements ArtifactVersion {
} }
} }
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) { private static Integer getNextIntegerToken(StringTokenizer tok) {
String s = tok.nextToken(); String s = tok.nextToken();
if ((s.length() > 1) && s.startsWith("0")) { if ((s.length() > 1) && s.startsWith("0")) {

View File

@ -19,10 +19,10 @@
package org.apache.maven.artifact.repository.metadata; package org.apache.maven.artifact.repository.metadata;
import java.io.File; import java.io.File;
import java.nio.file.Files;
import java.util.Collections; import java.util.Collections;
import java.util.Map; import java.util.Map;
import org.apache.commons.io.FileUtils;
import org.apache.maven.artifact.metadata.ArtifactMetadata; import org.apache.maven.artifact.metadata.ArtifactMetadata;
import org.apache.maven.artifact.repository.ArtifactRepository; import org.apache.maven.artifact.repository.ArtifactRepository;
import org.apache.maven.artifact.repository.DefaultArtifactRepository; import org.apache.maven.artifact.repository.DefaultArtifactRepository;
@ -50,7 +50,8 @@ public final class MetadataBridge extends AbstractMetadata implements MergeableM
public void merge(File current, File result) throws RepositoryException { public void merge(File current, File result) throws RepositoryException {
try { try {
if (current.exists()) { if (current.exists()) {
FileUtils.copyFile(current, result); Files.createDirectories(result.toPath().getParent());
Files.copy(current.toPath(), result.toPath());
} }
ArtifactRepository localRepo = new MetadataRepository(result); ArtifactRepository localRepo = new MetadataRepository(result);
metadata.storeInLocalRepository(localRepo, localRepo); metadata.storeInLocalRepository(localRepo, localRepo);

View File

@ -21,8 +21,9 @@ package org.apache.maven.artifact.deployer;
import javax.inject.Inject; import javax.inject.Inject;
import java.io.File; 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.AbstractArtifactComponentTestCase;
import org.apache.maven.artifact.Artifact; import org.apache.maven.artifact.Artifact;
import org.apache.maven.artifact.repository.ArtifactRepository; import org.apache.maven.artifact.repository.ArtifactRepository;
@ -60,15 +61,14 @@ public class ArtifactDeployerTest extends AbstractArtifactComponentTestCase {
Artifact artifact = createArtifact("artifact", "1.0"); Artifact artifact = createArtifact("artifact", "1.0");
File file = new File(artifactBasedir, "artifact-1.0.jar"); 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()); artifactDeployer.deploy(file, artifact, remoteRepository(), localRepository());
ArtifactRepository remoteRepository = remoteRepository(); ArtifactRepository remoteRepository = remoteRepository();
File deployedFile = new File(remoteRepository.getBasedir(), remoteRepository.pathOf(artifact)); File deployedFile = new File(remoteRepository.getBasedir(), remoteRepository.pathOf(artifact));
assertTrue(deployedFile.exists()); assertTrue(deployedFile.exists());
assertEquals( assertEquals("dummy", new String(Files.readAllBytes(deployedFile.toPath()), StandardCharsets.UTF_8).trim());
"dummy", FileUtils.readFileToString(deployedFile, "UTF-8").trim());
} finally { } finally {
sessionScope.exit(); sessionScope.exit();
} }

View File

@ -123,10 +123,6 @@ under the License.
<groupId>com.google.guava</groupId> <groupId>com.google.guava</groupId>
<artifactId>failureaccess</artifactId> <artifactId>failureaccess</artifactId>
</dependency> </dependency>
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
</dependency>
<dependency> <dependency>
<groupId>javax.inject</groupId> <groupId>javax.inject</groupId>
<artifactId>javax.inject</artifactId> <artifactId>javax.inject</artifactId>
@ -140,10 +136,6 @@ under the License.
<groupId>org.codehaus.plexus</groupId> <groupId>org.codehaus.plexus</groupId>
<artifactId>plexus-classworlds</artifactId> <artifactId>plexus-classworlds</artifactId>
</dependency> </dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
</dependency>
<dependency> <dependency>
<groupId>org.slf4j</groupId> <groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId> <artifactId>slf4j-api</artifactId>
@ -158,6 +150,11 @@ under the License.
<artifactId>commons-jxpath</artifactId> <artifactId>commons-jxpath</artifactId>
<scope>test</scope> <scope>test</scope>
</dependency> </dependency>
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<scope>test</scope>
</dependency>
<dependency> <dependency>
<groupId>org.mockito</groupId> <groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId> <artifactId>mockito-core</artifactId>

View File

@ -18,13 +18,13 @@
*/ */
package org.apache.maven.configuration; 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.Build;
import org.apache.maven.model.Model; import org.apache.maven.model.Model;
import org.apache.maven.model.Plugin; import org.apache.maven.model.Plugin;
import org.apache.maven.model.PluginExecution; import org.apache.maven.model.PluginExecution;
import org.apache.maven.model.PluginManagement; import org.apache.maven.model.PluginManagement;
import org.codehaus.plexus.util.StringUtils;
/** /**
* A basic bean configuration request. * A basic bean configuration request.
@ -89,7 +89,7 @@ public class DefaultBeanConfigurationRequest implements BeanConfigurationRequest
Model model, String pluginGroupId, String pluginArtifactId, String pluginExecutionId) { Model model, String pluginGroupId, String pluginArtifactId, String pluginExecutionId) {
Plugin plugin = findPlugin(model, pluginGroupId, pluginArtifactId); Plugin plugin = findPlugin(model, pluginGroupId, pluginArtifactId);
if (plugin != null) { if (plugin != null) {
if (StringUtils.isNotEmpty(pluginExecutionId)) { if (pluginExecutionId != null && !pluginExecutionId.isEmpty()) {
for (PluginExecution execution : plugin.getExecutions()) { for (PluginExecution execution : plugin.getExecutions()) {
if (pluginExecutionId.equals(execution.getId())) { if (pluginExecutionId.equals(execution.getId())) {
setConfiguration(execution.getConfiguration()); setConfiguration(execution.getConfiguration());
@ -104,8 +104,12 @@ public class DefaultBeanConfigurationRequest implements BeanConfigurationRequest
} }
private Plugin findPlugin(Model model, String groupId, String artifactId) { private Plugin findPlugin(Model model, String groupId, String artifactId) {
Validate.notBlank(groupId, "groupId can neither be null, empty nor blank"); if (Objects.requireNonNull(groupId, "groupId cannot be null").isEmpty()) {
Validate.notBlank(artifactId, "artifactId can neither be null, empty nor blank"); throw new IllegalArgumentException("groupId cannot be empty");
}
if (Objects.requireNonNull(artifactId, "artifactId cannot be null").isEmpty()) {
throw new IllegalArgumentException("artifactId cannot be empty");
}
if (model != null) { if (model != null) {
Build build = model.getBuild(); Build build = model.getBuild();

View File

@ -30,7 +30,6 @@ import java.nio.file.Paths;
import java.util.Properties; import java.util.Properties;
import java.util.stream.Stream; import java.util.stream.Stream;
import org.apache.commons.lang3.StringUtils;
import org.apache.maven.project.MavenProject; import org.apache.maven.project.MavenProject;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
@ -109,10 +108,11 @@ public class DefaultBuildResumptionDataRepository implements BuildResumptionData
// This method is made package-private for testing purposes // This method is made package-private for testing purposes
void applyResumptionProperties(MavenExecutionRequest request, Properties properties) { 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); String propertyValue = properties.getProperty(REMAINING_PROJECTS);
Stream.of(propertyValue.split(PROPERTY_DELIMITER)) Stream.of(propertyValue.split(PROPERTY_DELIMITER))
.filter(StringUtils::isNotEmpty) .filter(str -> str != null && !str.isEmpty())
.forEach(request.getProjectActivation()::activateOptionalProject); .forEach(request.getProjectActivation()::activateOptionalProject);
LOGGER.info("Resuming from {} due to the --resume / -r feature.", propertyValue); LOGGER.info("Resuming from {} due to the --resume / -r feature.", propertyValue);
} }

View File

@ -21,7 +21,6 @@ package org.apache.maven.internal.impl;
import javax.inject.Named; import javax.inject.Named;
import javax.inject.Singleton; import javax.inject.Singleton;
import org.apache.commons.lang3.StringUtils;
import org.apache.maven.api.ArtifactCoordinate; import org.apache.maven.api.ArtifactCoordinate;
import org.apache.maven.api.annotations.Nonnull; import org.apache.maven.api.annotations.Nonnull;
import org.apache.maven.api.services.ArtifactCoordinateFactory; import org.apache.maven.api.services.ArtifactCoordinateFactory;
@ -43,12 +42,12 @@ public class DefaultArtifactCoordinateFactory implements ArtifactCoordinateFacto
if (request.getType() != null) { if (request.getType() != null) {
type = session.getSession().getArtifactTypeRegistry().get(request.getType()); type = session.getSession().getArtifactTypeRegistry().get(request.getType());
} }
String classifier = StringUtils.isNotEmpty(request.getClassifier()) String str1 = request.getClassifier();
? request.getClassifier() String classifier =
: type != null ? type.getClassifier() : ""; str1 != null && !str1.isEmpty() ? request.getClassifier() : type != null ? type.getClassifier() : "";
String extension = StringUtils.isNotEmpty(request.getExtension()) String str = request.getExtension();
? request.getExtension() String extension =
: type != null ? type.getExtension() : ""; str != null && !str.isEmpty() ? request.getExtension() : type != null ? type.getExtension() : "";
return new DefaultArtifactCoordinate( return new DefaultArtifactCoordinate(
session, session,
new org.eclipse.aether.artifact.DefaultArtifact( new org.eclipse.aether.artifact.DefaultArtifact(

View File

@ -21,7 +21,6 @@ package org.apache.maven.internal.impl;
import javax.inject.Named; import javax.inject.Named;
import javax.inject.Singleton; import javax.inject.Singleton;
import org.apache.commons.lang3.StringUtils;
import org.apache.maven.api.Artifact; import org.apache.maven.api.Artifact;
import org.apache.maven.api.annotations.Nonnull; import org.apache.maven.api.annotations.Nonnull;
import org.apache.maven.api.services.ArtifactFactory; import org.apache.maven.api.services.ArtifactFactory;
@ -43,12 +42,12 @@ public class DefaultArtifactFactory implements ArtifactFactory {
if (request.getType() != null) { if (request.getType() != null) {
type = session.getSession().getArtifactTypeRegistry().get(request.getType()); type = session.getSession().getArtifactTypeRegistry().get(request.getType());
} }
String classifier = StringUtils.isNotEmpty(request.getClassifier()) String str1 = request.getClassifier();
? request.getClassifier() String classifier =
: type != null ? type.getClassifier() : null; str1 != null && !str1.isEmpty() ? request.getClassifier() : type != null ? type.getClassifier() : null;
String extension = StringUtils.isNotEmpty(request.getExtension()) String str = request.getExtension();
? request.getExtension() String extension =
: type != null ? type.getExtension() : null; str != null && !str.isEmpty() ? request.getExtension() : type != null ? type.getExtension() : null;
return new DefaultArtifact( return new DefaultArtifact(
session, session,
new org.eclipse.aether.artifact.DefaultArtifact( new org.eclipse.aether.artifact.DefaultArtifact(

View File

@ -24,7 +24,6 @@ import javax.inject.Singleton;
import org.apache.maven.plugin.MavenPluginPrerequisitesChecker; import org.apache.maven.plugin.MavenPluginPrerequisitesChecker;
import org.apache.maven.plugin.descriptor.PluginDescriptor; import org.apache.maven.plugin.descriptor.PluginDescriptor;
import org.codehaus.plexus.util.StringUtils;
import org.eclipse.aether.version.InvalidVersionSpecificationException; import org.eclipse.aether.version.InvalidVersionSpecificationException;
import org.eclipse.aether.version.Version; import org.eclipse.aether.version.Version;
import org.eclipse.aether.version.VersionConstraint; import org.eclipse.aether.version.VersionConstraint;
@ -44,7 +43,7 @@ public class MavenPluginJavaPrerequisiteChecker implements MavenPluginPrerequisi
@Override @Override
public void accept(PluginDescriptor pluginDescriptor) { public void accept(PluginDescriptor pluginDescriptor) {
String requiredJavaVersion = pluginDescriptor.getRequiredJavaVersion(); String requiredJavaVersion = pluginDescriptor.getRequiredJavaVersion();
if (StringUtils.isNotBlank(requiredJavaVersion)) { if (requiredJavaVersion != null && !requiredJavaVersion.isEmpty()) {
String currentJavaVersion = System.getProperty("java.version"); String currentJavaVersion = System.getProperty("java.version");
if (!matchesVersion(requiredJavaVersion, currentJavaVersion)) { if (!matchesVersion(requiredJavaVersion, currentJavaVersion)) {
throw new IllegalStateException("Required Java version " + requiredJavaVersion throw new IllegalStateException("Required Java version " + requiredJavaVersion

View File

@ -20,8 +20,8 @@ package org.apache.maven.project.artifact;
import java.io.File; import java.io.File;
import java.io.IOException; 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.Artifact;
import org.apache.maven.artifact.metadata.AbstractArtifactMetadata; import org.apache.maven.artifact.metadata.AbstractArtifactMetadata;
import org.apache.maven.artifact.metadata.ArtifactMetadata; import org.apache.maven.artifact.metadata.ArtifactMetadata;
@ -74,7 +74,8 @@ public class ProjectArtifactMetadata extends AbstractArtifactMetadata {
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
try { try {
FileUtils.copyFile(file, destination); Files.createDirectories(destination.toPath().getParent());
Files.copy(file.toPath(), destination.toPath());
} catch (IOException e) { } catch (IOException e) {
throw new RepositoryMetadataStoreException("Error copying POM to the local repository.", e); throw new RepositoryMetadataStoreException("Error copying POM to the local repository.", e);
} }

View File

@ -24,10 +24,9 @@ import javax.inject.Singleton;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.util.Objects;
import java.util.Properties; import java.util.Properties;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.Validate;
import org.apache.maven.rtinfo.RuntimeInformation; import org.apache.maven.rtinfo.RuntimeInformation;
import org.eclipse.aether.version.InvalidVersionSpecificationException; import org.eclipse.aether.version.InvalidVersionSpecificationException;
import org.eclipse.aether.version.Version; import org.eclipse.aether.version.Version;
@ -90,7 +89,9 @@ public class DefaultRuntimeInformation implements RuntimeInformation {
@Override @Override
public boolean isMavenVersion(String versionRange) { public boolean isMavenVersion(String versionRange) {
Validate.notBlank(versionRange, "versionRange can neither be null, empty nor blank"); if (Objects.requireNonNull(versionRange, "versionRange cannot be null").isEmpty()) {
throw new IllegalArgumentException("versionRange cannot be empty");
}
VersionConstraint constraint; VersionConstraint constraint;
try { try {
@ -102,7 +103,9 @@ public class DefaultRuntimeInformation implements RuntimeInformation {
Version current; Version current;
try { try {
String mavenVersion = getMavenVersion(); 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); current = versionScheme.parseVersion(mavenVersion);
} catch (InvalidVersionSpecificationException e) { } catch (InvalidVersionSpecificationException e) {

View File

@ -21,9 +21,9 @@ package org.apache.maven.artifact.handler;
import javax.inject.Inject; import javax.inject.Inject;
import java.io.File; import java.io.File;
import java.nio.file.Files;
import java.util.List; import java.util.List;
import org.apache.commons.io.FileUtils;
import org.codehaus.plexus.PlexusContainer; import org.codehaus.plexus.PlexusContainer;
import org.codehaus.plexus.testing.PlexusTest; import org.codehaus.plexus.testing.PlexusTest;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
@ -40,7 +40,7 @@ public class ArtifactHandlerTest {
public void testAptConsistency() throws Exception { public void testAptConsistency() throws Exception {
File apt = getTestFile("src/site/apt/artifact-handlers.apt"); 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) { for (String line : lines) {
if (line.startsWith("||")) { if (line.startsWith("||")) {

View File

@ -24,12 +24,12 @@ import javax.inject.Singleton;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.nio.file.Files;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.LinkedHashMap; import java.util.LinkedHashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import org.apache.commons.io.FileUtils;
import org.apache.maven.api.model.Model; import org.apache.maven.api.model.Model;
import org.apache.maven.artifact.Artifact; import org.apache.maven.artifact.Artifact;
import org.apache.maven.artifact.DefaultArtifact; import org.apache.maven.artifact.DefaultArtifact;
@ -274,7 +274,8 @@ public class TestRepositorySystem implements RepositorySystem {
File remoteFile = new File(remoteRepo.getBasedir(), remoteRepo.pathOf(artifact)); 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); artifact.setResolved(true);

View File

@ -19,6 +19,8 @@
package org.apache.maven.project; package org.apache.maven.project;
import java.io.File; import java.io.File;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path; import java.nio.file.Path;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections; import java.util.Collections;
@ -178,11 +180,11 @@ public class ProjectBuilderTest extends AbstractCoreMavenComponentTestCase {
projectBuilder.build(child, configuration); projectBuilder.build(child, configuration);
// modify parent // modify parent
File parent = new File(tempDir.toFile(), "pom.xml"); File parent = new File(tempDir.toFile(), "pom.xml");
String parentContent = FileUtils.readFileToString(parent, "UTF-8"); String parentContent = new String(Files.readAllBytes(parent.toPath()), StandardCharsets.UTF_8);
parentContent = parentContent.replace( parentContent = parentContent.replace(
"<packaging>pom</packaging>", "<packaging>pom</packaging>",
"<packaging>pom</packaging><properties><addedProperty>addedValue</addedProperty></properties>"); "<packaging>pom</packaging><properties><addedProperty>addedValue</addedProperty></properties>");
FileUtils.write(parent, parentContent, "UTF-8"); Files.write(parent.toPath(), parentContent.getBytes(StandardCharsets.UTF_8));
// re-build pom with modified parent // re-build pom with modified parent
ProjectBuildingResult result = projectBuilder.build(child, configuration); ProjectBuildingResult result = projectBuilder.build(child, configuration);
assertThat(result.getProject().getProperties(), hasKey((Object) "addedProperty")); assertThat(result.getProject().getProperties(), hasKey((Object) "addedProperty"));

View File

@ -22,9 +22,10 @@ import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.net.MalformedURLException; import java.net.MalformedURLException;
import java.net.URL; import java.net.URL;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.Collection; import java.util.Collection;
import org.apache.commons.io.FileUtils;
import org.eclipse.aether.artifact.Artifact; import org.eclipse.aether.artifact.Artifact;
import org.eclipse.aether.metadata.Metadata; import org.eclipse.aether.metadata.Metadata;
import org.eclipse.aether.repository.RemoteRepository; import org.eclipse.aether.repository.RemoteRepository;
@ -50,7 +51,10 @@ public class TestRepositoryConnector implements RepositoryConnector {
public TestRepositoryConnector(RemoteRepository repository) { public TestRepositoryConnector(RemoteRepository repository) {
this.repository = repository; this.repository = repository;
try { try {
basedir = FileUtils.toFile(new URL(repository.getUrl())); URL url = new URL(repository.getUrl());
if ("file".equals(url.getProtocol())) {
basedir = new File(url.getPath());
}
} catch (MalformedURLException e) { } catch (MalformedURLException e) {
throw new IllegalStateException(e); throw new IllegalStateException(e);
} }
@ -65,7 +69,9 @@ public class TestRepositoryConnector implements RepositoryConnector {
for (ArtifactDownload download : artifactDownloads) { for (ArtifactDownload download : artifactDownloads) {
File remoteFile = new File(basedir, path(download.getArtifact())); File remoteFile = new File(basedir, path(download.getArtifact()));
try { try {
FileUtils.copyFile(remoteFile, download.getFile()); Path dest = download.getFile().toPath();
Files.createDirectories(dest.getParent());
Files.copy(remoteFile.toPath(), dest);
} catch (IOException e) { } catch (IOException e) {
if (!remoteFile.exists()) { if (!remoteFile.exists()) {
download.setException(new ArtifactNotFoundException(download.getArtifact(), repository)); download.setException(new ArtifactNotFoundException(download.getArtifact(), repository));
@ -79,7 +85,9 @@ public class TestRepositoryConnector implements RepositoryConnector {
for (final MetadataDownload download : metadataDownloads) { for (final MetadataDownload download : metadataDownloads) {
File remoteFile = new File(basedir, path(download.getMetadata())); File remoteFile = new File(basedir, path(download.getMetadata()));
try { try {
FileUtils.copyFile(remoteFile, download.getFile()); Path dest = download.getFile().toPath();
Files.createDirectories(dest.getParent());
Files.copy(remoteFile.toPath(), dest);
} catch (IOException e) { } catch (IOException e) {
if (!remoteFile.exists()) { if (!remoteFile.exists()) {
download.setException(new MetadataNotFoundException(download.getMetadata(), repository)); download.setException(new MetadataNotFoundException(download.getMetadata(), repository));

View File

@ -146,10 +146,6 @@ under the License.
<groupId>commons-cli</groupId> <groupId>commons-cli</groupId>
<artifactId>commons-cli</artifactId> <artifactId>commons-cli</artifactId>
</dependency> </dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
</dependency>
<dependency> <dependency>
<groupId>org.mockito</groupId> <groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId> <artifactId>mockito-core</artifactId>

View File

@ -25,7 +25,6 @@ import java.util.Date;
import java.util.Locale; import java.util.Locale;
import java.util.Properties; import java.util.Properties;
import org.apache.commons.lang3.StringUtils;
import org.codehaus.plexus.util.Os; import org.codehaus.plexus.util.Os;
import org.slf4j.Logger; import org.slf4j.Logger;
@ -106,7 +105,7 @@ public final class CLIReportingUtils {
if (rev != null || timestamp != null) { if (rev != null || timestamp != null) {
msg += " ("; msg += " (";
msg += (rev != null ? rev : ""); msg += (rev != null ? rev : "");
if (StringUtils.isNotBlank(timestamp)) { if (timestamp != null && !timestamp.isEmpty()) {
String ts = formatTimestamp(Long.parseLong(timestamp)); String ts = formatTimestamp(Long.parseLong(timestamp));
msg += (rev != null ? "; " : "") + ts; msg += (rev != null ? "; " : "") + ts;
} }

View File

@ -23,7 +23,6 @@ import java.text.DecimalFormat;
import java.text.DecimalFormatSymbols; import java.text.DecimalFormatSymbols;
import java.util.Locale; import java.util.Locale;
import org.apache.commons.lang3.Validate;
import org.eclipse.aether.transfer.AbstractTransferListener; import org.eclipse.aether.transfer.AbstractTransferListener;
import org.eclipse.aether.transfer.TransferCancelledException; import org.eclipse.aether.transfer.TransferCancelledException;
import org.eclipse.aether.transfer.TransferEvent; import org.eclipse.aether.transfer.TransferEvent;
@ -100,7 +99,9 @@ public abstract class AbstractMavenTransferListener extends AbstractTransferList
public abstract String symbol(); public abstract String symbol();
public static ScaleUnit getScaleUnit(long size) { 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()) { if (size >= GIGABYTE.bytes()) {
return GIGABYTE; return GIGABYTE;
@ -132,7 +133,9 @@ public abstract class AbstractMavenTransferListener extends AbstractTransferList
@SuppressWarnings("checkstyle:magicnumber") @SuppressWarnings("checkstyle:magicnumber")
public String format(long size, ScaleUnit unit, boolean omitSymbol) { 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) { if (unit == null) {
unit = ScaleUnit.getScaleUnit(size); unit = ScaleUnit.getScaleUnit(size);
@ -157,12 +160,13 @@ public abstract class AbstractMavenTransferListener extends AbstractTransferList
} }
public String formatProgress(long progressedSize, long size) { public String formatProgress(long progressedSize, long size) {
Validate.isTrue(progressedSize >= 0L, "progressed file size cannot be negative: %s", progressedSize); if (progressedSize < 0L) {
Validate.isTrue( throw new IllegalArgumentException("progressed file size cannot be negative: " + size);
size < 0L || progressedSize <= size, }
"progressed file size cannot be greater than size: %s > %s", if (size >= 0 && progressedSize > size) {
progressedSize, throw new IllegalArgumentException(
size); "progressed file size cannot be greater than size: " + progressedSize + " > " + size);
}
if (size >= 0L && progressedSize != size) { if (size >= 0L && progressedSize != size) {
ScaleUnit unit = ScaleUnit.getScaleUnit(size); ScaleUnit unit = ScaleUnit.getScaleUnit(size);

View File

@ -25,7 +25,6 @@ import java.util.LinkedHashMap;
import java.util.Locale; import java.util.Locale;
import java.util.Map; import java.util.Map;
import org.apache.commons.lang3.StringUtils;
import org.eclipse.aether.transfer.TransferCancelledException; import org.eclipse.aether.transfer.TransferCancelledException;
import org.eclipse.aether.transfer.TransferEvent; import org.eclipse.aether.transfer.TransferEvent;
import org.eclipse.aether.transfer.TransferResource; import org.eclipse.aether.transfer.TransferResource;
@ -96,7 +95,8 @@ public class ConsoleMavenTransferListener extends AbstractMavenTransferListener
StringBuilder status = new StringBuilder(); StringBuilder status = new StringBuilder();
if (printResourceNames) { if (printResourceNames) {
status.append(StringUtils.substringAfterLast(resourceName, "/")); int idx = resourceName.lastIndexOf('/');
status.append(idx < 0 ? resourceName : resourceName.substring(idx + 1));
status.append(" ("); status.append(" (");
} }

View File

@ -407,11 +407,6 @@ under the License.
<artifactId>commons-jxpath</artifactId> <artifactId>commons-jxpath</artifactId>
<version>${jxpathVersion}</version> <version>${jxpathVersion}</version>
</dependency> </dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>${commonsLangVersion}</version>
</dependency>
<dependency> <dependency>
<groupId>org.codehaus.plexus</groupId> <groupId>org.codehaus.plexus</groupId>
<artifactId>plexus-sec-dispatcher</artifactId> <artifactId>plexus-sec-dispatcher</artifactId>