Java源码示例:org.gitlab4j.api.models.TreeItem
示例1
@NonNull
@Override
public Iterable<SCMFile> children() throws IOException, InterruptedException {
if (!this.isDirectory()) {
throw new IOException("Cannot get children from a regular file");
}
List<TreeItem> treeItems = fetchTree();
List<SCMFile> result = new ArrayList<>(treeItems.size());
for (TreeItem c : treeItems) {
Type t;
if (c.getType() == TreeItem.Type.TREE) {
t = Type.DIRECTORY;
} else if (c.getType() == TreeItem.Type.BLOB) {
if ("120000".equals(c.getMode())) {
// File Mode 120000 is a symlink
t = Type.LINK;
} else {
t = Type.REGULAR_FILE;
}
} else {
t = Type.OTHER;
}
result.add(new GitLabSCMFile(this, c.getName(), t));
}
return result;
}
示例2
private List<TreeItem> fetchTree() throws IOException {
try {
return gitLabApi.getRepositoryApi().getTree(projectPath, getPath(), ref);
} catch (GitLabApiException e) {
throw new IOException(String.format("%s not found at %s", getPath(), ref));
}
}
示例3
@Test
public void testTree() throws Exception {
List<TreeItem> tree = unmarshalResourceList(TreeItem.class, "tree.json");
assertTrue(compareJson(tree, "tree.json"));
}
示例4
/**
* Get a list of repository files and directories in a project.
* <p>
* GET /projects/:id/repository/tree
* <p>
* id (required) - The ID of a project
* path (optional) - The path inside repository. Used to get contend of subdirectories
* ref_name (optional) - The name of a repository branch or tag or if not given the default branch
* recursive (optional) - Boolean value used to get a recursive tree (false by default)
*
* @param projectId the ID of the project to get the files for
* @param filePath the path inside repository, used to get content of subdirectories
* @param refName the name of a repository branch or tag or if not given the default branch
* @param recursive flag to get a recursive tree or not
* @return a tree with the directories and files of a project
* @throws GitLabApiException if any exception occurs
*/
public List<TreeItem> getTree(Integer projectId, String filePath, String refName, Boolean recursive) throws GitLabApiException {
Form formData = new GitLabApiForm()
.withParam("id", projectId, true)
.withParam("path", filePath, false)
.withParam("ref_name", refName, false)
.withParam("recursive", recursive, false)
.withParam(PER_PAGE_PARAM, getDefaultPerPage());
Response response = get(Response.Status.OK, formData.asMap(), "projects", projectId, "repository", "tree");
return (response.readEntity(new GenericType<List<TreeItem>>() {
}));
}
示例5
/**
* Get a Pager of repository files and directories in a project.
* <p>
* GET /projects/:id/repository/tree
* <p>
* id (required) - The ID of a project
* path (optional) - The path inside repository. Used to get contend of subdirectories
* ref_name (optional) - The name of a repository branch or tag or if not given the default branch
* recursive (optional) - Boolean value used to get a recursive tree (false by default)
*
* @param projectId the ID of the project to get the files for
* @param filePath the path inside repository, used to get content of subdirectories
* @param refName the name of a repository branch or tag or if not given the default branch
* @param recursive flag to get a recursive tree or not
* @param itemsPerPage the number of Project instances that will be fetched per page
* @return a tree with the directories and files of a project
* @throws GitLabApiException if any exception occurs
*/
public Pager<TreeItem> getTree(Integer projectId, String filePath, String refName, Boolean recursive, int itemsPerPage) throws GitLabApiException {
Form formData = new GitLabApiForm()
.withParam("id", projectId, true)
.withParam("path", filePath, false)
.withParam("ref_name", refName, false)
.withParam("recursive", recursive, false);
return (new Pager<TreeItem>(this, TreeItem.class, itemsPerPage, formData.asMap(), "projects", projectId, "repository", "tree"));
}
示例6
/**
* Get a Pager of repository files and directories in a project.
*
* <pre><code>GitLab Endpoint: GET /projects/:id/repository/tree</code></pre>
*
* id (required) - The ID of a project
* path (optional) - The path inside repository. Used to get contend of subdirectories
* ref_name (optional) - The name of a repository branch or tag or if not given the default branch
* recursive (optional) - Boolean value used to get a recursive tree (false by default)
*
* @param projectIdOrPath the project in the form of an Integer(ID), String(path), or Project instance
* @param filePath the path inside repository, used to get content of subdirectories
* @param refName the name of a repository branch or tag or if not given the default branch
* @param recursive flag to get a recursive tree or not
* @param itemsPerPage the number of Project instances that will be fetched per page
* @return a tree with the directories and files of a project
* @throws GitLabApiException if any exception occurs
*/
public Pager<TreeItem> getTree(Object projectIdOrPath, String filePath, String refName, Boolean recursive, int itemsPerPage) throws GitLabApiException {
Form formData = new GitLabApiForm()
.withParam("id", getProjectIdOrPath(projectIdOrPath), true)
.withParam("path", filePath, false)
.withParam(isApiVersion(ApiVersion.V3) ? "ref_name" : "ref", (refName != null ? urlEncode(refName) : null), false)
.withParam("recursive", recursive, false);
return (new Pager<TreeItem>(this, TreeItem.class, itemsPerPage, formData.asMap(), "projects",
getProjectIdOrPath(projectIdOrPath), "repository", "tree"));
}
示例7
/**
* Get a list of repository files and directories in a project.
* <p>
* GET /projects/:id/repository/tree
*
* @param projectId the ID of the project to get the files for
* @return a tree with the root directories and files of a project
* @throws GitLabApiException if any exception occurs
*/
public List<TreeItem> getTree(Integer projectId) throws GitLabApiException {
return (getTree(projectId, "/", "master"));
}
示例8
/**
* Get a Pager of repository files and directories in a project.
* <p>
* GET /projects/:id/repository/tree
*
* @param projectId the ID of the project to get the files for
* @param itemsPerPage the number of Project instances that will be fetched per page
* @return a Pager containing a tree with the root directories and files of a project
* @throws GitLabApiException if any exception occurs
*/
public Pager<TreeItem> getTree(Integer projectId, int itemsPerPage) throws GitLabApiException {
return (getTree(projectId, "/", "master", false, itemsPerPage));
}
示例9
/**
* Get a list of repository files and directories in a project.
* <p>
* GET /projects/:id/repository/tree
* <p>
* id (required) - The ID of a project
* path (optional) - The path inside repository. Used to get content of subdirectories
* ref_name (optional) - The name of a repository branch or tag or if not given the default branch
*
* @param projectId the ID of the project to get the files for
* @param filePath the path inside repository, used to get content of subdirectories
* @param refName the name of a repository branch or tag or if not given the default branch
* @return a tree with the directories and files of a project
* @throws GitLabApiException if any exception occurs
*/
public List<TreeItem> getTree(Integer projectId, String filePath, String refName) throws GitLabApiException {
return (getTree(projectId, filePath, refName, false));
}
示例10
/**
* Get a Pager of repository files and directories in a project.
* <p>
* GET /projects/:id/repository/tree
* <p>
* id (required) - The ID of a project
* path (optional) - The path inside repository. Used to get content of subdirectories
* ref_name (optional) - The name of a repository branch or tag or if not given the default branch
*
* @param projectId the ID of the project to get the files for
* @param filePath the path inside repository, used to get content of subdirectories
* @param refName the name of a repository branch or tag or if not given the default branch
* @param itemsPerPage the number of Project instances that will be fetched per page
* @return a Pager containing a tree with the directories and files of a project
* @throws GitLabApiException if any exception occurs
*/
public Pager<TreeItem> getTree(Integer projectId, String filePath, String refName, int itemsPerPage) throws GitLabApiException {
return (getTree(projectId, filePath, refName, false, itemsPerPage));
}
示例11
/**
* Get a list of repository files and directories in a project.
*
* <pre><code>GitLab Endpoint: GET /projects/:id/repository/tree</code></pre>
*
* @param projectIdOrPath the project in the form of an Integer(ID), String(path), or Project instance
* @return a tree with the root directories and files of a project
* @throws GitLabApiException if any exception occurs
*/
public List<TreeItem> getTree(Object projectIdOrPath) throws GitLabApiException {
return (getTree(projectIdOrPath, "/", "master"));
}
示例12
/**
* Get a Pager of repository files and directories in a project.
*
* <pre><code>GitLab Endpoint: GET /projects/:id/repository/tree</code></pre>
*
* @param projectIdOrPath the project in the form of an Integer(ID), String(path), or Project instance
* @param itemsPerPage the number of Project instances that will be fetched per page
* @return a Pager containing a tree with the root directories and files of a project
* @throws GitLabApiException if any exception occurs
*/
public Pager<TreeItem> getTree(Object projectIdOrPath, int itemsPerPage) throws GitLabApiException {
return (getTree(projectIdOrPath, "/", "master", false, itemsPerPage));
}
示例13
/**
* Get a Stream of repository files and directories in a project.
*
* <pre><code>GitLab Endpoint: GET /projects/:id/repository/tree</code></pre>
*
* @param projectIdOrPath the project in the form of an Integer(ID), String(path), or Project instance
* @return a Stream containing a tree with the root directories and files of a project
* @throws GitLabApiException if any exception occurs
*/
public Stream<TreeItem> getTreeStream(Object projectIdOrPath) throws GitLabApiException {
return (getTreeStream(projectIdOrPath, "/", "master"));
}
示例14
/**
* Get a list of repository files and directories in a project.
*
* <pre><code>GitLab Endpoint: GET /projects/:id/repository/tree</code></pre>
*
* id (required) - The ID of a project
* path (optional) - The path inside repository. Used to get content of subdirectories
* ref_name (optional) - The name of a repository branch or tag or if not given the default branch
*
* @param projectIdOrPath the project in the form of an Integer(ID), String(path), or Project instance
* @param filePath the path inside repository, used to get content of subdirectories
* @param refName the name of a repository branch or tag or if not given the default branch
* @return a tree with the directories and files of a project
* @throws GitLabApiException if any exception occurs
*/
public List<TreeItem> getTree(Object projectIdOrPath, String filePath, String refName) throws GitLabApiException {
return (getTree(projectIdOrPath, filePath, refName, false));
}
示例15
/**
* Get a Pager of repository files and directories in a project.
*
* <pre><code>GitLab Endpoint: GET /projects/:id/repository/tree</code></pre>
*
* id (required) - The ID of a project
* path (optional) - The path inside repository. Used to get content of subdirectories
* ref_name (optional) - The name of a repository branch or tag or if not given the default branch
*
* @param projectIdOrPath the project in the form of an Integer(ID), String(path), or Project instance
* @param filePath the path inside repository, used to get content of subdirectories
* @param refName the name of a repository branch or tag or if not given the default branch
* @param itemsPerPage the number of Project instances that will be fetched per page
* @return a Pager containing a tree with the directories and files of a project
* @throws GitLabApiException if any exception occurs
*/
public Pager<TreeItem> getTree(Object projectIdOrPath, String filePath, String refName, int itemsPerPage) throws GitLabApiException {
return (getTree(projectIdOrPath, filePath, refName, false, itemsPerPage));
}
示例16
/**
* Get a Stream of repository files and directories in a project.
*
* <pre><code>GitLab Endpoint: GET /projects/:id/repository/tree</code></pre>
*
* id (required) - The ID of a project
* path (optional) - The path inside repository. Used to get content of subdirectories
* ref_name (optional) - The name of a repository branch or tag or if not given the default branch
*
* @param projectIdOrPath the project in the form of an Integer(ID), String(path), or Project instance
* @param filePath the path inside repository, used to get content of subdirectories
* @param refName the name of a repository branch or tag or if not given the default branch
* @return a Stream containing a tree with the directories and files of a project
* @throws GitLabApiException if any exception occurs
*/
public Stream<TreeItem> getTreeStream(Object projectIdOrPath, String filePath, String refName) throws GitLabApiException {
return (getTreeStream(projectIdOrPath, filePath, refName, false));
}
示例17
/**
* Get a list of repository files and directories in a project.
*
* <pre><code>GitLab Endpoint: GET /projects/:id/repository/tree</code></pre>
*
* id (required) - The ID of a project
* path (optional) - The path inside repository. Used to get contend of subdirectories
* ref_name (optional) - The name of a repository branch or tag or if not given the default branch
* recursive (optional) - Boolean value used to get a recursive tree (false by default)
*
* @param projectIdOrPath the project in the form of an Integer(ID), String(path), or Project instance
* @param filePath the path inside repository, used to get content of subdirectories
* @param refName the name of a repository branch or tag or if not given the default branch
* @param recursive flag to get a recursive tree or not
* @return a tree with the directories and files of a project
* @throws GitLabApiException if any exception occurs
*/
public List<TreeItem> getTree(Object projectIdOrPath, String filePath, String refName, Boolean recursive) throws GitLabApiException {
return (getTree(projectIdOrPath, filePath, refName, recursive, getDefaultPerPage()).all());
}
示例18
/**
* Get a Stream of repository files and directories in a project.
*
* <pre><code>GitLab Endpoint: GET /projects/:id/repository/tree</code></pre>
*
* id (required) - The ID of a project
* path (optional) - The path inside repository. Used to get contend of subdirectories
* ref_name (optional) - The name of a repository branch or tag or if not given the default branch
* recursive (optional) - Boolean value used to get a recursive tree (false by default)
*
* @param projectIdOrPath the project in the form of an Integer(ID), String(path), or Project instance
* @param filePath the path inside repository, used to get content of subdirectories
* @param refName the name of a repository branch or tag or if not given the default branch
* @param recursive flag to get a recursive tree or not
* @return a Stream containing a tree with the directories and files of a project
* @throws GitLabApiException if any exception occurs
*/
public Stream<TreeItem> getTreeStream(Object projectIdOrPath, String filePath, String refName, Boolean recursive) throws GitLabApiException {
return (getTree(projectIdOrPath, filePath, refName, recursive, getDefaultPerPage()).stream());
}