1 package org.apache.maven.shared.transfer.collection.internal;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 import java.util.ArrayList;
23 import java.util.List;
24
25 import org.apache.maven.RepositoryUtils;
26 import org.apache.maven.artifact.Artifact;
27 import org.apache.maven.artifact.repository.ArtifactRepository;
28 import org.apache.maven.shared.transfer.collection.DependencyCollectionException;
29 import org.apache.maven.shared.transfer.graph.DependencyNode;
30 import org.apache.maven.shared.transfer.graph.DependencyVisitor;
31 import org.eclipse.aether.repository.RemoteRepository;
32
33
34
35
36
37
38
39 class Maven31DependencyNodeAdapter implements DependencyNode
40 {
41
42 private org.eclipse.aether.graph.DependencyNode dependencyNode;
43
44
45
46
47 Maven31DependencyNodeAdapter( org.eclipse.aether.graph.DependencyNode dependencyNode )
48 {
49 this.dependencyNode = dependencyNode;
50 }
51
52 @Override
53 public Artifact getArtifact()
54 {
55 return getArtifact( dependencyNode.getArtifact() );
56 }
57
58 @Override
59 public List<DependencyNode> getChildren()
60 {
61 List<org.eclipse.aether.graph.DependencyNode> aetherChildren = dependencyNode.getChildren();
62 List<DependencyNode> children = new ArrayList<>( aetherChildren.size() );
63 for ( org.eclipse.aether.graph.DependencyNode aetherChild : aetherChildren )
64 {
65 children.add( new Maven31DependencyNodeAdapter( aetherChild ) );
66 }
67 return children;
68 }
69
70 @Override
71 public List<ArtifactRepository> getRemoteRepositories()
72 {
73 List<RemoteRepository> aetherRepositories = dependencyNode.getRepositories();
74 List<ArtifactRepository> mavenRepositories = new ArrayList<>( aetherRepositories.size() );
75
76 for ( RemoteRepository aetherRepository : aetherRepositories )
77 {
78 mavenRepositories.add( new Maven31ArtifactRepositoryAdapter( aetherRepository ) );
79 }
80
81 return mavenRepositories;
82 }
83
84 @Override
85 public String getScope()
86 {
87 return dependencyNode.getDependency().getScope();
88 }
89
90 @Override
91 public Boolean getOptional()
92 {
93 return dependencyNode.getDependency().getOptional();
94 }
95
96 @Override
97 public boolean accept( DependencyVisitor visitor )
98 {
99 if ( visitor.visitEnter( this ) )
100 {
101 for ( org.eclipse.aether.graph.DependencyNode aetherNode : dependencyNode.getChildren() )
102 {
103 DependencyNode child = new Maven31DependencyNodeAdapter( aetherNode );
104 if ( !child.accept( visitor ) )
105 {
106 break;
107 }
108 }
109 }
110
111 return visitor.visitLeave( this );
112 }
113
114 @Override
115 public int hashCode()
116 {
117 return dependencyNode.hashCode();
118 }
119
120 @Override
121 public boolean equals( Object obj )
122 {
123 if ( this == obj )
124 {
125 return true;
126 }
127 if ( obj == null )
128 {
129 return false;
130 }
131 if ( getClass() != obj.getClass() )
132 {
133 return false;
134 }
135
136 Maven31DependencyNodeAdapter other = (Maven31DependencyNodeAdapter) obj;
137 if ( dependencyNode == null )
138 {
139 if ( other.dependencyNode != null )
140 {
141 return false;
142 }
143 }
144 else if ( !dependencyNode.equals( other.dependencyNode ) )
145 {
146 return false;
147 }
148 return true;
149 }
150
151 private Artifact getArtifact( org.eclipse.aether.artifact.Artifact aetherArtifact )
152 {
153 try
154 {
155 return Invoker.invoke( RepositoryUtils.class, "toArtifact",
156 org.eclipse.aether.artifact.Artifact.class, aetherArtifact );
157 }
158 catch ( DependencyCollectionException e )
159 {
160 throw new RuntimeException( e );
161 }
162 }
163 }