View Javadoc
1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements.  See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership.  The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License.  You may obtain a copy of the License at
9    *
10   *   http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing,
13   * software distributed under the License is distributed on an
14   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   * KIND, either express or implied.  See the License for the
16   * specific language governing permissions and limitations
17   * under the License.
18   */
19  package org.apache.maven.internal.impl;
20  
21  import java.util.Collection;
22  
23  import org.apache.maven.api.*;
24  import org.apache.maven.api.annotations.Nonnull;
25  import org.apache.maven.api.annotations.Nullable;
26  import org.apache.maven.api.services.TypeRegistry;
27  import org.eclipse.aether.artifact.ArtifactProperties;
28  
29  import static org.apache.maven.internal.impl.Utils.nonNull;
30  
31  public class DefaultDependencyCoordinate implements DependencyCoordinate {
32      private final InternalSession session;
33      private final org.eclipse.aether.graph.Dependency dependency;
34  
35      public DefaultDependencyCoordinate(
36              @Nonnull InternalSession session, @Nonnull org.eclipse.aether.graph.Dependency dependency) {
37          this.session = nonNull(session, "session");
38          this.dependency = nonNull(dependency, "dependency");
39      }
40  
41      @Nonnull
42      public org.eclipse.aether.graph.Dependency getDependency() {
43          return dependency;
44      }
45  
46      @Override
47      public String getGroupId() {
48          return dependency.getArtifact().getGroupId();
49      }
50  
51      @Override
52      public String getArtifactId() {
53          return dependency.getArtifact().getArtifactId();
54      }
55  
56      @Override
57      public String getClassifier() {
58          return dependency.getArtifact().getClassifier();
59      }
60  
61      @Override
62      public VersionConstraint getVersion() {
63          return session.parseVersionConstraint(dependency.getArtifact().getVersion());
64      }
65  
66      @Override
67      public String getExtension() {
68          return dependency.getArtifact().getExtension();
69      }
70  
71      @Override
72      public Type getType() {
73          String type = dependency
74                  .getArtifact()
75                  .getProperty(ArtifactProperties.TYPE, dependency.getArtifact().getExtension());
76          return session.getService(TypeRegistry.class).getType(type);
77      }
78  
79      @Nonnull
80      @Override
81      public Scope getScope() {
82          return Scope.get(dependency.getScope());
83      }
84  
85      @Nullable
86      @Override
87      public Boolean getOptional() {
88          return dependency.getOptional();
89      }
90  
91      @Nonnull
92      @Override
93      public Collection<Exclusion> getExclusions() {
94          return new MappedCollection<>(dependency.getExclusions(), this::toExclusion);
95      }
96  
97      private Exclusion toExclusion(org.eclipse.aether.graph.Exclusion exclusion) {
98          return new Exclusion() {
99              @Nullable
100             @Override
101             public String getGroupId() {
102                 return exclusion.getGroupId();
103             }
104 
105             @Nullable
106             @Override
107             public String getArtifactId() {
108                 return exclusion.getArtifactId();
109             }
110         };
111     }
112 }