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

Migrate functional tests to Kotlin and Junit part 3 #1125

Merged
merged 13 commits into from
Jan 5, 2025
Prev Previous commit
Next Next commit
Refine TransformersTest
  • Loading branch information
Goooler committed Jan 4, 2025
commit 0774f1d092a469f787846dd0a0900a696ca6cddd
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
Loading