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.io.File;
22  import java.util.ArrayList;
23  import java.util.Collection;
24  import java.util.Date;
25  import org.apache.maven.artifact.repository.metadata.Metadata;
26  import org.eclipse.aether.artifact.Artifact;
27  
28  /**
29   * @author Hervé Boutemy
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 final boolean legacyFormat;
37  
38      protected MavenSnapshotMetadata(Metadata metadata, File file, boolean legacyFormat, Date timestamp) {
39          super(metadata, file, timestamp);
40          this.legacyFormat = legacyFormat;
41      }
42  
43      protected static Metadata createRepositoryMetadata(Artifact artifact, boolean legacyFormat) {
44          Metadata metadata = new Metadata();
45          if (!legacyFormat) {
46              metadata.setModelVersion("1.1.0");
47          }
48          metadata.setGroupId(artifact.getGroupId());
49          metadata.setArtifactId(artifact.getArtifactId());
50          metadata.setVersion(artifact.getBaseVersion());
51  
52          return metadata;
53      }
54  
55      public void bind(Artifact artifact) {
56          artifacts.add(artifact);
57      }
58  
59      public Object getKey() {
60          return getGroupId() + ':' + getArtifactId() + ':' + getVersion();
61      }
62  
63      public static Object getKey(Artifact artifact) {
64          return artifact.getGroupId() + ':' + artifact.getArtifactId() + ':' + artifact.getBaseVersion();
65      }
66  
67      protected String getKey(String classifier, String extension) {
68          return classifier + ':' + extension;
69      }
70  
71      public String getGroupId() {
72          return metadata.getGroupId();
73      }
74  
75      public String getArtifactId() {
76          return metadata.getArtifactId();
77      }
78  
79      public String getVersion() {
80          return metadata.getVersion();
81      }
82  
83      public Nature getNature() {
84          return Nature.SNAPSHOT;
85      }
86  }