Skip to content

Commit

Permalink
Merge pull request #4265 from robolectric:kill-fs-file
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 225880485
  • Loading branch information
copybara-robolectric committed Dec 17, 2018
2 parents e04e04c + f6952d5 commit 68e194a
Show file tree
Hide file tree
Showing 34 changed files with 315 additions and 279 deletions.
Expand Up @@ -27,8 +27,11 @@
import org.w3c.dom.NodeList;

/**
* A wrapper for an Android App Manifest, which represents information about one's App to an Android system.
* @see <a href="https://developer.android.com/guide/topics/manifest/manifest-intro.html">Android App Manifest</a>
* A wrapper for an Android App Manifest, which represents information about one's App to an Android
* system.
*
* @see <a href="https://developer.android.com/guide/topics/manifest/manifest-intro.html">Android
* App Manifest</a>
*/
@SuppressWarnings("NewApi")
public class AndroidManifest implements UsesSdk {
Expand Down Expand Up @@ -69,8 +72,8 @@ public class AndroidManifest implements UsesSdk {
* Creates a Robolectric configuration using specified locations.
*
* @param androidManifestFile Location of the AndroidManifest.xml file.
* @param resDirectory Location of the res directory.
* @param assetsDirectory Location of the assets directory.
* @param resDirectory Location of the res directory.
* @param assetsDirectory Location of the assets directory.
*/
public AndroidManifest(Path androidManifestFile, Path resDirectory, Path assetsDirectory) {
this(androidManifestFile, resDirectory, assetsDirectory, null);
Expand All @@ -80,11 +83,14 @@ public AndroidManifest(Path androidManifestFile, Path resDirectory, Path assetsD
* Creates a Robolectric configuration using specified values.
*
* @param androidManifestFile Location of the AndroidManifest.xml file.
* @param resDirectory Location of the res directory.
* @param assetsDirectory Location of the assets directory.
* @param resDirectory Location of the res directory.
* @param assetsDirectory Location of the assets directory.
* @param overridePackageName Application package name.
*/
public AndroidManifest(Path androidManifestFile, Path resDirectory, Path assetsDirectory,
public AndroidManifest(
Path androidManifestFile,
Path resDirectory,
Path assetsDirectory,
String overridePackageName) {
this(androidManifestFile, resDirectory, assetsDirectory, Collections.emptyList(), overridePackageName);
}
Expand All @@ -93,13 +99,17 @@ public AndroidManifest(Path androidManifestFile, Path resDirectory, Path assetsD
* Creates a Robolectric configuration using specified values.
*
* @param androidManifestFile Location of the AndroidManifest.xml file.
* @param resDirectory Location of the res directory.
* @param assetsDirectory Location of the assets directory.
* @param libraryManifests List of dependency library manifests.
* @param resDirectory Location of the res directory.
* @param assetsDirectory Location of the assets directory.
* @param libraryManifests List of dependency library manifests.
* @param overridePackageName Application package name.
*/
public AndroidManifest(Path androidManifestFile, Path resDirectory, Path assetsDirectory,
@Nonnull List<AndroidManifest> libraryManifests, String overridePackageName) {
public AndroidManifest(
Path androidManifestFile,
Path resDirectory,
Path assetsDirectory,
@Nonnull List<AndroidManifest> libraryManifests,
String overridePackageName) {
this(
androidManifestFile,
resDirectory,
Expand All @@ -109,8 +119,13 @@ public AndroidManifest(Path androidManifestFile, Path resDirectory, Path assetsD
null);
}

public AndroidManifest(Path androidManifestFile, Path resDirectory, Path assetsDirectory,
@Nonnull List<AndroidManifest> libraryManifests, String overridePackageName, Path apkFile) {
public AndroidManifest(
Path androidManifestFile,
Path resDirectory,
Path assetsDirectory,
@Nonnull List<AndroidManifest> libraryManifests,
String overridePackageName,
Path apkFile) {
this.androidManifestFile = androidManifestFile;
this.resDirectory = resDirectory;
this.assetsDirectory = assetsDirectory;
Expand Down
Expand Up @@ -21,8 +21,8 @@ public boolean test(Path file) {
}

/**
* It sure seems like a bug that Path#getFileName() returns "name/" for paths inside a jar,
* but "name" for paths on a regular filesystem.
* It sure seems like a bug that Path#getFileName() returns "name/" for paths inside a jar, but
* "name" for paths on a regular filesystem.
*/
private String nameWithoutTrailingSeparator(Path file) {
String fileName = file.getFileName().toString();
Expand Down
Expand Up @@ -5,9 +5,7 @@
import java.nio.file.Path;
import org.robolectric.util.Logger;

/**
* DrawableResourceLoader
*/
/** DrawableResourceLoader */
@SuppressWarnings("NewApi")
public class DrawableResourceLoader {
private final PackageResourceTable resourceTable;
Expand Down
20 changes: 6 additions & 14 deletions resources/src/main/java/org/robolectric/res/Fs.java
Expand Up @@ -33,17 +33,13 @@ abstract public class Fs {
@GuardedBy("ZIP_FILESYSTEMS")
private static final Map<Path, FsWrapper> ZIP_FILESYSTEMS = new HashMap<>();

/**
* @deprecated Use {@link File#toPath()} instead.
*/
/** @deprecated Use {@link File#toPath()} instead. */
@Deprecated
public static Path newFile(File file) {
return file.toPath();
}

/**
* @deprecated Use {@link #fromUrl(String)} instead.
*/
/** @deprecated Use {@link #fromUrl(String)} instead. */
@Deprecated
public static Path fileFromPath(String path) {
return Fs.fromUrl(path);
Expand All @@ -64,9 +60,9 @@ public static FileSystem forJar(Path jarFile) {
/**
* Use this method instead of {@link Paths#get(String, String...)} or {@link Paths#get(URI)}.
*
* Supports "file:path", "jar:file:jarfile.jar!/path", and plain old paths.
* <p>Supports "file:path", "jar:file:jarfile.jar!/path", and plain old paths.
*
* For JAR files, automatically open and cache filesystems.
* <p>For JAR files, automatically open and cache filesystems.
*/
public static Path fromUrl(String urlString) {
if (urlString.startsWith("file:") || urlString.startsWith("jar:")) {
Expand All @@ -82,9 +78,7 @@ public static Path fromUrl(String urlString) {
}
}

/**
* Isn't this what {@link Paths#get(URI)} should do?
*/
/** Isn't this what {@link Paths#get(URI)} should do? */
public static Path fromUrl(URL url) {
try {
switch (url.getProtocol()) {
Expand Down Expand Up @@ -166,9 +160,7 @@ public static String externalize(Path path) {
}
}

/**
* Returns a reference-counted Jar FileSystem, possibly one that was previously returned.
*/
/** Returns a reference-counted Jar FileSystem, possibly one that was previously returned. */
private static FileSystem getJarFs(Path jarFile) throws IOException {
Path key = jarFile.toAbsolutePath();

Expand Down
8 changes: 2 additions & 6 deletions resources/src/main/java/org/robolectric/res/FsFile.java
Expand Up @@ -7,17 +7,13 @@
@SuppressWarnings("NewApi")
public interface FsFile extends Path {

/**
* @deprecated use {@link Fs#externalize(Path)} instead.
*/
/** @deprecated use {@link Fs#externalize(Path)} instead. */
@Deprecated
default String getPath() {
return Fs.externalize(this);
}

/**
* @deprecated use {@link Path#resolve(Path)} instead.
*/
/** @deprecated use {@link Path#resolve(Path)} instead. */
@Deprecated
default Path join(String name) {
return this.resolve(name);
Expand Down
3 changes: 2 additions & 1 deletion resources/src/main/java/org/robolectric/res/Qualifiers.java
Expand Up @@ -7,7 +7,8 @@
import org.robolectric.res.android.ResTable_config;

/**
* Android qualifers as defined by https://developer.android.com/guide/topics/resources/providing-resources.html
* Android qualifers as defined by
* https://developer.android.com/guide/topics/resources/providing-resources.html
*/
@SuppressWarnings("NewApi")
public class Qualifiers {
Expand Down
Expand Up @@ -36,8 +36,12 @@ private void loadRawFiles(PackageResourceTable resourceTable, String resourceTyp

for (Path file : Fs.listFiles(rawDir)) {
String fileBaseName = Fs.baseNameFor(file);
resourceTable.addResource(resourceType, fileBaseName,
new FileTypedResource(file, ResType.FILE,
resourceTable.addResource(
resourceType,
fileBaseName,
new FileTypedResource(
file,
ResType.FILE,
new XmlContext(resourceTable.getPackageName(), file, qualifiers)));
}
}
Expand Down
Expand Up @@ -167,12 +167,18 @@ private void parseResourceFiles(ResourcePath resourcePath, PackageResourceTable
}
}

private void loadOpaque(ResourcePath resourcePath, final PackageResourceTable resourceTable, final String type, final ResType resType)
private void loadOpaque(
ResourcePath resourcePath,
final PackageResourceTable resourceTable,
final String type,
final ResType resType)
throws IOException {
new DocumentLoader(resourceTable.getPackageName(), resourcePath.getResourceBase()) {
@Override
protected void loadResourceXmlFile(XmlContext xmlContext) {
resourceTable.addResource(type, Fs.baseNameFor(xmlContext.getXmlFile()),
resourceTable.addResource(
type,
Fs.baseNameFor(xmlContext.getXmlFile()),
new FileTypedResource(xmlContext.getXmlFile(), resType, xmlContext));
}
}.load(type);
Expand Down
Expand Up @@ -14,7 +14,8 @@ public class StaxDocumentLoader extends DocumentLoader {
private final NodeHandler topLevelNodeHandler;
private final XMLInputFactory factory;

public StaxDocumentLoader(String packageName, Path resourceBase, NodeHandler topLevelNodeHandler) {
public StaxDocumentLoader(
String packageName, Path resourceBase, NodeHandler topLevelNodeHandler) {
super(packageName, resourceBase);

this.topLevelNodeHandler = topLevelNodeHandler;
Expand Down
Expand Up @@ -19,8 +19,10 @@
import org.robolectric.res.FileTypedResource;
import org.robolectric.res.Fs;

// transliterated from https://android.googlesource.com/platform/frameworks/base/+/android-9.0.0_r12/libs/androidfw/Asset.cpp
// and https://android.googlesource.com/platform/frameworks/base/+/android-9.0.0_r12/libs/androidfw/include/androidfw/Asset.h
// transliterated from
// https://android.googlesource.com/platform/frameworks/base/+/android-9.0.0_r12/libs/androidfw/Asset.cpp
// and
// https://android.googlesource.com/platform/frameworks/base/+/android-9.0.0_r12/libs/androidfw/include/androidfw/Asset.h
/*
* Instances of this class provide read-only operations on a byte stream.
*
Expand Down

0 comments on commit 68e194a

Please sign in to comment.