damondouglas commented on code in PR #24874:
URL: https://github.com/apache/beam/pull/24874#discussion_r1093449668


##########
playground/backend/internal/code_processing/code_processing.go:
##########
@@ -172,7 +172,11 @@ func compileStep(ctx context.Context, cacheService 
cache.Cache, paths *fs_tool.L
                        return nil
                }
        } else { // in case of Java, Go (not unit test), Scala - need compile 
step
-               executorBuilder := builder.Compiler(paths, sdkEnv)
+               executorBuilder, err := builder.Compiler(paths, sdkEnv)

Review Comment:
   The fact that we see logging of an error and not returning it makes this 
method difficult to test.
   The `compileStep` method signature should not have a `pipelineLifeCycleCtx 
context.Context` at the end. Typically context.Context is the first method 
argument.  I realize this is not part of the PR but it is making updates to 
this code more challenging.  Perhaps consider refactoring the method to do 
something like https://go.dev/play/p/f4fn1Scx1vE.



##########
playground/backend/internal/fs_tool/java_fs.go:
##########
@@ -52,27 +58,102 @@ func executableName(executableFileFolderPath string) 
(string, error) {
        }
 
        if len(dirEntries) == 1 {
-               return strings.Split(dirEntries[0].Name(), ".")[0], nil
+               return utils.TrimExtension(dirEntries[0].Name()), nil
        }
 
        for _, entry := range dirEntries {
-               content, err := ioutil.ReadFile(fmt.Sprintf("%s/%s", 
executableFileFolderPath, entry.Name()))
+               filePath := fmt.Sprintf("%s/%s", executableFileFolderPath, 
entry.Name())
+               content, err := os.ReadFile(filePath)
                if err != nil {
                        logger.Error(fmt.Sprintf("error during file reading: 
%s", err.Error()))
                        break
                }
-               ext := strings.Split(entry.Name(), ".")[1]
-               sdk := utils.ToSDKFromExt("." + ext)
+               ext := filepath.Ext(entry.Name())
+               filename := strings.TrimSuffix(entry.Name(), ext)
+               sdk := utils.ToSDKFromExt(ext)
 
                if sdk == pb.Sdk_SDK_UNSPECIFIED {
-                       logger.Error("invalid a file extension")
+                       logger.Error("invalid file extension")
                        break
                }
 
-               if utils.IsFileMain(string(content), sdk) {
-                       return strings.Split(entry.Name(), ".")[0], nil
+               switch ext {
+               case javaCompiledFileExtension:
+                       isMain, err := isMainClass(executableFileFolderPath, 
filename)
+                       if err != nil {
+                               return "", err
+                       }
+                       if isMain {
+                               logger.Infof("executableName(): main file is 
%s", filename)
+                               return filename, nil
+                       }
+               default:
+                       if utils.IsFileMain(string(content), sdk) {
+                               return filename, nil
+                       }
                }
+
+       }
+
+       return "", errors.New("cannot find file with main() method")
+}
+
+func testExecutableName(executableFileFolderPath string) (string, error) {

Review Comment:
   I was confused by the name of this method and its purpose.  What about 
`findExecutableName`?  Also, what if finding this file takes a long time?  
Should there be a context.WithTimeout?



-- 
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