public Object getSourceElement(IStackFrame stackFrame) {
    if (stackFrame instanceof ScriptStackFrame) {
      ScriptStackFrame sf = (ScriptStackFrame) stackFrame;
      URI uri = sf.getFileName();

      String pathname = uri.getPath();
      if (Platform.getOS().equals(Platform.OS_WIN32)) {
        pathname = pathname.substring(1);
      }

      File file = new File(pathname);

      IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
      IContainer container = root.getContainerForLocation(new Path(file.getParent()));

      if (container != null) {
        IResource resource = container.findMember(file.getName());

        if (resource instanceof IFile) {
          return (IFile) resource;
        }
      } else {
        return file;
      }
    }

    return null;
  }
Example #2
0
  private static void recursivelyFindFilesWithExtension(
      ArrayList<IResource> allFiles, IPath path, IWorkspaceRoot wsRoot, String extension) {
    IContainer container = wsRoot.getContainerForLocation(path);

    try {
      IResource[] resources = container.members();
      for (IResource resource : resources) {
        if (extension.equalsIgnoreCase(resource.getFileExtension())) {
          allFiles.add(resource);
        }
        if (resource.getType() == IResource.FOLDER) {
          IPath tempPath = resource.getLocation();
          recursivelyFindFilesWithExtension(allFiles, tempPath, wsRoot, extension);
        }
      }
    } catch (CoreException e) {
      // eat the exception, but throw it in the console
      e.printStackTrace();
    }
  }
Example #3
0
  @SuppressWarnings("unchecked")
  public Object getAdapter(Object adaptableObject, Class adapterType) {
    if (adapterType.isAssignableFrom(IHistoryPageSource.class)) {
      return historyPageSource;
    }

    if (IWorkbenchAdapter.class == adapterType) {
      if (adaptableObject instanceof RepositoryNode)
        return getRepsitoryNodeWorkbenchAdapter((RepositoryNode) adaptableObject);

      if (gitModelWorkbenchAdapter == null)
        gitModelWorkbenchAdapter = new GitModelWorkbenchAdapter();
      return gitModelWorkbenchAdapter;
    }

    if (adaptableObject instanceof GitModelObject && adapterType == ResourceMapping.class)
      return GitObjectMapping.create((GitModelObject) adaptableObject);

    if (adaptableObject instanceof GitModelObject && adapterType == IResource.class) {
      GitModelObject obj = (GitModelObject) adaptableObject;

      if (obj instanceof GitModelBlob) {
        IResource res = root.getFileForLocation(obj.getLocation());
        if (res == null) res = root.getFile(obj.getLocation());

        return res;
      }

      if (obj instanceof GitModelTree) {
        IResource res = root.getContainerForLocation(obj.getLocation());
        if (res == null) res = root.getFolder(obj.getLocation());

        return res;
      }
    }

    return null;
  }