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: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]