-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add
JvmFiles
and JvmFilesProvider
classes for easier univer…
…sal JVM targets manupulations Signed-off-by: Artyom Shendrik <[email protected]>
- Loading branch information
Showing
2 changed files
with
78 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package fluxo.conf.jvm | ||
|
||
import org.gradle.api.Task | ||
import org.gradle.api.file.FileCollection | ||
import org.gradle.api.file.RegularFile | ||
import org.gradle.api.provider.Provider | ||
|
||
internal class JvmFiles( | ||
val allRuntimeJars: FileCollection, | ||
val mainJar: Provider<RegularFile>, | ||
private val taskDependencies: Array<Any>, | ||
) { | ||
operator fun component1() = allRuntimeJars | ||
|
||
operator fun component2() = mainJar | ||
|
||
fun <T : Task> configureUsageBy(task: T, fn: T.(JvmFiles) -> Unit) { | ||
task.dependsOn(taskDependencies) | ||
task.fn(this) | ||
} | ||
} |
57 changes: 57 additions & 0 deletions
57
fluxo-kmp-conf/src/main/kotlin/fluxo/conf/jvm/JvmFilesProvider.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
package fluxo.conf.jvm | ||
|
||
import MAIN_SOURCE_SET_NAME | ||
import org.gradle.api.Project | ||
import org.gradle.api.file.FileCollection | ||
import org.gradle.api.tasks.SourceSet | ||
import org.gradle.jvm.tasks.Jar | ||
import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinJvmCompilation | ||
import org.jetbrains.kotlin.gradle.targets.jvm.KotlinJvmTarget | ||
|
||
internal sealed class JvmFilesProvider { | ||
abstract fun jvmCompileFiles(project: Project): JvmFiles | ||
|
||
abstract class GradleJvmFilesProvider : JvmFilesProvider() { | ||
protected abstract val jarTaskName: String | ||
protected abstract val compileFiles: FileCollection | ||
protected abstract val runtimeFiles: FileCollection | ||
|
||
override fun jvmCompileFiles(project: Project): JvmFiles { | ||
val jarTask = project.tasks.named(jarTaskName, Jar::class.java) | ||
val mainJar = jarTask.flatMap { it.archiveFile } | ||
val runtimeJarFiles = project.objects.fileCollection().apply { | ||
from(mainJar) | ||
from(compileFiles.filter { it.path.endsWith(".jar") }) | ||
} | ||
return JvmFiles(runtimeJarFiles, mainJar, arrayOf(jarTask)) | ||
} | ||
} | ||
|
||
class FromGradleSourceSet(private val sourceSet: SourceSet) : | ||
GradleJvmFilesProvider() { | ||
override val jarTaskName: String | ||
get() = sourceSet.jarTaskName | ||
|
||
override val compileFiles: FileCollection | ||
get() = sourceSet.compileClasspath | ||
|
||
override val runtimeFiles: FileCollection | ||
get() = sourceSet.runtimeClasspath | ||
} | ||
|
||
class FromKotlinMppTarget(private val target: KotlinJvmTarget) : | ||
GradleJvmFilesProvider() { | ||
|
||
override val jarTaskName: String | ||
get() = target.artifactsTaskName | ||
|
||
override val compileFiles: FileCollection | ||
get() = mainCompilation.compileDependencyFiles | ||
|
||
override val runtimeFiles: FileCollection | ||
get() = mainCompilation.runtimeDependencyFiles | ||
|
||
private val mainCompilation: KotlinJvmCompilation | ||
get() = target.compilations.getByName(MAIN_SOURCE_SET_NAME) | ||
} | ||
} |