Android Open Source - codemap J Git Wrapper






From Project

Back to project page codemap.

License

The source code is released under:

GNU General Public License

If you think the Android project codemap listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package com.hdweiss.codemap.data;
/*from  w w  w.  j a  v a 2s .  c o m*/
import java.io.File;
import java.io.IOException;

import org.eclipse.jgit.api.CloneCommand;
import org.eclipse.jgit.api.Git;
import org.eclipse.jgit.api.GitCommand;
import org.eclipse.jgit.api.PullCommand;
import org.eclipse.jgit.lib.ProgressMonitor;
import org.eclipse.jgit.storage.file.FileRepository;

import android.content.Context;
import android.os.AsyncTask;
import android.util.Log;
import android.widget.Toast;

import com.hdweiss.codemap.util.Utils;

public class JGitWrapper {
  
  private Context context;
  private Git git;
  
  private Project project;
  private ProjectController controller;
  
  public JGitWrapper(Project project, Context context) throws IOException {
    this.project = project;
    this.context = context;
    FileRepository localRepo = new FileRepository(project.getSourcePath(context) + "/.git");
    git = new Git(localRepo);
  }
  
  public void update(ProjectController controller) throws IllegalStateException {
    if (Utils.isNetworkOnline(context) == false)
      throw new IllegalStateException("Network is not available");
    
    this.controller = controller;
    File sourceRepo = new File(project.getSourcePath(context));
    
      GitCommand<?> command;
      
    if(sourceRepo.exists()) {
      command = git.pull();
    }
      else {
        command = Git.cloneRepository().setURI(project.getUrl())
      .setDirectory(new File(project.getSourcePath(context)));
      }
    
    new GitTask(project.getName()).execute(command);
  }

    
    private class GitTask extends AsyncTask<GitCommand<?>, Integer, Long> {
      
    private String projectName;
    private String status;

    public GitTask(String projectName) {
      this.projectName = projectName;
    }

    @Override
    protected Long doInBackground(GitCommand<?>... params) {
      GitCommand<?> command = params[0];
      
      Utils.announceSyncStart(context, projectName);

      if(command instanceof CloneCommand) {
        ((CloneCommand)command).setProgressMonitor(monitor);
        status = "Cloning";
      } else if(command instanceof PullCommand) {
        ((PullCommand)command).setProgressMonitor(monitor);
        status = "Pulling";
      } else {
        throw new IllegalArgumentException(
            "Coudln't attach progressMonitor to git command");
      }
      
      publishProgress(-1);
      
      try {
        command.call();
      } catch (Exception e) {
        status = e.getLocalizedMessage();
        publishProgress(100);
      }
      return 0L;
    }
    
    @Override
    protected void onProgressUpdate(Integer... values) {
      super.onProgressUpdate(values);
      int progress = values[0];
      
      Utils.announceSyncUpdateProgress(context, projectName, progress, status);
    }

    @Override
    protected void onPostExecute(Long result) {
      super.onPostExecute(result);
      controller.buildIndex();
      Toast.makeText(context, "Updated " + project.getName(), Toast.LENGTH_SHORT).show();
      Utils.announceSyncDone(context, projectName);
    }
    
    private ProgressMonitor monitor = new ProgressMonitor() {

      private int progress = 0;
      private int totalWork = 0;
      private int workCompleted = 0;

      public void start(int totalTasks) {
        Log.d("CodeMap", "total tasks: " + totalTasks);
      }

      public void beginTask(String title, int totalWork) {
        Log.d("CodeMap", "starting: " + title + " : " + totalWork);

        this.totalWork = totalWork;
        this.workCompleted = 0;
        status = title;
        publishProgress(0);
      }

      public void update(int completed) {
        this.workCompleted += completed;
        //Log.d("CodeMap", "completed: " + workCompleted + "/" + totalWork);
        int newProgress = getProgress();
        
        if(this.progress != newProgress) {
          this.progress = newProgress;
          publishProgress(newProgress);
        }
      }

      private int getProgress() {
        if(totalWork == 0)
          return 0;
        
        final int taskWorkProgress = (int) ((100.0 / totalWork)
            * workCompleted);
        return taskWorkProgress;
      }

      public void endTask() {
      }

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




Java Source Code List

com.hdweiss.codemap.data.CodeMapApp.java
com.hdweiss.codemap.data.CscopeEntry.java
com.hdweiss.codemap.data.CscopeWrapper.java
com.hdweiss.codemap.data.Cscope.java
com.hdweiss.codemap.data.ICodeMapItem.java
com.hdweiss.codemap.data.JGitWrapper.java
com.hdweiss.codemap.data.ProjectController.java
com.hdweiss.codemap.data.Project.java
com.hdweiss.codemap.data.SerializableItem.java
com.hdweiss.codemap.data.SerializableLink.java
com.hdweiss.codemap.util.AbsoluteLayout.java
com.hdweiss.codemap.util.CodeMapCursorPoint.java
com.hdweiss.codemap.util.CodeMapPoint.java
com.hdweiss.codemap.util.FlowLayout.java
com.hdweiss.codemap.util.ObjectSerializer.java
com.hdweiss.codemap.util.SpanUtils.java
com.hdweiss.codemap.util.SyntaxHighlighter.java
com.hdweiss.codemap.util.Utils.java
com.hdweiss.codemap.util.ZoomableAbsoluteLayout.java
com.hdweiss.codemap.util.ZoomableLinearLayout.java
com.hdweiss.codemap.view.CodeMapActivity.java
com.hdweiss.codemap.view.CodeMapTabListener.java
com.hdweiss.codemap.view.Preferences.java
com.hdweiss.codemap.view.project.ProjectAdapter.java
com.hdweiss.codemap.view.project.ProjectBrowser.java
com.hdweiss.codemap.view.project.ProjectItemView.java
com.hdweiss.codemap.view.project.ProjectWizard.java
com.hdweiss.codemap.view.workspace.CollisionManager.java
com.hdweiss.codemap.view.workspace.FindDeclarationTask.java
com.hdweiss.codemap.view.workspace.WorkspaceController.java
com.hdweiss.codemap.view.workspace.WorkspaceFragment.java
com.hdweiss.codemap.view.workspace.WorkspaceStateLoader.java
com.hdweiss.codemap.view.workspace.WorkspaceState.java
com.hdweiss.codemap.view.workspace.WorkspaceViewListeners.java
com.hdweiss.codemap.view.workspace.WorkspaceView.java
com.hdweiss.codemap.view.workspace.browser.WorkspaceBrowserAdapter.java
com.hdweiss.codemap.view.workspace.browser.WorkspaceBrowser.java
com.hdweiss.codemap.view.workspace.fragments.CodeMapAnnotation.java
com.hdweiss.codemap.view.workspace.fragments.CodeMapFunction.java
com.hdweiss.codemap.view.workspace.fragments.CodeMapImage.java
com.hdweiss.codemap.view.workspace.fragments.CodeMapItem.java
com.hdweiss.codemap.view.workspace.fragments.CodeMapLink.java
com.hdweiss.codemap.view.workspace.fragments.FunctionLinkSpan.java
com.hdweiss.codemap.view.workspace.outline.CscopeEntryAdapter.java
com.hdweiss.codemap.view.workspace.outline.OutlineAdapter.java
com.hdweiss.codemap.view.workspace.outline.OutlineBrowser.java
com.hdweiss.codemap.view.workspace.outline.OutlineItemComparator.java
com.hdweiss.codemap.view.workspace.outline.OutlineItemView.java
com.hdweiss.codemap.view.workspace.outline.OutlineItem.java