Skip to content
This repository was archived by the owner on Apr 25, 2024. It is now read-only.

Commit 51f9d78

Browse files
committed
Adding additional parameter for artifact search
1 parent 91b979d commit 51f9d78

4 files changed

Lines changed: 26 additions & 9 deletions

File tree

archiva-modules/archiva-base/archiva-indexer/src/main/java/org/apache/archiva/indexer/search/MavenRepositorySearch.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -182,8 +182,8 @@ public SearchResults search( String principal, SearchFields searchFields, Search
182182

183183
if ( StringUtils.isNotBlank( searchFields.getVersion() ) )
184184
{
185-
q.add( indexer.constructQuery( MAVEN.VERSION, searchFields.isExactSearch() ? new SourcedSearchExpression(
186-
searchFields.getVersion() ) : new SourcedSearchExpression( searchFields.getVersion() ) ), Occur.MUST );
185+
q.add( indexer.constructQuery( MAVEN.VERSION, new SourcedSearchExpression(
186+
searchFields.getVersion( ) ) ), Occur.MUST );
187187
}
188188

189189
if ( StringUtils.isNotBlank( searchFields.getPackaging() ) )

archiva-modules/archiva-web/archiva-rest/archiva-rest-api/src/main/java/org/apache/archiva/rest/api/services/SearchService.java

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
import org.apache.archiva.rest.api.model.SearchRequest;
2828
import org.apache.archiva.rest.api.model.StringList;
2929

30+
import javax.ws.rs.DefaultValue;
3031
import javax.ws.rs.GET;
3132
import javax.ws.rs.POST;
3233
import javax.ws.rs.Path;
@@ -120,7 +121,21 @@ List<Dependency> getDependencies( @QueryParam( "groupId" ) String groupId,
120121
throws ArchivaRestServiceException;
121122
*/
122123

123-
124+
/**
125+
* Returns a redirect to a artifact file, that matches given search parameter
126+
* @param repositoryId The repository id (optional)
127+
* @param groupId The search pattern for the group id of the artifact (required)
128+
* @param artifactId The search pattern for the artifact id of the artifact (required)
129+
* @param version The search pattern for the version of the artifact (required)
130+
* LATEST returns the latest version of the artifact.
131+
* @param packaging the packaging
132+
* @param classifier the artifact classifier
133+
* @param literalVersion true, if the version string should be treated literally, which means
134+
* LATEST search for versions with LATEST in the version string.
135+
* false, is default and treats v=LATEST special
136+
* @return the redirect response, if a artifact was found
137+
* @throws ArchivaRestServiceException
138+
*/
124139
@GET
125140
@Path( "/artifact" )
126141
@Produces( "text/html" )
@@ -130,7 +145,9 @@ Response redirectToArtifactFile( @QueryParam( "r" ) String repositoryId, //
130145
@QueryParam( "a" ) String artifactId, //
131146
@QueryParam( "v" ) String version, //
132147
@QueryParam( "p" ) String packaging, //
133-
@QueryParam( "c" ) String classifier )
148+
@QueryParam( "c" ) String classifier,
149+
@DefaultValue( "false" )
150+
@QueryParam( "literalVersion" ) Boolean literalVersion)
134151
throws ArchivaRestServiceException;
135152

136153

archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/DefaultSearchService.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,7 @@ public StringList getObservablesRepoIds()
255255

256256
@Override
257257
public Response redirectToArtifactFile( String repositoryId, String groupId, String artifactId, String version,
258-
String packaging, String classifier )
258+
String packaging, String classifier, Boolean literalVersion )
259259
throws ArchivaRestServiceException
260260
{
261261
try
@@ -338,7 +338,7 @@ public String getReasonPhrase()
338338
searchField.setGroupId( groupId );
339339
searchField.setArtifactId( artifactId );
340340
searchField.setPackaging( StringUtils.isBlank( packaging ) ? "jar" : packaging );
341-
if ( !StringUtils.equals( version, LATEST_KEYWORD ) )
341+
if ( literalVersion.booleanValue() || !StringUtils.equals( version, LATEST_KEYWORD ) )
342342
{
343343
searchField.setVersion( version );
344344
}

archiva-modules/archiva-web/archiva-web-common/src/test/java/org/apache/archiva/remotedownload/DownloadArtifactFromQueryTest.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ public void downloadFixedVersion()
135135
{
136136
Response response =
137137
getSearchService().redirectToArtifactFile( null, "org.apache.archiva", "archiva-test", "1.0", null,
138-
null );
138+
null, Boolean.FALSE );
139139

140140
}
141141
catch ( RedirectionException e )
@@ -163,7 +163,7 @@ public void downloadLatestVersion()
163163
{
164164
Response response =
165165
getSearchService().redirectToArtifactFile( null, "org.apache.archiva", "archiva-test", "LATEST", null,
166-
null );
166+
null , Boolean.FALSE);
167167

168168
}
169169
catch ( RedirectionException e )
@@ -190,7 +190,7 @@ public void download_no_content()
190190
{
191191
Response response =
192192
getSearchService().redirectToArtifactFile( null, "org.apache.archiva.beer", "archiva-wine", "LATEST",
193-
null, null );
193+
null, null, Boolean.FALSE );
194194

195195
Assert.assertEquals( Response.Status.NO_CONTENT.getStatusCode(), response.getStatus() );
196196

0 commit comments

Comments
 (0)