-
-
Notifications
You must be signed in to change notification settings - Fork 424
Optimize normalizeJar memory footprint and preserve entry metadata
#2164
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
2e6d62c
Stream jar entries in normalizeJar to reduce memory overhead
Goooler 6b4b3e5
Ensure META-INF/MANIFEST.MF is placed first in normalizeJar
Goooler b4db78b
Preserve original Unix mode permissions in normalizeJar
Goooler f4a95ce
Use camelCase method name in R8MinimizerTest
Goooler e3160f0
Combine ZipFile scope in normalizeJar
Goooler 16e4eba
Pass encoding for createZipOutputStream
Goooler d069922
Add comment explaining ZipFile usage in normalizeJar
Goooler 51c3fdc
Revert META-INF/MANIFEST.MF first entry ordering in normalizeJar
Goooler 4b723c0
Potential fix for pull request finding
Goooler ae7b42b
Cleanups
Goooler File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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
64 changes: 64 additions & 0 deletions
64
src/test/kotlin/com/github/jengelman/gradle/plugins/shadow/internal/R8MinimizerTest.kt
This file contains hidden or 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,64 @@ | ||
| package com.github.jengelman.gradle.plugins.shadow.internal | ||
|
|
||
| import assertk.assertThat | ||
| import assertk.assertions.isEqualTo | ||
| import com.github.jengelman.gradle.plugins.shadow.util.zipOutputStream | ||
| import java.nio.file.Path | ||
| import org.apache.tools.zip.UnixStat | ||
| import org.apache.tools.zip.ZipFile | ||
| import org.gradle.api.internal.project.ProjectInternal | ||
| import org.gradle.api.tasks.bundling.ZipEntryCompression | ||
| import org.gradle.process.ExecOperations | ||
| import org.gradle.testfixtures.ProjectBuilder | ||
| import org.junit.jupiter.api.Test | ||
| import org.junit.jupiter.api.io.TempDir | ||
|
|
||
| class R8MinimizerTest { | ||
| private val project = ProjectBuilder.builder().build() | ||
|
|
||
| @Test | ||
| fun normalizeJarPreservesUnixPermissions(@TempDir tempDir: Path) { | ||
| val inputJar = tempDir.resolve("input.jar") | ||
| val outputJar = tempDir.resolve("output.jar") | ||
| val expectedExecutableMode = UnixStat.FILE_FLAG or 493 // 0755 octal | ||
|
|
||
| inputJar.zipOutputStream().use { zos -> | ||
| zos.writeEntry("bin/script.sh", unixMode = UnixMode.raw(expectedExecutableMode)) { | ||
| write("echo hello\n".toByteArray()) | ||
| } | ||
| zos.writeEntry("com/example/Foo.class") { | ||
| write("class bytes".toByteArray()) | ||
| } | ||
| zos.writeEntry("META-INF/MANIFEST.MF") { | ||
| write("Manifest-Version: 1.0\n".toByteArray()) | ||
| } | ||
| } | ||
|
|
||
| val execOperations = (project as ProjectInternal).services.get(ExecOperations::class.java) | ||
| val r8Spec = project.objects.newInstance(DefaultR8Spec::class.java) | ||
| val minimizer = | ||
| R8Minimizer( | ||
| execOperations = execOperations, | ||
| logger = project.logger, | ||
| r8Classpath = project.files(), | ||
| r8Spec = r8Spec, | ||
| javaLauncher = project.provider { null }, | ||
| sourceSetsClassesDirs = emptyList(), | ||
| keptDependencyFiles = emptyList(), | ||
| relocators = emptyList(), | ||
| preserveFileTimestamps = true, | ||
| reproducibleFileOrder = true, | ||
| zip64 = false, | ||
| entryCompression = ZipEntryCompression.DEFLATED, | ||
| metadataCharset = Charsets.UTF_8.toString(), | ||
| ) | ||
|
|
||
| minimizer.normalizeJar(inputJar.toFile(), outputJar.toFile()) | ||
|
|
||
| ZipFile(outputJar.toFile()).use { zipFile -> | ||
| // Executable unix mode must be preserved | ||
| val scriptEntry = zipFile.getEntry("bin/script.sh") | ||
| assertThat(scriptEntry.unixMode).isEqualTo(expectedExecutableMode) | ||
| } | ||
| } | ||
| } |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.