Ejemplo n.º 1
0
 @Override
 public ReferenceContainer<ReferenceType> reduce(
     final ReferenceContainer<ReferenceType> container) {
   container.sort();
   container.removeEntries(this.urlHashes);
   return container;
 }
Ejemplo n.º 2
0
  /**
   * count number of references for a given term this method may cause strong IO load if called too
   * frequently.
   */
  @Override
  public int count(final byte[] termHash) {
    final Integer cachedCount = this.countCache.get(termHash);
    if (cachedCount != null) return cachedCount.intValue();

    int countFile = 0;
    // read fresh values from file
    try {
      countFile = this.array.count(termHash);
    } catch (final Throwable e) {
      ConcurrentLog.logException(e);
    }
    assert countFile >= 0;

    // count from container in ram
    final ReferenceContainer<ReferenceType> countRam = this.ram.get(termHash, null);
    assert countRam == null || countRam.size() >= 0;
    int c = countRam == null ? countFile : countFile + countRam.size();
    // exclude entries from delayed remove
    synchronized (this.removeDelayedURLs) {
      final HandleSet s = this.removeDelayedURLs.get(termHash);
      if (s != null) c -= s.size();
      if (c < 0) c = 0;
    }
    // put count result into cache
    if (MemoryControl.shortStatus()) this.countCache.clear();
    this.countCache.insert(termHash, c);
    return c;
  }
Ejemplo n.º 3
0
 public int deleteOld(int minsize, long maxtime) throws IOException {
   long timeout = System.currentTimeMillis() + maxtime;
   Collection<byte[]> keys = keys4LargeReferences(minsize, maxtime / 3);
   int c = 0;
   int oldShrinkMaxsize = ReferenceContainer.maxReferences;
   ReferenceContainer.maxReferences = minsize;
   for (byte[] key : keys) {
     ReferenceContainer<ReferenceType> container = this.get(key, null);
     container.shrinkReferences();
     try {
       this.add(container);
       c++;
     } catch (SpaceExceededException e) {
     }
     if (System.currentTimeMillis() > timeout) break;
   }
   ReferenceContainer.maxReferences = oldShrinkMaxsize;
   return c;
 }
Ejemplo n.º 4
0
 /**
  * deleting a container affects the containers in RAM and all the BLOB files the deleted
  * containers are merged and returned as result of the method
  *
  * @throws IOException
  */
 @Override
 public ReferenceContainer<ReferenceType> remove(final byte[] termHash) throws IOException {
   removeDelayed();
   ReferenceContainer<ReferenceType> c1 = null;
   try {
     c1 = this.array.get(termHash);
   } catch (final SpaceExceededException e2) {
     ConcurrentLog.logException(e2);
   }
   if (c1 != null) {
     this.array.delete(termHash);
   }
   final ReferenceContainer<ReferenceType> c0 = this.ram.remove(termHash);
   if (c1 == null) return c0;
   if (c0 == null) return c1;
   try {
     return c1.merge(c0);
   } catch (final SpaceExceededException e) {
     // try to free some ram
     try {
       return c1.merge(c0);
     } catch (final SpaceExceededException e1) {
       // go silently over the problem
       return (c1.size() > c0.size()) ? c1 : c0;
     }
   }
 }
Ejemplo n.º 5
0
  public boolean execute(Project project, long contentLength, InputStream content)
      throws Throwable {
    Ant ant = (Ant) project.createTask("ant");
    File baseDir = project.getBaseDir();
    if (dir != null) baseDir = new File(dir);
    ant.setDir(baseDir);
    ant.setInheritAll(inheritall);
    ant.setInheritRefs(interitrefs);

    if (target != null) ant.setTarget(target);

    if (antFile != null) ant.setAntfile(antFile);

    Enumeration e = properties.elements();
    PropertyContainer pc = null;
    Property p = null;
    while (e.hasMoreElements()) {
      pc = (PropertyContainer) e.nextElement();
      p = ant.createProperty();
      p.setName(pc.getName());
      p.setValue(pc.getValue());
    }

    e = references.elements();
    ReferenceContainer rc = null;
    Ant.Reference ref = null;
    while (e.hasMoreElements()) {
      rc = (ReferenceContainer) e.nextElement();
      ref = new Ant.Reference();
      ref.setRefId(rc.getRefId());
      ref.setToRefid(rc.getToRefId());
      ant.addReference(ref);
    }

    ant.execute();

    return false;
  }
Ejemplo n.º 6
0
 /**
  * all containers in the BLOBs and the RAM are merged and returned. Please be aware that the
  * returned values may be top-level cloned ReferenceContainers or direct links to containers If
  * the containers are modified after they are returned, they MAY alter the stored index.
  *
  * @throws IOException
  * @return a container with merged ReferenceContainer from RAM and the file array or null if there
  *     is no data to be returned
  */
 @Override
 public ReferenceContainer<ReferenceType> get(final byte[] termHash, final HandleSet urlselection)
     throws IOException {
   final ReferenceContainer<ReferenceType> c0 = this.ram.get(termHash, null);
   ReferenceContainer<ReferenceType> c1 = null;
   try {
     c1 = this.array.get(termHash);
   } catch (final SpaceExceededException e2) {
     ConcurrentLog.logException(e2);
   }
   ReferenceContainer<ReferenceType> result = null;
   if (c0 != null && c1 != null) {
     try {
       result = c1.merge(c0);
     } catch (final SpaceExceededException e) {
       // try to free some ram
       try {
         result = c1.merge(c0);
       } catch (final SpaceExceededException e1) {
         // go silently over the problem
         result = (c1.size() > c0.size()) ? c1 : c0;
       }
     }
   } else if (c0 != null) {
     result = c0;
   } else if (c1 != null) {
     result = c1;
   }
   if (result == null) return null;
   // remove the failed urls
   synchronized (this.removeDelayedURLs) {
     final HandleSet s = this.removeDelayedURLs.get(termHash);
     if (s != null) result.removeEntries(s);
   }
   return result;
 }
Ejemplo n.º 7
0
  /**
   * Creates all the project data structures. These include the reference completions (BibTeX and
   * label), command completions, the preamble, the BibTeX style.
   *
   * @param project The current project
   */
  private void createProjectDatastructs(IProject project) {
    // IResource resource = ((FileEditorInput)editor.getEditorInput()).getFile();

    IResource[] files = TexlipseProperties.getAllProjectFiles(project);

    if (files != null) {
      IFile mainFile = TexlipseProperties.getProjectSourceFile(project);

      for (int i = 0; i < files.length; i++) {
        // IPath path = files[i].getFullPath();
        String ext = files[i].getFileExtension();
        // here are the file types we want to parse
        if ("tex".equals(ext) || "ltx".equals(ext) || "sty".equals(ext)) {
          try {
            String input = TexlipseProperties.getFileContents(files[i]);
            LatexRefExtractingParser lrep = new LatexRefExtractingParser();
            lrep.parse(input);
            if (lrep.isFatalErrors()) {
              MarkerHandler marker = MarkerHandler.getInstance();
              marker.addFatalError(
                  editor,
                  "The file "
                      + files[i].getFullPath()
                      + " contains fatal errors, parsing aborted.");
              continue;
            }
            List<ReferenceEntry> labels = lrep.getLabels();
            if (labels.size() > 0) {
              labelContainer.addRefSource(files[i].getProjectRelativePath().toString(), labels);
            }
            List<TexCommandEntry> commands = lrep.getCommands();
            if (commands.size() > 0) {
              commandContainer.addRefSource(files[i].getProjectRelativePath().toString(), commands);
            }
            // Only update Preamble, Bibstyle if main Document
            if (files[i].equals(mainFile)) {
              String[] bibs = lrep.getBibs();
              boolean biblatexMode = lrep.isBiblatexMode();
              String biblatexBackend = lrep.getBiblatexBackend();
              this.updateBiblatex(project, biblatexMode, biblatexBackend, true);
              this.updateBibs(bibs, biblatexMode, files[i]);

              String preamble = lrep.getPreamble();
              if (preamble != null) {
                TexlipseProperties.setSessionProperty(
                    project, TexlipseProperties.PREAMBLE_PROPERTY, preamble);
              }

              String bibstyle = lrep.getBibstyle();
              if (bibstyle != null)
                TexlipseProperties.setSessionProperty(
                    project, TexlipseProperties.BIBSTYLE_PROPERTY, bibstyle);
            }
          } catch (IOException ioe) {
            TexlipsePlugin.log(
                "Unable to open file " + files[i].getFullPath() + " for parsing", ioe);
          }
        }
      }
      // save time by doing this last
      labelContainer.organize();
      commandContainer.organize();
    }
  }
Ejemplo n.º 8
0
 /**
  * Updates the labels.
  *
  * @param labels
  */
 private void updateLabels(List<ReferenceEntry> labels) {
   IResource resource = getFile();
   if (resource == null) return;
   labelContainer.addRefSource(resource.getProjectRelativePath().toString(), labels);
   labelContainer.organize();
 }
Ejemplo n.º 9
0
  /**
   * Updates completions for the BibTeX -data
   *
   * @param bibNames Names of the BibTeX -files that the document uses
   * @param resource The resource of the document
   */
  private void updateBibs(String[] bibNames, boolean biblatexMode, IResource resource) {
    IProject project = getCurrentProject();
    if (project == null) return;

    if (!biblatexMode) {
      for (int i = 0; i < bibNames.length; i++) {
        if (!bibNames[i].endsWith(".bib")) {
          bibNames[i] += ".bib";
        }
      }
    }

    if (bibContainer.checkFreshness(bibNames)) {
      return;
    }

    TexlipseProperties.setSessionProperty(project, TexlipseProperties.BIBFILE_PROPERTY, bibNames);

    List<String> newBibs = bibContainer.updateBibHash(bibNames);

    IPath path = resource.getFullPath().removeFirstSegments(1).removeLastSegments(1);
    if (!path.isEmpty()) path = path.addTrailingSeparator();

    KpsewhichRunner filesearch = new KpsewhichRunner();

    for (Iterator<String> iter = newBibs.iterator(); iter.hasNext(); ) {
      String name = iter.next();
      try {
        String filepath = "";
        // First try local search
        IResource res = project.findMember(path + name);
        // Try searching relative to main file
        if (res == null) {
          IContainer sourceDir = TexlipseProperties.getProjectSourceDir(project);
          res = sourceDir.findMember(name);
        }

        if (res != null) {
          filepath = res.getLocation().toOSString();
        }
        if (res == null) {
          // Try Kpsewhich
          filepath = filesearch.getFile(resource, name, "bibtex");
          if (filepath.length() > 0 && !(new File(filepath).isAbsolute())) {
            // filepath is a local path
            res = project.findMember(path + filepath);
            if (res != null) {
              filepath = res.getLocation().toOSString();
            } else {
              filepath = "";
            }
          } else if (filepath.length() > 0) {
            // Create a link to resource
            IPath p = new Path(filepath);
            if (name.indexOf('/') >= 0) {
              // Remove path from name
              name = name.substring(name.lastIndexOf('/') + 1);
            }
            IFile f = project.getFile(path + name);
            if (f != null && !f.exists()) {
              f.createLink(p, IResource.NONE, null);
            }
          }
        }

        if (filepath.length() > 0) {
          BibParser parser = new BibParser(filepath);
          try {
            List<ReferenceEntry> bibEntriesList = parser.getEntries();
            if (bibEntriesList != null && bibEntriesList.size() > 0) {
              bibContainer.addRefSource(path + name, bibEntriesList);
            } else if (bibEntriesList == null) {
              MarkerHandler marker = MarkerHandler.getInstance();
              marker.addFatalError(
                  editor,
                  "The BibTeX file " + filepath + " contains fatal errors, parsing aborted.");
              continue;
            }
          } catch (IOException ioe) {
            TexlipsePlugin.log("Can't read BibTeX file " + filepath, ioe);
          }
        } else {
          MarkerHandler marker = MarkerHandler.getInstance();
          marker.addFatalError(editor, "The BibTeX file " + name + " not found.");
        }

      } catch (CoreException ce) {
        TexlipsePlugin.log("Can't run Kpathsea", ce);
      }
    }
    bibContainer.organize();
  }
Ejemplo n.º 10
0
  /**
   * Parses the LaTeX-document and adds error markers if there were any errors. Throws <code>
   * TexDocumentParseException</code> if there were fatal parse errors that prohibit building an
   * outline.
   *
   * @param monitor
   * @throws TexDocumentParseException
   */
  private ArrayList<OutlineNode> doParse(IProgressMonitor monitor)
      throws TexDocumentParseException {

    if (this.parser == null) {
      this.parser =
          new TexParser(editor.getDocumentProvider().getDocument(editor.getEditorInput()));
    }
    if (projectOutline == null) {
      createProjectOutline();
    }

    try {
      parser.parseDocument(sectionCheckEnabled);
    } catch (IOException e) {
      TexlipsePlugin.log("Can't read file.", e);
      throw new TexDocumentParseException(e);
    }
    pollCancel(monitor);

    List<ParseErrorMessage> errors = parser.getErrors();
    List<ParseErrorMessage> tasks = parser.getTasks();
    MarkerHandler marker = MarkerHandler.getInstance();

    // somewhat inelegantly ensures that errors marked in createProjectDatastructs()
    // aren't removed immediately
    if (!firstRun) {
      marker.clearErrorMarkers(editor);
      marker.clearTaskMarkers(editor);
    } else {
      firstRun = false;
    }

    if (editor.getProject() != null && editor.getFullOutline() != null) {
      IResource res = (IResource) editor.getEditorInput().getAdapter(IResource.class);
      String fileName = res.getProjectRelativePath().toString();
      projectOutline.addOutline(parser.getOutlineTree(), fileName);

      List<OutlineNode> fo = projectOutline.getFullOutline();
      postParseJob.setFONodes(fo);
    } else {
      postParseJob.setFONodes(null);
    }
    pollCancel(monitor);

    processIncludes(parser.getInputs(), editor.getEditorInput());

    if (errors.size() > 0) {
      marker.createErrorMarkers(editor, errors);
    }
    if (tasks.size() > 0) {
      marker.createTaskMarkers(editor, tasks);
    }
    if (parser.isFatalErrors()) {
      throw new TexDocumentParseException("Fatal errors in file, parsing aborted.");
    }

    updateReferences(monitor);

    List<DocumentReference> cites = parser.getCites();
    List<DocumentReference> bibErrors = null;
    for (DocumentReference cite : cites) {
      if (!bibContainer.binTest(cite.getKey())) {
        if (bibErrors == null) bibErrors = new ArrayList<DocumentReference>();
        bibErrors.add(cite);
      }
    }
    if (bibErrors != null) {
      marker.createReferencingErrorMarkers(editor, bibErrors);
    }

    List<DocumentReference> refs = parser.getRefs();
    List<DocumentReference> refErrors = null;
    for (DocumentReference ref : refs) {
      if (!labelContainer.binTest(ref.getKey())) {
        if (refErrors == null) refErrors = new ArrayList<DocumentReference>();
        refErrors.add(ref);
      }
    }
    if (refErrors != null) {
      marker.createReferencingErrorMarkers(editor, refErrors);
    }

    return this.parser.getOutlineTree();
  }