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

The following examples show how to use org.codehaus.groovy.control.customizers.ImportCustomizer#addImports() . 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: GroovyExecutor.java    From hugegraph-loader with Apache License 2.0 6 votes vote down vote up
public void execute(String groovyScript, HugeClient client) {
    CompilerConfiguration config = new CompilerConfiguration();
    config.setScriptBaseClass(DelegatingScript.class.getName());
    ImportCustomizer importCustomizer = new ImportCustomizer();
    importCustomizer.addImports(HugeClient.class.getName());
    importCustomizer.addImports(SchemaManager.class.getName());
    config.addCompilationCustomizers(importCustomizer);

    GroovyShell shell = new GroovyShell(getClass().getClassLoader(),
                                        this.binding, config);

    // Groovy invoke java through the delegating script.
    DelegatingScript script = (DelegatingScript) shell.parse(groovyScript);
    script.setDelegate(client);
    script.run();
}
 
Example 2
Source File: ImportCustomizerFactory.java    From groovy with Apache License 2.0 6 votes vote down vote up
private void addImport(final ImportCustomizer customizer, final Object value) {
    if (value==null) return;
    if (value instanceof Collection) {
        for (Object e : (Collection)value) {
            addImport(customizer, e);
        }
    } else if (value instanceof String) {
        customizer.addImports((String)value);
    } else if (value instanceof Class) {
        customizer.addImports(((Class) value).getName());
    } else if (value instanceof GString) {
        customizer.addImports(value.toString());
    } else {
        throw new RuntimeException("Unsupported import value type ["+value+"]");
    }
}
 
Example 3
Source File: BaseStreamCompilerAutoConfiguration.java    From spring-cloud-cli with Apache License 2.0 5 votes vote down vote up
@Override
public void applyImports(ImportCustomizer imports) throws CompilationFailedException {
	this.integration.applyImports(imports);
	imports.addImports("org.springframework.boot.groovy.cloud.EnableBinding");
	imports.addImport("IntegrationMessageSource",
			"org.springframework.integration.core.MessageSource");
	imports.addStarImports("org.springframework.cloud.stream.annotation",
			"org.springframework.cloud.stream.messaging");
}
 
Example 4
Source File: EurekaClientCompilerAutoConfiguration.java    From spring-cloud-cli with Apache License 2.0 5 votes vote down vote up
@Override
public void applyImports(ImportCustomizer imports) throws CompilationFailedException {
	imports.addImports(
			"org.springframework.cloud.client.discovery.EnableDiscoveryClient",
			"org.springframework.cloud.netflix.eureka.EurekaInstanceConfigBean",
			"org.springframework.cloud.netflix.eureka.EurekaClientConfigBean",
			"org.springframework.cloud.client.discovery.DiscoveryClient",
			"org.springframework.cloud.client.ServiceInstance");
}
 
Example 5
Source File: EurekaServerCompilerAutoConfiguration.java    From spring-cloud-cli with Apache License 2.0 5 votes vote down vote up
@Override
public void applyImports(ImportCustomizer imports) throws CompilationFailedException {
	imports.addImports("org.springframework.cloud.netflix.eureka.server.EnableEurekaServer",
			"org.springframework.cloud.client.discovery.EnableDiscoveryClient",
			"org.springframework.cloud.netflix.eureka.server.EurekaServerConfigBean",
			"org.springframework.cloud.netflix.eureka.EurekaInstanceConfigBean",
			"org.springframework.cloud.netflix.eureka.EurekaClientConfigBean",
			"com.netflix.discovery.DiscoveryClient",
			"com.netflix.appinfo.InstanceInfo");
}
 
Example 6
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 7
Source File: SpringCloudCompilerAutoConfiguration.java    From spring-cloud-cli with Apache License 2.0 4 votes vote down vote up
@Override
public void applyImports(ImportCustomizer imports)
		throws CompilationFailedException {
	imports.addImports("org.springframework.cloud.context.config.annotation.RefreshScope");
}
 
Example 8
Source File: ConfigServerCompilerAutoConfiguration.java    From spring-cloud-cli with Apache License 2.0 4 votes vote down vote up
@Override
public void applyImports(ImportCustomizer imports) throws CompilationFailedException {
	imports.addImports("org.springframework.cloud.config.server.EnableConfigServer");
}
 
Example 9
Source File: StubRunnerCompilerAutoConfiguration.java    From spring-cloud-cli with Apache License 2.0 4 votes vote down vote up
@Override
public void applyImports(ImportCustomizer imports) throws CompilationFailedException {
	imports.addImports("org.springframework.cloud.contract.stubrunner.server.EnableStubRunnerServer");
}