-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: parepare for library as context
- Loading branch information
Showing
5 changed files
with
158 additions
and
28 deletions.
There are no files selected for viewing
23 changes: 23 additions & 0 deletions
23
unit-picker/src/main/kotlin/cc/unitmesh/pick/ext/CompositionDependencyExt.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package cc.unitmesh.pick.ext | ||
|
||
import org.archguard.scanner.core.sca.CompositionDependency | ||
|
||
fun CompositionDependency.Companion.from( | ||
name: String, | ||
group: String, | ||
artifactId: String, | ||
): CompositionDependency { | ||
return CompositionDependency( | ||
name = name, | ||
depName = name, | ||
depGroup = group, | ||
depArtifact = artifactId, | ||
packageManager = "", | ||
depVersion = "", | ||
version = "", | ||
path = "", | ||
depScope = "", | ||
id = "", | ||
parentId = "", | ||
) | ||
} |
61 changes: 61 additions & 0 deletions
61
unit-picker/src/main/kotlin/cc/unitmesh/pick/project/ProjectLibrary.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
package cc.unitmesh.pick.project | ||
|
||
import org.archguard.scanner.core.sca.CompositionDependency | ||
|
||
object ProjectLibrary { | ||
/** | ||
* | ||
* ```kotlin | ||
* | ||
* | ||
*/ | ||
fun prepare(deps: List<CompositionDependency>): TestStack { | ||
val testStack = TestStack() | ||
var hasMatchSpringMvc = false | ||
var hasMatchSpringData = false | ||
|
||
deps.forEach { dep -> | ||
SpringLibrary.SPRING_MVC.forEach { | ||
it.coords.forEach { coord -> | ||
if (dep.name.contains(coord)) { | ||
testStack.coreFrameworks.putIfAbsent(it.shortText, true) | ||
hasMatchSpringMvc = true | ||
} | ||
} | ||
} | ||
|
||
SpringLibrary.SPRING_DATA.forEach { | ||
it.coords.forEach { coord -> | ||
if (dep.name.contains(coord)) { | ||
testStack.coreFrameworks.putIfAbsent(it.shortText, true) | ||
hasMatchSpringData = true | ||
} | ||
} | ||
} | ||
|
||
when { | ||
dep.name.contains("org.springframework.boot:spring-boot-test") -> { | ||
testStack.testFrameworks.putIfAbsent("Spring Boot Test", true) | ||
} | ||
|
||
dep.name.contains("org.assertj:assertj-core") -> { | ||
testStack.testFrameworks.putIfAbsent("AssertJ", true) | ||
} | ||
|
||
dep.name.contains("org.junit.jupiter:junit-jupiter") -> { | ||
testStack.testFrameworks.putIfAbsent("JUnit 5", true) | ||
} | ||
|
||
dep.name.contains("org.mockito:mockito-core") -> { | ||
testStack.testFrameworks.putIfAbsent("Mockito", true) | ||
} | ||
|
||
dep.name.contains("com.h2database:h2") -> { | ||
testStack.testFrameworks.putIfAbsent("H2", true) | ||
} | ||
} | ||
} | ||
|
||
return testStack | ||
} | ||
} |
45 changes: 45 additions & 0 deletions
45
unit-picker/src/main/kotlin/cc/unitmesh/pick/project/SpringLibrary.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package cc.unitmesh.pick.project | ||
|
||
data class SpringDataLibraryDescriptor(val shortText: String, val coords: List<String>) | ||
data class LibraryDescriptor(val shortText: String, val coords: String) | ||
|
||
object SpringLibrary { | ||
// Spring | ||
private val SPRING_MVC_MAVEN = "org.springframework:spring-webmvc" | ||
private val SPRING_WEBFLUX_MAVEN = "org.springframework:spring-webflux" | ||
|
||
// Spring Data | ||
private val REACTOR_MAVEN = "io.projectreactor:reactor-core" | ||
private val MONGO_REACTIVE_STREAMS_MAVEN = "org.mongodb:mongodb-driver-reactivestreams" | ||
private val SPRING_DATA_COMMONS_MAVEN = "org.springframework.data:spring-data-commons" | ||
private val JPA_MAVEN = "org.springframework.data:spring-data-jpa" | ||
private val CASSANDRA_MAVEN = "org.springframework.data:spring-data-cassandra" | ||
private val COUCHBASE_MAVEN = "org.springframework.data:spring-data-couchbase" | ||
private val JDBC_MAVEN = "org.springframework.data:spring-data-jdbc" | ||
private val MONGO_MAVEN = "org.springframework.data:spring-data-mongodb" | ||
private val NEO4J_MAVEN = "org.springframework.data:spring-data-neo4j" | ||
private val R2DBC_MAVEN = "org.springframework.data:spring-data-r2dbc" | ||
private val REDIS_MAVEN = "org.springframework.data:spring-data-redis" | ||
|
||
val SPRING_DATA = listOf( | ||
SpringDataLibraryDescriptor("JPA ", listOf(JPA_MAVEN)), | ||
SpringDataLibraryDescriptor("CASSANDRA", listOf(CASSANDRA_MAVEN)), | ||
SpringDataLibraryDescriptor("REACTIVE CASSANDRA", listOf(CASSANDRA_MAVEN, REACTOR_MAVEN)), | ||
SpringDataLibraryDescriptor("COUCHBASE", listOf(COUCHBASE_MAVEN)), | ||
SpringDataLibraryDescriptor("REACTIVE COUCHBASE", listOf(COUCHBASE_MAVEN, REACTOR_MAVEN)), | ||
SpringDataLibraryDescriptor("JDBC", listOf(JDBC_MAVEN)), | ||
SpringDataLibraryDescriptor("MONGO", listOf(MONGO_MAVEN)), | ||
SpringDataLibraryDescriptor( | ||
"REACTIVE MONGO", | ||
listOf(MONGO_MAVEN, REACTOR_MAVEN, MONGO_REACTIVE_STREAMS_MAVEN) | ||
), | ||
SpringDataLibraryDescriptor("NEO4J", listOf(NEO4J_MAVEN)), | ||
SpringDataLibraryDescriptor("R2DBC", listOf(R2DBC_MAVEN)), | ||
SpringDataLibraryDescriptor("REDIS", listOf(REDIS_MAVEN)) | ||
) | ||
|
||
val SPRING_MVC = listOf( | ||
LibraryDescriptor("Spring MVC", SPRING_MVC_MAVEN), | ||
LibraryDescriptor("Spring WebFlux", SPRING_WEBFLUX_MAVEN) | ||
) | ||
} |
19 changes: 19 additions & 0 deletions
19
unit-picker/src/main/kotlin/cc/unitmesh/pick/project/TestStack.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package cc.unitmesh.pick.project | ||
|
||
/** | ||
* TODO: change to dependency tree | ||
*/ | ||
data class TestStack( | ||
val coreFrameworks: MutableMap<String, Boolean> = mutableMapOf(), | ||
val testFrameworks: MutableMap<String, Boolean> = mutableMapOf(), | ||
val deps: MutableMap<String, String> = mutableMapOf(), | ||
val devDeps: MutableMap<String, String> = mutableMapOf() | ||
) { | ||
fun coreFrameworks(): String { | ||
return coreFrameworks.keys.joinToString(", ") | ||
} | ||
|
||
fun testFrameworks(): String { | ||
return testFrameworks.keys.joinToString(", ") | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters