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

Commit

Permalink
feat: try to fix file type issues
Browse files Browse the repository at this point in the history
  • Loading branch information
phodal committed Mar 23, 2022
1 parent 4606c64 commit 96f6648
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,28 @@ package com.thoughtworks.archguard.git.scanner

import java.io.File
import java.nio.file.Files
import kotlin.io.path.isReadable

val TEN_MB = 10 * 1024 * 1024

class LineCounter {
companion object {
fun byPath(path: String): Long {
val file = File(path).toPath()
if(!file.isReadable()) {
println("Error path: $path")
return 0
}

return try {
val file = File(path)
val size = Files.size(file.toPath())
val size = Files.size(file)
if (size < TEN_MB) {
Files.lines(file.toPath()).count()
Files.lines(file).count()
} else {
0
}
} catch (e: Exception) {
println("Error path: $path")
e.printStackTrace()
0
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class ScannerService(private val gitAdapter: JGitAdapter,
val counts = gitAdapter.countChangesByPath(changeEntries)
val pathChanges: MutableList<PathChangeCount> = mutableListOf()
counts.forEach {
val lineCounts = LineCounter.byPath(it.key)
val lineCounts = LineCounter.byPath(arrayOf(File(gitPath).absolutePath, it.key).joinToString(File.separator))
pathChanges += PathChangeCount(
UUID.randomUUID().toString(),
it.key,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package com.thoughtworks.archguard.git.scanner
import com.thoughtworks.archguard.git.scanner.complexity.CognitiveComplexityParser
import org.junit.jupiter.api.Disabled
import org.junit.jupiter.api.Test
import java.io.File
import java.nio.file.Paths

internal class JGitAdapterTest {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package com.thoughtworks.archguard.git.scanner

import com.thoughtworks.archguard.git.scanner.complexity.CognitiveComplexityParser
import com.thoughtworks.archguard.git.scanner.helper.Bean2Sql
import org.junit.jupiter.api.Test

import org.junit.jupiter.api.Assertions.*

internal class ScannerServiceTest {

@Test
fun should_generate_sql_file_from_git() {
val jGitAdapter = JGitAdapter(CognitiveComplexityParser())
val scannerService = ScannerService(jGitAdapter, Bean2Sql())
scannerService.git2SqlFile("../../archguard-fe", "master", "0", "0", 1)
}
}

0 comments on commit 96f6648

Please sign in to comment.