Skip to content

Commit 39c983b

Browse files
committed
added GAVC search for Virtual and Remote Repositories
1 parent 306a5cd commit 39c983b

File tree

5 files changed

+50
-3
lines changed

5 files changed

+50
-3
lines changed

README.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -368,6 +368,25 @@ for (RepoPath searchItem : searchItems) {
368368
}
369369
```
370370

371+
##### Searching Files by GAVC and Virtual or Remote Repository
372+
373+
```groovy
374+
List<RepoPath> results = artifactory.searches().artifactsByGavc()
375+
.groupId("com.example")
376+
.artifactId("com.example.test")
377+
.repositories("maven-libs-release")
378+
.specific()
379+
.doSearch();
380+
381+
for (RepoPath searchItem : searchItems) {
382+
String repoKey = searchItem.getRepoKey();
383+
String itemPath = searchItem.getItemPath();
384+
}
385+
```
386+
* From Artifactory version 7.37.9, the following
387+
&specific=true(default false)
388+
attribute was added to support virtual and remote repositories. See [here](https://jfrog.com/help/r/jfrog-rest-apis/usage-for-remote-and-virtual-repositories).
389+
371390
##### Searching Latest Version by GAVC and Repository
372391

373392
```groovy

api/src/main/java/org/jfrog/artifactory/client/Searches.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,6 @@ public interface Searches {
6363

6464
List<AqlItem> artifactsByFileSpec(FileSpec fileSpec);
6565

66-
Searches virtualOrRemote();
66+
Searches specific();
6767

6868
}

services/src/main/groovy/org/jfrog/artifactory/client/impl/SearchesImpl.groovy

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ class SearchesImpl implements Searches {
9797
}
9898

9999
@Override
100-
Searches virtualOrRemote() {
100+
Searches specific() {
101101
this.searchQuery << [specific: "true"]
102102
this
103103
}

services/src/test/java/org/jfrog/artifactory/client/ArtifactoryTestsBase.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import org.apache.http.impl.client.CloseableHttpClient;
1111
import org.apache.http.impl.client.HttpClients;
1212
import org.jfrog.artifactory.client.model.LocalRepository;
13+
import org.jfrog.artifactory.client.model.RemoteRepository;
1314
import org.jfrog.artifactory.client.model.Repository;
1415
import org.jfrog.artifactory.client.model.VirtualRepository;
1516
import org.jfrog.artifactory.client.model.repository.settings.impl.MavenRepositorySettingsImpl;
@@ -52,12 +53,14 @@ public abstract class ArtifactoryTestsBase {
5253
protected String fileSha1;
5354
protected LocalRepository localRepository;
5455
protected VirtualRepository virtualRepository;
56+
protected RemoteRepository remoteRepository;
5557
protected String federationUrl;
5658

5759
@BeforeClass
5860
public void init() throws IOException {
5961
String localRepositoryKey = "java-client-" + getClass().getSimpleName();
6062
String virtualRepositoryKey = "java-client-virtual-" + getClass().getSimpleName();
63+
String remoteRepositoryKey = "java-client-remote-" + getClass().getSimpleName();
6164
Properties props = new Properties();
6265
// This file is not in GitHub. Create your own in src/test/resources.
6366
InputStream inputStream = this.getClass().getResourceAsStream("/artifactory-client.properties");
@@ -107,6 +110,17 @@ public void init() throws IOException {
107110
artifactory.repositories().create(1, virtualRepository);
108111
}
109112

113+
remoteRepository = artifactory.repositories().builders().remoteRepositoryBuilder()
114+
.key(remoteRepositoryKey)
115+
.url("https://repo1.maven.org/maven2/")
116+
.description("new maven remote repository")
117+
.repositorySettings(new MavenRepositorySettingsImpl())
118+
.build();
119+
120+
if (!artifactory.repository(remoteRepository.getKey()).exists()) {
121+
artifactory.repositories().create(1, remoteRepository);
122+
}
123+
110124
String jcenterRepoName = getJCenterRepoName();
111125
if (!artifactory.repository(jcenterRepoName).exists()) {
112126
Repository jcenter = artifactory.repositories().builders().remoteRepositoryBuilder()

services/src/test/java/org/jfrog/artifactory/client/SearchTests.java

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -194,12 +194,26 @@ public void testSearchByGavcAndVirtualRepository() throws IOException {
194194
.version("1.0.0")
195195
.classifier("zip")
196196
.repositories(virtualRepository.getKey())
197-
.virtualOrRemote()
197+
.specific()
198198
.doSearch();
199199
assertEquals(results.size(), 1);
200200
assertTrue(results.get(0).getItemPath().contains(artifactId + "-1.0.0-zip.jar"));
201201
}
202202

203+
@Test
204+
public void testSearchByGavcAndRemoteRepository() throws IOException {
205+
List<RepoPath> results = artifactory.searches().artifactsByGavc()
206+
.groupId("antlr")
207+
.artifactId("antlr")
208+
.version("2.7.1")
209+
.classifier("jar")
210+
.repositories(remoteRepository.getKey())
211+
.specific()
212+
.doSearch();
213+
assertEquals(results.size(), 2);
214+
assertTrue(results.get(0).getItemPath().contains("antlr-2.7.1.jar"));
215+
}
216+
203217
@Test
204218
public void testArtifactsCreatedSinceSearch() throws IOException {
205219
long startTime = System.currentTimeMillis() - 86400000L;

0 commit comments

Comments
 (0)