@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; } }; } }
/** @deprecated Use {@link #fromUrl(String)} instead. */ @Deprecated public static Path fileFromPath(String path) { return Fs.fromUrl(path); }
FileTypedResource(Path path, ResType resType, XmlContext xmlContext) { super(Fs.externalize(path), resType, xmlContext); this.path = path; }
public static Asset newFileAsset(FileTypedResource fileTypedResource) throws IOException { _FileAsset fileAsset = new _FileAsset(); Path path = fileTypedResource.getPath(); fileAsset.mFileName = Fs.externalize(path); fileAsset.mLength = Files.size(path); fileAsset.mBuf = Fs.getBytes(path); return fileAsset; }
private void listDrawableResources(Path dir, String type) throws IOException { Path[] files = Fs.listFiles(dir); if (files != null) { Qualifiers qualifiers; isNinePatch = true; } else { shortName = Fs.baseNameFor(f); isNinePatch = false;
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); } } }
public synchronized FsFile getCompileTimeSystemResourcesFile(DependencyResolver dependencyResolver) { if (compileTimeSystemResourcesFile == null) { DependencyJar compileTimeJar = new SdkConfig(27).getAndroidSdkDependency(); compileTimeSystemResourcesFile = Fs.newFile(dependencyResolver.getLocalArtifactUrl(compileTimeJar).getFile()); } return compileTimeSystemResourcesFile; }
try { dependencyResolver = new PropertiesDependencyResolver( Fs.newFile(propPath), null); } catch (IOException e) { Logger.info("Using Robolectric classes from %s", buildPathPropertiesUrl.getPath()); FsFile propertiesFile = Fs.fileFromPath(buildPathPropertiesUrl.getFile()); try { dependencyResolver = new PropertiesDependencyResolver(propertiesFile, dependencyResolver);
private static Path resourceFile(String... pathParts) { return Fs.join(resourcesBaseDir(), pathParts); }
@Nonnull 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"); // TODO: verify these can be loaded via raw-res path return new ResourcePath(androidRClass, systemResFs.join("raw-res/res"), systemResFs.join("raw-res/assets"), androidInternalRClass); } catch (ClassNotFoundException e) { throw new RuntimeException(e); } }
private Properties loadProperties(Path propertiesFile) throws IOException { final Properties properties = new Properties(); try (InputStream stream = Fs.getInputStream(propertiesFile)) { properties.load(stream); } return properties; }
void findDrawableResources(ResourcePath resourcePath) throws IOException { Path[] files = Fs.listFiles(resourcePath.getResourceBase()); if (files != null) { for (Path f : files) { if (Files.isDirectory(f) && f.getFileName().toString().startsWith("drawable")) { listDrawableResources(f, "drawable"); } else if (Files.isDirectory(f) && f.getFileName().toString().startsWith("mipmap")) { listDrawableResources(f, "mipmap"); } } } }
@HiddenApi @Implementation public final InputStream openNonAsset(int cookie, String fileName, int accessMode) throws IOException { final ResName resName = qualifyFromNonAssetFileName(fileName); final FileTypedResource typedResource = (FileTypedResource) resourceTable.getValue(resName, config); if (typedResource == null) { throw new IOException("Unable to find resource for " + fileName); } InputStream stream; if (accessMode == AssetManager.ACCESS_STREAMING) { stream = Fs.getInputStream(typedResource.getPath()); } else { stream = new ByteArrayInputStream(Fs.getBytes(typedResource.getPath())); } if (RuntimeEnvironment.getApiLevel() >= P) { Asset asset = Asset.newFileAsset(typedResource); long assetPtr = Registries.NATIVE_ASSET_REGISTRY.register(asset); // Camouflage the InputStream as an AssetInputStream so subsequent instanceof checks pass. stream = ShadowAssetInputStream.createAssetInputStream(stream, assetPtr, realObject); } return stream; }
@Override Collection<Path> getAllAssetDirs() { ArrayList<Path> paths = new ArrayList<>(); for (AssetPath assetPath : cppAssetManager.getAssetPaths()) { if (Files.isRegularFile(assetPath.file)) { paths.add(Fs.forJar(assetPath.file).getPath("assets")); } else { paths.add(assetPath.file); } } return paths; }
@Override Collection<FsFile> getAllAssetDirs() { ApkAssets[] apkAssetsArray = ReflectionHelpers.callInstanceMethod(realAssetManager, "getApkAssets"); ArrayList<FsFile> fsFiles = new ArrayList<>(); for (ApkAssets apkAssets : apkAssetsArray) { long apk_assets_native_ptr = ((ShadowArscApkAssets9) Shadow.extract(apkAssets)).getNativePtr(); CppApkAssets cppApkAssets = Registries.NATIVE_APK_ASSETS_REGISTRY.getNativeObject(apk_assets_native_ptr); if (new File(cppApkAssets.GetPath()).isFile()) { fsFiles.add(Fs.newJarFile(new File(cppApkAssets.GetPath())).join("assets")); } else { fsFiles.add(Fs.newFile(cppApkAssets.GetPath())); } } return fsFiles; }
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 public TypedResource getValue(@Nonnull ResName resName, ResTable_config config) { System.out.println("getValue(" + resName + ", \"" + config + "\")"); return new TypedResource<>(null, ResType.NULL, new XmlContext("", Fs.newFile("."), Qualifiers.parse(""))); }
private static Path resourceFile(String... pathParts) { return Fs.join(resourcesBaseDir(), pathParts); }
public static FsFile fromURL(URL url) { switch (url.getProtocol()) { case "file": return new FileFsFile(new File(url.getPath())); case "jar": String[] parts = url.getPath().split("!", 0); try { Fs fs = fromJar(new URL(parts[0])); return fs.join(parts[1].substring(1)); } catch (MalformedURLException e) { throw new IllegalArgumentException(e); } default: throw new IllegalArgumentException("unsupported fs type for '" + url + "'"); } }