Examples of GroovyClassLoader


Examples of com.dotcms.repackage.groovy.lang.GroovyClassLoader

      /**
       * Call the named method of the given object.
       */
      public Object call(Object sourceCode, String method, Object[] args) throws BSFException {
        GroovyClassLoader gcl = new GroovyClassLoader();
        try {
        return ((GroovyObject)gcl.parseClass(sourceCode.toString()).newInstance()).invokeMethod(method, args);
        } catch (Exception e) {
              throw new BSFException(BSFException.REASON_EXECUTION_ERROR, "exception from Groovy: " + e, e);
          }
      }
View Full Code Here

Examples of groovy.lang.GroovyClassLoader

        }

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

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

Examples of groovy.lang.GroovyClassLoader

                               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

Examples of groovy.lang.GroovyClassLoader

        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

Examples of groovy.lang.GroovyClassLoader

                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

Examples of groovy.lang.GroovyClassLoader

            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

Examples of groovy.lang.GroovyClassLoader

   * 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

Examples of groovy.lang.GroovyClassLoader

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

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

  }
View Full Code Here

Examples of groovy.lang.GroovyClassLoader

    }
    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

Examples of groovy.lang.GroovyClassLoader

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

      try
      {
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.