Package groovy.lang

Examples of groovy.lang.GroovyShell


        UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());

        final Console console = new Console(Console.class.getClassLoader());
        console.setBeforeExecution(new Closure(null) {
          public void doCall() {
            console.setShell(new GroovyShell(Console.class.getClassLoader(), new Binding()) {
              public Object run(String scriptText, String fileName, String[] args) throws org.codehaus.groovy.control.CompilationFailedException {
                return super.run(IMPORTS + scriptText, fileName, args);
              };
            });
          }
View Full Code Here


                log.log( Level.INFO, "Executing script: " + request.getUrl() );
            }
            Binding binding = createScriptContext(request, response);

            try {
                GroovyShell shell = new GroovyShell( binding );
                File groovyScript = Http.translatePath( groovyDir, request.getUrl() );
                if( groovyScript.exists() ) {
                    shell.evaluate( groovyScript.getAbsolutePath() );
                } else {
                    response.sendError( HttpURLConnection.HTTP_NOT_FOUND, request.getUrl() + " not found.");
                }
            } catch (ClassNotFoundException e) {
                log.log( Level.SEVERE, e.getMessage(), e );
View Full Code Here

    /**
     * Process Sockets.
     */
    private void processSockets() throws CompilationFailedException, IOException {
        GroovyShell groovy = new GroovyShell(conf);
        //check the script is currently valid before starting a server against the script
        if (isScriptFile) {
            groovy.parse(DefaultGroovyMethods.getText(huntForTheScriptFile(script)));
        } else {
            groovy.parse(script);
        }
        new GroovySocketServer(groovy, isScriptFile, script, autoOutput, port);
    }
View Full Code Here

    /**
     * Process the input files.
     */
    private void processFiles() throws CompilationFailedException, IOException {
        GroovyShell groovy = new GroovyShell(conf);

        Script s;

        if (isScriptFile) {
            s = groovy.parse(huntForTheScriptFile(script));
        } else {
            s = groovy.parse(script, "main");
        }

        if (args.isEmpty()) {
            BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
            PrintWriter writer = new PrintWriter(System.out);
View Full Code Here

   
    /**
     * Process the standard, single script with args.
     */
    private void processOnce() throws CompilationFailedException, IOException {
        GroovyShell groovy = new GroovyShell(conf);

        if (isScriptFile) {
            groovy.run(huntForTheScriptFile(script), args);
        }
        else {
            groovy.run(script, "script_from_command_line", args);
        }
    }
View Full Code Here

    if (args != null) {
      groovyBinding.setVariable("args", args.toArray(new String[args.size()]));
    } else {
      groovyBinding.setVariable("args", new String[0]);
    }
    final GroovyShell interp = new GroovyShell(groovyBinding);
    boolean ret = true;

    try {
      final File f = new File(groovyScript);
      interp.evaluate(f);
    } catch (final Exception e) {
      logger.error("Exception while sourcing file " + groovyScript, e);
      setMessage(e.getMessage());
      ret = false;
    } catch (final Error e) {
View Full Code Here

    final int autoclose = MathHelper.parseInt(attributes.get("autoclose"));
   
    ChatCondition condition = null;
    final String condString = attributes.get("condition");
    if (condString != null) {
      final GroovyShell interp = new GroovyShell(new Binding());
      String code = "import games.stendhal.server.entity.npc.condition.*;\r\n"
        + condString;
      try {
        condition = (ChatCondition) interp.evaluate(code);
      } catch (CompilationFailedException e) {
        throw new IllegalArgumentException(e);
      }
    }

View Full Code Here

    String value = ctx.getString("condition", null);
    if (value == null) {
      return null;
    }
    Binding groovyBinding = new Binding();
    final GroovyShell interp = new GroovyShell(groovyBinding);
    try {
      String code = "import games.stendhal.server.entity.npc.condition.*;\r\n"
        + value;
      return (ChatCondition) interp.evaluate(code);
    } catch (CompilationFailedException e) {
      throw new IllegalArgumentException(e);
    }
  }
View Full Code Here

    String value = ctx.getString("action", null);
    if (value == null) {
      return null;
    }
    Binding groovyBinding = new Binding();
    final GroovyShell interp = new GroovyShell(groovyBinding);
    try {
      String code = "import games.stendhal.server.entity.npc.action.*;\r\n"
        + value;
      return (ChatAction) interp.evaluate(code);
    } catch (CompilationFailedException e) {
      throw new IllegalArgumentException(e);
    }
  }
View Full Code Here

  public GInterpolator(Configuration conf, boolean cache, String[] imports, Map utils)
  {
    _conf = conf;
    _binding = new ConfigurationBinding(conf, utils);
    _shell = new GroovyShell(_binding);
    setCache(cache);
    _imports = imports;
  }
View Full Code Here

TOP

Related Classes of groovy.lang.GroovyShell

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.