Skip to content

Commit

Permalink
HYDRA-2663: Ignore test sources in changedProjectsInCompile (#9)
Browse files Browse the repository at this point in the history
  • Loading branch information
notxcain authored Aug 12, 2024
1 parent 6c598b4 commit 2f44446
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 6 deletions.
21 changes: 16 additions & 5 deletions src/main/scala/com/elarib/PartialSbtPlugin.scala
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@ object PartialSbtPlugin extends AutoPlugin {
baseDirectory: File,
loadedBuild: LoadedBuild,
partialSbtExcludedFiles: Seq[File],
dependencyFilter: ClasspathDep[ProjectRef] => Boolean
dependencyFilter: ClasspathDep[ProjectRef] => Boolean,
excludeTestFiles: Boolean
) =
Command(name)(_ => PartialSbParser.changeGetterParser)((st, changeGetter) => {

Expand All @@ -62,7 +63,8 @@ object PartialSbtPlugin extends AutoPlugin {
baseDirectory,
loadedBuild.allProjectRefs,
transitiveCompileDependencyMap,
partialSbtExcludedFiles
partialSbtExcludedFiles,
excludeTestFiles
)

logger.debug(s"${changedProjects.size} projects have been changed")
Expand Down Expand Up @@ -91,22 +93,25 @@ object PartialSbtPlugin extends AutoPlugin {
baseDirectory.value,
loadedBuild.value,
BuildKeys.partialSbtExcludedFiles.value,
Function.const(true)
Function.const(true),
excludeTestFiles = false
),
commands += changedProjectsCommand("changedProjectsInCompile")(
buildDependencies.value,
baseDirectory.value,
loadedBuild.value,
BuildKeys.partialSbtExcludedFiles.value,
hasCompileConfiguration
hasCompileConfiguration,
excludeTestFiles = true
)
)

private def findChangedModules(changeGetter: ChangeGetter)(
baseDir: sbt.File,
allProjectRefs: Seq[(ProjectRef, ResolvedProject)],
buildDeps: DependencyMap[ProjectRef],
excludedFiles: Seq[sbt.File]
excludedFiles: Seq[sbt.File],
excludeTestFiles: Boolean
): Seq[ResolvedProject] = {

val projectMap: Map[ProjectRef, ResolvedProject] = allProjectRefs.toMap
Expand Down Expand Up @@ -144,13 +149,19 @@ object PartialSbtPlugin extends AutoPlugin {

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

def isExcludedTestFile(file: sbt.File, resolvedProject: ResolvedProject): Boolean =
excludeTestFiles && file.getAbsolutePath.startsWith((resolvedProject.base / "src" / "test").getAbsolutePath)

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

diffsFiles
.flatMap(findContainingProject)
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
src/libs/testKit/build.sbt
src/libs/testKit/build.sbt
src/libs/lib-1/src/test/scala/Test.scala

0 comments on commit 2f44446

Please sign in to comment.