[MRM-1761] Returned URL in search result does not work for SNAPSHOTS

git-svn-id: https://svn.apache.org/repos/asf/archiva/trunk@1549368 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Olivier Lamy 2013-12-09 02:46:56 +00:00
parent 978ab1446b
commit b256625132
4 changed files with 78 additions and 2 deletions

View File

@ -527,6 +527,28 @@ public class ArchivaDavResourceFactory
return path; return path;
} }
private String evaluatePathWithVersion( ArchivaDavResourceLocator archivaLocator, ManagedRepositoryContent managedRepositoryContent )
throws DavException
{
String layout = managedRepositoryContent.getRepository() == null ? new ManagedRepository( ).getLayout() : managedRepositoryContent.getRepository().getLayout();
RepositoryStorage repositoryStorage =
this.applicationContext.getBean( "repositoryStorage#" + layout, RepositoryStorage.class );
try
{
return repositoryStorage.getFilePathWithVersion( archivaLocator.getResourcePath(), managedRepositoryContent );
}
catch ( LayoutException e )
{
log.error( e.getMessage(), e );
throw new DavException( HttpServletResponse.SC_INTERNAL_SERVER_ERROR, e );
}
catch ( XMLException e )
{
log.error( e.getMessage(), e );
throw new DavException( HttpServletResponse.SC_INTERNAL_SERVER_ERROR, e );
}
}
private DavResource processRepository( final DavServletRequest request, ArchivaDavResourceLocator archivaLocator, private DavResource processRepository( final DavServletRequest request, ArchivaDavResourceLocator archivaLocator,
String activePrincipal, ManagedRepositoryContent managedRepositoryContent, String activePrincipal, ManagedRepositoryContent managedRepositoryContent,
ManagedRepository managedRepository ) ManagedRepository managedRepository )
@ -535,7 +557,8 @@ public class ArchivaDavResourceFactory
DavResource resource = null; DavResource resource = null;
if ( isAuthorized( request, managedRepositoryContent.getId() ) ) if ( isAuthorized( request, managedRepositoryContent.getId() ) )
{ {
String path = getLogicalResource( archivaLocator, managedRepository, false ); // Maven Centric part ask evaluation if -SNAPSHOT
String path = evaluatePathWithVersion(archivaLocator, managedRepositoryContent);
if ( path.startsWith( "/" ) ) if ( path.startsWith( "/" ) )
{ {
path = path.substring( 1 ); path = path.substring( 1 );

View File

@ -91,7 +91,9 @@
org.apache.archiva.model, org.apache.archiva.model,
org.apache.archiva.policies, org.apache.archiva.policies,
org.apache.archiva.repository, org.apache.archiva.repository,
org.apache.archiva.admin.model.beans org.apache.archiva.admin.model.beans,
org.apache.archiva.repository.layout,
org.apache.archiva.xml
</Import-Package> </Import-Package>
</instructions> </instructions>
</configuration> </configuration>

View File

@ -27,6 +27,8 @@ import org.apache.archiva.metadata.repository.filter.Filter;
import org.apache.archiva.model.ArtifactReference; import org.apache.archiva.model.ArtifactReference;
import org.apache.archiva.policies.ProxyDownloadException; import org.apache.archiva.policies.ProxyDownloadException;
import org.apache.archiva.repository.ManagedRepositoryContent; import org.apache.archiva.repository.ManagedRepositoryContent;
import org.apache.archiva.repository.layout.LayoutException;
import org.apache.archiva.xml.XMLException;
import java.util.Collection; import java.util.Collection;
@ -70,4 +72,9 @@ public interface RepositoryStorage
* @since 2.0.0 * @since 2.0.0
*/ */
String getFilePath( String requestPath, ManagedRepository managedRepository ); String getFilePath( String requestPath, ManagedRepository managedRepository );
String getFilePathWithVersion( final String requestPath, ManagedRepositoryContent managedRepositoryContent )
throws LayoutException, XMLException;
} }

View File

@ -35,6 +35,7 @@ import org.apache.archiva.maven2.metadata.MavenMetadataReader;
import org.apache.archiva.metadata.model.ArtifactMetadata; import org.apache.archiva.metadata.model.ArtifactMetadata;
import org.apache.archiva.metadata.model.ProjectMetadata; import org.apache.archiva.metadata.model.ProjectMetadata;
import org.apache.archiva.metadata.model.ProjectVersionMetadata; import org.apache.archiva.metadata.model.ProjectVersionMetadata;
import org.apache.archiva.metadata.repository.RepositorySessionFactory;
import org.apache.archiva.metadata.repository.filter.Filter; import org.apache.archiva.metadata.repository.filter.Filter;
import org.apache.archiva.metadata.repository.storage.ReadMetadataRequest; import org.apache.archiva.metadata.repository.storage.ReadMetadataRequest;
import org.apache.archiva.metadata.repository.storage.RepositoryPathTranslator; import org.apache.archiva.metadata.repository.storage.RepositoryPathTranslator;
@ -50,6 +51,8 @@ import org.apache.archiva.proxy.common.WagonFactory;
import org.apache.archiva.proxy.model.RepositoryProxyConnectors; import org.apache.archiva.proxy.model.RepositoryProxyConnectors;
import org.apache.archiva.reports.RepositoryProblemFacet; import org.apache.archiva.reports.RepositoryProblemFacet;
import org.apache.archiva.repository.ManagedRepositoryContent; import org.apache.archiva.repository.ManagedRepositoryContent;
import org.apache.archiva.repository.content.PathParser;
import org.apache.archiva.repository.layout.LayoutException;
import org.apache.archiva.xml.XMLException; import org.apache.archiva.xml.XMLException;
import org.apache.commons.lang.ArrayUtils; import org.apache.commons.lang.ArrayUtils;
import org.apache.commons.lang.StringUtils; import org.apache.commons.lang.StringUtils;
@ -131,6 +134,10 @@ public class Maven2RepositoryStorage
@Inject @Inject
private ApplicationContext applicationContext; private ApplicationContext applicationContext;
@Inject
@Named ( value = "pathParser#default")
private PathParser pathParser;
private static final Logger log = LoggerFactory.getLogger( Maven2RepositoryStorage.class ); private static final Logger log = LoggerFactory.getLogger( Maven2RepositoryStorage.class );
private static final String METADATA_FILENAME_START = "maven-metadata"; private static final String METADATA_FILENAME_START = "maven-metadata";
@ -757,6 +764,34 @@ public class Maven2RepositoryStorage
} }
public String getFilePathWithVersion( final String requestPath, ManagedRepositoryContent managedRepositoryContent )
throws LayoutException, XMLException
{
String requestPathNoRepository = removePrefix( requestPath );
ArtifactReference artifactReference = pathParser.toArtifactReference( requestPathNoRepository );
String filePath = getFilePath( requestPath, managedRepositoryContent.getRepository() );
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 ) );
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 );
}
return filePath;
}
//----------------------------- //-----------------------------
@ -1002,4 +1037,13 @@ public class Maven2RepositoryStorage
} }
public PathParser getPathParser()
{
return pathParser;
}
public void setPathParser( PathParser pathParser )
{
this.pathParser = pathParser;
}
} }