-
-
Notifications
You must be signed in to change notification settings - Fork 5
Added library for zip transforms #23
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
Draft
shartte
wants to merge
13
commits into
main
Choose a base branch
from
ziptransform
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
f4c1998
Added library for zip transforms
shartte 574b5f7
Added library for zip transforms
shartte ea51ee4
Added library for zip transforms
shartte 29319d9
Use the transfer entry for output too.
shartte bede37d
Added parallel zip processor.
shartte d654c35
Slightly change API for precompressed content.
shartte 432df9f
incorrect crc32 check
shartte 3bd1920
Add a pool for deflaters
shartte ef8d437
No longer pool the entries
shartte 7850d45
Synchronize when opening streams.
shartte 31cf887
Synchronize when opening streams.
shartte 569b81f
Added getters
shartte f90d67f
Free deflaters
shartte 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
86 changes: 86 additions & 0 deletions
86
buildSrc/src/main/java/MakeObfuscatedClassesPackageVisibleTask.java
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,86 @@ | ||
| import org.gradle.api.DefaultTask; | ||
| import org.gradle.api.file.ConfigurableFileCollection; | ||
| import org.gradle.api.file.RegularFileProperty; | ||
| import org.gradle.api.provider.SetProperty; | ||
| import org.gradle.api.tasks.Input; | ||
| import org.gradle.api.tasks.InputFiles; | ||
| import org.gradle.api.tasks.OutputFile; | ||
| import org.gradle.api.tasks.PathSensitive; | ||
| import org.gradle.api.tasks.PathSensitivity; | ||
| import org.gradle.api.tasks.TaskAction; | ||
| import org.objectweb.asm.ClassReader; | ||
| import org.objectweb.asm.ClassVisitor; | ||
| import org.objectweb.asm.ClassWriter; | ||
| import org.objectweb.asm.Opcodes; | ||
|
|
||
| import java.io.BufferedOutputStream; | ||
| import java.io.FileOutputStream; | ||
| import java.io.IOException; | ||
| import java.util.Set; | ||
| import java.util.zip.ZipFile; | ||
| import java.util.zip.ZipOutputStream; | ||
|
|
||
| /** | ||
| * For the Zip Transform library, we let ProGuard obfuscate all third-party dependencies and move them | ||
| * into the same package as the library implementation. | ||
| * Since the library only has a single package, we can make all third party classes package-private, | ||
| * but sadly ProGuard has no optimization for this. | ||
| */ | ||
| public abstract class MakeObfuscatedClassesPackageVisibleTask extends DefaultTask { | ||
| @InputFiles | ||
| @PathSensitive(PathSensitivity.RELATIVE) | ||
| public abstract ConfigurableFileCollection getInputFiles(); | ||
|
|
||
| @Input | ||
| public abstract SetProperty<String> getClassWhitelist(); | ||
|
|
||
| @OutputFile | ||
| public abstract RegularFileProperty getOutputFile(); | ||
|
|
||
| @TaskAction | ||
| public void run() throws IOException { | ||
|
|
||
| Set<String> classWhitelist = getClassWhitelist().get(); | ||
|
|
||
| try (var zf = new ZipFile(getInputFiles().getSingleFile()); | ||
| var out = new ZipOutputStream(new BufferedOutputStream(new FileOutputStream(getOutputFile().getAsFile().get())))) { | ||
| var entries = zf.entries(); | ||
| while (entries.hasMoreElements()) { | ||
| var entry = entries.nextElement(); | ||
|
|
||
| if (entry.isDirectory()) { | ||
| out.putNextEntry(entry); | ||
| out.closeEntry(); | ||
| continue; | ||
| } | ||
|
|
||
| byte[] entryData; | ||
| try (var entryIn = zf.getInputStream(entry)) { | ||
| entryData = entryIn.readAllBytes(); | ||
| } | ||
|
|
||
| // Clear the access flags from classes that don't match our whitelist. | ||
| if (entry.getName().endsWith(".class") && !classWhitelist.contains(entry.getName())) { | ||
| ClassReader classReader = new ClassReader(entryData); | ||
| ClassWriter classWriter = new ClassWriter(0); | ||
|
|
||
| ClassVisitor classVisitor = new ClassVisitor(Opcodes.ASM9, classWriter) { | ||
| @Override | ||
| public void visit(int version, int access, String name, String signature, String superName, String[] interfaces) { | ||
| access &= ~(Opcodes.ACC_PUBLIC | Opcodes.ACC_PROTECTED | Opcodes.ACC_PRIVATE); | ||
| super.visit(version, access, name, signature, superName, interfaces); | ||
| } | ||
| }; | ||
|
|
||
| classReader.accept(classVisitor, 0); | ||
| entryData = classWriter.toByteArray(); | ||
| } | ||
|
|
||
| out.putNextEntry(entry); | ||
| out.write(entryData); | ||
| out.closeEntry(); | ||
| } | ||
| } | ||
|
|
||
| } | ||
| } |
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,14 @@ | ||
| import org.gradle.api.Plugin; | ||
| import org.gradle.api.Project; | ||
| import org.gradle.api.tasks.bundling.AbstractArchiveTask; | ||
|
|
||
| public class ShadowDefaultsPlugin implements Plugin<Project> { | ||
| @Override | ||
| public void apply(Project project) { | ||
| project.getPlugins().apply("com.gradleup.shadow"); | ||
|
|
||
| project.getTasks().named("shadowJar", AbstractArchiveTask.class, task -> { | ||
| task.getArchiveClassifier().set("fatjar"); | ||
| }); | ||
| } | ||
| } |
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
Oops, something went wrong.
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Isn't asm on 9.8 already?
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure, but we're compiling with JDK8 here. (I didn't actually check what the minimum java version for apache compress is hmmm).
edit Okay, Apache Compress also says "The current release requires Java 8 or above."