Skip to content

Commit

Permalink
Temporary workaround to address parts of b/177329741
Browse files Browse the repository at this point in the history
RELNOTES=None
PiperOrigin-RevId: 351544171
  • Loading branch information
sgjesse authored and copybara-github committed Jan 13, 2021
1 parent f30cae4 commit b0aa8e6
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import java.io.InputStream;
import java.nio.file.Path;
import java.util.Enumeration;
import java.util.function.Function;
import java.util.function.Predicate;
import java.util.zip.CRC32;
import java.util.zip.ZipEntry;
Expand All @@ -42,8 +43,8 @@ public static void addEntry(String name, byte[] bytes, int compressionMethod, Zi
zip.closeEntry();
}

private static ZipEntry copyEntryMetadata(ZipEntry entry) {
ZipEntry copy = new ZipEntry(entry.getName());
private static ZipEntry copyEntryMetadata(ZipEntry entry, String name) {
ZipEntry copy = new ZipEntry(name);
copy.setMethod(entry.getMethod());
if (entry.getSize() != -1) {
copy.setSize(entry.getSize());
Expand All @@ -67,13 +68,18 @@ private static ZipEntry copyEntryMetadata(ZipEntry entry) {
}

public static void copyEntries(
Path input, ZipOutputStream zipOutputStream, Predicate<String> exclude) throws IOException {
Path input,
ZipOutputStream zipOutputStream,
Predicate<String> exclude,
Function<String, String> nameMapping)
throws IOException {
try (ZipFile zipFile = new ZipFile(input.toFile())) {
Enumeration<? extends ZipEntry> entries = zipFile.entries();
while (entries.hasMoreElements()) {
ZipEntry entry = entries.nextElement();
if (!exclude.test(entry.getName())) {
zipOutputStream.putNextEntry(copyEntryMetadata(entry));
String name = entry.getName();
if (!exclude.test(name)) {
zipOutputStream.putNextEntry(copyEntryMetadata(entry, nameMapping.apply(name)));
try (InputStream stream = zipFile.getInputStream(entry)) {
ByteStreams.copy(stream, zipOutputStream);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,20 @@ public void finished(DiagnosticsHandler handler) {
out,
entryName ->
("module-info.class".equals(entryName) || entryName.startsWith("META-INF/versions/"))
|| ArchiveProgramResourceProvider.includeClassFileEntries(entryName));
|| ArchiveProgramResourceProvider.includeClassFileEntries(entryName),
name -> {
final String metainfServicesPrefix = "META-INF/services/";
if (name.startsWith(metainfServicesPrefix)) {
String serviceName = name.substring(metainfServicesPrefix.length());
if (serviceName.startsWith("java.time.")) {
name =
metainfServicesPrefix
+ "j$.time."
+ serviceName.substring("java.time.".length());
}
}
return name;
});

} catch (IOException e) {
handler.error(new ExceptionDiagnostic(e, origin));
Expand Down

0 comments on commit b0aa8e6

Please sign in to comment.