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.resolver;
20  
21  import java.nio.file.Path;
22  import java.util.ArrayList;
23  import java.util.Collection;
24  import java.util.Date;
25  
26  import org.apache.maven.api.metadata.Metadata;
27  import org.eclipse.aether.artifact.Artifact;
28  
29  /**
30   */
31  abstract class MavenSnapshotMetadata extends MavenMetadata {
32      static final String SNAPSHOT = "SNAPSHOT";
33  
34      protected final Collection<Artifact> artifacts = new ArrayList<>();
35  
36      protected MavenSnapshotMetadata(Metadata metadata, Path path, Date timestamp) {
37          super(metadata, path, timestamp);
38      }
39  
40      protected static Metadata createRepositoryMetadata(Artifact artifact) {
41          return Metadata.newBuilder()
42                  .modelVersion("1.1.0")
43                  .groupId(artifact.getGroupId())
44                  .artifactId(artifact.getArtifactId())
45                  .version(artifact.getBaseVersion())
46                  .build();
47      }
48  
49      public void bind(Artifact artifact) {
50          artifacts.add(artifact);
51      }
52  
53      public Object getKey() {
54          return getGroupId() + ':' + getArtifactId() + ':' + getVersion();
55      }
56  
57      public static Object getKey(Artifact artifact) {
58          return artifact.getGroupId() + ':' + artifact.getArtifactId() + ':' + artifact.getBaseVersion();
59      }
60  
61      protected String getKey(String classifier, String extension) {
62          return classifier + ':' + extension;
63      }
64  
65      @Override
66      public String getGroupId() {
67          return metadata.getGroupId();
68      }
69  
70      @Override
71      public String getArtifactId() {
72          return metadata.getArtifactId();
73      }
74  
75      @Override
76      public String getVersion() {
77          return metadata.getVersion();
78      }
79  
80      @Override
81      public Nature getNature() {
82          return Nature.SNAPSHOT;
83      }
84  }