示例#1
0
文件: Main.java 项目: NCIP/calims
 public static void main(String[] args) {
   errorReporter = new ToolErrorReporter(false, global.getErr());
   shellContextFactory.setErrorReporter(errorReporter);
   IProxy iproxy = new IProxy(IProxy.PROCESS_FILES, processOptions(args));
   global.init(shellContextFactory);
   shellContextFactory.call(iproxy);
 }
  /**
   * Execute the jsdoc toolkit executable.
   *
   * @param jsDocApp the location of the run.js within the jsDocToolkit
   * @param args the list of arguments for the jsdoc toolkit
   * @param extractDirectory The directory to set the execution from
   * @throws MavenReportException for any reporting exception
   */
  public static void executeJSDocToolkit(
      final File jsDocApp, final List<String> args, final File extractDirectory)
      throws MavenReportException {
    try {
      setConsoleOuput();
      LOGGER.info(
          "Executing with the following params: '" + args.toString().replaceAll(",", "") + "'");

      Context cx = Context.enter();
      cx.setLanguageVersion(Context.VERSION_1_6);
      Global global = new Global();
      PrintStream sysOut = new PrintStream(new Log4jOutputStream(LOGGER, Level.INFO), true);
      global.setErr(sysOut);
      global.setOut(sysOut);
      global.init(cx);

      Scriptable argsObj = cx.newArray(global, args.toArray(new Object[] {}));
      global.defineProperty("arguments", argsObj, ScriptableObject.DONTENUM);
      cx.evaluateReader(global, new FileReader(jsDocApp), jsDocApp.getName(), 1, null);
    } catch (FileNotFoundException e) {
      LOGGER.error("Not able to find jsdoc file at location " + jsDocApp.getAbsolutePath());
    } catch (IOException e) {
      LOGGER.error("Not able to read jsdoc file at location " + jsDocApp.getAbsolutePath());
    }
    LOGGER.info("JsDocToolkit Reporting completed.");
  }
 public static void help(
     final Context context, final Scriptable thisObj, final Object[] args, Function funObj) {
   logger.debug("help");
   PrintStream out = ((Global) funObj.getParentScope()).getOut();
   Global.help(context, thisObj, args, funObj);
   out.println(getMessage("msg.help", null));
 }
示例#4
0
文件: Main.java 项目: NCIP/calims
  static void processFiles(Context cx, String[] files) throws IOException {
    StringBuffer cout = new StringBuffer();
    if (files.length > 0) {
      for (int i = 0; i < files.length; i++) {
        try {
          String source = (String) readFileOrUrl(files[i], true);
          cout.append(Compressor.compressScript(source, 0, 1, escapeUnicode, stripConsole));
        } catch (IOException ex) {
          // continue processing files
        }
      }
    } else {
      byte[] data = Kit.readStream(global.getIn(), 4096);
      // Convert to String using the default encoding
      String source = new String(data);
      if (source != null) {
        cout.append(Compressor.compressScript(source, 0, 1, escapeUnicode, stripConsole));
      }
    }

    global.getOut().println(cout);
  }
示例#5
0
  /**
   * Create a new com.netscape.javascript.Context.
   *
   * @return the newly instantiated Context
   */
  public Object createContext() {
    // this is stolen from Main.java
    cx = new Context();
    ((Context) cx).enter();

    global = new Global();
    ((Context) cx).initStandardObjects(global);

    String[] names = {"print", "quit", "version", "load", "help", "loadClass"};
    try {
      global.defineFunctionProperties(names, Main.class, ScriptableObject.DONTENUM);
    } catch (PropertyException e) {

      throw new Error(e.getMessage());
    }

    return cx;
  }
示例#6
0
文件: Main.java 项目: NCIP/calims
 static {
   global.initQuitAction(new IProxy(IProxy.SYSTEM_EXIT, null));
 }
示例#7
0
文件: Main.java 项目: NCIP/calims
  public static String[] processOptions(String args[]) {
    List fileList = new ArrayList();
    String usageError = null;
    boolean showUsage = false;

    for (int i = 0; i < args.length; i++) {
      String arg = args[i];
      if (!arg.startsWith("-")) {
        fileList.add(arg);
      } else if (arg.equals("-js-version")) {
        if (++i == args.length) {
          usageError = arg;
        }
        int version = 0;
        try {
          version = Integer.parseInt(args[i]);
        } catch (NumberFormatException ex) {
          usageError = args[i];
        }
        if (!Context.isValidLanguageVersion(version)) {
          usageError = args[i];
        }
        if (usageError != null) shellContextFactory.setLanguageVersion(version);
      }
      /*
      			else if (arg.equals("-opt") || arg.equals("-O")) {
      				if (++i == args.length) {
      					usageError = arg;
      				}
      				int opt = 0;
      				try {
      					opt = Integer.parseInt(args[i]);
      				} catch (NumberFormatException ex) {
      					usageError = args[i];
      				}
      				if (opt == -2) {
      					// Compatibility with Cocoon Rhino fork
      					opt = -1;
      				} else if (!Context.isValidOptimizationLevel(opt)) {
      					usageError = args[i];
      				}
      				if (usageError != null) {
      					shellContextFactory.setOptimizationLevel(opt);
      				}
      			}
      			else if (arg.equals("-debug")) {
      				shellContextFactory.setGeneratingDebug(true);
      			}
      */
      else if (arg.equals("-?") || arg.equals("-help")) {
        showUsage = true;
      } else if (arg.equals("-escape-unicode")) {
        escapeUnicode = true;
      } else if (arg.equals("-stripConsole")) {
        if (i >= (args.length - 1)) {
          usageError = getMessage("msg.shell.stripConsoleMissingArg");
        } else {
          stripConsole = args[++i];
          if (!stripConsole.equals("normal")
              && !stripConsole.equals("warn")
              && !stripConsole.equals("all")) {
            usageError = getMessage("msg.shell.stripConsoleInvalid");
          }
        }
      }
    }

    // print error and usage message
    if (usageError != null) {
      global.getOut().println(getMessage("msg.shell.invalid", usageError));
    }
    if (usageError != null || showUsage) {
      global.getOut().println(getMessage("msg.shell.usage"));
      System.exit(1);
    }

    String[] files = new String[fileList.size()];
    files = (String[]) fileList.toArray(files);
    return files;
  }