@Override protected AndroidManifest getAppManifest(Config config) { String appRoot = "src/main/"; String manifestPath = appRoot + "AndroidManifest.xml"; String resDir = appRoot + "res"; String assetsDir = appRoot + "assets"; //return new AndroidManifest(Fs.fileFromPath("src/main/AndroidManifest.xml"), Fs.fileFromPath(resDir), Fs.fileFromPath(assetsDir)) { return new AndroidManifest(Fs.fileFromPath(manifestPath), Fs.fileFromPath(resDir), Fs.fileFromPath(assetsDir)) { @Override public List<ResourcePath> getIncludedResourcePaths() { List<ResourcePath> paths = super.getIncludedResourcePaths(); paths.add(new ResourcePath(getRClass(), Fs.fileFromPath("src/main/res"), getAssetsDirectory())); paths.add(new ResourcePath(getRClass(), Fs.fileFromPath("src/test/res"), getAssetsDirectory())); return paths; } }; }
@Test public void rememberThatSomeTestRunnerMethodsShouldBeOverridable() throws Exception { // super weak test for now, just remember not to make these methods static! //noinspection UnusedDeclaration class CustomTestRunner extends RobolectricTestRunner { public CustomTestRunner(Class<?> testClass) throws InitializationError { super(testClass); } @Override public PackageResourceLoader createResourceLoader(ResourcePath resourcePath) { return super.createResourceLoader(resourcePath); } @Override protected ResourceLoader createAppResourceLoader(ResourceLoader systemResourceLoader, AndroidManifest appManifest) { return super.createAppResourceLoader(systemResourceLoader, appManifest); } } }
/** * Returns the ResourceProvider for the compile time SDK. */ private static PackageResourceTable getCompiletimeSdkResourceTable() { if (compiletimeSdkResourceTable == null) { ResourceTableFactory resourceTableFactory = new ResourceTableFactory(); compiletimeSdkResourceTable = resourceTableFactory.newFrameworkResourceTable( new ResourcePath(android.R.class, null, null)); } return compiletimeSdkResourceTable; }
@Override protected AndroidManifest getAppManifest(Config config) { String buckManifest = System.getProperty(ROBOLECTRIC_MANIFEST); String buckResourcesProperty = System.getProperty(ROBOLECTRIC_RESOURCE_DIRECTORIES); if (buckManifest != null && buckResourcesProperty != null) { final List<String> buckResources = Arrays.asList(buckResourcesProperty.split(File.pathSeparator)); final FsFile res = Fs.fileFromPath(buckResources.get(buckResources.size() - 1)); final FsFile assets = Fs.fileFromPath(buckResources.get(buckResources.size() - 1)); final FsFile manifest = Fs.fileFromPath(buckManifest); return new AndroidManifest(manifest, res, assets, config.packageName()) { @Override public List<ResourcePath> getIncludedResourcePaths() { Collection<ResourcePath> resourcePaths = new LinkedHashSet<>(); resourcePaths.add(super.getResourcePath()); ListIterator<String> it = buckResources.listIterator(buckResources.size()); while (it.hasPrevious()) { resourcePaths.add(new ResourcePath( getRClass(), getPackageName(), Fs.fileFromPath(it.previous()), getAssetsDirectory())); } return new ArrayList<>(resourcePaths); } }; } else { return null; } }
protected ResourceLoader createAppResourceLoader(ResourceLoader systemResourceLoader, AndroidManifest appManifest) { List<PackageResourceLoader> appAndLibraryResourceLoaders = new ArrayList<PackageResourceLoader>(); for (ResourcePath resourcePath : appManifest.getIncludedResourcePaths()) { appAndLibraryResourceLoaders.add(createResourceLoader(resourcePath)); } OverlayResourceLoader overlayResourceLoader = new OverlayResourceLoader(appManifest.getPackageName(), appAndLibraryResourceLoaders); Map<String, ResourceLoader> resourceLoaders = new HashMap<String, ResourceLoader>(); resourceLoaders.put("android", systemResourceLoader); resourceLoaders.put(appManifest.getPackageName(), overlayResourceLoader); return new RoutingResourceLoader(resourceLoaders); }
public PackageResourceLoader createSystemResourceLoader(MavenCentral mavenCentral, RobolectricTestRunner robolectricTestRunner) { URL url = mavenCentral.getLocalArtifactUrl(robolectricTestRunner, sdkConfig.getSystemResourceDependency()); Fs systemResFs = Fs.fromJar(url); ResourceExtractor resourceExtractor = new ResourceExtractor(getRobolectricClassLoader()); ResourcePath resourcePath = new ResourcePath(resourceExtractor.getProcessedRFile(), resourceExtractor.getPackageName(), systemResFs.join("res"), systemResFs.join("assets")); return new PackageResourceLoader(resourcePath, resourceExtractor); }
private List<String> stringify(Collection<ResourcePath> resourcePaths) { List<String> resourcePathBases = new ArrayList<String>(); for (ResourcePath resourcePath : resourcePaths) { resourcePathBases.add(resourcePath.resourceBase.toString()); } return resourcePathBases; }
@Override protected ResourceLoader createAppResourceLoader(ResourceLoader systemResourceLoader, AndroidManifest appManifest) { List<PackageResourceLoader> appAndLibraryResourceLoaders = new ArrayList<PackageResourceLoader>(); for (ResourcePath resourcePath : appManifest.getIncludedResourcePaths()) { appAndLibraryResourceLoaders.add(createResourceLoader(resourcePath)); } OverlayResourceLoader overlayResourceLoader = new OverlayResourceLoaderWithDummyResources( appManifest.getPackageName(), appAndLibraryResourceLoaders, systemResourceLoader); Map<String, ResourceLoader> resourceLoaders = new HashMap<String, ResourceLoader>(); resourceLoaders.put("android", systemResourceLoader); resourceLoaders.put(appManifest.getPackageName(), overlayResourceLoader); return new RoutingResourceLoader(resourceLoaders); }
public List<ResourcePath> getIncludedResourcePaths() { Collection<ResourcePath> resourcePaths = new LinkedHashSet<ResourcePath>(); // Needs stable ordering and no duplicates resourcePaths.add(getResourcePath()); for (AndroidManifest libraryManifest : getLibraryManifests()) { resourcePaths.addAll(libraryManifest.getIncludedResourcePaths()); } return new ArrayList<ResourcePath>(resourcePaths); }
public PackageResourceLoader createResourceLoader(ResourcePath resourcePath) { return new PackageResourceLoader(resourcePath); }
public SystemResourceExtractor(ResourcePath systemResourcePath) { super(systemResourcePath); }
public static ResourcePath testResources() { return TEST_RESOURCE_PATH; }
public static ResourcePath lib1Resources() { return new ResourcePath(org.robolectric.lib1.R.class, "org.robolectric.lib1", resourceFile("lib1/res"), resourceFile("lib1/assets")); }
public static ResourcePath lib2Resources() { return new ResourcePath(org.robolectric.lib2.R.class, "org.robolectric.lib2", resourceFile("lib2/res"), resourceFile("lib2/assets")); }
public static ResourcePath lib3Resources() { return new ResourcePath(org.robolectric.lib3.R.class, "org.robolectric.lib3", resourceFile("lib3/res"), resourceFile("lib3/assets")); }
public static ResourcePath gradleAppResources() { return new ResourcePath(org.robolectric.gradleapp.R.class, "org.robolectric.gradleapp", resourceFile("gradle/res/layoutFlavor/menuBuildType"), resourceFile("gradle/assets/layoutFlavor/menuBuildType")); }
public ResourcePath getResourcePath() { validate(); return new ResourcePath(getRClass(), getPackageName(), resDirectory, assetsDirectory); }