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