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.repository.internal;
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.artifact.repository.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          Metadata metadata = new Metadata();
42          metadata.setModelVersion("1.1.0");
43          metadata.setGroupId(artifact.getGroupId());
44          metadata.setArtifactId(artifact.getArtifactId());
45          metadata.setVersion(artifact.getBaseVersion());
46  
47          return metadata;
48      }
49  
50      public void bind(Artifact artifact) {
51          artifacts.add(artifact);
52      }
53  
54      public Object getKey() {
55          return getGroupId() + ':' + getArtifactId() + ':' + getVersion();
56      }
57  
58      public static Object getKey(Artifact artifact) {
59          return artifact.getGroupId() + ':' + artifact.getArtifactId() + ':' + artifact.getBaseVersion();
60      }
61  
62      protected String getKey(String classifier, String extension) {
63          return classifier + ':' + extension;
64      }
65  
66      @Override
67      public String getGroupId() {
68          return metadata.getGroupId();
69      }
70  
71      @Override
72      public String getArtifactId() {
73          return metadata.getArtifactId();
74      }
75  
76      @Override
77      public String getVersion() {
78          return metadata.getVersion();
79      }
80  
81      @Override
82      public Nature getNature() {
83          return Nature.SNAPSHOT;
84      }
85  }