Build: Move dependencies cleanup to corresponding task action
Do cleanup only before dependencies unpacking to avoid tasks which are always not up-to-date
This commit is contained in:
@@ -2,7 +2,6 @@
|
||||
|
||||
import org.gradle.internal.os.OperatingSystem
|
||||
import java.io.Closeable
|
||||
import java.io.FileWriter
|
||||
import java.io.OutputStreamWriter
|
||||
import java.net.URI
|
||||
import java.text.SimpleDateFormat
|
||||
@@ -10,7 +9,8 @@ import java.util.*
|
||||
import javax.xml.stream.XMLOutputFactory
|
||||
|
||||
import org.jetbrains.kotlin.gradle.tasks.internal.CleanableStore
|
||||
import org.jetbrains.kotlin.gradle.tasks.CleanDataTask
|
||||
import java.time.Duration
|
||||
import java.time.Instant
|
||||
|
||||
plugins {
|
||||
base
|
||||
@@ -143,21 +143,7 @@ dependencies {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
val cleanupIntellijCore = tasks.register<CleanDataTask>("cleanupIntellijCore") {
|
||||
cleanableStoreProvider = provider { CleanableStore[repoDir.resolve("intellij-core").absolutePath] }
|
||||
}
|
||||
|
||||
val cleanupIntellijAnnotation = tasks.register<CleanDataTask>("cleanupIntellijAnnotation") {
|
||||
cleanableStoreProvider = provider { CleanableStore[repoDir.resolve(intellijRuntimeAnnotations).absolutePath] }
|
||||
}
|
||||
|
||||
val cleanupDependencies = tasks.register("cleanupDependencies") {
|
||||
dependsOn(cleanupIntellijCore)
|
||||
dependsOn(cleanupIntellijAnnotation)
|
||||
}
|
||||
|
||||
val makeIntellijCore = buildIvyRepositoryTaskAndRegisterCleanupTask(intellijCore, customDepsOrg, customDepsRepoDir)
|
||||
val makeIntellijCore = buildIvyRepositoryTask(intellijCore, customDepsOrg, customDepsRepoDir)
|
||||
|
||||
val makeIntellijAnnotations by tasks.registering(Copy::class) {
|
||||
dependsOn(makeIntellijCore)
|
||||
@@ -165,12 +151,17 @@ val makeIntellijAnnotations by tasks.registering(Copy::class) {
|
||||
val intellijCoreRepo = CleanableStore[repoDir.resolve("intellij-core").absolutePath][intellijVersion].use()
|
||||
from(intellijCoreRepo.resolve("artifacts/annotations.jar"))
|
||||
|
||||
val targetDir = CleanableStore[repoDir.resolve(intellijRuntimeAnnotations).absolutePath][intellijVersion].use()
|
||||
val annotationsStore = CleanableStore[repoDir.resolve(intellijRuntimeAnnotations).absolutePath]
|
||||
val targetDir = annotationsStore[intellijVersion].use()
|
||||
into(targetDir)
|
||||
|
||||
val ivyFile = File(targetDir, "$intellijRuntimeAnnotations.ivy.xml")
|
||||
outputs.files(ivyFile)
|
||||
|
||||
doFirst {
|
||||
annotationsStore.cleanStore()
|
||||
}
|
||||
|
||||
doLast {
|
||||
writeIvyXml(
|
||||
customDepsOrg,
|
||||
@@ -201,7 +192,7 @@ val mergeSources by tasks.creating(Jar::class.java) {
|
||||
val sourcesFile = mergeSources.outputs.files.singleFile
|
||||
|
||||
val makeIde = if (androidStudioBuild != null) {
|
||||
buildIvyRepositoryTaskAndRegisterCleanupTask(
|
||||
buildIvyRepositoryTask(
|
||||
androidStudio,
|
||||
customDepsOrg,
|
||||
customDepsRepoDir,
|
||||
@@ -212,9 +203,9 @@ val makeIde = if (androidStudioBuild != null) {
|
||||
)
|
||||
} else {
|
||||
val task = if (installIntellijUltimate) {
|
||||
buildIvyRepositoryTaskAndRegisterCleanupTask(intellijUltimate, customDepsOrg, customDepsRepoDir, null, sourcesFile)
|
||||
buildIvyRepositoryTask(intellijUltimate, customDepsOrg, customDepsRepoDir, null, sourcesFile)
|
||||
} else {
|
||||
buildIvyRepositoryTaskAndRegisterCleanupTask(intellij, customDepsOrg, customDepsRepoDir, null, sourcesFile)
|
||||
buildIvyRepositoryTask(intellij, customDepsOrg, customDepsRepoDir, null, sourcesFile)
|
||||
}
|
||||
|
||||
task.configure {
|
||||
@@ -224,7 +215,7 @@ val makeIde = if (androidStudioBuild != null) {
|
||||
task
|
||||
}
|
||||
|
||||
val buildJpsStandalone = buildIvyRepositoryTaskAndRegisterCleanupTask(jpsStandalone, customDepsOrg, customDepsRepoDir, null, sourcesFile)
|
||||
val buildJpsStandalone = buildIvyRepositoryTask(jpsStandalone, customDepsOrg, customDepsRepoDir, null, sourcesFile)
|
||||
|
||||
tasks.named("build") {
|
||||
dependsOn(
|
||||
@@ -238,24 +229,15 @@ tasks.named("build") {
|
||||
|
||||
if (installIntellijUltimate) {
|
||||
val buildNodeJsPlugin =
|
||||
buildIvyRepositoryTaskAndRegisterCleanupTask(nodeJSPlugin, customDepsOrg, customDepsRepoDir, ::skipToplevelDirectory, sourcesFile)
|
||||
buildIvyRepositoryTask(nodeJSPlugin, customDepsOrg, customDepsRepoDir, ::skipToplevelDirectory, sourcesFile)
|
||||
tasks.named("build") { dependsOn(buildNodeJsPlugin) }
|
||||
}
|
||||
|
||||
tasks.named("build") { dependsOn(cleanupDependencies) }
|
||||
|
||||
// Task to delete legacy repo locations
|
||||
tasks.register<Delete>("cleanLegacy") {
|
||||
delete("$projectDir/android-dx")
|
||||
delete("$projectDir/intellij-sdk")
|
||||
}
|
||||
|
||||
tasks.named<Delete>("clean") {
|
||||
//TODO specify repos to clean? Use CleanDataTask
|
||||
delete(customDepsRepoDir)
|
||||
}
|
||||
|
||||
fun buildIvyRepositoryTaskAndRegisterCleanupTask(
|
||||
fun buildIvyRepositoryTask(
|
||||
configuration: Configuration,
|
||||
organization: String,
|
||||
repoDirectory: File,
|
||||
@@ -268,7 +250,7 @@ fun buildIvyRepositoryTaskAndRegisterCleanupTask(
|
||||
fun ResolvedArtifact.moduleDirectory(): File =
|
||||
storeDirectory()[moduleVersion.id.version].use()
|
||||
|
||||
val buildIvyRepositoryTask = tasks.register("buildIvyRepositoryFor${configuration.name.capitalize()}") {
|
||||
return tasks.register("buildIvyRepositoryFor${configuration.name.capitalize()}") {
|
||||
dependsOn(configuration)
|
||||
inputs.files(configuration)
|
||||
|
||||
@@ -281,6 +263,9 @@ fun buildIvyRepositoryTaskAndRegisterCleanupTask(
|
||||
doFirst {
|
||||
val artifact = configuration.resolvedConfiguration.resolvedArtifacts.single()
|
||||
val moduleDirectory = artifact.moduleDirectory()
|
||||
|
||||
artifact.storeDirectory().cleanStore()
|
||||
|
||||
if (moduleDirectory.exists()) {
|
||||
logger.info("Path ${moduleDirectory.absolutePath} already exists, skipping unpacking.")
|
||||
return@doFirst
|
||||
@@ -344,20 +329,10 @@ fun buildIvyRepositoryTaskAndRegisterCleanupTask(
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
val cleanupIvyRepositoryTask = tasks.register<CleanDataTask>("cleanupIvyRepositoryFor${configuration.name.capitalize()}") {
|
||||
cleanableStoreProvider = provider {
|
||||
configuration.resolvedConfiguration.resolvedArtifacts.single().storeDirectory()
|
||||
}
|
||||
}
|
||||
|
||||
cleanupDependencies {
|
||||
dependsOn(cleanupIvyRepositoryTask)
|
||||
}
|
||||
|
||||
return buildIvyRepositoryTask
|
||||
}
|
||||
|
||||
fun CleanableStore.cleanStore() = cleanDir(Instant.now().minus(Duration.ofDays(30)))
|
||||
|
||||
fun writeIvyXml(
|
||||
organization: String,
|
||||
moduleName: String,
|
||||
|
||||
Reference in New Issue
Block a user