Search in sources :

Example 1 with ShowFileContentResponse

use of org.eclipse.che.api.git.shared.ShowFileContentResponse in project che by eclipse.

the class ShowFileContentTest method testShowFileContentFromBranch.

@Test(dataProvider = "GitConnectionFactory", dataProviderClass = GitConnectionFactoryProvider.class)
public void testShowFileContentFromBranch(GitConnectionFactory connectionFactory) throws IOException, ServerException, URISyntaxException, UnauthorizedException {
    //given
    //create new repository
    GitConnection connection = connectToInitializedGitRepository(connectionFactory, repository);
    addFile(connection, "newFile", "new file content");
    connection.add(AddParams.create(singletonList(".")));
    connection.commit(CommitParams.create("Test commit"));
    connection.branchCreate("new-branch", null);
    //when
    final ShowFileContentResponse response = connection.showFileContent("newFile", "new-branch");
    //then
    assertEquals("new file content", response.getContent());
}
Also used : ShowFileContentResponse(org.eclipse.che.api.git.shared.ShowFileContentResponse) GitConnection(org.eclipse.che.api.git.GitConnection) Test(org.testng.annotations.Test)

Example 2 with ShowFileContentResponse

use of org.eclipse.che.api.git.shared.ShowFileContentResponse in project che by eclipse.

the class ShowFileContentTest method testShowFileContentFromHead.

@Test(dataProvider = "GitConnectionFactory", dataProviderClass = GitConnectionFactoryProvider.class)
public void testShowFileContentFromHead(GitConnectionFactory connectionFactory) throws IOException, ServerException, URISyntaxException, UnauthorizedException {
    //given
    //create new repository
    GitConnection connection = connectToInitializedGitRepository(connectionFactory, repository);
    addFile(connection, "newFile", "new file content");
    connection.add(AddParams.create(singletonList(".")));
    connection.commit(CommitParams.create("Test commit"));
    //when
    final ShowFileContentResponse response = connection.showFileContent("newFile", "HEAD");
    //then
    assertEquals("new file content", response.getContent());
}
Also used : ShowFileContentResponse(org.eclipse.che.api.git.shared.ShowFileContentResponse) GitConnection(org.eclipse.che.api.git.GitConnection) Test(org.testng.annotations.Test)

Example 3 with ShowFileContentResponse

use of org.eclipse.che.api.git.shared.ShowFileContentResponse in project che by eclipse.

the class ComparePresenter method showCompareBetweenRevisions.

/**
     *
     * @param file
     *         path of the file
     * @param status
     *         status of the file
     * @param revisionA
     *         hash of the first revision or branch.
     *         If it is set to {@code null}, compare with empty repository state will be performed
     * @param revisionB
     *         hash of the second revision or branch.
     *         If it is set to {@code null}, compare with latest repository state will be performed
     */
public void showCompareBetweenRevisions(final Path file, final Status status, @Nullable final String revisionA, @Nullable final String revisionB) {
    this.compareWithLatest = false;
    final DevMachine devMachine = appContext.getDevMachine();
    final Path projectLocation = appContext.getRootProject().getLocation();
    view.setTitle(file.toString());
    if (status == Status.ADDED) {
        service.showFileContent(devMachine, projectLocation, file, revisionB).then(new Operation<ShowFileContentResponse>() {

            @Override
            public void apply(ShowFileContentResponse response) throws OperationException {
                view.setColumnTitles(revisionB + locale.compareReadOnlyTitle(), revisionA == null ? "" : revisionA + locale.compareReadOnlyTitle());
                view.show("", response.getContent(), file.toString(), true);
            }
        }).catchError(new Operation<PromiseError>() {

            @Override
            public void apply(PromiseError error) throws OperationException {
                notificationManager.notify(error.getMessage(), FAIL, NOT_EMERGE_MODE);
            }
        });
    } else if (status == Status.DELETED) {
        service.showFileContent(devMachine, projectLocation, file, revisionA).then(new Operation<ShowFileContentResponse>() {

            @Override
            public void apply(ShowFileContentResponse response) throws OperationException {
                view.setColumnTitles(revisionB + locale.compareReadOnlyTitle(), revisionA + locale.compareReadOnlyTitle());
                view.show(response.getContent(), "", file.toString(), true);
            }
        }).catchError(new Operation<PromiseError>() {

            @Override
            public void apply(PromiseError error) throws OperationException {
                notificationManager.notify(error.getMessage(), FAIL, NOT_EMERGE_MODE);
            }
        });
    } else {
        service.showFileContent(devMachine, projectLocation, file, revisionA).then(new Operation<ShowFileContentResponse>() {

            @Override
            public void apply(final ShowFileContentResponse contentAResponse) throws OperationException {
                service.showFileContent(devMachine, projectLocation, file, revisionB).then(new Operation<ShowFileContentResponse>() {

                    @Override
                    public void apply(ShowFileContentResponse contentBResponse) throws OperationException {
                        view.setColumnTitles(revisionB + locale.compareReadOnlyTitle(), revisionA + locale.compareReadOnlyTitle());
                        view.show(contentAResponse.getContent(), contentBResponse.getContent(), file.toString(), true);
                    }
                }).catchError(new Operation<PromiseError>() {

                    @Override
                    public void apply(PromiseError error) throws OperationException {
                        notificationManager.notify(error.getMessage(), FAIL, NOT_EMERGE_MODE);
                    }
                });
            }
        });
    }
}
Also used : Path(org.eclipse.che.ide.resource.Path) DevMachine(org.eclipse.che.ide.api.machine.DevMachine) PromiseError(org.eclipse.che.api.promises.client.PromiseError) ShowFileContentResponse(org.eclipse.che.api.git.shared.ShowFileContentResponse) Operation(org.eclipse.che.api.promises.client.Operation) OperationException(org.eclipse.che.api.promises.client.OperationException)

Example 4 with ShowFileContentResponse

use of org.eclipse.che.api.git.shared.ShowFileContentResponse in project che by eclipse.

the class JGitConnection method showFileContent.

@Override
public ShowFileContentResponse showFileContent(String file, String version) throws GitException {
    String content;
    ObjectId revision;
    try {
        revision = getRepository().resolve(version);
        try (RevWalk revWalk = new RevWalk(getRepository())) {
            RevCommit revCommit = revWalk.parseCommit(revision);
            RevTree tree = revCommit.getTree();
            try (TreeWalk treeWalk = new TreeWalk(getRepository())) {
                treeWalk.addTree(tree);
                treeWalk.setRecursive(true);
                treeWalk.setFilter(PathFilter.create(file));
                if (!treeWalk.next()) {
                    throw new GitException("fatal: Path '" + file + "' does not exist in '" + version + "'" + lineSeparator());
                }
                ObjectId objectId = treeWalk.getObjectId(0);
                ObjectLoader loader = repository.open(objectId);
                content = new String(loader.getBytes());
            }
        }
    } catch (IOException exception) {
        throw new GitException(exception.getMessage());
    }
    return newDto(ShowFileContentResponse.class).withContent(content);
}
Also used : ObjectId(org.eclipse.jgit.lib.ObjectId) GitException(org.eclipse.che.api.git.exception.GitException) ShowFileContentResponse(org.eclipse.che.api.git.shared.ShowFileContentResponse) ObjectLoader(org.eclipse.jgit.lib.ObjectLoader) IOException(java.io.IOException) RevWalk(org.eclipse.jgit.revwalk.RevWalk) TreeWalk(org.eclipse.jgit.treewalk.TreeWalk) RevTree(org.eclipse.jgit.revwalk.RevTree) RevCommit(org.eclipse.jgit.revwalk.RevCommit)

Example 5 with ShowFileContentResponse

use of org.eclipse.che.api.git.shared.ShowFileContentResponse in project che by eclipse.

the class ComparePresenter method showCompareWithLatest.

/**
     * Show compare window.
     *
     * @param file
     *         file name with its full path
     * @param status
     *         status of the file
     * @param revision
     *         hash of revision or branch
     */
public void showCompareWithLatest(final File file, final Status status, final String revision) {
    this.comparedFile = file;
    this.revision = revision;
    this.compareWithLatest = true;
    if (status.equals(ADDED)) {
        showCompare("");
        return;
    }
    final Optional<Project> project = file.getRelatedProject();
    if (!project.isPresent()) {
        return;
    }
    final Path relPath = file.getLocation().removeFirstSegments(project.get().getLocation().segmentCount());
    if (status.equals(DELETED)) {
        service.showFileContent(appContext.getDevMachine(), project.get().getLocation(), relPath, revision).then(new Operation<ShowFileContentResponse>() {

            @Override
            public void apply(ShowFileContentResponse content) throws OperationException {
                view.setTitle(file.getLocation().toString());
                view.setColumnTitles(locale.compareYourVersionTitle(), revision + locale.compareReadOnlyTitle());
                view.show(content.getContent(), "", file.getLocation().toString(), false);
            }
        }).catchError(new Operation<PromiseError>() {

            @Override
            public void apply(PromiseError error) throws OperationException {
                notificationManager.notify(error.getMessage(), FAIL, NOT_EMERGE_MODE);
            }
        });
    } else {
        service.showFileContent(appContext.getDevMachine(), project.get().getLocation(), relPath, revision).then(new Operation<ShowFileContentResponse>() {

            @Override
            public void apply(ShowFileContentResponse content) throws OperationException {
                showCompare(content.getContent());
            }
        }).catchError(new Operation<PromiseError>() {

            @Override
            public void apply(PromiseError error) throws OperationException {
                notificationManager.notify(error.getMessage(), FAIL, NOT_EMERGE_MODE);
            }
        });
    }
}
Also used : Path(org.eclipse.che.ide.resource.Path) Project(org.eclipse.che.ide.api.resources.Project) PromiseError(org.eclipse.che.api.promises.client.PromiseError) ShowFileContentResponse(org.eclipse.che.api.git.shared.ShowFileContentResponse) Operation(org.eclipse.che.api.promises.client.Operation) OperationException(org.eclipse.che.api.promises.client.OperationException)

Aggregations

ShowFileContentResponse (org.eclipse.che.api.git.shared.ShowFileContentResponse)5 GitConnection (org.eclipse.che.api.git.GitConnection)2 Operation (org.eclipse.che.api.promises.client.Operation)2 OperationException (org.eclipse.che.api.promises.client.OperationException)2 PromiseError (org.eclipse.che.api.promises.client.PromiseError)2 Path (org.eclipse.che.ide.resource.Path)2 Test (org.testng.annotations.Test)2 IOException (java.io.IOException)1 GitException (org.eclipse.che.api.git.exception.GitException)1 DevMachine (org.eclipse.che.ide.api.machine.DevMachine)1 Project (org.eclipse.che.ide.api.resources.Project)1 ObjectId (org.eclipse.jgit.lib.ObjectId)1 ObjectLoader (org.eclipse.jgit.lib.ObjectLoader)1 RevCommit (org.eclipse.jgit.revwalk.RevCommit)1 RevTree (org.eclipse.jgit.revwalk.RevTree)1 RevWalk (org.eclipse.jgit.revwalk.RevWalk)1 TreeWalk (org.eclipse.jgit.treewalk.TreeWalk)1