|
|
|
@ -18,19 +18,23 @@ package org.springframework.boot.cli.compiler.grape; |
|
|
|
|
|
|
|
|
|
|
|
import groovy.lang.GroovyClassLoader; |
|
|
|
import groovy.lang.GroovyClassLoader; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import java.io.File; |
|
|
|
import java.net.URI; |
|
|
|
import java.net.URI; |
|
|
|
import java.net.URL; |
|
|
|
import java.net.URL; |
|
|
|
import java.util.Arrays; |
|
|
|
import java.util.Arrays; |
|
|
|
import java.util.Collections; |
|
|
|
import java.util.Collections; |
|
|
|
import java.util.HashMap; |
|
|
|
import java.util.HashMap; |
|
|
|
|
|
|
|
import java.util.List; |
|
|
|
import java.util.Map; |
|
|
|
import java.util.Map; |
|
|
|
|
|
|
|
|
|
|
|
import org.eclipse.aether.DefaultRepositorySystemSession; |
|
|
|
import org.eclipse.aether.DefaultRepositorySystemSession; |
|
|
|
import org.eclipse.aether.util.repository.JreProxySelector; |
|
|
|
import org.eclipse.aether.repository.Authentication; |
|
|
|
|
|
|
|
import org.eclipse.aether.repository.RemoteRepository; |
|
|
|
import org.junit.Test; |
|
|
|
import org.junit.Test; |
|
|
|
import org.springframework.test.util.ReflectionTestUtils; |
|
|
|
import org.springframework.test.util.ReflectionTestUtils; |
|
|
|
|
|
|
|
|
|
|
|
import static org.junit.Assert.assertEquals; |
|
|
|
import static org.junit.Assert.assertEquals; |
|
|
|
|
|
|
|
import static org.junit.Assert.assertNotNull; |
|
|
|
import static org.junit.Assert.assertTrue; |
|
|
|
import static org.junit.Assert.assertTrue; |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
@ -42,10 +46,14 @@ public class AetherGrapeEngineTests { |
|
|
|
|
|
|
|
|
|
|
|
private final GroovyClassLoader groovyClassLoader = new GroovyClassLoader(); |
|
|
|
private final GroovyClassLoader groovyClassLoader = new GroovyClassLoader(); |
|
|
|
|
|
|
|
|
|
|
|
private final AetherGrapeEngine grapeEngine = AetherGrapeEngineFactory.create( |
|
|
|
private final AetherGrapeEngine grapeEngine = createGrapeEngine(); |
|
|
|
this.groovyClassLoader, Arrays.asList(new RepositoryConfiguration("central", |
|
|
|
|
|
|
|
URI.create("http://repo1.maven.org/maven2"), false)), |
|
|
|
private AetherGrapeEngine createGrapeEngine() { |
|
|
|
new DependencyResolutionContext()); |
|
|
|
return AetherGrapeEngineFactory.create(this.groovyClassLoader, Arrays |
|
|
|
|
|
|
|
.asList(new RepositoryConfiguration("central", URI |
|
|
|
|
|
|
|
.create("http://repo1.maven.org/maven2"), false)), |
|
|
|
|
|
|
|
new DependencyResolutionContext()); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
public void dependencyResolution() { |
|
|
|
public void dependencyResolution() { |
|
|
|
@ -59,10 +67,53 @@ public class AetherGrapeEngineTests { |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
public void proxySelector() { |
|
|
|
public void proxySelector() { |
|
|
|
DefaultRepositorySystemSession session = (DefaultRepositorySystemSession) ReflectionTestUtils |
|
|
|
doWithCustomUserHome(new Runnable() { |
|
|
|
.getField(this.grapeEngine, "session"); |
|
|
|
|
|
|
|
assertTrue((session.getProxySelector() instanceof CompositeProxySelector) |
|
|
|
@Override |
|
|
|
|| (session.getProxySelector() instanceof JreProxySelector)); |
|
|
|
public void run() { |
|
|
|
|
|
|
|
AetherGrapeEngine grapeEngine = createGrapeEngine(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
DefaultRepositorySystemSession session = (DefaultRepositorySystemSession) ReflectionTestUtils |
|
|
|
|
|
|
|
.getField(grapeEngine, "session"); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
assertTrue(session.getProxySelector() instanceof CompositeProxySelector); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
|
|
|
public void repositoryMirrors() { |
|
|
|
|
|
|
|
doWithCustomUserHome(new Runnable() { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@SuppressWarnings("unchecked") |
|
|
|
|
|
|
|
@Override |
|
|
|
|
|
|
|
public void run() { |
|
|
|
|
|
|
|
AetherGrapeEngine grapeEngine = createGrapeEngine(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
List<RemoteRepository> repositories = (List<RemoteRepository>) ReflectionTestUtils |
|
|
|
|
|
|
|
.getField(grapeEngine, "repositories"); |
|
|
|
|
|
|
|
assertEquals(1, repositories.size()); |
|
|
|
|
|
|
|
assertEquals("central-mirror", repositories.get(0).getId()); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
|
|
|
public void repositoryAuthentication() { |
|
|
|
|
|
|
|
doWithCustomUserHome(new Runnable() { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@SuppressWarnings("unchecked") |
|
|
|
|
|
|
|
@Override |
|
|
|
|
|
|
|
public void run() { |
|
|
|
|
|
|
|
AetherGrapeEngine grapeEngine = createGrapeEngine(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
List<RemoteRepository> repositories = (List<RemoteRepository>) ReflectionTestUtils |
|
|
|
|
|
|
|
.getField(grapeEngine, "repositories"); |
|
|
|
|
|
|
|
assertEquals(1, repositories.size()); |
|
|
|
|
|
|
|
Authentication authentication = repositories.get(0).getAuthentication(); |
|
|
|
|
|
|
|
assertNotNull(authentication); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
}); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@SuppressWarnings("unchecked") |
|
|
|
@SuppressWarnings("unchecked") |
|
|
|
@ -190,4 +241,26 @@ public class AetherGrapeEngineTests { |
|
|
|
exclusion.put("module", module); |
|
|
|
exclusion.put("module", module); |
|
|
|
return exclusion; |
|
|
|
return exclusion; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private void doWithCustomUserHome(Runnable action) { |
|
|
|
|
|
|
|
doWithSystemProperty("user.home", |
|
|
|
|
|
|
|
new File("src/test/resources").getAbsolutePath(), action); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private void doWithSystemProperty(String key, String value, Runnable action) { |
|
|
|
|
|
|
|
String previousValue = setOrClearSystemProperty(key, value); |
|
|
|
|
|
|
|
try { |
|
|
|
|
|
|
|
action.run(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
finally { |
|
|
|
|
|
|
|
setOrClearSystemProperty(key, previousValue); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private String setOrClearSystemProperty(String key, String value) { |
|
|
|
|
|
|
|
if (value != null) { |
|
|
|
|
|
|
|
return System.setProperty(key, value); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
return System.clearProperty(key); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|