Skip to content

Commit 5defa42

Browse files
committed
Update AetherGrapeEngineTests to only use milestone repo when needed
Closes gh-3051
1 parent bd3a40c commit 5defa42

File tree

1 file changed

+26
-23
lines changed

1 file changed

+26
-23
lines changed

spring-boot-cli/src/test/java/org/springframework/boot/cli/compiler/grape/AetherGrapeEngineTests.java

Lines changed: 26 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import java.io.File;
2222
import java.net.URI;
2323
import java.net.URL;
24+
import java.util.ArrayList;
2425
import java.util.Arrays;
2526
import java.util.Collections;
2627
import java.util.HashMap;
@@ -46,22 +47,24 @@ public class AetherGrapeEngineTests {
4647

4748
private final GroovyClassLoader groovyClassLoader = new GroovyClassLoader();
4849

49-
private final AetherGrapeEngine grapeEngine = createGrapeEngine();
50-
51-
private AetherGrapeEngine createGrapeEngine() {
52-
return AetherGrapeEngineFactory.create(this.groovyClassLoader, Arrays
53-
.asList(new RepositoryConfiguration("central", URI
54-
.create("http://repo1.maven.org/maven2"), false),
55-
new RepositoryConfiguration("spring-milestone", URI
56-
.create("http://repo.spring.io/milestone"), false)),
57-
new DependencyResolutionContext());
50+
private final RepositoryConfiguration springMilestones = new RepositoryConfiguration(
51+
"spring-milestones", URI.create("https://repo.spring.io/milestone"), false);
52+
53+
private AetherGrapeEngine createGrapeEngine(
54+
RepositoryConfiguration... additionalRepositories) {
55+
List<RepositoryConfiguration> repositoryConfigurations = new ArrayList<RepositoryConfiguration>();
56+
repositoryConfigurations.add(new RepositoryConfiguration("central", URI
57+
.create("http://repo1.maven.org/maven2"), false));
58+
repositoryConfigurations.addAll(Arrays.asList(additionalRepositories));
59+
return AetherGrapeEngineFactory.create(this.groovyClassLoader,
60+
repositoryConfigurations, new DependencyResolutionContext());
5861
}
5962

6063
@Test
6164
public void dependencyResolution() {
6265
Map<String, Object> args = new HashMap<String, Object>();
6366

64-
this.grapeEngine.grab(args,
67+
createGrapeEngine(this.springMilestones).grab(args,
6568
createDependency("org.springframework", "spring-jdbc", "3.2.4.RELEASE"));
6669

6770
assertEquals(5, this.groovyClassLoader.getURLs().length);
@@ -94,7 +97,7 @@ public void run() {
9497

9598
List<RemoteRepository> repositories = (List<RemoteRepository>) ReflectionTestUtils
9699
.getField(grapeEngine, "repositories");
97-
assertEquals(2, repositories.size());
100+
assertEquals(1, repositories.size());
98101
assertEquals("central-mirror", repositories.get(0).getId());
99102
}
100103
});
@@ -111,7 +114,7 @@ public void run() {
111114

112115
List<RemoteRepository> repositories = (List<RemoteRepository>) ReflectionTestUtils
113116
.getField(grapeEngine, "repositories");
114-
assertEquals(2, repositories.size());
117+
assertEquals(1, repositories.size());
115118
Authentication authentication = repositories.get(0).getAuthentication();
116119
assertNotNull(authentication);
117120
}
@@ -125,7 +128,7 @@ public void dependencyResolutionWithExclusions() {
125128
args.put("excludes",
126129
Arrays.asList(createExclusion("org.springframework", "spring-core")));
127130

128-
this.grapeEngine.grab(args,
131+
createGrapeEngine(this.springMilestones).grab(args,
129132
createDependency("org.springframework", "spring-jdbc", "3.2.4.RELEASE"),
130133
createDependency("org.springframework", "spring-beans", "3.2.4.RELEASE"));
131134

@@ -136,7 +139,7 @@ public void dependencyResolutionWithExclusions() {
136139
public void nonTransitiveDependencyResolution() {
137140
Map<String, Object> args = new HashMap<String, Object>();
138141

139-
this.grapeEngine.grab(
142+
createGrapeEngine().grab(
140143
args,
141144
createDependency("org.springframework", "spring-jdbc", "3.2.4.RELEASE",
142145
false));
@@ -150,7 +153,7 @@ public void dependencyResolutionWithCustomClassLoader() {
150153
GroovyClassLoader customClassLoader = new GroovyClassLoader();
151154
args.put("classLoader", customClassLoader);
152155

153-
this.grapeEngine.grab(args,
156+
createGrapeEngine(this.springMilestones).grab(args,
154157
createDependency("org.springframework", "spring-jdbc", "3.2.4.RELEASE"));
155158

156159
assertEquals(0, this.groovyClassLoader.getURLs().length);
@@ -160,10 +163,10 @@ public void dependencyResolutionWithCustomClassLoader() {
160163
@Test
161164
public void resolutionWithCustomResolver() {
162165
Map<String, Object> args = new HashMap<String, Object>();
163-
this.grapeEngine.addResolver(createResolver("restlet.org",
164-
"http://maven.restlet.org"));
165-
this.grapeEngine.grab(args,
166-
createDependency("org.restlet", "org.restlet", "1.1.6"));
166+
AetherGrapeEngine grapeEngine = this.createGrapeEngine();
167+
grapeEngine
168+
.addResolver(createResolver("restlet.org", "http://maven.restlet.org"));
169+
grapeEngine.grab(args, createDependency("org.restlet", "org.restlet", "1.1.6"));
167170
assertEquals(1, this.groovyClassLoader.getURLs().length);
168171
}
169172

@@ -173,7 +176,7 @@ public void differingTypeAndExt() {
173176
"grails-dependencies", "2.4.0");
174177
dependency.put("type", "foo");
175178
dependency.put("ext", "bar");
176-
this.grapeEngine.grab(Collections.emptyMap(), dependency);
179+
createGrapeEngine().grab(Collections.emptyMap(), dependency);
177180
}
178181

179182
@Test
@@ -182,7 +185,7 @@ public void pomDependencyResolutionViaType() {
182185
Map<String, Object> dependency = createDependency("org.springframework",
183186
"spring-framework-bom", "4.0.5.RELEASE");
184187
dependency.put("type", "pom");
185-
this.grapeEngine.grab(args, dependency);
188+
createGrapeEngine().grab(args, dependency);
186189
URL[] urls = this.groovyClassLoader.getURLs();
187190
assertEquals(1, urls.length);
188191
assertTrue(urls[0].toExternalForm().endsWith(".pom"));
@@ -194,7 +197,7 @@ public void pomDependencyResolutionViaExt() {
194197
Map<String, Object> dependency = createDependency("org.springframework",
195198
"spring-framework-bom", "4.0.5.RELEASE");
196199
dependency.put("ext", "pom");
197-
this.grapeEngine.grab(args, dependency);
200+
createGrapeEngine().grab(args, dependency);
198201
URL[] urls = this.groovyClassLoader.getURLs();
199202
assertEquals(1, urls.length);
200203
assertTrue(urls[0].toExternalForm().endsWith(".pom"));
@@ -207,7 +210,7 @@ public void resolutionWithClassifier() {
207210
Map<String, Object> dependency = createDependency("org.springframework",
208211
"spring-jdbc", "3.2.4.RELEASE", false);
209212
dependency.put("classifier", "sources");
210-
this.grapeEngine.grab(args, dependency);
213+
createGrapeEngine().grab(args, dependency);
211214

212215
URL[] urls = this.groovyClassLoader.getURLs();
213216
assertEquals(1, urls.length);

0 commit comments

Comments
 (0)