diff --git a/affectedmoduledetector/build.gradle b/affectedmoduledetector/build.gradle index ad872803..dcf16e72 100644 --- a/affectedmoduledetector/build.gradle +++ b/affectedmoduledetector/build.gradle @@ -3,6 +3,7 @@ plugins { id 'kotlin' id 'java-gradle-plugin' id "com.vanniktech.maven.publish" + id "org.jlleitschuh.gradle.ktlint" } apply from: rootProject.file("gradle/jacoco.gradle") diff --git a/affectedmoduledetector/src/main/kotlin/com/dropbox/affectedmoduledetector/AffectedModuleConfiguration.kt b/affectedmoduledetector/src/main/kotlin/com/dropbox/affectedmoduledetector/AffectedModuleConfiguration.kt index 82d4a1b1..7d309c33 100644 --- a/affectedmoduledetector/src/main/kotlin/com/dropbox/affectedmoduledetector/AffectedModuleConfiguration.kt +++ b/affectedmoduledetector/src/main/kotlin/com/dropbox/affectedmoduledetector/AffectedModuleConfiguration.kt @@ -82,23 +82,23 @@ class AffectedModuleConfiguration { var specifiedBranch: String? = null var compareFrom: String = "PreviousCommit" - set(value) { - val commitShaProviders = listOf( - "PreviousCommit", - "ForkCommit", - "SpecifiedBranchCommit", - "SpecifiedBranchCommitMergeBase" - ) - require(commitShaProviders.contains(value)) { - "The property configuration compareFrom must be one of the following: ${commitShaProviders.joinToString(", ")}" - } - if (value == "SpecifiedBranchCommit" || value == "SpecifiedBranchCommitMergeBase") { - requireNotNull(specifiedBranch) { - "Specify a branch using the configuration specifiedBranch" + set(value) { + val commitShaProviders = listOf( + "PreviousCommit", + "ForkCommit", + "SpecifiedBranchCommit", + "SpecifiedBranchCommitMergeBase" + ) + require(commitShaProviders.contains(value)) { + "The property configuration compareFrom must be one of the following: ${commitShaProviders.joinToString(", ")}" + } + if (value == "SpecifiedBranchCommit" || value == "SpecifiedBranchCommitMergeBase") { + requireNotNull(specifiedBranch) { + "Specify a branch using the configuration specifiedBranch" + } } + field = value } - field = value - } /** * A set of modules that will not be considered in the build process, even if changes are made in them. @@ -130,4 +130,4 @@ class AffectedModuleConfiguration { const val name = "affectedModuleDetector" } -} \ No newline at end of file +} diff --git a/affectedmoduledetector/src/main/kotlin/com/dropbox/affectedmoduledetector/AffectedModuleDetector.kt b/affectedmoduledetector/src/main/kotlin/com/dropbox/affectedmoduledetector/AffectedModuleDetector.kt index 2267465a..f0013a25 100644 --- a/affectedmoduledetector/src/main/kotlin/com/dropbox/affectedmoduledetector/AffectedModuleDetector.kt +++ b/affectedmoduledetector/src/main/kotlin/com/dropbox/affectedmoduledetector/AffectedModuleDetector.kt @@ -119,7 +119,7 @@ abstract class AffectedModuleDetector { require(rootProject == rootProject.rootProject) { "Project provided must be root, project was ${rootProject.path}" } - + val enabled = isProjectEnabled(rootProject) if (!enabled) { setInstance( @@ -380,7 +380,7 @@ class AffectedModuleDetectorImpl constructor( override fun hasAffectedProjects() = affectedProjects.isNotEmpty() override fun isProjectProvided2(project: Project): Boolean { - if(modules == null ) return true + if (modules == null) return true return modules.contains(project.path) } diff --git a/affectedmoduledetector/src/main/kotlin/com/dropbox/affectedmoduledetector/AffectedModuleDetectorPlugin.kt b/affectedmoduledetector/src/main/kotlin/com/dropbox/affectedmoduledetector/AffectedModuleDetectorPlugin.kt index f8771ae1..0822e923 100644 --- a/affectedmoduledetector/src/main/kotlin/com/dropbox/affectedmoduledetector/AffectedModuleDetectorPlugin.kt +++ b/affectedmoduledetector/src/main/kotlin/com/dropbox/affectedmoduledetector/AffectedModuleDetectorPlugin.kt @@ -178,7 +178,7 @@ class AffectedModuleDetectorPlugin : Plugin { else -> AffectedModuleDetector.isProjectAffected(pathOrNull.project) } - if (onlyIf && AffectedModuleDetector.isProjectProvided(project) && !isExcludedModule(config, path)) { + if (onlyIf && AffectedModuleDetector.isProjectProvided(project) && !isExcludedModule(config, path)) { task.dependsOn(path) } pathOrNull?.onlyIf { onlyIf } @@ -223,7 +223,7 @@ class AffectedModuleDetectorPlugin : Plugin { } private fun getPathAndTask(project: Project, task: String?): String? { - return if (task.isNullOrBlank()) null else "${project.path}:${task}" + return if (task.isNullOrBlank()) null else "${project.path}:$task" } private fun filterAndroidTests(project: Project) { diff --git a/affectedmoduledetector/src/main/kotlin/com/dropbox/affectedmoduledetector/AffectedTestConfiguration.kt b/affectedmoduledetector/src/main/kotlin/com/dropbox/affectedmoduledetector/AffectedTestConfiguration.kt index e7f5ae70..2746e16e 100644 --- a/affectedmoduledetector/src/main/kotlin/com/dropbox/affectedmoduledetector/AffectedTestConfiguration.kt +++ b/affectedmoduledetector/src/main/kotlin/com/dropbox/affectedmoduledetector/AffectedTestConfiguration.kt @@ -8,9 +8,9 @@ package com.dropbox.affectedmoduledetector */ open class AffectedTestConfiguration { - var assembleAndroidTestTask : String? = DEFAULT_ASSEMBLE_ANDROID_TEST_TASK - var runAndroidTestTask : String? = DEFAULT_ANDROID_TEST_TASK - var jvmTestTask : String? = DEFAULT_JVM_TEST_TASK + var assembleAndroidTestTask: String? = DEFAULT_ASSEMBLE_ANDROID_TEST_TASK + var runAndroidTestTask: String? = DEFAULT_ANDROID_TEST_TASK + var jvmTestTask: String? = DEFAULT_JVM_TEST_TASK companion object { const val name = "affectedTestConfiguration" @@ -20,4 +20,4 @@ open class AffectedTestConfiguration { internal const val DEFAULT_ASSEMBLE_ANDROID_TEST_TASK = "assembleDebugAndroidTest" internal const val DEFAULT_ANDROID_TEST_TASK = "connectedDebugAndroidTest" } -} \ No newline at end of file +} diff --git a/affectedmoduledetector/src/main/kotlin/com/dropbox/affectedmoduledetector/DependencyTracker.kt b/affectedmoduledetector/src/main/kotlin/com/dropbox/affectedmoduledetector/DependencyTracker.kt index 7aa856e0..3d235cfd 100644 --- a/affectedmoduledetector/src/main/kotlin/com/dropbox/affectedmoduledetector/DependencyTracker.kt +++ b/affectedmoduledetector/src/main/kotlin/com/dropbox/affectedmoduledetector/DependencyTracker.kt @@ -39,14 +39,16 @@ class DependencyTracker constructor( project.configurations.forEach { config -> logger?.info("checking config ${project.path}/$config for dependencies") config - .dependencies - .filterIsInstance(ProjectDependency::class.java) - .forEach { - logger?.info("there is a dependency from ${project.path} to " + - it.dependencyProject.path) - result.getOrPut(it.dependencyProject) { mutableSetOf() } - .add(project) - } + .dependencies + .filterIsInstance(ProjectDependency::class.java) + .forEach { + logger?.info( + "there is a dependency from ${project.path} to " + + it.dependencyProject.path + ) + result.getOrPut(it.dependencyProject) { mutableSetOf() } + .add(project) + } } } result @@ -61,9 +63,11 @@ class DependencyTracker constructor( } } addAllDependents(project) - logger?.info("dependents of ${project.path} is ${result.map { - it.path - }}") + logger?.info( + "dependents of ${project.path} is ${result.map { + it.path + }}" + ) // the project isn't a dependent of itself return result.minus(project) } diff --git a/affectedmoduledetector/src/main/kotlin/com/dropbox/affectedmoduledetector/GitClient.kt b/affectedmoduledetector/src/main/kotlin/com/dropbox/affectedmoduledetector/GitClient.kt index 7063a80c..d8e09135 100644 --- a/affectedmoduledetector/src/main/kotlin/com/dropbox/affectedmoduledetector/GitClient.kt +++ b/affectedmoduledetector/src/main/kotlin/com/dropbox/affectedmoduledetector/GitClient.kt @@ -97,7 +97,7 @@ internal class GitClientImpl( return ignoredFiles .orEmpty() .map { it.toRegex() } - .foldRight(changedFiles){ignoredFileRegex: Regex, fileList: List -> + .foldRight(changedFiles) { ignoredFileRegex: Regex, fileList: List -> fileList.filterNot { it.matches(ignoredFileRegex) } } } @@ -220,4 +220,4 @@ data class Commit( private val commitSHADelimiter: String = "_CommitSHA:", private val subjectDelimiter: String = "_Subject:", private val authorEmailDelimiter: String = "_Author:" -) \ No newline at end of file +) diff --git a/affectedmoduledetector/src/main/kotlin/com/dropbox/affectedmoduledetector/InternalTaskType.kt b/affectedmoduledetector/src/main/kotlin/com/dropbox/affectedmoduledetector/InternalTaskType.kt index b8907fed..bc38ecd6 100644 --- a/affectedmoduledetector/src/main/kotlin/com/dropbox/affectedmoduledetector/InternalTaskType.kt +++ b/affectedmoduledetector/src/main/kotlin/com/dropbox/affectedmoduledetector/InternalTaskType.kt @@ -4,7 +4,7 @@ internal enum class InternalTaskType( override val commandByImpact: String, override val originalGradleCommand: String, override val taskDescription: String -): AffectedModuleTaskType { +) : AffectedModuleTaskType { ANDROID_TEST( commandByImpact = "runAffectedAndroidTests", diff --git a/affectedmoduledetector/src/main/kotlin/com/dropbox/affectedmoduledetector/ToStringLogger.kt b/affectedmoduledetector/src/main/kotlin/com/dropbox/affectedmoduledetector/ToStringLogger.kt index edcdd479..14af4622 100644 --- a/affectedmoduledetector/src/main/kotlin/com/dropbox/affectedmoduledetector/ToStringLogger.kt +++ b/affectedmoduledetector/src/main/kotlin/com/dropbox/affectedmoduledetector/ToStringLogger.kt @@ -31,7 +31,12 @@ import org.gradle.api.services.BuildServiceParameters import org.gradle.internal.build.event.BuildEventListenerRegistryInternal import org.gradle.internal.logging.slf4j.OutputEventListenerBackedLogger import org.gradle.internal.logging.slf4j.OutputEventListenerBackedLoggerContext -import org.gradle.internal.operations.* +import org.gradle.internal.operations.BuildOperationDescriptor +import org.gradle.internal.operations.BuildOperationListener +import org.gradle.internal.operations.OperationFinishEvent +import org.gradle.internal.operations.OperationIdentifier +import org.gradle.internal.operations.OperationProgressEvent +import org.gradle.internal.operations.OperationStartEvent import org.gradle.internal.time.Clock import org.gradle.invocation.DefaultGradle import java.io.File @@ -42,18 +47,18 @@ import java.io.File internal open class ToStringLogger( private val loggerProvider: Provider? ) : OutputEventListenerBackedLogger( - "amd", - OutputEventListenerBackedLoggerContext { - System.currentTimeMillis() - }.also { - it.level = LogLevel.DEBUG - it.setOutputEventListener { outputEvent -> - loggerProvider?.get()?.parameters?.getStringBuilderProperty()?.get()?.appendLine(outputEvent.toString()) - } - }, - Clock { - System.currentTimeMillis() + "amd", + OutputEventListenerBackedLoggerContext { + System.currentTimeMillis() + }.also { + it.level = LogLevel.DEBUG + it.setOutputEventListener { outputEvent -> + loggerProvider?.get()?.parameters?.getStringBuilderProperty()?.get()?.appendLine(outputEvent.toString()) } + }, + Clock { + System.currentTimeMillis() + } ) { /** @@ -61,7 +66,6 @@ internal open class ToStringLogger( */ fun buildString() = loggerProvider?.get()?.parameters?.getStringBuilderProperty()?.get()?.toString() - @Suppress("UnstableApiUsage") // BuildService is not yet stable companion object { internal abstract class ToStringLoggerBuildService : BuildService, BuildOperationListener, AutoCloseable { interface ToStringLoggerBuildServiceParameters : BuildServiceParameters { diff --git a/affectedmoduledetector/src/main/kotlin/com/dropbox/affectedmoduledetector/commitshaproviders/ForkCommit.kt b/affectedmoduledetector/src/main/kotlin/com/dropbox/affectedmoduledetector/commitshaproviders/ForkCommit.kt index 6fdc9624..8e632c00 100644 --- a/affectedmoduledetector/src/main/kotlin/com/dropbox/affectedmoduledetector/commitshaproviders/ForkCommit.kt +++ b/affectedmoduledetector/src/main/kotlin/com/dropbox/affectedmoduledetector/commitshaproviders/ForkCommit.kt @@ -3,7 +3,7 @@ package com.dropbox.affectedmoduledetector.commitshaproviders import com.dropbox.affectedmoduledetector.GitClient import com.dropbox.affectedmoduledetector.Sha -class ForkCommit: CommitShaProvider { +class ForkCommit : CommitShaProvider { override fun get(commandRunner: GitClient.CommandRunner): Sha { val currentBranch = commandRunner.executeAndParseFirst(CURRENT_BRANCH_CMD) @@ -25,4 +25,4 @@ class ForkCommit: CommitShaProvider { const val CURRENT_BRANCH_CMD = "git rev-parse --abbrev-ref HEAD" const val SHOW_ALL_BRANCHES_CMD = "git show-branch -a" } -} \ No newline at end of file +} diff --git a/affectedmoduledetector/src/main/kotlin/com/dropbox/affectedmoduledetector/commitshaproviders/PreviousCommit.kt b/affectedmoduledetector/src/main/kotlin/com/dropbox/affectedmoduledetector/commitshaproviders/PreviousCommit.kt index c5ea79c3..79ffb7ce 100644 --- a/affectedmoduledetector/src/main/kotlin/com/dropbox/affectedmoduledetector/commitshaproviders/PreviousCommit.kt +++ b/affectedmoduledetector/src/main/kotlin/com/dropbox/affectedmoduledetector/commitshaproviders/PreviousCommit.kt @@ -3,11 +3,11 @@ package com.dropbox.affectedmoduledetector.commitshaproviders import com.dropbox.affectedmoduledetector.GitClient import com.dropbox.affectedmoduledetector.Sha -class PreviousCommit: CommitShaProvider { +class PreviousCommit : CommitShaProvider { override fun get(commandRunner: GitClient.CommandRunner): Sha { return commandRunner.executeAndParseFirst(PREV_COMMIT_CMD) } companion object { const val PREV_COMMIT_CMD = "git --no-pager rev-parse HEAD~1" } -} \ No newline at end of file +} diff --git a/affectedmoduledetector/src/main/kotlin/com/dropbox/affectedmoduledetector/commitshaproviders/SpecifiedBranchCommit.kt b/affectedmoduledetector/src/main/kotlin/com/dropbox/affectedmoduledetector/commitshaproviders/SpecifiedBranchCommit.kt index 96e98b8a..11486c18 100644 --- a/affectedmoduledetector/src/main/kotlin/com/dropbox/affectedmoduledetector/commitshaproviders/SpecifiedBranchCommit.kt +++ b/affectedmoduledetector/src/main/kotlin/com/dropbox/affectedmoduledetector/commitshaproviders/SpecifiedBranchCommit.kt @@ -8,4 +8,4 @@ class SpecifiedBranchCommit(private val branch: String) : CommitShaProvider { override fun get(commandRunner: GitClient.CommandRunner): Sha { return commandRunner.executeAndParseFirst("git rev-parse $branch") } -} \ No newline at end of file +} diff --git a/affectedmoduledetector/src/main/kotlin/com/dropbox/affectedmoduledetector/util/File.kt b/affectedmoduledetector/src/main/kotlin/com/dropbox/affectedmoduledetector/util/File.kt index 2921ed57..6567b669 100644 --- a/affectedmoduledetector/src/main/kotlin/com/dropbox/affectedmoduledetector/util/File.kt +++ b/affectedmoduledetector/src/main/kotlin/com/dropbox/affectedmoduledetector/util/File.kt @@ -21,4 +21,4 @@ fun String.toPathSections(rootProjectDir: File, gitRootDir: File): List } } return realSections.toList() -} \ No newline at end of file +} diff --git a/affectedmoduledetector/src/main/kotlin/com/dropbox/affectedmoduledetector/util/OsQuirks.kt b/affectedmoduledetector/src/main/kotlin/com/dropbox/affectedmoduledetector/util/OsQuirks.kt index c33ea70a..2cf86b57 100644 --- a/affectedmoduledetector/src/main/kotlin/com/dropbox/affectedmoduledetector/util/OsQuirks.kt +++ b/affectedmoduledetector/src/main/kotlin/com/dropbox/affectedmoduledetector/util/OsQuirks.kt @@ -22,4 +22,4 @@ fun String.toOsSpecificPath(): String { */ fun String.toOsSpecificLineEnding(): String { return this.replace("\n", System.lineSeparator()) -} \ No newline at end of file +} diff --git a/affectedmoduledetector/src/test/kotlin/com/dropbox/affectedmoduledetector/AffectedModuleConfigurationTest.kt b/affectedmoduledetector/src/test/kotlin/com/dropbox/affectedmoduledetector/AffectedModuleConfigurationTest.kt index e46d1ec0..ccb14f9e 100644 --- a/affectedmoduledetector/src/test/kotlin/com/dropbox/affectedmoduledetector/AffectedModuleConfigurationTest.kt +++ b/affectedmoduledetector/src/test/kotlin/com/dropbox/affectedmoduledetector/AffectedModuleConfigurationTest.kt @@ -16,7 +16,7 @@ class AffectedModuleConfigurationTest { @get:Rule val tmpFolder = TemporaryFolder() - private lateinit var config : AffectedModuleConfiguration + private lateinit var config: AffectedModuleConfiguration private val FAKE_TASK = AffectedModuleConfiguration.CustomTask( commandByImpact = "runFakeTask", @@ -122,7 +122,6 @@ class AffectedModuleConfigurationTest { fail("Expected to catch an exception") } - @Test fun `GIVEN AffectedModuleConfiguration WHEN base dir is set and paths affecting module is set THEN succeeds`() { // GIVEN @@ -159,7 +158,6 @@ class AffectedModuleConfigurationTest { fail("Expected to catch an exception") } - @Test fun `GIVEN AffectedModuleConfiguration WHEN companion object name is returned THEN affectedModuleDetector is returned`() { assertThat(AffectedModuleConfiguration.name).isEqualTo("affectedModuleDetector") @@ -231,7 +229,6 @@ class AffectedModuleConfigurationTest { } fail("Expected to catch an exception") - } @Test @@ -327,4 +324,4 @@ class AffectedModuleConfigurationTest { assert(actual.first().taskDescription == "Description of fake task") } -} \ No newline at end of file +} diff --git a/affectedmoduledetector/src/test/kotlin/com/dropbox/affectedmoduledetector/AffectedModuleDetectorPluginTest.kt b/affectedmoduledetector/src/test/kotlin/com/dropbox/affectedmoduledetector/AffectedModuleDetectorPluginTest.kt index ff1dd737..3ac25fd2 100644 --- a/affectedmoduledetector/src/test/kotlin/com/dropbox/affectedmoduledetector/AffectedModuleDetectorPluginTest.kt +++ b/affectedmoduledetector/src/test/kotlin/com/dropbox/affectedmoduledetector/AffectedModuleDetectorPluginTest.kt @@ -8,9 +8,9 @@ import org.junit.Before import org.junit.Rule import org.junit.Test import org.junit.rules.TemporaryFolder -import java.lang.IllegalStateException import org.junit.runner.RunWith import org.junit.runners.JUnit4 +import java.lang.IllegalStateException @RunWith(JUnit4::class) class AffectedModuleDetectorPluginTest { @@ -197,7 +197,7 @@ class AffectedModuleDetectorPluginTest { val customTasks = rootProject .tasks - .filter { it.group == AffectedModuleDetectorPlugin.CUSTOM_TASK_GROUP_NAME } + .filter { it.group == AffectedModuleDetectorPlugin.CUSTOM_TASK_GROUP_NAME } // THEN assert(customTasks.size == 2) diff --git a/affectedmoduledetector/src/test/kotlin/com/dropbox/affectedmoduledetector/AffectedTestConfigurationTest.kt b/affectedmoduledetector/src/test/kotlin/com/dropbox/affectedmoduledetector/AffectedTestConfigurationTest.kt index d18e29ed..90f21e7b 100644 --- a/affectedmoduledetector/src/test/kotlin/com/dropbox/affectedmoduledetector/AffectedTestConfigurationTest.kt +++ b/affectedmoduledetector/src/test/kotlin/com/dropbox/affectedmoduledetector/AffectedTestConfigurationTest.kt @@ -6,7 +6,7 @@ import org.junit.Test class AffectedTestConfigurationTest { - private lateinit var config : AffectedTestConfiguration + private lateinit var config: AffectedTestConfiguration @Before fun setup() { diff --git a/affectedmoduledetector/src/test/kotlin/com/dropbox/affectedmoduledetector/AttachLogsTestRule.kt b/affectedmoduledetector/src/test/kotlin/com/dropbox/affectedmoduledetector/AttachLogsTestRule.kt index 3dc91a75..624f4489 100644 --- a/affectedmoduledetector/src/test/kotlin/com/dropbox/affectedmoduledetector/AttachLogsTestRule.kt +++ b/affectedmoduledetector/src/test/kotlin/com/dropbox/affectedmoduledetector/AttachLogsTestRule.kt @@ -1,7 +1,6 @@ package com.dropbox.affectedmoduledetector import com.nhaarman.mockito_kotlin.mock -import org.gradle.api.provider.Provider import org.junit.rules.TestRule import org.junit.runner.Description import org.junit.runners.model.Statement @@ -10,7 +9,7 @@ import org.junit.runners.model.Statement * Special rule for dependency detector tests that will attach logs to a failure. */ class AttachLogsTestRule : TestRule { - internal val logger = mock { } + internal val logger = mock { } override fun apply(base: Statement, description: Description): Statement { return object : Statement() { override fun evaluate() { @@ -22,7 +21,7 @@ class AttachLogsTestRule : TestRule { test failed with msg: ${t.message} logs: ${logger.buildString()} - """.trimIndent(), + """.trimIndent(), t ) } diff --git a/affectedmoduledetector/src/test/kotlin/com/dropbox/affectedmoduledetector/GitClientImplTest.kt b/affectedmoduledetector/src/test/kotlin/com/dropbox/affectedmoduledetector/GitClientImplTest.kt index 82cf3346..5040d23c 100644 --- a/affectedmoduledetector/src/test/kotlin/com/dropbox/affectedmoduledetector/GitClientImplTest.kt +++ b/affectedmoduledetector/src/test/kotlin/com/dropbox/affectedmoduledetector/GitClientImplTest.kt @@ -1,14 +1,14 @@ package com.dropbox.affectedmoduledetector -import java.io.File +import com.dropbox.affectedmoduledetector.GitClientImpl.Companion.CHANGED_FILES_CMD_PREFIX +import com.dropbox.affectedmoduledetector.mocks.MockCommandRunner +import com.dropbox.affectedmoduledetector.mocks.MockCommitShaProvider import junit.framework.TestCase.assertEquals import org.junit.Rule import org.junit.Test import org.junit.runner.RunWith import org.junit.runners.JUnit4 -import com.dropbox.affectedmoduledetector.GitClientImpl.Companion.CHANGED_FILES_CMD_PREFIX -import com.dropbox.affectedmoduledetector.mocks.MockCommandRunner -import com.dropbox.affectedmoduledetector.mocks.MockCommitShaProvider +import java.io.File @RunWith(JUnit4::class) class GitClientImplTest { @@ -34,56 +34,60 @@ class GitClientImplTest { @Test fun givenChangedFiles_whenFindChangedFilesIncludeUncommitted_thenReturnChanges() { val changes = listOf( - convertToFilePath("d", "e", ".ignoredNot"), - convertToFilePath("a", "b", "c.java"), - convertToFilePath("d", "e", "f.java")) + convertToFilePath("d", "e", ".ignoredNot"), + convertToFilePath("a", "b", "c.java"), + convertToFilePath("d", "e", "f.java") + ) val changesWithIgnores = listOf( - convertToFilePath("a", "b", "anything.ignore"), - convertToFilePath("d", "e", ".ignore"), - convertToFilePath("d", "e", "IGNORED_FILE") + convertToFilePath("a", "b", "anything.ignore"), + convertToFilePath("d", "e", ".ignore"), + convertToFilePath("d", "e", "IGNORED_FILE") ) + changes commandRunner.addReply( - "$CHANGED_FILES_CMD_PREFIX mySha", + "$CHANGED_FILES_CMD_PREFIX mySha", changesWithIgnores.joinToString(System.lineSeparator()) ) commitShaProvider.addReply("mySha") assertEquals( - changes, - client.findChangedFiles(includeUncommitted = true)) + changes, + client.findChangedFiles(includeUncommitted = true) + ) } @Test fun findChangesSince_empty() { commitShaProvider.addReply("mySha") assertEquals( - emptyList(), - client.findChangedFiles() + emptyList(), + client.findChangedFiles() ) } @Test fun findChangesSince_twoCls() { val changes = listOf( - convertToFilePath("d", "e", ".ignoredNot"), - convertToFilePath("a", "b", "c.java"), - convertToFilePath("d", "e", "f.java")) + convertToFilePath("d", "e", ".ignoredNot"), + convertToFilePath("a", "b", "c.java"), + convertToFilePath("d", "e", "f.java") + ) val changesWithIgnores = listOf( - convertToFilePath("a", "b", "anything.ignore"), - convertToFilePath("d", "e", ".ignore"), - convertToFilePath("d", "e", "IGNORED_FILE") + convertToFilePath("a", "b", "anything.ignore"), + convertToFilePath("d", "e", ".ignore"), + convertToFilePath("d", "e", "IGNORED_FILE") ) + changes commandRunner.addReply( - "$CHANGED_FILES_CMD_PREFIX otherSha..mySha", + "$CHANGED_FILES_CMD_PREFIX otherSha..mySha", changesWithIgnores.joinToString(System.lineSeparator()) ) commitShaProvider.addReply("mySha") assertEquals( - changes, - client.findChangedFiles( - top = "otherSha", - includeUncommitted = false - )) + changes, + client.findChangedFiles( + top = "otherSha", + includeUncommitted = false + ) + ) } // For both Linux/Windows diff --git a/affectedmoduledetector/src/test/kotlin/com/dropbox/affectedmoduledetector/ProjectGraphTest.kt b/affectedmoduledetector/src/test/kotlin/com/dropbox/affectedmoduledetector/ProjectGraphTest.kt index 358c49c0..1a7f6126 100644 --- a/affectedmoduledetector/src/test/kotlin/com/dropbox/affectedmoduledetector/ProjectGraphTest.kt +++ b/affectedmoduledetector/src/test/kotlin/com/dropbox/affectedmoduledetector/ProjectGraphTest.kt @@ -1,6 +1,5 @@ package com.dropbox.affectedmoduledetector -import java.io.File import junit.framework.TestCase.assertEquals import junit.framework.TestCase.assertNull import org.gradle.api.plugins.ExtraPropertiesExtension @@ -10,6 +9,7 @@ import org.junit.Test import org.junit.rules.TemporaryFolder import org.junit.runner.RunWith import org.junit.runners.JUnit4 +import java.io.File @RunWith(JUnit4::class) class ProjectGraphTest { @@ -21,44 +21,44 @@ class ProjectGraphTest { fun testSimple() { val tmpDir = tmpFolder.root val root = ProjectBuilder.builder() - .withProjectDir(tmpDir) - .withName("root") - .build() + .withProjectDir(tmpDir) + .withName("root") + .build() // Project Graph expects supportRootFolder. (root.properties.get("ext") as ExtraPropertiesExtension).set("supportRootFolder", tmpDir) val p1 = ProjectBuilder.builder() - .withProjectDir(tmpDir.resolve("p1")) - .withName("p1") - .withParent(root) - .build() + .withProjectDir(tmpDir.resolve("p1")) + .withName("p1") + .withParent(root) + .build() val p2 = ProjectBuilder.builder() - .withProjectDir(tmpDir.resolve("p2")) - .withName("p2") - .withParent(root) - .build() + .withProjectDir(tmpDir.resolve("p2")) + .withName("p2") + .withParent(root) + .build() val p3 = ProjectBuilder.builder() - .withProjectDir(tmpDir.resolve("p1").resolve("p3")) - .withName("p3") - .withParent(p1) - .build() + .withProjectDir(tmpDir.resolve("p1").resolve("p3")) + .withName("p3") + .withParent(p1) + .build() val graph = ProjectGraph(root, tmpDir) assertNull(graph.findContainingProject("nowhere")) assertNull(graph.findContainingProject("rootfile.java")) assertEquals( - p1, - graph.findContainingProject("p1/px/x.java".toLocalPath()) + p1, + graph.findContainingProject("p1/px/x.java".toLocalPath()) ) assertEquals( - p1, - graph.findContainingProject("p1/a.java".toLocalPath()) + p1, + graph.findContainingProject("p1/a.java".toLocalPath()) ) assertEquals( - p3, - graph.findContainingProject("p1/p3/a.java".toLocalPath()) + p3, + graph.findContainingProject("p1/p3/a.java".toLocalPath()) ) assertEquals( - p2, - graph.findContainingProject("p2/a/b/c/d/e/f/a.java".toLocalPath()) + p2, + graph.findContainingProject("p2/a/b/c/d/e/f/a.java".toLocalPath()) ) } private fun String.toLocalPath() = this.split("/").joinToString(File.separator) diff --git a/affectedmoduledetector/src/test/kotlin/com/dropbox/affectedmoduledetector/commitshaproviders/CommitShaProviderTest.kt b/affectedmoduledetector/src/test/kotlin/com/dropbox/affectedmoduledetector/commitshaproviders/CommitShaProviderTest.kt index e50590cc..68540d28 100644 --- a/affectedmoduledetector/src/test/kotlin/com/dropbox/affectedmoduledetector/commitshaproviders/CommitShaProviderTest.kt +++ b/affectedmoduledetector/src/test/kotlin/com/dropbox/affectedmoduledetector/commitshaproviders/CommitShaProviderTest.kt @@ -1,11 +1,11 @@ package com.dropbox.affectedmoduledetector.commitshaproviders import com.google.common.truth.Truth.assertThat +import org.junit.Assert.fail import org.junit.Test import org.junit.runner.RunWith import org.junit.runners.JUnit4 import java.lang.IllegalArgumentException -import org.junit.Assert.fail @RunWith(JUnit4::class) class CommitShaProviderTest { @@ -68,4 +68,4 @@ class CommitShaProviderTest { assertThat(e.message).isEqualTo("Unsupported compareFrom type") } } -} \ No newline at end of file +} diff --git a/affectedmoduledetector/src/test/kotlin/com/dropbox/affectedmoduledetector/commitshaproviders/ForkCommitTest.kt b/affectedmoduledetector/src/test/kotlin/com/dropbox/affectedmoduledetector/commitshaproviders/ForkCommitTest.kt index 02e0dfdb..cd4ab389 100644 --- a/affectedmoduledetector/src/test/kotlin/com/dropbox/affectedmoduledetector/commitshaproviders/ForkCommitTest.kt +++ b/affectedmoduledetector/src/test/kotlin/com/dropbox/affectedmoduledetector/commitshaproviders/ForkCommitTest.kt @@ -75,4 +75,4 @@ class ForkCommitTest { assertThat(actual).isEqualTo("commit-sha") } -} \ No newline at end of file +} diff --git a/affectedmoduledetector/src/test/kotlin/com/dropbox/affectedmoduledetector/commitshaproviders/PreviousCommitTest.kt b/affectedmoduledetector/src/test/kotlin/com/dropbox/affectedmoduledetector/commitshaproviders/PreviousCommitTest.kt index 96fe112d..9d055849 100644 --- a/affectedmoduledetector/src/test/kotlin/com/dropbox/affectedmoduledetector/commitshaproviders/PreviousCommitTest.kt +++ b/affectedmoduledetector/src/test/kotlin/com/dropbox/affectedmoduledetector/commitshaproviders/PreviousCommitTest.kt @@ -30,4 +30,4 @@ class PreviousCommitTest { assertThat(actual).isEqualTo("commit-sha") } -} \ No newline at end of file +} diff --git a/affectedmoduledetector/src/test/kotlin/com/dropbox/affectedmoduledetector/commitshaproviders/SpecifiedBranchCommitTest.kt b/affectedmoduledetector/src/test/kotlin/com/dropbox/affectedmoduledetector/commitshaproviders/SpecifiedBranchCommitTest.kt index 3f0f3145..0b818731 100644 --- a/affectedmoduledetector/src/test/kotlin/com/dropbox/affectedmoduledetector/commitshaproviders/SpecifiedBranchCommitTest.kt +++ b/affectedmoduledetector/src/test/kotlin/com/dropbox/affectedmoduledetector/commitshaproviders/SpecifiedBranchCommitTest.kt @@ -26,4 +26,4 @@ class SpecifiedBranchCommitTest { Truth.assertThat(actual).isEqualTo("commit-sha") } -} \ No newline at end of file +} diff --git a/affectedmoduledetector/src/test/kotlin/com/dropbox/affectedmoduledetector/mocks/MockCommandRunner.kt b/affectedmoduledetector/src/test/kotlin/com/dropbox/affectedmoduledetector/mocks/MockCommandRunner.kt index 435df919..c3a822ff 100644 --- a/affectedmoduledetector/src/test/kotlin/com/dropbox/affectedmoduledetector/mocks/MockCommandRunner.kt +++ b/affectedmoduledetector/src/test/kotlin/com/dropbox/affectedmoduledetector/mocks/MockCommandRunner.kt @@ -29,4 +29,4 @@ internal class MockCommandRunner(private val logger: ToStringLogger) : GitClient logger.info("cmd: $command response: $it") } } -} \ No newline at end of file +} diff --git a/affectedmoduledetector/src/test/kotlin/com/dropbox/affectedmoduledetector/mocks/MockCommitShaProvider.kt b/affectedmoduledetector/src/test/kotlin/com/dropbox/affectedmoduledetector/mocks/MockCommitShaProvider.kt index eb684431..8fb15456 100644 --- a/affectedmoduledetector/src/test/kotlin/com/dropbox/affectedmoduledetector/mocks/MockCommitShaProvider.kt +++ b/affectedmoduledetector/src/test/kotlin/com/dropbox/affectedmoduledetector/mocks/MockCommitShaProvider.kt @@ -4,7 +4,7 @@ import com.dropbox.affectedmoduledetector.GitClient import com.dropbox.affectedmoduledetector.Sha import com.dropbox.affectedmoduledetector.commitshaproviders.CommitShaProvider -class MockCommitShaProvider: CommitShaProvider { +class MockCommitShaProvider : CommitShaProvider { private val replies = mutableListOf() fun addReply(sha: Sha) { @@ -13,4 +13,4 @@ class MockCommitShaProvider: CommitShaProvider { override fun get(commandRunner: GitClient.CommandRunner): Sha { return replies.first() } -} \ No newline at end of file +} diff --git a/affectedmoduledetector/src/test/kotlin/com/dropbox/affectedmoduledetector/rules/SetupAndroidProject.kt b/affectedmoduledetector/src/test/kotlin/com/dropbox/affectedmoduledetector/rules/SetupAndroidProject.kt index ff00863f..729f6fcc 100644 --- a/affectedmoduledetector/src/test/kotlin/com/dropbox/affectedmoduledetector/rules/SetupAndroidProject.kt +++ b/affectedmoduledetector/src/test/kotlin/com/dropbox/affectedmoduledetector/rules/SetupAndroidProject.kt @@ -41,4 +41,4 @@ class SetupAndroidProject : TemporaryFolder() { newFile("local.properties").writeText(it.readText()) } } -} \ No newline at end of file +}