Skip to content

Commit

Permalink
feat(unittest): enable get SCA from context
Browse files Browse the repository at this point in the history
  • Loading branch information
phodal committed Dec 22, 2023
1 parent b37552c commit 5c64dcc
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 1 deletion.
1 change: 1 addition & 0 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ chapi-typescript = { group = "com.phodal.chapi", name = "chapi-ast-typescript",
archguard-scanner-core = { group = "org.archguard.scanner", name = "scanner_core", version.ref = "archguard" }
archguard-lang-kotlin = { group = "org.archguard.scanner", name = "lang_kotlin", version.ref = "archguard" }
archguard-analyser-estimate = { group = "org.archguard.scanner", name = "analyser_estimate", version.ref = "archguard" }
archguard-analyser-sca = { group = "org.archguard.scanner", name = "analyser_sca", version.ref = "archguard" }

# ArchGuard Rule Linter
archguard-rule-core = { group = "org.archguard.scanner", name = "rule-core", version.ref = "archguard" }
Expand Down
1 change: 1 addition & 0 deletions unit-picker/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ dependencies {

implementation(libs.archguard.scanner.core)
implementation(libs.archguard.analyser.estimate)
implementation(libs.archguard.analyser.sca)

// checkout
implementation(libs.codedb.checkout)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,8 @@ class SingleProjectCodePicker(private val config: InsPickerOption) {
)
)
)
workerManager.init(codeDir, config.language)

val walkdirChannel = Channel<FileJob>()
val summary = mutableListOf<Instruction>()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ class JavaSimilarChunker(private val fileTree: HashMap<String, InstructionFileJo

// take the first 3 similar chunks or empty
val similarChunksText = if (similarChunks.size > 3) {
println("score: ${similarChunks.map { it.first }}")
similarChunks.take(3).map { it.second }
} else {
similarChunks.map { it.second }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import cc.unitmesh.core.completion.CompletionBuilderType
import cc.unitmesh.pick.option.InsQualityThreshold
import cc.unitmesh.quality.CodeQualityType
import kotlinx.serialization.Serializable
import org.archguard.scanner.core.sca.CompositionDependency

@Serializable
data class WorkerContext(
Expand All @@ -17,5 +18,6 @@ data class WorkerContext(
val maxCompletionInOneFile: Int,
val completionTypeSize: Int,
val insQualityThreshold: InsQualityThreshold = InsQualityThreshold(),
var compositionDependency: List<CompositionDependency> = listOf()
)

Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,13 @@ import cc.unitmesh.core.Instruction
import cc.unitmesh.pick.worker.lang.JavaWorker
import cc.unitmesh.pick.worker.base.LangWorker
import org.archguard.rule.common.Language
import org.archguard.scanner.analyser.ScaAnalyser
import org.archguard.scanner.analyser.count.LanguageService
import org.archguard.scanner.core.client.ArchGuardClient
import org.archguard.scanner.core.client.EmptyArchGuardClient
import org.archguard.scanner.core.sca.ScaContext
import org.slf4j.Logger
import java.io.File


class WorkerManager(private val workerContext: WorkerContext) {
Expand All @@ -24,6 +29,29 @@ class WorkerManager(private val workerContext: WorkerContext) {

private val logger: Logger = org.slf4j.LoggerFactory.getLogger(WorkerManager::class.java)

/**
* Initializes the project by scanning the specified code directory to retrieve the dependencies.
*
* @param codeDir The directory where the project code is stored.
* @param language The programming language used in the project.
*
*/
fun init(codeDir: File, language: String) {
val dependencies = ScaAnalyser(object : ScaContext {
override val client: ArchGuardClient = EmptyArchGuardClient()
override val language: String = language
override val path: String = codeDir.absolutePath
}).analyse()

if (dependencies.isEmpty()) {
logger.warn("no dependencies found in $codeDir")
} else {
logger.info("found ${dependencies.size} dependencies in $codeDir")
}

workerContext.compositionDependency = dependencies
}

fun addJobByThreshold(job: InstructionFileJob) {
val summary = job.fileSummary
if (!supportedExtensions.contains(summary.extension)) {
Expand Down

0 comments on commit 5c64dcc

Please sign in to comment.