Better internal helper methods (#1334)

This commit is contained in:
Guillaume Nodet 2023-12-07 21:05:02 +01:00 committed by GitHub
parent c4f62ff7c8
commit 71eb6de7e5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
21 changed files with 68 additions and 69 deletions

View File

@ -29,7 +29,6 @@ import java.util.Objects;
import java.util.Optional; import java.util.Optional;
import java.util.WeakHashMap; import java.util.WeakHashMap;
import java.util.concurrent.CopyOnWriteArrayList; import java.util.concurrent.CopyOnWriteArrayList;
import java.util.stream.Collectors;
import java.util.stream.Stream; import java.util.stream.Stream;
import org.apache.maven.api.Artifact; import org.apache.maven.api.Artifact;
@ -64,6 +63,7 @@ import org.apache.maven.api.services.VersionParser;
import org.apache.maven.artifact.repository.ArtifactRepository; import org.apache.maven.artifact.repository.ArtifactRepository;
import org.apache.maven.project.MavenProject; import org.apache.maven.project.MavenProject;
import static org.apache.maven.internal.impl.Utils.map;
import static org.apache.maven.internal.impl.Utils.nonNull; import static org.apache.maven.internal.impl.Utils.nonNull;
public abstract class AbstractSession implements InternalSession { public abstract class AbstractSession implements InternalSession {
@ -102,7 +102,7 @@ public abstract class AbstractSession implements InternalSession {
} }
public List<Project> getProjects(List<MavenProject> projects) { public List<Project> getProjects(List<MavenProject> projects) {
return projects == null ? null : projects.stream().map(this::getProject).collect(Collectors.toList()); return projects == null ? null : map(projects, this::getProject);
} }
public Project getProject(MavenProject project) { public Project getProject(MavenProject project) {
@ -110,9 +110,7 @@ public abstract class AbstractSession implements InternalSession {
} }
public List<org.eclipse.aether.repository.RemoteRepository> toRepositories(List<RemoteRepository> repositories) { public List<org.eclipse.aether.repository.RemoteRepository> toRepositories(List<RemoteRepository> repositories) {
return repositories == null return repositories == null ? null : map(repositories, this::toRepository);
? null
: repositories.stream().map(this::toRepository).collect(Collectors.toList());
} }
public org.eclipse.aether.repository.RemoteRepository toRepository(RemoteRepository repository) { public org.eclipse.aether.repository.RemoteRepository toRepository(RemoteRepository repository) {
@ -134,25 +132,19 @@ public abstract class AbstractSession implements InternalSession {
} }
public List<ArtifactRepository> toArtifactRepositories(List<RemoteRepository> repositories) { public List<ArtifactRepository> toArtifactRepositories(List<RemoteRepository> repositories) {
return repositories == null return repositories == null ? null : map(repositories, this::toArtifactRepository);
? null
: repositories.stream().map(this::toArtifactRepository).collect(Collectors.toList());
} }
public abstract ArtifactRepository toArtifactRepository(RemoteRepository repository); public abstract ArtifactRepository toArtifactRepository(RemoteRepository repository);
public List<org.eclipse.aether.graph.Dependency> toDependencies(Collection<DependencyCoordinate> dependencies) { public List<org.eclipse.aether.graph.Dependency> toDependencies(Collection<DependencyCoordinate> dependencies) {
return dependencies == null return dependencies == null ? null : map(dependencies, this::toDependency);
? null
: dependencies.stream().map(this::toDependency).collect(Collectors.toList());
} }
public abstract org.eclipse.aether.graph.Dependency toDependency(DependencyCoordinate dependency); public abstract org.eclipse.aether.graph.Dependency toDependency(DependencyCoordinate dependency);
public List<org.eclipse.aether.artifact.Artifact> toArtifacts(Collection<Artifact> artifacts) { public List<org.eclipse.aether.artifact.Artifact> toArtifacts(Collection<Artifact> artifacts) {
return artifacts == null return artifacts == null ? null : map(artifacts, this::toArtifact);
? null
: artifacts.stream().map(this::toArtifact).collect(Collectors.toList());
} }
public org.eclipse.aether.artifact.Artifact toArtifact(Artifact artifact) { public org.eclipse.aether.artifact.Artifact toArtifact(Artifact artifact) {

View File

@ -36,8 +36,8 @@ public class DefaultArtifact implements Artifact {
private final String id; private final String id;
public DefaultArtifact(@Nonnull InternalSession session, @Nonnull org.eclipse.aether.artifact.Artifact artifact) { public DefaultArtifact(@Nonnull InternalSession session, @Nonnull org.eclipse.aether.artifact.Artifact artifact) {
this.session = nonNull(session, "session can not be null"); this.session = nonNull(session, "session");
this.artifact = nonNull(artifact, "artifact can not be null"); this.artifact = nonNull(artifact, "artifact");
this.id = getGroupId() this.id = getGroupId()
+ ':' + ':'
+ getArtifactId() + getArtifactId()

View File

@ -35,8 +35,8 @@ public class DefaultArtifactCoordinate implements ArtifactCoordinate {
public DefaultArtifactCoordinate( public DefaultArtifactCoordinate(
@Nonnull InternalSession session, @Nonnull org.eclipse.aether.artifact.Artifact coordinate) { @Nonnull InternalSession session, @Nonnull org.eclipse.aether.artifact.Artifact coordinate) {
this.session = nonNull(session, "session can not be null"); this.session = nonNull(session, "session");
this.coordinate = nonNull(coordinate, "coordinate can not be null"); this.coordinate = nonNull(coordinate, "coordinate");
} }
public org.eclipse.aether.artifact.Artifact getCoordinate() { public org.eclipse.aether.artifact.Artifact getCoordinate() {

View File

@ -34,7 +34,7 @@ import static org.apache.maven.internal.impl.Utils.nonNull;
public class DefaultArtifactCoordinateFactory implements ArtifactCoordinateFactory { public class DefaultArtifactCoordinateFactory implements ArtifactCoordinateFactory {
@Override @Override
public ArtifactCoordinate create(@Nonnull ArtifactCoordinateFactoryRequest request) { public ArtifactCoordinate create(@Nonnull ArtifactCoordinateFactoryRequest request) {
nonNull(request, "request can not be null"); nonNull(request, "request");
InternalSession session = InternalSession.from(request.getSession()); InternalSession session = InternalSession.from(request.getSession());
ArtifactType type = null; ArtifactType type = null;
if (request.getType() != null) { if (request.getType() != null) {

View File

@ -47,15 +47,15 @@ public class DefaultArtifactDeployer implements ArtifactDeployer {
@Inject @Inject
DefaultArtifactDeployer(@Nonnull RepositorySystem repositorySystem) { DefaultArtifactDeployer(@Nonnull RepositorySystem repositorySystem) {
this.repositorySystem = nonNull(repositorySystem, "repositorySystem can not be null"); this.repositorySystem = nonNull(repositorySystem, "repositorySystem");
} }
@Override @Override
public void deploy(@Nonnull ArtifactDeployerRequest request) { public void deploy(@Nonnull ArtifactDeployerRequest request) {
nonNull(request, "request can not be null"); nonNull(request, "request");
InternalSession session = InternalSession.from(request.getSession()); InternalSession session = InternalSession.from(request.getSession());
Collection<Artifact> artifacts = nonNull(request.getArtifacts(), "request.artifacts can not be null"); Collection<Artifact> artifacts = nonNull(request.getArtifacts(), "request.artifacts");
RemoteRepository repository = nonNull(request.getRepository(), "request.repository can not be null"); RemoteRepository repository = nonNull(request.getRepository(), "request.repository");
try { try {
DeployRequest deployRequest = new DeployRequest() DeployRequest deployRequest = new DeployRequest()
.setRepository(session.toRepository(repository)) .setRepository(session.toRepository(repository))

View File

@ -34,7 +34,7 @@ import static org.apache.maven.internal.impl.Utils.nonNull;
public class DefaultArtifactFactory implements ArtifactFactory { public class DefaultArtifactFactory implements ArtifactFactory {
@Override @Override
public Artifact create(@Nonnull ArtifactFactoryRequest request) { public Artifact create(@Nonnull ArtifactFactoryRequest request) {
nonNull(request, "request can not be null"); nonNull(request, "request");
InternalSession session = InternalSession.from(request.getSession()); InternalSession session = InternalSession.from(request.getSession());
ArtifactType type = null; ArtifactType type = null;
if (request.getType() != null) { if (request.getType() != null) {

View File

@ -46,7 +46,7 @@ public class DefaultArtifactInstaller implements ArtifactInstaller {
@Override @Override
public void install(ArtifactInstallerRequest request) throws ArtifactInstallerException, IllegalArgumentException { public void install(ArtifactInstallerRequest request) throws ArtifactInstallerException, IllegalArgumentException {
nonNull(request, "request can not be null"); nonNull(request, "request");
InternalSession session = InternalSession.from(request.getSession()); InternalSession session = InternalSession.from(request.getSession());
try { try {
InstallRequest installRequest = InstallRequest installRequest =

View File

@ -51,13 +51,13 @@ public class DefaultArtifactResolver implements ArtifactResolver {
@Inject @Inject
DefaultArtifactResolver(@Nonnull RepositorySystem repositorySystem) { DefaultArtifactResolver(@Nonnull RepositorySystem repositorySystem) {
this.repositorySystem = nonNull(repositorySystem, "repositorySystem can not be null"); this.repositorySystem = nonNull(repositorySystem, "repositorySystem");
} }
@Override @Override
public ArtifactResolverResult resolve(ArtifactResolverRequest request) public ArtifactResolverResult resolve(ArtifactResolverRequest request)
throws ArtifactResolverException, IllegalArgumentException { throws ArtifactResolverException, IllegalArgumentException {
nonNull(request, "request can not be null"); nonNull(request, "request");
InternalSession session = InternalSession.from(request.getSession()); InternalSession session = InternalSession.from(request.getSession());
try { try {
Map<Artifact, Path> paths = new HashMap<>(); Map<Artifact, Path> paths = new HashMap<>();

View File

@ -58,7 +58,7 @@ public class DefaultDependencyCollector implements DependencyCollector {
@Override @Override
public DependencyCollectorResult collect(@Nonnull DependencyCollectorRequest request) public DependencyCollectorResult collect(@Nonnull DependencyCollectorRequest request)
throws DependencyCollectorException, IllegalArgumentException { throws DependencyCollectorException, IllegalArgumentException {
nonNull(request, "request can not be null"); nonNull(request, "request");
InternalSession session = InternalSession.from(request.getSession()); InternalSession session = InternalSession.from(request.getSession());
Artifact rootArtifact = Artifact rootArtifact =

View File

@ -21,8 +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 java.util.stream.Collectors;
import org.apache.maven.api.DependencyCoordinate; import org.apache.maven.api.DependencyCoordinate;
import org.apache.maven.api.Exclusion; import org.apache.maven.api.Exclusion;
import org.apache.maven.api.annotations.Nonnull; import org.apache.maven.api.annotations.Nonnull;
@ -30,6 +28,7 @@ import org.apache.maven.api.services.DependencyCoordinateFactory;
import org.apache.maven.api.services.DependencyCoordinateFactoryRequest; import org.apache.maven.api.services.DependencyCoordinateFactoryRequest;
import org.eclipse.aether.artifact.ArtifactType; import org.eclipse.aether.artifact.ArtifactType;
import static org.apache.maven.internal.impl.Utils.map;
import static org.apache.maven.internal.impl.Utils.nonNull; import static org.apache.maven.internal.impl.Utils.nonNull;
@Named @Named
@ -39,7 +38,7 @@ public class DefaultDependencyCoordinateFactory implements DependencyCoordinateF
@Nonnull @Nonnull
@Override @Override
public DependencyCoordinate create(@Nonnull DependencyCoordinateFactoryRequest request) { public DependencyCoordinate create(@Nonnull DependencyCoordinateFactoryRequest request) {
nonNull(request, "request can not be null"); nonNull(request, "request");
InternalSession session = InternalSession.from(request.getSession()); InternalSession session = InternalSession.from(request.getSession());
ArtifactType type = null; ArtifactType type = null;
@ -58,7 +57,7 @@ public class DefaultDependencyCoordinateFactory implements DependencyCoordinateF
type), type),
request.getScope(), request.getScope(),
request.isOptional(), request.isOptional(),
request.getExclusions().stream().map(this::toExclusion).collect(Collectors.toList()))); map(request.getExclusions(), this::toExclusion)));
} }
private org.eclipse.aether.graph.Exclusion toExclusion(Exclusion exclusion) { private org.eclipse.aether.graph.Exclusion toExclusion(Exclusion exclusion) {

View File

@ -40,7 +40,7 @@ public class DefaultDependencyProperties implements DependencyProperties {
} }
public DefaultDependencyProperties(@Nonnull Collection<String> flags) { public DefaultDependencyProperties(@Nonnull Collection<String> flags) {
nonNull(flags, "null flags"); nonNull(flags, "flags");
HashMap<String, String> map = new HashMap<>(); HashMap<String, String> map = new HashMap<>();
for (String flag : flags) { for (String flag : flags) {
map.put(flag, Boolean.TRUE.toString()); map.put(flag, Boolean.TRUE.toString());
@ -49,7 +49,7 @@ public class DefaultDependencyProperties implements DependencyProperties {
} }
public DefaultDependencyProperties(@Nonnull Map<String, String> properties) { public DefaultDependencyProperties(@Nonnull Map<String, String> properties) {
this.properties = Collections.unmodifiableMap(nonNull(properties, "null properties")); this.properties = Collections.unmodifiableMap(nonNull(properties, "properties"));
} }
@Nonnull @Nonnull
@ -60,7 +60,7 @@ public class DefaultDependencyProperties implements DependencyProperties {
@Override @Override
public boolean checkFlag(@Nonnull String flag) { public boolean checkFlag(@Nonnull String flag) {
nonNull(flag, "null flag"); nonNull(flag, "flag");
return Boolean.parseBoolean(properties.getOrDefault(flag, "")); return Boolean.parseBoolean(properties.getOrDefault(flag, ""));
} }
} }

View File

@ -33,7 +33,7 @@ public class DefaultLocalRepository implements LocalRepository {
@Inject @Inject
public DefaultLocalRepository(@Nonnull org.eclipse.aether.repository.LocalRepository repository) { public DefaultLocalRepository(@Nonnull org.eclipse.aether.repository.LocalRepository repository) {
this.repository = nonNull(repository, "repository can not be null"); this.repository = nonNull(repository, "repository");
} }
@Nonnull @Nonnull

View File

@ -47,7 +47,7 @@ import static org.apache.maven.internal.impl.Utils.nonNull;
public class DefaultModelXmlFactory implements ModelXmlFactory { public class DefaultModelXmlFactory implements ModelXmlFactory {
@Override @Override
public Model read(@Nonnull XmlReaderRequest request) throws XmlReaderException { public Model read(@Nonnull XmlReaderRequest request) throws XmlReaderException {
nonNull(request, "request can not be null"); nonNull(request, "request");
Path path = request.getPath(); Path path = request.getPath();
URL url = request.getURL(); URL url = request.getURL();
Reader reader = request.getReader(); Reader reader = request.getReader();
@ -82,8 +82,8 @@ public class DefaultModelXmlFactory implements ModelXmlFactory {
@Override @Override
public void write(XmlWriterRequest<Model> request) throws XmlWriterException { public void write(XmlWriterRequest<Model> request) throws XmlWriterException {
nonNull(request, "request can not be null"); nonNull(request, "request");
Model content = nonNull(request.getContent(), "content can not be null"); Model content = nonNull(request.getContent(), "content");
Path path = request.getPath(); Path path = request.getPath();
OutputStream outputStream = request.getOutputStream(); OutputStream outputStream = request.getOutputStream();
Writer writer = request.getWriter(); Writer writer = request.getWriter();

View File

@ -49,6 +49,8 @@ import org.codehaus.plexus.PlexusContainer;
import org.codehaus.plexus.component.repository.exception.ComponentLookupException; import org.codehaus.plexus.component.repository.exception.ComponentLookupException;
import org.eclipse.sisu.Typed; import org.eclipse.sisu.Typed;
import static org.apache.maven.internal.impl.Utils.map;
@Named @Named
@Typed @Typed
@SessionScoped @SessionScoped
@ -76,10 +78,9 @@ public class DefaultProjectManager implements ProjectManager {
@Override @Override
public Collection<Artifact> getAttachedArtifacts(Project project) { public Collection<Artifact> getAttachedArtifacts(Project project) {
InternalSession session = ((DefaultProject) project).getSession(); InternalSession session = ((DefaultProject) project).getSession();
Collection<Artifact> attached = getMavenProject(project).getAttachedArtifacts().stream() Collection<Artifact> attached = map(
.map(RepositoryUtils::toArtifact) getMavenProject(project).getAttachedArtifacts(),
.map(session::getArtifact) a -> session.getArtifact(RepositoryUtils.toArtifact(a)));
.collect(Collectors.toList());
return Collections.unmodifiableCollection(attached); return Collections.unmodifiableCollection(attached);
} }
@ -134,10 +135,7 @@ public class DefaultProjectManager implements ProjectManager {
InternalSession.from(session).getMavenSession(), InternalSession.from(session).getMavenSession(),
false, false,
Collections.emptySet()); Collections.emptySet());
return artifacts.stream() return map(artifacts, a -> InternalSession.from(session).getArtifact(RepositoryUtils.toArtifact(a)));
.map(RepositoryUtils::toArtifact)
.map(InternalSession.from(session)::getArtifact)
.collect(Collectors.toList());
} catch (LifecycleExecutionException | ComponentLookupException e) { } catch (LifecycleExecutionException | ComponentLookupException e) {
throw new MavenException("Unable to resolve project dependencies", e); throw new MavenException("Unable to resolve project dependencies", e);
} }

View File

@ -27,7 +27,6 @@ import java.util.NoSuchElementException;
import java.util.Objects; import java.util.Objects;
import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentHashMap;
import java.util.function.Supplier; import java.util.function.Supplier;
import java.util.stream.Collectors;
import org.apache.maven.RepositoryUtils; import org.apache.maven.RepositoryUtils;
import org.apache.maven.api.DependencyCoordinate; import org.apache.maven.api.DependencyCoordinate;
@ -54,6 +53,7 @@ import org.eclipse.aether.DefaultRepositorySystemSession;
import org.eclipse.aether.RepositorySystem; import org.eclipse.aether.RepositorySystem;
import org.eclipse.aether.RepositorySystemSession; import org.eclipse.aether.RepositorySystemSession;
import static org.apache.maven.internal.impl.Utils.map;
import static org.apache.maven.internal.impl.Utils.nonNull; import static org.apache.maven.internal.impl.Utils.nonNull;
public class DefaultSession extends AbstractSession { public class DefaultSession extends AbstractSession {
@ -80,10 +80,9 @@ public class DefaultSession extends AbstractSession {
this.repositorySystem = nonNull(repositorySystem); this.repositorySystem = nonNull(repositorySystem);
this.repositories = repositories != null this.repositories = repositories != null
? repositories ? repositories
: mavenSession.getRequest().getRemoteRepositories().stream() : map(
.map(RepositoryUtils::toRepo) mavenSession.getRequest().getRemoteRepositories(),
.map(this::getRemoteRepository) r -> getRemoteRepository(RepositoryUtils.toRepo(r)));
.collect(Collectors.toList());
this.mavenRepositorySystem = mavenRepositorySystem; this.mavenRepositorySystem = mavenRepositorySystem;
this.container = container; this.container = container;
this.runtimeInformation = runtimeInformation; this.runtimeInformation = runtimeInformation;

View File

@ -25,7 +25,6 @@ import java.io.InputStream;
import java.io.OutputStream; import java.io.OutputStream;
import java.io.Reader; import java.io.Reader;
import java.io.Writer; import java.io.Writer;
import java.util.Objects;
import org.apache.maven.api.annotations.Nonnull; import org.apache.maven.api.annotations.Nonnull;
import org.apache.maven.api.services.xml.SettingsXmlFactory; import org.apache.maven.api.services.xml.SettingsXmlFactory;
@ -38,12 +37,14 @@ import org.apache.maven.api.settings.Settings;
import org.apache.maven.settings.v4.SettingsStaxReader; import org.apache.maven.settings.v4.SettingsStaxReader;
import org.apache.maven.settings.v4.SettingsStaxWriter; import org.apache.maven.settings.v4.SettingsStaxWriter;
import static org.apache.maven.internal.impl.Utils.nonNull;
@Named @Named
@Singleton @Singleton
public class DefaultSettingsXmlFactory implements SettingsXmlFactory { public class DefaultSettingsXmlFactory implements SettingsXmlFactory {
@Override @Override
public Settings read(@Nonnull XmlReaderRequest request) throws XmlReaderException { public Settings read(@Nonnull XmlReaderRequest request) throws XmlReaderException {
Objects.requireNonNull(request, "request can not be null"); nonNull(request, "request");
Reader reader = request.getReader(); Reader reader = request.getReader();
InputStream inputStream = request.getInputStream(); InputStream inputStream = request.getInputStream();
if (reader == null && inputStream == null) { if (reader == null && inputStream == null) {
@ -68,8 +69,8 @@ public class DefaultSettingsXmlFactory implements SettingsXmlFactory {
@Override @Override
public void write(XmlWriterRequest<Settings> request) throws XmlWriterException { public void write(XmlWriterRequest<Settings> request) throws XmlWriterException {
Objects.requireNonNull(request, "request can not be null"); nonNull(request, "request");
Settings content = Objects.requireNonNull(request.getContent(), "content can not be null"); Settings content = nonNull(request.getContent(), "content");
OutputStream outputStream = request.getOutputStream(); OutputStream outputStream = request.getOutputStream();
Writer writer = request.getWriter(); Writer writer = request.getWriter();
if (writer == null && outputStream == null) { if (writer == null && outputStream == null) {

View File

@ -38,12 +38,14 @@ import org.apache.maven.api.toolchain.PersistedToolchains;
import org.apache.maven.toolchain.v4.MavenToolchainsStaxReader; import org.apache.maven.toolchain.v4.MavenToolchainsStaxReader;
import org.apache.maven.toolchain.v4.MavenToolchainsStaxWriter; import org.apache.maven.toolchain.v4.MavenToolchainsStaxWriter;
import static org.apache.maven.internal.impl.Utils.nonNull;
@Named @Named
@Singleton @Singleton
public class DefaultToolchainsXmlFactory implements ToolchainsXmlFactory { public class DefaultToolchainsXmlFactory implements ToolchainsXmlFactory {
@Override @Override
public PersistedToolchains read(@Nonnull XmlReaderRequest request) throws XmlReaderException { public PersistedToolchains read(@Nonnull XmlReaderRequest request) throws XmlReaderException {
Objects.requireNonNull(request, "request can not be null"); Objects.requireNonNull(request, "request");
Reader reader = request.getReader(); Reader reader = request.getReader();
InputStream inputStream = request.getInputStream(); InputStream inputStream = request.getInputStream();
if (reader == null && inputStream == null) { if (reader == null && inputStream == null) {
@ -68,8 +70,8 @@ public class DefaultToolchainsXmlFactory implements ToolchainsXmlFactory {
@Override @Override
public void write(XmlWriterRequest<PersistedToolchains> request) throws XmlWriterException { public void write(XmlWriterRequest<PersistedToolchains> request) throws XmlWriterException {
Objects.requireNonNull(request, "request can not be null"); nonNull(request, "request");
PersistedToolchains content = Objects.requireNonNull(request.getContent(), "content can not be null"); PersistedToolchains content = Objects.requireNonNull(request.getContent(), "content");
OutputStream outputStream = request.getOutputStream(); OutputStream outputStream = request.getOutputStream();
Writer writer = request.getWriter(); Writer writer = request.getWriter();
if (writer == null && outputStream == null) { if (writer == null && outputStream == null) {

View File

@ -36,10 +36,10 @@ public class DefaultType implements Type, ArtifactType {
private final DependencyProperties dependencyProperties; private final DependencyProperties dependencyProperties;
public DefaultType(String id, String extension, String classifier, DependencyProperties dependencyProperties) { public DefaultType(String id, String extension, String classifier, DependencyProperties dependencyProperties) {
nonNull(id, "null id"); nonNull(id, "id");
this.extension = nonNull(extension, "null extension"); this.extension = nonNull(extension, "extension");
this.classifier = classifier; this.classifier = classifier;
nonNull(dependencyProperties, "null dependencyProperties"); nonNull(dependencyProperties, "dependencyProperties");
HashMap<String, String> props = new HashMap<>(dependencyProperties.asMap()); HashMap<String, String> props = new HashMap<>(dependencyProperties.asMap());
props.put(ArtifactProperties.TYPE, id); props.put(ArtifactProperties.TYPE, id);
this.dependencyProperties = new DefaultDependencyProperties(props); this.dependencyProperties = new DefaultDependencyProperties(props);

View File

@ -70,7 +70,7 @@ public class DefaultTypeRegistry extends AbstractEventSpy implements TypeRegistr
@Override @Override
@Nonnull @Nonnull
public Type getType(String id) { public Type getType(String id) {
nonNull(id, "null id"); nonNull(id, "id");
return usedTypes.computeIfAbsent(id, i -> { return usedTypes.computeIfAbsent(id, i -> {
Type type = types.get(id); Type type = types.get(id);
if (type == null) { if (type == null) {

View File

@ -18,6 +18,11 @@
*/ */
package org.apache.maven.internal.impl; package org.apache.maven.internal.impl;
import java.util.Collection;
import java.util.List;
import java.util.function.Function;
import java.util.stream.Collectors;
class Utils { class Utils {
static <T> T nonNull(T t) { static <T> T nonNull(T t) {
if (t == null) { if (t == null) {
@ -26,17 +31,21 @@ class Utils {
return t; return t;
} }
static <T> T nonNull(T t, String message) { static <T> T nonNull(T t, String name) {
if (t == null) { if (t == null) {
throw new IllegalArgumentException(message); throw new IllegalArgumentException(name + " cannot be null");
} }
return t; return t;
} }
static <T> T cast(Class<T> clazz, Object o, String message) { static <T> T cast(Class<T> clazz, Object o, String name) {
if (!clazz.isInstance(o)) { if (!clazz.isInstance(o)) {
throw new IllegalArgumentException(message); throw new IllegalArgumentException(name + " is not an instance of " + clazz.getName());
} }
return clazz.cast(o); return clazz.cast(o);
} }
static <U, V> List<V> map(Collection<U> list, Function<U, V> mapper) {
return list.stream().map(mapper).collect(Collectors.toList());
}
} }

View File

@ -38,8 +38,7 @@ class WrapperNode extends AbstractNode {
@Override @Override
DependencyNode getDependencyNode() { DependencyNode getDependencyNode() {
return Utils.cast(AbstractNode.class, delegate, "delegate is not an instance of AbstractNode") return Utils.cast(AbstractNode.class, delegate, "delegate").getDependencyNode();
.getDependencyNode();
} }
@Override @Override