Skip to content

Commit 31e6391

Browse files
committed
added GAVC search for Virtual and Remote Repositories
1 parent a958efb commit 31e6391

File tree

5 files changed

+49
-1
lines changed

5 files changed

+49
-1
lines changed

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,4 +62,7 @@ public interface Searches {
6262
PropertyFilters itemsByProperty();
6363

6464
List<AqlItem> artifactsByFileSpec(FileSpec fileSpec);
65+
66+
Searches virtualOrRemote();
67+
6568
}

api/src/main/java/org/jfrog/artifactory/client/model/SearchResultReport.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,17 @@
99
public class SearchResultReport {
1010

1111
private String uri;
12+
private String downloadUri;
1213
private String created;
1314

1415
public String getUri() {
1516
return uri;
1617
}
1718

19+
public String getDownloadUri() {
20+
return downloadUri;
21+
}
22+
1823
public String getCreated() {
1924
return created;
2025
}

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

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,12 @@ class SearchesImpl implements Searches {
9696
this
9797
}
9898

99+
@Override
100+
Searches virtualOrRemote() {
101+
this.searchQuery << [specific: "true"]
102+
this
103+
}
104+
99105
List<RepoPath> doSearch() {
100106
if (!searchUrl) {
101107
throw new IllegalArgumentException("Search url wasn't set. Please call one of the 'artifacts...' methods before calling 'search()'")
@@ -122,9 +128,15 @@ class SearchesImpl implements Searches {
122128
String path = Util.getQueryPath("?", query)
123129
SearchResultImpl searchResults = artifactory.get("${getSearcherApi()}$url$path", SearchResultImpl, SearchResult)
124130
List<RepoPath> pathList = new ArrayList<>();
131+
String fullPath;
125132
for (SearchResultReport searchResultReport : searchResults.getResults()) {
126133
String uri = searchResultReport.getUri();
127-
String fullPath = uri.split(baseApiPath + '/storage/')[1]
134+
if (uri == null) {
135+
uri = searchResultReport.getDownloadUri()
136+
fullPath = uri.split('/artifactory/')[1]
137+
} else {
138+
fullPath = uri.split(baseApiPath + '/storage/')[1]
139+
}
128140
String repo = fullPath.substring(0,fullPath.indexOf('/'))
129141
pathList.add(new RepoPathImpl(repo, fullPath - (repo + '/')))
130142
}

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

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
import org.apache.http.impl.client.HttpClients;
1212
import org.jfrog.artifactory.client.model.LocalRepository;
1313
import org.jfrog.artifactory.client.model.Repository;
14+
import org.jfrog.artifactory.client.model.VirtualRepository;
1415
import org.jfrog.artifactory.client.model.repository.settings.impl.MavenRepositorySettingsImpl;
1516
import org.testng.annotations.AfterClass;
1617
import org.testng.annotations.BeforeClass;
@@ -48,11 +49,13 @@ public abstract class ArtifactoryTestsBase {
4849
protected String fileMd5;
4950
protected String fileSha1;
5051
protected LocalRepository localRepository;
52+
protected VirtualRepository virtualRepository;
5153
protected String federationUrl;
5254

5355
@BeforeClass
5456
public void init() throws IOException {
5557
String localRepositoryKey = "java-client-" + getClass().getSimpleName();
58+
String virtualRepositoryKey = "java-client-virtual-" + getClass().getSimpleName();
5659
Properties props = new Properties();
5760
// This file is not in GitHub. Create your own in src/test/resources.
5861
InputStream inputStream = this.getClass().getResourceAsStream("/artifactory-client.properties");
@@ -76,6 +79,7 @@ public void init() throws IOException {
7679
.setPassword(password)
7780
.build();
7881
deleteRepoIfExists(localRepositoryKey);
82+
deleteRepoIfExists(virtualRepositoryKey);
7983
deleteRepoIfExists(getJCenterRepoName());
8084
localRepository = artifactory.repositories().builders().localRepositoryBuilder()
8185
.key(localRepositoryKey)
@@ -84,10 +88,20 @@ public void init() throws IOException {
8488
.propertySets(Arrays.asList("artifactory"))
8589
.build();
8690

91+
virtualRepository = artifactory.repositories().builders().virtualRepositoryBuilder()
92+
.key(virtualRepositoryKey)
93+
.description("new virtual repository")
94+
.repositorySettings(new MavenRepositorySettingsImpl())
95+
.build();
96+
8797
if (!artifactory.repository(localRepository.getKey()).exists()) {
8898
artifactory.repositories().create(1, localRepository);
8999
}
90100

101+
if (!artifactory.repository(virtualRepository.getKey()).exists()) {
102+
artifactory.repositories().create(1, virtualRepository);
103+
}
104+
91105
String jcenterRepoName = getJCenterRepoName();
92106
if (!artifactory.repository(jcenterRepoName).exists()) {
93107
Repository jcenter = artifactory.repositories().builders().remoteRepositoryBuilder()

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

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,20 @@ public void testSearchByGavcAndRepository() throws IOException {
186186
assertTrue(results.get(0).getItemPath().contains(artifactId + "-1.0.0-zip.jar"));
187187
}
188188

189+
@Test
190+
public void testSearchByGavcAndVirtualRepository() throws IOException {
191+
List<RepoPath> results = artifactory.searches().artifactsByGavc()
192+
.groupId("com.example")
193+
.artifactId(artifactId)
194+
.version("1.0.0")
195+
.classifier("zip")
196+
.repositories(virtualRepository.getKey())
197+
.virtualOrRemote()
198+
.doSearch();
199+
assertEquals(results.size(), 1);
200+
assertTrue(results.get(0).getItemPath().contains(artifactId + "-1.0.0-zip.jar"));
201+
}
202+
189203
@Test
190204
public void testArtifactsCreatedSinceSearch() throws IOException {
191205
long startTime = System.currentTimeMillis() - 86400000L;

0 commit comments

Comments
 (0)