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   * @deprecated since 4.0.0, use {@code maven-api-impl} jar instead
31   */
32  @Deprecated(since = "4.0.0")
33  abstract class MavenSnapshotMetadata extends MavenMetadata {
34      static final String SNAPSHOT = "SNAPSHOT";
35  
36      protected final Collection<Artifact> artifacts = new ArrayList<>();
37  
38      protected MavenSnapshotMetadata(Metadata metadata, Path path, Date timestamp) {
39          super(metadata, path, timestamp);
40      }
41  
42      protected static Metadata createRepositoryMetadata(Artifact artifact) {
43          Metadata metadata = new Metadata();
44          metadata.setModelVersion("1.1.0");
45          metadata.setGroupId(artifact.getGroupId());
46          metadata.setArtifactId(artifact.getArtifactId());
47          metadata.setVersion(artifact.getBaseVersion());
48  
49          return metadata;
50      }
51  
52      public void bind(Artifact artifact) {
53          artifacts.add(artifact);
54      }
55  
56      public Object getKey() {
57          return getGroupId() + ':' + getArtifactId() + ':' + getVersion();
58      }
59  
60      public static Object getKey(Artifact artifact) {
61          return artifact.getGroupId() + ':' + artifact.getArtifactId() + ':' + artifact.getBaseVersion();
62      }
63  
64      protected String getKey(String classifier, String extension) {
65          return classifier + ':' + extension;
66      }
67  
68      @Override
69      public String getGroupId() {
70          return metadata.getGroupId();
71      }
72  
73      @Override
74      public String getArtifactId() {
75          return metadata.getArtifactId();
76      }
77  
78      @Override
79      public String getVersion() {
80          return metadata.getVersion();
81      }
82  
83      @Override
84      public Nature getNature() {
85          return Nature.SNAPSHOT;
86      }
87  }