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.util.Objects;
23  
24  import org.apache.maven.building.FileSource;
25  
26  /**
27   * Represents a model pulled from a repository
28   *
29   * @author Robert Scholte
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      public ArtifactModelSource(File file, String groupId, String artifactId, String version) {
42          super(file);
43          this.groupId = groupId;
44          this.artifactId = artifactId;
45          this.version = version;
46          this.hashCode = Objects.hash(groupId, artifactId, version);
47      }
48  
49      public String getGroupId() {
50          return groupId;
51      }
52  
53      public String getArtifactId() {
54          return artifactId;
55      }
56  
57      public String getVersion() {
58          return version;
59      }
60  
61      @Override
62      public int hashCode() {
63          return hashCode;
64      }
65  
66      @Override
67      public boolean equals(Object obj) {
68          if (this == obj) {
69              return true;
70          }
71          if (obj == null) {
72              return false;
73          }
74  
75          if (!ArtifactModelSource.class.equals(obj.getClass())) {
76              return false;
77          }
78  
79          ArtifactModelSource other = (ArtifactModelSource) obj;
80          return Objects.equals(artifactId, other.artifactId)
81                  && Objects.equals(groupId, other.groupId)
82                  && Objects.equals(version, other.version);
83      }
84  }