1 package org.apache.maven.internal.impl;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 import javax.inject.Named;
23 import javax.inject.Singleton;
24
25 import java.util.stream.Collectors;
26
27 import org.apache.maven.api.DependencyCoordinate;
28 import org.apache.maven.api.Exclusion;
29 import org.apache.maven.api.annotations.Nonnull;
30 import org.apache.maven.api.services.DependencyCoordinateFactory;
31 import org.apache.maven.api.services.DependencyCoordinateFactoryRequest;
32 import org.eclipse.aether.artifact.ArtifactType;
33
34 import static org.apache.maven.internal.impl.Utils.cast;
35 import static org.apache.maven.internal.impl.Utils.nonNull;
36
37 @Named
38 @Singleton
39 public class DefaultDependencyCoordinateFactory implements DependencyCoordinateFactory
40 {
41
42 @Nonnull
43 @Override
44 public DependencyCoordinate create( @Nonnull DependencyCoordinateFactoryRequest request )
45 {
46 nonNull( request, "request can not be null" );
47 DefaultSession session = cast( DefaultSession.class, request.getSession(),
48 "request.session should be a " + DefaultSession.class );
49
50 ArtifactType type = null;
51 if ( request.getType() != null )
52 {
53 type = session.getSession().getArtifactTypeRegistry().get( request.getType() );
54 }
55 return new DefaultDependencyCoordinate(
56 session,
57 new org.eclipse.aether.graph.Dependency(
58 new org.eclipse.aether.artifact.DefaultArtifact(
59 request.getGroupId(),
60 request.getArtifactId(),
61 request.getClassifier(),
62 request.getExtension(),
63 request.getVersion(),
64 type
65 ),
66 request.getScope(),
67 request.isOptional(),
68 request.getExclusions().stream().map( this::toExclusion ).collect( Collectors.toList() ) ) );
69 }
70
71 private org.eclipse.aether.graph.Exclusion toExclusion( Exclusion exclusion )
72 {
73 return new org.eclipse.aether.graph.Exclusion(
74 exclusion.getGroupId(), exclusion.getArtifactId(), "*", "*" );
75 }
76
77 }