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