Android Open Source - codemap Cscope






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  ww w  .  j  av a 2  s .c  om
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.Arrays;
import java.util.NoSuchElementException;

import android.content.Context;
import android.text.TextUtils;
import android.util.Log;

import com.hdweiss.codemap.util.Utils;

public class Cscope {
  public final static boolean WITH_INDEX = true;
  public final static boolean NO_INDEX = false;
  public final static boolean WITH_REFFILE = true;
  public final static boolean NO_REFFILE = false;
  
  private final static String EXE_FILENAME = "cscope";
  private final static String BUILDINDEX_OPTIONS = "-b -q";
  private final static String SEARCH_PATTERN = "-iname \'*.c\' -o -iname \'*.h\'";
  
  private final static String CSCOPE_NAMEFILE = "cscope.files";
  private final static String CSCOPE_REFFILE = "cscope.out";
  
  private Context context;
  private String cscopeExecPath = "";

  public Cscope(Context context) {
    this.context = context;

    prepareExecutable();
  }

  private void prepareExecutable() {
    try {
      context.openFileInput(EXE_FILENAME);
    } catch (FileNotFoundException e) {
      copyExecutableToInternalStorage();
    } finally {
      File file = context.getFileStreamPath(EXE_FILENAME);
      if (file.exists() && file.canExecute()) {
        this.cscopeExecPath = file.getAbsolutePath();
      }
    }
  }

  private void copyExecutableToInternalStorage() {
    try {
      InputStream is = context.getAssets().open(EXE_FILENAME);
      byte[] buffer = new byte[is.available()];
      is.read(buffer);
      is.close();

      FileOutputStream fos = context.openFileOutput(EXE_FILENAME,
          Context.MODE_PRIVATE);
      fos.write(buffer);
      fos.close();

      File file = context.getFileStreamPath(EXE_FILENAME);
      file.setExecutable(true);
    } catch (IOException e) {
      e.printStackTrace();
    }
  }
  
  public String runCommand(Project project, String options) {
    return runCommand(project, options, true, true);
  }
  
  public String runCommand(Project project, String options, String fileName) {
    if (TextUtils.isEmpty(fileName) == false && new File(fileName).exists())
      return runCommand(project, options + " " + fileName, false, false);
    else {
      Log.e("Cscope", "runCommand got invalid file: " + fileName);
      return runCommand(project, options, true, true);      
    }
  }
  
  private String runCommand(Project project, String options, boolean includeIndex, boolean includeReffile) {
    if (this.cscopeExecPath == null || this.cscopeExecPath.isEmpty()) {
      Log.e("CodeMap", "Could not get path to" + EXE_FILENAME + "executable");
      return "";
    }
    
    String command = getCscopeCommand(project, options, includeIndex, includeReffile);
    Log.d("Cscope", "runCommand: " + command);
    
    File tmpdir = context.getFilesDir();
    String[] environment = {"TMPDIR=" + tmpdir.getAbsolutePath()};
    String output = Utils.runCommand(command, environment);
    return output;
  }
  
  private String getCscopeCommand(Project project, String options, boolean includeIndex, boolean includeReffile) {
    StringBuilder builder = new StringBuilder();
    builder.append(this.cscopeExecPath).append(" ");
    if(includeIndex)
      builder.append("-i ").append(getNamefilePath(project.getName())).append(" ");
    
    if(includeReffile)
      builder.append("-f ").append(getReffilePath(project.getName())).append(" ");
    else
      builder.append("-f ").append(getReffilePath(project.getName())).append(".temp ");

      
    builder.append("-P ").append(project.getSourcePath(context)).append(" ");
    builder.append(options);
    return builder.toString();
  }
  
  /***************/
  
  public String generateNamefile(Project project) {
    String command = "find " + project.getSourcePath(context) + " " + SEARCH_PATTERN
        + ">" + getNamefilePath(project.getName());
    return Utils.runCommand(command);
  }
  
  public void deleteNamefile(String projectName) {
    File file = new File(getNamefilePath(projectName));
    file.delete();
  }
  
  private String getNamefilePath (String projectName) {
    File directory = Project.getProjectDirectory(projectName, context);
    return directory.getAbsolutePath() + File.separator + CSCOPE_NAMEFILE;
  }
  
  public FileInputStream getNamefileStream(String projectName) throws FileNotFoundException {
    File namefile = new File(Project.getProjectDirectory(projectName,
        context) + File.separator + CSCOPE_NAMEFILE);
    return new FileInputStream(namefile);
  }
  
  public String[] getFiles(Project project) throws FileNotFoundException {    
    FileInputStream stream = getNamefileStream(project.getName());
    
    String contents;
    try {
       contents = Utils.inputStreamToString(stream);
    } catch (NoSuchElementException e) {
      throw new FileNotFoundException(e.getLocalizedMessage());
    }
    
    String[] files = contents.trim().split("\n");
    
    int pathLength = project.getSourcePath(context).length() + 1;
    for(int i = 0; i < files.length; i++)
      files[i] = files[i].substring(pathLength);
    
    Arrays.sort(files);
    
    return files;
  }
  
  /******************/

  public String generateReffile(Project project) {
    return runCommand(project, BUILDINDEX_OPTIONS);
  }

  public void deleteReffile(String projectName) {
    File file = new File(getReffilePath(projectName));
    file.delete();
  }
  
  private String getReffilePath(String projectName) {    
    File directory = Project.getProjectDirectory(projectName, context);
    return directory.getAbsolutePath() + File.separator + CSCOPE_REFFILE;
  }
  
  public FileInputStream getReffileStream(String projectName) throws FileNotFoundException {
    File namefile = new File(Project.getProjectDirectory(projectName,
        context) + File.separator + CSCOPE_REFFILE);
    return new FileInputStream(namefile);
  }
}




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