Rendering
This commit is contained in:
		@@ -19,6 +19,7 @@ repositories {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
dependencies {
 | 
					dependencies {
 | 
				
			||||||
	implementation 'org.jetbrains.kotlin:kotlin-stdlib'
 | 
						implementation 'org.jetbrains.kotlin:kotlin-stdlib'
 | 
				
			||||||
 | 
						implementation "org.jetbrains.kotlin:kotlin-reflect:$kotlinVersion"
 | 
				
			||||||
	implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-core:1.3.7'
 | 
						implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-core:1.3.7'
 | 
				
			||||||
	implementation "com.xenomachina:kotlin-argparser:$kotlin_argparser_version"
 | 
						implementation "com.xenomachina:kotlin-argparser:$kotlin_argparser_version"
 | 
				
			||||||
	implementation "org.jetbrains.exposed:exposed-core:$kotlin_exposed_version"
 | 
						implementation "org.jetbrains.exposed:exposed-core:$kotlin_exposed_version"
 | 
				
			||||||
@@ -26,5 +27,7 @@ dependencies {
 | 
				
			|||||||
	implementation "org.jetbrains.exposed:exposed-jdbc:$kotlin_exposed_version"
 | 
						implementation "org.jetbrains.exposed:exposed-jdbc:$kotlin_exposed_version"
 | 
				
			||||||
	implementation "org.xerial:sqlite-jdbc:3.30.1"
 | 
						implementation "org.xerial:sqlite-jdbc:3.30.1"
 | 
				
			||||||
    implementation 'com.google.code.gson:gson:2.8.6'
 | 
					    implementation 'com.google.code.gson:gson:2.8.6'
 | 
				
			||||||
 | 
					    implementation 'org.python:jython-standalone:2.7.2'
 | 
				
			||||||
 | 
					    implementation 'org.pygments:pygments:2.5.2'
 | 
				
			||||||
	testImplementation 'junit:junit:4.12'
 | 
						testImplementation 'junit:junit:4.12'
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -1,3 +1,3 @@
 | 
				
			|||||||
kotlinVersion=1.3.71
 | 
					kotlinVersion=1.4.0
 | 
				
			||||||
kotlin_argparser_version=2.0.7
 | 
					kotlin_argparser_version=2.0.7
 | 
				
			||||||
kotlin_exposed_version=0.25.1
 | 
					kotlin_exposed_version=0.25.1
 | 
				
			||||||
@@ -115,9 +115,7 @@ fun main(args: Array<String>) = mainBody {
 | 
				
			|||||||
            }
 | 
					            }
 | 
				
			||||||
            return hasInterest
 | 
					            return hasInterest
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					        val fnames = repo.ls().split("\n").filter { it.isInteresting() }
 | 
				
			||||||
        fun GitRepo.interestingNames() = ls().split("\n").filter { it.isInteresting() }
 | 
					 | 
				
			||||||
        val fnames = repo.interestingNames()
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
        if (fnames.isEmpty()) {
 | 
					        if (fnames.isEmpty()) {
 | 
				
			||||||
            System.err.println("No interesting files found, exiting.")
 | 
					            System.err.println("No interesting files found, exiting.")
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -1,15 +1,11 @@
 | 
				
			|||||||
package me.msoucy.gbat
 | 
					package me.msoucy.gbat
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import java.io.File
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
import me.msoucy.gbat.models.ProjectTreeNode
 | 
					 | 
				
			||||||
import me.msoucy.gbat.models.ProjectTreeResult
 | 
					 | 
				
			||||||
import me.msoucy.gbat.models.Statistics
 | 
					 | 
				
			||||||
import me.msoucy.gbat.models.SummaryModel
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
import com.google.gson.GsonBuilder
 | 
					import com.google.gson.GsonBuilder
 | 
				
			||||||
 | 
					import java.io.File
 | 
				
			||||||
 | 
					import me.msoucy.gbat.models.SummaryModel
 | 
				
			||||||
import org.jetbrains.exposed.sql.*
 | 
					import org.jetbrains.exposed.sql.*
 | 
				
			||||||
import org.jetbrains.exposed.sql.transactions.transaction
 | 
					import org.jetbrains.exposed.sql.transactions.transaction
 | 
				
			||||||
 | 
					import org.python.util.PythonInterpreter
 | 
				
			||||||
 | 
					
 | 
				
			||||||
val NUM_RISKIEST_AUTHORS = 10
 | 
					val NUM_RISKIEST_AUTHORS = 10
 | 
				
			||||||
val NUM_RISKIEST_FILES = 10
 | 
					val NUM_RISKIEST_FILES = 10
 | 
				
			||||||
@@ -25,7 +21,7 @@ class SummaryRenderer(
 | 
				
			|||||||
        createFilesDir()
 | 
					        createFilesDir()
 | 
				
			||||||
        renderSummaryJson(projectRoot)
 | 
					        renderSummaryJson(projectRoot)
 | 
				
			||||||
        renderFileJson(projectRoot)
 | 
					        renderFileJson(projectRoot)
 | 
				
			||||||
        // renderSrc(projectRoot)
 | 
					        renderSrc(projectRoot)
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    private fun renderSummaryJson(projectRoot: File) {
 | 
					    private fun renderSummaryJson(projectRoot: File) {
 | 
				
			||||||
@@ -42,6 +38,32 @@ class SummaryRenderer(
 | 
				
			|||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    private fun createFilesDir() = filesDir.mkdirs()
 | 
					    private fun createFilesDir() = filesDir.mkdirs()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    private fun renderSrc(projectRoot: File) {
 | 
				
			||||||
 | 
					        val interpreter = PythonInterpreter()
 | 
				
			||||||
 | 
					        val cssFile = File(filesDir, "pygments.css")
 | 
				
			||||||
 | 
					        interpreter.exec("""
 | 
				
			||||||
 | 
					from pygments.formatters import HtmlFormatter
 | 
				
			||||||
 | 
					formatter = HtmlFormatter(linenos=True, lineanchors='gbab')
 | 
				
			||||||
 | 
					formatCss = formatter.get_style_defs()
 | 
				
			||||||
 | 
					""")
 | 
				
			||||||
 | 
					        cssFile.writeText(interpreter.get("formatCss", String::class.java))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        summaryModel.projectFiles(projectRoot.absolutePath).forEach {
 | 
				
			||||||
 | 
					            val resultFile = File(filesDir, "${it.fileId}.html")
 | 
				
			||||||
 | 
					            val lines = summaryModel.fileLines(it.fileId)
 | 
				
			||||||
 | 
					            val body = lines.joinToString("\n")
 | 
				
			||||||
 | 
					            interpreter["fname"] = it.fname.toString()
 | 
				
			||||||
 | 
					            interpreter["body"] = body
 | 
				
			||||||
 | 
					            interpreter.exec("""
 | 
				
			||||||
 | 
					from pygments import highlight
 | 
				
			||||||
 | 
					from pygments.lexers import guess_lexer_for_filename
 | 
				
			||||||
 | 
					lexer = guess_lexer_for_filename(fname, body)
 | 
				
			||||||
 | 
					html = highlight(body, lexer, formatter)
 | 
				
			||||||
 | 
					""")
 | 
				
			||||||
 | 
					            resultFile.writeText("""<link rel=stylesheet type="text/css" href="pygments.css">""" + interpreter.get("html", String::class.java))
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
fun renderSummary(
 | 
					fun renderSummary(
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -14,6 +14,7 @@ class GitRepo(val projectRoot: File, val git_exe: String) {
 | 
				
			|||||||
            "--name-only",
 | 
					            "--name-only",
 | 
				
			||||||
            "-r",
 | 
					            "-r",
 | 
				
			||||||
            "HEAD",
 | 
					            "HEAD",
 | 
				
			||||||
 | 
					            "--",
 | 
				
			||||||
            projectRoot.absolutePath
 | 
					            projectRoot.absolutePath
 | 
				
			||||||
        )
 | 
					        )
 | 
				
			||||||
        val (out, _) = cmd.runCommand(projectRoot)
 | 
					        val (out, _) = cmd.runCommand(projectRoot)
 | 
				
			||||||
@@ -40,6 +41,7 @@ class GitRepo(val projectRoot: File, val git_exe: String) {
 | 
				
			|||||||
            "--follow", // Follow history through renames
 | 
					            "--follow", // Follow history through renames
 | 
				
			||||||
            "--patience", // Use the patience diff algorithm
 | 
					            "--patience", // Use the patience diff algorithm
 | 
				
			||||||
            "-p", // Show patches
 | 
					            "-p", // Show patches
 | 
				
			||||||
 | 
					            "--",
 | 
				
			||||||
            fname.absolutePath
 | 
					            fname.absolutePath
 | 
				
			||||||
        )
 | 
					        )
 | 
				
			||||||
        val (out, err) = cmd.runCommand(projectRoot)
 | 
					        val (out, err) = cmd.runCommand(projectRoot)
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user