//  public void addPackageList(HashMap<String,Library> importToLibraryTable) {
 public void addPackageList(Map<String, List<Library>> importToLibraryTable) {
   //    PApplet.println(packages);
   for (String pkg : packageList) {
     //          pw.println(pkg + "\t" + libraryFolder.getAbsolutePath());
     //      PApplet.println(pkg + "\t" + getName());
     //      Library library = importToLibraryTable.get(pkg);
     List<Library> libraries = importToLibraryTable.get(pkg);
     if (libraries == null) {
       libraries = new ArrayList<Library>();
       importToLibraryTable.put(pkg, libraries);
     } else {
       if (Base.DEBUG) {
         System.err.println("The library found in");
         System.err.println(getPath());
         System.err.println("conflicts with");
         for (Library library : libraries) {
           System.err.println(library.getPath());
         }
         System.err.println("which already define(s) the package " + pkg);
         System.err.println("If you have a line in your sketch that reads");
         System.err.println("import " + pkg + ".*;");
         System.err.println("Then you'll need to first remove one of those libraries.");
         System.err.println();
       }
     }
     libraries.add(this);
   }
 }
 public static boolean hasMultipleArch(int platform, List<Library> libraries) {
   for (Library library : libraries) {
     if (library.hasMultipleArch(platform)) {
       return true;
     }
   }
   return false;
 }
  protected void updateContributionListing() {
    if (editor != null) {
      List<Contribution> contributions = new ArrayList<Contribution>();

      List<Library> libraries = new ArrayList<Library>(editor.getMode().contribLibraries);

      // Only add core libraries that are installed in the sketchbook
      // https://github.com/processing/processing/issues/3688
      // libraries.addAll(editor.getMode().coreLibraries);
      final String sketchbookPath = Base.getSketchbookLibrariesFolder().getAbsolutePath();
      for (Library lib : editor.getMode().coreLibraries) {
        if (lib.getLibraryPath().startsWith(sketchbookPath)) {
          libraries.add(lib);
        }
      }

      contributions.addAll(libraries);

      Base base = editor.getBase();

      List<ToolContribution> tools = base.getToolContribs();
      contributions.addAll(tools);

      List<ModeContribution> modes = base.getModeContribs();
      contributions.addAll(modes);

      List<ExamplesContribution> examples = base.getExampleContribs();
      contributions.addAll(examples);

      //    ArrayList<LibraryCompilation> compilations = LibraryCompilation.list(libraries);
      //
      //    // Remove libraries from the list that are part of a compilations
      //    for (LibraryCompilation compilation : compilations) {
      //      Iterator<Library> it = libraries.iterator();
      //      while (it.hasNext()) {
      //        Library current = it.next();
      //        if (compilation.getFolder().equals(current.getFolder().getParentFile())) {
      //          it.remove();
      //        }
      //      }
      //    }

      contribListing.updateInstalledList(contributions);
    }
  }
Exemple #4
0
  public Runner(JavaBuild build, RunnerListener listener) throws SketchException {
    this.listener = listener;
    //    this.sketch = sketch;
    this.build = build;

    if (listener instanceof Editor) {
      this.editor = (Editor) listener;
      sketchErr = editor.getConsole().getErr();
      sketchOut = editor.getConsole().getOut();
    } else {
      sketchErr = System.err;
      sketchOut = System.out;
    }

    // Make sure all the imported libraries will actually run with this setup.
    int bits = Base.getNativeBits();
    for (Library library : build.getImportedLibraries()) {
      if (!library.supportsArch(PApplet.platform, bits)) {
        sketchErr.println(library.getName() + " does not run in " + bits + "-bit mode.");
        int opposite = (bits == 32) ? 64 : 32;
        if (Base.isMacOS()) {
          // if (library.supportsArch(PConstants.MACOSX, opposite)) {  // should always be true
          throw new SketchException(
              "To use "
                  + library.getName()
                  + ", "
                  + "switch to "
                  + opposite
                  + "-bit mode in Preferences.");
          // }
        } else {
          throw new SketchException(
              library.getName()
                  + " is only compatible "
                  + "with the  "
                  + opposite
                  + "-bit download of Processing.");
          // throw new SketchException(library.getName() + " does not run in " + bits + "-bit
          // mode.");
          // "To use this library, switch to 32-bit mode in Preferences." (OS X)
          //  "To use this library, you must use the 32-bit version of Processing."
        }
      }
    }
  }
  /**
   * 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();
        }
      }
    }
  }