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

Commit

Permalink
feat(dep): add scope for maven
Browse files Browse the repository at this point in the history
  • Loading branch information
phodal committed Apr 21, 2022
1 parent f3a96a5 commit 6cacdab
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 4 deletions.
@@ -1,6 +1,7 @@
package org.archguard.scanner.dep.datafinder

import org.archguard.scanner.dep.common.Finder
import org.archguard.scanner.dep.model.DEP_SCOPE
import org.archguard.scanner.dep.model.DeclFile
import org.archguard.scanner.dep.model.DepDecl
import org.archguard.scanner.dep.model.DepDependency
Expand All @@ -26,7 +27,6 @@ class MavenFinder : Finder() {
val artifactId = xPath.compile("/project/artifactId").evaluate(xmlDocument, XPathConstants.STRING)
val version = xPath.compile("/project/version").evaluate(xmlDocument, XPathConstants.STRING)


return listOf(
DepDecl(
name = "$groupId:$artifactId",
Expand All @@ -45,12 +45,14 @@ class MavenFinder : Finder() {
val item: Element = nodeList.item(i) as Element
val groupId = xPath.evaluate("groupId", item) ?: ""
val artifact = xPath.evaluate("artifactId", item) ?: ""
val scope = xPath.evaluate("scope", item) ?: ""

DepDependency(
name = "$groupId:$artifact",
group = listOf(groupId),
artifact = artifact,
version = xPath.evaluate("version", item) ?: ""
version = xPath.evaluate("version", item) ?: "",
scope = DEP_SCOPE.from(scope)
)
}.toList()
}
Expand Down
Expand Up @@ -25,7 +25,20 @@ class DepDecl(

enum class DEP_SCOPE {
NORMAL,
TEST
TEST;

companion object {
fun from(str: String): DEP_SCOPE {
when(str) {
"test" -> {
return DEP_SCOPE.TEST
}
else -> {
return DEP_SCOPE.NORMAL
}
}
}
}
}

class DepDependency(
Expand Down
@@ -1,6 +1,8 @@
package org.archguard.scanner.dep.datafinder

import org.archguard.scanner.dep.model.DEP_SCOPE
import org.archguard.scanner.dep.model.DeclFile
import org.archguard.scanner.dep.model.DepSource
import org.junit.jupiter.api.Test
import kotlin.test.assertEquals

Expand Down Expand Up @@ -49,8 +51,16 @@ internal class MavenFinderTest {
val declFile = DeclFile("archguard", "pom.xml", sampleXml)
val lookupSource = MavenFinder().lookupSource(declFile)

val dependencies = lookupSource[0].dependencies
assertEquals("com.mycompany.app:my-app", lookupSource[0].name)
assertEquals("1.0-SNAPSHOT", lookupSource[0].version)
}

@Test
internal fun should_parse_scope() {
val declFile = DeclFile("archguard", "pom.xml", sampleXml)
val lookupSource = MavenFinder().lookupSource(declFile)

val dependencies = lookupSource[0].dependencies
assertEquals(DEP_SCOPE.TEST, dependencies[0].scope)
}
}

0 comments on commit 6cacdab

Please sign in to comment.