Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bump com.diffplug.spotless from 6.25.0 to 7.0.2 #271

Merged
merged 2 commits into from
Feb 3, 2025
Merged
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
2 changes: 1 addition & 1 deletion gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ kotlin = "2.1.0"
mavenPublish = "0.30.0"
osDetector = "1.7.3"
pluginPublish = "1.3.1"
spotless = "6.25.0"
spotless = "7.0.2"
buildConfig = "5.5.1"

# runtime
Expand Down
7 changes: 4 additions & 3 deletions src/main/kotlin/build/buf/gradle/BufYamlGenerator.kt
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,10 @@ internal class BufYamlGenerator {

// Collect `breaking: ignore:` entries.
val ignores =
bufYaml["breaking"]?.let { breaking ->
(breaking as? Map<*, *>)?.get("ignore") as? List<*>
}?.map { it.toString() } ?: emptyList()
bufYaml["breaking"]
?.let { breaking ->
(breaking as? Map<*, *>)?.get("ignore") as? List<*>
}?.map { it.toString() } ?: emptyList()

// Emit a module for each discovered workspace, copying ignores and concatenating their
// paths with the module root.
Expand Down
3 changes: 2 additions & 1 deletion src/main/kotlin/build/buf/gradle/LintTask.kt
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,8 @@ abstract class LintTask : AbstractBufExecTask() {

private fun File.readAndStripComments() =
lines(toPath()).use { lines ->
lines.asSequence()
lines
.asSequence()
.filterNot { it.matches("( ?)#.*".toRegex()) }
.joinToString(separator = lineSeparator)
}
Expand Down
6 changes: 5 additions & 1 deletion src/main/kotlin/build/buf/gradle/OutputSupport.kt
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ import org.gradle.api.Project
const val BUF_BUILD_DIR = "bufbuild"

internal val Project.bufbuildDir
get() = layout.buildDirectory.dir(BUF_BUILD_DIR).get().asFile
get() =
layout.buildDirectory
.dir(BUF_BUILD_DIR)
.get()
.asFile

internal fun ArtifactDetails.groupAndArtifact() = "$groupId:$artifactId"
16 changes: 10 additions & 6 deletions src/main/kotlin/build/buf/gradle/ProtobufGradlePluginSupport.kt
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,8 @@ private fun WriteWorkspaceYamlTask.workspaceSymLinkEntries() =
// includes any proto files that are simply references (includes) as well as those that will be processed (code
// generation or validation).
private fun Task.allProtoDirs() =
project.allProtoSourceSetDirs()
project
.allProtoSourceSetDirs()
.plus(project.file(Paths.get(BUILD_EXTRACTED_INCLUDE_PROTOS_MAIN)))
.toSet()

Expand All @@ -193,25 +194,28 @@ private fun Project.allProtoSourceSetDirs() = projectProtoSourceSetDirs() + andr

// Returns android proto source set directories that protobuf-gradle-plugin will codegen.
private fun Project.androidProtoSourceSetDirs() =
extensions.findByName("android")
extensions
.findByName("android")
?.let { baseExtension ->
val prop = baseExtension::class.declaredMemberProperties.single { it.name == "sourceSets" }
@Suppress("UNCHECKED_CAST")
(prop as KProperty1<Any, Set<ExtensionAware>>).get(baseExtension)
}
.orEmpty()
}.orEmpty()
.flatMap { it.projectProtoSourceSetDirs() }
.toSet()

// Returns all proto source set directories that the protobuf-gradle-plugin will codegen.
private fun Project.projectProtoSourceSetDirs() =
the<SourceSetContainer>().flatMap { it.projectProtoSourceSetDirs() }
the<SourceSetContainer>()
.flatMap { it.projectProtoSourceSetDirs() }
.toSet()

// Returns all directories within the "proto" source set of the receiver that actually contain proto files. This includes
// directories explicitly added to the source set, as well as directories containing files from "protobuf" dependencies.
private fun ExtensionAware.projectProtoSourceSetDirs() =
extensions.getByName<SourceDirectorySet>("proto").srcDirs
extensions
.getByName<SourceDirectorySet>("proto")
.srcDirs
.toSet()

internal fun AbstractBufTask.makeMangledRelativizedPathStr(file: File) = mangle(projectDir.get().toPath().relativize(file.toPath()))
Expand Down
10 changes: 6 additions & 4 deletions src/test/kotlin/build/buf/gradle/AbstractBufIntegrationTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,9 @@ abstract class AbstractBufIntegrationTest : IntegrationTest {
File(projectDir, "gradle.properties").writeText("org.gradle.jvmargs=-Xmx5g")

val testName =
testInfo.testMethod.get().name
testInfo.testMethod
.get()
.name
.replace(",", "")
.replace("--", "")
.replace(" ", "_")
Expand All @@ -63,7 +65,8 @@ abstract class AbstractBufIntegrationTest : IntegrationTest {
}

fun gradleRunner() =
GradleRunner.create()
GradleRunner
.create()
.withProjectDir(projectDir)
.withPluginClasspath()
.withArguments(
Expand All @@ -72,8 +75,7 @@ abstract class AbstractBufIntegrationTest : IntegrationTest {
"-PkotlinVersion=1.7.20",
"-PandroidGradleVersion=7.3.0",
"--configuration-cache",
)
.withDebug(false) // Enable for interactive debugging
).withDebug(false) // Enable for interactive debugging
.let { WrappedRunner(it) }

override fun checkRunner() = gradleRunner().withArguments(CHECK_TASK_NAME)
Expand Down
4 changes: 3 additions & 1 deletion src/test/kotlin/build/buf/gradle/AbstractLintTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@ import org.gradle.testkit.runner.TaskOutcome.FAILED
import org.gradle.testkit.runner.TaskOutcome.SUCCESS
import org.junit.jupiter.api.Test

abstract class AbstractLintTest : LintTestUtilities, AbstractBufIntegrationTest() {
abstract class AbstractLintTest :
AbstractBufIntegrationTest(),
LintTestUtilities {
@Test
fun `lint a basic correct message with default config`() {
assertSuccess()
Expand Down
13 changes: 7 additions & 6 deletions src/test/kotlin/build/buf/gradle/ImageGenerationSupport.kt
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,13 @@ private val NULL_SENTINEL = Any()
object ImageGenerationSupport {
@JvmStatic
fun publicationFileExtensionTestCase() =
Lists.cartesianProduct(
ImageFormat.values().map { it.formatName },
CompressionFormat.values().map { it.ext } + NULL_SENTINEL,
).map { imageAndCompression ->
Arguments.of(imageAndCompression[0], imageAndCompression[1].takeIf { it != NULL_SENTINEL })
}
Lists
.cartesianProduct(
ImageFormat.values().map { it.formatName },
CompressionFormat.values().map { it.ext } + NULL_SENTINEL,
).map { imageAndCompression ->
Arguments.of(imageAndCompression[0], imageAndCompression[1].takeIf { it != NULL_SENTINEL })
}

fun AbstractBufIntegrationTest.replaceBuildDetails(
format: String,
Expand Down
5 changes: 4 additions & 1 deletion src/test/kotlin/build/buf/gradle/LintTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,7 @@

package build.buf.gradle

class LintTest : ConfigOverrideableLintTests, NonProtobufGradlePluginLintTests, AbstractLintTest()
class LintTest :
AbstractLintTest(),
ConfigOverrideableLintTests,
NonProtobufGradlePluginLintTests
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@ package build.buf.gradle

import org.junit.jupiter.api.Test

class LintWithProtobufGradleTest : ConfigOverrideableLintTests, AbstractLintTest() {
class LintWithProtobufGradleTest :
AbstractLintTest(),
ConfigOverrideableLintTests {
@Test
fun `lint with protobuf plugin applied after buf plugin`() {
assertSuccess()
Expand Down
4 changes: 3 additions & 1 deletion src/test/kotlin/build/buf/gradle/LintWithWorkspaceTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@ package build.buf.gradle

import org.junit.jupiter.api.Test

class LintWithWorkspaceTest : NonProtobufGradlePluginLintTests, AbstractLintTest() {
class LintWithWorkspaceTest :
AbstractLintTest(),
NonProtobufGradlePluginLintTests {
@Test
fun `lint with a config in workspace`() {
assertSuccess()
Expand Down