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