Skip to content

Commit ab7f9c3

Browse files
author
Denis Mikhaylov
committed
Improve detection of a changed project
1 parent 95dc8ac commit ab7f9c3

File tree

3 files changed

+21
-12
lines changed

3 files changed

+21
-12
lines changed

src/main/scala/com/elarib/PartialSbtPlugin.scala

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@ package com.elarib
22

33
import com.elarib.model.{ChangeGetter, PartialSbParser}
44
import org.apache.logging.log4j.LogManager
5-
import sbt.Keys._
5+
import sbt.*
6+
import sbt.Keys.*
67
import sbt.internal.BuildDependencies.DependencyMap
7-
import sbt._
88

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

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

115-
val modulesToBuild: Seq[ResolvedProject] = modulesWithPath
116-
.filter { case (_, resolvedProject) =>
117-
diffsFiles.exists(file => file.getAbsolutePath.contains(resolvedProject.base.getAbsolutePath))
118-
}
115+
def findContainingProject(file: File): Option[(ProjectRef, ResolvedProject)] =
116+
modulesWithPath
117+
.filter { case (_, resolvedProject) =>
118+
file.getAbsolutePath.contains(resolvedProject.base.getAbsolutePath)
119+
}
120+
.sortBy(_._2.base.getAbsolutePath.length)
121+
.lastOption
122+
123+
diffsFiles
124+
.flatMap(findContainingProject)
125+
.distinct
119126
.flatMap { case (projectRef, resolvedProject) =>
120127
reverseDependencyMap
121128
.get(projectRef)
@@ -124,8 +131,6 @@ object PartialSbtPlugin extends AutoPlugin {
124131
}
125132
.distinct
126133
.sortBy(_.id)
127-
128-
modulesToBuild
129134
}
130135

131136
}
@@ -162,5 +167,4 @@ object PartialSbtPlugin extends AutoPlugin {
162167
else
163168
file.getCanonicalPath == ef.getCanonicalPath
164169
}
165-
166170
}

src/sbt-test/test-projects/multi-module-project/build.sbt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,10 @@ lazy val secondLib = sbt
8383
.settings(com.elarib.BuildKeys.partialSbtOpaqueProject := ())
8484

8585
//Tools
86+
lazy val toolsProject = sbt
87+
.Project("tools", tools)
88+
.settings(settings("tools"))
89+
8690
lazy val firstTool = sbt
8791
.Project("tool-1", tools / "tool-1")
8892
.dependsOn(firstLib)
Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
Metabuild files have changed. Need to reload all the 10 projects
2-
10 projects have been changed
1+
Metabuild files have changed. Need to reload all the 11 projects
2+
11 projects have been changed
33
lib-1
44
lib-2
55
multi-module-project
@@ -9,4 +9,5 @@ service-3
99
service-4
1010
tool-1
1111
tool-2
12-
tool-3
12+
tool-3
13+
tools

0 commit comments

Comments
 (0)