mirror of https://github.com/apache/archiva.git
test classifiers and custom types
PR: MRM-9 git-svn-id: https://svn.apache.org/repos/asf/maven/repository-manager/trunk@349700 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
ecdba7fcc4
commit
5040db2f65
|
@ -94,8 +94,6 @@ public class DefaultArtifactDiscoverer
|
|||
Collections.reverse( pathParts );
|
||||
String groupId = StringUtils.join( pathParts.iterator(), "." );
|
||||
|
||||
result = artifactFactory.createArtifact( groupId, artifactId, version, Artifact.SCOPE_RUNTIME, "jar" );
|
||||
|
||||
String remainingFilename = filename;
|
||||
if ( !remainingFilename.startsWith( artifactId + "-" ) )
|
||||
{
|
||||
|
@ -105,11 +103,67 @@ public class DefaultArtifactDiscoverer
|
|||
}
|
||||
|
||||
remainingFilename = remainingFilename.substring( artifactId.length() + 1 );
|
||||
|
||||
String classifier = null;
|
||||
|
||||
// TODO: use artifact handler, share with legacy discoverer
|
||||
String type;
|
||||
if ( remainingFilename.endsWith( ".tar.gz" ) )
|
||||
{
|
||||
type = "distribution-tgz";
|
||||
remainingFilename = remainingFilename.substring( 0, remainingFilename.length() - 7 );
|
||||
}
|
||||
else if ( remainingFilename.endsWith( ".zip" ) )
|
||||
{
|
||||
type = "distribution-zip";
|
||||
remainingFilename = remainingFilename.substring( 0, remainingFilename.length() - 4 );
|
||||
}
|
||||
else if ( remainingFilename.endsWith( "-sources.jar" ) )
|
||||
{
|
||||
type = "java-source";
|
||||
classifier = "sources";
|
||||
remainingFilename = remainingFilename.substring( 0, remainingFilename.length() - 12 );
|
||||
}
|
||||
else
|
||||
{
|
||||
int index = remainingFilename.lastIndexOf( "." );
|
||||
if ( index < 0 )
|
||||
{
|
||||
addKickedOutPath( path );
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
type = remainingFilename.substring( index + 1 );
|
||||
remainingFilename = remainingFilename.substring( 0, index );
|
||||
}
|
||||
|
||||
if ( classifier == null )
|
||||
{
|
||||
result = artifactFactory.createArtifact( groupId, artifactId, version, Artifact.SCOPE_RUNTIME, type );
|
||||
}
|
||||
else
|
||||
{
|
||||
result = artifactFactory.createArtifactWithClassifier( groupId, artifactId, version, type, classifier );
|
||||
}
|
||||
|
||||
if ( result.isSnapshot() )
|
||||
{
|
||||
result = artifactFactory.createArtifact( groupId, artifactId,
|
||||
remainingFilename.substring( 0, remainingFilename.length() - 4 ),
|
||||
Artifact.SCOPE_RUNTIME, "jar" );
|
||||
// version is XXX-SNAPSHOT, filename is XXX-yyyyMMdd.hhmmss-b
|
||||
int classifierIndex = remainingFilename.indexOf( '-', version.length() + 8 );
|
||||
if ( classifierIndex >= 0 )
|
||||
{
|
||||
classifier = remainingFilename.substring( classifierIndex + 1 );
|
||||
remainingFilename = remainingFilename.substring( 0, classifierIndex );
|
||||
result = artifactFactory.createArtifactWithClassifier( groupId, artifactId, remainingFilename, type,
|
||||
classifier );
|
||||
}
|
||||
else
|
||||
{
|
||||
result = artifactFactory.createArtifact( groupId, artifactId, remainingFilename, Artifact.SCOPE_RUNTIME,
|
||||
type );
|
||||
}
|
||||
|
||||
// poor encapsulation requires we do this to populate base version
|
||||
if ( !result.isSnapshot() )
|
||||
{
|
||||
|
@ -130,6 +184,17 @@ public class DefaultArtifactDiscoverer
|
|||
|
||||
return null;
|
||||
}
|
||||
else if ( !remainingFilename.equals( version ) )
|
||||
{
|
||||
if ( remainingFilename.charAt( version.length() ) != '-' )
|
||||
{
|
||||
addKickedOutPath( path );
|
||||
|
||||
return null;
|
||||
}
|
||||
classifier = remainingFilename.substring( version.length() + 1 );
|
||||
result = artifactFactory.createArtifactWithClassifier( groupId, artifactId, version, type, classifier );
|
||||
}
|
||||
|
||||
result.setFile( new File( path ) );
|
||||
|
||||
|
|
|
@ -99,6 +99,7 @@ public class LegacyArtifactDiscoverer
|
|||
|
||||
String lastAvceToken = (String) avceTokenList.removeLast();
|
||||
|
||||
// TODO: share with other discoverer, use artifact handlers instead
|
||||
if ( lastAvceToken.endsWith( ".tar.gz" ) )
|
||||
{
|
||||
type = "distribution-tgz";
|
||||
|
|
|
@ -29,7 +29,7 @@ import java.util.List;
|
|||
*
|
||||
* @author <a href="mailto:brett@apache.org">Brett Porter</a>
|
||||
* @version $Id$
|
||||
* @todo other tests for kickouts to do here, along the lines of wrong artifactId, parse classifiers, locate poms
|
||||
* @todo test location of poms, checksums
|
||||
*/
|
||||
public class DefaultArtifactDiscovererTest
|
||||
extends PlexusTestCase
|
||||
|
@ -212,6 +212,45 @@ public class DefaultArtifactDiscovererTest
|
|||
}
|
||||
}
|
||||
|
||||
public void testInclusion()
|
||||
{
|
||||
List artifacts = discoverer.discoverArtifacts( repositoryLocation, null, true );
|
||||
assertNotNull( "Check artifacts not null", artifacts );
|
||||
|
||||
assertTrue( "Check normal included",
|
||||
artifacts.contains( createArtifact( "org.apache.maven", "testing", "1.0" ) ) );
|
||||
}
|
||||
|
||||
public void testArtifactWithClassifier()
|
||||
{
|
||||
List artifacts = discoverer.discoverArtifacts( repositoryLocation, null, true );
|
||||
assertNotNull( "Check artifacts not null", artifacts );
|
||||
|
||||
assertTrue( "Check normal included",
|
||||
artifacts.contains( createArtifact( "org.apache.maven", "some-ejb", "1.0", "jar", "client" ) ) );
|
||||
}
|
||||
|
||||
public void testJavaSourcesInclusion()
|
||||
{
|
||||
List artifacts = discoverer.discoverArtifacts( repositoryLocation, null, true );
|
||||
assertNotNull( "Check artifacts not null", artifacts );
|
||||
|
||||
assertTrue( "Check normal included",
|
||||
artifacts.contains( createArtifact( "org.apache.maven", "testing", "1.0", "java-source" ) ) );
|
||||
}
|
||||
|
||||
public void testDistributionInclusion()
|
||||
{
|
||||
List artifacts = discoverer.discoverArtifacts( repositoryLocation, null, true );
|
||||
assertNotNull( "Check artifacts not null", artifacts );
|
||||
|
||||
assertTrue( "Check zip included",
|
||||
artifacts.contains( createArtifact( "org.apache.maven", "testing", "1.0", "distribution-zip" ) ) );
|
||||
|
||||
assertTrue( "Check tar.gz included",
|
||||
artifacts.contains( createArtifact( "org.apache.maven", "testing", "1.0", "distribution-tgz" ) ) );
|
||||
}
|
||||
|
||||
public void testSnapshotInclusion()
|
||||
{
|
||||
List artifacts = discoverer.discoverArtifacts( repositoryLocation, null, true );
|
||||
|
@ -237,4 +276,14 @@ public class DefaultArtifactDiscovererTest
|
|||
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