Skip to content

Commit 20b856a

Browse files
author
JFrog Pipelines Step
committed
Merge remote-tracking branch 'origin/dev'
2 parents 19b8cb5 + 62181a4 commit 20b856a

File tree

8 files changed

+103
-3
lines changed

8 files changed

+103
-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: 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 specific();
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
}

gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
currentVersion=2.19.1
1+
currentVersion=2.19.x-SNAPSHOT

release/pipelines.release.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ pipelines:
8787
8888
# Update next development version
8989
- git clean -fd
90-
- git checkout dev
90+
- git checkout dev -f
9191
- git merge origin/master
9292
- sed -i "s/\(currentVersion=\).*\$/\1${NEXT_DEVELOPMENT_VERSION}/" gradle.properties
9393
- git commit -am "[artifactory-release] Next development version [skipRun]"

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 specific() {
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: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,9 @@
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;
15+
import org.jfrog.artifactory.client.model.VirtualRepository;
1416
import org.jfrog.artifactory.client.model.repository.settings.impl.MavenRepositorySettingsImpl;
1517
import org.testng.annotations.AfterClass;
1618
import org.testng.annotations.BeforeClass;
@@ -20,7 +22,9 @@
2022
import java.io.InputStreamReader;
2123
import java.security.MessageDigest;
2224
import java.security.NoSuchAlgorithmException;
25+
import java.util.ArrayList;
2326
import java.util.Arrays;
27+
import java.util.Collection;
2428
import java.util.Properties;
2529

2630
import static org.apache.commons.codec.binary.Base64.encodeBase64;
@@ -48,11 +52,15 @@ public abstract class ArtifactoryTestsBase {
4852
protected String fileMd5;
4953
protected String fileSha1;
5054
protected LocalRepository localRepository;
55+
protected VirtualRepository virtualRepository;
56+
protected RemoteRepository remoteRepository;
5157
protected String federationUrl;
5258

5359
@BeforeClass
5460
public void init() throws IOException {
5561
String localRepositoryKey = "java-client-" + getClass().getSimpleName();
62+
String virtualRepositoryKey = "java-client-virtual-" + getClass().getSimpleName();
63+
String remoteRepositoryKey = "java-client-remote-" + getClass().getSimpleName();
5664
Properties props = new Properties();
5765
// This file is not in GitHub. Create your own in src/test/resources.
5866
InputStream inputStream = this.getClass().getResourceAsStream("/artifactory-client.properties");
@@ -76,6 +84,7 @@ public void init() throws IOException {
7684
.setPassword(password)
7785
.build();
7886
deleteRepoIfExists(localRepositoryKey);
87+
deleteRepoIfExists(virtualRepositoryKey);
7988
deleteRepoIfExists(getJCenterRepoName());
8089
localRepository = artifactory.repositories().builders().localRepositoryBuilder()
8190
.key(localRepositoryKey)
@@ -84,10 +93,34 @@ public void init() throws IOException {
8493
.propertySets(Arrays.asList("artifactory"))
8594
.build();
8695

96+
Collection<String> repositories = new ArrayList<>();
97+
repositories.add(localRepositoryKey);
98+
virtualRepository = artifactory.repositories().builders().virtualRepositoryBuilder()
99+
.key(virtualRepositoryKey)
100+
.description("new virtual repository")
101+
.repositorySettings(new MavenRepositorySettingsImpl())
102+
.repositories(repositories)
103+
.build();
104+
87105
if (!artifactory.repository(localRepository.getKey()).exists()) {
88106
artifactory.repositories().create(1, localRepository);
89107
}
90108

109+
if (!artifactory.repository(virtualRepository.getKey()).exists()) {
110+
artifactory.repositories().create(1, virtualRepository);
111+
}
112+
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+
91124
String jcenterRepoName = getJCenterRepoName();
92125
if (!artifactory.repository(jcenterRepoName).exists()) {
93126
Repository jcenter = artifactory.repositories().builders().remoteRepositoryBuilder()

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

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,34 @@ 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+
.specific()
198+
.doSearch();
199+
assertEquals(results.size(), 1);
200+
assertTrue(results.get(0).getItemPath().contains(artifactId + "-1.0.0-zip.jar"));
201+
}
202+
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+
189217
@Test
190218
public void testArtifactsCreatedSinceSearch() throws IOException {
191219
long startTime = System.currentTimeMillis() - 86400000L;

0 commit comments

Comments
 (0)