gemini-code-assist[bot] commented on code in PR #36255:
URL: https://github.com/apache/beam/pull/36255#discussion_r2373655377


##########
examples/java/iceberg/build.gradle:
##########
@@ -87,3 +87,41 @@ dependencies {
     runtimeOnly project(path: project.getProperty("runnerDependency"))
   }
 }
+
+/*
+ * A convenient task to run individual example directly on Beam repo.
+ *
+ * Usage:
+ * ./gradlew :examples:java:iceberg:execute 
-PmainClass=org.apache.beam.examples.iceberg.<ClassName>`\
+ *  
-Pexec.args="runner=[DataflowRunner|DirectRunner|FlinkRunner|SparkRunner|PrismRunner]
 \
+ * <pipeline options>"
+ */
+tasks.create(name:"execute", type:JavaExec) {
+  mainClass = project.hasProperty("mainClass") ? 
project.getProperty("mainClass") : "NONE"
+  def execArgs =  project.findProperty("exec.args")
+  String runner
+  if (execArgs) {
+    // configure runner dependency from args
+    def runnerPattern = /runner[ =]([A-Za-z]+)/
+    def matcher = execArgs =~ runnerPattern
+    if (matcher) {
+      runner = matcher[0][1]
+      runner = runner.substring(0, 1).toLowerCase() + runner.substring(1);

Review Comment:
   ![medium](https://www.gstatic.com/codereviewagent/medium-priority.svg)
   
   For better readability and to use a more idiomatic Groovy approach, you can 
use the `uncapitalize()` method to convert the first letter of the string to 
lowercase.
   
   ```
         runner = runner.uncapitalize();
   ```



##########
examples/java/iceberg/build.gradle:
##########
@@ -87,3 +87,41 @@ dependencies {
     runtimeOnly project(path: project.getProperty("runnerDependency"))
   }
 }
+
+/*
+ * A convenient task to run individual example directly on Beam repo.
+ *
+ * Usage:
+ * ./gradlew :examples:java:iceberg:execute 
-PmainClass=org.apache.beam.examples.iceberg.<ClassName>`\
+ *  
-Pexec.args="runner=[DataflowRunner|DirectRunner|FlinkRunner|SparkRunner|PrismRunner]
 \
+ * <pipeline options>"
+ */
+tasks.create(name:"execute", type:JavaExec) {
+  mainClass = project.hasProperty("mainClass") ? 
project.getProperty("mainClass") : "NONE"

Review Comment:
   ![medium](https://www.gstatic.com/codereviewagent/medium-priority.svg)
   
   It's better to fail early with a clear error message if the `mainClass` 
property is not provided. The current implementation sets it to "NONE", which 
will lead to a less intuitive error message from the `JavaExec` task. Using the 
Elvis operator with `throw` makes the check concise and idiomatic.
   
   ```
     mainClass = project.findProperty("mainClass") ?: throw new 
GradleException("The 'mainClass' property is required. Please specify it using 
-PmainClass=<your.main.Class>")
   ```



-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to