Пример #1
0
  /**
   * Processes import statements to obtain classpaths of contributed libraries. This would be needed
   * for compilation check. Also, adds stuff(jar files, class files, candy) from the code folder.
   * And it looks messed up.
   */
  private void prepareCompilerClasspath() {
    if (!loadCompClass) return;
    // System.out.println("1..");
    classpathJars = new ArrayList<URL>();
    String entry = "";
    boolean codeFolderChecked = false;
    for (ImportStatement impstat : programImports) {
      String item = impstat.importName;
      int dot = item.lastIndexOf('.');
      entry = (dot == -1) ? item : item.substring(0, dot);

      entry = entry.substring(6).trim();
      // System.out.println("Entry--" + entry);
      if (ignorableImport(entry)) {
        // System.out.println("Ignoring: " + entry);
        continue;
      }
      Library library = null;

      // Try to get the library classpath and add it to the list
      try {
        library = editor.getMode().getLibrary(entry);
        // System.out.println("lib->" + library.getClassPath() + "<-");
        String libraryPath[] =
            PApplet.split(library.getClassPath().substring(1).trim(), File.pathSeparatorChar);
        for (int i = 0; i < libraryPath.length; i++) {
          // System.out.println(entry + " ::"
          // + new File(libraryPath[i]).toURI().toURL());
          classpathJars.add(new File(libraryPath[i]).toURI().toURL());
        }
        // System.out.println("-- ");
        // classpath[count] = (new File(library.getClassPath()
        // .substring(1))).toURI().toURL();
        // System.out.println("  found ");
        // System.out.println(library.getClassPath().substring(1));
      } catch (Exception e) {
        if (library == null && !codeFolderChecked) {
          // System.out.println(1);
          // Look around in the code folder for jar files
          if (editor.getSketch().hasCodeFolder()) {
            File codeFolder = editor.getSketch().getCodeFolder();

            // get a list of .jar files in the "code" folder
            // (class files in subfolders should also be picked up)
            String codeFolderClassPath = Base.contentsToClassPath(codeFolder);
            codeFolderChecked = true;
            if (codeFolderClassPath.equalsIgnoreCase("")) {
              System.err.println(
                  "XQMODE: Yikes! Can't find \""
                      + entry
                      + "\" library! Line: "
                      + impstat.lineNumber
                      + " in tab: "
                      + editor.getSketch().getCode(impstat.tab).getPrettyName());
              System.out.println(
                  "Please make sure that the library is present in <sketchbook "
                      + "folder>/libraries folder or in the code folder of your sketch");
            }
            String codeFolderPath[] =
                PApplet.split(codeFolderClassPath.substring(1).trim(), File.pathSeparatorChar);
            try {
              for (int i = 0; i < codeFolderPath.length; i++) {
                classpathJars.add(new File(codeFolderPath[i]).toURI().toURL());
              }

            } catch (Exception e2) {
              System.out.println("Yikes! codefolder, prepareImports(): " + e2);
            }
          } else {
            System.err.println(
                "XQMODE: Yikes! Can't find \""
                    + entry
                    + "\" library! Line: "
                    + impstat.lineNumber
                    + " in tab: "
                    + editor.getSketch().getCode(impstat.tab).getPrettyName());
            System.out.println(
                "Please make sure that the library is present in <sketchbook "
                    + "folder>/libraries folder or in the code folder of your sketch");
          }

        } else {
          System.err.println("Yikes! There was some problem in prepareImports(): " + e);
          System.err.println("I was processing: " + entry);

          // e.printStackTrace();
        }
      }
    }
  }