Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4265 from robolectric/kill-fs-file
Kill FsFile et al. in favor of java.nio.file.Path
- Loading branch information
Showing
64 changed files
with
854 additions
and
1,179 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
35 changes: 35 additions & 0 deletions
35
resources/src/main/java/org/robolectric/res/DirBaseNameFilter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package org.robolectric.res; | ||
|
||
import java.io.File; | ||
import java.nio.file.Path; | ||
import java.util.function.Predicate; | ||
|
||
@SuppressWarnings({"NewApi", "AndroidJdkLibsChecker"}) | ||
class DirBaseNameFilter implements Predicate<Path> { | ||
private final String prefix; | ||
private final String prefixDash; | ||
|
||
DirBaseNameFilter(String prefix) { | ||
this.prefix = prefix; | ||
this.prefixDash = prefix + "-"; | ||
} | ||
|
||
@Override | ||
public boolean test(Path file) { | ||
String fileName = nameWithoutTrailingSeparator(file); | ||
return fileName.equals(prefix) || fileName.startsWith(prefixDash); | ||
} | ||
|
||
/** | ||
* 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(); | ||
int trailingSlash = fileName.indexOf(File.separatorChar); | ||
if (trailingSlash != -1) { | ||
fileName = fileName.substring(0, trailingSlash); | ||
} | ||
return fileName; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.