Package groovy.lang

Examples of groovy.lang.GroovyClassLoader.parseClass()


    protected void setUp() throws Exception {
        super.setUp();
        GroovyClassLoader cl = new GroovyClassLoader(getClass().getClassLoader());
        implClass1 = cl.parseClass(SCRIPT);
        implClass2 = cl.parseClass(SCRIPT2);
        scopeContainer = createMock(ScopeContainer.class);
        expect(scopeContainer.getInstance(isA(AtomicComponent.class))).andStubAnswer(new IAnswer() {
            public Object answer() throws Throwable {
                return ((AtomicComponent) getCurrentArguments()[0]).createInstance();
            }
View Full Code Here


        // create the implementation class for the script
        Class<? extends GroovyObject> groovyClass;
        try {
            String script = implementation.getScript();
            // REVIEW JFM can we cache the class?
            groovyClass = groovyClassLoader.parseClass(script);
        } catch (CompilationFailedException e) {
            BuilderConfigException bce = new BuilderConfigException(e);
            bce.setIdentifier(name);
            throw bce;
        }
View Full Code Here

    try {
      if (path2rules != null) {
        ClassLoader parent = getClass().getClassLoader();
        GroovyClassLoader loader = new GroovyClassLoader(parent);
        Class<?> groovyClass = loader.parseClass(new File(path2rules
            .toURI()));
        groovyObject = (GroovyObject) groovyClass.newInstance();
      }
    } catch (Exception ioe) {
      throw new RuntimeException("Failed to initialize Groovy!", ioe);
View Full Code Here

      String   cwp  = getCodeWriterPath( tmps );

      ClassLoader parent = getClass().getClassLoader();
      GroovyClassLoader loader = new GroovyClassLoader(parent);
     
      Class groovyClass = loader.parseClass( new File( cwp ) );
      GroovyObject gtm = (GroovyObject) groovyClass.newInstance();

      // DO NOT use CommandLineUserMessageHandler here - causes infinite recursion
      MessageHandlerOutputStream  out  = new MessageHandlerOutputStream( UserMessageHandler.INFO,  rumh );
      MessageHandlerOutputStream  err  = new MessageHandlerOutputStream( UserMessageHandler.ERROR, rumh );
View Full Code Here

            setRunnableCode(urlLoader.parseClass(gcs));
        }
        else
        {
            String groovySource = expandNCubeShortCuts(buildGroovy(getCmd(), cube.getName(), cmdHash));
            setRunnableCode(urlLoader.parseClass(groovySource));
        }
        compiledClasses.put(cmdHash, getRunnableCode());
    }

    static String expandNCubeShortCuts(String groovy)
View Full Code Here

            }

            GroovyCodeSource gcs = new GroovyCodeSource(groovySourceUrl);
            gcs.setCachable(false);

            setRunnableCode(urlLoader.parseClass(gcs));
        }
        else
        {
            String groovySource = expandNCubeShortCuts(buildGroovy(getCmd(), cube.getName(), cmdHash));
            setRunnableCode(urlLoader.parseClass(groovySource));
View Full Code Here

    @SuppressWarnings(value = "unchecked")
    private void loadCommand(File file) {
        try {
            ClassLoader parent = getClass().getClassLoader();
            GroovyClassLoader loader = new GroovyClassLoader(parent);
            Class<? extends Command> groovyClass = (Class<? extends Command>) loader.parseClass(file);

            if(groovyClass.isAnnotationPresent(CommandDefinition.class)) {
                boolean correctClass = false;
                for(Class groovyInterface : groovyClass.getInterfaces()) {
                    if(groovyInterface.equals(Command.class)) {
View Full Code Here

    public void test_groovy() throws Exception {
        ClassLoader parent = Thread.currentThread().getContextClassLoader();
        GroovyClassLoader loader = new GroovyClassLoader(parent);

        // A类
        Class AClass = loader.parseClass("class A {\n" + //
                                         "    int id\n" + //
                                         "}");

        // A实例
        GroovyObject a = (GroovyObject) AClass.newInstance();
View Full Code Here

        Assert.assertEquals(a.getProperty("id"), aa.getProperty("id"));
       
        System.out.println(a);

        // B类,继承于A
        Class BClass = loader.parseClass("class B extends A {\n" + //
            "    String name\n" + //
            "}");

        // B实例
        GroovyObject b = (GroovyObject) BClass.newInstance();
View Full Code Here

        // Compile the script into an object
        Class<?> scriptClass;
        try {
            String groovySource = IOGroovyMethods.getText(in, GroovyPageParser.GROOVY_SOURCE_CHAR_ENCODING);
            //System.out.println(groovySource);
            scriptClass = groovyClassLoader.parseClass(groovySource, name);
        }
        catch (CompilationFailedException e) {
            LOG.error("Compilation error compiling GSP ["+name+"]:" + e.getMessage(), e);

            int lineNumber = ExceptionUtils.extractLineNumber(e);
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.