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 static org.apache.maven.internal.impl.Utils.nonNull;
22  
23  import java.util.Objects;
24  import org.apache.maven.api.ArtifactCoordinate;
25  import org.apache.maven.api.VersionRange;
26  import org.apache.maven.api.annotations.Nonnull;
27  
28  /**
29   * A wrapper class around a maven resolver artifact.
30   */
31  public class DefaultArtifactCoordinate implements ArtifactCoordinate {
32      private final @Nonnull AbstractSession session;
33      private final @Nonnull org.eclipse.aether.artifact.Artifact coordinate;
34  
35      public DefaultArtifactCoordinate(
36              @Nonnull AbstractSession session, @Nonnull org.eclipse.aether.artifact.Artifact coordinate) {
37          this.session = nonNull(session, "session can not be null");
38          this.coordinate = nonNull(coordinate, "coordinate can not be null");
39      }
40  
41      public org.eclipse.aether.artifact.Artifact getCoordinate() {
42          return coordinate;
43      }
44  
45      @Nonnull
46      @Override
47      public String getGroupId() {
48          return coordinate.getGroupId();
49      }
50  
51      @Nonnull
52      @Override
53      public String getArtifactId() {
54          return coordinate.getArtifactId();
55      }
56  
57      @Nonnull
58      @Override
59      public VersionRange getVersion() {
60          return session.parseVersionRange(coordinate.getVersion());
61      }
62  
63      @Override
64      public String getExtension() {
65          return coordinate.getExtension();
66      }
67  
68      @Nonnull
69      @Override
70      public String getClassifier() {
71          return coordinate.getClassifier();
72      }
73  
74      @Override
75      public boolean equals(Object o) {
76          if (this == o) {
77              return true;
78          }
79          if (o == null || getClass() != o.getClass()) {
80              return false;
81          }
82          DefaultArtifactCoordinate that = (DefaultArtifactCoordinate) o;
83          return Objects.equals(this.getGroupId(), that.getGroupId())
84                  && Objects.equals(this.getArtifactId(), that.getArtifactId())
85                  && Objects.equals(this.getVersion(), that.getVersion())
86                  && Objects.equals(this.getClassifier(), that.getClassifier());
87      }
88  
89      @Override
90      public int hashCode() {
91          return Objects.hash(getGroupId(), getArtifactId(), getVersion(), getClassifier());
92      }
93  
94      @Override
95      public String toString() {
96          return coordinate.toString();
97      }
98  }