use of org.robolectric.internal.dependency.DependencyResolver in project robolectric by robolectric.
the class LegacyDependencyResolver method pickOne.
private static DependencyResolver pickOne(Properties properties, DefinitelyNotAClassLoader classLoader) {
String propPath = properties.getProperty("robolectric-deps.properties");
if (propPath != null) {
return new PropertiesDependencyResolver(Paths.get(propPath));
}
String dependencyDir = properties.getProperty("robolectric.dependency.dir");
if (dependencyDir != null || Boolean.parseBoolean(properties.getProperty("robolectric.offline"))) {
return new LocalDependencyResolver(new File(dependencyDir == null ? "." : dependencyDir));
}
URL buildPathPropertiesUrl = classLoader.getResource("robolectric-deps.properties");
if (buildPathPropertiesUrl != null) {
return new PropertiesDependencyResolver(Paths.get(Fs.toUri(buildPathPropertiesUrl)));
}
Class<?> clazz;
try {
clazz = classLoader.loadClass("org.robolectric.internal.dependency.MavenDependencyResolver");
return (DependencyResolver) ReflectionHelpers.callConstructor(clazz);
} catch (ClassNotFoundException e) {
throw new RuntimeException(e);
}
}
use of org.robolectric.internal.dependency.DependencyResolver in project robolectric by robolectric.
the class LegacyDependencyResolverTest method whenRobolectricDependencyDirProperty.
@Test
public void whenRobolectricDependencyDirProperty() throws Exception {
Path jarsPath = tempDirectory.create("jars");
Path sdkJarPath = tempDirectory.createFile("jars/android-all-" + VERSION + ".jar", "...");
properties.setProperty("robolectric.dependency.dir", jarsPath.toString());
DependencyResolver resolver = new LegacyDependencyResolver(properties, mockClassLoader);
URL jarUrl = resolver.getLocalArtifactUrl(DEPENDENCY_COORDS);
assertThat(Fs.fromUrl(jarUrl)).isEqualTo(sdkJarPath);
}
use of org.robolectric.internal.dependency.DependencyResolver in project robolectric by robolectric.
the class LegacyDependencyResolverTest method whenRobolectricDepsPropertiesResource.
@Test
public void whenRobolectricDepsPropertiesResource() throws Exception {
Path depsPath = tempDirectory.createFile("deps.properties", "org.robolectric\\:android-all\\:" + VERSION + ": file-123.jar");
when(mockClassLoader.getResource("robolectric-deps.properties")).thenReturn(meh(depsPath));
DependencyResolver resolver = new LegacyDependencyResolver(properties, mockClassLoader);
URL jarUrl = resolver.getLocalArtifactUrl(DEPENDENCY_COORDS);
assertThat(Fs.fromUrl(jarUrl).toString()).endsWith("file-123.jar");
}
use of org.robolectric.internal.dependency.DependencyResolver in project robolectric by robolectric.
the class LegacyDependencyResolverTest method whenRobolectricDepsPropertiesProperty.
@Test
public void whenRobolectricDepsPropertiesProperty() throws Exception {
Path depsPath = tempDirectory.createFile("deps.properties", "org.robolectric\\:android-all\\:" + VERSION + ": file-123.jar");
Path jarPath = tempDirectory.createFile("file-123.jar", "...");
properties.setProperty("robolectric-deps.properties", depsPath.toString());
DependencyResolver resolver = new LegacyDependencyResolver(properties, mockClassLoader);
URL jarUrl = resolver.getLocalArtifactUrl(DEPENDENCY_COORDS);
assertThat(Fs.fromUrl(jarUrl)).isEqualTo(jarPath);
}
use of org.robolectric.internal.dependency.DependencyResolver in project robolectric by robolectric.
the class LegacyDependencyResolverTest method whenNoPropertiesOrResourceFile.
@Test
public void whenNoPropertiesOrResourceFile() throws Exception {
when(mockClassLoader.getResource("robolectric-deps.properties")).thenReturn(null);
when(mockClassLoader.loadClass("org.robolectric.internal.dependency.MavenDependencyResolver")).thenReturn((Class) FakeMavenDependencyResolver.class);
DependencyResolver resolver = new LegacyDependencyResolver(properties, mockClassLoader);
URL jarUrl = resolver.getLocalArtifactUrl(DEPENDENCY_COORDS);
assertThat(Fs.fromUrl(jarUrl)).isEqualTo(Paths.get("/some/fake/file.jar").toAbsolutePath());
}
Aggregations