/**
  * Initializes variables, which are often reused. This should be called every time there is a
  * chance that project settings have been changed.
  */
 public void init() {
   sourceDir = TexlipseProperties.getProjectSourceDir(project);
   outputDir = TexlipseProperties.getProjectOutputDir(project);
   tempDir = TexlipseProperties.getProjectTempDir(project);
   format = TexlipseProperties.getProjectProperty(project, TexlipseProperties.OUTPUT_FORMAT);
   sourceFile = TexlipseProperties.getProjectSourceFile(project);
 }
示例#2
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();
  }