Esempio n. 1
0
  /**
   * Perform the 'alias' command.
   *
   * @param session JSwat session on which to operate.
   * @param args Tokenized string of command arguments.
   * @param out Output to write messages to.
   */
  public void perform(Session session, CommandArguments args, Log out) {
    CommandManager cmdman = (CommandManager) session.getManager(CommandManager.class);
    if (args.hasMoreTokens()) {
      String aliasName = args.nextToken();
      if (args.hasMoreTokens()) {
        // Grab rest of string as alias value.
        // Be sure to preserve the quotes and escapes.
        args.returnAsIs(true);
        String alias = args.rest().trim();
        if (alias.charAt(0) == '"' && alias.charAt(alias.length() - 1) == '"') {
          // Must remove the enclosing quotes because the
          // command parser doesn't handle that.
          alias = alias.substring(1, alias.length() - 1);
        }

        // Add the command alias to the list.
        cmdman.createAlias(aliasName, alias);
        out.writeln(Bundle.getString("alias.defined") + ' ' + aliasName);
      } else {
        // One argument, show the alias definition.
        String alias = cmdman.getAlias(aliasName);
        if (alias == null) {
          throw new CommandException(Bundle.getString("alias.undefined") + ' ' + aliasName);
        } else {
          out.writeln("alias " + aliasName + ' ' + alias);
        }
      }
    } else {
      // No arguments, show the defined aliases.
      cmdman.listAliases();
    }
  } // perform
Esempio n. 2
0
  /**
   * Try to add a breakpoint at the last clicked class and line. Displays an appropriate error
   * message if needed.
   *
   * @param session Session.
   * @param bpman breakpoint manager.
   * @return new breakpoint if successful, null if error.
   */
  protected Breakpoint addBreakpoint(Session session, BreakpointManager bpman) {
    if (lastClickedClass == null) {
      // Fall back on default behavior.
      return super.addBreakpoint(session, bpman);
    }

    try {
      String fname = sourceSrc.getName();
      Breakpoint bp = new LineBreakpoint(lastClickedClass, fname, lastClickedLine);
      bpman.addNewBreakpoint(bp);
      return bp;
    } catch (ClassNotFoundException cnfe) {
      session
          .getUIAdapter()
          .showMessage(
              UIAdapter.MESSAGE_ERROR,
              Bundle.getString("AddBreak.invalidClassMsg") + ' ' + lastClickedClass);
      return null;
    } catch (ResolveException re) {
      session.getUIAdapter().showMessage(UIAdapter.MESSAGE_ERROR, re.errorMessage());
      return null;
    }
  } // addBreakpoint
Esempio n. 3
0
  /**
   * Perform the 'history' command.
   *
   * @param session JSwat session on which to operate.
   * @param args Tokenized string of command arguments.
   * @param out Output to write messages to.
   */
  public void perform(Session session, CommandArguments args, Log out) {
    CommandManager cmdman = (CommandManager) session.getManager(CommandManager.class);

    if (args.hasMoreTokens()) {
      String arg = args.nextToken();
      try {
        int size = Integer.parseInt(arg);
        cmdman.setHistorySize(size);
        out.writeln(Bundle.getString("history.sizeSet"));
      } catch (NumberFormatException nfe) {
        throw new CommandException(Bundle.getString("history.invalidSize"));
      } catch (IllegalArgumentException iae) {
        throw new CommandException(Bundle.getString("history.invalidRange"));
      }
    } else {
      cmdman.displayHistory();
    }
  } // perform
Esempio n. 4
0
  /**
   * Perform the 'hotswap' command.
   *
   * @param session JSwat session on which to operate.
   * @param args Tokenized string of command arguments.
   * @param out Output to write messages to.
   */
  public void perform(Session session, CommandArguments args, Log out) {
    if (!session.isActive()) {
      throw new CommandException(Bundle.getString("noActiveSession"));
    }

    if (!args.hasMoreTokens()) {
      throw new MissingArgumentsException();
    }

    // Name of class is required; name of .class file is optional.
    String cname = args.nextToken();
    String cfile = null;
    if (args.hasMoreTokens()) {
      cfile = args.nextToken();
    }

    // Find the ReferenceType for this class.
    VirtualMachine vm = session.getConnection().getVM();
    List classes = vm.classesByName(cname);
    if (classes.size() == 0) {
      throw new CommandException(Bundle.getString("hotswap.noSuchClass"));
    }
    ReferenceType clazz = (ReferenceType) classes.get(0);

    // Did the user give us a .class file?
    InputStream is = null;
    if (cfile == null) {
      // Try to find the .class file.
      PathManager pathman = (PathManager) session.getManager(PathManager.class);
      SourceSource src = pathman.mapClass(clazz);
      if (src == null) {
        throw new CommandException(Bundle.getString("hotswap.fileNotFound"));
      }
      is = src.getInputStream();
    } else {
      // A filename was given, just open it.
      try {
        is = new FileInputStream(cfile);
      } catch (FileNotFoundException fnfe) {
        throw new CommandException(Bundle.getString("hotswap.fileNotFound"));
      }
    }

    // Do the actual hotswap operation.
    try {
      Classes.hotswap(clazz, is, vm);
      out.writeln(Bundle.getString("hotswap.success"));
    } catch (UnsupportedOperationException uoe) {
      if (!vm.canRedefineClasses()) {
        throw new CommandException(Bundle.getString("hotswap.noHotSwap"));
      } else if (!vm.canAddMethod()) {
        throw new CommandException(Bundle.getString("hotswap.noAddMethod"));
      } else if (!vm.canUnrestrictedlyRedefineClasses()) {
        throw new CommandException(Bundle.getString("hotswap.noUnrestricted"));
      } else {
        throw new CommandException(Bundle.getString("hotswap.unsupported"));
      }
    } catch (IOException ioe) {
      throw new CommandException(Bundle.getString("hotswap.errorReadingFile") + ' ' + ioe);
    } catch (NoClassDefFoundError ncdfe) {
      throw new CommandException(Bundle.getString("hotswap.wrongClass"));
    } catch (VerifyError ve) {
      throw new CommandException(Bundle.getString("hotswap.verifyError") + ' ' + ve);
    } catch (UnsupportedClassVersionError ucve) {
      throw new CommandException(Bundle.getString("hotswap.versionError") + ' ' + ucve);
    } catch (ClassFormatError cfe) {
      throw new CommandException(Bundle.getString("hotswap.formatError") + ' ' + cfe);
    } catch (ClassCircularityError cce) {
      throw new CommandException(Bundle.getString("hotswap.circularity") + ' ' + cce);
    } finally {
      if (is != null) {
        try {
          is.close();
        } catch (IOException ioe) {
        }
      }
    }
  } // perform