001package org.apache.maven.artifact.repository.metadata; 002 003/* 004 * Licensed to the Apache Software Foundation (ASF) under one 005 * or more contributor license agreements. See the NOTICE file 006 * distributed with this work for additional information 007 * regarding copyright ownership. The ASF licenses this file 008 * to you under the Apache License, Version 2.0 (the 009 * "License"); you may not use this file except in compliance 010 * with the License. You may obtain a copy of the License at 011 * 012 * http://www.apache.org/licenses/LICENSE-2.0 013 * 014 * Unless required by applicable law or agreed to in writing, 015 * software distributed under the License is distributed on an 016 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 017 * KIND, either express or implied. See the License for the 018 * specific language governing permissions and limitations 019 * under the License. 020 */ 021 022import org.apache.maven.artifact.Artifact; 023import org.apache.maven.artifact.ArtifactUtils; 024import org.apache.maven.artifact.repository.ArtifactRepository; 025import org.apache.maven.artifact.versioning.ArtifactVersion; 026import org.apache.maven.artifact.versioning.Restriction; 027import org.apache.maven.artifact.versioning.VersionRange; 028 029/** 030 * Metadata for the artifact directory of the repository. 031 * 032 * @author <a href="mailto:brett@apache.org">Brett Porter</a> 033 */ 034public class ArtifactRepositoryMetadata 035 extends AbstractRepositoryMetadata 036{ 037 private Artifact artifact; 038 039 public ArtifactRepositoryMetadata( Artifact artifact ) 040 { 041 this( artifact, null ); 042 } 043 044 public ArtifactRepositoryMetadata( Artifact artifact, 045 Versioning versioning ) 046 { 047 super( createMetadata( artifact, versioning ) ); 048 this.artifact = artifact; 049 } 050 051 public boolean storedInGroupDirectory() 052 { 053 return false; 054 } 055 056 public boolean storedInArtifactVersionDirectory() 057 { 058 return false; 059 } 060 061 public String getGroupId() 062 { 063 return artifact.getGroupId(); 064 } 065 066 public String getArtifactId() 067 { 068 return artifact.getArtifactId(); 069 } 070 071 public String getBaseVersion() 072 { 073 // Don't want the artifact's version in here, as this is stored in the directory above that 074 return null; 075 } 076 077 public Object getKey() 078 { 079 return "artifact " + artifact.getGroupId() + ":" + artifact.getArtifactId(); 080 } 081 082 public boolean isSnapshot() 083 { 084 // Don't consider the artifact's version in here, as this is stored in the directory above that 085 return false; 086 } 087 088 public int getNature() 089 { 090 if ( artifact.getVersion() != null ) 091 { 092 return artifact.isSnapshot() ? SNAPSHOT : RELEASE; 093 } 094 095 VersionRange range = artifact.getVersionRange(); 096 if ( range != null ) 097 { 098 for ( Restriction restriction : range.getRestrictions() ) 099 { 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}