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.ArtifactCoordinates;
24  import org.apache.maven.api.VersionConstraint;
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 DefaultArtifactCoordinates implements ArtifactCoordinates {
33      private final @Nonnull InternalSession session;
34      private final @Nonnull org.eclipse.aether.artifact.Artifact coordinates;
35  
36      public DefaultArtifactCoordinates(
37              @Nonnull InternalSession session, @Nonnull org.eclipse.aether.artifact.Artifact coordinates) {
38          this.session = nonNull(session, "session");
39          this.coordinates = nonNull(coordinates, "coordinates");
40      }
41  
42      public org.eclipse.aether.artifact.Artifact getCoordinates() {
43          return coordinates;
44      }
45  
46      @Nonnull
47      @Override
48      public String getGroupId() {
49          return coordinates.getGroupId();
50      }
51  
52      @Nonnull
53      @Override
54      public String getArtifactId() {
55          return coordinates.getArtifactId();
56      }
57  
58      @Nonnull
59      @Override
60      public VersionConstraint getVersionConstraint() {
61          return session.parseVersionConstraint(coordinates.getVersion());
62      }
63  
64      @Override
65      public String getExtension() {
66          return coordinates.getExtension();
67      }
68  
69      @Nonnull
70      @Override
71      public String getClassifier() {
72          return coordinates.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          DefaultArtifactCoordinates that = (DefaultArtifactCoordinates) o;
84          return Objects.equals(this.getGroupId(), that.getGroupId())
85                  && Objects.equals(this.getArtifactId(), that.getArtifactId())
86                  && Objects.equals(this.getVersionConstraint(), that.getVersionConstraint())
87                  && Objects.equals(this.getClassifier(), that.getClassifier());
88      }
89  
90      @Override
91      public int hashCode() {
92          return Objects.hash(getGroupId(), getArtifactId(), getVersionConstraint(), getClassifier());
93      }
94  
95      @Override
96      public String toString() {
97          return coordinates.toString();
98      }
99  }