Skip to content

Commit

Permalink
Automatic code cleanup.
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 431921185
  • Loading branch information
Googler authored and copybara-github committed Mar 2, 2022
1 parent 694e01d commit 8769d5d
Showing 1 changed file with 46 additions and 46 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,52 @@ public boolean finished() {
return finish;
}

@Override
public void finished(DiagnosticsHandler handler) {
if (!finished()) {
return;
}
FilteringDependencyCollector dependencyCollector =
new FilteringDependencyCollector(this.dependencyCollector);
initializeInputDependencies(handler, dependencyCollector);
dependencyCollector.setFiltering();
try (ZipOutputStream out =
new ZipOutputStream(new BufferedOutputStream(Files.newOutputStream(archive)))) {
for (ClassFileData classFile : classFiles) {
ZipUtils.addEntry(classFile.fileName, classFile.data, ZipEntry.STORED, out);
new DesugaredClassFileDependencyCollector(classFile, dependencyCollector).run();
}
// Add dependency metadata if required.
byte[] desugarDeps = dependencyCollector.toByteArray();
if (desugarDeps != null) {
ZipUtils.addEntry(Desugar.DESUGAR_DEPS_FILENAME, desugarDeps, ZipEntry.STORED, out);
}
ZipUtils.copyEntries(
input,
out,
entryName ->
("module-info.class".equals(entryName) || entryName.startsWith("META-INF/versions/"))
|| ArchiveProgramResourceProvider.includeClassFileEntries(entryName)
|| (entryName.endsWith("/") && flags == EXCLUDE_PATH_ENTRIES),
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));
}
}

public void setFinish(boolean finish) {
this.finish = finish;
}
Expand Down Expand Up @@ -125,52 +171,6 @@ public void accept(ByteDataView data, String descriptor, DiagnosticsHandler hand
DescriptorUtils.descriptorToClassFileName(descriptor), data.copyByteData()));
}

@Override
public void finished(DiagnosticsHandler handler) {
if (!finished()) {
return;
}
FilteringDependencyCollector dependencyCollector =
new FilteringDependencyCollector(this.dependencyCollector);
initializeInputDependencies(handler, dependencyCollector);
dependencyCollector.setFiltering();
try (ZipOutputStream out =
new ZipOutputStream(new BufferedOutputStream(Files.newOutputStream(archive)))) {
for (ClassFileData classFile : classFiles) {
ZipUtils.addEntry(classFile.fileName, classFile.data, ZipEntry.STORED, out);
new DesugaredClassFileDependencyCollector(classFile, dependencyCollector).run();
}
// Add dependency metadata if required.
byte[] desugarDeps = dependencyCollector.toByteArray();
if (desugarDeps != null) {
ZipUtils.addEntry(Desugar.DESUGAR_DEPS_FILENAME, desugarDeps, ZipEntry.STORED, out);
}
ZipUtils.copyEntries(
input,
out,
entryName ->
("module-info.class".equals(entryName) || entryName.startsWith("META-INF/versions/"))
|| ArchiveProgramResourceProvider.includeClassFileEntries(entryName)
|| (entryName.endsWith("/") && flags == EXCLUDE_PATH_ENTRIES),
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));
}
}

private void initializeInputDependencies(
DiagnosticsHandler handler, FilteringDependencyCollector dependencyCollector) {
try (ZipFile zipFile = new ZipFile(input.toFile())) {
Expand Down

0 comments on commit 8769d5d

Please sign in to comment.