Desugared library nio: fix real path
Move the add-on to the R8 code base
Change-Id: I975e51c5023f8c209b0399a8bf897c54d420efa5
diff --git a/build.gradle b/build.gradle
index 7123eb7..f5838d6 100644
--- a/build.gradle
+++ b/build.gradle
@@ -3,6 +3,7 @@
// BSD-style license that can be found in the LICENSE file.
+
import desugaredlibrary.CustomConversionAsmRewriterTask
import dx.DexMergerTask
import dx.DxTask
@@ -1091,7 +1092,6 @@
task rawBuildLibraryDesugarConversions(type: Zip, dependsOn: downloadDeps) {
from sourceSets.libraryDesugarConversions.output
include "java/**/*.class"
- include "desugar/sun/nio/fs/DesugarAndroid*.class"
baseName 'library_desugar_conversions_raw'
destinationDir file('build/tmp/desugaredlibrary')
}
diff --git a/src/library_desugar/java/desugar/sun/nio/fs/DesugarAndroidBasicFileAttributeView.java b/src/library_desugar/java/desugar/sun/nio/fs/DesugarAndroidBasicFileAttributeView.java
deleted file mode 100644
index b8be0e2..0000000
--- a/src/library_desugar/java/desugar/sun/nio/fs/DesugarAndroidBasicFileAttributeView.java
+++ /dev/null
@@ -1,32 +0,0 @@
-// Copyright (c) 2022, the R8 project authors. Please see the AUTHORS file
-// for details. All rights reserved. Use of this source code is governed by a
-// BSD-style license that can be found in the LICENSE file.
-
-package desugar.sun.nio.fs;
-
-import java.io.IOException;
-import java.nio.file.Path;
-import java.nio.file.attribute.BasicFileAttributes;
-import java.util.Map;
-
-class DesugarAndroidBasicFileAttributeView extends DesugarBasicFileAttributeView {
-
- private final Path path;
-
- public DesugarAndroidBasicFileAttributeView(Path path) {
- super(path);
- this.path = path;
- }
-
- @Override
- public BasicFileAttributes readAttributes() throws IOException {
- path.getFileSystem().provider().checkAccess(path);
- return super.readAttributes();
- }
-
- @Override
- public Map<String, Object> readAttributes(String[] requested) throws IOException {
- path.getFileSystem().provider().checkAccess(path);
- return super.readAttributes(requested);
- }
-}
diff --git a/src/library_desugar/java/desugar/sun/nio/fs/DesugarAndroidDefaultFileSystemProvider.java b/src/library_desugar/java/desugar/sun/nio/fs/DesugarAndroidDefaultFileSystemProvider.java
deleted file mode 100644
index 8de3f76..0000000
--- a/src/library_desugar/java/desugar/sun/nio/fs/DesugarAndroidDefaultFileSystemProvider.java
+++ /dev/null
@@ -1,25 +0,0 @@
-// Copyright (c) 2022, the R8 project authors. Please see the AUTHORS file
-// for details. All rights reserved. Use of this source code is governed by a
-// BSD-style license that can be found in the LICENSE file.
-
-package desugar.sun.nio.fs;
-
-import java.net.URI;
-import java.nio.file.FileSystem;
-import java.nio.file.spi.FileSystemProvider;
-
-public class DesugarAndroidDefaultFileSystemProvider {
- private static final FileSystemProvider INSTANCE = DesugarAndroidFileSystemProvider.create();
-
- private DesugarAndroidDefaultFileSystemProvider() {}
-
- /** Returns the platform's default file system provider. */
- public static FileSystemProvider instance() {
- return INSTANCE;
- }
-
- /** Returns the platform's default file system. */
- public static FileSystem theFileSystem() {
- return INSTANCE.getFileSystem(URI.create("file:///"));
- }
-}
diff --git a/src/library_desugar/java/desugar/sun/nio/fs/DesugarAndroidFileSystemProvider.java b/src/library_desugar/java/desugar/sun/nio/fs/DesugarAndroidFileSystemProvider.java
deleted file mode 100644
index 6b4a062..0000000
--- a/src/library_desugar/java/desugar/sun/nio/fs/DesugarAndroidFileSystemProvider.java
+++ /dev/null
@@ -1,166 +0,0 @@
-// Copyright (c) 2022, the R8 project authors. Please see the AUTHORS file
-// for details. All rights reserved. Use of this source code is governed by a
-// BSD-style license that can be found in the LICENSE file.
-
-package desugar.sun.nio.fs;
-
-import java.adapter.AndroidVersionTest;
-import java.io.IOException;
-import java.nio.channels.DesugarChannels;
-import java.nio.channels.FileChannel;
-import java.nio.channels.SeekableByteChannel;
-import java.nio.file.CopyOption;
-import java.nio.file.FileAlreadyExistsException;
-import java.nio.file.Files;
-import java.nio.file.LinkOption;
-import java.nio.file.NoSuchFileException;
-import java.nio.file.OpenOption;
-import java.nio.file.Path;
-import java.nio.file.StandardCopyOption;
-import java.nio.file.attribute.BasicFileAttributeView;
-import java.nio.file.attribute.FileAttribute;
-import java.nio.file.attribute.FileAttributeView;
-import java.nio.file.spi.FileSystemProvider;
-import java.util.Map;
-import java.util.Set;
-
-/** Linux implementation of {@link FileSystemProvider} for desugar support. */
-public class DesugarAndroidFileSystemProvider
- extends desugar.sun.nio.fs.DesugarLinuxFileSystemProvider {
-
- public static DesugarAndroidFileSystemProvider create() {
- return new DesugarAndroidFileSystemProvider(System.getProperty("user.dir"), "/");
- }
-
- DesugarAndroidFileSystemProvider(String userDir, String rootDir) {
- super(userDir, rootDir);
- }
-
- @Override
- public void copy(Path source, Path target, CopyOption... options) throws IOException {
- if (!containsCopyOption(options, StandardCopyOption.REPLACE_EXISTING) && Files.exists(target)) {
- throw new FileAlreadyExistsException(target.toString());
- }
- if (containsCopyOption(options, StandardCopyOption.ATOMIC_MOVE)) {
- throw new UnsupportedOperationException("Unsupported copy option");
- }
- super.copy(source, target, options);
- }
-
- @Override
- public void move(Path source, Path target, CopyOption... options) throws IOException {
- if (!containsCopyOption(options, StandardCopyOption.REPLACE_EXISTING) && Files.exists(target)) {
- throw new FileAlreadyExistsException(target.toString());
- }
- if (containsCopyOption(options, StandardCopyOption.COPY_ATTRIBUTES)) {
- throw new UnsupportedOperationException("Unsupported copy option");
- }
- super.move(source, target, options);
- }
-
- private boolean containsCopyOption(CopyOption[] options, CopyOption option) {
- for (CopyOption copyOption : options) {
- if (copyOption == option) {
- return true;
- }
- }
- return false;
- }
-
- @Override
- public void createDirectory(Path dir, FileAttribute<?>... attrs) throws IOException {
- if (dir.getParent() != null && !Files.exists(dir.getParent())) {
- throw new NoSuchFileException(dir.toString());
- }
- super.createDirectory(dir, attrs);
- }
-
- @Override
- public <V extends FileAttributeView> V getFileAttributeView(
- Path path, Class<V> type, LinkOption... options) {
- if (type == null) {
- throw new NullPointerException();
- }
- if (type == BasicFileAttributeView.class) {
- return type.cast(new DesugarAndroidBasicFileAttributeView(path));
- }
- return null;
- }
-
- @Override
- public Map<String, Object> readAttributes(Path path, String attributes, LinkOption... options)
- throws IOException {
- int attributesTypeIndexEnd = attributes.indexOf(":");
- final Class<? extends BasicFileAttributeView> attributeViewType;
- final String[] requestedAttributes;
- if (attributesTypeIndexEnd == -1) {
- attributeViewType = BasicFileAttributeView.class;
- requestedAttributes = attributes.split(",");
- } else {
- String attributeTypeSpec = attributes.substring(0, attributesTypeIndexEnd);
- if ("basic".equals(attributeTypeSpec)) {
- attributeViewType = BasicFileAttributeView.class;
- } else {
- throw new UnsupportedOperationException(
- String.format("Requested attribute type for: %s is not available.", attributeTypeSpec));
- }
- requestedAttributes = attributes.substring(attributesTypeIndexEnd + 1).split(",");
- }
- if (attributeViewType == BasicFileAttributeView.class) {
- DesugarBasicFileAttributeView attrView = new DesugarAndroidBasicFileAttributeView(path);
- return attrView.readAttributes(requestedAttributes);
- }
- throw new AssertionError("Unexpected View '" + attributeViewType + "' requested");
- }
-
- private boolean exists(Path file) {
- try {
- checkAccess(file);
- return true;
- } catch (IOException ioe) {
- return false;
- }
- }
-
- @Override
- public void delete(Path path) throws IOException {
- if (exists(path)) {
- deleteIfExists(path);
- return;
- }
- throw new NoSuchFileException(path.toString());
- }
-
- @Override
- public SeekableByteChannel newByteChannel(
- Path path, Set<? extends OpenOption> options, FileAttribute<?>... attrs) throws IOException {
- if (path.toFile().isDirectory()) {
- throw new UnsupportedOperationException(
- "The desugar library does not support creating a file channel on a directory: " + path);
- }
- // A FileChannel is a SeekableByteChannel.
- return newFileChannel(path, options, attrs);
- }
-
- @Override
- public FileChannel newFileChannel(
- Path path, Set<? extends OpenOption> options, FileAttribute<?>... attrs) throws IOException {
- if (AndroidVersionTest.is26OrAbove) {
- throw new RuntimeException("Above Api 26, the platform FileSystemProvider should be used.");
- }
- return DesugarChannels.openEmulatedFileChannel(path, options, attrs);
- }
-
- @Override
- public boolean isSameFile(Path path, Path path2) throws IOException {
- // If the paths are equals, then it answers true even if they do not exist.
- if (path.equals(path2)) {
- return true;
- }
- // If the paths are not equal, they could still be equal due to symbolic link and so on, but
- // in that case accessibility is checked.
- checkAccess(path);
- checkAccess(path2);
- return super.isSameFile(path, path2);
- }
-}
diff --git a/src/library_desugar/java/desugar/sun/nio/fs/DesugarBasicFileAttributeView.java b/src/library_desugar/java/desugar/sun/nio/fs/DesugarBasicFileAttributeView.java
deleted file mode 100644
index c62a952..0000000
--- a/src/library_desugar/java/desugar/sun/nio/fs/DesugarBasicFileAttributeView.java
+++ /dev/null
@@ -1,27 +0,0 @@
-// Copyright (c) 2022, the R8 project authors. Please see the AUTHORS file
-// for details. All rights reserved. Use of this source code is governed by a
-// BSD-style license that can be found in the LICENSE file.
-
-package desugar.sun.nio.fs;
-
-import java.io.IOException;
-import java.nio.file.Path;
-import java.nio.file.attribute.BasicFileAttributes;
-import java.nio.file.attribute.FileTime;
-import java.util.Map;
-
-public class DesugarBasicFileAttributeView {
-
- public DesugarBasicFileAttributeView(Path path) {}
-
- public BasicFileAttributes readAttributes() throws IOException {
- return null;
- }
-
- public void setTimes(FileTime lastModifiedTime, FileTime lastAccessTime, FileTime createTime)
- throws IOException {}
-
- public Map<String, Object> readAttributes(String[] requested) throws IOException {
- return null;
- }
-}
diff --git a/src/library_desugar/java/desugar/sun/nio/fs/DesugarBasicFileAttributes.java b/src/library_desugar/java/desugar/sun/nio/fs/DesugarBasicFileAttributes.java
deleted file mode 100644
index 8121b78..0000000
--- a/src/library_desugar/java/desugar/sun/nio/fs/DesugarBasicFileAttributes.java
+++ /dev/null
@@ -1,61 +0,0 @@
-// Copyright (c) 2022, the R8 project authors. Please see the AUTHORS file
-// for details. All rights reserved. Use of this source code is governed by a
-// BSD-style license that can be found in the LICENSE file.
-
-package desugar.sun.nio.fs;
-
-import java.io.File;
-import java.nio.file.attribute.BasicFileAttributes;
-import java.nio.file.attribute.FileTime;
-
-public class DesugarBasicFileAttributes implements BasicFileAttributes {
-
- static DesugarBasicFileAttributes create(File file) {
- return null;
- }
-
- @Override
- public FileTime lastModifiedTime() {
- return null;
- }
-
- @Override
- public FileTime lastAccessTime() {
- return null;
- }
-
- @Override
- public FileTime creationTime() {
- return null;
- }
-
- @Override
- public boolean isRegularFile() {
- return false;
- }
-
- @Override
- public boolean isDirectory() {
- return false;
- }
-
- @Override
- public boolean isSymbolicLink() {
- return false;
- }
-
- @Override
- public boolean isOther() {
- return false;
- }
-
- @Override
- public long size() {
- return 0;
- }
-
- @Override
- public Object fileKey() {
- return null;
- }
-}
diff --git a/src/library_desugar/java/desugar/sun/nio/fs/DesugarDefaultFileSystemProvider.java b/src/library_desugar/java/desugar/sun/nio/fs/DesugarDefaultFileSystemProvider.java
new file mode 100644
index 0000000..ae066b2
--- /dev/null
+++ b/src/library_desugar/java/desugar/sun/nio/fs/DesugarDefaultFileSystemProvider.java
@@ -0,0 +1,22 @@
+// Copyright (c) 2023, the R8 project authors. Please see the AUTHORS file
+// for details. All rights reserved. Use of this source code is governed by a
+// BSD-style license that can be found in the LICENSE file.
+
+package desugar.sun.nio.fs;
+
+import java.nio.file.FileSystem;
+import java.nio.file.spi.FileSystemProvider;
+
+/** Creates this platform's default FileSystemProvider. */
+public class DesugarDefaultFileSystemProvider {
+
+ /** Returns the platform's default file system provider. */
+ public static FileSystemProvider instance() {
+ return null;
+ }
+
+ /** Returns the platform's default file system. */
+ public static FileSystem theFileSystem() {
+ return null;
+ }
+}
diff --git a/src/library_desugar/java/desugar/sun/nio/fs/DesugarDefaultFileTypeDetector.java b/src/library_desugar/java/desugar/sun/nio/fs/DesugarDefaultFileTypeDetector.java
index 916d6e0..1871b85 100644
--- a/src/library_desugar/java/desugar/sun/nio/fs/DesugarDefaultFileTypeDetector.java
+++ b/src/library_desugar/java/desugar/sun/nio/fs/DesugarDefaultFileTypeDetector.java
@@ -1,4 +1,4 @@
-// Copyright (c) 2022, the R8 project authors. Please see the AUTHORS file
+// Copyright (c) 2023, the R8 project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
@@ -7,6 +7,7 @@
import java.nio.file.spi.FileTypeDetector;
public class DesugarDefaultFileTypeDetector {
+
public static FileTypeDetector create() {
return null;
}
diff --git a/src/library_desugar/java/desugar/sun/nio/fs/DesugarLinuxFileSystemProvider.java b/src/library_desugar/java/desugar/sun/nio/fs/DesugarLinuxFileSystemProvider.java
deleted file mode 100644
index 566bf12..0000000
--- a/src/library_desugar/java/desugar/sun/nio/fs/DesugarLinuxFileSystemProvider.java
+++ /dev/null
@@ -1,116 +0,0 @@
-// Copyright (c) 2022, the R8 project authors. Please see the AUTHORS file
-// for details. All rights reserved. Use of this source code is governed by a
-// BSD-style license that can be found in the LICENSE file.
-
-package desugar.sun.nio.fs;
-
-import java.io.IOException;
-import java.net.URI;
-import java.nio.channels.SeekableByteChannel;
-import java.nio.file.AccessMode;
-import java.nio.file.CopyOption;
-import java.nio.file.DirectoryStream;
-import java.nio.file.DirectoryStream.Filter;
-import java.nio.file.FileStore;
-import java.nio.file.FileSystem;
-import java.nio.file.LinkOption;
-import java.nio.file.OpenOption;
-import java.nio.file.Path;
-import java.nio.file.attribute.BasicFileAttributes;
-import java.nio.file.attribute.FileAttribute;
-import java.nio.file.attribute.FileAttributeView;
-import java.nio.file.spi.FileSystemProvider;
-import java.util.Map;
-import java.util.Set;
-
-public class DesugarLinuxFileSystemProvider extends FileSystemProvider {
-
- DesugarLinuxFileSystemProvider(String userDir, String rootDir) {
- super();
- }
-
- @Override
- public String getScheme() {
- return null;
- }
-
- @Override
- public FileSystem newFileSystem(URI uri, Map<String, ?> map) throws IOException {
- return null;
- }
-
- @Override
- public FileSystem getFileSystem(URI uri) {
- return null;
- }
-
- @Override
- public Path getPath(URI uri) {
- return null;
- }
-
- @Override
- public SeekableByteChannel newByteChannel(
- Path path, Set<? extends OpenOption> set, FileAttribute<?>... fileAttributes)
- throws IOException {
- return null;
- }
-
- @Override
- public DirectoryStream<Path> newDirectoryStream(Path path, Filter<? super Path> filter)
- throws IOException {
- return null;
- }
-
- @Override
- public void createDirectory(Path path, FileAttribute<?>... fileAttributes) throws IOException {}
-
- @Override
- public void delete(Path path) throws IOException {}
-
- @Override
- public void copy(Path path, Path path1, CopyOption... copyOptions) throws IOException {}
-
- @Override
- public void move(Path path, Path path1, CopyOption... copyOptions) throws IOException {}
-
- @Override
- public boolean isSameFile(Path path, Path path1) throws IOException {
- return false;
- }
-
- @Override
- public boolean isHidden(Path path) throws IOException {
- return false;
- }
-
- @Override
- public FileStore getFileStore(Path path) throws IOException {
- return null;
- }
-
- @Override
- public void checkAccess(Path path, AccessMode... accessModes) throws IOException {}
-
- @Override
- public <V extends FileAttributeView> V getFileAttributeView(
- Path path, Class<V> aClass, LinkOption... linkOptions) {
- return null;
- }
-
- @Override
- public <A extends BasicFileAttributes> A readAttributes(
- Path path, Class<A> aClass, LinkOption... linkOptions) throws IOException {
- return null;
- }
-
- @Override
- public Map<String, Object> readAttributes(Path path, String s, LinkOption... linkOptions)
- throws IOException {
- return null;
- }
-
- @Override
- public void setAttribute(Path path, String s, Object o, LinkOption... linkOptions)
- throws IOException {}
-}
diff --git a/src/library_desugar/java/java/adapter/HybridFileSystemProvider.java b/src/library_desugar/java/java/adapter/HybridFileSystemProvider.java
index eea074f..bd3b845 100644
--- a/src/library_desugar/java/java/adapter/HybridFileSystemProvider.java
+++ b/src/library_desugar/java/java/adapter/HybridFileSystemProvider.java
@@ -6,7 +6,7 @@
import android.os.StrictMode;
import android.os.StrictMode.ThreadPolicy;
-import desugar.sun.nio.fs.DesugarAndroidDefaultFileSystemProvider;
+import desugar.sun.nio.fs.DesugarDefaultFileSystemProvider;
import j$.nio.file.FileSystems;
import java.net.URI;
import java.nio.file.FileSystem;
@@ -34,7 +34,7 @@
// We cannot set the ThreadPolicy in headless and it should not matter.
setThreadPolicy();
}
- return DesugarAndroidDefaultFileSystemProvider.instance();
+ return DesugarDefaultFileSystemProvider.instance();
}
private static void setThreadPolicy() {
diff --git a/src/test/java/com/android/tools/r8/desugar/desugaredlibrary/jdk11/PathTest.java b/src/test/java/com/android/tools/r8/desugar/desugaredlibrary/jdk11/PathTest.java
index 104876d..7bc93d4 100644
--- a/src/test/java/com/android/tools/r8/desugar/desugaredlibrary/jdk11/PathTest.java
+++ b/src/test/java/com/android/tools/r8/desugar/desugaredlibrary/jdk11/PathTest.java
@@ -13,6 +13,8 @@
import com.android.tools.r8.utils.StringUtils;
import com.google.common.collect.ImmutableList;
import java.io.File;
+import java.io.IOException;
+import java.nio.file.LinkOption;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.List;
@@ -30,12 +32,31 @@
private static final String EXPECTED_RESULT_DESUGARING =
StringUtils.lines(
- "x.txt", "dir", "dir/x.txt", "/", "class j$.desugar.sun.nio.fs.DesugarLinuxFileSystem");
+ "x.txt",
+ "dir",
+ "dir/x.txt",
+ "/",
+ "class j$.desugar.sun.nio.fs.DesugarLinuxFileSystem",
+ "class java.nio.file.NoSuchFileException :: notExisting",
+ "class java.nio.file.NoSuchFileException :: notExisting");
private static final String EXPECTED_RESULT_DESUGARING_PLATFORM_FILE_SYSTEM =
StringUtils.lines(
- "x.txt", "dir", "dir/x.txt", "/", "class j$.nio.file.FileSystem$VivifiedWrapper");
+ "x.txt",
+ "dir",
+ "dir/x.txt",
+ "/",
+ "class j$.nio.file.FileSystem$VivifiedWrapper",
+ "class java.nio.file.NoSuchFileException :: notExisting",
+ "class java.nio.file.NoSuchFileException :: notExisting");
private static final String EXPECTED_RESULT_NO_DESUGARING =
- StringUtils.lines("x.txt", "dir", "dir/x.txt", "/", "class sun.nio.fs.LinuxFileSystem");
+ StringUtils.lines(
+ "x.txt",
+ "dir",
+ "dir/x.txt",
+ "/",
+ "class sun.nio.fs.LinuxFileSystem",
+ "class java.nio.file.NoSuchFileException :: notExisting",
+ "class java.nio.file.NoSuchFileException :: notExisting");
@Parameters(name = "{0}, spec: {1}, {2}")
public static List<Object[]> data() {
@@ -80,16 +101,36 @@
public static class TestClass {
+ private static void printError(Throwable t) {
+ String[] split =
+ t.getMessage() == null ? new String[] {"no-message"} : t.getMessage().split("/");
+ System.out.println(t.getClass() + " :: " + split[split.length - 1]);
+ }
+
public static void main(String[] args) {
File file = new File("x.txt");
Path path1 = file.toPath();
System.out.println(path1);
- Path path2 = Paths.get("dir/");
- System.out.println(path2);
- Path resolve = path2.resolve(path1);
+ Path dir = Paths.get("dir/");
+ System.out.println(dir);
+ Path resolve = dir.resolve(path1);
System.out.println(resolve);
System.out.println(resolve.getFileSystem().getSeparator());
System.out.println(resolve.getFileSystem().getClass());
+
+ Path notExisting = dir.resolve("notExisting");
+ try {
+ notExisting.toRealPath();
+ System.out.println("IOException not raised!");
+ } catch (IOException e) {
+ printError(e);
+ }
+ try {
+ notExisting.toRealPath(LinkOption.NOFOLLOW_LINKS);
+ System.out.println("IOException not raised!");
+ } catch (IOException e) {
+ printError(e);
+ }
}
}
}
diff --git a/third_party/openjdk/desugar_jdk_libs_11.tar.gz.sha1 b/third_party/openjdk/desugar_jdk_libs_11.tar.gz.sha1
index a75d743..d52bbc5 100644
--- a/third_party/openjdk/desugar_jdk_libs_11.tar.gz.sha1
+++ b/third_party/openjdk/desugar_jdk_libs_11.tar.gz.sha1
@@ -1 +1 @@
-baf1112d9c5ee962bf5085a81289f43b9f38697e
\ No newline at end of file
+024c0b5aa78dba1442189dc55367551825cc4085
\ No newline at end of file