Package groovy.lang

Examples of groovy.lang.GroovyClassLoader.parseClass()


        public Class<? extends T> generate() {
            src.format("}");

            GroovyClassLoader classLoader = new GroovyClassLoader(type.getClassLoader());
            return classLoader.parseClass(src.toString());
        }
    }
}
View Full Code Here


        };
        String scriptText = source.getResource().getText();
        String scriptName = source.getClassName();
        GroovyCodeSource codeSource = new GroovyCodeSource(scriptText == null ? "" : scriptText, scriptName, "/groovy/script");
        try {
            groovyClassLoader.parseClass(codeSource, false);
        } catch (MultipleCompilationErrorsException e) {
            SyntaxException syntaxError = e.getErrorCollector().getSyntaxError(0);
            Integer lineNumber = syntaxError == null ? null : syntaxError.getLine();
            throw new ScriptCompilationException(String.format("Could not compile %s.", source.getDisplayName()), e, source,
                    lineNumber);
View Full Code Here

    {
        try
        {
            final GroovyClassLoader grooveyClassLoader = new GroovyClassLoader(this.getClassLoader());
            final Class groovyClass =
                grooveyClassLoader.parseClass(
                    this.getContents(new File(this.scriptPath)),
                    scriptPath);
            final GroovyObject groovyObject = (GroovyObject)groovyClass.newInstance();

            this.copyProperties(
View Full Code Here

    Object[] mainMethodArgs = WRAPPER_MANAGER.getMainMethodArgs();
    try
    {
      ClassLoader parent = WrapperGroovyMain.class.getClassLoader();
      GroovyClassLoader loader = new GroovyClassLoader(parent);
      Class groovyClass = loader.parseClass(scriptFile);
      GroovyObject script = (GroovyObject) groovyClass.newInstance();
      script.invokeMethod("main", mainMethodArgs);
    }
    catch (Throwable e)
    {
View Full Code Here

                    "    return v\n" +
                    "  }\n" +
                    "}";

            GroovyClassLoader loader = new GroovyClassLoader(getClass().getClassLoader());
            groovyClass = loader.parseClass(groovyString);
            try {
                match = groovyClass.getDeclaredMethod("match");
                metaField = groovyClass.getField("meta");
            } catch (NoSuchFieldException e) {
                // can never occur as we control the groovy string
View Full Code Here

public class BytecodeGroovyClassLoaderBehaviour {

    @Test
    public void shouldCacheBytes() throws IOException {
        GroovyClassLoader classLoader = new BytecodeGroovyClassLoader();
        assertNotNull((Class<?>) classLoader.parseClass("class Hello { }"));
        InputStream bytecode = classLoader.getResourceAsStream("Hello.class");
        assertNotNull(bytecode);
        bytecode.close();
    }
View Full Code Here

  public CompiledScript compile(String scriptName, String scriptCode) throws ScriptCompilerException
  {
    try
    {
      GroovyClassLoader gcl = new GroovyClassLoader();
      Class scriptClass = gcl.parseClass(scriptCode);
      if (scriptClass == null)
      {
        throw new ScriptCompilerException("No compiled script code in script \"" + scriptName + "\"");
      }
      return new CompiledGroovyScript(scriptName, gcl.parseClass(scriptCode));
View Full Code Here

      Class scriptClass = gcl.parseClass(scriptCode);
      if (scriptClass == null)
      {
        throw new ScriptCompilerException("No compiled script code in script \"" + scriptName + "\"");
      }
      return new CompiledGroovyScript(scriptName, gcl.parseClass(scriptCode));
    }
    catch (CompilationFailedException x)
    {
      throw new ScriptCompilerException("Unable to compile script", x);
    }
View Full Code Here

    try
    {
//      GroovyShell gs = new GroovyShell();
//      gs.parse(scriptCode);
      GroovyClassLoader gcl = new GroovyClassLoader();
      Class scriptClass = gcl.parseClass(scriptCode);
      if (scriptClass == null)
      {
        throw new ScriptCompilerException("No compiled script code");
      }
    }
View Full Code Here

        InputStream in = new ByteArrayInputStream(bytes);
        GroovyCodeSource gcs = new GroovyCodeSource(in, templateName, "/groovy/shell");
        GroovyClassLoader loader = new GroovyClassLoader(Thread.currentThread().getContextClassLoader(), config);
        Class<?> scriptClass;
        try {
            scriptClass = loader.parseClass(gcs, false);
        } catch (CompilationFailedException e) {
            throw new GroovyCompilationException(e, templateText, groovyText);
        } catch (ClassFormatError e) {
            throw new GroovyCompilationException(e, templateText, groovyText);
        }
View Full Code Here

TOP
Copyright © 2018 www.massapi.com. 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.