/** * Create a new {@link SpringApplicationRunner} instance. * @param configuration the configuration * @param sources the files to compile/watch * @param args input arguments */ SpringApplicationRunner(SpringApplicationRunnerConfiguration configuration, String[] sources, String... args) { this.configuration = configuration; this.sources = sources.clone(); this.args = args.clone(); this.compiler = new GroovyCompiler(configuration); int level = configuration.getLogLevel().intValue(); if (level <= Level.FINER.intValue()) { System.setProperty( "org.springframework.boot.cli.compiler.grape.ProgressReporter", "detail"); System.setProperty("trace", "true"); } else if (level <= Level.FINE.intValue()) { System.setProperty("debug", "true"); } else if (level == Level.OFF.intValue()) { System.setProperty("spring.main.banner-mode", "OFF"); System.setProperty("logging.level.ROOT", "OFF"); System.setProperty( "org.springframework.boot.cli.compiler.grape.ProgressReporter", "none"); } }
@Override public List<File> resolve(List<String> artifactIdentifiers) throws CompilationFailedException, IOException { GroovyCompiler groovyCompiler = new GroovyCompiler(this.configuration); List<File> artifactFiles = new ArrayList<>(); if (!artifactIdentifiers.isEmpty()) { List<URL> initialUrls = getClassPathUrls(groovyCompiler); groovyCompiler.compile(createSources(artifactIdentifiers)); List<URL> artifactUrls = getClassPathUrls(groovyCompiler); artifactUrls.removeAll(initialUrls); for (URL artifactUrl : artifactUrls) { artifactFiles.add(toFile(artifactUrl)); } } return artifactFiles; }
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; }
@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; }