Skip to content

Commit

Permalink
Allow package exclusive for ConfigureShadowRelocation
Browse files Browse the repository at this point in the history
  • Loading branch information
ward-eric committed Mar 18, 2020
1 parent d4e649d commit 5b5f231
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 2 deletions.
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'
])
}
}

0 comments on commit 5b5f231

Please sign in to comment.