@Override protected AndroidManifest getAppManifest(Config config) { String manifestProperty = "../rosie/src/test/AndroidManifest.xml"; String resProperty = "../rosie/src/main/res"; return new AndroidManifest(Fs.fileFromPath(manifestProperty), Fs.fileFromPath(resProperty)) { @Override public int getTargetSdkVersion() { return MAX_SDK_SUPPORTED_BY_ROBOLECTRIC; } }; } }
@Override protected AndroidManifest getAppManifest(Config config) { String res = String.format("../lib/build/intermediates/res/merged/%1$s/%2$s", BuildConfig.FLAVOR, BuildConfig.BUILD_TYPE); String asset = "src/main/assets"; return new AndroidManifest(Fs.fileFromPath(MANIFEST_PATH), Fs.fileFromPath(res), Fs.fileFromPath(asset)); } }
private FsFile getFsFileFromProperty(String name) { String path = properties.getProperty(name); if (path == null || path.isEmpty()) { return null; } if (path.startsWith("jar")) { try { URL url = new URL(path); return Fs.fromURL(url); } catch (MalformedURLException e) { throw new RuntimeException(e); } } else { return Fs.fileFromPath(path); } } }
@Nonnull private List<FsFile> getDirectoriesFromProperty(String property) { if (property == null) { return Collections.emptyList(); } List<String> dirs; if (property.startsWith("@")) { String filename = property.substring(1); try { dirs = Arrays.asList( new String(Util.readBytes(new FileInputStream(filename)), UTF_8).split("\\n")); } catch (IOException e) { throw new RuntimeException("Cannot read file " + filename); } } else { dirs = Arrays.asList(property.split(File.pathSeparator)); } List<FsFile> files = new ArrayList<>(); for (String dir : dirs) { files.add(Fs.fileFromPath(dir)); } return files; } }
@Override public ManifestIdentifier identify(Config config) { String buckManifest = System.getProperty(BUCK_ROBOLECTRIC_MANIFEST); FsFile manifestFile = Fs.fileFromPath(buckManifest); String buckResDirs = System.getProperty(BUCK_ROBOLECTRIC_RES_DIRECTORIES); String buckAssetsDirs = System.getProperty(BUCK_ROBOLECTRIC_ASSETS_DIRECTORIES); String packageName = config.packageName(); final List<FsFile> buckResources = getDirectoriesFromProperty(buckResDirs); final List<FsFile> buckAssets = getDirectoriesFromProperty(buckAssetsDirs); final FsFile resDir = buckResources.size() == 0 ? null : buckResources.get(buckResources.size() - 1); final FsFile assetsDir = buckAssets.size() == 0 ? null : buckAssets.get(buckAssets.size() - 1); final List<ManifestIdentifier> libraries; if (resDir == null && assetsDir == null) { libraries = null; } else { libraries = new ArrayList<>(); for (int i = 0; i < buckResources.size() - 1; i++) { libraries.add(new ManifestIdentifier((String) null, null, buckResources.get(i), null, null)); } for (int i = 0; i < buckAssets.size() - 1; i++) { libraries.add(new ManifestIdentifier(null, null, null, buckAssets.get(i), null)); } } return new ManifestIdentifier(packageName, manifestFile, resDir, assetsDir, libraries); }
Logger.info("Using Robolectric classes from %s", buildPathPropertiesUrl.getPath()); FsFile propertiesFile = Fs.fileFromPath(buildPathPropertiesUrl.getFile()); try { dependencyResolver = new PropertiesDependencyResolver(propertiesFile, dependencyResolver);
private FsFile getFsFileFromPath(String property) { if (property.startsWith("jar")) { try { URL url = new URL(property); return Fs.fromURL(url); } catch (MalformedURLException e) { throw new RuntimeException(e); } } else { return Fs.fileFromPath(property); } }
@Override protected AndroidManifest getAppManifest(Config config) { String manifestProperty = "../app/src/main/AndroidManifest.xml"; String resProperty = "../app/src/main/res"; return new AndroidManifest(Fs.fileFromPath(manifestProperty), Fs.fileFromPath(resProperty)) { @Override public int getTargetSdkVersion() { return MAX_SDK_SUPPORTED_BY_ROBOLECTRIC; } }; } }
public File getNativeLibraryPath() { String tempPath = System.getProperty("java.io.tmpdir"); if (tempPath == null) { throw new IllegalStateException("Java temporary directory is not defined (java.io.tmpdir)"); } return new File(Fs.fileFromPath(tempPath).join("robolectric-libs", getLibName()).getPath()); }
public File getNativeLibraryPath() { String tempPath = System.getProperty("java.io.tmpdir"); if (tempPath == null) { throw new IllegalStateException("Java temporary directory is not defined (java.io.tmpdir)"); } return new File(Fs.fileFromPath(tempPath).join("robolectric-libs", getLibName()).getPath()); }
public File getNativeLibraryPath() { String tempPath = System.getProperty("java.io.tmpdir"); if (tempPath == null) { throw new IllegalStateException("Java temporary directory is not defined (java.io.tmpdir)"); } return new File(Fs.fileFromPath(tempPath).join("robolectric-libs", getLibName()).getPath()); }
@Implementation public final XmlResourceParser openXmlResourceParser(int cookie, String fileName) throws IOException { XmlBlock xmlBlock = XmlBlock.create(Fs.fileFromPath(fileName), "fixme"); if (xmlBlock == null) { throw new Resources.NotFoundException(fileName); } return getXmlResourceParser(null, xmlBlock, "fixme"); }
@Implementation public final XmlResourceParser openXmlResourceParser(int cookie, String fileName) throws IOException { XmlBlock xmlBlock = XmlBlock.create(Fs.fileFromPath(fileName), "fixme"); if (xmlBlock == null) { throw new Resources.NotFoundException(fileName); } return getXmlResourceParser(null, xmlBlock, "fixme"); }
manifestFile = Fs.fileFromPath(manifestProperty); baseDir = manifestFile.getParent(); } else { resDir = Fs.fileFromPath(resourcesProperty); } else { resDir = baseDir.join(config.resourceDir()); assetDir = Fs.fileFromPath(assetsProperty); } else { assetDir = baseDir.join(config.assetDir());
@Implementation protected final XmlResourceParser openXmlResourceParser(int cookie, String fileName) throws IOException { XmlBlock xmlBlock = XmlBlock.create(Fs.fileFromPath(fileName), resourceTable.getPackageName()); if (xmlBlock == null) { throw new Resources.NotFoundException(fileName); } return getXmlResourceParser(resourceTable, xmlBlock, resourceTable.getPackageName()); }
@Test public void permissionCheck() { AndroidManifest androidManifest = new AndroidManifest(Fs.fileFromPath("build/intermediates/manifests/full/debug/AndroidManifest.xml"), null, null); List<String> permissions = androidManifest.getUsedPermissions(); //List of expected permissions to be present in AndroidManifest.xml String[] expectedPermissions = { "android.permission.ACCESS_NETWORK_STATE", "android.permission.DOWNLOAD_WITHOUT_NOTIFICATION", "android.permission.INTERNET", "android.permission.READ_EXTERNAL_STORAGE", "android.permission.WRITE_EXTERNAL_STORAGE", "android.permission.AUTHENTICATE_ACCOUNTS", "android.permission.GET_ACCOUNTS", "android.permission.MANAGE_ACCOUNTS", "android.permission.USE_CREDENTIALS", "android.permission.WAKE_LOCK" }; //Checking expected permissions one by one for (String permission : expectedPermissions) { if (!permissions.contains(permission)) { showError(permission); } } }