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

chore: lint _all_ the things #908

Merged
merged 2 commits into from
May 2, 2023
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
45 changes: 22 additions & 23 deletions aws-runtime/aws-config/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -97,12 +97,12 @@ codegen {
// generate an sts client
create("sts-credentials-provider") {
imports = listOf(
awsModelFile("sts.json")
awsModelFile("sts.json"),
)

smithyKotlinPlugin {
serviceShapeId = "com.amazonaws.sts#AWSSecurityTokenServiceV20110615"
packageName = "${basePackage}.sts"
packageName = "$basePackage.sts"
packageVersion = project.version.toString()
packageDescription = "Internal STS credentials provider"
sdkId = "STS"
Expand All @@ -115,29 +115,29 @@ codegen {
// TODO - could we add a trait such that we change visibility to `internal` or a build setting...?
transforms = listOf(
"""
{
"name": "awsSdkKotlinIncludeOperations",
"args": {
"operations": [
"com.amazonaws.sts#AssumeRole",
"com.amazonaws.sts#AssumeRoleWithWebIdentity"
]
{
"name": "awsSdkKotlinIncludeOperations",
"args": {
"operations": [
"com.amazonaws.sts#AssumeRole",
"com.amazonaws.sts#AssumeRoleWithWebIdentity"
]
}
}
}
"""
""",
)
}

// generate an sso client
create("sso-credentials-provider") {
imports = listOf(
awsModelFile("sso.json")
awsModelFile("sso.json"),
)

val serviceShape = "com.amazonaws.sso#SWBPortalService"
smithyKotlinPlugin {
serviceShapeId = serviceShape
packageName = "${basePackage}.sso"
packageName = "$basePackage.sso"
packageVersion = project.version.toString()
packageDescription = "Internal SSO credentials provider"
sdkId = "SSO"
Expand All @@ -148,16 +148,16 @@ codegen {
}

transforms = listOf(
"""
{
"name": "awsSdkKotlinIncludeOperations",
"args": {
"operations": [
"com.amazonaws.sso#GetRoleCredentials"
]
"""
{
"name": "awsSdkKotlinIncludeOperations",
"args": {
"operations": [
"com.amazonaws.sso#GetRoleCredentials"
]
}
}
}
"""
""",
)
}
}
Expand Down Expand Up @@ -210,7 +210,6 @@ listOf("apiElements", "runtimeElements").forEach {
}
}


// suppress internal generated clients
tasks.named<DokkaTaskPartial>("dokkaHtmlPartial") {
dokkaSourceSets.configureEach {
Expand Down
1 change: 0 additions & 1 deletion aws-runtime/aws-core/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ description = "AWS client runtime core"
extra["displayName"] = "AWS :: SDK :: Kotlin :: Client Runtime"
extra["moduleName"] = "aws.sdk.kotlin.runtime"


val smithyKotlinVersion: String by project

kotlin {
Expand Down
2 changes: 1 addition & 1 deletion aws-runtime/aws-endpoint/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ val smithyKotlinVersion: String by project

kotlin {
sourceSets {
commonMain{
commonMain {
dependencies {
implementation(project(":aws-runtime:aws-core"))
// exposes Endpoint
Expand Down
12 changes: 6 additions & 6 deletions aws-runtime/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ val optinAnnotations = listOf(
"kotlin.RequiresOptIn",
)

fun projectNeedsPlatform(project: Project, platform: String ): Boolean {
fun projectNeedsPlatform(project: Project, platform: String): Boolean {
val files = project.projectDir.listFiles()
val hasPosix = files.any { it.name == "posix" }
val hasDarwin = files.any { it.name == "darwin" }
Expand All @@ -29,7 +29,7 @@ fun projectNeedsPlatform(project: Project, platform: String ): Boolean {
if (hasDarwin && platform == "posix") return false
if (!hasPosix && !hasDarwin && platform == "darwin") return false
// add implicit JVM target if it has a common module
return files.any{ it.name == platform || (it.name == "common" && platform == "jvm")}
return files.any { it.name == platform || (it.name == "common" && platform == "jvm") }
}

kotlin {
Expand All @@ -55,9 +55,9 @@ subprojects {
// subproject.
platforms.forEach { platform ->
if (projectNeedsPlatform(project, platform)) {
configure(listOf(project)){
configure(listOf(project)) {
logger.info("${project.name} needs platform: $platform")
apply(from = rootProject.file("gradle/${platform}.gradle"))
apply(from = rootProject.file("gradle/$platform.gradle"))
}
}
}
Expand All @@ -68,7 +68,7 @@ subprojects {
sourceSets {
all {
val srcDir = if (name.endsWith("Main")) "src" else "test"
val resourcesPrefix = if (name.endsWith("Test")) "test-" else ""
val resourcesPrefix = if (name.endsWith("Test")) "test-" else ""
// the name is always the platform followed by a suffix of either "Main" or "Test" (e.g. jvmMain, commonTest, etc)
val platform = name.substring(0, name.length - 4)
kotlin.srcDir("$platform/$srcDir")
Expand All @@ -86,7 +86,7 @@ subprojects {
}
}

task<org.jetbrains.kotlin.gradle.testing.internal.KotlinTestReport>("rootAllTest"){
task<org.jetbrains.kotlin.gradle.testing.internal.KotlinTestReport>("rootAllTest") {
destinationDir = File(project.buildDir, "reports/tests/rootAllTest")
val rootAllTest = this
subprojects {
Expand Down
17 changes: 7 additions & 10 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
* SPDX-License-Identifier: Apache-2.0
*/
import java.util.Properties
import java.net.URL
import java.time.Duration
import java.util.Properties

plugins {
kotlin("jvm") version "1.8.10" apply false
Expand Down Expand Up @@ -38,7 +38,7 @@ allprojects {
"separateInheritedMembers" : true,
"templatesDir": "${rootProject.file("docs/dokka-presets/templates")}"
}
"""
""",
)
pluginsMapConfiguration.set(pluginConfigMap)
}
Expand Down Expand Up @@ -157,14 +157,9 @@ dependencies {
}

val lintPaths = listOf(
"codegen/smithy-aws-kotlin-codegen/**/*.kt",
"aws-runtime/**/*.kt",
"examples/**/*.kt",
"dokka-aws/**/*.kt",
"gradle/sdk-plugins/src/**/*.kt",
"services/**/*.kt",
"!services/*/generated-src/**/*.kt",
"tests/**/*.kt"
"**/*.{kt,kts}",
"!**/generated-src/**",
"!**/smithyprojections/**",
)

tasks.register<JavaExec>("ktlint") {
Expand All @@ -173,6 +168,7 @@ tasks.register<JavaExec>("ktlint") {
classpath = configurations.getByName("ktlint")
main = "com.pinterest.ktlint.Main"
args = lintPaths
jvmArgs("--add-opens", "java.base/java.lang=ALL-UNNAMED")
Copy link
Contributor

Choose a reason for hiding this comment

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

Question: What does this do?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I don't know exactly what it does but it was necessary to get around issues when running gg ktlintFormat. I saw instances of NoClassDefFoundError and InaccessibleObjectException and the related GH issues mentioned this as a solution. KtLint's integrations guide also mentions this may be necessary, albeit in the context of custom Gradle integration (rather than via a plugin like we're doing).

}

tasks.register<JavaExec>("ktlintFormat") {
Expand All @@ -181,6 +177,7 @@ tasks.register<JavaExec>("ktlintFormat") {
classpath = configurations.getByName("ktlint")
main = "com.pinterest.ktlint.Main"
args = listOf("-F") + lintPaths
jvmArgs("--add-opens", "java.base/java.lang=ALL-UNNAMED")
}

// configure coverage for the entire project
Expand Down
6 changes: 2 additions & 4 deletions codegen/protocol-tests/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ data class ProtocolTest(val projectionName: String, val serviceShapeId: String,
val packageName: String = projectionName.toLowerCase().filter { it.isLetterOrDigit() }
}


// The following section exposes Smithy protocol test suites as gradle test targets
// for the configured protocols in [enabledProtocols].
val enabledProtocols = listOf(
Expand Down Expand Up @@ -49,7 +48,7 @@ codegen {
"services": ["${test.serviceShapeId}"]
}
}
"""
""",
)

smithyKotlinPlugin {
Expand All @@ -61,7 +60,7 @@ codegen {
generateFullProject = true
optInAnnotations = listOf(
"aws.smithy.kotlin.runtime.InternalApi",
"aws.sdk.kotlin.runtime.InternalSdkApi"
"aws.sdk.kotlin.runtime.InternalSdkApi",
)
}
}
Expand Down Expand Up @@ -89,7 +88,6 @@ open class ProtocolTestTask : DefaultTask() {
@get:Input
var projection: aws.sdk.kotlin.gradle.codegen.dsl.SmithyProjection? = null


@TaskAction
fun runTests() {
val projection = requireNotNull(projection) { "projection is required task input" }
Expand Down
25 changes: 10 additions & 15 deletions codegen/sdk/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ import aws.sdk.kotlin.gradle.codegen.dsl.smithyKotlinPlugin
import software.amazon.smithy.gradle.tasks.SmithyBuild
import software.amazon.smithy.model.Model
import software.amazon.smithy.model.shapes.ServiceShape
import java.util.*
import java.nio.file.Paths
import java.util.*
import kotlin.streams.toList

description = "AWS SDK codegen tasks"
Expand Down Expand Up @@ -94,12 +94,11 @@ data class AwsService(

)


val disabledServices = setOf(
// timestream requires endpoint discovery
// https://github.com/awslabs/smithy-kotlin/issues/146
"timestream-write",
"timestream-query"
"timestream-query",
)

// Manually create the projections rather than using the extension to avoid unnecessary configuration evaluation.
Expand All @@ -112,7 +111,7 @@ fun awsServiceProjections(): Provider<List<SmithyProjection>> {
it.map { service ->
SmithyProjection(
service.projectionName,
project.projectionRootDir(service.projectionName)
project.projectionRootDir(service.projectionName),
).apply {
val importPaths = mutableListOf(service.modelFile.absolutePath)
if (file(service.modelExtrasDir).exists()) {
Expand Down Expand Up @@ -238,7 +237,7 @@ fun ServiceShape.protocol(): String =
"aws.protocols#awsQuery",
"aws.protocols#ec2Query",
"aws.protocols#restJson1",
"aws.protocols#restXml"
"aws.protocols#restXml",
).first { protocol -> findTrait(protocol).isPresent }.split("#")[1]

// Class and functions for service and protocol membership for SDK generation
Expand Down Expand Up @@ -281,22 +280,22 @@ fun String.kotlinNamespace(): String = split(".")
* NOTE: this will also be the artifact name in the GAV coordinates
*/
val AwsService.destinationDir: String
get(){
get() {
val sanitizedName = sdkId.replace(" ", "").replace("-", "").toLowerCase()
return rootProject.file("services/${sanitizedName}").absolutePath
return rootProject.file("services/$sanitizedName").absolutePath
}

/**
* Service specific model extras
*/
val AwsService.modelExtrasDir: String
get() = rootProject.file("${destinationDir}/model").absolutePath
get() = rootProject.file("$destinationDir/model").absolutePath

/**
* Defines where service-specific transforms are located
*/
val AwsService.transformsDir: String
get() = rootProject.file("${destinationDir}/transforms").absolutePath
get() = rootProject.file("$destinationDir/transforms").absolutePath

fun forwardProperty(name: String) {
getProperty(name)?.let {
Expand Down Expand Up @@ -340,7 +339,6 @@ tasks.register("bootstrap") {
finalizedBy(stageSdks)
}


/**
* Represents a type for a model that is sourced from aws-models
*/
Expand All @@ -356,7 +354,7 @@ data class SourceModel(
/**
* The service version from the model
*/
val version: String
val version: String,
) {
/**
* The model filename in aws-sdk-kotlin
Expand All @@ -374,7 +372,6 @@ fun discoverSourceModels(repoPath: String): List<SourceModel> {
?.map { Paths.get(it.absolutePath, "smithy", "model.json").toFile() }
?.filter { it.exists() } ?: error("no models found in $root")


return models.map { file ->
val model = Model.assembler().addImport(file.absolutePath).assemble().result.get()
val services: List<ServiceShape> = model.shapes(ServiceShape::class.java).sorted().toList()
Expand All @@ -387,7 +384,6 @@ fun discoverSourceModels(repoPath: String): List<SourceModel> {
}
}


fun discoverAwsModelsRepoPath(): String? {
val discovered = rootProject.file("../aws-models")
if (discovered.exists()) return discovered.absolutePath
Expand Down Expand Up @@ -422,7 +418,7 @@ tasks.register("syncAwsModels") {

// sync known existing models
val pairs = existingModelsBySdkId.values.mapNotNull { existing ->
sourceModelsBySdkId[existing.sdkId]?.let { source -> Pair(source, existing)}
sourceModelsBySdkId[existing.sdkId]?.let { source -> Pair(source, existing) }
}

val modelsDir = project.file("aws-models")
Expand Down Expand Up @@ -454,7 +450,6 @@ tasks.register("syncAwsModels") {
}
}


// generate warnings at the end so they are more visible
if (orphaned.isNotEmpty() || newSources.isNotEmpty()) {
println("\nWarnings:")
Expand Down
1 change: 0 additions & 1 deletion gradle/sdk-plugins/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -50,4 +50,3 @@ gradlePlugin {
}
}
}

2 changes: 1 addition & 1 deletion gradle/sdk-plugins/settings.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
* SPDX-License-Identifier: Apache-2.0
*/
rootProject.name = "sdk-plugins"
rootProject.name = "sdk-plugins"
2 changes: 1 addition & 1 deletion services/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ subprojects {
sourceSets {
all {
val srcDir = if (name.endsWith("Main")) "src" else "test"
val resourcesPrefix = if (name.endsWith("Test")) "test-" else ""
val resourcesPrefix = if (name.endsWith("Test")) "test-" else ""
// the name is always the platform followed by a suffix of either "Main" or "Test" (e.g. jvmMain, commonTest, etc)
val platform = name.substring(0, name.length - 4)
kotlin.srcDir("$platform/$srcDir")
Expand Down
Loading