This is an automated email from the ASF dual-hosted git repository. tsato pushed a commit to branch main in repository https://gitbox.apache.org/repos/asf/camel-k.git
commit 214acdc1feb8b80ee8873b1c8d12f04ab855e291 Author: Tadayoshi Sato <sato.tadayo...@gmail.com> AuthorDate: Tue Mar 1 20:59:59 2022 +0900 fix(cli): kamel local run with integration dir outside of current dir --- e2e/local/local_run_test.go | 3 +++ pkg/cmd/local_run.go | 25 ++++++------------- pkg/cmd/util_commands.go | 2 +- pkg/cmd/util_dependencies.go | 59 ++++++++++++++------------------------------ 4 files changed, 31 insertions(+), 58 deletions(-) diff --git a/e2e/local/local_run_test.go b/e2e/local/local_run_test.go index 6eeb00d..4a8b1a0 100644 --- a/e2e/local/local_run_test.go +++ b/e2e/local/local_run_test.go @@ -120,5 +120,8 @@ func TestLocalRunIntegrationDirectory(t *testing.T) { cancel2() }() + Eventually(dir+"/../quarkus", TestTimeoutShort).Should(BeADirectory()) + Eventually(dir+"/../app", TestTimeoutShort).Should(BeADirectory()) + Eventually(dir+"/../lib", TestTimeoutShort).Should(BeADirectory()) Eventually(logScanner.IsFound("Magicstring!"), TestTimeoutMedium).Should(BeTrue()) } diff --git a/pkg/cmd/local_run.go b/pkg/cmd/local_run.go index 696704a..a1cf21a 100644 --- a/pkg/cmd/local_run.go +++ b/pkg/cmd/local_run.go @@ -169,34 +169,25 @@ func (command *localRunCmdOptions) run(cmd *cobra.Command, args []string) error localDependenciesDirectory := getCustomDependenciesDir(command.IntegrationDirectory) // The quarkus application files need to be at a specific location i.e.: - // <current_working_folder>/quarkus/quarkus-application.dat - // <current_working_folder>/quarkus/generated-bytecode.jar - localQuarkusDir, err := getCustomQuarkusDir() - if err != nil { - return err - } + // <integration_directory>/../quarkus/quarkus-application.dat + // <integration_directory>/../quarkus/generated-bytecode.jar + localQuarkusDir := getCustomQuarkusDir(command.IntegrationDirectory) err = util.CopyQuarkusAppFiles(localDependenciesDirectory, localQuarkusDir) if err != nil { return err } // The dependency jar files need to be at a specific location i.e.: - // <current_working_folder>/lib/main/*.jar - localLibDirectory, err := getCustomLibDir() - if err != nil { - return err - } + // <integration_directory>/../lib/main/*.jar + localLibDirectory := getCustomLibDir(command.IntegrationDirectory) err = util.CopyLibFiles(localDependenciesDirectory, localLibDirectory) if err != nil { return err } // The Camel K jar file needs to be at a specific location i.e.: - // <current_working_folder>/app/camel-k-integration-X.X.X{-SNAPSHOT}.jar - localAppDirectory, err := getCustomAppDir() - if err != nil { - return err - } + // <integration_directory>/../app/camel-k-integration-X.X.X{-SNAPSHOT}.jar + localAppDirectory := getCustomAppDir(command.IntegrationDirectory) err = util.CopyAppFile(localDependenciesDirectory, localAppDirectory) if err != nil { return err @@ -277,7 +268,7 @@ func (command *localRunCmdOptions) deinit() error { } if command.IntegrationDirectory != "" { - err := deleteLocalIntegrationDirs() + err := deleteLocalIntegrationDirs(command.IntegrationDirectory) if err != nil { return err } diff --git a/pkg/cmd/util_commands.go b/pkg/cmd/util_commands.go index c7c3605..15a14c8 100644 --- a/pkg/cmd/util_commands.go +++ b/pkg/cmd/util_commands.go @@ -108,7 +108,7 @@ func RunLocalIntegrationRunCommand(ctx context.Context, properties []string, dep } // Output command we are about to run. - fmt.Printf("Executing: %s", strings.Join(cmd.Args, " ")) + fmt.Printf("Executing: %s\n", strings.Join(cmd.Args, " ")) // Run integration locally. err = cmd.Run() diff --git a/pkg/cmd/util_dependencies.go b/pkg/cmd/util_dependencies.go index 1409d7d..dfabb92 100644 --- a/pkg/cmd/util_dependencies.go +++ b/pkg/cmd/util_dependencies.go @@ -497,54 +497,33 @@ func getCustomRoutesDir(integrationDirectory string) string { return path.Join(integrationDirectory, "routes") } -func getCustomQuarkusDir() (string, error) { - currentDir, err := os.Getwd() - if err != nil { - return "", err - } - return path.Join(currentDir, "quarkus"), nil +func getCustomQuarkusDir(integrationDirectory string) string { + parentDir := path.Dir(strings.TrimSuffix(integrationDirectory, "/")) + return path.Join(parentDir, "quarkus") } -func getCustomLibDir() (string, error) { - currentDir, err := os.Getwd() - if err != nil { - return "", err - } - return path.Join(currentDir, "lib/main"), nil +func getCustomLibDir(integrationDirectory string) string { + parentDir := path.Dir(strings.TrimSuffix(integrationDirectory, "/")) + return path.Join(parentDir, "lib/main") } -func getCustomAppDir() (string, error) { - currentDir, err := os.Getwd() - if err != nil { - return "", err - } - return path.Join(currentDir, "app"), nil +func getCustomAppDir(integrationDirectory string) string { + parentDir := path.Dir(strings.TrimSuffix(integrationDirectory, "/")) + return path.Join(parentDir, "app") } -func deleteLocalIntegrationDirs() error { - directory, err := getCustomQuarkusDir() - if err != nil { - return err - } - - err = os.RemoveAll(directory) - if err != nil { - return err +func deleteLocalIntegrationDirs(integrationDirectory string) error { + dirs := []string{ + getCustomQuarkusDir(integrationDirectory), + getCustomLibDir(integrationDirectory), + getCustomAppDir(integrationDirectory), } - err = os.RemoveAll("lib") - if err != nil { - return err - } - - directory, err = getCustomAppDir() - if err != nil { - return err - } - - err = os.RemoveAll(directory) - if err != nil { - return err + for _, dir := range dirs { + err := os.RemoveAll(dir) + if err != nil { + return err + } } return nil