/** * Create a new {@link GroovyCompiler} instance. * @param configuration the compiler configuration */ public GroovyCompiler(final GroovyCompilerConfiguration configuration) { this.configuration = configuration; this.loader = createLoader(configuration); DependencyResolutionContext resolutionContext = new DependencyResolutionContext(); AetherGrapeEngine grapeEngine = AetherGrapeEngineFactory.create(this.loader, configuration.getRepositoryConfiguration(), resolutionContext); GrapeEngineInstaller.install(grapeEngine); this.loader.getConfiguration() .addCompilationCustomizers(new CompilerAutoConfigureCustomizer()); if (configuration.isAutoconfigure()) { this.compilerAutoConfigurations = ServiceLoader .load(CompilerAutoConfiguration.class); } else { this.compilerAutoConfigurations = Collections.emptySet(); } this.transformations = new ArrayList<ASTTransformation>(); this.transformations .add(new DependencyManagementBomTransformation(resolutionContext)); this.transformations.add(new DependencyAutoConfigurationTransformation( this.loader, resolutionContext, this.compilerAutoConfigurations)); this.transformations.add(new GroovyBeansTransformation()); if (this.configuration.isGuessDependencies()) { this.transformations.add( new ResolveDependencyCoordinatesTransformation(resolutionContext)); } for (ASTTransformation transformation : ServiceLoader .load(SpringBootAstTransformation.class)) { this.transformations.add(transformation); } Collections.sort(this.transformations, AnnotationAwareOrderComparator.INSTANCE); }
private URLClassLoader populateClassloader(OptionSet options) throws MalformedURLException { DependencyResolutionContext resolutionContext = new DependencyResolutionContext(); List<RepositoryConfiguration> repositoryConfiguration = RepositoryConfigurationFactory .createDefaultRepositoryConfiguration(); repositoryConfiguration.add(0, new RepositoryConfiguration("local", new File("repository").toURI(), true)); boolean quiet = true; if (options.has(debugOption)) { System.setProperty("groovy.grape.report.downloads", "true"); quiet = false; } AetherGrapeEngine grapeEngine = AetherGrapeEngineFactory.create(null, repositoryConfiguration, resolutionContext, quiet); HashMap<String, Object> dependency = new HashMap<>(); dependency.put("group", "org.springframework.cloud.launcher"); dependency.put("module", "spring-cloud-launcher-deployer"); dependency.put("version", getVersion()); dependency.put("transitive", false); URI[] uris = grapeEngine.resolve(null, dependency); URLClassLoader loader = new URLClassLoader(new URL[] { uris[0].toURL() }, getClass().getClassLoader().getParent().getParent()); log.debug("resolved URIs " + Arrays.asList(loader.getURLs())); return loader; }