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