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 2019/01/23 14:54:40 UTC

[camel-k] branch master updated: Allow to configure the location fo the local maven repo #358

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


The following commit(s) were added to refs/heads/master by this push:
     new dbc8a6c  Allow to configure the location fo the local maven repo #358
dbc8a6c is described below

commit dbc8a6c70fdf97f219b33f0996436ea5ae2c9e92
Author: lburgazzoli <lb...@gmail.com>
AuthorDate: Tue Jan 22 16:22:56 2019 +0100

    Allow to configure the location fo the local maven repo #358
---
 deploy/platform-cr.yaml                              |  1 +
 deploy/resources.go                                  |  1 +
 pkg/apis/camel/v1alpha1/integrationplatform_types.go |  1 +
 pkg/builder/builder_steps.go                         |  6 ++++--
 pkg/cmd/install.go                                   |  5 +++++
 pkg/trait/rest.go                                    | 10 ++++++----
 pkg/util/maven/maven.go                              | 15 ++++++---------
 7 files changed, 24 insertions(+), 15 deletions(-)

diff --git a/deploy/platform-cr.yaml b/deploy/platform-cr.yaml
index e92676b..8f9b3e6 100644
--- a/deploy/platform-cr.yaml
+++ b/deploy/platform-cr.yaml
@@ -8,3 +8,4 @@ spec:
   build:
     camelVersion: "2.23.1"
     baseImage: "fabric8/s2i-java:3.0-java8"
+    localRepository: "/tmp/artifacts/m2"
diff --git a/deploy/resources.go b/deploy/resources.go
index 68cfc91..2a0028e 100644
--- a/deploy/resources.go
+++ b/deploy/resources.go
@@ -3342,6 +3342,7 @@ spec:
   build:
     camelVersion: "2.23.1"
     baseImage: "fabric8/s2i-java:3.0-java8"
+    localRepository: "/tmp/artifacts/m2"
 
 `
 	Resources["platform-integration-context-groovy.yaml"] =
diff --git a/pkg/apis/camel/v1alpha1/integrationplatform_types.go b/pkg/apis/camel/v1alpha1/integrationplatform_types.go
index c70281d..e2c94f0 100644
--- a/pkg/apis/camel/v1alpha1/integrationplatform_types.go
+++ b/pkg/apis/camel/v1alpha1/integrationplatform_types.go
@@ -78,6 +78,7 @@ type IntegrationPlatformBuildSpec struct {
 	CamelVersion    string                                  `json:"camelVersion,omitempty"`
 	BaseImage       string                                  `json:"baseImage,omitempty"`
 	Properties      map[string]string                       `json:"properties,omitempty"`
+	LocalRepository string                                  `json:"localRepository,omitempty"`
 	Repositories    []string                                `json:"repositories,omitempty"`
 }
 
diff --git a/pkg/builder/builder_steps.go b/pkg/builder/builder_steps.go
index 876647f..555befc 100644
--- a/pkg/builder/builder_steps.go
+++ b/pkg/builder/builder_steps.go
@@ -111,9 +111,11 @@ func ComputeDependencies(ctx *Context) error {
 		return err
 	}
 
-	goal := fmt.Sprintf("org.apache.camel.k:camel-k-maven-plugin:%s:generate-dependency-list", version.Version)
+	opts := make([]string, 0, 2)
+	opts = append(opts, maven.ExtraOptions(ctx.Request.Platform.Build)...)
+	opts = append(opts, fmt.Sprintf("org.apache.camel.k:camel-k-maven-plugin:%s:generate-dependency-list", version.Version))
 
-	err = maven.Run(p, goal)
+	err = maven.Run(p, opts...)
 	if err != nil {
 		return errors.Wrap(err, "failure while determining classpath")
 	}
diff --git a/pkg/cmd/install.go b/pkg/cmd/install.go
index 48792f9..2b54d8c 100644
--- a/pkg/cmd/install.go
+++ b/pkg/cmd/install.go
@@ -52,6 +52,7 @@ func newCmdInstall(rootCmdOptions *RootCmdOptions) *cobra.Command {
 	cmd.Flags().StringVar(&impl.organization, "organization", "", "A organization on the Docker registry that can be used to publish images")
 	cmd.Flags().StringVar(&impl.pushSecret, "push-secret", "", "A secret used to push images to the Docker registry")
 	cmd.Flags().StringSliceVar(&impl.repositories, "repository", nil, "Add a maven repository")
+	cmd.Flags().StringVar(&impl.localRepository, "local-repository", "", "Location of the local maven repository")
 	cmd.Flags().StringSliceVarP(&impl.properties, "property", "p", nil, "Add a camel property")
 	cmd.Flags().StringVar(&impl.camelVersion, "camel-version", "", "Set the camel version")
 	cmd.Flags().StringVar(&impl.baseImage, "base-image", "", "Set the base image used to run integrations")
@@ -81,6 +82,7 @@ type installCmdOptions struct {
 	pushSecret       string
 	camelVersion     string
 	baseImage        string
+	localRepository  string
 	repositories     []string
 	properties       []string
 	contexts         []string
@@ -140,6 +142,9 @@ func (o *installCmdOptions) install(cmd *cobra.Command, args []string) error {
 				}
 			}
 		}
+		if o.localRepository != "" {
+			platform.Spec.Build.LocalRepository = o.localRepository
+		}
 		if len(o.repositories) > 0 {
 			platform.Spec.Build.Repositories = o.repositories
 		}
diff --git a/pkg/trait/rest.go b/pkg/trait/rest.go
index 8001373..a8596f7 100644
--- a/pkg/trait/rest.go
+++ b/pkg/trait/rest.go
@@ -99,11 +99,13 @@ func (t *restTrait) Apply(e *Environment) error {
 			return err
 		}
 
-		goal := fmt.Sprintf("org.apache.camel.k:camel-k-maven-plugin:%s:generate-rest-xml", version.Version)
-		iArg := "-Dopenapi.spec=" + in
-		oArg := "-Ddsl.out=" + out
+		opts := make([]string, 0, 4)
+		opts = append(opts, maven.ExtraOptions(e.Platform.Spec.Build)...)
+		opts = append(opts, fmt.Sprintf("org.apache.camel.k:camel-k-maven-plugin:%s:generate-rest-xml", version.Version))
+		opts = append(opts, "-Dopenapi.spec="+in)
+		opts = append(opts, "-Ddsl.out="+out)
 
-		if err := maven.Run(tmpDir, goal, iArg, oArg); err != nil {
+		if err := maven.Run(tmpDir, opts...); err != nil {
 			return err
 		}
 
diff --git a/pkg/util/maven/maven.go b/pkg/util/maven/maven.go
index c2a90d1..782cb83 100644
--- a/pkg/util/maven/maven.go
+++ b/pkg/util/maven/maven.go
@@ -80,11 +80,7 @@ func Run(buildDir string, args ...string) error {
 		"logger": "maven",
 	})
 
-	cmdArgs := make([]string, 0, 1+len(args))
-	cmdArgs = append(cmdArgs, extraOptions())
-	cmdArgs = append(cmdArgs, args...)
-
-	cmd := exec.Command(mvnCmd, cmdArgs...)
+	cmd := exec.Command(mvnCmd, args...)
 	cmd.Dir = buildDir
 	cmd.Stdout = os.Stdout
 	cmd.Stderr = os.Stderr
@@ -126,9 +122,10 @@ func ParseGAV(gav string) (Dependency, error) {
 	return dep, nil
 }
 
-func extraOptions() string {
-	if _, err := os.Stat("/tmp/artifacts/m2"); err == nil {
-		return "-Dmaven.repo.local=/tmp/artifacts/m2"
+// ExtraOptions --
+func ExtraOptions(spec v1alpha1.IntegrationPlatformBuildSpec) []string {
+	if _, err := os.Stat(spec.LocalRepository); err == nil {
+		return []string{"-Dmaven.repo.local=" + spec.LocalRepository}
 	}
-	return "-Dcamel.noop=true"
+	return []string{"-Dcamel.noop=true"}
 }