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.model.building;
20  
21  import java.io.File;
22  import java.nio.file.Path;
23  import java.util.Objects;
24  
25  import org.apache.maven.building.FileSource;
26  
27  /**
28   * Represents a model pulled from a repository
29   *
30   * @since 4.0.0
31   */
32  public class ArtifactModelSource extends FileSource implements ModelSource {
33      private final String groupId;
34  
35      private final String artifactId;
36  
37      private final String version;
38  
39      private final int hashCode;
40  
41      @Deprecated
42      public ArtifactModelSource(File file, String groupId, String artifactId, String version) {
43          super(file);
44          this.groupId = groupId;
45          this.artifactId = artifactId;
46          this.version = version;
47          this.hashCode = Objects.hash(groupId, artifactId, version);
48      }
49  
50      public ArtifactModelSource(Path path, String groupId, String artifactId, String version) {
51          super(path);
52          this.groupId = groupId;
53          this.artifactId = artifactId;
54          this.version = version;
55          this.hashCode = Objects.hash(groupId, artifactId, version);
56      }
57  
58      public String getGroupId() {
59          return groupId;
60      }
61  
62      public String getArtifactId() {
63          return artifactId;
64      }
65  
66      public String getVersion() {
67          return version;
68      }
69  
70      @Override
71      public int hashCode() {
72          return hashCode;
73      }
74  
75      @Override
76      public boolean equals(Object obj) {
77          if (this == obj) {
78              return true;
79          }
80          if (obj == null) {
81              return false;
82          }
83  
84          if (!ArtifactModelSource.class.equals(obj.getClass())) {
85              return false;
86          }
87  
88          ArtifactModelSource other = (ArtifactModelSource) obj;
89          return Objects.equals(artifactId, other.artifactId)
90                  && Objects.equals(groupId, other.groupId)
91                  && Objects.equals(version, other.version);
92      }
93  
94      @Override
95      public String toString() {
96          return groupId + ":" + artifactId + ":" + version;
97      }
98  }