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


##########
playground/backend/internal/fs_tool/java_fs.go:
##########
@@ -52,27 +59,112 @@ 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()))
-               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)
+               select {
+               case <-ctx.Done():
+                       return "", ctx.Err()
+               default:
+                       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 := filepath.Ext(entry.Name())
+                       filename := strings.TrimSuffix(entry.Name(), ext)
+                       sdk := utils.ToSDKFromExt(ext)
+
+                       if sdk == pb.Sdk_SDK_UNSPECIFIED {
+                               logger.Error("invalid file extension")
+                               break
+                       }
 
-               if sdk == pb.Sdk_SDK_UNSPECIFIED {
-                       logger.Error("invalid a file extension")
-                       break
+                       switch ext {
+                       case javaCompiledFileExtension:
+                               isMain, err := isMainClass(ctx, 
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")
+}
+
+// findTestExecutableName returns name of .class file which has JUnit tests
+func findTestExecutableName(ctx context.Context, executableFileFolderPath 
string) (string, error) {
+       dirEntries, err := os.ReadDir(executableFileFolderPath)
+       if err != nil {
+               return "", err
+       }
+       if len(dirEntries) < 1 {
+               return "", errors.New("number of executable files should be at 
least one")
+       }
+
+       if len(dirEntries) == 1 {
+               return utils.TrimExtension(dirEntries[0].Name()), nil
+       }
+
+       for _, entry := range dirEntries {
+               select {
+               case <-ctx.Done():
+                       return "", ctx.Err()
+               default:
+                       if err != nil {

Review Comment:
   Removed the condition



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