Skip to content

Commit

Permalink
chore: init basic api check for rule
Browse files Browse the repository at this point in the history
  • Loading branch information
phodal committed Dec 7, 2023
1 parent 24849af commit 96170aa
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,22 @@
package cc.unitmesh.quality

import org.archguard.linter.rule.sql.DatamapRuleVisitor
import org.archguard.linter.rule.sql.SqlRuleSetProvider
import org.archguard.linter.rule.webapi.WebApiRuleSetProvider
import org.archguard.linter.rule.webapi.WebApiRuleVisitor
import org.archguard.rule.core.Issue
import org.archguard.scanner.core.sourcecode.CodeDatabaseRelation
import org.archguard.scanner.core.sourcecode.ContainerService

class ExtRuleAnalyser {
// check with WebAPI, SQL or Other rule by ArchGuard
val webApiRuleSetProvider = WebApiRuleSetProvider()
val sqlRuleSetProvider = SqlRuleSetProvider()

fun checkApi(services: List<ContainerService>): List<Issue> {
return WebApiRuleVisitor(services).visitor(listOf(webApiRuleSetProvider.get()))
}

fun checkSql(relations: List<CodeDatabaseRelation>): List<Issue> {
return DatamapRuleVisitor(relations).visitor(listOf(sqlRuleSetProvider.get()))
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,14 @@ class JavaLangWorker : LangWorker() {
this.jobs.add(job)
val code = job.fileSummary.content.decodeToString()
tryAddClassToTree(code, job)

job.container = JavaAnalyser().analysis(code, job.fileSummary.location)
}

private fun tryAddClassToTree(code: String, job: PickJob) {
val packageMatch = packageRegex.find(code)
if (packageMatch != null) {
val packageName = packageMatch.groupValues[1]
// in Java the filename is the class name
val className = job.fileSummary.filename.substring(0, job.fileSummary.filename.length - extLength)
val fullClassName = "$packageName.$className"
packageTree[fullClassName] = job
Expand All @@ -48,7 +48,7 @@ class JavaLangWorker : LangWorker() {
override suspend fun start(): List<Instruction> = coroutineScope {
// 1. read directory to a collection of files for FileJob
jobs.map {
println(it.container)

}

// 2. check package information from line 1?
Expand Down

0 comments on commit 96170aa

Please sign in to comment.