View Javadoc
1   package org.apache.maven.artifact.repository.metadata;
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 org.apache.maven.artifact.Artifact;
23  import org.apache.maven.artifact.ArtifactUtils;
24  import org.apache.maven.artifact.repository.ArtifactRepository;
25  import org.apache.maven.artifact.versioning.ArtifactVersion;
26  import org.apache.maven.artifact.versioning.Restriction;
27  import org.apache.maven.artifact.versioning.VersionRange;
28  
29  /**
30   * Metadata for the artifact directory of the repository.
31   *
32   * @author <a href="mailto:brett@apache.org">Brett Porter</a>
33   */
34  public class ArtifactRepositoryMetadata
35      extends AbstractRepositoryMetadata
36  {
37      private Artifact artifact;
38  
39      public ArtifactRepositoryMetadata( Artifact artifact )
40      {
41          this( artifact, null );
42      }
43  
44      public ArtifactRepositoryMetadata( Artifact artifact,
45                                         Versioning versioning )
46      {
47          super( createMetadata( artifact, versioning ) );
48          this.artifact = artifact;
49      }
50  
51      public boolean storedInGroupDirectory()
52      {
53          return false;
54      }
55  
56      public boolean storedInArtifactVersionDirectory()
57      {
58          return false;
59      }
60  
61      public String getGroupId()
62      {
63          return artifact.getGroupId();
64      }
65  
66      public String getArtifactId()
67      {
68          return artifact.getArtifactId();
69      }
70  
71      public String getBaseVersion()
72      {
73          // Don't want the artifact's version in here, as this is stored in the directory above that
74          return null;
75      }
76  
77      public Object getKey()
78      {
79          return "artifact " + artifact.getGroupId() + ":" + artifact.getArtifactId();
80      }
81  
82      public boolean isSnapshot()
83      {
84          // Don't consider the artifact's version in here, as this is stored in the directory above that
85          return false;
86      }
87  
88      public int getNature()
89      {
90          if ( artifact.getVersion() != null )
91          {
92              return artifact.isSnapshot() ? SNAPSHOT : RELEASE;
93          }
94  
95          VersionRange range = artifact.getVersionRange();
96          if ( range != null )
97          {
98              for ( Restriction restriction : range.getRestrictions() )
99              {
100                 if ( isSnapshot( restriction.getLowerBound() ) || isSnapshot( restriction.getUpperBound() ) )
101                 {
102                     return RELEASE_OR_SNAPSHOT;
103                 }
104             }
105         }
106 
107         return RELEASE;
108     }
109 
110     private boolean isSnapshot( ArtifactVersion version )
111     {
112         return version != null && ArtifactUtils.isSnapshot( version.getQualifier() );
113     }
114 
115     public ArtifactRepository getRepository()
116     {
117         return null;
118     }
119 
120     public void setRepository( ArtifactRepository remoteRepository )
121     {
122         /*
123          * NOTE: Metadata at the g:a level contains a collection of available versions. After merging, we can't tell
124          * which repository provides which version so the metadata manager must not restrict the artifact resolution to
125          * the repository with the most recent updates.
126          */
127     }
128 
129 }