Пример #1
0
 /** Returns the name of JavaFileObject, similar to {@link java.io.File#getName} */
 public static String getName(final JavaFileObject fo, final boolean noExt) {
   assert fo != null;
   if (fo instanceof Base) {
     Base baseFileObject = (Base) fo;
     if (noExt) {
       return baseFileObject.getName();
     } else {
       StringBuilder sb = new StringBuilder();
       sb.append(baseFileObject.getName());
       sb.append('.'); // NOI18N
       sb.append(baseFileObject.getExt());
       return sb.toString();
     }
   }
   try {
     final URL url = fo.toUri().toURL();
     String path = url.getPath();
     int index1 = path.lastIndexOf('/'); // NOI18N
     int len;
     if (noExt) {
       final int index2 = path.lastIndexOf('.'); // NOI18N
       if (index2 > index1) {
         len = index2;
       } else {
         len = path.length();
       }
     } else {
       len = path.length();
     }
     path = path.substring(index1 + 1, len);
     return path;
   } catch (MalformedURLException e) {
     return null;
   }
 }
  public boolean avrdude(Collection params) throws RunnerException {
    List commandDownloader = new ArrayList();
    commandDownloader.add("avrdude");

    // Point avrdude at its config file since it's in a non-standard location.
    if (Base.isMacOS()) {
      commandDownloader.add("-C" + "hardware/tools/avr/etc/avrdude.conf");
    } else if (Base.isWindows()) {
      String userdir = System.getProperty("user.dir") + File.separator;
      commandDownloader.add("-C" + userdir + "hardware/tools/avr/etc/avrdude.conf");
    } else {
      // ???: is it better to have Linux users install avrdude themselves, in
      // a way that it can find its own configuration file?
      commandDownloader.add("-C" + "hardware/tools/avrdude.conf");
    }

    if (Preferences.getBoolean("upload.verbose")) {
      commandDownloader.add("-v");
      commandDownloader.add("-v");
      commandDownloader.add("-v");
      commandDownloader.add("-v");
    } else {
      commandDownloader.add("-q");
      commandDownloader.add("-q");
    }
    // XXX: quick hack to chop the "atmega" off of "atmega8" and "atmega168",
    // then shove an "m" at the beginning.  won't work for attiny's, etc.
    commandDownloader.add(
        "-pm" + Preferences.get("boards." + Preferences.get("board") + ".build.mcu").substring(6));
    commandDownloader.addAll(params);

    return executeUploadCommand(commandDownloader);
  }
Пример #3
0
  public void paintComponent(Graphics g) {
    if (name == "" && serialport == "") {
      Map<String, String> boardPreferences = Base.getBoardPreferences();
      if (boardPreferences != null) setBoardName(boardPreferences.get("name"));
      else setBoardName("-");
      setSerialPort(Preferences.get("serial.port"));
    }
    g.setColor(background);
    Dimension size = getSize();
    g.fillRect(0, 0, size.width, size.height);

    g.setFont(font);
    g.setColor(foreground);
    int baseline = (high + g.getFontMetrics().getAscent()) / 2;
    g.drawString(text, 6, baseline);

    g.setColor(messageForeground);
    String tmp = name + " on " + serialport;

    Rectangle2D bounds = g.getFontMetrics().getStringBounds(tmp, null);

    g.drawString(tmp, size.width - (int) bounds.getWidth() - 20, baseline);

    if (Base.isMacOS()) {
      g.drawImage(resize, size.width - 20, 0, this);
    }
  }
Пример #4
0
  /**
   * Make sure the sketch hasn't been moved or deleted by some nefarious user. If they did, try to
   * re-create it and save. Only checks to see if the main folder is still around, but not its
   * contents.
   */
  private void ensureExistence() {
    if (sketch.getFolder().exists()) return;

    Base.showWarning(
        tr("Sketch Disappeared"),
        tr(
            "The sketch folder has disappeared.\n "
                + "Will attempt to re-save in the same location,\n"
                + "but anything besides the code will be lost."),
        null);
    try {
      sketch.getFolder().mkdirs();

      for (SketchFile file : sketch.getFiles()) {
        file.save(); // this will force a save
      }
      calcModified();

    } catch (Exception e) {
      Base.showWarning(
          tr("Could not re-save sketch"),
          tr(
              "Could not properly re-save the sketch. "
                  + "You may be in trouble at this point,\n"
                  + "and it might be time to copy and paste "
                  + "your code to another text editor."),
          e);
    }
  }
Пример #5
0
  /** Handler for the Rename Code menu option. */
  public void handleRenameCode() {
    SketchFile current = editor.getCurrentTab().getSketchFile();

    editor.status.clearState();
    // make sure the user didn't hide the sketch folder
    ensureExistence();

    if (current.isPrimary() && editor.untitled) {
      Base.showMessage(
          tr("Sketch is Untitled"),
          tr("How about saving the sketch first \n" + "before trying to rename it?"));
      return;
    }

    // if read-only, give an error
    if (isReadOnly(
        BaseNoGui.librariesIndexer.getInstalledLibraries(), BaseNoGui.getExamplesPath())) {
      // if the files are read-only, need to first do a "save as".
      Base.showMessage(
          tr("Sketch is Read-Only"),
          tr(
              "Some files are marked \"read-only\", so you'll\n"
                  + "need to re-save the sketch in another location,\n"
                  + "and try again."));
      return;
    }

    // ask for new name of file (internal to window)
    // TODO maybe just popup a text area?
    renamingCode = true;
    String prompt = current.isPrimary() ? "New name for sketch:" : "New name for file:";
    String oldName = current.getPrettyName();
    editor.status.edit(prompt, oldName);
  }
Пример #6
0
  public boolean Validate(ParserSession PS, Base ParentObject) {
    int Errs = PS.getErrorCount();
    _ParentObject = ParentObject;

    _ColumnObjs =
        ValidationHelper.ProcessColumn(
            PS,
            ParentObject,
            "JSONMapping '" + _Name + "'",
            _Columns,
            new ValidationHelper.Processor() {
              @Override
              public boolean process(ParserSession PS, Base ParentObject, String What, Column C) {
                if (C._Type == ColumnType.BINARY)
                  PS.AddError(
                      ParentObject.getWhat()
                          + " '"
                          + _ParentObject.getFullName()
                          + "' is defining a JSON mapping with column '"
                          + C.getName()
                          + "' which is a binary. Binaries cannot be JSONed.");
                return true;
              }
            });

    if (_Sync == true && _ParentObject.isOCC() == false)
      PS.AddError(
          ParentObject.getWhat()
              + " '"
              + _ParentObject.getFullName()
              + "' is defining a 'sync' JSON mapping but the parent object is not OCC.");

    return Errs == PS.getErrorCount();
  }
Пример #7
0
 public void allocSiteTest1() {
   String tainted = TelephonyManager.getDeviceId();
   int i = 3;
   Base obj = i > 10 ? new A() : new B();
   String copy = obj.transform(tainted);
   ConnectionManager cm = new ConnectionManager();
   cm.publish(copy);
 }
 public static void main(String[] args) {
   // TODO 自动生成的方法存根
   A a = new p12_25().new C();
   try {
     a.foobar();
   } catch (Base e) {
     e.printStackTrace();
   }
 }
Пример #9
0
  /** Remove a piece of code from the sketch and from the disk. */
  public void handleDeleteCode() throws IOException {
    SketchFile current = editor.getCurrentTab().getSketchFile();
    editor.status.clearState();
    // make sure the user didn't hide the sketch folder
    ensureExistence();

    // if read-only, give an error
    if (isReadOnly(
        BaseNoGui.librariesIndexer.getInstalledLibraries(), BaseNoGui.getExamplesPath())) {
      // if the files are read-only, need to first do a "save as".
      Base.showMessage(
          tr("Sketch is Read-Only"),
          tr(
              "Some files are marked \"read-only\", so you'll\n"
                  + "need to re-save the sketch in another location,\n"
                  + "and try again."));
      return;
    }

    // confirm deletion with user, yes/no
    Object[] options = {tr("OK"), tr("Cancel")};
    String prompt =
        current.isPrimary()
            ? tr("Are you sure you want to delete this sketch?")
            : I18n.format(tr("Are you sure you want to delete \"{0}\"?"), current.getPrettyName());
    int result =
        JOptionPane.showOptionDialog(
            editor,
            prompt,
            tr("Delete"),
            JOptionPane.YES_NO_OPTION,
            JOptionPane.QUESTION_MESSAGE,
            null,
            options,
            options[0]);
    if (result == JOptionPane.YES_OPTION) {
      if (current.isPrimary()) {
        sketch.delete();
        editor.base.handleClose(editor);
      } else {
        // delete the file
        if (!current.delete(sketch.getBuildPath().toPath())) {
          Base.showMessage(
              tr("Couldn't do it"),
              I18n.format(tr("Could not delete \"{0}\"."), current.getFileName()));
          return;
        }

        // just set current tab to the main tab
        editor.selectTab(0);

        // update the tabs
        editor.header.repaint();
      }
    }
  }
  @SmallTest
  @MediumTest
  @LargeTest
  public void testCastingToSameTypeGivesSameObject() {
    Base base = GraphObject.Factory.create(Base.class);

    Base cast = base.cast(Base.class);

    assertTrue(base == cast);
  }
Пример #11
0
  /**
   * Evaluate this bounds. The bounds member is updated.
   *
   * @param size Size of the Window to draw in.
   * @param flags Text Alignment flags.
   * @param posFlags Subzones Side bits.
   * @param transfo A transformation to locate this relatively to a center.
   * @param supCtr Center of the parent satellite (Place center).
   * @param center Center of this before the transformation.
   */
  protected void setTextBnds(
      Dimension size, int flags, int posFlags, Transfo transfo, Point supCtr, Point center) {
    boolean isFloat = Base.isEnabled(flags, FLOAT_BIT);
    int dx = 0,
        dy = 0,
        x = center.x,
        y = center.y,
        w = m_bounds.width,
        h = m_bounds.height,
        w2 = w >> 1,
        h2 = h >> 1;

    if (supCtr != null) {
      dx = x - supCtr.x;
      dy = y - supCtr.y;
    }

    if (Base.isEnabled(flags, CORNER_BIT) && supCtr != null) {
      if ((posFlags & ActiveZone.SIDE_BIT) != 0) {
        x += (posFlags & ActiveZone.LEFT_BIT) != 0 ? w2 : -w2;
      } else {
        if (dx != 0) {
          x += dx > 0 ? w2 : -w2;
        }
      }

      if (dy != 0) {
        y += dy > 0 ? h2 : -h2;
      }
    } else if (isFloat) {
      x += w2;
      y += h2 + 32; // cursor height
    }

    if (transfo != null) {
      Point dp = transfo.getCart();
      x += dp.x;
      y += dp.y;
    }

    x -= w2;
    y -= h2;

    if (isFloat) // avoid boundaries!
    {
      if (x < 0) x = 4;
      else if (x + w - 1 > size.width) x = size.width - 4 - w - 1;

      if (y < 0) y = 4;
      else if (y + h > size.height) y = size.height - 4 - h;
    }

    m_bounds.x = x;
    m_bounds.y = y;
  }
Пример #12
0
  /**
   * It calculates the mean square error(MSE)
   *
   * @param cromosoma it contains the chromosome values
   * @return the mean square error(MSE)
   */
  public double ECM_tra(double[] cromosoma) {
    int i;
    double suma;

    Bs.Decodifica(cromosoma);
    for (i = 0, suma = 0.0; i < long_tabla_tra; i++) {
      double aux = Bs.FLC(tabla_tra[i].ejemplo);
      suma += 0.5 * Math.pow(tabla_tra[i].ejemplo[Bs.getN_var_estado()] - aux, 2.);
    }
    return (suma / (double) this.long_tabla_tra);
  }
Пример #13
0
 @Before
 public void setup() {
   a = new Base();
   b = new Base();
   c = new Super();
   a.x = "a";
   b.x = "b";
   c.x = "c";
   a.y = 11L;
   c.ignore = 12;
 }
Пример #14
0
 public static void applyLAF() {
   try {
     if (Base.isMacOS()) {
       System.setProperty("apple.laf.useScreenMenuBar", "true");
       System.setProperty("com.apple.mrj.application.apple.menu.about.name", "UECIDE");
     }
     UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
   } catch (Exception e) {
     Base.error(e);
   }
 }
  @SmallTest
  @MediumTest
  @LargeTest
  public void testCastingToBaseTypeGivesSameObject() {
    Derived derived = GraphObject.Factory.create(Derived.class);

    Base cast = derived.cast(Base.class);
    assertTrue(derived == cast);

    cast = cast.cast(Derived.class);
    assertTrue(derived == cast);
  }
Пример #16
0
 public static void main(final String[] argv) throws IOException {
   final String filea = argv[argv.length - 2];
   final String fileb = argv[argv.length - 1];
   final String[] a = DiffPrint.slurp(filea);
   final String[] b = DiffPrint.slurp(fileb);
   final Diff d = new Diff(a, b);
   char style = 'n';
   for (int i = 0; i < argv.length - 2; ++i) {
     final String f = argv[i];
     if (f.startsWith("-")) {
       for (int j = 1; j < f.length(); ++j) {
         switch (f.charAt(j)) {
           case 'e': // Ed style
             style = 'e';
             break;
           case 'c': // Context diff
             style = 'c';
             break;
           case 'u':
             style = 'u';
             break;
         }
       }
     }
   }
   final boolean reverse = style == 'e';
   final Diff.change script = d.diff_2(reverse);
   if (script == null) {
     System.err.println("No differences");
   } else {
     Base p;
     switch (style) {
       case 'e':
         p = new EdPrint(a, b);
         break;
       case 'c':
         p = new ContextPrint(a, b);
         break;
       case 'u':
         p = new UnifiedPrint(a, b);
         break;
       default:
         p = new NormalPrint(a, b);
     }
     p.print_header(filea, fileb);
     p.print_script(script);
   }
 }
Пример #17
0
  /** Add import statements to the current tab for the specified library */
  public void importLibrary(UserLibrary lib) throws IOException {
    // make sure the user didn't hide the sketch folder
    ensureExistence();

    List<String> list = lib.getIncludes();
    if (list == null) {
      File srcFolder = lib.getSrcFolder();
      String[] headers = Base.headerListFromIncludePath(srcFolder);
      list = Arrays.asList(headers);
    }
    if (list.isEmpty()) {
      return;
    }

    // import statements into the main sketch file (code[0])
    // if the current code is a .java file, insert into current
    // if (current.flavor == PDE) {
    SketchFile file = editor.getCurrentTab().getSketchFile();
    if (file.isExtension(Sketch.SKETCH_EXTENSIONS)) editor.selectTab(0);

    // could also scan the text in the file to see if each import
    // statement is already in there, but if the user has the import
    // commented out, then this will be a problem.
    StringBuilder buffer = new StringBuilder();
    for (String aList : list) {
      buffer.append("#include <");
      buffer.append(aList);
      buffer.append(">\n");
    }
    buffer.append('\n');
    buffer.append(editor.getCurrentTab().getText());
    editor.getCurrentTab().setText(buffer.toString());
    editor.getCurrentTab().setSelection(0, 0); // scroll to start
  }
Пример #18
0
  @Override
  protected void onSaveInstanceState(Bundle outState) {
    super.onSaveInstanceState(outState);

    ArrayList<String> vals = new ArrayList<String>();
    ArrayList<Integer> ids = new ArrayList<Integer>();
    int newone = 0;

    for (int i = 0; i < max; i++) {
      if (!checkFiles(i)) {
        newone = i;
        ids.add(i);
        vals.add(thetexts.get(i).edit.getText().toString());
      } else if (thetexts.get(i).changed) {
        ids.add(i);
        vals.add(thetexts.get(i).edit.getText().toString());
      }
    }

    if (newone > 0) outState.putInt("newone", newone);
    outState.putStringArrayList("vals", vals);
    outState.putIntegerArrayList("ids", ids);
    if (curfocus != null) outState.putInt("curfocus", curfocus.getId());
    outState.putBoolean("OKAY", true);
  }
Пример #19
0
  void initLogger() {
    final boolean VERBOSE_LOGGING = true;
    final int LOG_SIZE = 512 * 1024; // max log file size (in bytes)

    Logger globalLogger = Logger.getLogger("");
    // Logger logger = Logger.getLogger(Logger.GLOBAL_LOGGER_NAME); // doesn't work on os x
    if (VERBOSE_LOGGING) {
      globalLogger.setLevel(Level.INFO);
    } else {
      globalLogger.setLevel(Level.WARNING);
    }

    // enable logging to file
    try {
      // settings is writable for built-in modes, mode folder is not writable
      File logFolder = Base.getSettingsFile("debug");
      if (!logFolder.exists()) {
        logFolder.mkdir();
      }
      File logFile = new File(logFolder, "DebugMode.%g.log");
      Handler handler = new FileHandler(logFile.getAbsolutePath(), LOG_SIZE, 10, false);
      globalLogger.addHandler(handler);

    } catch (IOException ex) {
      Logger.getLogger(JavaMode.class.getName()).log(Level.SEVERE, null, ex);
    } catch (SecurityException ex) {
      Logger.getLogger(JavaMode.class.getName()).log(Level.SEVERE, null, ex);
    }
  }
Пример #20
0
 void baseInit() {
   _state = Base.stateInit();
   _previousByte = 0;
   for (int i = 0; i < Base.kNumRepDistances; i++) {
     _repDistances[i] = 0;
   }
 }
Пример #21
0
  public EditorLineStatus(JEditTextArea textarea) {
    this.textarea = textarea;
    textarea.editorLineStatus = this;

    background = Theme.getColor("linestatus.bgcolor");
    font = Theme.getFont("linestatus.font");
    foreground = Theme.getColor("linestatus.color");
    high = Theme.getInteger("linestatus.height");

    if (Base.isMacOS()) {
      resize = Base.getThemeImage("resize.gif", this);
    }
    // linestatus.bgcolor = #000000
    // linestatus.font    = SansSerif,plain,10
    // linestatus.color   = #FFFFFF
  }
  /** Add import statements to the current tab for all of packages inside the specified jar file. */
  public void handleImportLibrary(String jarPath) {
    // make sure the user didn't hide the sketch folder
    sketch.ensureExistence();

    // import statements into the main sketch file (code[0])
    // if the current code is a .java file, insert into current
    // if (current.flavor == PDE) {
    if (mode.isDefaultExtension(sketch.getCurrentCode())) {
      sketch.setCurrentCode(0);
    }

    // could also scan the text in the file to see if each import
    // statement is already in there, but if the user has the import
    // commented out, then this will be a problem.
    String[] list = Base.packageListFromClassPath(jarPath);
    StringBuffer buffer = new StringBuffer();
    for (int i = 0; i < list.length; i++) {
      buffer.append("import ");
      buffer.append(list[i]);
      buffer.append(".*;\n");
    }
    buffer.append('\n');
    buffer.append(getText());
    setText(buffer.toString());
    setSelection(0, 0); // scroll to start
    sketch.setModified(true);
  }
Пример #23
0
    /**
     * Print a hunk of a normal diff. This is a contiguous portion of a complete edit script,
     * describing changes in consecutive lines.
     */
    @Override
    protected void print_hunk(final Diff.change hunk) {

      /* Determine range of line numbers involved in each file.  */
      analyze_hunk(hunk);
      if ((this.deletes == 0) && (this.inserts == 0)) {
        return;
      }

      /* Print out the line number header for this hunk */
      print_number_range(',', this.first0, this.last0);
      this.outfile.print(Base.change_letter(this.inserts, this.deletes));
      print_number_range(',', this.first1, this.last1);
      this.outfile.println();

      /* Print the lines that the first file has.  */
      if (this.deletes != 0) {
        for (int i = this.first0; i <= this.last0; i++) {
          print_1_line("< ", this.file0[i]);
        }
      }

      if ((this.inserts != 0) && (this.deletes != 0)) {
        this.outfile.println("---");
      }

      /* Print the lines that the second file has.  */
      if (this.inserts != 0) {
        for (int i = this.first1; i <= this.last1; i++) {
          print_1_line("> ", this.file1[i]);
        }
      }
    }
Пример #24
0
  protected Connector findConnector(String connectorName) {
    //    List connectors =
    //      com.sun.jdi.Bootstrap.virtualMachineManager().allConnectors();
    List connectors = org.eclipse.jdi.Bootstrap.virtualMachineManager().allConnectors();

    //    // debug: code to list available connectors
    //    Iterator iter2 = connectors.iterator();
    //    while (iter2.hasNext()) {
    //      Connector connector = (Connector)iter2.next();
    //      System.out.println("connector name is " + connector.name());
    //    }

    for (Object c : connectors) {
      Connector connector = (Connector) c;
      //      System.out.println(connector.name());
      //    }
      //    Iterator iter = connectors.iterator();
      //    while (iter.hasNext()) {
      //      Connector connector = (Connector)iter.next();
      if (connector.name().equals(connectorName)) {
        return connector;
      }
    }
    Base.showError(
        "Compiler Error",
        "findConnector() failed to find " + connectorName + " inside Runner",
        null);
    return null; // Not reachable
  }
  public EditorButtons(Editor editor) {
    this.editor = editor;
    buttons = Base.getImage("buttons.gif", this);

    buttonCount = 0;
    which = new int[BUTTON_COUNT];

    // which[buttonCount++] = NOTHING;
    which[buttonCount++] = RUN;
    which[buttonCount++] = STOP;
    which[buttonCount++] = NEW;
    which[buttonCount++] = OPEN;
    which[buttonCount++] = SAVE;
    which[buttonCount++] = EXPORT;
    which[buttonCount++] = SERIAL;

    currentRollover = -1;

    // hardcoding new blue color scheme for consistency with images,
    // see EditorStatus.java for details.
    // bgcolor = Preferences.getColor("buttons.bgcolor");
    bgcolor = new Color(0x04, 0x4F, 0x6F);

    status = "";

    statusFont = Preferences.getFont("buttons.status.font");
    statusColor = Preferences.getColor("buttons.status.color");

    // statusY = (BUTTON_COUNT + 1) * BUTTON_HEIGHT;

    addMouseListener(this);
    addMouseMotionListener(this);
  }
Пример #26
0
  /** Save all code in the current sketch. */
  public boolean save() throws IOException {
    // make sure the user didn't hide the sketch folder
    ensureExistence();

    if (isReadOnly(
        BaseNoGui.librariesIndexer.getInstalledLibraries(), BaseNoGui.getExamplesPath())) {
      Base.showMessage(
          tr("Sketch is read-only"),
          tr(
              "Some files are marked \"read-only\", so you'll\n"
                  + "need to re-save this sketch to another location."));
      return saveAs();
    }

    // rename .pde files to .ino
    List<SketchFile> oldFiles = new ArrayList<>();
    for (SketchFile file : sketch.getFiles()) {
      if (file.isExtension(Sketch.OLD_SKETCH_EXTENSIONS)) oldFiles.add(file);
    }

    if (oldFiles.size() > 0) {
      if (PreferencesData.get("editor.update_extension") == null) {
        Object[] options = {tr("OK"), tr("Cancel")};
        int result =
            JOptionPane.showOptionDialog(
                editor,
                tr(
                    "In Arduino 1.0, the default file extension has changed\n"
                        + "from .pde to .ino.  New sketches (including those created\n"
                        + "by \"Save-As\") will use the new extension.  The extension\n"
                        + "of existing sketches will be updated on save, but you can\n"
                        + "disable this in the Preferences dialog.\n"
                        + "\n"
                        + "Save sketch and update its extension?"),
                tr(".pde -> .ino"),
                JOptionPane.OK_CANCEL_OPTION,
                JOptionPane.QUESTION_MESSAGE,
                null,
                options,
                options[0]);

        if (result != JOptionPane.OK_OPTION) return false; // save cancelled

        PreferencesData.setBoolean("editor.update_extension", true);
      }

      if (PreferencesData.getBoolean("editor.update_extension")) {
        // Do rename of all .pde files to new .ino extension
        for (SketchFile file : oldFiles) {
          File newName =
              FileUtils.replaceExtension(file.getFile(), Sketch.DEFAULT_SKETCH_EXTENSION);
          file.renameTo(newName.getName());
        }
      }
    }

    sketch.save();
    return true;
  }
Пример #27
0
 public void resetBy(File another) {
   super.resetBy(another);
   setId(another.getId());
   setDir(another.getDir());
   setName(another.getName());
   setSize(another.getSize());
   setProductionId(another.getProductionId());
 }
Пример #28
0
 private void test_exception(Base base) {
   try {
     String retval = base.base_op("bad_name");
     fail("base_op returned without exception on bad call");
   } catch (BadInput e) {
     // expected exception
   }
 }
Пример #29
0
  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);
    }
  }
Пример #30
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."
        }
      }
    }
  }