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 legacy repository layout (Maven 1.x).
35 * @author Brett Porter
36 * @plexus.component role="org.apache.maven.repository.discovery.ArtifactDiscoverer" role-hint="org.apache.maven.repository.discovery.LegacyArtifactDiscoverer"
38 public class LegacyArtifactDiscoverer
39 extends AbstractArtifactDiscoverer
40 implements ArtifactDiscoverer
42 private final static String POM = ".pom";
44 private final static String DELIM = "\\";
49 private ArtifactFactory artifactFactory;
51 public List discoverArtifacts( ArtifactRepository repository, String blacklistedPatterns, boolean includeSnapshots )
53 List artifacts = new ArrayList();
55 File repositoryBase = new File( repository.getBasedir() );
56 String[] artifactPaths = scanForArtifactPaths( repositoryBase, blacklistedPatterns );
58 for ( int i = 0; i < artifactPaths.length; i++ )
60 String path = artifactPaths[i];
62 Artifact artifact = ArtifactUtils.buildArtifactFromLegacyPath( path, artifactFactory );
63 if ( artifact != null )
65 artifact.setRepository( repository );
66 artifact.setFile( new File( repositoryBase, path ) );
68 if ( includeSnapshots || !artifact.isSnapshot() )
70 artifacts.add( artifact );
75 addKickedOutPath( path );
82 public List discoverStandalonePoms( ArtifactRepository repository, String blacklistedPatterns,
83 boolean convertSnapshots )
85 List artifacts = new ArrayList();
87 File repositoryBase = new File( repository.getBasedir() );
89 String[] artifactPaths = scanForArtifactPaths( repositoryBase, blacklistedPatterns );
91 for ( int i = 0; i < artifactPaths.length; i++ )
93 String path = artifactPaths[i];
95 if ( path.toLowerCase().endsWith( POM ) )
97 Artifact pomArtifact = ArtifactUtils.buildArtifactFromLegacyPath( path, artifactFactory );
98 if ( pomArtifact != null )
100 pomArtifact.setFile( new File( repositoryBase, path ) );
103 MavenXpp3Reader mavenReader = new MavenXpp3Reader();
104 String filename = repositoryBase.getAbsolutePath() + DELIM + path;
107 Model model = mavenReader.read( new FileReader( filename ) );
108 if ( ( pomArtifact != null ) && ( "pom".equals( model.getPackaging() ) ) )
110 if ( convertSnapshots || !pomArtifact.isSnapshot() )
112 artifacts.add( pomArtifact );
116 catch ( Exception e )
118 getLogger().info( "error reading file: " + filename );