Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 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
Expand Up @@ -174,8 +174,7 @@ internal abstract class AnalyzeArtifactSizeMetrics : DefaultTask() {
if (artifactOrdinaryChange) appendLine(ordinary)
}

private fun ArtifactSizeMetric.requiresAttention() =
this.percentage > pluginConfig.significantChangeThresholdPercentage || this.percentage.isNaN()
private fun ArtifactSizeMetric.requiresAttention() = this.percentage > pluginConfig.significantChangeThresholdPercentage || this.percentage.isNaN()

private data class ArtifactSizeMetric(
val currentSize: Long,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,11 @@ class ArtifactSizeMetricsPlugin : Plugin<Project> {
}
}

private fun Project.subprojectArtifactSizeMetricsTask(): TaskProvider<CollectArtifactSizeMetrics> =
tasks.register<CollectArtifactSizeMetrics>("artifactSizeMetrics") {
group = TASK_GROUP
onlyIf { tasks.findByName("jvmJar") != null }
dependsOn(tasks.withType<Jar>())
}
private fun Project.subprojectArtifactSizeMetricsTask(): TaskProvider<CollectArtifactSizeMetrics> = tasks.register<CollectArtifactSizeMetrics>("artifactSizeMetrics") {
group = TASK_GROUP
onlyIf { tasks.findByName("jvmJar") != null }
dependsOn(tasks.withType<Jar>())
}
Comment on lines -41 to +45
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Question: I'm noticing a lot of reformatting which lengthens lines past 120 chars. Was this an automated reformat or did you manually make these changes for some reason?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was an automated format from ktlint


private fun Project.registerRootProjectArtifactSizeMetricsTask(
subProjects: List<TaskProvider<CollectArtifactSizeMetrics>>,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,13 +67,12 @@ internal abstract class CollectDelegatedArtifactSizeMetrics : DefaultTask() {
}
}

private suspend fun S3Client.getObjectAsText(objectKey: String) =
getObject(
GetObjectRequest {
bucket = S3_ARTIFACT_SIZE_METRICS_BUCKET
key = objectKey
},
) { it.body?.decodeToString() ?: throw AwsSdkGradleException("Metrics file $objectKey is missing a body") }
private suspend fun S3Client.getObjectAsText(objectKey: String) = getObject(
GetObjectRequest {
bucket = S3_ARTIFACT_SIZE_METRICS_BUCKET
key = objectKey
},
) { it.body?.decodeToString() ?: throw AwsSdkGradleException("Metrics file $objectKey is missing a body") }

private fun combine(metricsFiles: List<String>) = buildString {
appendLine("Artifact, Size")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
*/
package aws.sdk.kotlin.gradle.plugins.artifactsizemetrics

import aws.sdk.kotlin.gradle.util.stringPropertyNotNull
import aws.sdk.kotlin.services.cloudwatch.CloudWatchClient
import aws.sdk.kotlin.services.cloudwatch.model.Dimension
import aws.sdk.kotlin.services.cloudwatch.model.MetricDatum
Expand Down Expand Up @@ -36,7 +35,6 @@ internal abstract class PutArtifactSizeMetricsInCloudWatch : DefaultTask() {
fun put() {
val currentTime = Instant.now()
val pluginConfig = project.rootProject.extensions.getByType(ArtifactSizeMetricsPluginConfig::class.java)
val releaseTag = project.stringPropertyNotNull("release")

val metrics = metricsFile
.get()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,7 @@ public fun Project.localProperties(): Map<String, Any> {
* * property from extras
* @return property if it exists or null
*/
public fun Project.prop(name: String): Any? =
properties[name] ?: localProperties()[name] ?: extra.getOrNull(name)
public fun Project.prop(name: String): Any? = properties[name] ?: localProperties()[name] ?: extra.getOrNull(name)

inline fun <reified T> Project.typedProp(name: String): T? {
val any = prop(name)
Expand All @@ -70,9 +69,8 @@ public inline fun Project.verifyRootProject(lazyMessage: () -> Any) {
* @throws AwsSdkGradleException If the property is empty or null
* @return The property as a String
*/
fun Project.stringPropertyNotNull(property: String): String =
findProperty(property)?.toString()?.also {
check(it.isNotEmpty()) { "The $property property is set to empty \"-P$property=\" (no value set). Please specify a value." }
} ?: throw AwsSdkGradleException("The $property property is not set. Please set a value: \"-P$property=YOUR_VALUE\"")
fun Project.stringPropertyNotNull(property: String): String = findProperty(property)?.toString()?.also {
check(it.isNotEmpty()) { "The $property property is set to empty \"-P$property=\" (no value set). Please specify a value." }
} ?: throw AwsSdkGradleException("The $property property is not set. Please set a value: \"-P$property=YOUR_VALUE\"")

class AwsSdkGradleException(message: String) : GradleException(message)
2 changes: 1 addition & 1 deletion build-plugins/kmp-conventions/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ repositories {

dependencies {
implementation(project(":build-plugins:build-support"))
compileOnly(kotlin("gradle-plugin", "2.0.10"))
compileOnly(kotlin("gradle-plugin", "2.1.0"))
testImplementation(libs.junit.jupiter)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,13 @@ open class SmithyBuildExtension(private val project: Project) {
* @param projectionName the name of the projection to get the output path for
* @param pluginName the name of the plugin to get the output path for
*/
public fun getProjectionPath(projectionName: String, pluginName: String): Provider<Path> =
SmithyUtils.getProjectionOutputDirProperty(project).map {
// FIXME - smithy gradle plugin expects the input file to pass "isDirectory"
// but that flag is only true IFF the path exists AND is a directory
// see https://github.com/smithy-lang/smithy-gradle-plugin/issues/113
it.asFile.mkdirs()
SmithyUtils.getProjectionPluginPath(it.asFile, projectionName, pluginName)
}
public fun getProjectionPath(projectionName: String, pluginName: String): Provider<Path> = SmithyUtils.getProjectionOutputDirProperty(project).map {
// FIXME - smithy gradle plugin expects the input file to pass "isDirectory"
// but that flag is only true IFF the path exists AND is a directory
// see https://github.com/smithy-lang/smithy-gradle-plugin/issues/113
it.asFile.mkdirs()
SmithyUtils.getProjectionPluginPath(it.asFile, projectionName, pluginName)
}
}

// smithy-kotlin specific extensions
Expand All @@ -43,14 +42,12 @@ open class SmithyBuildExtension(private val project: Project) {
*
* @param projectionName the name of the projection to use
*/
public fun SmithyBuildExtension.smithyKotlinProjectionPath(projectionName: String): Provider<Path> =
getProjectionPath(projectionName, "kotlin-codegen")
public fun SmithyBuildExtension.smithyKotlinProjectionPath(projectionName: String): Provider<Path> = getProjectionPath(projectionName, "kotlin-codegen")

/**
* Get the default generated kotlin source directory for the `smithy-kotlin` plugin.
* This is equivalent to `smithyBuild.getProjectionPath(projectionName, "kotlin-codegen")
*
* @param projectionName the name of the projection to use
*/
public fun SmithyBuildExtension.smithyKotlinProjectionSrcDir(projectionName: String): Provider<Path> =
smithyKotlinProjectionPath(projectionName).map { it.resolve("src/main/kotlin") }
public fun SmithyBuildExtension.smithyKotlinProjectionSrcDir(projectionName: String): Provider<Path> = smithyKotlinProjectionPath(projectionName).map { it.resolve("src/main/kotlin") }
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,7 @@ class SmithyBuildPlugin : Plugin<Project> {
registerCodegenTasks()
}

private fun Project.installExtension() =
extensions.create(SMITHY_BUILD_EXTENSION_NAME, SmithyBuildExtension::class.java, project)
private fun Project.installExtension() = extensions.create(SMITHY_BUILD_EXTENSION_NAME, SmithyBuildExtension::class.java, project)

private fun Project.registerCodegenTasks() {
val generateSmithyBuild = tasks.register<GenerateSmithyBuild>(TASK_GENERATE_SMITHY_BUILD) {
Expand All @@ -102,8 +101,6 @@ class SmithyBuildPlugin : Plugin<Project> {
tasks.register<SmithyBuildTask>(TASK_GENERATE_SMITHY_PROJECTIONS) {
group = "codegen"
dependsOn(generateSmithyBuild)
resolvedCliClasspath.set(codegenConfig)
runtimeClasspath.set(codegenConfig)
buildClasspath.set(codegenConfig)
smithyBuildConfigs.set(project.files(generateSmithyBuild))
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Question: Why were these removed?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

smithy-gradle-plugin was updated in 1.1.0 to make AbstractSmithyCliTask extend Gradle's DefaultTask rather than BaseSmithyTask which previously exposed these fields.

But I now see they have a cliClassPath property to replace resolvedCliClasspath, so I've re-enabled that config. For runtimeClasspath there is a new cliExecutionClasspath, but it defaults to cliClassPath + buildClasspath so I won't re-enable that config.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,7 @@ open class SmithyKotlinApiSettings : ToNode {
return result
}

override fun toString(): String =
"SmithyKotlinApiSettings(visibility=$visibility, nullabilityCheckMode=$nullabilityCheckMode, defaultValueSerializationMode=$defaultValueSerializationMode, enableEndpointAuthProvider=$enableEndpointAuthProvider)"
override fun toString(): String = "SmithyKotlinApiSettings(visibility=$visibility, nullabilityCheckMode=$nullabilityCheckMode, defaultValueSerializationMode=$defaultValueSerializationMode, enableEndpointAuthProvider=$enableEndpointAuthProvider)"
}

open class SmithyKotlinBuildSettings : ToNode {
Expand Down Expand Up @@ -92,8 +91,7 @@ open class SmithyKotlinBuildSettings : ToNode {
return result
}

override fun toString(): String =
"SmithyKotlinBuildSettings(generateFullProject=$generateFullProject, generateDefaultBuildFiles=$generateDefaultBuildFiles, optInAnnotations=$optInAnnotations)"
override fun toString(): String = "SmithyKotlinBuildSettings(generateFullProject=$generateFullProject, generateDefaultBuildFiles=$generateDefaultBuildFiles, optInAnnotations=$optInAnnotations)"
}

open class SmithyKotlinPluginSettings : SmithyBuildPluginSettings {
Expand Down Expand Up @@ -160,8 +158,7 @@ open class SmithyKotlinPluginSettings : SmithyBuildPluginSettings {
return obj.build()
}

override fun toString(): String =
"SmithyKotlinPluginSettings(pluginName='$pluginName', serviceShapeId=$serviceShapeId, packageName=$packageName, packageVersion=$packageVersion, packageDescription=$packageDescription, sdkId=$sdkId, buildSettings=$buildSettings, apiSettings=$apiSettings)"
override fun toString(): String = "SmithyKotlinPluginSettings(pluginName='$pluginName', serviceShapeId=$serviceShapeId, packageName=$packageName, packageVersion=$packageVersion, packageDescription=$packageDescription, sdkId=$sdkId, buildSettings=$buildSettings, apiSettings=$apiSettings)"
}

fun SmithyProjection.smithyKotlinPlugin(configure: SmithyKotlinPluginSettings.() -> Unit) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,7 @@ internal fun ObjectNode.Builder.withNullableMember(key: String, member: Boolean?
return withMember(key, member)
}

internal fun <T : ToNode> ObjectNode.Builder.withNullableMember(key: String, member: T?): ObjectNode.Builder =
withOptionalMember(key, Optional.ofNullable(member))
internal fun <T : ToNode> ObjectNode.Builder.withNullableMember(key: String, member: T?): ObjectNode.Builder = withOptionalMember(key, Optional.ofNullable(member))

internal fun ObjectNode.Builder.withArrayMember(key: String, member: List<String>): ObjectNode.Builder = apply {
val arrNode = member.map { Node.from(it) }.let { ArrayNode.fromNodes(it) }
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
kotlin.code.style=official

# kotlin
kotlinVersion=2.0.10
kotlinVersion=2.1.0
8 changes: 4 additions & 4 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[versions]
ktlint = "1.3.0"
smithy-version = "1.42.0"
smithy-gradle-plugin-version = "0.9.0"
ktlint = "1.5.0"
smithy-version = "1.53.0"
smithy-gradle-plugin-version = "1.1.0"
junit-version = "5.10.1"

[libraries]
Expand All @@ -11,7 +11,7 @@ ktlint-cli-ruleset-core = { module = "com.pinterest.ktlint:ktlint-cli-ruleset-co
ktlint-test = {module = "com.pinterest.ktlint:ktlint-test", version.ref = "ktlint" }
nexusPublishPlugin = { module = "io.github.gradle-nexus:publish-plugin", version = "1.3.0" }
smithy-model = { module = "software.amazon.smithy:smithy-model", version.ref = "smithy-version" }
smithy-gradle-base-plugin = { module = "software.amazon.smithy:smithy-base-plugin", version.ref = "smithy-gradle-plugin-version" }
smithy-gradle-base-plugin = { module = "software.amazon.smithy.gradle:smithy-base", version.ref = "smithy-gradle-plugin-version" }

junit-jupiter = { module = "org.junit.jupiter:junit-jupiter", version.ref = "junit-version" }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,8 @@ class MultilineIfElseBlockRule : Rule(RuleId("multiline-if-else-block"), About()
/**
* Determines if this node is an `else if` block.
*/
private fun ASTNode.isElseIfBlock() =
elementType == ElementType.ELSE &&
firstChildNode?.elementType == ElementType.IF
private fun ASTNode.isElseIfBlock() = elementType == ElementType.ELSE &&
firstChildNode?.elementType == ElementType.IF

/**
* Determines if this node is on the same source file line number as its parent.
Expand Down
Loading