mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
IJI-66: automatic update of mappings.json
This commit is contained in:
+20
-7
@@ -5,10 +5,7 @@ import com.intellij.openapi.application.PathManager
|
||||
import org.jetbrains.intellij.build.images.IconsClassGenerator
|
||||
import org.jetbrains.intellij.build.images.ImageCollector
|
||||
import org.jetbrains.intellij.build.images.isImage
|
||||
import org.jetbrains.intellij.build.images.sync.Context
|
||||
import org.jetbrains.intellij.build.images.sync.isAncestorOf
|
||||
import org.jetbrains.intellij.build.images.sync.isValidIcon
|
||||
import org.jetbrains.intellij.build.images.sync.protectStdErr
|
||||
import org.jetbrains.intellij.build.images.sync.*
|
||||
import org.jetbrains.jps.model.serialization.JpsSerializationManager
|
||||
import java.io.File
|
||||
import java.nio.file.FileVisitResult
|
||||
@@ -24,7 +21,7 @@ fun main() = generateMappings()
|
||||
private fun generateMappings() {
|
||||
val mappings = (loadIdeaGeneratedIcons() + loadNonGeneratedIcons("idea")).groupBy {
|
||||
"${it.product}#${it.set}"
|
||||
}.values.flatMap {
|
||||
}.toSortedMap().values.flatMap {
|
||||
if (it.size > 1) {
|
||||
System.err.println("Duplicates were generated $it\nRenaming")
|
||||
it.subList(1, it.size).mapIndexed { i, duplicate ->
|
||||
@@ -36,13 +33,29 @@ private fun generateMappings() {
|
||||
val mappingsJson = mappings.joinToString(separator = ",\n") {
|
||||
it.toString().prependIndent(" ")
|
||||
}
|
||||
println("""
|
||||
val json = """
|
||||
|{
|
||||
| "mappings": [
|
||||
|$mappingsJson
|
||||
| ]
|
||||
|}
|
||||
""".trimMargin())
|
||||
""".trimMargin()
|
||||
val path = File(System.getProperty("mappings.json.path") ?: error("Specify mappings.json.path"))
|
||||
val repo = findGitRepoRoot(path)
|
||||
fun String.normalize() = replace(Regex("\\s+"), " ").trim()
|
||||
if (json.normalize() == path.readText().normalize()) {
|
||||
println("Update is not required")
|
||||
}
|
||||
else {
|
||||
val branch = System.getProperty("branch") ?: "icons-mappings-update"
|
||||
withUser(repo, "MappingsUpdater", "mappings-updater-no-reply@jetbrains.com") {
|
||||
execute(repo, GIT, "checkout", "-B", branch, "origin/master")
|
||||
path.writeText(json)
|
||||
val jsonFile = path.toRelativeString(repo)
|
||||
stageFiles(listOf(jsonFile), repo)
|
||||
commitAndPush(repo, "refs/heads/$branch", "$jsonFile automatic update")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private class Mapping(val product: String, val set: String, val path: String) {
|
||||
|
||||
+2
-3
@@ -6,7 +6,7 @@ import java.io.IOException
|
||||
import java.util.stream.Collectors
|
||||
import java.util.stream.Stream
|
||||
|
||||
private val GIT = (System.getenv("TEAMCITY_GIT_PATH") ?: System.getenv("GIT") ?: "git").also {
|
||||
internal val GIT = (System.getenv("TEAMCITY_GIT_PATH") ?: System.getenv("GIT") ?: "git").also {
|
||||
val noGitFound = "Git is not found, please specify path to git executable in TEAMCITY_GIT_PATH or GIT or add it to PATH"
|
||||
try {
|
||||
val gitVersion = execute(null, it, "--version")
|
||||
@@ -136,9 +136,8 @@ private fun splitAndTry(factor: Int, files: List<String>, repo: File, block: (fi
|
||||
}
|
||||
|
||||
internal fun commitAndPush(repo: File, branch: String, message: String): String {
|
||||
execute(repo, GIT, "checkout", "-B", branch)
|
||||
execute(repo, GIT, "commit", "-m", message)
|
||||
push(repo, "$branch:$branch")
|
||||
push(repo, "+$branch:$branch")
|
||||
return commitInfo(repo)?.hash ?: error("Unable to read last commit")
|
||||
}
|
||||
|
||||
|
||||
+3
-2
@@ -251,10 +251,10 @@ private val reposMapGuard = Any()
|
||||
internal fun findRepo(file: File): File {
|
||||
if (!reposMap.containsKey(file)) synchronized(reposMapGuard) {
|
||||
if (!reposMap.containsKey(file)) {
|
||||
reposMap += file to findGitRepoRoot(file, silent = true)
|
||||
reposMap = reposMap + (file to findGitRepoRoot(file, silent = true))
|
||||
}
|
||||
}
|
||||
return reposMap[file]!!
|
||||
return reposMap.getValue(file)
|
||||
}
|
||||
|
||||
private fun findCommits(context: Context, root: File, changes: Changes) = changes.all()
|
||||
@@ -281,6 +281,7 @@ private fun commitAndPush(branch: String,
|
||||
message: String,
|
||||
repos: Collection<File>) = repos.parallelStream().map {
|
||||
withUser(it, user, email) {
|
||||
execute(it, GIT, "checkout", "-B", branch)
|
||||
commitAndPush(it, branch, message)
|
||||
}
|
||||
}.toList()
|
||||
|
||||
Reference in New Issue
Block a user