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 org.gradle.internal.os.OperatingSystem
|
||||||
import java.io.Closeable
|
import java.io.Closeable
|
||||||
import java.io.FileWriter
|
|
||||||
import java.io.OutputStreamWriter
|
import java.io.OutputStreamWriter
|
||||||
import java.net.URI
|
import java.net.URI
|
||||||
import java.text.SimpleDateFormat
|
import java.text.SimpleDateFormat
|
||||||
@@ -10,7 +9,8 @@ import java.util.*
|
|||||||
import javax.xml.stream.XMLOutputFactory
|
import javax.xml.stream.XMLOutputFactory
|
||||||
|
|
||||||
import org.jetbrains.kotlin.gradle.tasks.internal.CleanableStore
|
import org.jetbrains.kotlin.gradle.tasks.internal.CleanableStore
|
||||||
import org.jetbrains.kotlin.gradle.tasks.CleanDataTask
|
import java.time.Duration
|
||||||
|
import java.time.Instant
|
||||||
|
|
||||||
plugins {
|
plugins {
|
||||||
base
|
base
|
||||||
@@ -143,21 +143,7 @@ dependencies {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
val makeIntellijCore = buildIvyRepositoryTask(intellijCore, customDepsOrg, customDepsRepoDir)
|
||||||
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 makeIntellijAnnotations by tasks.registering(Copy::class) {
|
val makeIntellijAnnotations by tasks.registering(Copy::class) {
|
||||||
dependsOn(makeIntellijCore)
|
dependsOn(makeIntellijCore)
|
||||||
@@ -165,12 +151,17 @@ val makeIntellijAnnotations by tasks.registering(Copy::class) {
|
|||||||
val intellijCoreRepo = CleanableStore[repoDir.resolve("intellij-core").absolutePath][intellijVersion].use()
|
val intellijCoreRepo = CleanableStore[repoDir.resolve("intellij-core").absolutePath][intellijVersion].use()
|
||||||
from(intellijCoreRepo.resolve("artifacts/annotations.jar"))
|
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)
|
into(targetDir)
|
||||||
|
|
||||||
val ivyFile = File(targetDir, "$intellijRuntimeAnnotations.ivy.xml")
|
val ivyFile = File(targetDir, "$intellijRuntimeAnnotations.ivy.xml")
|
||||||
outputs.files(ivyFile)
|
outputs.files(ivyFile)
|
||||||
|
|
||||||
|
doFirst {
|
||||||
|
annotationsStore.cleanStore()
|
||||||
|
}
|
||||||
|
|
||||||
doLast {
|
doLast {
|
||||||
writeIvyXml(
|
writeIvyXml(
|
||||||
customDepsOrg,
|
customDepsOrg,
|
||||||
@@ -201,7 +192,7 @@ val mergeSources by tasks.creating(Jar::class.java) {
|
|||||||
val sourcesFile = mergeSources.outputs.files.singleFile
|
val sourcesFile = mergeSources.outputs.files.singleFile
|
||||||
|
|
||||||
val makeIde = if (androidStudioBuild != null) {
|
val makeIde = if (androidStudioBuild != null) {
|
||||||
buildIvyRepositoryTaskAndRegisterCleanupTask(
|
buildIvyRepositoryTask(
|
||||||
androidStudio,
|
androidStudio,
|
||||||
customDepsOrg,
|
customDepsOrg,
|
||||||
customDepsRepoDir,
|
customDepsRepoDir,
|
||||||
@@ -212,9 +203,9 @@ val makeIde = if (androidStudioBuild != null) {
|
|||||||
)
|
)
|
||||||
} else {
|
} else {
|
||||||
val task = if (installIntellijUltimate) {
|
val task = if (installIntellijUltimate) {
|
||||||
buildIvyRepositoryTaskAndRegisterCleanupTask(intellijUltimate, customDepsOrg, customDepsRepoDir, null, sourcesFile)
|
buildIvyRepositoryTask(intellijUltimate, customDepsOrg, customDepsRepoDir, null, sourcesFile)
|
||||||
} else {
|
} else {
|
||||||
buildIvyRepositoryTaskAndRegisterCleanupTask(intellij, customDepsOrg, customDepsRepoDir, null, sourcesFile)
|
buildIvyRepositoryTask(intellij, customDepsOrg, customDepsRepoDir, null, sourcesFile)
|
||||||
}
|
}
|
||||||
|
|
||||||
task.configure {
|
task.configure {
|
||||||
@@ -224,7 +215,7 @@ val makeIde = if (androidStudioBuild != null) {
|
|||||||
task
|
task
|
||||||
}
|
}
|
||||||
|
|
||||||
val buildJpsStandalone = buildIvyRepositoryTaskAndRegisterCleanupTask(jpsStandalone, customDepsOrg, customDepsRepoDir, null, sourcesFile)
|
val buildJpsStandalone = buildIvyRepositoryTask(jpsStandalone, customDepsOrg, customDepsRepoDir, null, sourcesFile)
|
||||||
|
|
||||||
tasks.named("build") {
|
tasks.named("build") {
|
||||||
dependsOn(
|
dependsOn(
|
||||||
@@ -238,24 +229,15 @@ tasks.named("build") {
|
|||||||
|
|
||||||
if (installIntellijUltimate) {
|
if (installIntellijUltimate) {
|
||||||
val buildNodeJsPlugin =
|
val buildNodeJsPlugin =
|
||||||
buildIvyRepositoryTaskAndRegisterCleanupTask(nodeJSPlugin, customDepsOrg, customDepsRepoDir, ::skipToplevelDirectory, sourcesFile)
|
buildIvyRepositoryTask(nodeJSPlugin, customDepsOrg, customDepsRepoDir, ::skipToplevelDirectory, sourcesFile)
|
||||||
tasks.named("build") { dependsOn(buildNodeJsPlugin) }
|
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") {
|
tasks.named<Delete>("clean") {
|
||||||
//TODO specify repos to clean? Use CleanDataTask
|
|
||||||
delete(customDepsRepoDir)
|
delete(customDepsRepoDir)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun buildIvyRepositoryTaskAndRegisterCleanupTask(
|
fun buildIvyRepositoryTask(
|
||||||
configuration: Configuration,
|
configuration: Configuration,
|
||||||
organization: String,
|
organization: String,
|
||||||
repoDirectory: File,
|
repoDirectory: File,
|
||||||
@@ -268,7 +250,7 @@ fun buildIvyRepositoryTaskAndRegisterCleanupTask(
|
|||||||
fun ResolvedArtifact.moduleDirectory(): File =
|
fun ResolvedArtifact.moduleDirectory(): File =
|
||||||
storeDirectory()[moduleVersion.id.version].use()
|
storeDirectory()[moduleVersion.id.version].use()
|
||||||
|
|
||||||
val buildIvyRepositoryTask = tasks.register("buildIvyRepositoryFor${configuration.name.capitalize()}") {
|
return tasks.register("buildIvyRepositoryFor${configuration.name.capitalize()}") {
|
||||||
dependsOn(configuration)
|
dependsOn(configuration)
|
||||||
inputs.files(configuration)
|
inputs.files(configuration)
|
||||||
|
|
||||||
@@ -281,6 +263,9 @@ fun buildIvyRepositoryTaskAndRegisterCleanupTask(
|
|||||||
doFirst {
|
doFirst {
|
||||||
val artifact = configuration.resolvedConfiguration.resolvedArtifacts.single()
|
val artifact = configuration.resolvedConfiguration.resolvedArtifacts.single()
|
||||||
val moduleDirectory = artifact.moduleDirectory()
|
val moduleDirectory = artifact.moduleDirectory()
|
||||||
|
|
||||||
|
artifact.storeDirectory().cleanStore()
|
||||||
|
|
||||||
if (moduleDirectory.exists()) {
|
if (moduleDirectory.exists()) {
|
||||||
logger.info("Path ${moduleDirectory.absolutePath} already exists, skipping unpacking.")
|
logger.info("Path ${moduleDirectory.absolutePath} already exists, skipping unpacking.")
|
||||||
return@doFirst
|
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(
|
fun writeIvyXml(
|
||||||
organization: String,
|
organization: String,
|
||||||
moduleName: String,
|
moduleName: String,
|
||||||
|
|||||||
Reference in New Issue
Block a user