icons.gant: cleanups after IDEA-CR-16996

This commit is contained in:
Aleksey Pivovarov
2017-03-03 20:56:57 +03:00
parent 94d6b8d0c0
commit 362d13e65e
5 changed files with 20 additions and 60 deletions
@@ -23,11 +23,9 @@ import org.jetbrains.jps.model.java.JavaSourceRootProperties
import org.jetbrains.jps.model.java.JavaSourceRootType
import org.jetbrains.jps.model.module.JpsModule
import org.jetbrains.jps.util.JpsPathUtil
import java.io.BufferedReader
import java.io.File
import java.io.StringReader
import java.util.*
import java.util.function.Function
import kotlin.comparisons.compareBy
class IconsClassGenerator(val projectHome: File, val util: JpsModule) {
private var processedClasses = 0
@@ -81,8 +79,8 @@ class IconsClassGenerator(val projectHome: File, val util: JpsModule) {
val text = generate(module, className, packageName, customLoad, copyrightComment)
if (text != null) {
processedClasses++
if (!outFile.exists() || !sameLines(outFile.readText(), text)) {
if (!outFile.exists() || outFile.readText().lines() != text.lines()) {
outFile.parentFile.mkdirs()
outFile.writeText(text)
println("Updated icons class: ${outFile.name}")
@@ -91,7 +89,7 @@ class IconsClassGenerator(val projectHome: File, val util: JpsModule) {
}
fun printStats() {
println("")
println()
println("Generated classes: $processedClasses. Processed icons: $processedIcons")
}
@@ -114,18 +112,6 @@ class IconsClassGenerator(val projectHome: File, val util: JpsModule) {
return if (comment.trim().endsWith("*/")) comment else ""
}
private fun sameLines(a: String, b: String): Boolean {
val ra = BufferedReader(StringReader(a))
val rb = BufferedReader(StringReader(b))
while (true) {
val la = ra.readLine()
val lb = rb.readLine()
if (la != lb) return false
if (la == null) return true
}
}
private fun generate(module: JpsModule, className: String, packageName: String, customLoad: Boolean, copyrightComment: String): String? {
val answer = StringBuilder()
answer.append(copyrightComment)
@@ -302,5 +288,5 @@ class IconsClassGenerator(val projectHome: File, val util: JpsModule) {
}
// legacy ordering
private val NAME_COMPARATOR: Comparator<String> = Comparator.comparing(Function<String, String> { it.toLowerCase() + "." })
private val NAME_COMPARATOR: Comparator<String> = compareBy { it.toLowerCase() + "." }
}
@@ -18,7 +18,6 @@ package com.intellij.build.scripts
import com.intellij.openapi.util.io.FileUtil
import com.intellij.openapi.util.io.FileUtilRt
import com.intellij.openapi.util.text.StringUtil
import com.intellij.util.containers.ContainerUtil
import org.jetbrains.jps.model.java.JavaModuleSourceRootTypes
import org.jetbrains.jps.model.module.JpsModule
import org.jetbrains.jps.model.module.JpsModuleSourceRoot
@@ -74,7 +73,7 @@ internal class ImageCollector(val projectHome: File, val iconsOnly: Boolean = tr
if (file.isDirectory) {
val root = sourceRoot.file
val childRobotData = robotData.fork(file, root)
val childPrefix = ContainerUtil.append(prefix, file.name)
val childPrefix = prefix + file.name
processDirectory(file, sourceRoot, childRobotData, childPrefix)
}
else if (isImage(file, iconsOnly)) {
@@ -94,7 +93,7 @@ internal class ImageCollector(val projectHome: File, val iconsOnly: Boolean = tr
if (skipped) return
val iconPaths = result.computeIfAbsent(id, { ImagePaths(id, sourceRoot, used, deprecated) })
if (iconPaths.files[type] == null) {
if (type !in iconPaths.files) {
iconPaths.files[type] = file
}
else {
@@ -103,7 +102,7 @@ internal class ImageCollector(val projectHome: File, val iconsOnly: Boolean = tr
}
private fun upToProjectHome(dir: File): IconRobotsData {
if (dir == projectHome) return IconRobotsData()
if (FileUtil.filesEqual(dir, projectHome)) return IconRobotsData()
val parent = dir.parentFile ?: return IconRobotsData()
return upToProjectHome(parent).fork(parent, projectHome)
}
@@ -126,39 +125,14 @@ internal class ImageCollector(val projectHome: File, val iconsOnly: Boolean = tr
return childCommon
}
else if (isImage(file, iconsOnly)) {
return getCommonAncestor(common, file)
if (common == null) return file
return FileUtil.findAncestor(common, file)
}
else {
return common
}
}
private fun getCommonAncestor(file1: File?, file2: File?): File? {
if (file1 == null) return file2
if (file2 == null) return file1
val c1 = pathComponents(file1)
val c2 = pathComponents(file2)
val size = Math.min(c1.size, c2.size)
var cur: File? = null
for (i in 0..size - 1) {
if (c1[i] != c2[i]) break
cur = c1[i]
}
return cur
}
private fun pathComponents(file: File): List<File> {
val answer = ArrayList<File>()
var cur: File? = file
while (cur != null) {
answer.add(cur)
cur = cur.parentFile
}
return answer.reversed()
}
private inner class IconRobotsData(private val parent: IconRobotsData? = null) {
private val skip: MutableSet<Matcher> = HashSet()
private val used: MutableSet<Matcher> = HashSet()
@@ -38,17 +38,17 @@ abstract class ImageSanityCheckerBase(val projectHome: File, val ignoreSkipTag:
private fun checkHaveRetinaVersion(images: List<ImagePaths>, module: JpsModule) {
process(images, Severity.INFO, "image without retina version", module) { image ->
val hasRetina = image.files[RETINA] != null
val hasRetinaDarcula = image.files[RETINA_DARCULA] != null
val hasRetina = RETINA in image.files
val hasRetinaDarcula = RETINA_DARCULA in image.files
return@process hasRetina || hasRetinaDarcula
}
}
private fun checkHaveCompleteIconSet(images: List<ImagePaths>, module: JpsModule) {
process(images, WARNING, "image without complete set of additional icons", module) { image ->
val hasRetina = image.files[RETINA] != null
val hasDarcula = image.files[DARCULA] != null
val hasRetinaDarcula = image.files[RETINA_DARCULA] != null
val hasRetina = RETINA in image.files
val hasDarcula = DARCULA in image.files
val hasRetinaDarcula = RETINA_DARCULA in image.files
if (hasRetinaDarcula) {
return@process hasRetina && hasDarcula
@@ -109,14 +109,14 @@ class ImageSanityChecker(projectHome: File) : ImageSanityCheckerBase(projectHome
fun printInfo() {
if (infos.isNotEmpty()) {
println("")
println()
println(infos)
}
}
fun printWarnings() {
if (warnings.isNotEmpty()) {
println("")
println()
println(warnings)
}
}
@@ -47,7 +47,7 @@ class ImageSizeOptimizer(val projectHome: File) {
}
fun printStats() {
println("")
println()
println("PNG size optimization: $optimizedTotal bytes in total")
}
@@ -19,7 +19,7 @@ import com.intellij.openapi.util.text.StringUtil
import java.awt.*
import java.io.File
internal val File.children: List<File> get() = if (this.isDirectory) this.listFiles().toList() else emptyList()
internal val File.children: List<File> get() = if (isDirectory) listFiles().toList() else emptyList()
internal fun isImage(file: File, iconsOnly: Boolean): Boolean {
if (!isImage(file.name)) return false
@@ -71,7 +71,7 @@ internal enum class ImageType(private val suffix: String) {
fun stripSuffix(name: String): String {
val type = fromName(name)
return StringUtil.trimEnd(name, type.suffix)
return name.removeSuffix(type.suffix)
}
}
}