Skip to content

Commit

Permalink
Improve detection of a changed project
Browse files Browse the repository at this point in the history
  • Loading branch information
Denis Mikhaylov committed Aug 6, 2024
1 parent 95dc8ac commit 91fb032
Showing 1 changed file with 13 additions and 9 deletions.
22 changes: 13 additions & 9 deletions src/main/scala/com/elarib/PartialSbtPlugin.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ package com.elarib

import com.elarib.model.{ChangeGetter, PartialSbParser}
import org.apache.logging.log4j.LogManager
import sbt.Keys._
import sbt.*
import sbt.Keys.*
import sbt.internal.BuildDependencies.DependencyMap
import sbt._

object BuildKeys {
val partialSbtExcludedFiles = sbt.settingKey[Seq[sbt.File]]("Files that should be excluded from analysis.")
Expand Down Expand Up @@ -112,10 +112,17 @@ object PartialSbtPlugin extends AutoPlugin {

val diffsFiles: Seq[sbt.File] = changeGetter.changes.filterNot(f => isFileExcluded(baseDir)(f, excludedFiles))

val modulesToBuild: Seq[ResolvedProject] = modulesWithPath
.filter { case (_, resolvedProject) =>
diffsFiles.exists(file => file.getAbsolutePath.contains(resolvedProject.base.getAbsolutePath))
}
def findContainingProject(file: File): Option[(ProjectRef, ResolvedProject)] =
modulesWithPath
.filter { case (_, resolvedProject) =>
file.getAbsolutePath.contains(resolvedProject.base.getAbsolutePath)
}
.sortBy(_._2.base.getAbsolutePath.length)
.lastOption

diffsFiles
.flatMap(findContainingProject)
.distinct
.flatMap { case (projectRef, resolvedProject) =>
reverseDependencyMap
.get(projectRef)
Expand All @@ -124,8 +131,6 @@ object PartialSbtPlugin extends AutoPlugin {
}
.distinct
.sortBy(_.id)

modulesToBuild
}

}
Expand Down Expand Up @@ -162,5 +167,4 @@ object PartialSbtPlugin extends AutoPlugin {
else
file.getCanonicalPath == ef.getCanonicalPath
}

}

0 comments on commit 91fb032

Please sign in to comment.