1 package org.apache.maven.archiva.layer;
4 * Copyright 2005-2006 The Apache Software Foundation.
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
19 import org.apache.maven.artifact.Artifact;
20 import org.apache.maven.artifact.repository.ArtifactRepository;
21 import org.apache.maven.artifact.repository.metadata.ArtifactRepositoryMetadata;
22 import org.apache.maven.artifact.repository.metadata.Metadata;
23 import org.apache.maven.artifact.repository.metadata.io.xpp3.MetadataXpp3Reader;
24 import org.codehaus.plexus.util.xml.pull.XmlPullParserException;
27 import java.io.FileNotFoundException;
28 import java.io.FileReader;
29 import java.io.IOException;
30 import java.util.List;
35 public class DefaultRepositoryQueryLayer
36 implements RepositoryQueryLayer
38 protected ArtifactRepository repository;
40 public DefaultRepositoryQueryLayer( ArtifactRepository repository )
42 this.repository = repository;
45 public boolean containsArtifact( Artifact artifact )
47 File f = new File( repository.getBasedir(), repository.pathOf( artifact ) );
51 public List getVersions( Artifact artifact )
52 throws RepositoryQueryLayerException
54 Metadata metadata = getMetadata( artifact );
56 return metadata.getVersioning().getVersions();
59 public ArtifactRepository getRepository()
64 private Metadata getMetadata( Artifact artifact )
65 throws RepositoryQueryLayerException
69 ArtifactRepositoryMetadata repositoryMetadata = new ArtifactRepositoryMetadata( artifact );
70 String path = repository.pathOfRemoteRepositoryMetadata( repositoryMetadata );
71 File metadataFile = new File( repository.getBasedir(), path );
72 if ( metadataFile.exists() )
74 MetadataXpp3Reader reader = new MetadataXpp3Reader();
77 metadata = reader.read( new FileReader( metadataFile ) );
79 catch ( FileNotFoundException e )
81 throw new RepositoryQueryLayerException( "Error occurred while attempting to read metadata file", e );
83 catch ( IOException e )
85 throw new RepositoryQueryLayerException( "Error occurred while attempting to read metadata file", e );
87 catch ( XmlPullParserException e )
89 throw new RepositoryQueryLayerException( "Error occurred while attempting to read metadata file", e );
94 throw new RepositoryQueryLayerException( "Metadata not found: " + metadataFile.getAbsolutePath() );