fix unit tests

git-svn-id: https://svn.apache.org/repos/asf/archiva/trunk@1549370 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Olivier Lamy 2013-12-09 02:47:18 +00:00
parent 74e63f4bbb
commit 449de093e2
2 changed files with 47 additions and 22 deletions

View File

@ -524,9 +524,9 @@ public class ArchivaDavResourceFactoryTest
expect( repoFactory.getManagedRepositoryContent( INTERNAL_REPO ) ).andReturn( internalRepo );
expect( request.getMethod() ).andReturn( "GET" ).times( 2 );
expect( request.getMethod() ).andReturn( "GET" ).times( 3 );
expect( request.getRemoteAddr() ).andReturn( "http://localhost:8080" ).times( 2 );
expect( request.getRemoteAddr() ).andReturn( "http://localhost:8080" ).times( 3 );
expect( request.getDavSession() ).andReturn( new ArchivaDavSession() ).times( 2 );
@ -575,7 +575,7 @@ public class ArchivaDavResourceFactoryTest
expect( request.getMethod() ).andReturn( "GET" ).times( 2 );
expect( request.getRemoteAddr() ).andReturn( "http://localhost:8080" ).times( 2 );
expect( request.getRemoteAddr() ).andReturn( "http://localhost:8080" ).times( 3 );
expect( request.getDavSession() ).andReturn( new ArchivaDavSession() ).times( 2 );

View File

@ -289,8 +289,8 @@ public class Maven2RepositoryStorage
if ( ( problem.getException() instanceof FileNotFoundException && e.getModelId() != null &&
!e.getModelId().equals( problem.getModelId() ) ) )
{
log.warn( "The artifact's parent POM file '{}' cannot be resolved. " +
"Using defaults for project version metadata..", file );
log.warn( "The artifact's parent POM file '{}' cannot be resolved. "
+ "Using defaults for project version metadata..", file );
ProjectVersionMetadata metadata = new ProjectVersionMetadata();
metadata.setId( readMetadataRequest.getProjectVersion() );
@ -765,41 +765,67 @@ public class Maven2RepositoryStorage
}
public String getFilePathWithVersion( final String requestPath, ManagedRepositoryContent managedRepositoryContent )
throws LayoutException, XMLException
throws XMLException
{
String requestPathNoRepository = removePrefix( requestPath );
ArtifactReference artifactReference = pathParser.toArtifactReference( requestPathNoRepository );
if (StringUtils.endsWith( requestPath, METADATA_FILENAME ))
{
return getFilePath( requestPath, managedRepositoryContent.getRepository() );
}
String filePath = getFilePath( requestPath, managedRepositoryContent.getRepository() );
String requestPathNoRepository = removePrefix( requestPath );
ArtifactReference artifactReference = null;
try
{
artifactReference = pathParser.toArtifactReference( filePath );
}
catch ( LayoutException e )
{
return filePath;
}
if ( StringUtils.endsWith( artifactReference.getVersion(), "SNAPSHOT" ) )
{
// read maven metadata to get last timestamp
File metadataDir = new File( managedRepositoryContent.getRepoRoot(), filePath ).getParentFile();
ArchivaRepositoryMetadata archivaRepositoryMetadata = MavenMetadataReader.read( new File(metadataDir, METADATA_FILENAME ) );
if ( !metadataDir.exists() )
{
return filePath;
}
File metadataFile = new File( metadataDir, METADATA_FILENAME );
if ( !metadataFile.exists() )
{
return filePath;
}
ArchivaRepositoryMetadata archivaRepositoryMetadata = MavenMetadataReader.read( metadataFile );
int buildNumber = archivaRepositoryMetadata.getSnapshotVersion().getBuildNumber();
String timestamp = archivaRepositoryMetadata.getSnapshotVersion().getTimestamp();
// org/apache/archiva/archiva-checksum/1.4-M4-SNAPSHOT/archiva-checksum-1.4-M4-SNAPSHOT.jar
// -> archiva-checksum-1.4-M4-20130425.081822-1.jar
filePath = StringUtils.replace( filePath, artifactReference.getArtifactId() + "-" + artifactReference.getVersion(),
artifactReference.getArtifactId() + "-" + StringUtils.remove( artifactReference.getVersion(), "-SNAPSHOT")
+ "-" + timestamp + "-" + buildNumber );
filePath =
StringUtils.replace( filePath, artifactReference.getArtifactId() + "-" + artifactReference.getVersion(),
artifactReference.getArtifactId() + "-" + StringUtils.remove(
artifactReference.getVersion(), "-SNAPSHOT" ) + "-" + timestamp + "-"
+ buildNumber );
}
return filePath;
}
//-----------------------------
// internal
//-----------------------------
/**
* FIXME remove
*
* @param href
* @return
*/
@ -992,7 +1018,6 @@ public class Maven2RepositoryStorage
}
private static final class PomFilenameFilter
implements FilenameFilter
{