use of org.robolectric.res.ResourcePath in project robolectric by robolectric.
the class BuckManifestFactory method create.
@Override
public AndroidManifest create(ManifestIdentifier manifestIdentifier) {
String buckResDirs = System.getProperty(BUCK_ROBOLECTRIC_RES_DIRECTORIES);
String buckAssetsDirs = System.getProperty(BUCK_ROBOLECTRIC_ASSETS_DIRECTORIES);
String packageName = manifestIdentifier.getPackageName();
FsFile manifestFile = manifestIdentifier.getManifestFile();
final List<String> buckResources = buckResDirs == null ? null : Arrays.asList(buckResDirs.split(File.pathSeparator));
final List<String> buckAssets = buckAssetsDirs == null ? null : Arrays.asList(buckAssetsDirs.split(File.pathSeparator));
final FsFile resDir = (buckResources == null || "".equals(buckResources)) ? null : Fs.fileFromPath(buckResources.get(buckResources.size() - 1));
final FsFile assetsDir = (buckAssets == null || "".equals(buckAssets)) ? null : Fs.fileFromPath(buckAssets.get(buckAssets.size() - 1));
Logger.debug("Robolectric assets directory: " + (assetsDir == null ? null : assetsDir.getPath()));
Logger.debug(" Robolectric res directory: " + (resDir == null ? null : resDir.getPath()));
Logger.debug(" Robolectric manifest path: " + manifestFile.getPath());
Logger.debug(" Robolectric package name: " + packageName);
return new AndroidManifest(manifestFile, resDir, assetsDir, packageName) {
@Override
public List<ResourcePath> getIncludedResourcePaths() {
// Needs stable ordering and no duplicates
Collection<ResourcePath> resourcePaths = new LinkedHashSet<>();
resourcePaths.add(super.getResourcePath());
// Add all the buck resource folders, no duplicates as they are being added to a set.
if (buckResources != null) {
ListIterator<String> it = buckResources.listIterator(buckResources.size());
while (it.hasPrevious()) {
resourcePaths.add(new ResourcePath(getRClass(), Fs.fileFromPath(it.previous()), getAssetsDirectory()));
}
}
return new ArrayList<>(resourcePaths);
}
};
}
use of org.robolectric.res.ResourcePath in project robolectric by robolectric.
the class SdkEnvironment method createRuntimeSdkResourcePath.
@NotNull
private ResourcePath createRuntimeSdkResourcePath(DependencyResolver dependencyResolver) {
try {
Fs systemResFs = Fs.fromJar(dependencyResolver.getLocalArtifactUrl(sdkConfig.getAndroidSdkDependency()));
Class<?> androidRClass = getRobolectricClassLoader().loadClass("android.R");
Class<?> androidInternalRClass = getRobolectricClassLoader().loadClass("com.android.internal.R");
return new ResourcePath(androidRClass, systemResFs.join("res"), systemResFs.join("assets"), androidInternalRClass);
} catch (ClassNotFoundException e) {
throw new RuntimeException(e);
}
}
use of org.robolectric.res.ResourcePath in project robolectric by robolectric.
the class SdkEnvironment method getSystemResourceTable.
public synchronized PackageResourceTable getSystemResourceTable(DependencyResolver dependencyResolver) {
if (systemResourceTable == null) {
ResourcePath resourcePath = createRuntimeSdkResourcePath(dependencyResolver);
systemResourceTable = ResourceTableFactory.newFrameworkResourceTable(resourcePath);
}
return systemResourceTable;
}
use of org.robolectric.res.ResourcePath in project robolectric by robolectric.
the class BuckManifestFactoryTest method multiple_res_dirs.
@Test
public void multiple_res_dirs() throws Exception {
ManifestIdentifier manifestIdentifier = buckManifestFactory.identify(configBuilder.build());
AndroidManifest manifest = buckManifestFactory.create(manifestIdentifier);
assertThat(manifest.getResDirectory()).isEqualTo(FileFsFile.from("buck/res2"));
assertThat(manifest.getAssetsDirectory()).isEqualTo(FileFsFile.from("buck/assets"));
List<ResourcePath> resourcePathList = manifest.getIncludedResourcePaths();
assertThat(resourcePathList.size()).isEqualTo(2);
assertThat(resourcePathList).containsExactly(new ResourcePath(manifest.getRClass(), FileFsFile.from("buck/res2"), FileFsFile.from("buck/assets")), new ResourcePath(manifest.getRClass(), FileFsFile.from("buck/res1"), FileFsFile.from("buck/assets")));
}
use of org.robolectric.res.ResourcePath in project robolectric by robolectric.
the class TestUtil method systemResources.
public static ResourcePath systemResources() {
if (SYSTEM_RESOURCE_PATH == null) {
SdkConfig sdkConfig = new SdkConfig(SdkConfig.MAX_SDK_VERSION);
Fs fs = Fs.fromJar(new MavenDependencyResolver().getLocalArtifactUrl(sdkConfig.getAndroidSdkDependency()));
SYSTEM_RESOURCE_PATH = new ResourcePath(android.R.class, fs.join("res"), fs.join("assets"));
}
return SYSTEM_RESOURCE_PATH;
}
Aggregations