Java Code Examples for org.codehaus.groovy.control.customizers.ImportCustomizer#addStaticStars()

The following examples show how to use org.codehaus.groovy.control.customizers.ImportCustomizer#addStaticStars() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ApiGroovyCompiler.java    From pushfish-android with BSD 2-Clause "Simplified" License 6 votes vote down vote up
private void applyConfigurationScript(File configScript, CompilerConfiguration configuration) {
    VersionNumber version = parseGroovyVersion();
    if (version.compareTo(VersionNumber.parse("2.1")) < 0) {
        throw new GradleException("Using a Groovy compiler configuration script requires Groovy 2.1+ but found Groovy " + version + "");
    }
    Binding binding = new Binding();
    binding.setVariable("configuration", configuration);

    CompilerConfiguration configuratorConfig = new CompilerConfiguration();
    ImportCustomizer customizer = new ImportCustomizer();
    customizer.addStaticStars("org.codehaus.groovy.control.customizers.builder.CompilerCustomizationBuilder");
    configuratorConfig.addCompilationCustomizers(customizer);

    GroovyShell shell = new GroovyShell(binding, configuratorConfig);
    try {
        shell.evaluate(configScript);
    } catch (Exception e) {
        throw new GradleException("Could not execute Groovy compiler configuration script: " + configScript.getAbsolutePath(), e);
    }
}
 
Example 2
Source File: Groovy.java    From groovy with Apache License 2.0 6 votes vote down vote up
private void configureCompiler() {
    if (scriptBaseClass != null) {
        configuration.setScriptBaseClass(scriptBaseClass);
    }
    if (configscript != null) {
        Binding binding = new Binding();
        binding.setVariable("configuration", configuration);

        CompilerConfiguration configuratorConfig = new CompilerConfiguration();
        ImportCustomizer customizer = new ImportCustomizer();
        customizer.addStaticStars("org.codehaus.groovy.control.customizers.builder.CompilerCustomizationBuilder");
        configuratorConfig.addCompilationCustomizers(customizer);

        GroovyShell shell = new GroovyShell(binding, configuratorConfig);
        File confSrc = new File(configscript);
        try {
            shell.evaluate(confSrc);
        } catch (IOException e) {
            throw new BuildException("Unable to configure compiler using configuration file: " + confSrc, e);
        }
    }
}
 
Example 3
Source File: ApiGroovyCompiler.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 6 votes vote down vote up
private void applyConfigurationScript(File configScript, CompilerConfiguration configuration) {
    VersionNumber version = parseGroovyVersion();
    if (version.compareTo(VersionNumber.parse("2.1")) < 0) {
        throw new GradleException("Using a Groovy compiler configuration script requires Groovy 2.1+ but found Groovy " + version + "");
    }
    Binding binding = new Binding();
    binding.setVariable("configuration", configuration);

    CompilerConfiguration configuratorConfig = new CompilerConfiguration();
    ImportCustomizer customizer = new ImportCustomizer();
    customizer.addStaticStars("org.codehaus.groovy.control.customizers.builder.CompilerCustomizationBuilder");
    configuratorConfig.addCompilationCustomizers(customizer);

    GroovyShell shell = new GroovyShell(binding, configuratorConfig);
    try {
        shell.evaluate(configScript);
    } catch (Exception e) {
        throw new GradleException("Could not execute Groovy compiler configuration script: " + configScript.getAbsolutePath(), e);
    }
}
 
Example 4
Source File: GroovyClassLoaderFactory.java    From beakerx with Apache License 2.0 5 votes vote down vote up
public static void addImportPathToImportCustomizer(ImportCustomizer icz, ImportPath importLine) {
  if (importLine.asString().startsWith(STATIC_WORD_WITH_SPACE)) {

    String pureImport = importLine.asString()
            .replace(STATIC_WORD_WITH_SPACE, StringUtils.EMPTY)
            .replace(DOT_STAR_POSTFIX, StringUtils.EMPTY);

    if (importLine.asString().endsWith(DOT_STAR_POSTFIX)) {
      icz.addStaticStars(pureImport);
    } else {
      int index = pureImport.lastIndexOf('.');
      if (index == -1) {
        return;
      }
      icz.addStaticImport(pureImport.substring(0, index), pureImport.substring(index + 1));
    }

  } else {

    if (importLine.asString().endsWith(DOT_STAR_POSTFIX)) {
      icz.addStarImports(importLine.asString().replace(DOT_STAR_POSTFIX, StringUtils.EMPTY));
    } else {
      icz.addImports(importLine.asString());
    }

  }
}
 
Example 5
Source File: CustomGroovyShellFactory.java    From wildfly-camel with Apache License 2.0 5 votes vote down vote up
public GroovyShell createGroovyShell(Exchange exchange) {
    ImportCustomizer importCustomizer = new ImportCustomizer();
    importCustomizer.addStaticStars("org.wildfly.camel.test.groovy.subA.CustomUtils");
    CompilerConfiguration configuration = new CompilerConfiguration();
    configuration.addCompilationCustomizers(importCustomizer);
    ClassLoader classLoader = exchange.getContext().getApplicationContextClassLoader();
    return new GroovyShell(classLoader, configuration);
}
 
Example 6
Source File: GroovyMain.java    From groovy with Apache License 2.0 3 votes vote down vote up
private static GroovyShell createConfigScriptsShell(CompilerConfiguration conf) {
    Binding binding = new Binding();
    binding.setVariable("configuration", conf);

    CompilerConfiguration configuratorConfig = new CompilerConfiguration();
    ImportCustomizer customizer = new ImportCustomizer();

    customizer.addStaticStars("org.codehaus.groovy.control.customizers.builder.CompilerCustomizationBuilder");

    configuratorConfig.addCompilationCustomizers(customizer);

    return new GroovyShell(binding, configuratorConfig);
}