Skip to content
Merged
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
@@ -1,7 +1,7 @@
package com.github.jengelman.gradle.plugins.shadow

import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar
import com.github.jengelman.gradle.plugins.shadow.util.AppendableMavenFileRepository
import com.github.jengelman.gradle.plugins.shadow.util.AppendableMavenRepository
import org.apache.commons.lang3.StringUtils
import org.gradle.testkit.runner.BuildResult
import org.gradle.testkit.runner.GradleRunner
Expand All @@ -17,13 +17,13 @@ abstract class BasePluginSpecification extends Specification {
@TempDir
Path root

AppendableMavenFileRepository repo
AppendableMavenRepository repo

def setup() {
repo = new AppendableMavenFileRepository(root.resolve('maven-repo'))
repo.module('junit', 'junit', '3.8.2')
.use(Paths.get(this.class.classLoader.getResource('junit-3.8.2.jar').toURI()))
.publish()
repo = new AppendableMavenRepository(root.resolve('local-maven-repo'), runner)
repo.module('junit', 'junit', '3.8.2') { module ->
module.useJar(Paths.get(this.class.classLoader.getResource('junit-3.8.2.jar').toURI()))
}.publish()

projectScriptFile << getDefaultProjectBuildScript('java', true, true)
settingsScriptFile << getDefaultSettingsBuildScript()
Expand Down Expand Up @@ -57,7 +57,7 @@ abstract class BasePluginSpecification extends Specification {
return """
dependencyResolutionManagement {
repositories {
maven { url = "${repo.uri}" }
maven { url = "${repo.root.toUri()}" }
mavenCentral()
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import com.github.jengelman.gradle.plugins.shadow.ShadowApplicationPlugin.Compan
import com.github.jengelman.gradle.plugins.shadow.ShadowJavaPlugin.Companion.SHADOW_JAR_TASK_NAME
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 com.github.jengelman.gradle.plugins.shadow.util.AppendableMavenRepository
import com.github.jengelman.gradle.plugins.shadow.util.JarPath
import java.nio.file.Path
import java.util.Properties
Expand All @@ -30,16 +30,16 @@ import org.junit.jupiter.api.TestInstance
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
abstract class BasePluginTest {
private lateinit var root: Path
lateinit var repo: AppendableMavenFileRepository
lateinit var localRepo: AppendableMavenRepository

@BeforeEach
open fun setup() {
root = createTempDirectory()

repo = repo()
repo.module("junit", "junit", "3.8.2")
.use(testJar)
.publish()
localRepo = repo()
localRepo.module("junit", "junit", "3.8.2") {
useJar(testJar)
}.publish()

projectScriptPath.writeText(getDefaultProjectBuildScript(withGroup = true, withVersion = true))
settingsScriptPath.writeText(getDefaultSettingsBuildScript())
Expand Down Expand Up @@ -81,7 +81,7 @@ abstract class BasePluginTest {
$startBlock
dependencyResolutionManagement {
repositories {
maven { url = '${repo.uri}' }
maven { url = '${localRepo.root.toUri()}' }
mavenCentral()
}
}
Expand All @@ -90,27 +90,28 @@ abstract class BasePluginTest {
}

fun publishArtifactA() {
repo.module("shadow", "a", "1.0")
.insertFile("a.properties", "a")
.insertFile("a2.properties", "a2")
.publish()
localRepo.module("shadow", "a", "1.0") {
insert("a.properties", "a")
insert("a2.properties", "a2")
}.publish()
}

fun publishArtifactB() {
repo.module("shadow", "b", "1.0")
.insertFile("b.properties", "b")
.publish()
localRepo.module("shadow", "b", "1.0") {
insert("b.properties", "b")
}.publish()
}

fun publishArtifactCD(circular: Boolean = false) {
repo.module("shadow", "c", "1.0")
.insertFile("c.properties", "c")
.apply { if (circular) dependsOn("d") }
.publish()
repo.module("shadow", "d", "1.0")
.insertFile("d.properties", "d")
.dependsOn("c")
.publish()
localRepo.module("shadow", "c", "1.0") {
insert("c.properties", "c")
if (circular) {
addDependency("shadow", "d", "1.0")
}
}.module("shadow", "d", "1.0") {
insert("d.properties", "d")
addDependency("shadow", "c", "1.0")
}.publish()
}

open val shadowJarTask = SHADOW_JAR_TASK_NAME
Expand Down Expand Up @@ -146,8 +147,8 @@ abstract class BasePluginTest {
}
}

fun repo(path: String = "maven-repo"): AppendableMavenFileRepository {
return AppendableMavenFileRepository(root.resolve(path))
fun repo(path: String = "local-maven-repo"): AppendableMavenRepository {
return AppendableMavenRepository(root.resolve(path), runner)
}

private val runner: GradleRunner
Expand All @@ -160,12 +161,7 @@ abstract class BasePluginTest {
}

fun runner(arguments: Iterable<String>): GradleRunner {
val allArguments = listOf(
"--warning-mode=fail",
"--configuration-cache",
"--stacktrace",
) + arguments
return runner.withArguments(allArguments)
return runner.withArguments(commonArguments + arguments)
}

inline fun run(
Expand Down Expand Up @@ -319,6 +315,12 @@ abstract class BasePluginTest {
tasks.named('$SHADOW_RUN_TASK_NAME', ${JavaJarExec::class.java.name})
""".trimIndent()

val commonArguments = listOf(
"--warning-mode=fail",
"--configuration-cache",
"--stacktrace",
)

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

fun fromJar(vararg paths: Path): String {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import assertk.assertThat
import assertk.assertions.containsOnly
import assertk.assertions.isEmpty
import assertk.assertions.isEqualTo
import com.github.jengelman.gradle.plugins.shadow.util.AppendableMavenFileRepository
import com.github.jengelman.gradle.plugins.shadow.util.AppendableMavenRepository
import com.github.jengelman.gradle.plugins.shadow.util.GradleModuleMetadata
import com.github.jengelman.gradle.plugins.shadow.util.Issue
import com.github.jengelman.gradle.plugins.shadow.util.JarPath
Expand Down Expand Up @@ -34,12 +34,12 @@ class PublishingTest : BasePluginTest() {
private val gmmAdapter = moshi.adapter(GradleModuleMetadata::class.java)
private val pomReader = MavenXpp3Reader()

private lateinit var publishingRepo: AppendableMavenFileRepository
private lateinit var remoteRepo: AppendableMavenRepository

@BeforeEach
override fun setup() {
super.setup()
publishingRepo = repo("remote-repo")
remoteRepo = repo("remote-maven-repo")

publishArtifactA()
publishArtifactB()
Expand Down Expand Up @@ -217,7 +217,7 @@ class PublishingTest : BasePluginTest() {
}

private fun repoPath(path: String): Path {
return publishingRepo.rootDir.resolve(path).also {
return remoteRepo.root.resolve(path).also {
check(it.exists()) { "Path not found: $it" }
check(it.isRegularFile()) { "Path is not a regular file: $it" }
}
Expand Down Expand Up @@ -258,7 +258,7 @@ class PublishingTest : BasePluginTest() {
}
repositories {
maven {
url = '${publishingRepo.uri}'
url = '${remoteRepo.root.toUri()}'
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -288,9 +288,9 @@ class RelocationTest : BasePluginTest() {
)
@Test
fun relocateResourceFiles() {
repo.module("shadow", "dep", "1.0")
.insertFile("foo/dep.properties", "c")
.publish()
localRepo.module("shadow", "dep", "1.0") {
insert("foo/dep.properties", "c")
}.publish()
path("src/main/java/foo/Foo.java").writeText(
"""
package foo;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -382,15 +382,15 @@ class ShadowPluginTest : BasePluginTest() {

@Test
fun excludeSomeMetaInfFilesByDefault() {
repo.module("shadow", "a", "1.0")
.insertFile("a.properties", "a")
.insertFile("META-INF/INDEX.LIST", "JarIndex-Version: 1.0")
.insertFile("META-INF/a.SF", "Signature File")
.insertFile("META-INF/a.DSA", "DSA Signature Block")
.insertFile("META-INF/a.RSA", "RSA Signature Block")
.insertFile("META-INF/a.properties", "key=value")
.insertFile("module-info.class", "module myModuleName {}")
.publish()
localRepo.module("shadow", "a", "1.0") {
insert("a.properties", "a")
insert("META-INF/INDEX.LIST", "JarIndex-Version: 1.0")
insert("META-INF/a.SF", "Signature File")
insert("META-INF/a.DSA", "DSA Signature Block")
insert("META-INF/a.RSA", "RSA Signature Block")
insert("META-INF/a.properties", "key=value")
insert("module-info.class", "module myModuleName {}")
}.publish()

path("src/main/java/shadow/Passed.java").writeText(
"""
Expand Down Expand Up @@ -449,19 +449,16 @@ class ShadowPluginTest : BasePluginTest() {

@Test
fun includeJavaLibraryConfigurationsByDefault() {
repo.module("shadow", "api", "1.0")
.insertFile("api.properties", "api")
.publish()
repo.module("shadow", "implementation-dep", "1.0")
.insertFile("implementation-dep.properties", "implementation-dep")
.publish()
repo.module("shadow", "implementation", "1.0")
.insertFile("implementation.properties", "implementation")
.dependsOn("implementation-dep")
.publish()
repo.module("shadow", "runtimeOnly", "1.0")
.insertFile("runtimeOnly.properties", "runtimeOnly")
.publish()
localRepo.module("shadow", "api", "1.0") {
insert("api.properties", "api")
}.module("shadow", "implementation-dep", "1.0") {
insert("implementation-dep.properties", "implementation-dep")
}.module("shadow", "implementation", "1.0") {
insert("implementation.properties", "implementation")
addDependency("shadow", "implementation-dep", "1.0")
}.module("shadow", "runtimeOnly", "1.0") {
insert("runtimeOnly.properties", "runtimeOnly")
}.publish()

projectScriptPath.writeText(
"""
Expand Down Expand Up @@ -511,12 +508,11 @@ class ShadowPluginTest : BasePluginTest() {

@Test
fun defaultCopyingStrategy() {
repo.module("shadow", "a", "1.0")
.insertFile("META-INF/MANIFEST.MF", "MANIFEST A")
.publish()
repo.module("shadow", "b", "1.0")
.insertFile("META-INF/MANIFEST.MF", "MANIFEST B")
.publish()
localRepo.module("shadow", "a", "1.0") {
insert("META-INF/MANIFEST.MF", "MANIFEST A")
}.module("shadow", "b", "1.0") {
insert("META-INF/MANIFEST.MF", "MANIFEST B")
}.publish()

projectScriptPath.appendText(
"""
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
package com.github.jengelman.gradle.plugins.shadow.transformers

import com.github.jengelman.gradle.plugins.shadow.BasePluginTest
import com.github.jengelman.gradle.plugins.shadow.util.AppendableJar
import com.github.jengelman.gradle.plugins.shadow.util.JarBuilder
import java.nio.file.Path
import kotlin.io.path.writeText

sealed class BaseTransformerTest : BasePluginTest() {

fun buildJarOne(
builder: AppendableJar.() -> Unit = {
builder: JarBuilder.() -> Unit = {
insert(ENTRY_SERVICES_SHADE, CONTENT_ONE)
insert(ENTRY_SERVICES_FOO, "one")
},
Expand All @@ -17,16 +17,16 @@ sealed class BaseTransformerTest : BasePluginTest() {
}

fun buildJarTwo(
builder: AppendableJar.() -> Unit = {
builder: JarBuilder.() -> Unit = {
insert(ENTRY_SERVICES_SHADE, CONTENT_TWO)
insert(ENTRY_SERVICES_FOO, "two")
},
): Path {
return buildJar("two.jar", builder)
}

inline fun buildJar(path: String, builder: AppendableJar.() -> Unit): Path {
return AppendableJar(path(path)).apply(builder).write()
inline fun buildJar(path: String, builder: JarBuilder.() -> Unit): Path {
return JarBuilder(path(path)).apply(builder).write()
}

fun writeMainClass() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -178,9 +178,9 @@ class ServiceFileTransformerTest : BaseTransformerTest() {
val one = buildJarOne {
insert(servicesShadowEntry, CONTENT_ONE)
}.toUri().toURL().path
repo.module("shadow", "two", "1.0")
.insertFile(servicesShadowEntry, CONTENT_TWO)
.publish()
localRepo.module("shadow", "two", "1.0") {
insert(servicesShadowEntry, CONTENT_TWO)
}.publish()

projectScriptPath.appendText(
"""
Expand Down

This file was deleted.

Loading
Loading