Skip to content

Commit

Permalink
Merge util classes
Browse files Browse the repository at this point in the history
  • Loading branch information
Goooler committed Nov 7, 2024
1 parent ffb1104 commit b5c2450
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 29 deletions.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
package com.github.jengelman.gradle.plugins.shadow.internal

import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar
import org.apache.tools.zip.ZipOutputStream
import org.gradle.api.internal.file.copy.CopySpecInternal
import org.gradle.api.tasks.bundling.Jar
import org.gradle.api.tasks.bundling.ZipEntryCompression
import org.gradle.api.tasks.util.PatternSet

class GradleVersionUtil {
import java.util.jar.JarFile

class Utils {

static PatternSet getRootPatternSet(CopySpecInternal mainSpec) {
return mainSpec.buildRootResolver().getPatternSet()
Expand All @@ -22,4 +25,22 @@ class GradleVersionUtil {
throw new IllegalArgumentException(String.format("Unknown Compression type %s", entryCompression))
}
}

static void configureRelocation(ShadowJar target, String prefix) {
def packages = [] as Set<String>
target.configurations.each { configuration ->
configuration.files.each { jar ->
JarFile jf = new JarFile(jar)
jf.entries().each { entry ->
if (entry.name.endsWith(".class") && entry.name != "module-info.class") {
packages << entry.name[0..entry.name.lastIndexOf('/') - 1].replaceAll('/', '.')
}
}
jf.close()
}
}
packages.each {
target.relocate(it, "${prefix}.${it}")
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -151,14 +151,14 @@ FileCollection getSourceSetsClassesDirs() {

@Internal
protected ZipCompressor getInternalCompressor() {
return GradleVersionUtil.getInternalCompressor(getEntryCompression(), this);
return Utils.getInternalCompressor(getEntryCompression(), this);
}

@TaskAction
@Override
protected void copy() {
if (enableRelocation) {
RelocationUtil.configureRelocation(this, relocationPrefix);
Utils.configureRelocation(this, relocationPrefix);
}
from(getIncludedDependencies());
super.copy();
Expand All @@ -177,7 +177,7 @@ public FileCollection getIncludedDependencies() {
*/
@Internal
protected PatternSet getRootPatternSet() {
return GradleVersionUtil.getRootPatternSet(getMainSpec());
return Utils.getRootPatternSet(getMainSpec());
}

/**
Expand Down

0 comments on commit b5c2450

Please sign in to comment.