Package groovy.lang

Examples of groovy.lang.GroovyCodeSource


    */
   // Override this method if need other behavior.
   @Deprecated
   protected GroovyCodeSource createCodeSource(final InputStream in, final String name)
   {
      GroovyCodeSource gcs = SecurityHelper.doPrivilegedAction(new PrivilegedAction<GroovyCodeSource>() {
         public GroovyCodeSource run()
         {
            return new GroovyCodeSource(in, name, "/groovy/script");
         }
      });
      gcs.setCachable(false);
      return gcs;
   }
View Full Code Here


    * @param url the URL for loading script.
    * @throws IOException it script can't be loaded.
    */
   public boolean loadScript(URL url) throws IOException
   {
      Object resource = groovyScriptInstantiator.instantiateScript(new GroovyCodeSource(url), groovyClassLoader);
      if (binder.bind(resource))
      {
         // add mapping script URL to name of class.
         scriptsURL2ClassMap.put(new URLScriptKey(url), resource.getClass());
         return true;
View Full Code Here

      }
   }

   private GroovyCodeSource createCodeSource(InputStream in, String name)
   {
      GroovyCodeSource gcs = new GroovyCodeSource(in, name, "/groovy/script/jaxrs");
      gcs.setCachable(false);
      return gcs;
   }
View Full Code Here

        GroovyObject object = demo.compile("src/examples/groovy/swing/SwingDemo.groovy");
        object.invokeMethod("run", null);
    }

    protected GroovyObject compile(String fileName) throws Exception {
        Class groovyClass = loader.parseClass(new GroovyCodeSource(new File(fileName)));
        GroovyObject object = (GroovyObject) groovyClass.newInstance();
        assertTrue(object != null);
        return object;
    }
View Full Code Here

    URL url = ClassUtils.getURL(fileName);
    if (url == null) return groovyFile;
    File file = getGroovyFile(url);
    long lastModified = file.lastModified();
    if (groovyFile == null || groovyFile.isUpdate(lastModified)) {
      GroovyCodeSource source = new GroovyCodeSource(file);
      source.setCachable(false); //cache disabled
      Class<?> c = loader.parseClass(source, false); //cache disabled
      if (c != null) {
        groovyFile = new GroovyFile(c, lastModified);
      }
    }
View Full Code Here

    //Mailing list post by Richard Hensley reporting a CodeSource bug.  A GroovyCodeSource created
    //with a URL was causing an NPE.
    public void testCodeSource() throws IOException, CompilationFailedException {
        URL script = loader.getResource("groovy/ArrayTest.groovy");
        try {
            new GroovyCodeSource(script);
        } catch (RuntimeException re) {
            assertEquals("Could not construct a GroovyCodeSource from a null URL", re.getMessage());
        }
    }
View Full Code Here

      * Execute the groovy script contained in file.  If missingPermission
      * is non-null, then this invocation expects an AccessControlException with missingPermission
      * as the reason.  If missingPermission is null, the script is expected to execute successfully.
      */
    protected Class parseClass(File file) {
        GroovyCodeSource gcs = null;
        try {
            gcs = new GroovyCodeSource(file);
        } catch (IOException fnfe) {
            fail(fnfe.toString());
        }
        return parseClass(gcs);
    }
View Full Code Here

      */
    protected void assertExecute(File file, Permission missingPermission) {
        if (!isSecurityAvailable()) {
            return;
        }
        GroovyCodeSource gcs = null;
        try {
            gcs = new GroovyCodeSource(file);
        } catch (IOException fnfe) {
            fail(fnfe.toString());
        }
        parseAndExecute(gcs, missingPermission);
    }
View Full Code Here

            return;
        }
        if (codeBase == null) {
            codeBase = "/groovy/security/test";
        }
        parseAndExecute(new GroovyCodeSource(scriptStr, generateClassName(), codeBase), missingPermission);
    }
View Full Code Here

    public void testCreateScriptWithScriptClass() {
        GroovyClassLoader classLoader = new GroovyClassLoader();
        String controlProperty = "text";
        String controlValue = "I am a script";
        String code = controlProperty + " = '" + controlValue + "'";
        GroovyCodeSource codeSource = new GroovyCodeSource(code, "testscript", "/groovy/shell");
        Class scriptClass = classLoader.parseClass(codeSource, false);
        Script script = InvokerHelper.createScript(scriptClass, new Binding(bindingVariables));
        assertEquals(bindingVariables, script.getBinding().getVariables());
        script.run();
        assertEquals(controlValue, script.getProperty(controlProperty));
View Full Code Here

TOP

Related Classes of groovy.lang.GroovyCodeSource

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.