Search in sources :

Example 1 with ResourcePath

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);
        }
    };
}
Also used : FsFile(org.robolectric.res.FsFile) LinkedHashSet(java.util.LinkedHashSet) ResourcePath(org.robolectric.res.ResourcePath) ArrayList(java.util.ArrayList) AndroidManifest(org.robolectric.manifest.AndroidManifest)

Example 2 with ResourcePath

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);
    }
}
Also used : ResourcePath(org.robolectric.res.ResourcePath) Fs(org.robolectric.res.Fs) NotNull(org.jetbrains.annotations.NotNull)

Example 3 with ResourcePath

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;
}
Also used : ResourcePath(org.robolectric.res.ResourcePath)

Example 4 with ResourcePath

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")));
}
Also used : ResourcePath(org.robolectric.res.ResourcePath) AndroidManifest(org.robolectric.manifest.AndroidManifest) Test(org.junit.Test)

Example 5 with ResourcePath

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;
}
Also used : R(org.robolectric.R) ResourcePath(org.robolectric.res.ResourcePath) SdkConfig(org.robolectric.internal.SdkConfig) MavenDependencyResolver(org.robolectric.internal.dependency.MavenDependencyResolver) Fs(org.robolectric.res.Fs)

Aggregations

ResourcePath (org.robolectric.res.ResourcePath)5 AndroidManifest (org.robolectric.manifest.AndroidManifest)2 Fs (org.robolectric.res.Fs)2 ArrayList (java.util.ArrayList)1 LinkedHashSet (java.util.LinkedHashSet)1 NotNull (org.jetbrains.annotations.NotNull)1 Test (org.junit.Test)1 R (org.robolectric.R)1 SdkConfig (org.robolectric.internal.SdkConfig)1 MavenDependencyResolver (org.robolectric.internal.dependency.MavenDependencyResolver)1 FsFile (org.robolectric.res.FsFile)1