includePom in index search results configurable: false by default

git-svn-id: https://svn.apache.org/repos/asf/archiva/trunk@1203376 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Olivier Lamy 2011-11-17 21:29:44 +00:00
parent 6eb766e9d9
commit 988f8b45f3
7 changed files with 83 additions and 34 deletions

View File

@ -124,7 +124,7 @@ public class NexusRepositorySearch
// we retun only artifacts without classifier in quick search, olamy cannot find a way to say with this field empty // we retun only artifacts without classifier in quick search, olamy cannot find a way to say with this field empty
// FIXME cannot find a way currently to setup this in constructQuery !!! // FIXME cannot find a way currently to setup this in constructQuery !!!
return search( limits, q, indexingContextIds, NoClassifierArtifactInfoFiler.LIST, principal, selectedRepos ); return search( limits, q, indexingContextIds, NoClassifierArtifactInfoFiler.LIST, selectedRepos, false );
} }
@ -235,13 +235,13 @@ public class NexusRepositorySearch
throw new RepositorySearchException( "No search fields set." ); throw new RepositorySearchException( "No search fields set." );
} }
return search( limits, q, indexingContextIds, Collections.<ArtifactInfoFiler>emptyList(), principal, return search( limits, q, indexingContextIds, Collections.<ArtifactInfoFiler>emptyList(),
searchFields.getRepositories() ); searchFields.getRepositories(), searchFields.isIncludePomArtifacts() );
} }
private SearchResults search( SearchResultLimits limits, BooleanQuery q, List<String> indexingContextIds, private SearchResults search( SearchResultLimits limits, BooleanQuery q, List<String> indexingContextIds,
List<? extends ArtifactInfoFiler> filters, String principal, List<? extends ArtifactInfoFiler> filters,
List<String> selectedRepos ) List<String> selectedRepos, boolean includePoms)
throws RepositorySearchException throws RepositorySearchException
{ {
@ -259,7 +259,7 @@ public class NexusRepositorySearch
return results; return results;
} }
return convertToSearchResults( response, limits, filters, principal, selectedRepos ); return convertToSearchResults( response, limits, filters, selectedRepos, includePoms );
} }
catch ( IOException e ) catch ( IOException e )
{ {
@ -449,7 +449,7 @@ public class NexusRepositorySearch
private SearchResults convertToSearchResults( FlatSearchResponse response, SearchResultLimits limits, private SearchResults convertToSearchResults( FlatSearchResponse response, SearchResultLimits limits,
List<? extends ArtifactInfoFiler> artifactInfoFilers, List<? extends ArtifactInfoFiler> artifactInfoFilers,
String principal, List<String> selectedRepos ) List<String>selectedRepos, boolean includePoms)
throws RepositoryAdminException throws RepositoryAdminException
{ {
SearchResults results = new SearchResults(); SearchResults results = new SearchResults();
@ -457,7 +457,7 @@ public class NexusRepositorySearch
for ( ArtifactInfo artifactInfo : artifactInfos ) for ( ArtifactInfo artifactInfo : artifactInfos )
{ {
if ( StringUtils.equalsIgnoreCase( "pom", artifactInfo.fextension ) ) if ( StringUtils.equalsIgnoreCase( "pom", artifactInfo.fextension ) && !includePoms )
{ {
continue; continue;
} }
@ -500,6 +500,7 @@ public class NexusRepositorySearch
hit.setPrefix( artifactInfo.prefix ); hit.setPrefix( artifactInfo.prefix );
hit.setPackaging( artifactInfo.packaging ); hit.setPackaging( artifactInfo.packaging );
hit.setClassifier( artifactInfo.classifier ); hit.setClassifier( artifactInfo.classifier );
hit.setFileExtension( artifactInfo.fextension );
hit.setUrl( getBaseUrl( artifactInfo, selectedRepos ) ); hit.setUrl( getBaseUrl( artifactInfo, selectedRepos ) );
} }

View File

@ -29,7 +29,7 @@ import java.util.Set;
public interface RepositorySearch public interface RepositorySearch
{ {
/** /**
* Quick search. * Quick search by won't return artifact with file extension pom
* *
* @param principal * @param principal
* @param selectedRepos * @param selectedRepos

View File

@ -97,6 +97,12 @@ public class SearchFields
*/ */
private String bundleExportService; private String bundleExportService;
/**
* not return artifact with file extension pom
* @since 1.4-M2
*/
private boolean includePomArtifacts = false;
private String classifier; private String classifier;
public SearchFields() public SearchFields()
@ -246,6 +252,16 @@ public class SearchFields
this.bundleName = bundleName; this.bundleName = bundleName;
} }
public boolean isIncludePomArtifacts()
{
return includePomArtifacts;
}
public void setIncludePomArtifacts( boolean includePomArtifacts )
{
this.includePomArtifacts = includePomArtifacts;
}
@Override @Override
public String toString() public String toString()
{ {
@ -263,6 +279,7 @@ public class SearchFields
sb.append( ", bundleImportPackage='" ).append( bundleImportPackage ).append( '\'' ); sb.append( ", bundleImportPackage='" ).append( bundleImportPackage ).append( '\'' );
sb.append( ", bundleName='" ).append( bundleName ).append( '\'' ); sb.append( ", bundleName='" ).append( bundleName ).append( '\'' );
sb.append( ", bundleExportService='" ).append( bundleExportService ).append( '\'' ); sb.append( ", bundleExportService='" ).append( bundleExportService ).append( '\'' );
sb.append( ", includePomArtifacts=" ).append( includePomArtifacts );
sb.append( ", classifier='" ).append( classifier ).append( '\'' ); sb.append( ", classifier='" ).append( classifier ).append( '\'' );
sb.append( '}' ); sb.append( '}' );
return sb.toString(); return sb.toString();

View File

@ -129,6 +129,12 @@ public class SearchResultHit
private String classifier; private String classifier;
/**
* file extension of the search result
* @since 1.4-M2
*/
private String fileExtension;
public String getContext() public String getContext()
{ {
return context; return context;
@ -344,6 +350,16 @@ public class SearchResultHit
this.classifier = classifier; this.classifier = classifier;
} }
public String getFileExtension()
{
return fileExtension;
}
public void setFileExtension( String fileExtension )
{
this.fileExtension = fileExtension;
}
@Override @Override
public String toString() public String toString()
{ {
@ -369,6 +385,7 @@ public class SearchResultHit
sb.append( ", bundleImportPackage='" ).append( bundleImportPackage ).append( '\'' ); sb.append( ", bundleImportPackage='" ).append( bundleImportPackage ).append( '\'' );
sb.append( ", bundleRequireBundle='" ).append( bundleRequireBundle ).append( '\'' ); sb.append( ", bundleRequireBundle='" ).append( bundleRequireBundle ).append( '\'' );
sb.append( ", classifier='" ).append( classifier ).append( '\'' ); sb.append( ", classifier='" ).append( classifier ).append( '\'' );
sb.append( ", fileExtension='" ).append( fileExtension ).append( '\'' );
sb.append( '}' ); sb.append( '}' );
return sb.toString(); return sb.toString();
} }

View File

@ -127,6 +127,12 @@ public class Artifact
private String packaging; private String packaging;
/**
* file extension of the search result
* @since 1.4-M2
*/
private String fileExtension;
public Artifact() public Artifact()
{ {
@ -334,6 +340,15 @@ public class Artifact
this.packaging = packaging; this.packaging = packaging;
} }
public String getFileExtension()
{
return fileExtension;
}
public void setFileExtension( String fileExtension )
{
this.fileExtension = fileExtension;
}
@Override @Override
public String toString() public String toString()
@ -360,6 +375,7 @@ public class Artifact
sb.append( ", bundleRequireBundle='" ).append( bundleRequireBundle ).append( '\'' ); sb.append( ", bundleRequireBundle='" ).append( bundleRequireBundle ).append( '\'' );
sb.append( ", classifier='" ).append( classifier ).append( '\'' ); sb.append( ", classifier='" ).append( classifier ).append( '\'' );
sb.append( ", packaging='" ).append( packaging ).append( '\'' ); sb.append( ", packaging='" ).append( packaging ).append( '\'' );
sb.append( ", fileExtension='" ).append( fileExtension ).append( '\'' );
sb.append( '}' ); sb.append( '}' );
return sb.toString(); return sb.toString();
} }

View File

@ -86,6 +86,12 @@ public class SearchRequest
private String classifier; private String classifier;
/**
* not return artifact with file extension pom
* @since 1.4-M2
*/
private boolean includePomArtifacts = false;
public SearchRequest() public SearchRequest()
{ {
// no op // no op
@ -213,6 +219,16 @@ public class SearchRequest
this.classifier = classifier; this.classifier = classifier;
} }
public boolean isIncludePomArtifacts()
{
return includePomArtifacts;
}
public void setIncludePomArtifacts( boolean includePomArtifacts )
{
this.includePomArtifacts = includePomArtifacts;
}
@Override @Override
public String toString() public String toString()
{ {
@ -229,6 +245,7 @@ public class SearchRequest
sb.append( ", bundleExportPackage='" ).append( bundleExportPackage ).append( '\'' ); sb.append( ", bundleExportPackage='" ).append( bundleExportPackage ).append( '\'' );
sb.append( ", bundleExportService='" ).append( bundleExportService ).append( '\'' ); sb.append( ", bundleExportService='" ).append( bundleExportService ).append( '\'' );
sb.append( ", classifier='" ).append( classifier ).append( '\'' ); sb.append( ", classifier='" ).append( classifier ).append( '\'' );
sb.append( ", includePomArtifacts=" ).append( includePomArtifacts );
sb.append( '}' ); sb.append( '}' );
return sb.toString(); return sb.toString();
} }

View File

@ -229,31 +229,6 @@ public class DefaultSearchService
{ {
for ( String version : hit.getVersions() ) for ( String version : hit.getVersions() )
{ {
/*
Artifact versionned = new Artifact( );
versionned.setArtifactId( hit.getArtifactId());
versionned.setGroupId( hit.getGroupId() );
versionned.setRepositoryId(hit.getRepositoryId() );
versionned.setBundleExportPackage( hit.getBundleExportPackage() );
versionned.setBundleExportService( hit.getBundleExportService());
versionned.setBundleSymbolicName(hit.getBundleSymbolicName() );
versionned.setBundleVersion( artifactInfo.bundleVersion );
versionned.setBundleDescription( artifactInfo.bundleDescription );
versionned.setBundleDocUrl( artifactInfo.bundleDocUrl );
versionned.setBundleRequireBundle( artifactInfo.bundleRequireBundle );
versionned.setBundleImportPackage( artifactInfo.bundleImportPackage );
versionned.setBundleLicense( artifactInfo.bundleLicense );
versionned.setBundleName( artifactInfo.bundleName );
versionned.setContext( artifactInfo.context );
versionned.setGoals( artifactInfo.goals );
versionned.setPrefix( artifactInfo.prefix );
// sure ??
versionned.setUrl( artifactInfo.remoteUrl );
*/
// FIXME archiva url ??
Artifact versionned = new BeanReplicator().replicateBean( hit, Artifact.class ); Artifact versionned = new BeanReplicator().replicateBean( hit, Artifact.class );
@ -271,6 +246,12 @@ public class DefaultSearchService
return artifacts; return artifacts;
} }
/**
* TODO add a configuration mechanism to have configured the base archiva url
* @param httpContext
* @param artifact
* @return
*/
private String getArtifactUrl( HttpContext httpContext, Artifact artifact ) private String getArtifactUrl( HttpContext httpContext, Artifact artifact )
{ {
if ( httpContext == null ) if ( httpContext == null )