You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by nf...@apache.org on 2020/11/17 10:46:39 UTC

[camel-k] 05/12: Ensure Maven working directory is kept until after the integration is run.

This is an automated email from the ASF dual-hosted git repository.

nferraro pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/camel-k.git

commit a62cdf4627e58e9cd8a8e354648104bc0c177947
Author: Doru Bercea <gh...@ibm.com>
AuthorDate: Tue Nov 10 12:52:47 2020 -0500

    Ensure Maven working directory is kept until after the integration is run.
---
 pkg/builder/runtime/quarkus.go |  9 +++++++++
 pkg/cmd/inspect.go             | 14 ++++++++++++++
 pkg/cmd/local_run.go           | 14 ++++++++++++++
 pkg/cmd/util_dependencies.go   | 35 +++++++++++++++++++++++++----------
 4 files changed, 62 insertions(+), 10 deletions(-)

diff --git a/pkg/builder/runtime/quarkus.go b/pkg/builder/runtime/quarkus.go
index a98faba..dbc3e33 100644
--- a/pkg/builder/runtime/quarkus.go
+++ b/pkg/builder/runtime/quarkus.go
@@ -259,5 +259,14 @@ func ProcessQuarkusTransitiveDependencies(mc maven.Context, content []byte) ([]v
 		Checksum: "sha1:" + runnerChecksum,
 	})
 
+	// currentpath, errr := os.Getwd()
+	// if errr != nil {
+	// 	return nil, errr
+	// }
+	// _, err = util.CopyFile(path.Join(mc.Path, "target", runner), path.Join(currentpath, runner))
+	// if err != nil {
+	// 	return nil, err
+	// }
+
 	return artifacts, nil
 }
diff --git a/pkg/cmd/inspect.go b/pkg/cmd/inspect.go
index e524e56..9967cfd 100644
--- a/pkg/cmd/inspect.go
+++ b/pkg/cmd/inspect.go
@@ -40,9 +40,15 @@ will be generated by calling Maven and then printed in the selected output forma
 			if err := options.validate(args); err != nil {
 				return err
 			}
+			if err := options.init(); err != nil {
+				return err
+			}
 			if err := options.run(args); err != nil {
 				fmt.Println(err.Error())
 			}
+			if err := options.deinit(); err != nil {
+				return err
+			}
 
 			return nil
 		},
@@ -71,6 +77,10 @@ func (command *inspectCmdOptions) validate(args []string) error {
 	return validateIntegrationForDependencies(args, command.AdditionalDependencies)
 }
 
+func (command *inspectCmdOptions) init() error {
+	return createMavenWorkingDirectory()
+}
+
 func (command *inspectCmdOptions) run(args []string) error {
 	// Fetch dependencies.
 	dependencies, err := getDependencies(args, command.AdditionalDependencies, command.AllDependencies)
@@ -86,3 +96,7 @@ func (command *inspectCmdOptions) run(args []string) error {
 
 	return nil
 }
+
+func (command *inspectCmdOptions) deinit() error {
+	return deleteMavenWorkingDirectory()
+}
diff --git a/pkg/cmd/local_run.go b/pkg/cmd/local_run.go
index a76daa3..2031e52 100644
--- a/pkg/cmd/local_run.go
+++ b/pkg/cmd/local_run.go
@@ -38,9 +38,15 @@ func newCmdLocalRun(rootCmdOptions *RootCmdOptions) (*cobra.Command, *localRunCm
 			if err := options.validate(args); err != nil {
 				return err
 			}
+			if err := options.init(); err != nil {
+				return err
+			}
 			if err := options.run(args); err != nil {
 				fmt.Println(err.Error())
 			}
+			if err := options.deinit(); err != nil {
+				return err
+			}
 
 			return nil
 		},
@@ -87,6 +93,10 @@ func (command *localRunCmdOptions) validate(args []string) error {
 	return nil
 }
 
+func (command *localRunCmdOptions) init() error {
+	return createMavenWorkingDirectory()
+}
+
 func (command *localRunCmdOptions) run(args []string) error {
 	// Fetch dependencies.
 	dependencies, err := getDependencies(args, command.AdditionalDependencies, true)
@@ -108,3 +118,7 @@ func (command *localRunCmdOptions) run(args []string) error {
 
 	return nil
 }
+
+func (command *localRunCmdOptions) deinit() error {
+	return deleteMavenWorkingDirectory()
+}
diff --git a/pkg/cmd/util_dependencies.go b/pkg/cmd/util_dependencies.go
index 49d0d07..cd29a3e 100644
--- a/pkg/cmd/util_dependencies.go
+++ b/pkg/cmd/util_dependencies.go
@@ -35,6 +35,10 @@ import (
 	"github.com/scylladb/go-set/strset"
 )
 
+// Directory used by Maven for an invocation of the kamel local command.
+// By default a temporary folder will be used.
+var mavenWorkingDirectory string = ""
+
 var acceptedDependencyTypes = []string{"bom", "camel", "camel-k", "camel-quarkus", "mvn", "github"}
 
 const defaultDependenciesDirectoryName = "dependencies"
@@ -112,14 +116,8 @@ func getTransitiveDependencies(
 		return nil, err
 	}
 
-	// Create local Maven context.
-	temporaryDirectory, err := ioutil.TempDir(os.TempDir(), "maven-")
-	if err != nil {
-		return nil, err
-	}
-
 	// Maven local context to be used for generating the transitive dependencies.
-	mc := maven.NewContext(temporaryDirectory, project)
+	mc := maven.NewContext(mavenWorkingDirectory, project)
 	mc.LocalRepository = mvn.LocalRepository
 	mc.Timeout = mvn.GetTimeout().Duration
 
@@ -150,9 +148,6 @@ func getTransitiveDependencies(
 		transitiveDependencies = append(transitiveDependencies, entry.Location)
 	}
 
-	// Remove directory used for computing the dependencies.
-	defer os.RemoveAll(temporaryDirectory)
-
 	return transitiveDependencies, nil
 }
 
@@ -301,3 +296,23 @@ func validateIntegrationForDependencies(args []string, additionalDependencies []
 
 	return nil
 }
+
+func createMavenWorkingDirectory() error {
+	// Create local Maven context.
+	temporaryDirectory, err := ioutil.TempDir(os.TempDir(), "maven-")
+	if err != nil {
+		return err
+	}
+
+	// Set the Maven directory to the default value.
+	mavenWorkingDirectory = temporaryDirectory
+
+	return nil
+}
+
+func deleteMavenWorkingDirectory() error {
+	// Remove directory used for computing the dependencies.
+	defer os.RemoveAll(mavenWorkingDirectory)
+
+	return nil
+}