You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@beam.apache.org by "TSultanov (via GitHub)" <gi...@apache.org> on 2023/02/02 10:52:13 UTC

[GitHub] [beam] TSultanov commented on a diff in pull request #24874: [Playground] Implement Java & Go multifile examples execution

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


##########
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:
   Improved naming and passed context into the functions to support timeouts



-- 
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: github-unsubscribe@beam.apache.org

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