mirror of https://github.com/apache/maven.git
[MNG-7764] Small code improvements (#1088)
This commit is contained in:
parent
c9f0c237e0
commit
5ebbb8ff50
|
@ -25,8 +25,6 @@ import javax.inject.Singleton;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
|
||||||
import java.util.Properties;
|
|
||||||
|
|
||||||
import org.apache.maven.api.annotations.Nonnull;
|
import org.apache.maven.api.annotations.Nonnull;
|
||||||
import org.apache.maven.api.services.BuilderProblem;
|
import org.apache.maven.api.services.BuilderProblem;
|
||||||
|
@ -55,7 +53,6 @@ public class DefaultToolchainsBuilder implements ToolchainsBuilder {
|
||||||
@Override
|
@Override
|
||||||
public ToolchainsBuilderResult build(ToolchainsBuilderRequest request)
|
public ToolchainsBuilderResult build(ToolchainsBuilderRequest request)
|
||||||
throws ToolchainsBuilderException, IllegalArgumentException {
|
throws ToolchainsBuilderException, IllegalArgumentException {
|
||||||
DefaultSession session = (DefaultSession) request.getSession();
|
|
||||||
try {
|
try {
|
||||||
DefaultToolchainsBuildingRequest req = new DefaultToolchainsBuildingRequest();
|
DefaultToolchainsBuildingRequest req = new DefaultToolchainsBuildingRequest();
|
||||||
if (request.getGlobalToolchainsSource().isPresent()) {
|
if (request.getGlobalToolchainsSource().isPresent()) {
|
||||||
|
@ -89,12 +86,6 @@ public class DefaultToolchainsBuilder implements ToolchainsBuilder {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private Properties toProperties(Map<String, String> map) {
|
|
||||||
Properties properties = new Properties();
|
|
||||||
properties.putAll(map);
|
|
||||||
return properties;
|
|
||||||
}
|
|
||||||
|
|
||||||
private static class MappedToolchainsSource implements org.apache.maven.building.Source {
|
private static class MappedToolchainsSource implements org.apache.maven.building.Source {
|
||||||
private final Source source;
|
private final Source source;
|
||||||
|
|
||||||
|
|
|
@ -38,6 +38,7 @@ import org.apache.maven.plugin.MojoExecution;
|
||||||
import org.apache.maven.plugin.descriptor.MojoDescriptor;
|
import org.apache.maven.plugin.descriptor.MojoDescriptor;
|
||||||
import org.apache.maven.plugin.descriptor.Parameter;
|
import org.apache.maven.plugin.descriptor.Parameter;
|
||||||
import org.apache.maven.project.MavenProject;
|
import org.apache.maven.project.MavenProject;
|
||||||
|
import org.codehaus.plexus.util.xml.Xpp3Dom;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
@ -173,7 +174,7 @@ public class DefaultMojoExecutionConfigurator implements MojoExecutionConfigurat
|
||||||
|
|
||||||
private Set<String> getUnknownParameters(MojoExecution mojoExecution, Set<String> parameters) {
|
private Set<String> getUnknownParameters(MojoExecution mojoExecution, Set<String> parameters) {
|
||||||
return stream(mojoExecution.getConfiguration().getChildren())
|
return stream(mojoExecution.getConfiguration().getChildren())
|
||||||
.map(x -> x.getName())
|
.map(Xpp3Dom::getName)
|
||||||
.filter(name -> !parameters.contains(name))
|
.filter(name -> !parameters.contains(name))
|
||||||
.collect(Collectors.toSet());
|
.collect(Collectors.toSet());
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,14 +18,14 @@
|
||||||
*/
|
*/
|
||||||
package org.apache.maven.lifecycle.internal;
|
package org.apache.maven.lifecycle.internal;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
import java.util.function.Function;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
import org.apache.maven.artifact.ArtifactUtils;
|
import org.apache.maven.artifact.ArtifactUtils;
|
||||||
import org.apache.maven.execution.MavenSession;
|
import org.apache.maven.execution.MavenSession;
|
||||||
|
@ -55,23 +55,14 @@ public class ProjectBuildList implements Iterable<ProjectSegment> {
|
||||||
* @return a project build list for the supplied task segment
|
* @return a project build list for the supplied task segment
|
||||||
*/
|
*/
|
||||||
public ProjectBuildList getByTaskSegment(TaskSegment taskSegment) {
|
public ProjectBuildList getByTaskSegment(TaskSegment taskSegment) {
|
||||||
List<ProjectSegment> currentSegment = new ArrayList<>();
|
return new ProjectBuildList(
|
||||||
for (ProjectSegment projectBuild : items) {
|
items.stream().filter(pb -> taskSegment == pb.getTaskSegment()).collect(Collectors.toList()));
|
||||||
if (taskSegment == projectBuild.getTaskSegment()) { // NOTE: There's no notion of taskSegment equality.
|
|
||||||
currentSegment.add(projectBuild);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return new ProjectBuildList(currentSegment);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public Map<MavenProject, ProjectSegment> selectSegment(TaskSegment taskSegment) {
|
public Map<MavenProject, ProjectSegment> selectSegment(TaskSegment taskSegment) {
|
||||||
Map<MavenProject, ProjectSegment> result = new HashMap<>();
|
return items.stream()
|
||||||
for (ProjectSegment projectBuild : items) {
|
.filter(pb -> taskSegment == pb.getTaskSegment())
|
||||||
if (taskSegment == projectBuild.getTaskSegment()) { // NOTE: There's no notion of taskSegment equality.
|
.collect(Collectors.toMap(ProjectSegment::getProject, Function.identity()));
|
||||||
result.put(projectBuild.getProject(), projectBuild);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -80,12 +71,10 @@ public class ProjectBuildList implements Iterable<ProjectSegment> {
|
||||||
* @return The projectSegment or null.
|
* @return The projectSegment or null.
|
||||||
*/
|
*/
|
||||||
public ProjectSegment findByMavenProject(MavenProject mavenProject) {
|
public ProjectSegment findByMavenProject(MavenProject mavenProject) {
|
||||||
for (ProjectSegment projectBuild : items) {
|
return items.stream()
|
||||||
if (mavenProject.equals(projectBuild.getProject())) {
|
.filter(pb -> mavenProject.equals(pb.getProject()))
|
||||||
return projectBuild;
|
.findFirst()
|
||||||
}
|
.orElse(null);
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public Iterator<ProjectSegment> iterator() {
|
public Iterator<ProjectSegment> iterator() {
|
||||||
|
@ -125,11 +114,6 @@ public class ProjectBuildList implements Iterable<ProjectSegment> {
|
||||||
* @return a set of all the projects managed by the build
|
* @return a set of all the projects managed by the build
|
||||||
*/
|
*/
|
||||||
public Set<MavenProject> getProjects() {
|
public Set<MavenProject> getProjects() {
|
||||||
Set<MavenProject> projects = new HashSet<>();
|
return items.stream().map(ProjectSegment::getProject).collect(Collectors.toSet());
|
||||||
|
|
||||||
for (ProjectSegment s : items) {
|
|
||||||
projects.add(s.getProject());
|
|
||||||
}
|
|
||||||
return projects;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,10 +19,14 @@
|
||||||
package org.apache.maven.lifecycle.mapping;
|
package org.apache.maven.lifecycle.mapping;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Arrays;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
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 java.util.Optional;
|
||||||
|
import java.util.function.Function;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
import org.codehaus.plexus.util.StringUtils;
|
import org.codehaus.plexus.util.StringUtils;
|
||||||
|
|
||||||
|
@ -54,31 +58,21 @@ public class LifecyclePhase {
|
||||||
|
|
||||||
if (goals != null && !goals.isEmpty()) {
|
if (goals != null && !goals.isEmpty()) {
|
||||||
String[] mojoGoals = StringUtils.split(goals, ",");
|
String[] mojoGoals = StringUtils.split(goals, ",");
|
||||||
|
mojos = Arrays.stream(mojoGoals).map(fromGoalIntoLifecycleMojo).collect(Collectors.toList());
|
||||||
for (String mojoGoal : mojoGoals) {
|
|
||||||
LifecycleMojo lifecycleMojo = new LifecycleMojo();
|
|
||||||
lifecycleMojo.setGoal(mojoGoal.trim());
|
|
||||||
mojos.add(lifecycleMojo);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private final Function<String, LifecycleMojo> fromGoalIntoLifecycleMojo = s -> {
|
||||||
|
LifecycleMojo lifecycleMojo = new LifecycleMojo();
|
||||||
|
lifecycleMojo.setGoal(s.trim());
|
||||||
|
return lifecycleMojo;
|
||||||
|
};
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
StringBuilder sb = new StringBuilder();
|
return Optional.ofNullable(getMojos()).orElse(Collections.emptyList()).stream()
|
||||||
boolean first = true;
|
.map(LifecycleMojo::getGoal)
|
||||||
List<LifecycleMojo> mojos = getMojos();
|
.collect(Collectors.joining(","));
|
||||||
if (mojos != null) {
|
|
||||||
for (LifecycleMojo mojo : mojos) {
|
|
||||||
if (first) {
|
|
||||||
first = false;
|
|
||||||
} else {
|
|
||||||
sb.append(',');
|
|
||||||
}
|
|
||||||
sb.append(mojo.getGoal());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return sb.toString();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Deprecated
|
@Deprecated
|
||||||
|
|
|
@ -1054,11 +1054,8 @@ public class MavenCli {
|
||||||
String referenceKey = "";
|
String referenceKey = "";
|
||||||
|
|
||||||
if (StringUtils.isNotEmpty(summary.getReference())) {
|
if (StringUtils.isNotEmpty(summary.getReference())) {
|
||||||
referenceKey = references.get(summary.getReference());
|
referenceKey =
|
||||||
if (referenceKey == null) {
|
references.computeIfAbsent(summary.getReference(), k -> "[Help " + (references.size() + 1) + "]");
|
||||||
referenceKey = "[Help " + (references.size() + 1) + "]";
|
|
||||||
references.put(summary.getReference(), referenceKey);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
String msg = summary.getMessage();
|
String msg = summary.getMessage();
|
||||||
|
|
|
@ -53,15 +53,4 @@ class DeveloperTest {
|
||||||
void testToStringNullSafe() {
|
void testToStringNullSafe() {
|
||||||
assertNotNull(new Developer().toString());
|
assertNotNull(new Developer().toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testToStringNotNonsense() {
|
|
||||||
Developer dev = new Developer();
|
|
||||||
dev.setName("Maven Tester");
|
|
||||||
dev.setEmail("tester@acme.localdomain");
|
|
||||||
dev.setId("20220118");
|
|
||||||
|
|
||||||
String s = dev.toString();
|
|
||||||
|
|
||||||
assert "Developer {id=20220118, Contributor {name=Maven Tester, email=tester@acme.localdomain}}".equals(s) : s;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue