Skip to content

Commit 7efd809

Browse files
tomballcopybara-github
authored andcommitted
Builds full_jre_emul_lib from sources, instead of using subset library deps. Adds avoid_dep tags to subset libraries.
PiperOrigin-RevId: 753687051
1 parent b0ffaab commit 7efd809

File tree

5 files changed

+33
-249
lines changed

5 files changed

+33
-249
lines changed

jre_emul/Classes/com/google/j2objc/util/PropertiesXmlLoader.java

-73
This file was deleted.

jre_emul/android/platform/libcore/luni/src/main/java/java/nio/NioUtils.java

+8-48
Original file line numberDiff line numberDiff line change
@@ -16,24 +16,15 @@
1616

1717
package java.nio;
1818

19-
import dalvik.annotation.compat.UnsupportedAppUsage;
19+
import static libcore.io.OsConstants.O_ACCMODE;
20+
import static libcore.io.OsConstants.O_RDONLY;
21+
import static libcore.io.OsConstants.O_WRONLY;
2022

21-
import com.google.j2objc.LibraryNotLinkedError;
22-
import java.io.Closeable;
23+
import dalvik.annotation.compat.UnsupportedAppUsage;
2324
import java.io.FileDescriptor;
24-
import java.io.IOException;
2525
import java.nio.channels.FileChannel;
26-
import java.util.Set;
27-
28-
import sun.misc.Cleaner;
29-
import sun.nio.ch.DirectBuffer;
3026
import sun.nio.ch.FileChannelImpl;
3127

32-
import static libcore.io.OsConstants.O_ACCMODE;
33-
import static libcore.io.OsConstants.O_APPEND;
34-
import static libcore.io.OsConstants.O_RDONLY;
35-
import static libcore.io.OsConstants.O_WRONLY;
36-
3728
/**
3829
* @hide internal use only
3930
*/
@@ -64,43 +55,12 @@ public static FileDescriptor getFD(FileChannel fc) {
6455
}
6556
*/
6657

67-
/**
68-
* Helps bridge between io and nio.
69-
*/
70-
public static FileChannel newFileChannel(Closeable ioObject, FileDescriptor fd, int mode) {
71-
ChannelFactory factory = ChannelFactory.INSTANCE;
72-
if (factory == null) {
73-
throw new LibraryNotLinkedError("Channel support", "jre_channels",
74-
"JavaNioChannelFactoryImpl");
75-
}
76-
return factory.newFileChannel(ioObject, fd, mode);
77-
}
78-
79-
public static FileChannel newFileChannelSafe(Object stream, FileDescriptor fd, int mode) {
80-
ChannelFactory factory = ChannelFactory.INSTANCE;
81-
if (factory != null) {
82-
return factory.newFileChannel(stream, fd, mode);
83-
} else {
84-
return null;
85-
}
58+
public FileChannel newFileChannel(Object ioObject, FileDescriptor fd, int mode) {
59+
boolean readable = (mode & O_ACCMODE) != O_WRONLY;
60+
boolean writable = (mode & O_ACCMODE) != O_RDONLY;
61+
return FileChannelImpl.open(fd, null, readable, writable, ioObject);
8662
}
8763

88-
static interface ChannelFactory {
89-
FileChannel newFileChannel(Object stream, FileDescriptor fd, int mode);
90-
91-
static final ChannelFactory INSTANCE = getChannelFactory();
92-
}
93-
94-
// Native implementation avoids the use of Class.forName(). This code might end up invoked from
95-
// within the internals of Class.forName(), and re-invoking it causes deadlock.
96-
private static native ChannelFactory getChannelFactory() /*-[
97-
Class cls = NSClassFromString(@"JavaNioChannelFactoryImpl");
98-
if (cls) {
99-
return AUTORELEASE([[cls alloc] init]);
100-
}
101-
return nil;
102-
]-*/;
103-
10464
/**
10565
* Exposes the array backing a non-direct ByteBuffer, even if the ByteBuffer is read-only.
10666
* Normally, attempting to access the array backing a read-only buffer throws.

jre_emul/android/platform/libcore/ojluni/src/main/java/java/nio/ChannelFactoryImpl.java

-42
This file was deleted.

jre_emul/android/platform/libcore/ojluni/src/main/java/java/util/Properties.java

+23-84
Original file line numberDiff line numberDiff line change
@@ -26,22 +26,15 @@
2626

2727
package java.util;
2828

29-
import com.google.j2objc.LibraryNotLinkedError;
30-
import com.google.j2objc.util.XmlLoader;
3129
import java.io.BufferedWriter;
3230
import java.io.IOException;
33-
import java.io.PrintStream;
34-
import java.io.PrintWriter;
3531
import java.io.InputStream;
3632
import java.io.OutputStream;
3733
import java.io.OutputStreamWriter;
3834
import java.io.PrintStream;
3935
import java.io.PrintWriter;
4036
import java.io.Reader;
4137
import java.io.Writer;
42-
import java.nio.charset.Charset;
43-
import java.nio.charset.IllegalCharsetNameException;
44-
import java.nio.charset.UnsupportedCharsetException;
4538

4639
// Android-removed: Dead native2ascii links.
4740
// These links are also gone in OpenJDK 9.
@@ -910,21 +903,16 @@ private void store0(BufferedWriter bw, String comments, boolean escUnicode)
910903
*/
911904
public synchronized void loadFromXML(InputStream in)
912905
throws IOException, InvalidPropertiesFormatException {
913-
XmlLoader loader = getXmlLoader();
914-
if (loader == null) {
915-
throw new LibraryNotLinkedError(
916-
"XML support", "jre_xml", "ComGoogleJ2objcUtilPropertiesXmlLoader");
917-
}
918-
loader.load(this, in);
919-
}
920-
921-
private static XmlLoader getXmlLoader() {
922-
try {
923-
Class<?> loaderClass = Class.forName("com.google.j2objc.util.PropertiesXmlLoader");
924-
return (XmlLoader) loaderClass.newInstance();
925-
} catch (Exception e) {
926-
return null;
927-
}
906+
// Android-changed: Keep OpenJDK7u40's XmlUtils.
907+
// XmlSupport's system property based XmlPropertiesProvider
908+
// selection does not make sense on Android and has too many
909+
// dependencies on classes that are not available on Android.
910+
//
911+
// Objects.requireNonNull(in);
912+
// PropertiesDefaultHandler handler = new PropertiesDefaultHandler();
913+
// handler.load(this, in);
914+
XMLUtils.load(this, Objects.requireNonNull(in));
915+
in.close();
928916
}
929917

930918
/**
@@ -994,72 +982,23 @@ public void storeToXML(OutputStream os, String comment)
994982
*/
995983
public void storeToXML(OutputStream os, String comment, String encoding)
996984
throws IOException {
997-
if (os == null) {
998-
throw new NullPointerException("os == null");
999-
} else if (encoding == null) {
1000-
throw new NullPointerException("encoding == null");
1001-
}
1002-
985+
// Android-changed: Keep OpenJDK7u40's XmlUtils.
986+
// XmlSupport's system property based XmlPropertiesProvider
987+
// selection does not make sense on Android and has too many
988+
// dependencies on classes that are not available on Android.
1003989
/*
1004-
* We can write to XML file using encoding parameter but note that some
1005-
* aliases for encodings are not supported by the XML parser. Thus we
1006-
* have to know canonical name for encoding used to store data in XML
1007-
* since the XML parser must recognize encoding name used to store data.
1008-
*/
990+
Objects.requireNonNull(os);
991+
Objects.requireNonNull(encoding);
1009992
1010-
String encodingCanonicalName;
1011993
try {
1012-
encodingCanonicalName = Charset.forName(encoding).name();
1013-
} catch (IllegalCharsetNameException e) {
1014-
System.out.println("Warning: encoding name " + encoding
1015-
+ " is illegal, using UTF-8 as default encoding");
1016-
encodingCanonicalName = "UTF-8";
1017-
} catch (UnsupportedCharsetException e) {
1018-
System.out.println("Warning: encoding " + encoding
1019-
+ " is not supported, using UTF-8 as default encoding");
1020-
encodingCanonicalName = "UTF-8";
1021-
}
1022-
1023-
PrintStream printStream = new PrintStream(os, false,
1024-
encodingCanonicalName);
1025-
1026-
printStream.print("<?xml version=\"1.0\" encoding=\"");
1027-
printStream.print(encodingCanonicalName);
1028-
printStream.println("\"?>");
1029-
1030-
printStream.print("<!DOCTYPE properties SYSTEM \"");
1031-
printStream.print(PROP_DTD_NAME);
1032-
printStream.println("\">");
1033-
1034-
printStream.println("<properties>");
1035-
1036-
if (comment != null) {
1037-
printStream.print("<comment>");
1038-
printStream.print(substitutePredefinedEntries(comment));
1039-
printStream.println("</comment>");
994+
Charset charset = Charset.forName(encoding);
995+
storeToXML(os, comment, charset);
996+
} catch (IllegalCharsetNameException | UnsupportedCharsetException e) {
997+
throw new UnsupportedEncodingException(encoding);
1040998
}
1041-
1042-
for (Map.Entry<Object, Object> entry : entrySet()) {
1043-
String keyValue = (String) entry.getKey();
1044-
String entryValue = (String) entry.getValue();
1045-
printStream.print("<entry key=\"");
1046-
printStream.print(substitutePredefinedEntries(keyValue));
1047-
printStream.print("\">");
1048-
printStream.print(substitutePredefinedEntries(entryValue));
1049-
printStream.println("</entry>");
1050-
}
1051-
printStream.println("</properties>");
1052-
printStream.flush();
1053-
}
1054-
1055-
private String substitutePredefinedEntries(String s) {
1056-
// substitution for predefined character entities to use them safely in XML.
1057-
s = s.replaceAll("&", "&amp;");
1058-
s = s.replaceAll("<", "&lt;");
1059-
s = s.replaceAll(">", "&gt;");
1060-
s = s.replaceAll("'", "&apos;");
1061-
s = s.replaceAll("\"", "&quot;");
1062-
return s;
999+
*/
1000+
XMLUtils.save(this, Objects.requireNonNull(os), comment,
1001+
Objects.requireNonNull(encoding));
10631002
}
10641003

10651004
/**

jre_emul/jre_sources.mk

+2-2
Original file line numberDiff line numberDiff line change
@@ -644,6 +644,7 @@ JAVA_PRIVATE_SOURCES_CORE = \
644644
java/util/ImmutableCollections.java \
645645
java/util/RegularEnumSet.java \
646646
java/util/Tripwire.java \
647+
java/util/XMLUtils.java \
647648
java/util/logging/Logging.java \
648649
java/util/logging/LoggingProxyImpl.java \
649650
java/util/stream/AbstractPipeline.java \
@@ -973,7 +974,6 @@ JAVA_PUBLIC_SOURCES_CONCURRENT = \
973974
JAVA_PRIVATE_SOURCES_CONCURRENT =
974975

975976
JAVA_PUBLIC_SOURCES_CHANNELS = \
976-
java/nio/ChannelFactoryImpl.java \
977977
java/nio/channels/AcceptPendingException.java \
978978
java/nio/channels/AlreadyBoundException.java \
979979
java/nio/channels/AlreadyConnectedException.java \
@@ -1289,6 +1289,7 @@ JAVA_PUBLIC_SOURCES_SECURITY = \
12891289
java/security/NoSuchAlgorithmException.java \
12901290
java/security/NoSuchProviderException.java \
12911291
java/security/Policy.java \
1292+
java/security/PolicySpi.java \
12921293
java/security/Principal.java \
12931294
java/security/PrivateKey.java \
12941295
java/security/PrivilegedAction.java \
@@ -1680,7 +1681,6 @@ JAVA_PRIVATE_SOURCES_SSL = \
16801681
com/google/j2objc/net/ssl/IosSslContextSpi.java
16811682

16821683
JAVA_PUBLIC_SOURCES_XML = \
1683-
com/google/j2objc/util/PropertiesXmlLoader.java \
16841684
javax/xml/XMLConstants.java \
16851685
javax/xml/datatype/DatatypeConfigurationException.java \
16861686
javax/xml/datatype/DatatypeConstants.java \

0 commit comments

Comments
 (0)