Skip to content
This repository has been archived by the owner on May 25, 2022. It is now read-only.

Commit

Permalink
feat: add append to files for content
Browse files Browse the repository at this point in the history
  • Loading branch information
phodal committed Mar 22, 2022
1 parent 1893985 commit 3def653
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,12 @@ data class ChangeEntry(
@Sql("change_mode") val changeMode: String,
@Sql("commit_id") val commitId: String)

@Sql("scm_path_change_count")
data class PathChangeCount(
@Sql("id") val id: String,
@Sql("path") val path: String,
@Sql("changes") val changes: Int,
@Sql("system_id") val systemId: Long)

@Target(AnnotationTarget.CLASS, AnnotationTarget.PROPERTY)
annotation class Sql(val value: String)
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package com.thoughtworks.archguard.git.scanner

import com.thoughtworks.archguard.git.scanner.helper.Bean2Sql
import java.io.File
import java.util.*

/*
* core scanner
Expand All @@ -11,14 +12,25 @@ class ScannerService(private val gitAdapter: JGitAdapter,
private val bean2Sql: Bean2Sql) {

fun git2SqlFile(gitPath: String, branch: String, after: String, repoId: String, systemId: Long) {
val result = gitAdapter.scan(gitPath, branch, after, repoId, systemId)
val (commitLogs, changeEntries) = gitAdapter.scan(gitPath, branch, after, repoId, systemId)
val file = File("output.sql")
if (file.exists()) {
file.delete()
}

file.appendText(result.first.joinToString("\n") { bean2Sql.bean2Sql(it) })
file.appendText(result.second.joinToString("\n") { bean2Sql.bean2Sql(it) })
}
val counts = gitAdapter.countChangesByPath(changeEntries)
val pathChanges: MutableList<PathChangeCount> = mutableListOf()
counts.forEach {
pathChanges += PathChangeCount(
UUID.randomUUID().toString(),
it.key,
it.value,
systemId
)
}

file.appendText(commitLogs.joinToString("\n") { bean2Sql.bean2Sql(it) })
file.appendText(changeEntries.joinToString("\n") { bean2Sql.bean2Sql(it) })
file.appendText(pathChanges.joinToString("\n") { bean2Sql.bean2Sql(it) })
}
}

0 comments on commit 3def653

Please sign in to comment.