Remove plexus-utils and commons-xxx references (#833)

This commit is contained in:
Guillaume Nodet
2023-04-06 10:52:45 +02:00
committed by GitHub
parent eef6c2f16f
commit 5093ced94b
6 changed files with 39 additions and 63 deletions

View File

@@ -43,7 +43,6 @@ import java.util.stream.Stream;
import org.apache.maven.cli.internal.extension.model.CoreExtension; import org.apache.maven.cli.internal.extension.model.CoreExtension;
import org.apache.maven.cli.internal.extension.model.io.xpp3.CoreExtensionsXpp3Reader; import org.apache.maven.cli.internal.extension.model.io.xpp3.CoreExtensionsXpp3Reader;
import org.codehaus.plexus.util.StringUtils;
import org.codehaus.plexus.util.xml.pull.XmlPullParserException; import org.codehaus.plexus.util.xml.pull.XmlPullParserException;
import org.mvndaemon.mvnd.common.Environment; import org.mvndaemon.mvnd.common.Environment;
import org.mvndaemon.mvnd.common.InterpolationHelper; import org.mvndaemon.mvnd.common.InterpolationHelper;
@@ -440,8 +439,8 @@ public class DaemonParameters {
private static List<String> parseExtClasspath(Path userDir) { private static List<String> parseExtClasspath(Path userDir) {
String extClassPath = System.getProperty(EXT_CLASS_PATH); String extClassPath = System.getProperty(EXT_CLASS_PATH);
List<String> jars = new ArrayList<>(); List<String> jars = new ArrayList<>();
if (StringUtils.isNotEmpty(extClassPath)) { if (extClassPath != null) {
for (String jar : StringUtils.split(extClassPath, File.pathSeparator)) { for (String jar : extClassPath.split(File.pathSeparator)) {
Path path = userDir.resolve(jar).toAbsolutePath(); Path path = userDir.resolve(jar).toAbsolutePath();
jars.add(path.toString()); jars.add(path.toString());
} }

View File

@@ -93,7 +93,6 @@ import org.codehaus.plexus.PlexusContainer;
import org.codehaus.plexus.classworlds.ClassWorld; import org.codehaus.plexus.classworlds.ClassWorld;
import org.codehaus.plexus.classworlds.realm.ClassRealm; import org.codehaus.plexus.classworlds.realm.ClassRealm;
import org.codehaus.plexus.component.repository.exception.ComponentLookupException; import org.codehaus.plexus.component.repository.exception.ComponentLookupException;
import org.codehaus.plexus.util.StringUtils;
import org.eclipse.aether.transfer.TransferListener; import org.eclipse.aether.transfer.TransferListener;
import org.mvndaemon.mvnd.cache.invalidating.InvalidatingExtensionRealmCache; import org.mvndaemon.mvnd.cache.invalidating.InvalidatingExtensionRealmCache;
import org.mvndaemon.mvnd.cache.invalidating.InvalidatingPluginArtifactsCache; import org.mvndaemon.mvnd.cache.invalidating.InvalidatingPluginArtifactsCache;
@@ -652,12 +651,10 @@ public class DaemonMavenCli implements DaemonCli {
List<File> jars = new ArrayList<>(); List<File> jars = new ArrayList<>();
if (StringUtils.isNotEmpty(extClassPath)) { if (extClassPath != null) {
for (String jar : StringUtils.split(extClassPath, File.pathSeparator)) { for (String jar : extClassPath.split(File.pathSeparator)) {
File file = resolveFile(new File(jar), cliRequest.workingDirectory); File file = resolveFile(new File(jar), cliRequest.workingDirectory);
slf4jLogger.debug(" Included {}", file); slf4jLogger.debug(" Included {}", file);
jars.add(file); jars.add(file);
} }
} }
@@ -819,19 +816,11 @@ public class DaemonMavenCli implements DaemonCli {
private void logSummary( private void logSummary(
ExceptionSummary summary, Map<String, String> references, String indent, boolean showErrors) { ExceptionSummary summary, Map<String, String> references, String indent, boolean showErrors) {
String referenceKey = "";
if (StringUtils.isNotEmpty(summary.getReference())) {
referenceKey = references.get(summary.getReference());
if (referenceKey == null) {
referenceKey = "[Help " + (references.size() + 1) + "]";
references.put(summary.getReference(), referenceKey);
}
}
String msg = summary.getMessage(); String msg = summary.getMessage();
if (StringUtils.isNotEmpty(referenceKey)) { if (!summary.getReference().isEmpty()) {
String referenceKey =
references.computeIfAbsent(summary.getReference(), k -> "[Help " + (references.size() + 1) + "]");
if (msg.indexOf('\n') < 0) { if (msg.indexOf('\n') < 0) {
msg += " -> " + buffer().strong(referenceKey); msg += " -> " + buffer().strong(referenceKey);
} else { } else {

View File

@@ -49,7 +49,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.execution.MavenExecutionRequest; import org.apache.maven.execution.MavenExecutionRequest;
import org.apache.maven.project.MavenProject; import org.apache.maven.project.MavenProject;
import org.slf4j.Logger; import org.slf4j.Logger;
@@ -144,10 +143,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())) { if (properties.containsKey(REMAINING_PROJECTS)
&& (request.getResumeFrom() == null || request.getResumeFrom().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(s -> s != null && !s.isEmpty())
.forEach(request.getSelectedProjects()::add); .forEach(request.getSelectedProjects()::add);
LOGGER.info("Resuming from {} due to the --resume / -r feature.", propertyValue); LOGGER.info("Resuming from {} due to the --resume / -r feature.", propertyValue);
} }

View File

@@ -45,7 +45,6 @@ import com.google.inject.AbstractModule;
import org.apache.commons.cli.CommandLine; import org.apache.commons.cli.CommandLine;
import org.apache.commons.cli.Option; import org.apache.commons.cli.Option;
import org.apache.commons.cli.ParseException; import org.apache.commons.cli.ParseException;
import org.apache.commons.lang3.math.NumberUtils;
import org.apache.maven.InternalErrorException; import org.apache.maven.InternalErrorException;
import org.apache.maven.Maven; import org.apache.maven.Maven;
import org.apache.maven.building.FileSource; import org.apache.maven.building.FileSource;
@@ -88,7 +87,6 @@ import org.codehaus.plexus.PlexusContainer;
import org.codehaus.plexus.classworlds.ClassWorld; import org.codehaus.plexus.classworlds.ClassWorld;
import org.codehaus.plexus.classworlds.realm.ClassRealm; import org.codehaus.plexus.classworlds.realm.ClassRealm;
import org.codehaus.plexus.component.repository.exception.ComponentLookupException; import org.codehaus.plexus.component.repository.exception.ComponentLookupException;
import org.codehaus.plexus.util.StringUtils;
import org.eclipse.aether.transfer.TransferListener; import org.eclipse.aether.transfer.TransferListener;
import org.mvndaemon.mvnd.cache.invalidating.InvalidatingExtensionRealmCache; import org.mvndaemon.mvnd.cache.invalidating.InvalidatingExtensionRealmCache;
import org.mvndaemon.mvnd.cache.invalidating.InvalidatingPluginArtifactsCache; import org.mvndaemon.mvnd.cache.invalidating.InvalidatingPluginArtifactsCache;
@@ -637,12 +635,10 @@ public class DaemonMavenCli implements DaemonCli {
List<File> jars = new ArrayList<>(); List<File> jars = new ArrayList<>();
if (StringUtils.isNotEmpty(extClassPath)) { if (extClassPath != null) {
for (String jar : StringUtils.split(extClassPath, File.pathSeparator)) { for (String jar : extClassPath.split(File.pathSeparator)) {
File file = resolveFile(new File(jar), cliRequest.workingDirectory); File file = resolveFile(new File(jar), cliRequest.workingDirectory);
slf4jLogger.debug(" Included {}", file); slf4jLogger.debug(" Included {}", file);
jars.add(file); jars.add(file);
} }
} }
@@ -787,19 +783,11 @@ public class DaemonMavenCli implements DaemonCli {
private void logSummary( private void logSummary(
ExceptionSummary summary, Map<String, String> references, String indent, boolean showErrors) { ExceptionSummary summary, Map<String, String> references, String indent, boolean showErrors) {
String referenceKey = "";
if (StringUtils.isNotEmpty(summary.getReference())) {
referenceKey = references.get(summary.getReference());
if (referenceKey == null) {
referenceKey = "[Help " + (references.size() + 1) + "]";
references.put(summary.getReference(), referenceKey);
}
}
String msg = summary.getMessage(); String msg = summary.getMessage();
if (StringUtils.isNotEmpty(referenceKey)) { if (!summary.getReference().isEmpty()) {
String referenceKey =
references.computeIfAbsent(summary.getReference(), k -> "[Help " + (references.size() + 1) + "]");
if (msg.indexOf('\n') < 0) { if (msg.indexOf('\n') < 0) {
msg += " -> " + buffer().strong(referenceKey); msg += " -> " + buffer().strong(referenceKey);
} else { } else {
@@ -1241,29 +1229,23 @@ public class DaemonMavenCli implements DaemonCli {
int calculateDegreeOfConcurrency(String threadConfiguration) { int calculateDegreeOfConcurrency(String threadConfiguration) {
if (threadConfiguration.endsWith("C")) { if (threadConfiguration.endsWith("C")) {
threadConfiguration = threadConfiguration.substring(0, threadConfiguration.length() - 1); try {
String str = threadConfiguration.substring(0, threadConfiguration.length() - 1);
float coreMultiplier = Float.parseFloat(str);
if (!NumberUtils.isParsable(threadConfiguration)) { 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;
} catch (NumberFormatException e) {
throw new IllegalArgumentException("Invalid threads core multiplier value: '" + threadConfiguration throw new IllegalArgumentException("Invalid threads core multiplier value: '" + threadConfiguration
+ "C'. Supported are int and float values ending with C."); + "C'. Supported are int and float values ending with C.");
} }
float coreMultiplier = Float.parseFloat(threadConfiguration);
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 { } else {
if (!NumberUtils.isParsable(threadConfiguration)) {
throw new IllegalArgumentException(
"Invalid threads value: '" + threadConfiguration + "'. Supported are int values.");
}
try { try {
int threads = Integer.parseInt(threadConfiguration); int threads = Integer.parseInt(threadConfiguration);

View File

@@ -31,7 +31,6 @@ import org.codehaus.plexus.components.interactivity.InputHandler;
import org.codehaus.plexus.components.interactivity.OutputHandler; import org.codehaus.plexus.components.interactivity.OutputHandler;
import org.codehaus.plexus.components.interactivity.Prompter; import org.codehaus.plexus.components.interactivity.Prompter;
import org.codehaus.plexus.components.interactivity.PrompterException; import org.codehaus.plexus.components.interactivity.PrompterException;
import org.codehaus.plexus.util.StringUtils;
import org.eclipse.sisu.Priority; import org.eclipse.sisu.Priority;
import org.eclipse.sisu.Typed; import org.eclipse.sisu.Typed;
import org.mvndaemon.mvnd.common.Message; import org.mvndaemon.mvnd.common.Message;
@@ -115,7 +114,7 @@ public class DaemonPrompter extends AbstractInputHandler implements Prompter, In
} catch (IOException e) { } catch (IOException e) {
throw new PrompterException("Failed to prompt user", e); throw new PrompterException("Failed to prompt user", e);
} }
if (StringUtils.isEmpty(line)) { if (line == null || line.isEmpty()) {
line = defaultReply; line = defaultReply;
} }
if (line != null && (possibleValues != null && !possibleValues.contains(line))) { if (line != null && (possibleValues != null && !possibleValues.contains(line))) {

View File

@@ -36,7 +36,6 @@ import org.apache.maven.eventspy.EventSpy;
import org.apache.maven.execution.ExecutionEvent; import org.apache.maven.execution.ExecutionEvent;
import org.apache.maven.execution.MavenSession; import org.apache.maven.execution.MavenSession;
import org.apache.maven.plugin.MojoExecution; import org.apache.maven.plugin.MojoExecution;
import org.codehaus.plexus.util.StringUtils;
import org.eclipse.sisu.Typed; import org.eclipse.sisu.Typed;
import org.mvndaemon.mvnd.common.Environment; import org.mvndaemon.mvnd.common.Environment;
import org.slf4j.Logger; import org.slf4j.Logger;
@@ -196,9 +195,17 @@ public class BuildTimeEventSpy extends AbstractEventSpy {
public String name() { public String name() {
String name = mojo.getKey(); String name = mojo.getKey();
String truncatedName = if (name.length() < MAX_NAME_LENGTH) {
name.length() >= MAX_NAME_LENGTH ? StringUtils.substring(name, 0, MAX_NAME_LENGTH) : name + " "; StringBuilder sb = new StringBuilder(MAX_NAME_LENGTH);
return StringUtils.rightPad(truncatedName, MAX_NAME_LENGTH, "."); sb.append(name);
sb.append(' ');
while (sb.length() < MAX_NAME_LENGTH) {
sb.append('.');
}
return sb.toString();
} else {
return name.substring(0, MAX_NAME_LENGTH);
}
} }
public long duration() { public long duration() {