@Override protected ExitStatus run(OptionSet options) throws Exception { SourceOptions sourceOptions = new SourceOptions(options); List<RepositoryConfiguration> repositoryConfiguration = RepositoryConfigurationFactory .createDefaultRepositoryConfiguration(); GroovyCompilerConfiguration configuration = new OptionSetGroovyCompilerConfiguration( options, this, repositoryConfiguration); if (System.getProperty("grape.root") == null) { System.setProperty("grape.root", "."); } GroovyCompiler groovyCompiler = new GroovyCompiler(configuration); groovyCompiler.compile(sourceOptions.getSourcesArray()); return ExitStatus.OK; }
private GroovyCompiler createCompiler(OptionSet options) { List<RepositoryConfiguration> repositoryConfiguration = RepositoryConfigurationFactory .createDefaultRepositoryConfiguration(); GroovyCompilerConfiguration configuration = new OptionSetGroovyCompilerConfiguration( options, this, repositoryConfiguration); GroovyCompiler groovyCompiler = new GroovyCompiler(configuration); groovyCompiler.getAstTransformations().add(0, new GrabAnnotationTransform()); return groovyCompiler; }
private static GroovyCompilerConfiguration createCompilerConfiguration( OptionSet options, CompilerOptionHandler compilerOptionHandler) { List<RepositoryConfiguration> repositoryConfiguration = RepositoryConfigurationFactory .createDefaultRepositoryConfiguration(); return new OptionSetGroovyCompilerConfiguration(options, compilerOptionHandler, repositoryConfiguration) { @Override public boolean isAutoconfigure() { return false; } }; }
@Override public void apply(GroovyClassLoader loader, GroovyCompilerConfiguration configuration, GeneratorContext generatorContext, SourceUnit source, ClassNode classNode) throws CompilationFailedException { if (!AstUtils.hasAtLeastOneAnnotation(classNode, "RunWith")) { AnnotationNode runWith = new AnnotationNode(ClassHelper.make("RunWith")); runWith.addMember("value", new ClassExpression(ClassHelper.make("SpringRunner"))); classNode.addAnnotation(runWith); } }
@Before public void setupResolver() { GroovyCompilerConfiguration configuration = new GroovyCompilerConfiguration() { @Override public boolean isGuessImports() { return true; } @Override public boolean isGuessDependencies() { return true; } @Override public boolean isAutoconfigure() { return false; } @Override public GroovyCompilerScope getScope() { return GroovyCompilerScope.DEFAULT; } @Override public List<RepositoryConfiguration> getRepositoryConfiguration() { return RepositoryConfigurationFactory .createDefaultRepositoryConfiguration(); } @Override public String[] getClasspath() { return new String[] { "." }; } }; this.resolver = new GroovyGrabDependencyResolver(configuration); }
@Override public void apply(GroovyClassLoader loader, GroovyCompilerConfiguration configuration, GeneratorContext generatorContext, SourceUnit source, ClassNode classNode) throws CompilationFailedException { if (!AstUtils.hasAtLeastOneAnnotation(classNode, "RunWith")) { AnnotationNode runwith = new AnnotationNode(ClassHelper.make("RunWith")); runwith.addMember("value", new ClassExpression(ClassHelper.make("SpringJUnit4ClassRunner"))); classNode.addAnnotation(runwith); } }
GroovyGrabDependencyResolver(GroovyCompilerConfiguration configuration) { this.configuration = configuration; }
@Override public void applyToMainClass(GroovyClassLoader loader, GroovyCompilerConfiguration configuration, GeneratorContext generatorContext, SourceUnit source, ClassNode classNode) throws CompilationFailedException { addEnableAutoConfigurationAnnotation(source, classNode); }