hit.setGoals( artifactInfo.goals );
hit.setPrefix( artifactInfo.prefix );
hit.setPackaging( artifactInfo.packaging );
+ hit.setClassifier( artifactInfo.classifier );
// sure ??
hit.setUrl( artifactInfo.remoteUrl );
}
private String classifier;
+ private String packaging;
+
public Artifact()
{
this.classifier = classifier;
}
+
+ public String getPackaging()
+ {
+ return packaging;
+ }
+
+ public void setPackaging( String packaging )
+ {
+ this.packaging = packaging;
+ }
+
+
@Override
public String toString()
{
sb.append( ", bundleImportPackage='" ).append( bundleImportPackage ).append( '\'' );
sb.append( ", bundleRequireBundle='" ).append( bundleRequireBundle ).append( '\'' );
sb.append( ", classifier='" ).append( classifier ).append( '\'' );
+ sb.append( ", packaging='" ).append( packaging ).append( '\'' );
sb.append( '}' );
return sb.toString();
}
@Produces( { MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML, MediaType.TEXT_PLAIN } )
@RedbackAuthorization( noPermission = true, noRestriction = true )
List<Artifact> getArtifactVersions( @QueryParam( "groupId" ) String groupId,
- @QueryParam( "artifactId" ) String artifactId )
+ @QueryParam( "artifactId" ) String artifactId,
+ @QueryParam( "packaging" ) String packaging )
throws ArchivaRestServiceException;
@Path( "searchArtifacts" )
import org.apache.archiva.rest.api.model.SearchRequest;
import org.apache.archiva.rest.api.services.ArchivaRestServiceException;
import org.apache.archiva.rest.api.services.SearchService;
+import org.apache.archiva.rest.services.searchfilter.ArtifactFiler;
+import org.apache.archiva.rest.services.searchfilter.NoClassifierArtifactFiler;
import org.apache.archiva.security.AccessDeniedException;
import org.apache.archiva.security.ArchivaSecurityException;
import org.apache.archiva.security.PrincipalNotFoundException;
SearchResults searchResults =
repositorySearch.search( getPrincipal(), getObservableRepos(), queryString, limits,
Collections.<String>emptyList() );
- return getArtifacts( searchResults );
+ return getArtifacts( searchResults, new ArrayList<ArtifactFiler>( NoClassifierArtifactFiler.LIST ) );
+
}
catch ( RepositorySearchException e )
{
}
}
- public List<Artifact> getArtifactVersions( String groupId, String artifactId )
+ public List<Artifact> getArtifactVersions( String groupId, String artifactId, String packaging )
throws ArchivaRestServiceException
{
if ( StringUtils.isBlank( groupId ) || StringUtils.isBlank( artifactId ) )
SearchFields searchField = new SearchFields();
searchField.setGroupId( groupId );
searchField.setArtifactId( artifactId );
- SearchResultLimits limits = new SearchResultLimits( 0 );
+ searchField.setPackaging( StringUtils.isBlank( packaging ) ? "jar" : packaging );
try
{
- SearchResults searchResults = repositorySearch.search( getPrincipal(), searchField, limits );
- return getArtifacts( searchResults );
+ SearchResults searchResults = repositorySearch.search( getPrincipal(), searchField, null );
+ return getArtifacts( searchResults, Collections.<ArtifactFiler>emptyList() );
}
catch ( RepositorySearchException e )
{
try
{
SearchResults searchResults = repositorySearch.search( getPrincipal(), searchField, limits );
- return getArtifacts( searchResults );
+ return getArtifacts( searchResults, Collections.<ArtifactFiler>emptyList() );
}
catch ( RepositorySearchException e )
{
: redbackRequestInformation.getUser().getUsername() );
}
- protected List<Artifact> getArtifacts( SearchResults searchResults )
+ protected List<Artifact> getArtifacts( SearchResults searchResults, List<ArtifactFiler> artifactFilers )
{
if ( searchResults == null || searchResults.isEmpty() )
{
if ( StringUtils.isNotBlank( version ) )
{
versionned.setVersion( version );
- artifacts.add( versionned );
+ if ( applyFiltering( versionned, artifactFilers, artifacts ) )
+ {
+ artifacts.add( versionned );
+ }
}
}
}
}
return artifacts;
}
+
+ protected boolean applyFiltering( Artifact artifact, List<ArtifactFiler> artifactFilers, List<Artifact> artifacts )
+ {
+ if ( artifact == null )
+ {
+ return false;
+ }
+ if ( artifactFilers == null || artifactFilers.isEmpty() )
+ {
+ return true;
+ }
+ for ( ArtifactFiler filter : artifactFilers )
+ {
+ if ( !filter.addArtifactInResult( artifact, artifacts ) )
+ {
+ return false;
+ }
+ }
+ return true;
+ }
}
import org.junit.Test;
import java.io.File;
+import java.util.Date;
import java.util.List;
/**
List<Artifact> artifacts = searchService.quickSearch( "commons-logging" );
assertNotNull( artifacts );
- assertTrue( " empty results for commons-logging search", artifacts.size() == 6 );
+ assertTrue( " not 6 results for commons-logging search but " + artifacts.size() + ":" + artifacts,
+ artifacts.size() == 6 );
log.info( "artifacts for commons-logging size {} search {}", artifacts.size(), artifacts );
deleteTestRepo( testRepoId, targetRepo );
SearchService searchService = getSearchService( authorizationHeader );
- List<Artifact> artifacts = searchService.getArtifactVersions( "commons-logging", "commons-logging" );
+ List<Artifact> artifacts = searchService.getArtifactVersions( "commons-logging", "commons-logging", "jar" );
assertNotNull( artifacts );
- assertTrue( " empty results for commons-logging search", artifacts.size() == 6 );
+ assertTrue( " not 3 results for commons-logging search but " + artifacts.size() + ":" + artifacts,
+ artifacts.size() == 13 );
log.info( "artifacts for commons-logging size {} search {}", artifacts.size(), artifacts );
deleteTestRepo( testRepoId, targetRepo );
}
@Test
- public void searchWithSearchRequestGroupIdAndArtifactId()
+ public void searchWithSearchRequestGroupIdAndArtifactIdAndClassifier()
throws Exception
{
SearchService searchService = getSearchService( authorizationHeader );
- SearchRequest searchRequest = new SearchRequest( );
+ SearchRequest searchRequest = new SearchRequest();
searchRequest.setGroupId( "commons-logging" );
searchRequest.setArtifactId( "commons-logging" );
searchRequest.setClassifier( "sources" );
List<Artifact> artifacts = searchService.searchArtifacts( searchRequest );
assertNotNull( artifacts );
- assertTrue( " empty results for commons-logging search", artifacts.size() == 6 );
+ assertTrue( " not 2 results for commons-logging search but " + artifacts.size() + ":" + artifacts,
+ artifacts.size() == 2 );
log.info( "artifacts for commons-logging size {} search {}", artifacts.size(), artifacts );
deleteTestRepo( testRepoId, targetRepo );
private File createAndIndexRepo( String testRepoId )
throws Exception
{
+ if ( getManagedRepositoriesService( authorizationHeader ).getManagedRepository( testRepoId ) != null )
+ {
+ getManagedRepositoriesService( authorizationHeader ).deleteManagedRepository( testRepoId, true );
+ }
File targetRepo = new File( System.getProperty( "targetDir", "./target" ), "test-repo" );
cleanupFiles( targetRepo );
managedRepository.setName( "test repo" );
managedRepository.setLocation( targetRepo.getPath() );
+ managedRepository.setIndexDirectory( targetRepo.getPath() + "/index-" + Long.toString( new Date().getTime() ) );
ManagedRepositoriesService service = getManagedRepositoriesService( authorizationHeader );
service.addManagedRepository( managedRepository );
-
getRepositoriesService( authorizationHeader ).scanRepositoryNow( testRepoId, true );
return targetRepo;
}
- private void cleanupFiles(File targetRepo)
+ private void cleanupFiles( File targetRepo )
throws Exception
{