Package groovy.lang

Examples of groovy.lang.GroovyCodeSource


    //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


    private static GroovyCodeSource getCodeSource(boolean scriptFile, String scriptFilenameOrText) {
        if (scriptFile) {
            try {
                if (uriPattern.matcher(scriptFilenameOrText).matches()) {
                    return new GroovyCodeSource(new URI(scriptFilenameOrText));
                } else {
                    return new GroovyCodeSource(GroovyMain.searchForGroovyScriptFile(scriptFilenameOrText));
                }
            } catch (IOException e) {
                throw new GroovyRuntimeException("Unable to get script from: " + scriptFilenameOrText, e);
            } catch (URISyntaxException e) {
                throw new GroovyRuntimeException("Unable to get script from URI: " + scriptFilenameOrText, e);
            }
        } else {
            // We could jump through some hoops to have GroovyShell make our script name, but that seems unwarranted.
            // If we *did* jump through that hoop then we should probably change the run loop to not recompile
            // the script on every iteration since the script text can't change (the reason for the recompilation).
            return new GroovyCodeSource(scriptFilenameOrText, generateScriptName(), GroovyShell.DEFAULT_CODE_BASE);
        }
    }
View Full Code Here

     */
    protected GroovyCodeSource getScriptSource(boolean isScriptFile, String script) throws IOException, URISyntaxException {
        //check the script is currently valid before starting a server against the script
        if (isScriptFile) {
            if (uriPattern.matcher(script).matches()) {
                return new GroovyCodeSource(new URI(script));
            } else {
                return new GroovyCodeSource(huntForTheScriptFile(script));
            }
        } else {
            return new GroovyCodeSource(script, "script_from_command_line", GroovyShell.DEFAULT_CODE_BASE);
        }
    }
View Full Code Here

        final Map<String, String> modeltypes;

        @SuppressWarnings("unchecked")
        public MarkupTemplateMaker(final Reader reader, String sourceName, Map<String, String> modelTypes) {
            String name = sourceName != null ? sourceName : "GeneratedMarkupTemplate" + counter.getAndIncrement();
            templateClass = groovyClassLoader.parseClass(new GroovyCodeSource(reader, name, ""), modelTypes);
            this.modeltypes = modelTypes;
        }
View Full Code Here

        }

        @SuppressWarnings("unchecked")
        public MarkupTemplateMaker(final URL resource, Map<String, String> modelTypes) throws IOException {
            boolean cache = templateConfiguration.isCacheTemplates();
            GroovyCodeSource codeSource;
            if (cache) {
                // we use a map in addition to the internal caching mechanism of Groovy because the latter
                // will always read from the URL even if it's cached
                String key = resource.toExternalForm();
                codeSource = codeSourceCache.get(key);
                if (codeSource == null) {
                    codeSource = new GroovyCodeSource(resource);
                    codeSourceCache.put(key, codeSource);
                }
            } else {
                codeSource = new GroovyCodeSource(resource);
            }
            codeSource.setCachable(cache);
            templateClass = groovyClassLoader.parseClass(codeSource, modelTypes);
            this.modeltypes = modelTypes;
        }
View Full Code Here

            if (groovySourceUrl == null)
            {
                throw new IllegalArgumentException("Groovy code source URL is non-relative, add base url to GroovyClassLoader on NCubeManager.addBaseResourceUrls(): " + url);
            }

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

            setRunnableCode(urlLoader.parseClass(gcs));
        }
        else
        {
View Full Code Here

    /**
     * Used internally to reload the script back when coming back from the persisted state
     * (therefore we don't want to record this.)
     */
    /*package*/ Script reparse(String className, String text) throws CompilationFailedException {
        return super.parse(new GroovyCodeSource(text,className,DEFAULT_CODE_BASE));
    }
View Full Code Here

    {
        String url = getUrl();
        if (StringUtilities.hasContent(url))
        {
            url = url.trim();
            GroovyCodeSource gcs;
            if (url.toLowerCase().startsWith("res://"))
            {   // URL to file within classpath
                gcs = new GroovyCodeSource(GroovyBase.class.getClassLoader().getResource(url.substring(6)));
            }
            else
            {   // URL to non-classpath file
                gcs = new GroovyCodeSource(new URL(url));
            }
            gcs.setCachable(false);
            setRunnableCode(groovyClassLoader.parseClass(gcs));
        }
        else
        {
            String groovySource = expandNCubeShortCuts(buildGroovy(getCmd(), cubeName, cmdHash));
View Full Code Here

            URL groovySourceUrl = loader.getResource(url);
            if (groovySourceUrl == null)
            {
                throw new IllegalArgumentException("Groovy code source URL is non-relative, add base url to GroovyClassLoader on NCubeManager.setUrlClassLoader(): " + url);
            }
            GroovyCodeSource gcs = new GroovyCodeSource(groovySourceUrl);
            gcs.setCachable(false);
            setRunnableCode(loader.parseClass(gcs));
        }
        else
        {
            String groovySource = expandNCubeShortCuts(buildGroovy(getCmd(), cube.getName(), cmdHash));
View Full Code Here

    * @param name code source name
    * @return GroovyCodeSource
    */
   protected GroovyCodeSource createCodeSource(InputStream in, String name)
   {
      GroovyCodeSource gcs = new GroovyCodeSource(in, name, "/groovy/script/jaxrs");
      gcs.setCachable(false);
      return gcs;
   }
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.