Search in sources :

Example 1 with AndroidManifest

use of org.robolectric.manifest.AndroidManifest in project android-oss by kickstarter.

the class KSRobolectricGradleTestRunner method getAppManifest.

@Override
protected AndroidManifest getAppManifest(final Config config) {
    if (config.constants() == Void.class) {
        Logger.error("Field 'constants' not specified in @Config annotation");
        Logger.error("This is required when using RobolectricGradleTestRunner!");
        throw new RuntimeException("No 'constants' field in @Config annotation!");
    }
    final String type = getType(config);
    final String flavor = getFlavor(config);
    final String packageName = getPackageName(config);
    final FileFsFile res;
    final FileFsFile assets;
    final FileFsFile manifest;
    // res/merged added in Android Gradle plugin 1.3-beta1
    if (FileFsFile.from(BUILD_OUTPUT, "res", "merged").exists()) {
        res = FileFsFile.from(BUILD_OUTPUT, "res", "merged", flavor, type);
    } else if (FileFsFile.from(BUILD_OUTPUT, "res").exists()) {
        res = FileFsFile.from(BUILD_OUTPUT, "res", flavor, type);
    } else {
        res = FileFsFile.from(BUILD_OUTPUT, "bundles", flavor, type, "res");
    }
    if (FileFsFile.from(BUILD_OUTPUT, "assets").exists()) {
        assets = FileFsFile.from(BUILD_OUTPUT, "assets", flavor, type);
    } else {
        assets = FileFsFile.from(BUILD_OUTPUT, "bundles", flavor, type, "assets");
    }
    if (FileFsFile.from(BUILD_OUTPUT, "manifests").exists()) {
        manifest = FileFsFile.from(BUILD_OUTPUT, "manifests", "full", flavor, type, "AndroidManifest.xml");
    } else {
        manifest = FileFsFile.from(BUILD_OUTPUT, "bundles", flavor, type, "AndroidManifest.xml");
    }
    Logger.debug("Robolectric assets directory: " + assets.getPath());
    Logger.debug("   Robolectric res directory: " + res.getPath());
    Logger.debug("   Robolectric manifest path: " + manifest.getPath());
    Logger.debug("    Robolectric package name: " + packageName);
    return new AndroidManifest(manifest, res, assets) {

        @Override
        public String getRClassName() throws Exception {
            return com.kickstarter.R.class.getName();
        }
    };
}
Also used : FileFsFile(org.robolectric.res.FileFsFile) AndroidManifest(org.robolectric.manifest.AndroidManifest)

Example 2 with AndroidManifest

use of org.robolectric.manifest.AndroidManifest in project robolectric by robolectric.

the class ShadowTypefaceTest method setup.

@Before
public void setup() throws Exception {
    AndroidManifest appManifest = shadowOf(RuntimeEnvironment.application).getAppManifest();
    fontFile = temporaryAsset.createFile(appManifest, "myFont.ttf", "myFontData");
    List<AndroidManifest> libraryManifests = appManifest.getLibraryManifests();
    temporaryAsset.createFile(libraryManifests.get(0), "libFont.ttf", "libFontData");
}
Also used : AndroidManifest(org.robolectric.manifest.AndroidManifest) Before(org.junit.Before)

Example 3 with AndroidManifest

use of org.robolectric.manifest.AndroidManifest 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 4 with AndroidManifest

use of org.robolectric.manifest.AndroidManifest in project robolectric by robolectric.

the class GradleManifestFactory method create.

@Override
public AndroidManifest create(ManifestIdentifier manifestIdentifier) {
    FsFile manifestFile = manifestIdentifier.getManifestFile();
    FsFile resDir = manifestIdentifier.getResDir();
    FsFile assetDir = manifestIdentifier.getAssetDir();
    final String packageName = manifestIdentifier.getPackageName();
    Logger.debug("Robolectric assets directory: " + assetDir.getPath());
    Logger.debug("   Robolectric res directory: " + resDir.getPath());
    Logger.debug("   Robolectric manifest path: " + manifestFile.getPath());
    Logger.debug("    Robolectric package name: " + packageName);
    return new AndroidManifest(manifestFile, resDir, assetDir, packageName);
}
Also used : FileFsFile(org.robolectric.res.FileFsFile) FsFile(org.robolectric.res.FsFile) AndroidManifest(org.robolectric.manifest.AndroidManifest)

Example 5 with AndroidManifest

use of org.robolectric.manifest.AndroidManifest in project robolectric by robolectric.

the class MavenManifestFactory method create.

@Override
public AndroidManifest create(ManifestIdentifier manifestIdentifier) {
    AndroidManifest appManifest;
    FsFile manifestFile = manifestIdentifier.getManifestFile();
    if (manifestFile == null) {
        appManifest = createDummyManifest(manifestIdentifier.getPackageName());
    } else if (!manifestFile.exists()) {
        System.out.println("WARNING: No manifest file found at " + manifestFile.getPath() + ".");
        System.out.println("Falling back to the Android OS resources only.");
        System.out.println("To remove this warning, annotate your test class with @Config(manifest=Config.NONE).");
        appManifest = createDummyManifest(manifestIdentifier.getPackageName());
    } else {
        FsFile resDir = manifestIdentifier.getResDir();
        FsFile assetDir = manifestIdentifier.getAssetDir();
        String packageName = manifestIdentifier.getPackageName();
        Logger.debug("Robolectric assets directory: " + assetDir.getPath());
        Logger.debug("   Robolectric res directory: " + resDir.getPath());
        Logger.debug("   Robolectric manifest path: " + manifestFile.getPath());
        Logger.debug("    Robolectric package name: " + packageName);
        appManifest = new AndroidManifest(manifestFile, resDir, assetDir, packageName);
    }
    List<FsFile> libraryDirs = manifestIdentifier.getLibraryDirs();
    appManifest.setLibraryManifests(createLibraryManifests(appManifest, libraryDirs));
    return appManifest;
}
Also used : FsFile(org.robolectric.res.FsFile) AndroidManifest(org.robolectric.manifest.AndroidManifest)

Aggregations

AndroidManifest (org.robolectric.manifest.AndroidManifest)62 Test (org.junit.Test)28 ArrayList (java.util.ArrayList)10 ResourcePath (org.robolectric.res.ResourcePath)9 Properties (java.util.Properties)8 ActivityData (org.robolectric.manifest.ActivityData)8 Context (android.content.Context)6 BuildConfig (org.robolectric.gradleapp.BuildConfig)6 IntentFilterData (org.robolectric.manifest.IntentFilterData)6 FileFsFile (org.robolectric.res.FileFsFile)5 FsFile (org.robolectric.res.FsFile)5 Config (org.robolectric.annotation.Config)4 ActivityInfo (android.content.pm.ActivityInfo)3 File (java.io.File)3 DefaultManifestFactory (org.robolectric.internal.DefaultManifestFactory)3 ManifestFactory (org.robolectric.internal.ManifestFactory)3 Application (android.app.Application)2 ManifestIdentifier (org.robolectric.internal.ManifestIdentifier)2 ContentProviderData (org.robolectric.manifest.ContentProviderData)2 Sdk (org.robolectric.pluginapi.Sdk)2