mirror of https://github.com/apache/archiva.git
Refactored tests and created an Abstract test case.
Also, refactored some of the module classes and improved some javadocs. git-svn-id: https://svn.apache.org/repos/asf/maven/repository-manager/trunk@414034 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
b5aeb8c65b
commit
14d7e27eb8
|
@ -56,6 +56,14 @@ public abstract class AbstractArtifactDiscoverer
|
|||
return scanForArtifactPaths( repositoryBase, blacklistedPatterns, null, STANDARD_DISCOVERY_EXCLUDES );
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a list of artifacts found in a specified repository
|
||||
*
|
||||
* @param repository The ArtifactRepository to discover artifacts
|
||||
* @param blacklistedPatterns Comma-delimited list of string paths that will be excluded in the discovery
|
||||
* @param includeSnapshots if the repository contains snapshots which should also be included
|
||||
* @return list of artifacts
|
||||
*/
|
||||
public List discoverArtifacts( ArtifactRepository repository, String blacklistedPatterns, boolean includeSnapshots )
|
||||
{
|
||||
if ( !"file".equals( repository.getProtocol() ) )
|
||||
|
@ -73,7 +81,7 @@ public abstract class AbstractArtifactDiscoverer
|
|||
{
|
||||
String path = artifactPaths[i];
|
||||
|
||||
Artifact artifact = null;
|
||||
Artifact artifact;
|
||||
try
|
||||
{
|
||||
artifact = buildArtifactFromPath( path, repository );
|
||||
|
@ -92,6 +100,14 @@ public abstract class AbstractArtifactDiscoverer
|
|||
return artifacts;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a list of pom packaging artifacts found in a specified repository
|
||||
*
|
||||
* @param repository The ArtifactRepository to discover artifacts
|
||||
* @param blacklistedPatterns Comma-delimited list of string paths that will be excluded in the discovery
|
||||
* @param includeSnapshots if the repository contains snapshots which should also be included
|
||||
* @return list of pom artifacts
|
||||
*/
|
||||
public List discoverStandalonePoms( ArtifactRepository repository, String blacklistedPatterns,
|
||||
boolean includeSnapshots )
|
||||
{
|
||||
|
@ -148,6 +164,14 @@ public abstract class AbstractArtifactDiscoverer
|
|||
return artifacts;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an artifact object that is represented by the specified path in a repository
|
||||
*
|
||||
* @param path The path that is pointing to an artifact
|
||||
* @param repository The repository of the artifact
|
||||
* @return Artifact
|
||||
* @throws DiscovererException when the specified path does correspond to an artifact
|
||||
*/
|
||||
public Artifact buildArtifactFromPath( String path, ArtifactRepository repository )
|
||||
throws DiscovererException
|
||||
{
|
||||
|
|
|
@ -59,6 +59,11 @@ public abstract class AbstractDiscoverer
|
|||
kickedOutPaths.add( new DiscovererPath( path, reason ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an iterator for the list if DiscovererPaths that were found to not represent a searched object
|
||||
*
|
||||
* @return Iterator for the DiscovererPath List
|
||||
*/
|
||||
public Iterator getKickedOutPathsIterator()
|
||||
{
|
||||
return kickedOutPaths.iterator();
|
||||
|
@ -102,6 +107,11 @@ public abstract class AbstractDiscoverer
|
|||
return scanner.getIncludedFiles();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an iterator for the list if DiscovererPaths that were not processed because they are explicitly excluded
|
||||
*
|
||||
* @return Iterator for the DiscovererPath List
|
||||
*/
|
||||
public Iterator getExcludedPathsIterator()
|
||||
{
|
||||
return excludedPaths.iterator();
|
||||
|
|
|
@ -34,6 +34,9 @@ import java.util.StringTokenizer;
|
|||
public class DefaultArtifactDiscoverer
|
||||
extends AbstractArtifactDiscoverer
|
||||
{
|
||||
/**
|
||||
* @see org.apache.maven.repository.discovery.ArtifactDiscoverer#buildArtifact(String)
|
||||
*/
|
||||
public Artifact buildArtifact( String path )
|
||||
throws DiscovererException
|
||||
{
|
||||
|
|
|
@ -51,14 +51,16 @@ public class DefaultMetadataDiscoverer
|
|||
/**
|
||||
* Standard patterns to include in discovery of metadata files.
|
||||
*/
|
||||
private static final String[] STANDARD_DISCOVERY_INCLUDES = {"**/*-metadata.xml", "**/*/*-metadata.xml",
|
||||
"**/*/*/*-metadata.xml", "**/*-metadata-*.xml", "**/*/*-metadata-*.xml", "**/*/*/*-metadata-*.xml"};
|
||||
private static final String[] STANDARD_DISCOVERY_INCLUDES = {"**/*-metadata.xml",
|
||||
"**/*/*-metadata.xml",
|
||||
"**/*/*/*-metadata.xml",
|
||||
"**/*-metadata-*.xml",
|
||||
"**/*/*-metadata-*.xml",
|
||||
"**/*/*/*-metadata-*.xml"
|
||||
};
|
||||
|
||||
/**
|
||||
* Search the repository for metadata files.
|
||||
*
|
||||
* @param repositoryBase
|
||||
* @param blacklistedPatterns
|
||||
* @see org.apache.maven.repository.discovery.MetadataDiscoverer#discoverMetadata(java.io.File, String)
|
||||
*/
|
||||
public List discoverMetadata( File repositoryBase, String blacklistedPatterns )
|
||||
{
|
||||
|
@ -92,7 +94,7 @@ public class DefaultMetadataDiscoverer
|
|||
private RepositoryMetadata buildMetadata( String repo, String metadataPath )
|
||||
throws DiscovererException
|
||||
{
|
||||
Metadata m = null;
|
||||
Metadata m;
|
||||
String repoPath = repo + "/" + metadataPath;
|
||||
try
|
||||
{
|
||||
|
@ -128,6 +130,13 @@ public class DefaultMetadataDiscoverer
|
|||
return repositoryMetadata;
|
||||
}
|
||||
|
||||
/**
|
||||
* Builds a RepositoryMetadata object from a Metadata object and its path
|
||||
*
|
||||
* @param m Metadata
|
||||
* @param metadataPath path
|
||||
* @return RepositoryMetadata if the parameters represent one; null if not
|
||||
*/
|
||||
private RepositoryMetadata buildMetadata( Metadata m, String metadataPath )
|
||||
{
|
||||
String metaGroupId = m.getGroupId();
|
||||
|
|
|
@ -37,6 +37,9 @@ import java.util.StringTokenizer;
|
|||
public class LegacyArtifactDiscoverer
|
||||
extends AbstractArtifactDiscoverer
|
||||
{
|
||||
/**
|
||||
* @see org.apache.maven.repository.discovery.ArtifactDiscoverer#buildArtifact(String)
|
||||
*/
|
||||
public Artifact buildArtifact( String path )
|
||||
throws DiscovererException
|
||||
{
|
||||
|
|
|
@ -0,0 +1,82 @@
|
|||
package org.apache.maven.repository.discovery;
|
||||
|
||||
/*
|
||||
* Copyright 2005-2006 The Apache Software Foundation.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import org.codehaus.plexus.PlexusTestCase;
|
||||
import org.apache.maven.artifact.factory.ArtifactFactory;
|
||||
import org.apache.maven.artifact.repository.ArtifactRepositoryFactory;
|
||||
import org.apache.maven.artifact.repository.ArtifactRepository;
|
||||
import org.apache.maven.artifact.repository.layout.ArtifactRepositoryLayout;
|
||||
import org.apache.maven.artifact.Artifact;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
/**
|
||||
* @author Edwin Punzalan
|
||||
*/
|
||||
public abstract class AbstractArtifactDiscovererTest
|
||||
extends PlexusTestCase
|
||||
{
|
||||
protected ArtifactDiscoverer discoverer;
|
||||
|
||||
private ArtifactFactory factory;
|
||||
|
||||
protected ArtifactRepository repository;
|
||||
|
||||
protected abstract String getLayout();
|
||||
|
||||
protected abstract File getRepositoryFile();
|
||||
|
||||
protected void setUp()
|
||||
throws Exception
|
||||
{
|
||||
super.setUp();
|
||||
|
||||
discoverer = (ArtifactDiscoverer) lookup( ArtifactDiscoverer.ROLE, getLayout() );
|
||||
|
||||
factory = (ArtifactFactory) lookup( ArtifactFactory.ROLE );
|
||||
|
||||
repository = getRepository();
|
||||
}
|
||||
|
||||
protected ArtifactRepository getRepository()
|
||||
throws Exception
|
||||
{
|
||||
File basedir = getRepositoryFile();
|
||||
|
||||
ArtifactRepositoryFactory factory = (ArtifactRepositoryFactory) lookup( ArtifactRepositoryFactory.ROLE );
|
||||
|
||||
ArtifactRepositoryLayout layout = (ArtifactRepositoryLayout) lookup( ArtifactRepositoryLayout.ROLE, getLayout() );
|
||||
|
||||
return factory.createArtifactRepository( "discoveryRepo", "file://" + basedir, layout, null, null );
|
||||
}
|
||||
|
||||
protected Artifact createArtifact( String groupId, String artifactId, String version )
|
||||
{
|
||||
return factory.createArtifact( groupId, artifactId, version, null, "jar" );
|
||||
}
|
||||
|
||||
protected Artifact createArtifact( String groupId, String artifactId, String version, String type )
|
||||
{
|
||||
return factory.createArtifact( groupId, artifactId, version, null, type );
|
||||
}
|
||||
|
||||
protected Artifact createArtifact( String groupId, String artifactId, String version, String type, String classifier )
|
||||
{
|
||||
return factory.createArtifactWithClassifier( groupId, artifactId, version, type, classifier );
|
||||
}
|
||||
}
|
|
@ -17,12 +17,7 @@ package org.apache.maven.repository.discovery;
|
|||
*/
|
||||
|
||||
import org.apache.maven.artifact.Artifact;
|
||||
import org.apache.maven.artifact.factory.ArtifactFactory;
|
||||
import org.apache.maven.artifact.repository.ArtifactRepository;
|
||||
import org.apache.maven.artifact.repository.ArtifactRepositoryFactory;
|
||||
import org.apache.maven.artifact.repository.layout.ArtifactRepositoryLayout;
|
||||
import org.apache.maven.model.Model;
|
||||
import org.codehaus.plexus.PlexusTestCase;
|
||||
import org.codehaus.plexus.component.repository.exception.ComponentLookupException;
|
||||
|
||||
import java.io.File;
|
||||
|
@ -40,28 +35,16 @@ import java.util.List;
|
|||
* @todo test location of poms, checksums
|
||||
*/
|
||||
public class DefaultArtifactDiscovererTest
|
||||
extends PlexusTestCase
|
||||
extends AbstractArtifactDiscovererTest
|
||||
{
|
||||
private ArtifactDiscoverer discoverer;
|
||||
|
||||
private ArtifactFactory factory;
|
||||
|
||||
private ArtifactRepository repository;
|
||||
|
||||
protected void setUp()
|
||||
throws Exception
|
||||
protected String getLayout()
|
||||
{
|
||||
super.setUp();
|
||||
return "default";
|
||||
}
|
||||
|
||||
discoverer = (ArtifactDiscoverer) lookup( ArtifactDiscoverer.ROLE, "default" );
|
||||
|
||||
factory = (ArtifactFactory) lookup( ArtifactFactory.ROLE );
|
||||
|
||||
File basedir = getTestFile( "src/test/repository" );
|
||||
ArtifactRepositoryFactory factory = (ArtifactRepositoryFactory) lookup( ArtifactRepositoryFactory.ROLE );
|
||||
|
||||
ArtifactRepositoryLayout layout = (ArtifactRepositoryLayout) lookup( ArtifactRepositoryLayout.ROLE, "default" );
|
||||
repository = factory.createArtifactRepository( "discoveryRepo", "file://" + basedir, layout, null, null );
|
||||
protected File getRepositoryFile()
|
||||
{
|
||||
return getTestFile( "src/test/repository" );
|
||||
}
|
||||
|
||||
public void testDefaultExcludes()
|
||||
|
@ -594,20 +577,4 @@ public class DefaultArtifactDiscovererTest
|
|||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
private Artifact createArtifact( String groupId, String artifactId, String version )
|
||||
{
|
||||
return factory.createArtifact( groupId, artifactId, version, null, "jar" );
|
||||
}
|
||||
|
||||
private Artifact createArtifact( String groupId, String artifactId, String version, String type )
|
||||
{
|
||||
return factory.createArtifact( groupId, artifactId, version, null, type );
|
||||
}
|
||||
|
||||
private Artifact createArtifact( String groupId, String artifactId, String version, String type, String classifier )
|
||||
{
|
||||
return factory.createArtifactWithClassifier( groupId, artifactId, version, type, classifier );
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -17,11 +17,6 @@ package org.apache.maven.repository.discovery;
|
|||
*/
|
||||
|
||||
import org.apache.maven.artifact.Artifact;
|
||||
import org.apache.maven.artifact.factory.ArtifactFactory;
|
||||
import org.apache.maven.artifact.repository.ArtifactRepository;
|
||||
import org.apache.maven.artifact.repository.ArtifactRepositoryFactory;
|
||||
import org.apache.maven.artifact.repository.layout.ArtifactRepositoryLayout;
|
||||
import org.codehaus.plexus.PlexusTestCase;
|
||||
import org.codehaus.plexus.component.repository.exception.ComponentLookupException;
|
||||
|
||||
import java.io.File;
|
||||
|
@ -34,32 +29,18 @@ import java.util.List;
|
|||
*
|
||||
* @author <a href="mailto:brett@apache.org">Brett Porter</a>
|
||||
* @version $Id$
|
||||
* @todo share as much as possible with default via abstract test case
|
||||
*/
|
||||
public class LegacyArtifactDiscovererTest
|
||||
extends PlexusTestCase
|
||||
extends AbstractArtifactDiscovererTest
|
||||
{
|
||||
private ArtifactDiscoverer discoverer;
|
||||
|
||||
private ArtifactFactory factory;
|
||||
|
||||
private ArtifactRepository repository;
|
||||
|
||||
protected void setUp()
|
||||
throws Exception
|
||||
protected String getLayout()
|
||||
{
|
||||
super.setUp();
|
||||
return "legacy";
|
||||
}
|
||||
|
||||
discoverer = (ArtifactDiscoverer) lookup( ArtifactDiscoverer.ROLE, "legacy" );
|
||||
|
||||
factory = (ArtifactFactory) lookup( ArtifactFactory.ROLE );
|
||||
|
||||
File basedir = getTestFile( "src/test/legacy-repository" );
|
||||
|
||||
ArtifactRepositoryFactory factory = (ArtifactRepositoryFactory) lookup( ArtifactRepositoryFactory.ROLE );
|
||||
|
||||
ArtifactRepositoryLayout layout = (ArtifactRepositoryLayout) lookup( ArtifactRepositoryLayout.ROLE, "legacy" );
|
||||
repository = factory.createArtifactRepository( "discoveryRepo", "file://" + basedir, layout, null, null );
|
||||
protected File getRepositoryFile()
|
||||
{
|
||||
return getTestFile( "src/test/legacy-repository" );
|
||||
}
|
||||
|
||||
public void testDefaultExcludes()
|
||||
|
@ -433,20 +414,4 @@ public class LegacyArtifactDiscovererTest
|
|||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
private Artifact createArtifact( String groupId, String artifactId, String version )
|
||||
{
|
||||
return factory.createArtifact( groupId, artifactId, version, null, "jar" );
|
||||
}
|
||||
|
||||
private Artifact createArtifact( String groupId, String artifactId, String version, String type )
|
||||
{
|
||||
return factory.createArtifact( groupId, artifactId, version, null, type );
|
||||
}
|
||||
|
||||
private Artifact createArtifact( String groupId, String artifactId, String version, String type, String classifier )
|
||||
{
|
||||
return factory.createArtifactWithClassifier( groupId, artifactId, version, type, classifier );
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue