org.gitlab4j.api.models.TreeItem Java Examples

The following examples show how to use org.gitlab4j.api.models.TreeItem. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: GitLabSCMFile.java    From gitlab-branch-source-plugin with MIT License 7 votes vote down vote up
@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;
}
 
Example #2
Source File: GitLabSCMFile.java    From gitlab-branch-source-plugin with MIT License 5 votes vote down vote up
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));
    }
}
 
Example #3
Source File: TestGitLabApiBeans.java    From gitlab4j-api with MIT License 4 votes vote down vote up
@Test
public void testTree() throws Exception {
    List<TreeItem> tree = unmarshalResourceList(TreeItem.class, "tree.json");
    assertTrue(compareJson(tree, "tree.json"));
}
 
Example #4
Source File: RepositoryApi.java    From choerodon-starters with Apache License 2.0 3 votes vote down vote up
/**
 * 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>>() {
    }));
}
 
Example #5
Source File: RepositoryApi.java    From choerodon-starters with Apache License 2.0 3 votes vote down vote up
/**
 * 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"));
}
 
Example #6
Source File: RepositoryApi.java    From gitlab4j-api with MIT License 3 votes vote down vote up
/**
 * 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"));
}
 
Example #7
Source File: RepositoryApi.java    From choerodon-starters with Apache License 2.0 2 votes vote down vote up
/**
 * 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));
}
 
Example #8
Source File: RepositoryApi.java    From choerodon-starters with Apache License 2.0 2 votes vote down vote up
/**
 * 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));
}
 
Example #9
Source File: RepositoryApi.java    From choerodon-starters with Apache License 2.0 2 votes vote down vote up
/**
 * 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));
}
 
Example #10
Source File: RepositoryApi.java    From gitlab4j-api with MIT License 2 votes vote down vote up
/**
 * 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"));
}
 
Example #11
Source File: RepositoryApi.java    From gitlab4j-api with MIT License 2 votes vote down vote up
/**
 * 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));
}
 
Example #12
Source File: RepositoryApi.java    From gitlab4j-api with MIT License 2 votes vote down vote up
/**
 * 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"));
}
 
Example #13
Source File: RepositoryApi.java    From gitlab4j-api with MIT License 2 votes vote down vote up
/**
 * 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));
}
 
Example #14
Source File: RepositoryApi.java    From gitlab4j-api with MIT License 2 votes vote down vote up
/**
 * 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));
}
 
Example #15
Source File: RepositoryApi.java    From gitlab4j-api with MIT License 2 votes vote down vote up
/**
 * 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));
}
 
Example #16
Source File: RepositoryApi.java    From gitlab4j-api with MIT License 2 votes vote down vote up
/**
 * 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());
}
 
Example #17
Source File: RepositoryApi.java    From gitlab4j-api with MIT License 2 votes vote down vote up
/**
 * 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());
}
 
Example #18
Source File: RepositoryApi.java    From choerodon-starters with Apache License 2.0 2 votes vote down vote up
/**
 * 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"));
}