// Path: src/main/java/com/bazoud/elasticsearch/river/git/beans/Context.java
// @Data
// @SuppressWarnings("PMD.UnusedPrivateField")
// public class Context {
//     private String name;
//     private String uri;
//     private File projectPath;
//     private Repository repository;
//     private String workingDir =
//         System.getProperty("user.home") + File.separator + ".elasticsearch-river-git";
//     private Collection<Ref> refs;
//     private Client client;
//     private Optional<Pattern> issuePattern = Optional.absent();
//     private String issueRegex;
//     private boolean indexingDiff;
//     private long updateRate = TimeUnit.MILLISECONDS.convert(15, TimeUnit.MINUTES);
//     private String type = "git";
//     private String riverName;
//     private String riverIndexName;
// }
// 
// Path: src/main/java/com/bazoud/elasticsearch/river/git/guava/MyFunction.java
// public abstract class MyFunction<F, T> implements Function<F, T> {
//     private static ESLogger logger = Loggers.getLogger(MyFunction.class);
// 
//     @Override
//     public T apply(F input) {
//         T output = null;
//         try {
//             output = doApply(input);
//         } catch (Throwable e) {
//             logger.error(this.getClass().getName(), e);
//             Throwables.propagate(e);
//         }
//         return output;
//     }
// 
//     public abstract T doApply(F input) throws Throwable;
// }
// 
// Path: src/main/java/com/bazoud/elasticsearch/river/git/jgit/LoggingProgressMonitor.java
// public class LoggingProgressMonitor implements ProgressMonitor {
//     private ESLogger logger;
// 
//     public LoggingProgressMonitor(ESLogger logger) {
//         this.logger = logger;
//     }
// 
//     @Override
//     public void start(int totalTasks) {
//     }
// 
//     @Override
//     public void beginTask(String title, int totalWork) {
//         logger.info(title);
//     }
// 
//     @Override
//     public void update(int completed) {
//     }
// 
//     @Override
//     public void endTask() {
//     }
// 
//     @Override
//     public boolean isCancelled() {
//         return false;
//     }
// }


import java.util.Collection;
import org.eclipse.jgit.api.Git;
import org.eclipse.jgit.lib.Ref;
import org.eclipse.jgit.lib.Repository;
import org.elasticsearch.common.logging.ESLogger;
import org.elasticsearch.common.logging.Loggers;
import com.bazoud.elasticsearch.river.git.beans.Context;
import com.bazoud.elasticsearch.river.git.guava.MyFunction;
import com.bazoud.elasticsearch.river.git.jgit.LoggingProgressMonitor;
import static org.eclipse.jgit.lib.Constants.R_HEADS;
package com.bazoud.elasticsearch.river.git.flow;





/**
 * @author Olivier Bazoud
 */
public class CloneRepositoryFunction extends MyFunction<Context, Context> {
    private static ESLogger logger = Loggers.getLogger(CloneRepositoryFunction.class);

    @Override
    public Context doApply(Context context) throws Throwable {
        logger.info("Cloning the '{}' repository at path: '{}'", context.getName(), context.getProjectPath());
        Git git = Git.cloneRepository()
            .setBare(true)
            .setNoCheckout(true)
            .setCloneAllBranches(true)
            .setDirectory(context.getProjectPath())
            .setURI(context.getUri())
            .setProgressMonitor(new LoggingProgressMonitor(logger))
            .call();
        Repository repository = git.getRepository();
// Path: src/main/java/com/bazoud/elasticsearch/river/git/beans/Context.java
// @Data
// @SuppressWarnings("PMD.UnusedPrivateField")
// public class Context {
//     private String name;
//     private String uri;
//     private File projectPath;
//     private Repository repository;
//     private String workingDir =
//         System.getProperty("user.home") + File.separator + ".elasticsearch-river-git";
//     private Collection<Ref> refs;
//     private Client client;
//     private Optional<Pattern> issuePattern = Optional.absent();
//     private String issueRegex;
//     private boolean indexingDiff;
//     private long updateRate = TimeUnit.MILLISECONDS.convert(15, TimeUnit.MINUTES);
//     private String type = "git";
//     private String riverName;
//     private String riverIndexName;
// }
// 
// Path: src/main/java/com/bazoud/elasticsearch/river/git/guava/MyFunction.java
// public abstract class MyFunction<F, T> implements Function<F, T> {
//     private static ESLogger logger = Loggers.getLogger(MyFunction.class);
// 
//     @Override
//     public T apply(F input) {
//         T output = null;
//         try {
//             output = doApply(input);
//         } catch (Throwable e) {
//             logger.error(this.getClass().getName(), e);
//             Throwables.propagate(e);
//         }
//         return output;
//     }
// 
//     public abstract T doApply(F input) throws Throwable;
// }
// 
// Path: src/main/java/com/bazoud/elasticsearch/river/git/jgit/LoggingProgressMonitor.java
// public class LoggingProgressMonitor implements ProgressMonitor {
//     private ESLogger logger;
// 
//     public LoggingProgressMonitor(ESLogger logger) {
//         this.logger = logger;
//     }
// 
//     @Override
//     public void start(int totalTasks) {
//     }
// 
//     @Override
//     public void beginTask(String title, int totalWork) {
//         logger.info(title);
//     }
// 
//     @Override
//     public void update(int completed) {
//     }
// 
//     @Override
//     public void endTask() {
//     }
// 
//     @Override
//     public boolean isCancelled() {
//         return false;
//     }
// }


// Path: src/main/java/com/bazoud/elasticsearch/river/git/flow/CloneRepositoryFunction.java
import java.util.Collection;
import org.eclipse.jgit.api.Git;
import org.eclipse.jgit.lib.Ref;
import org.eclipse.jgit.lib.Repository;
import org.elasticsearch.common.logging.ESLogger;
import org.elasticsearch.common.logging.Loggers;
import com.bazoud.elasticsearch.river.git.beans.Context;
import com.bazoud.elasticsearch.river.git.guava.MyFunction;
import com.bazoud.elasticsearch.river.git.jgit.LoggingProgressMonitor;
import static org.eclipse.jgit.lib.Constants.R_HEADS;

package com.bazoud.elasticsearch.river.git.flow;





/**
 * @author Olivier Bazoud
 */
public class CloneRepositoryFunction extends MyFunction<Context, Context> {
    private static ESLogger logger = Loggers.getLogger(CloneRepositoryFunction.class);

    @Override
    public Context doApply(Context context) throws Throwable {
        logger.info("Cloning the '{}' repository at path: '{}'", context.getName(), context.getProjectPath());
        Git git = Git.cloneRepository()
            .setBare(true)
            .setNoCheckout(true)
            .setCloneAllBranches(true)
            .setDirectory(context.getProjectPath())
            .setURI(context.getUri())
            .setProgressMonitor(new LoggingProgressMonitor(logger))
            .call();
        Repository repository = git.getRepository();
        context.setRepository(repository);