Example usage for org.eclipse.jgit.lib ProgressMonitor ProgressMonitor

List of usage examples for org.eclipse.jgit.lib ProgressMonitor ProgressMonitor

Introduction

In this page you can find the example usage for org.eclipse.jgit.lib ProgressMonitor ProgressMonitor.

Prototype

ProgressMonitor

Source Link

Usage

From source file:com.door43.translationstudio.tasks.PullTargetTranslationTask.java

private String pull(Repo repo, String remote) {
    Git git;/* w w  w. j av a  2 s  .c  o m*/
    try {
        repo.deleteRemote("origin");
        repo.setRemote("origin", remote);
        git = repo.getGit();
    } catch (IOException e) {
        return null;
    }

    Manifest localManifest = Manifest.generate(this.targetTranslation.getPath());

    // TODO: we might want to get some progress feedback for the user
    PullCommand pullCommand = git.pull().setTransportConfigCallback(new TransportCallback()).setRemote("origin")
            .setStrategy(mergeStrategy).setRemoteBranchName("master").setProgressMonitor(new ProgressMonitor() {
                @Override
                public void start(int totalTasks) {

                }

                @Override
                public void beginTask(String title, int totalWork) {

                }

                @Override
                public void update(int completed) {

                }

                @Override
                public void endTask() {

                }

                @Override
                public boolean isCancelled() {
                    return false;
                }
            });
    try {
        PullResult result = pullCommand.call();
        MergeResult mergeResult = result.getMergeResult();
        if (mergeResult != null && mergeResult.getConflicts() != null
                && mergeResult.getConflicts().size() > 0) {
            this.status = Status.MERGE_CONFLICTS;
            this.conflicts = mergeResult.getConflicts();

            // revert manifest merge conflict to avoid corruption
            if (this.conflicts.containsKey("manifest.json")) {
                Logger.i("PullTargetTranslationTask", "Reverting to server manifest");
                try {
                    git.checkout().setStage(CheckoutCommand.Stage.THEIRS).addPath("manifest.json").call();
                    Manifest remoteManifest = Manifest.generate(this.targetTranslation.getPath());
                    localManifest = TargetTranslation.mergeManifests(localManifest, remoteManifest);
                } catch (CheckoutConflictException e) {
                    // failed to reset manifest.json
                    Logger.e(this.getClass().getName(), "Failed to reset manifest: " + e.getMessage(), e);
                } finally {
                    localManifest.save();
                }
            }

            // keep our license
            if (this.conflicts.containsKey("LICENSE.md")) {
                Logger.i("PullTargetTranslationTask", "Reverting to local license");
                try {
                    git.checkout().setStage(CheckoutCommand.Stage.OURS).addPath("LICENSE.md").call();
                } catch (CheckoutConflictException e) {
                    Logger.e(this.getClass().getName(), "Failed to reset license: " + e.getMessage(), e);
                }
            }
        } else {
            this.status = Status.UP_TO_DATE;
        }

        return "message";
    } catch (TransportException e) {
        Logger.e(this.getClass().getName(), e.getMessage(), e);
        Throwable cause = e.getCause();
        if (cause != null) {
            Throwable subException = cause.getCause();
            if (subException != null) {
                String detail = subException.getMessage();
                if ("Auth fail".equals(detail)) {
                    this.status = Status.AUTH_FAILURE; // we do special handling for auth failure
                }
            } else if (cause instanceof NoRemoteRepositoryException) {
                this.status = Status.NO_REMOTE_REPO;
            }
        }
        return null;
    } catch (Exception e) {
        Throwable cause = e.getCause();
        if (cause instanceof NoRemoteRepositoryException) {
            this.status = Status.NO_REMOTE_REPO;
        }
        Logger.e(this.getClass().getName(), e.getMessage(), e);
        return null;
    } catch (OutOfMemoryError e) {
        Logger.e(this.getClass().getName(), e.getMessage(), e);
        this.status = Status.OUT_OF_MEMORY;
        return null;
    } catch (Throwable e) {
        Logger.e(this.getClass().getName(), e.getMessage(), e);
        return null;
    }
}

From source file:io.github.thefishlive.updater.Updater.java

License:Open Source License

private ProgressMonitor buildProgressMonitor() {
    return new ProgressMonitor() {
        private int curIndent = -1;

        @Override/*w  w  w.  j  a v a 2s  .  c om*/
        public void start(int totalTasks) {
        }

        @Override
        public void beginTask(String title, int totalWork) {
            if (!title.startsWith("remote:"))
                curIndent++;
            String message = title + "(" + totalWork + ")";
            for (int i = 0; i < curIndent; i++) {
                message = "\t" + message;
            }
            System.out.println(message);
        }

        @Override
        public void update(int completed) {
        }

        @Override
        public void endTask() {
            String message = "Task ended";
            for (int i = 0; i < curIndent; i++) {
                message = "\t" + message;
            }
            System.out.println(message);
            curIndent--;
        }

        @Override
        public boolean isCancelled() {
            return false;
        }

    };
}