Skip to content

Commit

Permalink
optimized code
Browse files Browse the repository at this point in the history
Signed-off-by: JingZhang Chen <iRoiocam@gmail.com>
  • Loading branch information
Roiocam committed Jan 29, 2024
1 parent 798ecaf commit e608c8b
Showing 1 changed file with 13 additions and 29 deletions.
42 changes: 13 additions & 29 deletions src/main/scala/io/github/roiocam/DependWalkerPlugin.scala
Original file line number Diff line number Diff line change
Expand Up @@ -27,26 +27,14 @@ object DependWalkerPlugin extends AutoPlugin {
* @param currentProject
* @return
*/
def scopedKeyIsMatch(
currentKey: ScopedKey[_],
executeTaskMatcher: ScopeKeyMatcher,
currentProject: ProjectRef
): Boolean = {
val predicate: (ScopedKey[_], ScopedKey[_]) => Boolean = (sk, vk) =>
executeTaskMatcher.mode match {
case CheckConfig => sk.scope.config == vk.scope.config
case CheckTask => sk.key == vk.key
case CheckBoth => sk.key == vk.key && sk.scope.config == vk.scope.config
case _ => false
}

currentKey.scope.project match {
case Select(projectRef) =>
projectRef == currentProject && predicate(
currentKey,
executeTaskMatcher.key
)
case _ => false
def scopedKeyIsMatch(sk: ScopedKey[_], matcher: ScopeKeyMatcher): Boolean = {
val expectConfig = matcher.key.scope.config
val expectKey = matcher.key.key
matcher.mode match {
case CheckConfig => sk.scope.config == expectConfig
case CheckTask => sk.key == expectKey
case CheckBoth => sk.key == expectKey && sk.scope.config == expectConfig
case _ => false
}
}

Expand All @@ -59,12 +47,9 @@ object DependWalkerPlugin extends AutoPlugin {
def dependWalk(
dependencies: Set[_ <: ScopedKey[_]],
expectDependMatcher: ScopeKeyMatcher
)(implicit
cMap: Map[Def.ScopedKey[_], Def.Flattened],
currentProject: ProjectRef
): Boolean = {
)(implicit cMap: Map[Def.ScopedKey[_], Def.Flattened]): Boolean = {
dependencies.exists { sk =>
scopedKeyIsMatch(sk, expectDependMatcher, currentProject) match {
scopedKeyIsMatch(sk, expectDependMatcher) match {
case true => true
case false =>
cMap.get(sk).exists { flattened =>
Expand Down Expand Up @@ -92,10 +77,9 @@ object DependWalkerPlugin extends AutoPlugin {
)(implicit cMap: Map[Def.ScopedKey[_], Def.Flattened]): Unit = {
val executeTaskOnCurrentProject = cMap.collect {
case (currentKey, _)
if scopedKeyIsMatch(
if currentKey.scope.project.isSelect && scopedKeyIsMatch(
currentKey,
walkTask.executeTask,
currentProject
walkTask.executeTask
) =>
currentKey
}
Expand All @@ -105,7 +89,7 @@ object DependWalkerPlugin extends AutoPlugin {
case Some(c) => c.dependencies.toSet;
case None => Set.empty
}
if (dependWalk(depends, walkTask.expectDepend)(cMap, currentProject)) {
if (dependWalk(depends, walkTask.expectDepend)) {
println(
s"Depend verified in the tree of ${currentProject.project} / ${key.scope.config} / ${key.key}"
)
Expand Down

0 comments on commit e608c8b

Please sign in to comment.