1 package org.apache.maven.repository.discovery;
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.factory.ArtifactFactory;
21 import org.apache.maven.artifact.repository.ArtifactRepository;
22 import org.apache.maven.model.Model;
23 import org.apache.maven.model.io.xpp3.MavenXpp3Reader;
24 import org.apache.maven.repository.ArtifactUtils;
27 import java.io.FileReader;
28 import java.util.ArrayList;
29 import java.util.List;
32 * Artifact discoverer for the new repository layout (Maven 2.0+).
35 * @author Brett Porter
36 * @plexus.component role="org.apache.maven.repository.discovery.ArtifactDiscoverer" role-hint="org.apache.maven.repository.discovery.DefaultArtifactDiscoverer"
38 public class DefaultArtifactDiscoverer
39 extends AbstractArtifactDiscoverer
40 implements ArtifactDiscoverer
42 private final static String POM = ".pom";
47 private ArtifactFactory artifactFactory;
49 public List discoverArtifacts( ArtifactRepository repository, String blacklistedPatterns, boolean includeSnapshots )
51 if ( !"file".equals( repository.getProtocol() ) )
53 throw new UnsupportedOperationException( "Only filesystem repositories are supported" );
56 File repositoryBase = new File( repository.getBasedir() );
58 List artifacts = new ArrayList();
60 String[] artifactPaths = scanForArtifactPaths( repositoryBase, blacklistedPatterns );
62 for ( int i = 0; i < artifactPaths.length; i++ )
64 String path = artifactPaths[i];
66 Artifact artifact = ArtifactUtils.buildArtifact( repositoryBase, path, repository, artifactFactory );
68 if ( artifact != null )
70 if ( includeSnapshots || !artifact.isSnapshot() )
72 artifacts.add( artifact );
77 addKickedOutPath( path );
84 public List discoverStandalonePoms( ArtifactRepository repository, String blacklistedPatterns,
85 boolean convertSnapshots )
87 List artifacts = new ArrayList();
89 File repositoryBase = new File( repository.getBasedir() );
91 String[] artifactPaths = scanForArtifactPaths( repositoryBase, blacklistedPatterns );
93 for ( int i = 0; i < artifactPaths.length; i++ )
95 String path = artifactPaths[i];
97 if ( path.toLowerCase().endsWith( POM ) )
99 Artifact pomArtifact = ArtifactUtils.buildArtifact( path, artifactFactory );
100 if ( pomArtifact != null )
102 pomArtifact.setFile( new File( repositoryBase, path ) );
105 MavenXpp3Reader mavenReader = new MavenXpp3Reader();
106 String filename = repositoryBase.getAbsolutePath() + "/" + path;
109 Model model = mavenReader.read( new FileReader( filename ) );
110 if ( ( model != null ) && ( "pom".equals( model.getPackaging() ) ) )
112 artifacts.add( model );
114 /*if ( ( pomArtifact != null ) && ( "pom".equals( model.getPackaging() ) ) )
116 if ( convertSnapshots || !pomArtifact.isSnapshot() )
118 artifacts.add( pomArtifact );
123 catch ( Exception e )
125 getLogger().info( "error reading file: " + filename );