Skip to content

Commit 7bbf59a

Browse files
HegedusI-Iege
authored andcommitted
add file list to readme
1 parent de63056 commit 7bbf59a

11 files changed

Lines changed: 179 additions & 12 deletions

File tree

README.md

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,16 @@ for (RepositorySummary repoSummary : artifactory.storage().getStorageInfo().getR
191191
##### Getting Items
192192
```
193193
ItemHandle fileItem = artifactory.repository("RepoName").file("path/to/file.txt");
194-
ItemHandle folderItem = artifactory.repository("RepoName").folder("path/to/folder");
194+
FolderHandle folderItem = artifactory.repository("RepoName").folder("path/to/folder");
195+
```
196+
197+
##### Getting All Items Under A Folder
198+
```
199+
FolderHandle folder = artifactory.repository("RepoName").folder("path/to/folder");
200+
boolean deep = true;
201+
boolean listFolders = true;
202+
boolean timeStamps = true;
203+
FileList list = folder.list(deep, listFolders, timeStamps);
195204
```
196205

197206
##### Copying Items
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
package org.jfrog.artifactory.client;
2+
3+
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
4+
import org.jfrog.artifactory.client.model.FileList;
5+
6+
@JsonIgnoreProperties(ignoreUnknown = true)
7+
public interface FolderHandle extends ItemHandle {
8+
FileList list(boolean deep, boolean listFolders, boolean timestamps);
9+
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
@JsonIgnoreProperties(ignoreUnknown = true)
1717
public interface RepositoryHandle {
1818

19-
ItemHandle folder(String folderName);
19+
FolderHandle folder(String folderName);
2020

2121
ItemHandle file(String filePath);
2222

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
package org.jfrog.artifactory.client.model;
2+
3+
import java.util.List;
4+
5+
public interface FileList {
6+
7+
int size();
8+
List<ListItem> getFiles();
9+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
package org.jfrog.artifactory.client.model;
2+
3+
import java.util.Date;
4+
5+
public interface ListItem {
6+
String getUri();
7+
Long getSize();
8+
Date getLastModified();
9+
Boolean isFolder();
10+
String getSha1();
11+
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
package org.jfrog.artifactory.client.impl
2+
3+
import org.jfrog.artifactory.client.FolderHandle
4+
import org.jfrog.artifactory.client.model.FileList
5+
import org.jfrog.artifactory.client.model.impl.FileListImpl
6+
7+
class FolderHandleImpl extends ItemHandleImpl implements FolderHandle {
8+
9+
private String baseApiPath
10+
11+
private ArtifactoryImpl artifactory
12+
private String repo
13+
private String path
14+
15+
FolderHandleImpl(ArtifactoryImpl artifactory, String baseApiPath, String repo, String path, Class itemType) {
16+
super(artifactory, baseApiPath, repo, path, itemType)
17+
this.artifactory = artifactory
18+
this.repo = repo
19+
this.path = path
20+
this.baseApiPath = baseApiPath
21+
}
22+
23+
FileList list(boolean deep, boolean listFolders, boolean timestamps) {
24+
String deepInt = toInt(deep)
25+
String listFoldersInt = toInt(listFolders)
26+
String timestampsInt = toInt(timestamps)
27+
String url = baseApiPath + "/storage/$repo/$path?list&deep=$deepInt&listFolders=$listFoldersInt&mdTimestamps=$timestampsInt"
28+
return artifactory.get(url, FileListImpl, FileList)
29+
}
30+
31+
private static String toInt(boolean b) {
32+
return b?"1":"0"
33+
}
34+
35+
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,8 @@ class RepositoryHandleImpl implements RepositoryHandle {
4040

4141
//TODO: [by yl] Use a FileHandler and a FolderHandler instead or returning Items
4242
@Override
43-
ItemHandle folder(String folderName) {
44-
new ItemHandleImpl(artifactory, baseApiPath, repoKey, folderName, FolderImpl)
43+
FolderHandle folder(String folderName) {
44+
new FolderHandleImpl(artifactory, baseApiPath, repoKey, folderName, FolderImpl)
4545
}
4646

4747
@Override
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
package org.jfrog.artifactory.client.model.impl;
2+
3+
import org.jfrog.artifactory.client.model.FileList;
4+
import org.jfrog.artifactory.client.model.ListItem;
5+
6+
import java.util.Arrays;
7+
import java.util.Date;
8+
import java.util.List;
9+
10+
public class FileListImpl implements FileList {
11+
12+
String uri;
13+
Date created;
14+
ListItemImpl[] files;
15+
16+
FileListImpl(String uri, Date created, ListItemImpl[] files) {
17+
this.uri = uri;
18+
this.created = created;
19+
this.files = files;
20+
}
21+
22+
public FileListImpl() {
23+
}
24+
25+
@Override
26+
public int size() {
27+
return files.length;
28+
}
29+
30+
@Override
31+
public List<ListItem> getFiles() {
32+
return Arrays.asList(files);
33+
}
34+
}
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
package org.jfrog.artifactory.client.model.impl;
2+
3+
import org.jfrog.artifactory.client.model.ListItem;
4+
5+
import java.util.Date;
6+
7+
public class ListItemImpl implements ListItem {
8+
String uri;
9+
Long size;
10+
Date lastModified;
11+
Boolean folder;
12+
String sha1;
13+
14+
ListItemImpl(String uri, Long size, Date lastModified, Boolean folder) {
15+
this.uri = uri;
16+
this.size = size;
17+
this.lastModified = lastModified;
18+
this.folder = folder;
19+
}
20+
21+
ListItemImpl() {
22+
}
23+
24+
@Override
25+
public String getUri() {
26+
return uri;
27+
}
28+
29+
@Override
30+
public Long getSize() {
31+
return size;
32+
}
33+
34+
@Override
35+
public Date getLastModified() {
36+
return lastModified;
37+
}
38+
39+
@Override
40+
public Boolean isFolder() {
41+
return folder;
42+
}
43+
44+
@Override
45+
public String getSha1() {
46+
return sha1;
47+
}
48+
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
version=2.9.1
1+
version=2.9.x-SNAPSHOT

0 commit comments

Comments
 (0)