use of org.robolectric.res.FileFsFile 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();
}
};
}
use of org.robolectric.res.FileFsFile in project robolectric by robolectric.
the class TemporaryAsset method createFile.
public File createFile(AndroidManifest manifest, String fileName, String contents) throws Exception {
File assetBase = ((FileFsFile) manifest.getAssetsDirectory()).getFile();
File file = new File(assetBase, fileName);
file.getParentFile().mkdirs();
FileWriter fileWriter = new FileWriter(file);
try {
fileWriter.write(contents);
} finally {
fileWriter.close();
}
assetsToDelete.add(file);
return file;
}
use of org.robolectric.res.FileFsFile in project robolectric by robolectric.
the class GradleManifestFactory method identify.
@Override
public ManifestIdentifier identify(Config config) {
if (config.constants() == Void.class) {
Logger.error("Field 'constants' not specified in @Config annotation");
Logger.error("This is required when using Robolectric with Gradle!");
throw new RuntimeException("No 'constants' field in @Config annotation!");
}
final String buildOutputDir = getBuildOutputDir(config);
final String type = getType(config);
final String flavor = getFlavor(config);
final String abiSplit = getAbiSplit(config);
final String packageName = config.packageName().isEmpty() ? config.constants().getPackage().getName() : config.packageName();
final FileFsFile res;
final FileFsFile assets;
final FileFsFile manifest;
if (FileFsFile.from(buildOutputDir, "data-binding-layout-out").exists()) {
// Android gradle plugin 1.5.0+ puts the merged layouts in data-binding-layout-out.
// https://github.com/robolectric/robolectric/issues/2143
res = FileFsFile.from(buildOutputDir, "data-binding-layout-out", flavor, type);
} else if (FileFsFile.from(buildOutputDir, "res", "merged").exists()) {
// res/merged added in Android Gradle plugin 1.3-beta1
res = FileFsFile.from(buildOutputDir, "res", "merged", flavor, type);
} else if (FileFsFile.from(buildOutputDir, "res").exists()) {
res = FileFsFile.from(buildOutputDir, "res", flavor, type);
} else {
res = FileFsFile.from(buildOutputDir, "bundles", flavor, type, "res");
}
if (!Config.DEFAULT_ASSET_FOLDER.equals(config.assetDir()) && FileFsFile.from(buildOutputDir, config.assetDir()).exists()) {
assets = FileFsFile.from(buildOutputDir, config.assetDir());
} else if (FileFsFile.from(buildOutputDir, "assets").exists()) {
assets = FileFsFile.from(buildOutputDir, "assets", flavor, type);
} else {
assets = FileFsFile.from(buildOutputDir, "bundles", flavor, type, "assets");
}
String manifestName = config.manifest();
URL manifestUrl = getClass().getClassLoader().getResource(manifestName);
if (manifestUrl != null && manifestUrl.getProtocol().equals("file")) {
manifest = FileFsFile.from(manifestUrl.getPath());
} else if (FileFsFile.from(buildOutputDir, "manifests", "full").exists()) {
manifest = FileFsFile.from(buildOutputDir, "manifests", "full", flavor, abiSplit, type, manifestName);
} else if (FileFsFile.from(buildOutputDir, "manifests", "aapt").exists()) {
// Android gradle plugin 2.2.0+ can put library manifest files inside of "aapt" instead of "full"
manifest = FileFsFile.from(buildOutputDir, "manifests", "aapt", flavor, abiSplit, type, manifestName);
} else {
manifest = FileFsFile.from(buildOutputDir, "bundles", flavor, abiSplit, type, manifestName);
}
return new ManifestIdentifier(manifest, res, assets, packageName, null);
}
use of org.robolectric.res.FileFsFile in project edx-app-android by edx.
the class DataBindingRobolectricGradleTestRunner method getAppManifest.
@Override
protected AndroidManifest getAppManifest(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;
if (FileFsFile.from(BUILD_OUTPUT, "data-binding-layout-out").exists()) {
// Android gradle plugin 1.5.0+ puts the merged layouts in data-binding-layout-out.
// https://github.com/robolectric/robolectric/issues/2143
res = FileFsFile.from(BUILD_OUTPUT, "data-binding-layout-out", flavor, type);
} else if (FileFsFile.from(BUILD_OUTPUT, "res", "merged").exists()) {
// res/merged added in Android Gradle plugin 1.3-beta1
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, packageName);
}
use of org.robolectric.res.FileFsFile in project algoliasearch-client-android by algolia.
the class CustomRunner method getAppManifest.
@Override
protected AndroidManifest getAppManifest(Config config) {
final String cwd = System.getProperty("user.dir");
Logger.debug("Current working directory: " + cwd);
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;
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()) {
// [CUSTOMIZED] The default implementation uses `full` instead of `aapt`.
manifest = FileFsFile.from(BUILD_OUTPUT, "manifests", "aapt", 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, packageName);
}
Aggregations