View Javadoc
1   package org.apache.maven.repository.internal;
2   
3   /*
4    * Licensed to the Apache Software Foundation (ASF) under one
5    * or more contributor license agreements.  See the NOTICE file
6    * distributed with this work for additional information
7    * regarding copyright ownership.  The ASF licenses this file
8    * to you under the Apache License, Version 2.0 (the
9    * "License"); you may not use this file except in compliance
10   * with the License.  You may obtain a copy of the License at
11   *
12   *   http://www.apache.org/licenses/LICENSE-2.0
13   *
14   * Unless required by applicable law or agreed to in writing,
15   * software distributed under the License is distributed on an
16   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17   * KIND, either express or implied.  See the License for the
18   * specific language governing permissions and limitations
19   * under the License.
20   */
21  
22  import java.io.File;
23  import java.util.ArrayList;
24  import java.util.Collection;
25  import java.util.Date;
26  
27  import org.apache.maven.artifact.repository.metadata.Metadata;
28  import org.eclipse.aether.artifact.Artifact;
29  
30  /**
31   * @author Hervé Boutemy
32   */
33  abstract class MavenSnapshotMetadata
34      extends MavenMetadata
35  {
36      static final String SNAPSHOT = "SNAPSHOT";
37  
38      protected final Collection<Artifact> artifacts = new ArrayList<>();
39  
40      protected final boolean legacyFormat;
41  
42      protected MavenSnapshotMetadata( Metadata metadata, File file, boolean legacyFormat, Date timestamp )
43      {
44          super( metadata, file, timestamp );
45          this.legacyFormat = legacyFormat;
46      }
47  
48      protected static Metadata createRepositoryMetadata( Artifact artifact, boolean legacyFormat )
49      {
50          Metadata metadata = new Metadata();
51          if ( !legacyFormat )
52          {
53              metadata.setModelVersion( "1.1.0" );
54          }
55          metadata.setGroupId( artifact.getGroupId() );
56          metadata.setArtifactId( artifact.getArtifactId() );
57          metadata.setVersion( artifact.getBaseVersion() );
58  
59          return metadata;
60      }
61  
62      public void bind( Artifact artifact )
63      {
64          artifacts.add( artifact );
65      }
66  
67      public Object getKey()
68      {
69          return getGroupId() + ':' + getArtifactId() + ':' + getVersion();
70      }
71  
72      public static Object getKey( Artifact artifact )
73      {
74          return artifact.getGroupId() + ':' + artifact.getArtifactId() + ':' + artifact.getBaseVersion();
75      }
76  
77      protected String getKey( String classifier, String extension )
78      {
79          return classifier + ':' + extension;
80      }
81  
82      public String getGroupId()
83      {
84          return metadata.getGroupId();
85      }
86  
87      public String getArtifactId()
88      {
89          return metadata.getArtifactId();
90      }
91  
92      public String getVersion()
93      {
94          return metadata.getVersion();
95      }
96  
97      public Nature getNature()
98      {
99          return Nature.SNAPSHOT;
100     }
101 }