1 package org.apache.maven.plugin.internal;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 import org.eclipse.aether.artifact.Artifact;
23 import org.eclipse.aether.collection.DependencyCollectionContext;
24 import org.eclipse.aether.collection.DependencySelector;
25 import org.eclipse.aether.graph.Dependency;
26
27
28
29
30
31
32
33
34
35
36 class WagonExcluder
37 implements DependencySelector
38 {
39
40 private final boolean coreArtifact;
41
42 public WagonExcluder()
43 {
44 this( false );
45 }
46
47 private WagonExcluder( boolean coreArtifact )
48 {
49 this.coreArtifact = coreArtifact;
50 }
51
52 public boolean selectDependency( Dependency dependency )
53 {
54 return !coreArtifact || !isWagonProvider( dependency.getArtifact() );
55 }
56
57 public DependencySelector deriveChildSelector( DependencyCollectionContext context )
58 {
59 if ( coreArtifact || !isLegacyCoreArtifact( context.getDependency().getArtifact() ) )
60 {
61 return this;
62 }
63 else
64 {
65 return new WagonExcluder( true );
66 }
67 }
68
69 private boolean isLegacyCoreArtifact( Artifact artifact )
70 {
71 String version = artifact.getVersion();
72 return version != null && version.startsWith( "2." ) && artifact.getArtifactId().startsWith( "maven-" )
73 && artifact.getGroupId().equals( "org.apache.maven" );
74 }
75
76 private boolean isWagonProvider( Artifact artifact )
77 {
78 if ( "org.apache.maven.wagon".equals( artifact.getGroupId() ) )
79 {
80 return artifact.getArtifactId().startsWith( "wagon-" );
81 }
82 return false;
83 }
84
85 @Override
86 public boolean equals( Object obj )
87 {
88 if ( obj == this )
89 {
90 return true;
91 }
92 else if ( obj == null || !getClass().equals( obj.getClass() ) )
93 {
94 return false;
95 }
96
97 WagonExcluder that = (WagonExcluder) obj;
98 return coreArtifact == that.coreArtifact;
99 }
100
101 @Override
102 public int hashCode()
103 {
104 int hash = getClass().hashCode();
105 hash = hash * 31 + ( coreArtifact ? 1 : 0 );
106 return hash;
107 }
108
109 }