@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; }
@Override public List<File> resolve(List<String> artifactIdentifiers) throws CompilationFailedException, IOException { GroovyCompiler groovyCompiler = new GroovyCompiler(this.configuration); List<File> artifactFiles = new ArrayList<File>(); 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; }
/** * Create a new {@link SpringApplicationRunner} instance. * @param configuration the configuration * @param sources the files to compile/watch * @param args input arguments */ SpringApplicationRunner(final 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("groovy.grape.report.downloads", "true"); System.setProperty("trace", "true"); } else if (level <= Level.FINE.intValue()) { System.setProperty("debug", "true"); } else if (level == Level.OFF.intValue()) { System.setProperty("spring.main.showBanner", "false"); System.setProperty("logging.level.ROOT", "OFF"); } }
@Override protected ExitStatus run(OptionSet options) throws Exception { List<?> nonOptionArguments = new ArrayList<Object>( options.nonOptionArguments()); Assert.isTrue(nonOptionArguments.size() >= 2, "The name of the resulting " + this.type + " and at least one source file must be specified"); File output = new File((String) nonOptionArguments.remove(0)); Assert.isTrue(output.getName().toLowerCase().endsWith("." + this.type), "The output '" + output + "' is not a " + this.type.toUpperCase() + " file."); deleteIfExists(output); GroovyCompiler compiler = createCompiler(options); List<URL> classpath = getClassPathUrls(compiler); List<MatchedResource> classpathEntries = findMatchingClasspathEntries( classpath, options); String[] sources = new SourceOptions(nonOptionArguments).getSourcesArray(); Class<?>[] compiledClasses = compiler.compile(sources); List<URL> dependencies = getClassPathUrls(compiler); dependencies.removeAll(classpath); writeJar(output, compiledClasses, classpathEntries, dependencies); 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 List<URL> getClassPathUrls(GroovyCompiler compiler) { return new ArrayList<URL>(Arrays.asList(compiler.getLoader().getURLs())); }
/** * Create a new {@link TestRunner} instance. * @param configuration the configuration * @param sources the sources * @param args the args */ TestRunner(TestRunnerConfiguration configuration, String[] sources, String[] args) { this.sources = sources.clone(); this.compiler = new GroovyCompiler(configuration); }