Package groovy.lang

Examples of groovy.lang.GroovyClassLoader$ClassCollector


        }

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

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


                               File classesDir, final Transformer transformer) {
        logger.info("Compiling {} using {}.", source.getDisplayName(), transformer != null ? transformer.getClass().getSimpleName() : "no transformer");

        final EmptyScriptDetector emptyScriptDetector = new EmptyScriptDetector();
        final PackageStatementDetector packageDetector = new PackageStatementDetector();
        GroovyClassLoader groovyClassLoader = new GroovyClassLoader(classLoader, configuration, false) {
            @Override
            protected CompilationUnit createCompilationUnit(CompilerConfiguration compilerConfiguration,
                                                            CodeSource codeSource) {
                CompilationUnit compilationUnit = new CompilationUnit(compilerConfiguration, codeSource, this) {
                    // This creepy bit of code is here to put the full source path of the script into the debug info for
                    // the class.  This makes it possible for a debugger to find the source file for the class.  By default
                    // Groovy will only put the filename into the class, but that does not help a debugger for Gradle
                    // because it does not know where Gradle scripts might live.
                    @Override
                    protected groovyjarjarasm.asm.ClassVisitor createClassVisitor() {
                        return new ClassWriter(ClassWriter.COMPUTE_MAXS) {
                            // ignore the sourcePath that is given by Groovy (this is only the filename) and instead
                            // insert the full path if our script source has a source file
                            @Override
                            public void visitSource(String sourcePath, String debugInfo) {
                                super.visitSource(source.getFileName(), debugInfo);
                            }
                        };
                    }
                };

                if (transformer != null) {
                    transformer.register(compilationUnit);
                }

                compilationUnit.addPhaseOperation(packageDetector, Phases.CANONICALIZATION);
                compilationUnit.addPhaseOperation(emptyScriptDetector, Phases.CANONICALIZATION);
                return compilationUnit;
            }
        };
        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

        String methodName,
        Object[] args)
    {
        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

                if (!found && new File(cpEntry).exists())
                    antLoader.addPathElement(cpEntry);
            }
        }

        GroovyClassLoader loader = new GroovyClassLoader(parent, configuration);
        // in command line we don't need to do script lookups
        loader.setResourceLoader(new GroovyResourceLoader() {
            public URL loadGroovySource(String filename) throws MalformedURLException {
                return null;
            }
        });
View Full Code Here

            scriptExtensions.add(getScriptExtension().substring(2)); // first extension will be the one set explicitly on <groovyc>

            Path classpath = getClasspath() != null ? getClasspath() : new Path(getProject());
            final String[] pe = classpath.list();
            final GroovyClassLoader loader = new GroovyClassLoader(getClass().getClassLoader());
            for (String file : pe) {
                loader.addClasspath(file);
            }
            scriptExtensions.addAll(SourceExtensionHandler.getRegisteredExtensions(loader));
        }
    }
View Full Code Here

   * Return the GroovyClassLoader used by this script factory.
   */
  public GroovyClassLoader getGroovyClassLoader() {
    synchronized (this.scriptClassMonitor) {
      if (this.groovyClassLoader == null) {
        this.groovyClassLoader = new GroovyClassLoader(ClassUtils.getDefaultClassLoader());
      }
      return this.groovyClassLoader;
    }
  }
View Full Code Here

  public boolean requiresScriptedObjectRefresh(ScriptSource scriptSource) {
    return false;
  }

  public void setBeanClassLoader(ClassLoader classLoader) {
    this.groovyClassLoader = new GroovyClassLoader(classLoader);

  }
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

    synchronized (GroovyScript.class)
    {
      if (groovyClassLoader == null)
      {
        groovyClassLoader = new GroovyClassLoader(getClass().getClassLoader());       
        setGroovyClasspath(groovyClassLoader);
      }

      try
      {
View Full Code Here

     * @param cc
     * @return the new expanded classloader
     */
    private ClassLoader expandClassLoader(ClassLoader cl, CompilerConfiguration cc) {
        if ((classpath != null) && classpath.size() > 0) {
            cl = new GroovyClassLoader(cl, cc);
            for(GroovyScriptPath path : classpath) {
                ((GroovyClassLoader)cl).addURL(path.asURL());
            }
        }
        List<GroovyScriptPath> globalClasspath = getDescriptor().getDefaultClasspath();
        if ((globalClasspath != null) && (globalClasspath.size() > 0)) {
            if (!(cl instanceof GroovyClassLoader)) {
                cl = new GroovyClassLoader(cl, cc);
            }
            for(GroovyScriptPath path : globalClasspath) {
                ((GroovyClassLoader)cl).addURL(path.asURL());
            }
        }
View Full Code Here

TOP

Related Classes of groovy.lang.GroovyClassLoader$ClassCollector

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.