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