// Path: AndroidGears/src/Workers/Git/GitWorker.java
// public class GitWorker extends SwingWorker<Void, Void> {
//     private static final int DEFAULT_TIMEOUT = 5000; //10s
//     private  String REMOTE_SPECS_URL = "https://github.com/AndroidGears/Specs.git";
// 
//     public boolean successful = false;
// 
//     @Override
//     protected Void doInBackground() throws Exception {
//         SettingsManager.getInstance().loadSettings();
//         syncAndroidGears();
//         return null;
//     }
// 
//     private void syncAndroidGears(){
//         //Setup file
//         File androidGearsDirectory = Utils.androidGearsDirectory();
// 
//         //Pull changes or clone repo
//         if(androidGearsDirectory.exists()){
//             successful = pullChanges(androidGearsDirectory);
//         }
//         else {
//             androidGearsDirectory.mkdir();
//             successful = cloneRepository(androidGearsDirectory);
//         }
//     }
// 
//     private Boolean cloneRepository(File androidGearsDirectory){
//         try {
//            Git git = Git.cloneRepository()
//                     .setURI(REMOTE_SPECS_URL)
//                     .setBranch("master")
//                     .setDirectory(androidGearsDirectory)
//                    .setTimeout(DEFAULT_TIMEOUT)
//                     .call();
// 
//             //Get repos directory
//            File reposDirectory = git.getRepository().getDirectory().getParentFile();
// 
//             //Close git connection!
//             git.close();
// 
//             //If everything was created successfully, return true
//             if (reposDirectory != null){
//                 if (reposDirectory.exists()){
//                     if (reposDirectory.list().length > 1){
//                         return true;
//                     }
//                 }
//             }
//         } catch (GitAPIException e) {
//             e.printStackTrace();
// 
//         }
// 
//         return false;
//     }
// 
//     private Boolean pullChanges(File androidGearsDirectory){
//         try {
//             Git git = Git.open(new File(androidGearsDirectory.getAbsolutePath()+ Utils.pathSeparator()+".git"));
//             PullResult result = git.pull().setTimeout(DEFAULT_TIMEOUT).call();
//             git.close();
//             return result.isSuccessful();
// 
//             /*
//             PullCommand pullCmd = git.pull();
// 
//             PullResult result = pullCmd.call();
//             FetchResult fetchResult = result.getFetchResult();
//             MergeResult mergeResult = result.getMergeResult();
//             mergeResult.getMergeStatus();  // this should be interesting*/
//         }
//         catch (IOException exception){
//             //cloneRepository(androidGearsDirectory);
//         }
//         catch (GitAPIException exception){
//             exception.printStackTrace();
//         }
// 
//         return false;
//     }
// }
// 
// Path: AndroidGears/src/Workers/Git/IgnoreCheckWorker.java
// public class IgnoreCheckWorker extends SwingWorker<Void, Void>{
// 
//     @Override
//     protected Void doInBackground() throws Exception {
// 
//         //Load settings from file
//         SettingsManager.getInstance().loadSettings();
// 
//         //If the ignore is set, try and add it. If it already exists, the following won't do anything
//         if (SettingsManager.getInstance().getAutoIgnore()){
//            SettingsManager.getInstance().setCreateIgnore(true);
//         }
// 
//         return null;
//     }
// }


import Workers.Git.GitWorker;
import Workers.Git.IgnoreCheckWorker;
import com.intellij.openapi.components.ApplicationComponent;
import org.jetbrains.annotations.NotNull;

/**
 * Created by matthewyork on 3/31/14.
 */
public class GitComponent implements ApplicationComponent {

    private  String REMOTE_SPECS_URL = "https://github.com/AndroidGears/Specs.git";

    public GitComponent() {
    }

    public void initComponent() {

        //Clones/Pulls on the specNames repo
        GitWorker worker = new GitWorker(){
            @Override
            protected void done() {
                super.done();

            }
        };
// Path: AndroidGears/src/Workers/Git/GitWorker.java
// public class GitWorker extends SwingWorker<Void, Void> {
//     private static final int DEFAULT_TIMEOUT = 5000; //10s
//     private  String REMOTE_SPECS_URL = "https://github.com/AndroidGears/Specs.git";
// 
//     public boolean successful = false;
// 
//     @Override
//     protected Void doInBackground() throws Exception {
//         SettingsManager.getInstance().loadSettings();
//         syncAndroidGears();
//         return null;
//     }
// 
//     private void syncAndroidGears(){
//         //Setup file
//         File androidGearsDirectory = Utils.androidGearsDirectory();
// 
//         //Pull changes or clone repo
//         if(androidGearsDirectory.exists()){
//             successful = pullChanges(androidGearsDirectory);
//         }
//         else {
//             androidGearsDirectory.mkdir();
//             successful = cloneRepository(androidGearsDirectory);
//         }
//     }
// 
//     private Boolean cloneRepository(File androidGearsDirectory){
//         try {
//            Git git = Git.cloneRepository()
//                     .setURI(REMOTE_SPECS_URL)
//                     .setBranch("master")
//                     .setDirectory(androidGearsDirectory)
//                    .setTimeout(DEFAULT_TIMEOUT)
//                     .call();
// 
//             //Get repos directory
//            File reposDirectory = git.getRepository().getDirectory().getParentFile();
// 
//             //Close git connection!
//             git.close();
// 
//             //If everything was created successfully, return true
//             if (reposDirectory != null){
//                 if (reposDirectory.exists()){
//                     if (reposDirectory.list().length > 1){
//                         return true;
//                     }
//                 }
//             }
//         } catch (GitAPIException e) {
//             e.printStackTrace();
// 
//         }
// 
//         return false;
//     }
// 
//     private Boolean pullChanges(File androidGearsDirectory){
//         try {
//             Git git = Git.open(new File(androidGearsDirectory.getAbsolutePath()+ Utils.pathSeparator()+".git"));
//             PullResult result = git.pull().setTimeout(DEFAULT_TIMEOUT).call();
//             git.close();
//             return result.isSuccessful();
// 
//             /*
//             PullCommand pullCmd = git.pull();
// 
//             PullResult result = pullCmd.call();
//             FetchResult fetchResult = result.getFetchResult();
//             MergeResult mergeResult = result.getMergeResult();
//             mergeResult.getMergeStatus();  // this should be interesting*/
//         }
//         catch (IOException exception){
//             //cloneRepository(androidGearsDirectory);
//         }
//         catch (GitAPIException exception){
//             exception.printStackTrace();
//         }
// 
//         return false;
//     }
// }
// 
// Path: AndroidGears/src/Workers/Git/IgnoreCheckWorker.java
// public class IgnoreCheckWorker extends SwingWorker<Void, Void>{
// 
//     @Override
//     protected Void doInBackground() throws Exception {
// 
//         //Load settings from file
//         SettingsManager.getInstance().loadSettings();
// 
//         //If the ignore is set, try and add it. If it already exists, the following won't do anything
//         if (SettingsManager.getInstance().getAutoIgnore()){
//            SettingsManager.getInstance().setCreateIgnore(true);
//         }
// 
//         return null;
//     }
// }


// Path: AndroidGears/src/GitComponent.java
import Workers.Git.GitWorker;
import Workers.Git.IgnoreCheckWorker;
import com.intellij.openapi.components.ApplicationComponent;
import org.jetbrains.annotations.NotNull;


/**
 * Created by matthewyork on 3/31/14.
 */
public class GitComponent implements ApplicationComponent {

    private  String REMOTE_SPECS_URL = "https://github.com/AndroidGears/Specs.git";

    public GitComponent() {
    }

    public void initComponent() {

        //Clones/Pulls on the specNames repo
        GitWorker worker = new GitWorker(){
            @Override
            protected void done() {
                super.done();

            }
        };
        worker.execute();