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
9 changes: 4 additions & 5 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,10 @@ spotless {
kotlinGradle { ktfmt(libs.ktfmt.get().version).googleStyle() }
}

val testPluginClasspath by
configurations.registering {
isCanBeResolved = true
description = "Plugins used in integration tests could be resolved in classpath."
}
val testPluginClasspath by configurations.registering {
isCanBeResolved = true
description = "Plugins used in integration tests could be resolved in classpath."
}

val testKit by sourceSets.creating
val testKitImplementation by configurations.getting
Expand Down
2 changes: 1 addition & 1 deletion gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ pluginPublish = { module = "com.gradle.publish:plugin-publish-plugin", version.r

androidx-gradlePluginLints = "androidx.lint:lint-gradle:1.0.0-alpha05"
# Dummy to get renovate updates, the version is used in rootProject build.gradle with spotless.
ktfmt = "com.facebook:ktfmt:0.61"
ktfmt = "com.facebook:ktfmt:0.62"

junit-bom = "org.junit:junit-bom:6.0.3"
assertk = "com.willowtreeapps.assertk:assertk:0.28.1"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -636,8 +636,9 @@ class RelocationTest : BasePluginTest() {

val originalModule =
KotlinModuleMetadata.read(requireResourceAsStream(originalModuleFilePath).readBytes())
val relocatedModule =
outputShadowedJar.use { KotlinModuleMetadata.read(it.getBytes(relocatedModuleFilePath)) }
val relocatedModule = outputShadowedJar.use {
KotlinModuleMetadata.read(it.getBytes(relocatedModuleFilePath))
}

assertThat(relocatedModule.version.toString()).isEqualTo("2.2.0")
assertThat(originalModule.version.toString()).isEqualTo("2.2.0")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,8 +144,9 @@ class TransformersTest : BaseTransformerTest() {

runWithSuccess(shadowJarPath)

val actualFileBytes =
outputShadowedJar.use { jar -> jar.getStream(PLUGIN_CACHE_FILE).use { it.readAllBytes() } }
val actualFileBytes = outputShadowedJar.use { jar ->
jar.getStream(PLUGIN_CACHE_FILE).use { it.readAllBytes() }
}
assertThat(actualFileBytes.contentHashCode()).all {
// Hash of the original plugin cache file.
isNotEqualTo(-2114104185)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,11 +112,9 @@ public interface DependencyFilter : Serializable {
it == resolvedDependency.moduleGroup ||
resolvedDependency.moduleGroup.matches(it.toRegex())
} ?: true
val nameMatch =
name.let {
it == resolvedDependency.moduleName ||
resolvedDependency.moduleName.matches(it.toRegex())
}
val nameMatch = name.let {
it == resolvedDependency.moduleName || resolvedDependency.moduleName.matches(it.toRegex())
}
val versionMatch =
version?.let {
// Version like `1.0.0+1` can't be converted to regex directly because `+` is a special
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,12 +64,11 @@ import org.gradle.language.base.plugins.LifecycleBasePlugin
@CacheableTask
public abstract class ShadowJar : Jar() {
private val dependencyFilterForMinimize = MinimizeDependencyFilter(project)
private val shadowDependencies =
project.provider {
// Find shadow configuration here instead of get, as the ShadowJar tasks could be registered
// without Shadow plugin applied.
project.configurations.findByName(ShadowBasePlugin.CONFIGURATION_NAME) ?: project.files()
}
private val shadowDependencies = project.provider {
// Find shadow configuration here instead of get, as the ShadowJar tasks could be registered
// without Shadow plugin applied.
project.configurations.findByName(ShadowBasePlugin.CONFIGURATION_NAME) ?: project.files()
}

init {
group = LifecycleBasePlugin.BUILD_GROUP
Expand Down Expand Up @@ -98,34 +97,30 @@ public abstract class ShadowJar : Jar() {
public open val minimizeJar: Property<Boolean> = objectFactory.property(false)

@get:Classpath
public open val toMinimize: ConfigurableFileCollection =
objectFactory.fileCollection {
minimizeJar.map {
if (it) (dependencyFilterForMinimize.resolve(configurations.get()) - apiJars)
else emptySet()
}
public open val toMinimize: ConfigurableFileCollection = objectFactory.fileCollection {
minimizeJar.map {
if (it) (dependencyFilterForMinimize.resolve(configurations.get()) - apiJars) else emptySet()
}
}

@get:Classpath
public open val apiJars: ConfigurableFileCollection =
objectFactory.fileCollection {
minimizeJar.map { if (it) project.getApiJars() else emptySet<File>() }
}
public open val apiJars: ConfigurableFileCollection = objectFactory.fileCollection {
minimizeJar.map { if (it) project.getApiJars() else emptySet<File>() }
}

@get:InputFiles
@get:PathSensitive(PathSensitivity.RELATIVE)
public open val sourceSetsClassesDirs: ConfigurableFileCollection =
objectFactory.fileCollection {
minimizeJar.map {
if (it) {
project.sourceSets.map { sourceSet ->
sourceSet.output.classesDirs.filter(File::isDirectory)
}
} else {
emptySet()
public open val sourceSetsClassesDirs: ConfigurableFileCollection = objectFactory.fileCollection {
minimizeJar.map {
if (it) {
project.sourceSets.map { sourceSet ->
sourceSet.output.classesDirs.filter(File::isDirectory)
}
} else {
emptySet()
}
}
}

/** [ResourceTransformer]s to be applied in the shadow steps. */
@get:Nested
Expand All @@ -148,10 +143,9 @@ public abstract class ShadowJar : Jar() {

/** Final dependencies to be shadowed. */
@get:Classpath
public open val includedDependencies: ConfigurableFileCollection =
objectFactory.fileCollection {
dependencyFilter.zip(configurations) { df, cs -> df.resolve(cs) }
}
public open val includedDependencies: ConfigurableFileCollection = objectFactory.fileCollection {
dependencyFilter.zip(configurations) { df, cs -> df.resolve(cs) }
}

/**
* Enables auto relocation of packages in the dependencies.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,9 @@ public interface ResourceTransformer : Named {
@JvmStatic
public fun <T : ResourceTransformer> Class<T>.create(objectFactory: ObjectFactory): T {
// If the constructor takes a single ObjectFactory, inject it in.
val constructor =
constructors.find { it.parameterTypes.singleOrNull() == ObjectFactory::class.java }
val constructor = constructors.find {
it.parameterTypes.singleOrNull() == ObjectFactory::class.java
}
return if (constructor != null) {
objectFactory.newInstance(this@create)
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,10 @@ class RelocatorsTest {
private companion object {
val primitiveTypes = setOf('B', 'C', 'D', 'F', 'I', 'J', 'S', 'Z')

val primitiveTypePatterns =
primitiveTypes.map {
// Methods like `void method(boolean arg1, org.package.ClassA arg2)`
Arguments.of("(${it}Lorg/package/ClassA;)V", "(${it}Lshadow/org/package/ClassA;)V")
}
val primitiveTypePatterns = primitiveTypes.map {
// Methods like `void method(boolean arg1, org.package.ClassA arg2)`
Arguments.of("(${it}Lorg/package/ClassA;)V", "(${it}Lshadow/org/package/ClassA;)V")
}

@JvmStatic
fun signaturePatternsProvider() =
Expand Down