Skip to content

Commit

Permalink
Refine TransformersTest
Browse files Browse the repository at this point in the history
  • Loading branch information
Goooler committed Jan 4, 2025
1 parent 050b3f1 commit a759f6c
Show file tree
Hide file tree
Showing 3 changed files with 260 additions and 290 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import com.github.jengelman.gradle.plugins.shadow.tasks.JavaJarExec
import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar
import com.github.jengelman.gradle.plugins.shadow.util.AppendableMavenFileRepository
import java.nio.file.Path
import java.util.Properties
import java.util.jar.JarFile
import kotlin.io.path.ExperimentalPathApi
import kotlin.io.path.Path
Expand Down Expand Up @@ -328,6 +329,12 @@ abstract class BasePluginTest {
tasks.named('$SHADOW_RUN_TASK_NAME', ${JavaJarExec::class.java.name})
""".trimIndent()

fun String.toProperties(): Properties = Properties().apply { load(byteInputStream()) }

fun fromJar(vararg paths: Path): String {
return paths.joinToString(System.lineSeparator()) { "from('${it.toUri().toURL().path}')" }
}

fun BuildResult.assertNoDeprecationWarnings() = apply {
output.lines().forEach {
assert(!containsDeprecationWarning(it))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import com.github.jengelman.gradle.plugins.shadow.util.Issue
import java.util.jar.JarFile
import kotlin.io.path.appendText
import kotlin.io.path.readText
import kotlin.io.path.toPath
import kotlin.io.path.writeText
import org.gradle.api.plugins.JavaPlugin
import org.gradle.testfixtures.ProjectBuilder
Expand Down Expand Up @@ -81,16 +82,15 @@ class ShadowPluginTest : BasePluginTest() {

@Test
fun shadowCopy() {
val artifactJarPath = requireNotNull(this::class.java.classLoader.getResource("test-artifact-1.0-SNAPSHOT.jar"))
.path
val projectJarPath = requireNotNull(this::class.java.classLoader.getResource("test-project-1.0-SNAPSHOT.jar"))
.path
val artifactJar = requireNotNull(this::class.java.classLoader.getResource("test-artifact-1.0-SNAPSHOT.jar"))
.toURI().toPath()
val projectJar = requireNotNull(this::class.java.classLoader.getResource("test-project-1.0-SNAPSHOT.jar"))
.toURI().toPath()

projectScriptPath.appendText(
"""
$shadowJar {
from('$artifactJarPath')
from('$projectJarPath')
${fromJar(artifactJar, projectJar)}
}
""".trimIndent(),
)
Expand Down
Loading

0 comments on commit a759f6c

Please sign in to comment.