Skip to content

Commit

Permalink
Add fileCollection extension
Browse files Browse the repository at this point in the history
  • Loading branch information
Goooler committed Dec 13, 2024
1 parent c748c2a commit 75f5647
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,14 @@ internal inline fun <reified T : Any> ObjectFactory.property(defaultValue: T? =
/**
* TODO: this could be removed after bumping the min Gradle requirement to 8.8 or above.
*/
internal fun ConfigurableFileCollection.conventionCompat(vararg paths: Any): ConfigurableFileCollection {
return if (GradleVersion.current() >= GradleVersion.version("8.8")) {
convention(paths)
} else {
setFrom(paths)
this
internal inline fun ObjectFactory.fileCollection(path: () -> Any): ConfigurableFileCollection {
return fileCollection().apply {
@Suppress("UnstableApiUsage")
if (GradleVersion.current() >= GradleVersion.version("8.8")) {
convention(path())
} else {
setFrom(path())
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import com.github.jengelman.gradle.plugins.shadow.internal.DependencyFilter
import com.github.jengelman.gradle.plugins.shadow.internal.MinimizeDependencyFilter
import com.github.jengelman.gradle.plugins.shadow.internal.UnusedTracker
import com.github.jengelman.gradle.plugins.shadow.internal.ZipCompressor
import com.github.jengelman.gradle.plugins.shadow.internal.conventionCompat
import com.github.jengelman.gradle.plugins.shadow.internal.fileCollection
import com.github.jengelman.gradle.plugins.shadow.internal.property
import com.github.jengelman.gradle.plugins.shadow.relocation.CacheableRelocator
import com.github.jengelman.gradle.plugins.shadow.relocation.Relocator
Expand Down Expand Up @@ -78,29 +78,30 @@ public abstract class ShadowJar :
public open val minimizeJar: Property<Boolean> = objectFactory.property(false)

@get:Classpath
public open val toMinimize: ConfigurableFileCollection = objectFactory.fileCollection()
.conventionCompat(
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()
.conventionCompat(
minimizeJar.map {
if (it) UnusedTracker.getApiJarsFromProject(project) else emptySet()
},
)
public open val apiJars: ConfigurableFileCollection = objectFactory.fileCollection {
minimizeJar.map { minimize ->
if (minimize) UnusedTracker.getApiJarsFromProject(project) else emptySet()
}
}

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

@get:Internal
protected open val rootPatternSet: PatternSet
Expand Down Expand Up @@ -131,8 +132,9 @@ public abstract class ShadowJar :
objectFactory.property(DefaultDependencyFilter(project))

@get:Classpath
public open val includedDependencies: ConfigurableFileCollection = objectFactory.fileCollection()
.conventionCompat(dependencyFilter.zip(configurations) { df, cs -> df.resolve(cs) })
public open val includedDependencies: ConfigurableFileCollection = objectFactory.fileCollection {
dependencyFilter.zip(configurations) { df, cs -> df.resolve(cs) }
}

/**
* Enable relocation of packages in the jar.
Expand Down

0 comments on commit 75f5647

Please sign in to comment.