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

Add test cases for SimpleRelocator #1094

Merged
merged 5 commits into from
Dec 9, 2024
Merged

Conversation

Goooler
Copy link
Member

@Goooler Goooler commented Dec 7, 2024

@Goooler Goooler force-pushed the g/20241208/exclude-sources branch from edc49c1 to d28a7ed Compare December 7, 2024 18:00
luneo7 and others added 2 commits December 9, 2024 11:01
Co-authored-by: zinking <[email protected]>
Co-authored-by: Zongle Wang <[email protected]>
…241208/exclude-sources

// Conflicts:
//	src/main/groovy/com/github/jengelman/gradle/plugins/shadow/impl/RelocatorRemapper.groovy
//	src/main/groovy/com/github/jengelman/gradle/plugins/shadow/relocation/Relocator.groovy
//	src/main/groovy/com/github/jengelman/gradle/plugins/shadow/relocation/SimpleRelocator.groovy
//	src/main/groovy/com/github/jengelman/gradle/plugins/shadow/tasks/ShadowCopyAction.groovy
//	src/test/groovy/com/github/jengelman/gradle/plugins/shadow/relocation/SimpleRelocatorTest.groovy
@Goooler Goooler force-pushed the g/20241208/exclude-sources branch 3 times, most recently from 0c32db0 to 80b9b77 Compare December 9, 2024 03:32
@Goooler Goooler force-pushed the g/20241208/exclude-sources branch from 80b9b77 to 7d85cfe Compare December 9, 2024 03:33
@Goooler
Copy link
Member Author

Goooler commented Dec 9, 2024

@portlek As you can see, all tests passed after adding 0778c4b.

…urces

// Conflicts:
//	src/test/kotlin/com/github/jengelman/gradle/plugins/shadow/relocation/SimpleRelocatorTest.kt
@Goooler Goooler changed the title Support including and excluding sources in SimpleRelocator Add test cases for SimpleRelocator Dec 9, 2024
@Goooler Goooler changed the title Add test cases for SimpleRelocator Add test cases for SimpleRelocator Dec 9, 2024
@Goooler Goooler marked this pull request as ready for review December 9, 2024 08:20
@Goooler Goooler merged commit b016d84 into main Dec 9, 2024
7 checks passed
@Goooler Goooler deleted the g/20241208/exclude-sources branch December 9, 2024 08:22
@portlek
Copy link
Contributor

portlek commented Dec 9, 2024

@Goooler Sorry, but it doesn't work for me. am i doing something wrong here?

build.gradle.kts

relocate("a.b", "x.y.z.shade.a.b") {
    include("x/y/z/**/*")
}

Decompiled version of the jar:

package x.y.z;

import a.b.Example;
import a.b.c.Example;

@Test
fun testRelocateSourceWithExcludes() {
  // Main relocator with in-/excludes
  val relocator = SimpleRelocator(
    "org.apache.maven",
    "com.acme.maven"
  )
  relocator.include("foo.bar")
  relocator.include("zot.baz")
  relocator.exclude("irrelevant.exclude")
  relocator.exclude("org.apache.maven.exclude1")
  relocator.exclude("org.apache.maven.sub.exclude2")
  // Make sure not to replace variables 'io' and 'ioInput', package 'java.io'
  val ioRelocator = SimpleRelocator("io", "shaded.io")
  // Check corner case which was not working in PR #100
  val asmRelocator = SimpleRelocator("org.objectweb.asm", "aj.org.objectweb.asm")
  // Make sure not to replace 'foo' package by path-like 'shaded/foo'
  val fooRelocator = SimpleRelocator(
    "foo",
    "shaded.foo",
    excludes = listOf("foo.bar"),
  )
  assertThat(
    fooRelocator.applyToSourceContent(
      asmRelocator.applyToSourceContent(
        ioRelocator.applyToSourceContent(relocator.applyToSourceContent(sourceFile)),
      ),
    ),
  ).isEqualTo(relocatedFile)
}

this doesn't pass, i've just move include/excludes parameters to use the include/exclude methods. the reason i believe is that it calculates the sourcePackageExcludes and sourcePathExcludes on init, and when you add include/exclude after the creation of the simple relocator object it doesn't calculates that, and there is no way to create the relocator object with the include/exclude parameters as far as i know.


#1098 you can check this issue to see how to reproduce it and how it looks like in the code.

@Goooler
Copy link
Member Author

Goooler commented Dec 10, 2024

https://gradleup.com/shadow/configuration/relocation/#filtering-relocation

@Issue('SHADOW-58')
def "relocate dependency files"() {
given:
buildFile << """
dependencies {
implementation 'junit:junit:3.8.2'
}
tasks.named('shadowJar', com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar) {
relocate 'junit.textui', 'a'
relocate 'junit.framework', 'b'
manifest {
attributes 'TEST-VALUE': 'FOO'
}
}
""".stripIndent()
when:
run('shadowJar')
then:
contains(output, [
'META-INF/MANIFEST.MF',
'a/ResultPrinter.class',
'a/TestRunner.class',
'b/Assert.class',
'b/AssertionFailedError.class',
'b/ComparisonCompactor.class',
'b/ComparisonFailure.class',
'b/Protectable.class',
'b/Test.class',
'b/TestCase.class',
'b/TestFailure.class',
'b/TestListener.class',
'b/TestResult$1.class',
'b/TestResult.class',
'b/TestSuite$1.class',
'b/TestSuite.class'
])

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants