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,
String activePrincipal, ManagedRepositoryContent managedRepositoryContent,
ManagedRepository managedRepository )
DavResource resource = null;
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( "/" ) )
{
path = path.substring( 1 );
import org.apache.archiva.metadata.model.ArtifactMetadata;
import org.apache.archiva.metadata.model.ProjectMetadata;
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.storage.ReadMetadataRequest;
import org.apache.archiva.metadata.repository.storage.RepositoryPathTranslator;
import org.apache.archiva.proxy.model.RepositoryProxyConnectors;
import org.apache.archiva.reports.RepositoryProblemFacet;
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.commons.lang.ArrayUtils;
import org.apache.commons.lang.StringUtils;
@Inject
private ApplicationContext applicationContext;
+ @Inject
+ @Named ( value = "pathParser#default")
+ private PathParser pathParser;
+
private static final Logger log = LoggerFactory.getLogger( Maven2RepositoryStorage.class );
private static final String METADATA_FILENAME_START = "maven-metadata";
}
+ 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;
+ }
+
//-----------------------------
}
+ public PathParser getPathParser()
+ {
+ return pathParser;
+ }
+
+ public void setPathParser( PathParser pathParser )
+ {
+ this.pathParser = pathParser;
+ }
}