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 ab7f9c3
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 12 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
}

}
4 changes: 4 additions & 0 deletions src/sbt-test/test-projects/multi-module-project/build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,10 @@ lazy val secondLib = sbt
.settings(com.elarib.BuildKeys.partialSbtOpaqueProject := ())

//Tools
lazy val toolsProject = sbt
.Project("tools", tools)
.settings(settings("tools"))

lazy val firstTool = sbt
.Project("tool-1", tools / "tool-1")
.dependsOn(firstLib)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
Metabuild files have changed. Need to reload all the 10 projects
10 projects have been changed
Metabuild files have changed. Need to reload all the 11 projects
11 projects have been changed
lib-1
lib-2
multi-module-project
Expand All @@ -9,4 +9,5 @@ service-3
service-4
tool-1
tool-2
tool-3
tool-3
tools

0 comments on commit ab7f9c3

Please sign in to comment.