Skip to content
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

Allow package exclusion for ConfigureShadowRelocation #555

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ class ConfigureShadowRelocation extends DefaultTask {
@Input
String prefix = "shadow"

@Input
List<String> excludedPackages = []

@InputFiles @Optional
List<Configuration> getConfigurations() {
return target.configurations
Expand All @@ -31,7 +34,7 @@ class ConfigureShadowRelocation extends DefaultTask {
configuration.files.each { jar ->
JarFile jf = new JarFile(jar)
jf.entries().each { entry ->
if (entry.name.endsWith(".class")) {
if (entry.name.endsWith(".class") && !matchesExcludeList(entry.name)) {
packages << entry.name[0..entry.name.lastIndexOf('/')-1].replaceAll('/', '.')
}
}
Expand All @@ -48,4 +51,11 @@ class ConfigureShadowRelocation extends DefaultTask {
return "configureRelocation${task.name.capitalize()}"
}

boolean matchesExcludeList(String className) {
return excludedPackages.any {
if (className.startsWith(it)) {
return true
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ class ConfigureShadowRelocationSpec extends PluginSpecification {
when:
runner.withArguments('shadowJar', '-s').build()

then:
then:
contains(output, [
'META-INF/MANIFEST.MF',
Expand All @@ -44,4 +43,44 @@ class ConfigureShadowRelocationSpec extends PluginSpecification {
'shadow/junit/framework/TestSuite.class'
])
}

def "auto relocate plugin dependencies with exclusion list"() {
given:
buildFile << """

task relocateShadowJar(type: com.github.jengelman.gradle.plugins.shadow.tasks.ConfigureShadowRelocation) {
target = tasks.shadowJar
excludedPackages = ["junit/framework"]
}

tasks.shadowJar.dependsOn tasks.relocateShadowJar

dependencies {
compile 'junit:junit:3.8.2'
}
""".stripIndent()

when:
runner.withArguments('shadowJar', '-s').build()

then:
contains(output, [
'META-INF/MANIFEST.MF',
'shadow/junit/textui/ResultPrinter.class',
'shadow/junit/textui/TestRunner.class',
'junit/framework/Assert.class',
'junit/framework/AssertionFailedError.class',
'junit/framework/ComparisonCompactor.class',
'junit/framework/ComparisonFailure.class',
'junit/framework/Protectable.class',
'junit/framework/Test.class',
'junit/framework/TestCase.class',
'junit/framework/TestFailure.class',
'junit/framework/TestListener.class',
'junit/framework/TestResult$1.class',
'junit/framework/TestResult.class',
'junit/framework/TestSuite$1.class',
'junit/framework/TestSuite.class'
])
}
}