[MRM-1668] download artifacts when coming from search results.

git-svn-id: https://svn.apache.org/repos/asf/archiva/trunk@1384563 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Olivier Lamy 2012-09-13 22:11:00 +00:00
parent 0638fbf4b1
commit bdb81fef28
7 changed files with 221 additions and 121 deletions

View File

@ -19,7 +19,6 @@ package org.apache.archiva.proxy;
* under the License.
*/
import com.google.common.collect.Lists;
import com.google.common.io.Files;
import org.apache.archiva.admin.model.RepositoryAdminException;
import org.apache.archiva.admin.model.beans.NetworkProxy;
@ -41,6 +40,9 @@ import org.apache.archiva.policies.ProxyDownloadException;
import org.apache.archiva.policies.urlcache.UrlFailureCache;
import org.apache.archiva.proxy.common.WagonFactory;
import org.apache.archiva.proxy.common.WagonFactoryException;
import org.apache.archiva.redback.components.registry.Registry;
import org.apache.archiva.redback.components.registry.RegistryListener;
import org.apache.archiva.redback.components.taskqueue.TaskQueueException;
import org.apache.archiva.repository.ManagedRepositoryContent;
import org.apache.archiva.repository.RemoteRepositoryContent;
import org.apache.archiva.repository.RepositoryContentFactory;
@ -64,9 +66,6 @@ import org.apache.maven.wagon.authentication.AuthenticationInfo;
import org.apache.maven.wagon.proxy.ProxyInfo;
import org.apache.maven.wagon.repository.Repository;
import org.apache.tools.ant.types.selectors.SelectorUtils;
import org.apache.archiva.redback.components.registry.Registry;
import org.apache.archiva.redback.components.registry.RegistryListener;
import org.apache.archiva.redback.components.taskqueue.TaskQueueException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;
@ -90,7 +89,6 @@ import java.util.concurrent.ConcurrentHashMap;
/**
* DefaultRepositoryProxyConnectors
*
*
* @todo exception handling needs work - "not modified" is not really an exceptional case, and it has more layers than
* your average brown onion
*/
@ -444,19 +442,17 @@ public class DefaultRepositoryProxyConnectors
}
catch ( NotFoundException e )
{
if ( log.isDebugEnabled() )
{
log.debug( "Metadata {} not found on remote repository \"{}\".",
Lists.<Object>newArrayList( logicalPath, targetRepository.getRepository().getId() ), e );
}
log.debug( "Metadata {} not found on remote repository '{}'.", logicalPath,
targetRepository.getRepository().getId(), e );
}
catch ( NotModifiedException e )
{
if ( log.isDebugEnabled() )
{
log.debug( "Metadata {} not updated on remote repository \"{}\".",
Lists.<Object>newArrayList( logicalPath, targetRepository.getRepository().getId() ), e );
}
log.debug( "Metadata {} not updated on remote repository '{}'.", logicalPath,
targetRepository.getRepository().getId(), e );
}
catch ( ProxyException e )
{

View File

@ -19,14 +19,14 @@ package org.apache.archiva.rest.api.services;
*/
import org.apache.archiva.admin.model.beans.ManagedRepository;
import org.apache.archiva.maven2.model.Artifact;
import org.apache.archiva.maven2.model.TreeEntry;
import org.apache.archiva.metadata.model.ProjectVersionMetadata;
import org.apache.archiva.redback.authorization.RedbackAuthorization;
import org.apache.archiva.maven2.model.Artifact;
import org.apache.archiva.rest.api.model.ArtifactContent;
import org.apache.archiva.rest.api.model.ArtifactContentEntry;
import org.apache.archiva.rest.api.model.BrowseResult;
import org.apache.archiva.rest.api.model.Entry;
import org.apache.archiva.maven2.model.TreeEntry;
import org.apache.archiva.rest.api.model.VersionsList;
import javax.ws.rs.DELETE;
@ -164,8 +164,7 @@ public interface BrowseService
@GET
@Produces ( { MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML } )
@RedbackAuthorization ( noPermission = true, noRestriction = true )
List<Artifact> getArtifactDownloadInfos( @PathParam( "g" ) String groupId,
@PathParam( "a" ) String artifactId,
List<Artifact> getArtifactDownloadInfos( @PathParam ( "g" ) String groupId, @PathParam ( "a" ) String artifactId,
@PathParam ( "v" ) String version,
@QueryParam ( "repositoryId" ) String repositoryId )
throws ArchivaRestServiceException;
@ -182,4 +181,16 @@ public interface BrowseService
@QueryParam ( "t" ) String type, @QueryParam ( "p" ) String path,
@QueryParam ( "repositoryId" ) String repositoryId )
throws ArchivaRestServiceException;
@Path ( "artifactAvailable/{g}/{a}/{v}" )
@GET
@Produces ( { MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML } )
@RedbackAuthorization ( noPermission = true, noRestriction = true )
/**
* verify if an artifact is available locally if not download from proxies will be try
* @since 1.4-M3
*/
Boolean artifactAvailable( @PathParam ( "g" ) String groupId, @PathParam ( "a" ) String artifactId,
@PathParam ( "v" ) String version, @QueryParam ( "repositoryId" ) String repositoryId )
throws ArchivaRestServiceException;
}

View File

@ -135,6 +135,10 @@
<groupId>org.apache.archiva</groupId>
<artifactId>archiva-rest-api</artifactId>
</dependency>
<dependency>
<groupId>org.apache.archiva</groupId>
<artifactId>archiva-proxy</artifactId>
</dependency>
<dependency>
<groupId>org.apache.archiva.redback</groupId>
<artifactId>redback-rest-services</artifactId>

View File

@ -22,6 +22,7 @@ package org.apache.archiva.rest.services;
import org.apache.archiva.admin.model.AuditInformation;
import org.apache.archiva.admin.model.RepositoryAdminException;
import org.apache.archiva.admin.model.admin.ArchivaAdministration;
import org.apache.archiva.admin.model.managed.ManagedRepositoryAdmin;
import org.apache.archiva.audit.AuditEvent;
import org.apache.archiva.audit.AuditListener;
import org.apache.archiva.common.utils.VersionUtil;
@ -77,6 +78,9 @@ public abstract class AbstractRestService
@Inject
protected ArchivaAdministration archivaAdministration;
@Inject
protected ManagedRepositoryAdmin managedRepositoryAdmin;
@Context
protected HttpServletRequest httpServletRequest;

View File

@ -18,8 +18,10 @@ package org.apache.archiva.rest.services;
* under the License.
*/
import org.apache.archiva.admin.model.RepositoryAdminException;
import org.apache.archiva.admin.model.beans.ManagedRepository;
import org.apache.archiva.common.utils.VersionComparator;
import org.apache.archiva.common.utils.VersionUtil;
import org.apache.archiva.dependency.tree.maven2.DependencyTreeBuilder;
import org.apache.archiva.maven2.model.Artifact;
import org.apache.archiva.maven2.model.TreeEntry;
@ -36,6 +38,7 @@ import org.apache.archiva.metadata.repository.RepositorySession;
import org.apache.archiva.metadata.repository.storage.maven2.ArtifactMetadataVersionComparator;
import org.apache.archiva.metadata.repository.storage.maven2.MavenProjectFacet;
import org.apache.archiva.model.ArchivaArtifact;
import org.apache.archiva.proxy.RepositoryProxyConnectors;
import org.apache.archiva.repository.ManagedRepositoryContent;
import org.apache.archiva.repository.RepositoryContentFactory;
import org.apache.archiva.repository.RepositoryException;
@ -58,6 +61,7 @@ import org.apache.commons.lang.StringUtils;
import org.springframework.stereotype.Service;
import javax.inject.Inject;
import javax.inject.Named;
import javax.ws.rs.core.Response;
import java.io.File;
import java.io.IOException;
@ -91,6 +95,10 @@ public class DefaultBrowseService
@Inject
private RepositoryContentFactory repositoryContentFactory;
@Inject
@Named ( value = "repositoryProxyConnectors#default" )
private RepositoryProxyConnectors connectors;
public BrowseResult getRootGroups( String repositoryId )
throws ArchivaRestServiceException
{
@ -268,7 +276,7 @@ public class DefaultBrowseService
}
catch ( MetadataResolutionException e )
{
log.error(
log.warn(
"Skipping invalid metadata while compiling shared model for " + groupId + ":" + artifactId
+ " in repo " + repoId + ": " + e.getMessage() );
}
@ -778,6 +786,70 @@ public class DefaultBrowseService
return new ArtifactContent();
}
public Boolean artifactAvailable( String groupId, String artifactId, String version, String repositoryId )
throws ArchivaRestServiceException
{
List<String> selectedRepos = getSelectedRepos( repositoryId );
try
{
for ( String repoId : selectedRepos )
{
ManagedRepository managedRepository = managedRepositoryAdmin.getManagedRepository( repoId );
boolean snapshot = VersionUtil.isSnapshot( version );
if ( ( snapshot && !managedRepository.isSnapshots() ) || ( !snapshot
&& managedRepository.isSnapshots() ) )
{
continue;
}
ManagedRepositoryContent managedRepositoryContent =
repositoryContentFactory.getManagedRepositoryContent( repoId );
// FIXME default to jar which can be wrong for war zip etc....
ArchivaArtifact archivaArtifact =
new ArchivaArtifact( groupId, artifactId, version, "", "jar", repoId );
File file = managedRepositoryContent.toFile( archivaArtifact );
if ( file != null && file.exists() )
{
return true;
}
String path = managedRepositoryContent.toPath( archivaArtifact );
file = connectors.fetchFromProxies( managedRepositoryContent, path );
if ( file != null && file.exists() )
{
// download pom now
String pomPath = StringUtils.substringBeforeLast( path, ".jar" ) + ".pom";
connectors.fetchFromProxies( managedRepositoryContent, pomPath );
return true;
}
}
}
catch ( RepositoryAdminException e )
{
log.error( e.getMessage(), e );
throw new ArchivaRestServiceException( e.getMessage(),
Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(), e );
}
catch ( RepositoryException e )
{
log.error( e.getMessage(), e );
throw new ArchivaRestServiceException( e.getMessage(),
Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(), e );
}
return false;
}
//---------------------------
// internals
//---------------------------
private void closeQuietly( JarFile jarFile )
{
if ( jarFile != null )
@ -793,10 +865,6 @@ public class DefaultBrowseService
}
}
//---------------------------
// internals
//---------------------------
protected List<ArtifactContentEntry> readFileEntries( File file, String filterPath, String repoId )
throws IOException
{

View File

@ -53,9 +53,6 @@ public class DefaultManagedRepositoriesService
implements ManagedRepositoriesService
{
@Inject
private ManagedRepositoryAdmin managedRepositoryAdmin;
@Inject
private RepositoryCommonValidator repositoryCommonValidator;

View File

@ -329,6 +329,21 @@ function(jquery,ui,sammy,tmpl) {
return;
}
}
var artifactAvailableUrl="restServices/archivaServices/browseService/artifactAvailable/"+encodeURIComponent(groupId)+"/"+encodeURIComponent(artifactId);
artifactAvailableUrl+="/"+encodeURIComponent(version);
var selectedRepo=getSelectedBrowsingRepository();
if (selectedRepo){
artifactAvailableUrl+="?repositoryId="+encodeURIComponent(selectedRepo);
}
$("#main-content").html( mediumSpinnerImg());
$.ajax(artifactAvailableUrl, {
type: "GET",
dataType: 'json',
success: function(data) {
// TODO take of the result true or false
//$.log("artifactAvailable:"+data);
generalDisplayArtifactDetailsVersionView(groupId,artifactId,version,repositoryId,
function(artifactVersionDetailViewModel){
$("#main-content #"+tabToActivate).tab('show');
@ -337,6 +352,11 @@ function(jquery,ui,sammy,tmpl) {
}
}
);
}
});
};
this.get('#artifact/:groupId/:artifactId/:version',function(context){