-
Notifications
You must be signed in to change notification settings - Fork 434
Generate accessors for ArtifactHandler
#1020
Generate accessors for ArtifactHandler
#1020
Conversation
This doesn't entirely address all use cases but hits some of them. For example, something like val myConfig by configurations.creating
artifacts {
myConfig(something)
} Wouldn't work (right now). Want me to tackle that in this MR or a different one? What are the desired supported DSL invocations? |
@mkobit Any chance this can be updated so that it can be merged? |
@JLLeitschuh I was going to wait for some feedback before I spent more time on this. I wasn't sure if the direction going forward is to use |
@mkobit, the target code changed a lot, would you be willing to rebase on top of |
@eskatos yes, I'll try and tackle it in the next couple of days |
I'm trying to work through this now, but converting it to the I have, for the non- AccessorFragment(
source = name.run {
"""
/**
* Adds an artifact to the '$original' configuration.
*
* @param artifactNotation the group of the module to be added as a dependency.
* @return The artifact.
*
* @see [ArtifactHandler.add]
*/
fun ArtifactHandler.`$kotlinIdentifier`(artifactNotation: Any): PublishArtifact =
add("$stringLiteral", artifactNotation)
"""
},
bytecode = {
publicStaticMethod(signature) {
ALOAD(0)
LDC(name.original)
ALOAD(1)
INVOKEINTERFACE(GradleTypeName.artifactHandler, "add", "(Ljava/lang/String;Ljava/lang/Object;)Lorg/gradle/api/artifacts/PublishArtifact;")
ARETURN()
}
},
metadata = {
writer.writeFunctionOf(
receiverType = GradleType.artifactHandler,
returnType = GradleType.publishArtifact,
name = propertyName,
functionFlags = publicFunctionFlags,
parameters = {
visitParameter("artifactNotation", KotlinType.any)
},
signature = signature
)
},
signature = JvmMethodSignature(
name.original,
"(Lorg/gradle/api/artifacts/dsl/ArtifactHandler;Ljava/lang/Object;)Lorg/gradle/api/artifacts/PublishArtifact;"
)
) and testing that seems to work. Then, for the other method, I am obviously missing something: AccessorFragment(
source = name.run {
"""
/**
* Adds an artifact to the '$original' configuration.
*
* @param artifactNotation the group of the module to be added as a dependency.
* @param configureAction The action to execute to configure the artifact.
* @return The artifact.
*
* @see [ArtifactHandler.add]
*/
fun ArtifactHandler.`$kotlinIdentifier`(
artifactNotation: Any,
configureAction: ConfigurablePublishArtifact.() -> Unit): PublishArtifact =
add("$stringLiteral", artifactNotation, configureAction)
"""
},
bytecode = {
publicStaticMethod(signature) {
ALOAD(0)
LDC(propertyName)
ALOAD(1)
ALOAD(2)
INVOKEINTERFACE(GradleTypeName.artifactHandler, "add", "(Ljava/lang/String;Ljava/lang/Object;Lorg/gradle/api/Action;)Lorg/gradle/api/artifacts/PublishArtifact;")
ARETURN()
}
},
metadata = {
writer.writeFunctionOf(
receiverType = GradleType.artifactHandler,
returnType = GradleType.publishArtifact,
name = propertyName,
functionFlags = publicFunctionFlags,
parameters = {
visitParameter("artifactNotation", KotlinType.any)
visitParameter("configureAction", actionTypeOf(GradleType.configurablePublishArtifact))
},
signature = signature
)
},
signature = JvmMethodSignature(
name.original,
"(Lorg/gradle/api/artifacts/dsl/ArtifactHandler;Ljava/lang/Object;Lkotlin/jvm/functions/Function1<-Lorg/gradle/api/artifacts/ConfigurablePublishArtifact;Lkotlin/Unit;>;)Lorg/gradle/api/artifacts/PublishArtifact;"
)
) leads to
Any suggestions for working through this? |
issue #889 Signed-off-by: Mike Kobit <[email protected]>
… {}` DSL block Signed-off-by: Mike Kobit <[email protected]>
Thanks for the tip @bamboo - I haven't dove deeply into JVM byte code operations before so I definitely learned a few things while working on this. I think this is in a ready-for-review state now. |
/** | ||
* Configures the artifacts. | ||
*/ | ||
inline operator fun invoke(configuration: ArtifactHandlerScope.() -> Unit) = |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does this return the PublishArtifact
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Returns Unit
like the DependencyHandlerScope
- I followed the same style that was there, but would be alright with marking the return as explicit
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's keep things uniform. If you feel strongly about it @JLLeitschuh, please open a separate issue with a motivation keeping api/dsl uniformity in mind.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was just checking, I couldn't tell from reading the code what was returned. I don't feel strongly either way.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
First review pass, I'll get back to this again later
...s/src/test/kotlin/org/gradle/kotlin/dsl/integration/ProjectSchemaAccessorsIntegrationTest.kt
Outdated
Show resolved
Hide resolved
...s/src/test/kotlin/org/gradle/kotlin/dsl/integration/ProjectSchemaAccessorsIntegrationTest.kt
Outdated
Show resolved
Hide resolved
...s/src/test/kotlin/org/gradle/kotlin/dsl/integration/ProjectSchemaAccessorsIntegrationTest.kt
Outdated
Show resolved
Hide resolved
subprojects/provider/src/main/kotlin/org/gradle/kotlin/dsl/accessors/AccessorsClassPath.kt
Show resolved
Hide resolved
subprojects/provider/src/main/kotlin/org/gradle/kotlin/dsl/accessors/CodeGenerator.kt
Outdated
Show resolved
Hide resolved
...s/src/test/kotlin/org/gradle/kotlin/dsl/integration/ProjectSchemaAccessorsIntegrationTest.kt
Show resolved
Hide resolved
/** | ||
* Configures the artifacts. | ||
*/ | ||
inline operator fun invoke(configuration: ArtifactHandlerScope.() -> Unit) = |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's keep things uniform. If you feel strongly about it @JLLeitschuh, please open a separate issue with a motivation keeping api/dsl uniformity in mind.
@mkobit DCO is failing on these, you may need to use an interactive rebase to add the sign-off on some of these commits. |
Thanks @JLLeitschuh - I guess I need a way to automate that... |
Signed-off-by: Mike Kobit <[email protected]>
Signed-off-by: Mike Kobit <[email protected]>
Signed-off-by: Mike Kobit <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you @mkobit!
issue #889
Signed-off-by: Mike Kobit [email protected]
Context
#889
Contributor Checklist
develop
branch./gradlew check --parallel