HoustonPutman commented on code in PR #1793:
URL: https://github.com/apache/solr/pull/1793#discussion_r1588028324


##########
solr/solrj/build.gradle:
##########
@@ -85,3 +94,73 @@ dependencies {
   testImplementation 'org.apache.commons:commons-lang3'
   testImplementation 'io.dropwizard.metrics:metrics-core'
 }
+
+/**
+ * Java Code Generation for Solr API
+ */
+
+evaluationDependsOn(":solr:api")
+
+configurations {
+  openApiSpecFile {
+    canBeConsumed = false
+  }
+}
+
+ext {
+  generatedCodeDir = "${buildDir}/generated/"
+  javaTemplateDir = "${projectDir}/src/resources/java-template"
+}
+
+dependencies {
+  openApiSpecFile(project(path: ":solr:api", configuration: "openapiSpec"))
+}
+
+/**
+ * Code Generation task
+ */
+openApiGenerate {
+  generatorName = "java"
+  inputSpec = project(":solr:api").openApiSpecFile
+
+  // Add 'debugModels: ""' or 'debugOperations: ""' to get the JSON input to 
mustache templating for those components
+  globalProperties.set([apis: "", models: "false"])
+  templateDir = project.javaTemplateDir
+  apiPackage = "org.apache.solr.client.solrj.request"
+  outputDir = project.generatedCodeDir
+  generateApiTests = false
+  generateModelTests = false
+  generateApiDocumentation = false
+  generateModelDocumentation = false
+  additionalProperties = ["modelPackage": "org.apache.solr.client.api.model"]
+}
+
+tasks.openApiGenerate.dependsOn configurations.openApiSpecFile
+
+def generatedFiles = files("${project.generatedCodeDir}/src/main/java") {
+  builtBy tasks.openApiGenerate
+}
+
+/**
+ * Setup Spotless (Code formatting) for the generated java files
+ */
+def generatedExt = new JavaExtension(spotless)
+project.spotlessJavaSetup.execute(generatedExt)
+generatedExt.target(generatedFiles)
+def generatedSpotlessTask = 
generatedExt.createIndependentApplyTask("generatedSpotless")
+generatedSpotlessTask.group("build")
+generatedSpotlessTask.description("Apply formatting for generated code")
+
+tasks.openApiGenerate.finalizedBy generatedSpotlessTask
+

Review Comment:
   > An ideal Gradle file is declarative yet this code is as imperative as can 
be.
   
   So this is imperative code that is creating declarative tasks. Which is 
something very well supported in Gradle.
   If you want to share the chatGPT suggestions, I'm happy to take a look, but 
this was very hard to get working well in the first place, so I'd be surprised 
if chatGPT gives us something that works.
   
   > There is something missing here:
   `generatedSpotlessTask.dependsOn(':checkJdkInternalsExportedToGradle')`
   
   Yes, but ideally we just fix `spotless.gradle` to not require that a 
spottless task be named a certain way. we can instead see all the tasks that 
are of type `SpotlessApply`.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscr...@solr.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscr...@solr.apache.org
For additional commands, e-mail: issues-h...@solr.apache.org

Reply via email to