Skip to content

Commit

Permalink
Support exclusion of certain projects from analysis
Browse files Browse the repository at this point in the history
  • Loading branch information
Denis Mikhaylov committed Aug 6, 2024
1 parent 8655e7f commit 4305612
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 7 deletions.
13 changes: 11 additions & 2 deletions src/main/scala/com/elarib/PartialSbtPlugin.scala
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import sbt._

object BuildKeys {
val partialSbtExcludedFiles = sbt.settingKey[Seq[sbt.File]]("Files that should be excluded from analysis.")
val partialSbtExcludedProject: SettingKey[Unit] = sbt.settingKey[Unit]("Exclude project from analysis.")
}

object PartialSbtPlugin extends AutoPlugin {
Expand Down Expand Up @@ -50,6 +51,7 @@ object PartialSbtPlugin extends AutoPlugin {
st
}),
commands += Command("changedProjects")(_ => PartialSbParser.changeGetterParser)((st, changeGetter) => {

val changedProjects: Seq[ResolvedProject] =
findChangedModules(changeGetter)(
baseDirectory.value,
Expand Down Expand Up @@ -82,6 +84,9 @@ object PartialSbtPlugin extends AutoPlugin {
projectMap.values.toSeq
.sortBy(_.id)
case Nil =>
def isIncludedInAnalysis(resolvedProject: ResolvedProject): Boolean =
!resolvedProject.settings.exists(_.key.key == BuildKeys.partialSbtExcludedProject.key)

val reverseDependencyMap: DependencyMap[ResolvedProject] = buildDeps
.foldLeft[DependencyMap[ResolvedProject]](Map.empty) { (acc, dependency) =>
val (ref, dependsOnList) = dependency
Expand All @@ -94,11 +99,15 @@ object PartialSbtPlugin extends AutoPlugin {
.fold(resolvedProjects)(_ +: resolvedProjects)
dependencyMap + (key -> newValue)
}

}
.filterKeys { projectRef =>
projectMap.get(projectRef).exists(isIncludedInAnalysis)
}

val modulesWithPath: Seq[(ProjectRef, ResolvedProject)] =
allProjectRefs.filter(_._2.base != baseDir)
allProjectRefs.filter { case (_, resolvedProject) =>
isIncludedInAnalysis(resolvedProject) && resolvedProject.base != baseDir
}

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

Expand Down
3 changes: 2 additions & 1 deletion src/sbt-test/test-projects/multi-module-project/build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ commands += Command("addEnvVar")(_ => sbt.internal.util.complete.Parsers.spaceDe
// Projects
// +-----------+ +-----------+
// | | | |
// | lib-1 +<---------+ +--------->+ lib-2 |
// | lib-1 +<---------+ +--------->+ lib-2 (X) |
// | | | | | |
// +-----^-----+ | | +---+-------+
// | | | ^
Expand Down Expand Up @@ -80,6 +80,7 @@ lazy val firstLib = sbt
lazy val secondLib = sbt
.Project("lib-2", libs / "lib-2")
.settings(settings("lib-2"))
.settings(com.elarib.BuildKeys.partialSbtExcludedProject := ())

//Tools
lazy val firstTool = sbt
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
9 projects have been changed
6 projects have been changed
lib-1
lib-2
service-1
service-2
service-3
service-4
tool-1
tool-2
tool-3

0 comments on commit 4305612

Please sign in to comment.