Remove Boot-specifics from AetherGrapeEngine
With the goal of making AetherGrapeEngine generally useful with Groovy, this commit removes any Boot specifics from it. Specifically, there is now only a single default repository: Maven Central. The Boot-specific Spring milestone and snapshot repositories are now added via @GrabResolver annotations that are added using an ASTTransformation. As part of this change, AetherGrapeEngine has also been updated to store its repositories using a LinkedHashSet, this ensures that the same repository is not used more than once while maintaining their ordering.
This commit is contained in:
parent
b05f3e2eec
commit
32fc2c3d1c
|
|
@ -44,6 +44,7 @@ import org.codehaus.groovy.transform.ASTTransformationVisitor;
|
|||
import org.springframework.boot.cli.compiler.grape.AetherGrapeEngine;
|
||||
import org.springframework.boot.cli.compiler.grape.GrapeEngineInstaller;
|
||||
import org.springframework.boot.cli.compiler.transformation.DependencyAutoConfigurationTransformation;
|
||||
import org.springframework.boot.cli.compiler.transformation.GrabResolversAutoConfigurationTransformation;
|
||||
import org.springframework.boot.cli.compiler.transformation.ResolveDependencyCoordinatesTransformation;
|
||||
|
||||
/**
|
||||
|
|
@ -95,6 +96,7 @@ public class GroovyCompiler {
|
|||
CompilerAutoConfiguration.class, GroovyCompiler.class.getClassLoader());
|
||||
|
||||
this.transformations = new ArrayList<ASTTransformation>();
|
||||
this.transformations.add(new GrabResolversAutoConfigurationTransformation());
|
||||
this.transformations.add(new DependencyAutoConfigurationTransformation(
|
||||
this.loader, this.coordinatesResolver, this.compilerAutoConfigurations));
|
||||
if (this.configuration.isGuessDependencies()) {
|
||||
|
|
|
|||
|
|
@ -25,8 +25,10 @@ import java.net.URI;
|
|||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import org.apache.maven.repository.internal.MavenRepositorySystemUtils;
|
||||
import org.eclipse.aether.DefaultRepositorySystemSession;
|
||||
|
|
@ -78,7 +80,7 @@ public class AetherGrapeEngine implements GrapeEngine {
|
|||
|
||||
private final RepositorySystem repositorySystem;
|
||||
|
||||
private final List<RemoteRepository> repositories;
|
||||
private final Set<RemoteRepository> repositories;
|
||||
|
||||
public AetherGrapeEngine(GroovyClassLoader classLoader) {
|
||||
this.classLoader = classLoader;
|
||||
|
|
@ -115,19 +117,13 @@ public class AetherGrapeEngine implements GrapeEngine {
|
|||
return new File(System.getProperty("user.home"), ".m2");
|
||||
}
|
||||
|
||||
private List<RemoteRepository> getRemoteRepositories() {
|
||||
List<RemoteRepository> repositories = new ArrayList<RemoteRepository>();
|
||||
private Set<RemoteRepository> getRemoteRepositories() {
|
||||
LinkedHashSet<RemoteRepository> repositories = new LinkedHashSet<RemoteRepository>();
|
||||
addRemoteRepository(repositories, "central", "http://repo1.maven.org/maven2/");
|
||||
if (!Boolean.getBoolean("disableSpringSnapshotRepos")) {
|
||||
addRemoteRepository(repositories, "spring-snapshot",
|
||||
"http://repo.spring.io/snapshot");
|
||||
addRemoteRepository(repositories, "spring-milestone",
|
||||
"http://repo.spring.io/milestone");
|
||||
}
|
||||
return repositories;
|
||||
}
|
||||
|
||||
private void addRemoteRepository(List<RemoteRepository> repositories, String id,
|
||||
private void addRemoteRepository(Set<RemoteRepository> repositories, String id,
|
||||
String url) {
|
||||
repositories.add(new RemoteRepository.Builder(id, "default", url).build());
|
||||
}
|
||||
|
|
@ -221,7 +217,7 @@ public class AetherGrapeEngine implements GrapeEngine {
|
|||
throws ArtifactResolutionException {
|
||||
try {
|
||||
CollectRequest collectRequest = new CollectRequest((Dependency) null,
|
||||
dependencies, this.repositories);
|
||||
dependencies, new ArrayList<RemoteRepository>(this.repositories));
|
||||
DependencyRequest dependencyRequest = new DependencyRequest(collectRequest,
|
||||
DependencyFilterUtils.classpathFilter(JavaScopes.COMPILE));
|
||||
DependencyResult dependencyResult = this.repositorySystem
|
||||
|
|
|
|||
|
|
@ -0,0 +1,61 @@
|
|||
/*
|
||||
* Copyright 2012-2013 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.boot.cli.compiler.transformation;
|
||||
|
||||
import groovy.lang.GrabResolver;
|
||||
|
||||
import org.codehaus.groovy.ast.ASTNode;
|
||||
import org.codehaus.groovy.ast.AnnotationNode;
|
||||
import org.codehaus.groovy.ast.ClassNode;
|
||||
import org.codehaus.groovy.ast.ModuleNode;
|
||||
import org.codehaus.groovy.ast.expr.ConstantExpression;
|
||||
import org.codehaus.groovy.control.SourceUnit;
|
||||
import org.codehaus.groovy.transform.ASTTransformation;
|
||||
|
||||
/**
|
||||
* {@link ASTTransformation} to apply Grab resolver auto-configuration, thereby
|
||||
* configuring the repositories available for dependency resolution.
|
||||
*
|
||||
* @author Andy Wilkinson
|
||||
*/
|
||||
public final class GrabResolversAutoConfigurationTransformation implements
|
||||
ASTTransformation {
|
||||
|
||||
@Override
|
||||
public void visit(ASTNode[] nodes, SourceUnit source) {
|
||||
if (!Boolean.getBoolean("disableSpringSnapshotRepos")) {
|
||||
for (ASTNode node : nodes) {
|
||||
if (node instanceof ModuleNode) {
|
||||
ModuleNode module = (ModuleNode) node;
|
||||
ClassNode classNode = module.getClasses().get(0);
|
||||
classNode.addAnnotation(createGrabResolverAnnotation(
|
||||
"spring-snapshot", "http://repo.spring.io/snapshot"));
|
||||
classNode.addAnnotation(createGrabResolverAnnotation(
|
||||
"spring-milestone", "http://repo.spring.io/milestone"));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private AnnotationNode createGrabResolverAnnotation(String name, String url) {
|
||||
AnnotationNode resolverAnnotation = new AnnotationNode(new ClassNode(
|
||||
GrabResolver.class));
|
||||
resolverAnnotation.addMember("name", new ConstantExpression(name));
|
||||
resolverAnnotation.addMember("root", new ConstantExpression(url));
|
||||
return resolverAnnotation;
|
||||
}
|
||||
}
|
||||
|
|
@ -87,23 +87,6 @@ public class AetherGrapeEngineTests {
|
|||
assertEquals(6, customClassLoader.getURLs().length);
|
||||
}
|
||||
|
||||
@Test(expected = DependencyResolutionFailedException.class)
|
||||
public void resolutionWithSnapshotRepositoriesDisabled() {
|
||||
Map<String, Object> args = new HashMap<String, Object>();
|
||||
System.setProperty("disableSpringSnapshotRepos", "true");
|
||||
try {
|
||||
AetherGrapeEngine aetherGrapeEngine = new AetherGrapeEngine(
|
||||
this.groovyClassLoader);
|
||||
aetherGrapeEngine.addResolver(createResolver("restlet.org",
|
||||
"http://maven.restlet.org"));
|
||||
aetherGrapeEngine.grab(args,
|
||||
createDependency("org.springframework", "spring-jdbc", "3.2.0.M1"));
|
||||
}
|
||||
finally {
|
||||
System.clearProperty("disableSpringSnapshotRepos");
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void resolutionWithCustomResolver() {
|
||||
Map<String, Object> args = new HashMap<String, Object>();
|
||||
|
|
|
|||
Loading…
Reference in New Issue