* limitations under the License.
*/
-import org.codehaus.plexus.logging.AbstractLogEnabled;
-import org.codehaus.plexus.util.DirectoryScanner;
-import org.codehaus.plexus.util.FileUtils;
+import org.apache.maven.artifact.Artifact;
+import org.apache.maven.artifact.repository.ArtifactRepository;
+import org.apache.maven.model.Model;
+import org.apache.maven.model.io.xpp3.MavenXpp3Reader;
import java.io.File;
+import java.io.FileReader;
import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Iterator;
import java.util.List;
/**
* @author Brett Porter
*/
public abstract class AbstractArtifactDiscoverer
- extends AbstractLogEnabled
+ extends AbstractDiscoverer
{
/**
* Standard patterns to exclude from discovery as they are not artifacts.
"**/*.MD5", "**/*.sha1", "**/*.SHA1", "**/*snapshot-version", "*/website/**", "*/licenses/**", "*/licences/**",
"**/.htaccess", "**/*.html", "**/*.asc", "**/*.txt", "**/*.xml", "**/README*", "**/CHANGELOG*", "**/KEYS*"};
- private static final String[] EMPTY_STRING_ARRAY = new String[0];
-
- private List excludedPaths = new ArrayList();
-
- private List kickedOutPaths = new ArrayList();
+ protected static final String POM = ".pom";
/**
* Scan the repository for artifact paths.
return scanForArtifactPaths( repositoryBase, blacklistedPatterns, null, STANDARD_DISCOVERY_EXCLUDES );
}
- /**
- * Scan the repository for artifact paths.
- */
- protected String[] scanForArtifactPaths( File repositoryBase, String blacklistedPatterns, String[] includes,
- String[] excludes )
+ protected abstract Artifact buildArtifactFromPath( String path, ArtifactRepository repository );
+
+ public List discoverArtifacts( ArtifactRepository repository, String blacklistedPatterns, boolean includeSnapshots )
{
- List allExcludes = new ArrayList();
- allExcludes.addAll( FileUtils.getDefaultExcludesAsList() );
- if ( excludes != null )
+ if ( !"file".equals( repository.getProtocol() ) )
{
- allExcludes.addAll( Arrays.asList( excludes ) );
+ throw new UnsupportedOperationException( "Only filesystem repositories are supported" );
}
- if ( blacklistedPatterns != null && blacklistedPatterns.length() > 0 )
- {
- allExcludes.addAll( Arrays.asList( blacklistedPatterns.split( "," ) ) );
- }
+ File repositoryBase = new File( repository.getBasedir() );
- DirectoryScanner scanner = new DirectoryScanner();
- scanner.setBasedir( repositoryBase );
- if ( includes != null )
- {
- scanner.setIncludes( includes );
- }
- scanner.setExcludes( (String[]) allExcludes.toArray( EMPTY_STRING_ARRAY ) );
+ List artifacts = new ArrayList();
- scanner.scan();
+ String[] artifactPaths = scanForArtifactPaths( repositoryBase, blacklistedPatterns );
- excludedPaths.addAll( Arrays.asList( scanner.getExcludedFiles() ) );
+ for ( int i = 0; i < artifactPaths.length; i++ )
+ {
+ String path = artifactPaths[i];
+
+ Artifact artifact = buildArtifactFromPath( path, repository );
+ if ( artifact != null )
+ {
+ if ( includeSnapshots || !artifact.isSnapshot() )
+ {
+ artifacts.add( artifact );
+ }
+ }
+ else
+ {
+ addKickedOutPath( path );
+ }
+ }
- return scanner.getIncludedFiles();
+ return artifacts;
}
- /**
- * Add a path to the list of files that were kicked out due to being invalid.
- *
- * @param path the path to add
- * @todo add a reason
- */
- protected void addKickedOutPath( String path )
+ public List discoverStandalonePoms( ArtifactRepository repository, String blacklistedPatterns,
+ boolean includeSnapshots )
{
- kickedOutPaths.add( path );
- }
+ List artifacts = new ArrayList();
- public Iterator getExcludedPathsIterator()
- {
- return excludedPaths.iterator();
- }
+ File repositoryBase = new File( repository.getBasedir() );
- public Iterator getKickedOutPathsIterator()
- {
- return kickedOutPaths.iterator();
+ String[] artifactPaths = scanForArtifactPaths( repositoryBase, blacklistedPatterns );
+
+ for ( int i = 0; i < artifactPaths.length; i++ )
+ {
+ String path = artifactPaths[i];
+
+ if ( path.toLowerCase().endsWith( POM ) )
+ {
+ Artifact pomArtifact = buildArtifactFromPath( path, repository );
+ if ( pomArtifact != null )
+ {
+ pomArtifact.setFile( new File( repositoryBase, path ) );
+ }
+
+ MavenXpp3Reader mavenReader = new MavenXpp3Reader();
+ String filename = repositoryBase.getAbsolutePath() + "/" + path;
+ try
+ {
+ Model model = mavenReader.read( new FileReader( filename ) );
+ if ( ( pomArtifact != null ) && ( "pom".equals( model.getPackaging() ) ) )
+ {
+ if ( includeSnapshots || !pomArtifact.isSnapshot() )
+ {
+ artifacts.add( model );
+ }
+ }
+ }
+ catch ( Exception e )
+ {
+ getLogger().info( "error reading file: " + filename );
+ e.printStackTrace();
+ }
+ }
+ }
+
+ return artifacts;
}
}
--- /dev/null
+package org.apache.maven.repository.discovery;
+
+import org.apache.maven.artifact.factory.ArtifactFactory;
+import org.codehaus.plexus.logging.AbstractLogEnabled;
+import org.codehaus.plexus.util.DirectoryScanner;
+import org.codehaus.plexus.util.FileUtils;
+
+import java.io.File;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Iterator;
+import java.util.List;
+
+/**
+ * TODO [!]: Description.
+ *
+ * @author <a href="mailto:brett@apache.org">Brett Porter</a>
+ */
+public class AbstractDiscoverer
+ extends AbstractLogEnabled
+{
+ private List kickedOutPaths = new ArrayList();
+
+ /**
+ * @plexus.requirement
+ */
+ protected ArtifactFactory artifactFactory;
+
+ private static final String[] EMPTY_STRING_ARRAY = new String[0];
+
+ private List excludedPaths = new ArrayList();
+
+ /**
+ * Add a path to the list of files that were kicked out due to being invalid.
+ *
+ * @param path the path to add
+ * @todo add a reason
+ */
+ protected void addKickedOutPath( String path )
+ {
+ kickedOutPaths.add( path );
+ }
+
+ public Iterator getKickedOutPathsIterator()
+ {
+ return kickedOutPaths.iterator();
+ }
+
+ /**
+ * Scan the repository for artifact paths.
+ */
+ protected String[] scanForArtifactPaths( File repositoryBase, String blacklistedPatterns, String[] includes,
+ String[] excludes )
+ {
+ List allExcludes = new ArrayList();
+ allExcludes.addAll( FileUtils.getDefaultExcludesAsList() );
+ if ( excludes != null )
+ {
+ allExcludes.addAll( Arrays.asList( excludes ) );
+ }
+
+ if ( blacklistedPatterns != null && blacklistedPatterns.length() > 0 )
+ {
+ allExcludes.addAll( Arrays.asList( blacklistedPatterns.split( "," ) ) );
+ }
+
+ DirectoryScanner scanner = new DirectoryScanner();
+ scanner.setBasedir( repositoryBase );
+ if ( includes != null )
+ {
+ scanner.setIncludes( includes );
+ }
+ scanner.setExcludes( (String[]) allExcludes.toArray( EMPTY_STRING_ARRAY ) );
+
+ scanner.scan();
+
+ excludedPaths.addAll( Arrays.asList( scanner.getExcludedFiles() ) );
+
+ return scanner.getIncludedFiles();
+ }
+
+ public Iterator getExcludedPathsIterator()
+ {
+ return excludedPaths.iterator();
+ }
+}
*/
import org.apache.maven.artifact.Artifact;
-import org.apache.maven.artifact.factory.ArtifactFactory;
import org.apache.maven.artifact.repository.ArtifactRepository;
-import org.apache.maven.model.Model;
-import org.apache.maven.model.io.xpp3.MavenXpp3Reader;
import org.apache.maven.repository.ArtifactUtils;
-import java.io.File;
-import java.io.FileReader;
-import java.util.ArrayList;
-import java.util.List;
-
/**
* Artifact discoverer for the new repository layout (Maven 2.0+).
*
* @author John Casey
* @author Brett Porter
- * @plexus.component role="org.apache.maven.repository.discovery.ArtifactDiscoverer" role-hint="org.apache.maven.repository.discovery.DefaultArtifactDiscoverer"
+ * @plexus.component role="org.apache.maven.repository.discovery.ArtifactDiscoverer" role-hint="default"
*/
public class DefaultArtifactDiscoverer
extends AbstractArtifactDiscoverer
implements ArtifactDiscoverer
{
- private final static String POM = ".pom";
-
- /**
- * @plexus.requirement
- */
- private ArtifactFactory artifactFactory;
-
- public List discoverArtifacts( ArtifactRepository repository, String blacklistedPatterns, boolean includeSnapshots )
+ protected Artifact buildArtifactFromPath( String path, ArtifactRepository repository )
{
- if ( !"file".equals( repository.getProtocol() ) )
- {
- throw new UnsupportedOperationException( "Only filesystem repositories are supported" );
- }
-
- File repositoryBase = new File( repository.getBasedir() );
-
- List artifacts = new ArrayList();
-
- String[] artifactPaths = scanForArtifactPaths( repositoryBase, blacklistedPatterns );
-
- for ( int i = 0; i < artifactPaths.length; i++ )
- {
- String path = artifactPaths[i];
-
- Artifact artifact = ArtifactUtils.buildArtifact( repositoryBase, path, repository, artifactFactory );
-
- if ( artifact != null )
- {
- if ( includeSnapshots || !artifact.isSnapshot() )
- {
- artifacts.add( artifact );
- }
- }
- else
- {
- addKickedOutPath( path );
- }
- }
-
- return artifacts;
- }
-
- public List discoverStandalonePoms( ArtifactRepository repository, String blacklistedPatterns,
- boolean convertSnapshots )
- {
- List artifacts = new ArrayList();
-
- File repositoryBase = new File( repository.getBasedir() );
-
- String[] artifactPaths = scanForArtifactPaths( repositoryBase, blacklistedPatterns );
-
- for ( int i = 0; i < artifactPaths.length; i++ )
- {
- String path = artifactPaths[i];
-
- if ( path.toLowerCase().endsWith( POM ) )
- {
- Artifact pomArtifact = ArtifactUtils.buildArtifact( path, artifactFactory );
- if ( pomArtifact != null )
- {
- pomArtifact.setFile( new File( repositoryBase, path ) );
- }
-
- MavenXpp3Reader mavenReader = new MavenXpp3Reader();
- String filename = repositoryBase.getAbsolutePath() + "/" + path;
- try
- {
- Model model = mavenReader.read( new FileReader( filename ) );
- if ( ( model != null ) && ( "pom".equals( model.getPackaging() ) ) )
- {
- artifacts.add( model );
- }
- /*if ( ( pomArtifact != null ) && ( "pom".equals( model.getPackaging() ) ) )
- {
- if ( convertSnapshots || !pomArtifact.isSnapshot() )
- {
- artifacts.add( pomArtifact );
- }
- }
- */
- }
- catch ( Exception e )
- {
- getLogger().info( "error reading file: " + filename );
- e.printStackTrace();
- }
- }
- }
-
- return artifacts;
+ return ArtifactUtils.buildArtifact( path, repository, artifactFactory );
}
}
*/
import org.apache.maven.artifact.Artifact;
-import org.apache.maven.artifact.factory.ArtifactFactory;
import org.apache.maven.artifact.repository.metadata.ArtifactRepositoryMetadata;
import org.apache.maven.artifact.repository.metadata.GroupRepositoryMetadata;
import org.apache.maven.artifact.repository.metadata.Metadata;
* @plexus.component role="org.apache.maven.repository.discovery.MetadataDiscoverer" role-hint="org.apache.maven.repository.discovery.DefaultMetadataDiscoverer"
*/
public class DefaultMetadataDiscoverer
- extends AbstractArtifactDiscoverer
+ extends AbstractDiscoverer
implements MetadataDiscoverer
{
- /**
- * @plexus.requirement
- */
- private ArtifactFactory artifactFactory;
-
/**
* Standard patterns to include in discovery of metadata files.
*/
*/
import org.apache.maven.artifact.Artifact;
-import org.apache.maven.artifact.factory.ArtifactFactory;
import org.apache.maven.artifact.repository.ArtifactRepository;
-import org.apache.maven.model.Model;
-import org.apache.maven.model.io.xpp3.MavenXpp3Reader;
import org.apache.maven.repository.ArtifactUtils;
import java.io.File;
-import java.io.FileReader;
-import java.util.ArrayList;
-import java.util.List;
/**
* Artifact discoverer for the legacy repository layout (Maven 1.x).
*
* @author John Casey
* @author Brett Porter
- * @plexus.component role="org.apache.maven.repository.discovery.ArtifactDiscoverer" role-hint="org.apache.maven.repository.discovery.LegacyArtifactDiscoverer"
+ * @plexus.component role="org.apache.maven.repository.discovery.ArtifactDiscoverer" role-hint="legacy"
*/
public class LegacyArtifactDiscoverer
extends AbstractArtifactDiscoverer
implements ArtifactDiscoverer
{
- private final static String POM = ".pom";
-
- private final static String DELIM = "\\";
-
- /**
- * @plexus.requirement
- */
- private ArtifactFactory artifactFactory;
-
- public List discoverArtifacts( ArtifactRepository repository, String blacklistedPatterns, boolean includeSnapshots )
+ protected Artifact buildArtifactFromPath( String path, ArtifactRepository repository )
{
- List artifacts = new ArrayList();
+ Artifact artifact = ArtifactUtils.buildArtifactFromLegacyPath( path, artifactFactory );
- File repositoryBase = new File( repository.getBasedir() );
- String[] artifactPaths = scanForArtifactPaths( repositoryBase, blacklistedPatterns );
-
- for ( int i = 0; i < artifactPaths.length; i++ )
+ if ( artifact != null )
{
- String path = artifactPaths[i];
-
- Artifact artifact = ArtifactUtils.buildArtifactFromLegacyPath( path, artifactFactory );
- if ( artifact != null )
- {
- artifact.setRepository( repository );
- artifact.setFile( new File( repositoryBase, path ) );
-
- if ( includeSnapshots || !artifact.isSnapshot() )
- {
- artifacts.add( artifact );
- }
- }
- else
- {
- addKickedOutPath( path );
- }
- }
-
- return artifacts;
- }
-
- public List discoverStandalonePoms( ArtifactRepository repository, String blacklistedPatterns,
- boolean convertSnapshots )
- {
- List artifacts = new ArrayList();
-
- File repositoryBase = new File( repository.getBasedir() );
-
- String[] artifactPaths = scanForArtifactPaths( repositoryBase, blacklistedPatterns );
-
- for ( int i = 0; i < artifactPaths.length; i++ )
- {
- String path = artifactPaths[i];
-
- if ( path.toLowerCase().endsWith( POM ) )
- {
- Artifact pomArtifact = ArtifactUtils.buildArtifactFromLegacyPath( path, artifactFactory );
- if ( pomArtifact != null )
- {
- pomArtifact.setFile( new File( repositoryBase, path ) );
- }
-
- MavenXpp3Reader mavenReader = new MavenXpp3Reader();
- String filename = repositoryBase.getAbsolutePath() + DELIM + path;
- try
- {
- Model model = mavenReader.read( new FileReader( filename ) );
- if ( ( pomArtifact != null ) && ( "pom".equals( model.getPackaging() ) ) )
- {
- if ( convertSnapshots || !pomArtifact.isSnapshot() )
- {
- artifacts.add( pomArtifact );
- }
- }
- }
- catch ( Exception e )
- {
- getLogger().info( "error reading file: " + filename );
- e.printStackTrace();
- }
- }
+ artifact.setRepository( repository );
+ artifact.setFile( new File( repository.getBasedir(), path ) );
}
- return artifacts;
+ return artifact;
}
}
{
super.setUp();
- discoverer = (ArtifactDiscoverer) lookup( ArtifactDiscoverer.ROLE,
- "org.apache.maven.repository.discovery.DefaultArtifactDiscoverer" );
+ discoverer = (ArtifactDiscoverer) lookup( ArtifactDiscoverer.ROLE, "default" );
factory = (ArtifactFactory) lookup( ArtifactFactory.ROLE );
{
super.setUp();
- discoverer = (ArtifactDiscoverer) lookup( ArtifactDiscoverer.ROLE,
- "org.apache.maven.repository.discovery.LegacyArtifactDiscoverer" );
+ discoverer = (ArtifactDiscoverer) lookup( ArtifactDiscoverer.ROLE, "legacy" );
factory = (ArtifactFactory) lookup( ArtifactFactory.ROLE );
/**
* Method used to build an artifact and then set its repository and file fields with the proper values
*
- * @param repositoryBase the base directory of the repository
* @param path the path of the artifact relative from the repository base directory
* @param repository the repository where the artifact can be found
* @param artifactFactory the artifactFactory to build the Artifact object when the given path is a valid artifact path
* @return Artifact object if the given path represents an artifact path, otherwise, returns null
*/
- public static Artifact buildArtifact( File repositoryBase, String path, ArtifactRepository repository,
- ArtifactFactory artifactFactory )
+ public static Artifact buildArtifact( String path, ArtifactRepository repository, ArtifactFactory artifactFactory )
{
Artifact artifact = buildArtifact( path, artifactFactory );
if ( artifact != null )
{
artifact.setRepository( repository );
- artifact.setFile( new File( repositoryBase, path ) );
+ artifact.setFile( new File( repository.getBasedir(), path ) );
}
return artifact;