Skip to content

Commit

Permalink
add file list to readme
Browse files Browse the repository at this point in the history
  • Loading branch information
I-Iege authored and hege committed Feb 1, 2021
1 parent de63056 commit 42a5671
Show file tree
Hide file tree
Showing 11 changed files with 179 additions and 12 deletions.
11 changes: 10 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,16 @@ for (RepositorySummary repoSummary : artifactory.storage().getStorageInfo().getR
##### Getting Items
```
ItemHandle fileItem = artifactory.repository("RepoName").file("path/to/file.txt");
ItemHandle folderItem = artifactory.repository("RepoName").folder("path/to/folder");
FolderHandle folderItem = artifactory.repository("RepoName").folder("path/to/folder");
```

##### Getting All Items Under A Folder
```
FolderHandle folder = artifactory.repository("RepoName").folder("path/to/folder");
boolean deep = true;
boolean listFolders = true;
boolean timeStamps = true;
FileList list = folder.list(deep, listFolders, timeStamps);
```

##### Copying Items
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package org.jfrog.artifactory.client;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import org.jfrog.artifactory.client.model.FileList;

@JsonIgnoreProperties(ignoreUnknown = true)
public interface FolderHandle extends ItemHandle {
FileList list(boolean deep, boolean listFolders, boolean timestamps);
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
@JsonIgnoreProperties(ignoreUnknown = true)
public interface RepositoryHandle {

ItemHandle folder(String folderName);
FolderHandle folder(String folderName);

ItemHandle file(String filePath);

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package org.jfrog.artifactory.client.model;

import java.util.List;

public interface FileList {

int size();
List<ListItem> getFiles();
}
11 changes: 11 additions & 0 deletions api/src/main/java/org/jfrog/artifactory/client/model/ListItem.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package org.jfrog.artifactory.client.model;

import java.util.Date;

public interface ListItem {
String getUri();
Long getSize();
Date getLastModified();
Boolean isFolder();
String getSha1();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package org.jfrog.artifactory.client.impl

import org.jfrog.artifactory.client.FolderHandle
import org.jfrog.artifactory.client.model.FileList
import org.jfrog.artifactory.client.model.impl.FileListImpl

class FolderHandleImpl extends ItemHandleImpl implements FolderHandle {

private String baseApiPath

private ArtifactoryImpl artifactory
private String repo
private String path

FolderHandleImpl(ArtifactoryImpl artifactory, String baseApiPath, String repo, String path, Class itemType) {
super(artifactory, baseApiPath, repo, path, itemType)
this.artifactory = artifactory
this.repo = repo
this.path = path
this.baseApiPath = baseApiPath
}

FileList list(boolean deep, boolean listFolders, boolean timestamps) {
String deepInt = toInt(deep)
String listFoldersInt = toInt(listFolders)
String timestampsInt = toInt(timestamps)
String url = baseApiPath + "/storage/$repo/$path?list&deep=$deepInt&listFolders=$listFoldersInt&mdTimestamps=$timestampsInt"
return artifactory.get(url, FileListImpl, FileList)
}

private static String toInt(boolean b) {
return b?"1":"0"
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ class RepositoryHandleImpl implements RepositoryHandle {

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

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package org.jfrog.artifactory.client.model.impl;

import org.jfrog.artifactory.client.model.FileList;
import org.jfrog.artifactory.client.model.ListItem;

import java.util.Arrays;
import java.util.Date;
import java.util.List;

public class FileListImpl implements FileList {

String uri;
Date created;
ListItemImpl[] files;

FileListImpl(String uri, Date created, ListItemImpl[] files) {
this.uri = uri;
this.created = created;
this.files = files;
}

public FileListImpl() {
}

@Override
public int size() {
return files.length;
}

@Override
public List<ListItem> getFiles() {
return Arrays.asList(files);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package org.jfrog.artifactory.client.model.impl;

import org.jfrog.artifactory.client.model.ListItem;

import java.util.Date;

public class ListItemImpl implements ListItem {
String uri;
Long size;
Date lastModified;
Boolean folder;
String sha1;

ListItemImpl(String uri, Long size, Date lastModified, Boolean folder) {
this.uri = uri;
this.size = size;
this.lastModified = lastModified;
this.folder = folder;
}

ListItemImpl() {
}

@Override
public String getUri() {
return uri;
}

@Override
public Long getSize() {
return size;
}

@Override
public Date getLastModified() {
return lastModified;
}

@Override
public Boolean isFolder() {
return folder;
}

@Override
public String getSha1() {
return sha1;
}
}
Original file line number Diff line number Diff line change
@@ -1 +1 @@
version=2.9.1
version=2.9.x-SNAPSHOT
26 changes: 19 additions & 7 deletions services/src/test/java/org/jfrog/artifactory/client/ItemTests.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,14 @@
import org.apache.http.client.HttpResponseException;
import org.jfrog.artifactory.client.impl.ArtifactoryRequestImpl;
import org.jfrog.artifactory.client.impl.CopyMoveException;
import org.jfrog.artifactory.client.model.File;
import org.jfrog.artifactory.client.model.Folder;
import org.jfrog.artifactory.client.model.Item;
import org.jfrog.artifactory.client.model.LocalRepository;
import org.jfrog.artifactory.client.model.*;
import org.jfrog.artifactory.client.model.repository.settings.RepositorySettings;
import org.jfrog.artifactory.client.model.repository.settings.impl.GenericRepositorySettingsImpl;
import org.testng.annotations.Test;

import java.io.IOException;
import java.io.InputStream;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.*;

import static org.testng.Assert.*;

Expand All @@ -29,6 +24,23 @@ public class ItemTests extends ArtifactoryTestsBase {
protected static final String NEW_LOCAL_FROM = "new-local-from";
protected static final String NEW_LOCAL_TO = "new-local-to";

@Test
public void testFolderList() throws IOException {
artifactory.repository(getJCenterRepoName()).download("junit/junit/4.10/junit-4.10-sources.jar").doDownload();

FileList list = artifactory.repository(getJcenterCacheName()).folder("junit").list(true,true,true);
assertNotNull(list);
assertEquals(list.size(),3);
assertEquals(list.getFiles().get(2).getSha1(),"6c98d6766e72d5575f96c9479d1c1d3b865c6e25");
Calendar calendar = Calendar.getInstance();
calendar.setTimeInMillis(1317323539000L);
Date date = calendar.getTime();
assertEquals(list.getFiles().get(2).getLastModified().getTime(),calendar.getTime().getTime());

FileList list2 = artifactory.repository(getJcenterCacheName()).folder("junit").list(true,false,false);
assertEquals(list2.size(),1);
}

@Test
public void testFolderInfo() throws IOException {
// Get the folder to the cache
Expand Down

0 comments on commit 42a5671

Please sign in to comment.