/** @see IActionDelegate#run(IAction) */
  protected void doRun() {
    IRunnableWithProgress code =
        new IRunnableWithProgress() {

          public void run(IProgressMonitor monitor)
              throws InvocationTargetException, InterruptedException {
            monitor.beginTask(
                Messages.getString("ChangeLog.PrepareChangeLog"), 1000); // $NON-NLS-1$
            prepareChangeLog(monitor);
            monitor.done();
          }
        };

    ProgressMonitorDialog pd =
        new ProgressMonitorDialog(getWorkbench().getActiveWorkbenchWindow().getShell());

    try {
      pd.run(false /* fork */, false /* cancelable */, code);
    } catch (InvocationTargetException e) {
      ChangelogPlugin.getDefault()
          .getLog()
          .log(
              new Status(
                  IStatus.ERROR, ChangelogPlugin.PLUGIN_ID, IStatus.ERROR, e.getMessage(), e));
      return;
    } catch (InterruptedException e) {
      ChangelogPlugin.getDefault()
          .getLog()
          .log(
              new Status(
                  IStatus.ERROR, ChangelogPlugin.PLUGIN_ID, IStatus.ERROR, e.getMessage(), e));
    }
  }
Exemplo n.º 2
0
 private int findChangeLogPattern(IDocument changelog_doc, int startOffset) {
   // find the "pattern" of a changelog entry. Not a specific one,
   // but one that "looks" like an entry
   int nextEntry = startOffset;
   int line_length = 0;
   String entry = ""; // $NON-NLS-1$
   while (nextEntry < changelog_doc.getLength()) {
     try {
       // Get the line of interest in the changelog document
       line_length = changelog_doc.getLineOfOffset(nextEntry);
       entry = changelog_doc.get(nextEntry, changelog_doc.getLineLength(line_length));
       // Attempt to find date pattern on line
       if (matchDatePattern(entry)) {
         // nextDate -= entry.length()+1;
         break;
       }
       // If no date matches, move to the next line
       nextEntry += changelog_doc.getLineLength(line_length);
     } catch (BadLocationException e) {
       ChangelogPlugin.getDefault()
           .getLog()
           .log(
               new Status(
                   IStatus.ERROR, ChangelogPlugin.PLUGIN_ID, IStatus.ERROR, e.getMessage(), e));
     }
   }
   return nextEntry;
 }
  private String parseCurrentFunctionAtOffset(String editorName, IEditorInput input, int offset) {

    IParserChangeLogContrib parser = extensionManager.getParserContributor(editorName);

    // return empty string if function parser for editorName is not present
    if (parser == null) return "";

    try {
      return parser.parseCurrentFunction(input, offset);
    } catch (CoreException e) {
      ChangelogPlugin.getDefault()
          .getLog()
          .log(
              new Status(
                  IStatus.ERROR, ChangelogPlugin.PLUGIN_ID, IStatus.ERROR, e.getMessage(), e));
    }
    return "";
  }
Exemplo n.º 4
0
  private int findChangeLogEntry(IDocument changelog_doc, String entry) {
    FindReplaceDocumentAdapter findDocumentAptd = new FindReplaceDocumentAdapter(changelog_doc);
    IRegion region = null;
    try {
      region = findDocumentAptd.find(0, entry, true, false, /*whole world */ false, true);
    } catch (BadLocationException e) {
      ChangelogPlugin.getDefault()
          .getLog()
          .log(
              new Status(
                  IStatus.ERROR, ChangelogPlugin.PLUGIN_ID, IStatus.ERROR, e.getMessage(), e));

      return -1;
    }
    if (region != null) {
      // If the user's entry is not at the beginning of the file,
      // make a new entry.
      return region.getOffset() > 0 ? -1 : 0;
    } else return -1;
  }
  /**
   * Guesses the function effected/modified by the patch from local file(newer file).
   *
   * @param patchFileInfo patch file
   * @return array of unique function names
   */
  private String[] guessFunctionNames(PatchFile patchFileInfo) {

    // if this file is new file or removed file, do not guess function files
    // TODO: create an option to include function names on
    // new files or not
    if (patchFileInfo.isNewfile() || patchFileInfo.isRemovedFile()) {
      return new String[] {""};
    }

    String[] fnames = new String[0];
    String editorName = ""; // $NON-NLS-1$

    try {
      IEditorDescriptor ed =
          org.eclipse.ui.ide.IDE.getEditorDescriptor(patchFileInfo.getPath().toOSString());
      editorName = ed.getId().substring(ed.getId().lastIndexOf(".") + 1); // $NON-NLS-1$
    } catch (PartInitException e1) {
      ChangelogPlugin.getDefault()
          .getLog()
          .log(
              new Status(
                  IStatus.ERROR, ChangelogPlugin.PLUGIN_ID, IStatus.ERROR, e1.getMessage(), e1));
      return new String[0];
    }

    // check if the file type is supported

    // get editor input for target file

    IFileEditorInput fei = new FileEditorInput((IFile) patchFileInfo.getResource());

    SourceEditorInput sei = new SourceEditorInput(patchFileInfo.getStorage());

    MyDocumentProvider mdp = new MyDocumentProvider();
    MyStorageDocumentProvider msdp = new MyStorageDocumentProvider();

    try {
      // get document for target file (one for local file, one for repository storage)
      IDocument doc = mdp.createDocument(fei);
      IDocument olddoc = msdp.createDocument(sei);

      HashMap<String, String> functionNamesMap = new HashMap<String, String>();
      ArrayList<String> nameList = new ArrayList<String>();

      // for all the ranges
      for (PatchRangeElement tpre : patchFileInfo.getRanges()) {

        for (int j = tpre.ffromLine; j <= tpre.ftoLine; j++) {

          String functionGuess = "";
          // add func that determines type of file.
          // right now it assumes it's java file.
          if (tpre.isLocalChange()) {
            if ((j < 0) || (j > doc.getNumberOfLines() - 1)) continue; // ignore out of bound lines
            functionGuess = parseCurrentFunctionAtOffset(editorName, fei, doc.getLineOffset(j));
          } else {
            if ((j < 0) || (j > olddoc.getNumberOfLines() - 1))
              continue; // ignore out of bound lines
            functionGuess = parseCurrentFunctionAtOffset(editorName, sei, olddoc.getLineOffset(j));
          }

          // putting it in hashmap will eliminate duplicate
          // guesses.  We use a list to keep track of ordering which
          // is helpful when trying to document a large set of changes.
          if (functionNamesMap.get(functionGuess) == null) nameList.add(functionGuess);
          functionNamesMap.put(functionGuess, functionGuess);
        }
      }

      // dump all unique func. guesses in the order found
      fnames = new String[nameList.size()];
      fnames = nameList.toArray(fnames);

    } catch (CoreException e) {
      ChangelogPlugin.getDefault()
          .getLog()
          .log(
              new Status(
                  IStatus.ERROR, ChangelogPlugin.PLUGIN_ID, IStatus.ERROR, e.getMessage(), e));
    } catch (BadLocationException e) {
      ChangelogPlugin.getDefault()
          .getLog()
          .log(
              new Status(
                  IStatus.ERROR, ChangelogPlugin.PLUGIN_ID, IStatus.ERROR, e.getMessage(), e));
    } catch (Exception e) {
      ChangelogPlugin.getDefault()
          .getLog()
          .log(
              new Status(
                  IStatus.ERROR, ChangelogPlugin.PLUGIN_ID, IStatus.ERROR, e.getMessage(), e));
      e.printStackTrace();
    }
    return fnames;
  }