Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
package com.dropbox.affectedmoduledetector

import com.dropbox.affectedmoduledetector.commitshaproviders.CommitShaProvider
import com.dropbox.affectedmoduledetector.commitshaproviders.ForkCommit
import com.dropbox.affectedmoduledetector.commitshaproviders.PreviousCommit
import com.dropbox.affectedmoduledetector.commitshaproviders.SpecifiedBranchCommit
import com.dropbox.affectedmoduledetector.commitshaproviders.SpecifiedBranchCommitMergeBase
import com.dropbox.affectedmoduledetector.commitshaproviders.SpecifiedRawCommitSha
import com.dropbox.affectedmoduledetector.util.toOsSpecificPath
import com.dropbox.affectedmoduledetector.vcs.BaseVcsClientProvider
import com.dropbox.affectedmoduledetector.vcs.GitClientProviderImpl
import java.io.File
import java.io.Serializable

Expand Down Expand Up @@ -80,6 +88,10 @@ class AffectedModuleConfiguration : Serializable {
return field
}

var commitShaProvider: CommitShaProvider = PreviousCommit()

var vcsClientProvider: BaseVcsClientProvider = GitClientProviderImpl()

var specifiedBranch: String? = null

var specifiedRawCommitSha: String? = null
Expand All @@ -100,11 +112,22 @@ class AffectedModuleConfiguration : Serializable {
requireNotNull(specifiedBranch) {
"Specify a branch using the configuration specifiedBranch"
}
when (value) {
"SpecifiedBranchCommit" -> commitShaProvider = SpecifiedBranchCommit(specifiedBranch!!)
"SpecifiedBranchCommitMergeBase" -> commitShaProvider = SpecifiedBranchCommitMergeBase(specifiedBranch!!)
}
}
if (value == "SpecifiedRawCommitSha") {
requireNotNull(specifiedRawCommitSha) {
"Provide a Commit SHA for the specifiedRawCommitSha property when using SpecifiedRawCommitSha comparison strategy."
}
commitShaProvider = SpecifiedRawCommitSha(specifiedRawCommitSha!!)
}
if (value == "PreviousCommit") {
commitShaProvider = PreviousCommit()
}
if (value == "ForkCommit") {
commitShaProvider = ForkCommit()
}
field = value
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -200,17 +200,15 @@ abstract class AffectedModuleDetector(protected val logger: Logger?) {
rootProject
)

val gitClient = GitClientImpl(
val vcsClient = config.vcsClientProvider.get(
rootProject.projectDir,
logger,
commitShaProviderConfiguration = CommitShaProviderConfiguration(
type = config.compareFrom,
specifiedBranch = config.specifiedBranch,
specifiedSha = config.specifiedRawCommitSha,
CommitShaProviderConfiguration(
provider = config.commitShaProvider,
top = config.top,
includeUncommitted = config.includeUncommitted
),
ignoredFiles = config.ignoredFiles
config.ignoredFiles,
)

logger.lifecycle("projects evaluated")
Expand All @@ -226,8 +224,8 @@ abstract class AffectedModuleDetector(protected val logger: Logger?) {
parameters.projectSubset = subset
parameters.modules = modules
parameters.config = config
parameters.gitChangedFilesProvider = gitClient.findChangedFiles(rootProject)
parameters.gitRoot.set(gitClient.getGitRoot())
parameters.changedFilesProvider = vcsClient.findChangedFiles(rootProject)
parameters.vcsRoot.set(vcsClient.getVcsRoot())
}
logger.info("Using real detector with $subset")
instance.wrapped = provider
Expand Down Expand Up @@ -409,9 +407,9 @@ abstract class AffectedModuleDetectorLoader :
var ignoreUnknownProjects: Boolean
var projectSubset: ProjectSubset
var modules: Set<String>?
var gitChangedFilesProvider: Provider<List<String>>
var changedFilesProvider: Provider<List<String>>
var config: AffectedModuleConfiguration
val gitRoot: DirectoryProperty
val vcsRoot: DirectoryProperty
}

val detector: AffectedModuleDetector by lazy {
Expand All @@ -427,8 +425,8 @@ abstract class AffectedModuleDetectorLoader :
projectSubset = parameters.projectSubset,
modules = parameters.modules,
config = parameters.config,
changedFilesProvider = parameters.gitChangedFilesProvider,
gitRoot = parameters.gitRoot.get().asFile
changedFilesProvider = parameters.changedFilesProvider,
vcsRoot = parameters.vcsRoot.get().asFile
)
}
}
Expand Down Expand Up @@ -482,7 +480,7 @@ class AffectedModuleDetectorImpl(
private val modules: Set<String>? = null,
private val config: AffectedModuleConfiguration,
private val changedFilesProvider: Provider<List<String>>,
private val gitRoot: File,
private val vcsRoot: File,
) : AffectedModuleDetector(logger) {

init {
Expand Down Expand Up @@ -651,7 +649,7 @@ class AffectedModuleDetectorImpl(
} else {
File(projectGraph.getRootProjectPath()!!.path)
}
val pathSections = relativeFilePath.toPathSections(rootProjectDir, gitRoot)
val pathSections = relativeFilePath.toPathSections(rootProjectDir, vcsRoot)
val projectRelativePath = pathSections.joinToString(File.separatorChar.toString())

return config.pathsAffectingAllModules.any { projectRelativePath.startsWith(it) }
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,15 @@
package com.dropbox.affectedmoduledetector.commitshaproviders

import com.dropbox.affectedmoduledetector.GitClient
import com.dropbox.affectedmoduledetector.Sha
import com.dropbox.affectedmoduledetector.vcs.VcsClient
import com.dropbox.affectedmoduledetector.vcs.Sha
import java.io.Serializable

interface CommitShaProvider : Serializable {
fun get(commandRunner: GitClient.CommandRunner): Sha
fun get(commandRunner: VcsClient.CommandRunner): Sha
}

data class CommitShaProviderConfiguration(
val type: String,
val specifiedBranch: String? = null,
val specifiedSha: String? = null,
val provider: CommitShaProvider,
val top: Sha,
val includeUncommitted: Boolean
) : Serializable
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package com.dropbox.affectedmoduledetector.commitshaproviders

import com.dropbox.affectedmoduledetector.GitClient
import com.dropbox.affectedmoduledetector.Sha
import com.dropbox.affectedmoduledetector.vcs.VcsClient
import com.dropbox.affectedmoduledetector.vcs.Sha

class ForkCommit : CommitShaProvider {
override fun get(commandRunner: GitClient.CommandRunner): Sha {
override fun get(commandRunner: VcsClient.CommandRunner): Sha {
val currentBranch = commandRunner.executeAndParseFirst(CURRENT_BRANCH_CMD)

val parentBranch = commandRunner.executeAndParse(SHOW_ALL_BRANCHES_CMD)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package com.dropbox.affectedmoduledetector.commitshaproviders

import com.dropbox.affectedmoduledetector.GitClient
import com.dropbox.affectedmoduledetector.Sha
import com.dropbox.affectedmoduledetector.vcs.VcsClient
import com.dropbox.affectedmoduledetector.vcs.Sha

class PreviousCommit : CommitShaProvider {
override fun get(commandRunner: GitClient.CommandRunner): Sha {
override fun get(commandRunner: VcsClient.CommandRunner): Sha {
return commandRunner.executeAndParseFirst(PREV_COMMIT_CMD)
}
companion object {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package com.dropbox.affectedmoduledetector.commitshaproviders

import com.dropbox.affectedmoduledetector.GitClient
import com.dropbox.affectedmoduledetector.Sha
import com.dropbox.affectedmoduledetector.vcs.VcsClient
import com.dropbox.affectedmoduledetector.vcs.Sha

class SpecifiedBranchCommit(private val branch: String) : CommitShaProvider {

override fun get(commandRunner: GitClient.CommandRunner): Sha {
override fun get(commandRunner: VcsClient.CommandRunner): Sha {
return commandRunner.executeAndParseFirst("git rev-parse $branch")
}
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package com.dropbox.affectedmoduledetector.commitshaproviders

import com.dropbox.affectedmoduledetector.GitClient
import com.dropbox.affectedmoduledetector.Sha
import com.dropbox.affectedmoduledetector.vcs.VcsClient
import com.dropbox.affectedmoduledetector.vcs.Sha

class SpecifiedBranchCommitMergeBase(private val specifiedBranch: String) : CommitShaProvider {

override fun get(commandRunner: GitClient.CommandRunner): Sha {
override fun get(commandRunner: VcsClient.CommandRunner): Sha {
val currentBranch = commandRunner.executeAndParseFirst(CURRENT_BRANCH_CMD)
return commandRunner.executeAndParseFirst("git merge-base $currentBranch $specifiedBranch")
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package com.dropbox.affectedmoduledetector.commitshaproviders

import com.dropbox.affectedmoduledetector.GitClient
import com.dropbox.affectedmoduledetector.Sha
import com.dropbox.affectedmoduledetector.vcs.VcsClient
import com.dropbox.affectedmoduledetector.vcs.Sha

class SpecifiedRawCommitSha(private val commitSha: String) : CommitShaProvider {
override fun get(commandRunner: GitClient.CommandRunner): Sha {
override fun get(commandRunner: VcsClient.CommandRunner): Sha {
return commitSha
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package com.dropbox.affectedmoduledetector.vcs

import com.dropbox.affectedmoduledetector.FileLogger
import com.dropbox.affectedmoduledetector.commitshaproviders.CommitShaProviderConfiguration
import java.io.File
import java.io.Serializable

typealias Sha = String

abstract class BaseVcsClient(
protected val workingDir: File,
protected val logger: FileLogger?,
protected val commitShaProviderConfiguration: CommitShaProviderConfiguration,
protected val ignoredFiles: Set<String>?,
): VcsClient

abstract class BaseVcsClientProvider: Serializable {
abstract fun get(
workingDir: File,
logger: FileLogger?,
commitShaProviderConfiguration: CommitShaProviderConfiguration,
ignoredFiles: Set<String>?
): BaseVcsClient
}
Loading