Search in sources :

Example 1 with CachedDependencyResolver

use of org.robolectric.internal.dependency.CachedDependencyResolver in project robolectric by robolectric.

the class RobolectricTestRunner method getJarResolver.

protected DependencyResolver getJarResolver() {
    if (dependencyResolver == null) {
        if (Boolean.getBoolean("robolectric.offline")) {
            String dependencyDir = System.getProperty("robolectric.dependency.dir", ".");
            dependencyResolver = new LocalDependencyResolver(new File(dependencyDir));
        } else {
            File cacheDir = new File(new File(System.getProperty("java.io.tmpdir")), "robolectric");
            if (cacheDir.exists() || cacheDir.mkdir()) {
                Logger.info("Dependency cache location: %s", cacheDir.getAbsolutePath());
                dependencyResolver = new CachedDependencyResolver(new MavenDependencyResolver(), cacheDir, 60 * 60 * 24 * 1000);
            } else {
                dependencyResolver = new MavenDependencyResolver();
            }
        }
        URL buildPathPropertiesUrl = getClass().getClassLoader().getResource("robolectric-deps.properties");
        if (buildPathPropertiesUrl != null) {
            Logger.info("Using Robolectric classes from %s", buildPathPropertiesUrl.getPath());
            FsFile propertiesFile = Fs.fileFromPath(buildPathPropertiesUrl.getFile());
            try {
                dependencyResolver = new PropertiesDependencyResolver(propertiesFile, dependencyResolver);
            } catch (IOException e) {
                throw new RuntimeException("couldn't read " + buildPathPropertiesUrl, e);
            }
        }
    }
    return dependencyResolver;
}
Also used : FsFile(org.robolectric.res.FsFile) LocalDependencyResolver(org.robolectric.internal.dependency.LocalDependencyResolver) CachedDependencyResolver(org.robolectric.internal.dependency.CachedDependencyResolver) PropertiesDependencyResolver(org.robolectric.internal.dependency.PropertiesDependencyResolver) MavenDependencyResolver(org.robolectric.internal.dependency.MavenDependencyResolver) IOException(java.io.IOException) File(java.io.File) FsFile(org.robolectric.res.FsFile) URL(java.net.URL)

Aggregations

File (java.io.File)1 IOException (java.io.IOException)1 URL (java.net.URL)1 CachedDependencyResolver (org.robolectric.internal.dependency.CachedDependencyResolver)1 LocalDependencyResolver (org.robolectric.internal.dependency.LocalDependencyResolver)1 MavenDependencyResolver (org.robolectric.internal.dependency.MavenDependencyResolver)1 PropertiesDependencyResolver (org.robolectric.internal.dependency.PropertiesDependencyResolver)1 FsFile (org.robolectric.res.FsFile)1