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 2021/05/27 10:35:28 UTC

[camel-k] branch main updated (4788a21 -> e622575)

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

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


    from 4788a21  Updated CHANGELOG.md
     new 7ce7b01  refactor(trait): property names and error condition
     new eacd805  refactor(cmd/util): validateProperty files unit test
     new d5910ed  feat(cmd/run): build-property file support
     new e93afb2  doc(examples): build-property file support
     new 719b158  refactor(trait): property names and error condition
     new 0efff02  feat(run/property): new file format as build-property
     new e51e70d  refactor(examples): --property file: example
     new 552a51b  feat(e2e): runtime and build time property files test
     new d1eebeb  feat(cmd): modeline properties support
     new 0533bf1  chore(doc): modeline examples
     new e622575  chore(doc): modeline build-property and property updates

The 11 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 docs/modules/ROOT/pages/cli/modeline.adoc          |  8 +--
 e2e/common/config/config_test.go                   | 11 ++-
 ...ute.groovy => build-property-file-route.groovy} |  4 +-
 e2e/common/config/files/quarkus.properties         |  3 +
 .../modeline-build-property-file-route.groovy      |  6 +-
 .../modeline/modeline-build-property-route.groovy  |  4 +-
 .../modeline/modeline-property-file-route.groovy   |  6 +-
 .../modeline-property-route.groovy}                |  4 +-
 examples/modeline/quarkus.properties               |  3 +
 .../user-config/build-property-file-route.groovy   |  4 +-
 examples/user-config/property-file-route.groovy    |  2 +-
 examples/user-config/quarkus.properties            |  3 +
 pkg/cmd/modeline_test.go                           | 77 +++++++++++++++++++-
 pkg/cmd/run.go                                     | 83 +++++++++++++++++-----
 pkg/cmd/run_test.go                                | 47 +++++++++++-
 pkg/cmd/util_dependencies.go                       | 22 ++++--
 pkg/cmd/util_dependencies_test.go                  | 68 ++++++++++++++++++
 pkg/trait/builder.go                               |  1 +
 18 files changed, 313 insertions(+), 43 deletions(-)
 copy e2e/common/config/files/{build-property-route.groovy => build-property-file-route.groovy} (84%)
 create mode 100644 e2e/common/config/files/quarkus.properties
 copy e2e/common/config/files/build-property-route.groovy => examples/modeline/modeline-build-property-file-route.groovy (84%)
 copy e2e/common/config/files/build-property-route.groovy => examples/modeline/modeline-build-property-route.groovy (89%)
 copy e2e/common/config/files/property-route.groovy => examples/modeline/modeline-property-file-route.groovy (85%)
 copy examples/{user-config/property-route.groovy => modeline/modeline-property-route.groovy} (90%)
 create mode 100644 examples/modeline/quarkus.properties
 copy e2e/common/config/files/build-property-route.groovy => examples/user-config/build-property-file-route.groovy (84%)
 create mode 100644 examples/user-config/quarkus.properties
 create mode 100644 pkg/cmd/util_dependencies_test.go

[camel-k] 08/11: feat(e2e): runtime and build time property files test

Posted by nf...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

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

commit 552a51b71ccb13cc6675ef17b849305ff7ec5196
Author: Pasquale Congiusti <pa...@gmail.com>
AuthorDate: Mon May 24 16:43:45 2021 +0200

    feat(e2e): runtime and build time property files test
    
    Ref #2003
---
 e2e/common/config/config_test.go                   | 11 +++++++-
 .../config/files/build-property-file-route.groovy  | 29 ++++++++++++++++++++++
 e2e/common/config/files/quarkus.properties         |  3 +++
 pkg/cmd/run.go                                     |  4 ---
 pkg/trait/builder.go                               | 13 +---------
 5 files changed, 43 insertions(+), 17 deletions(-)

diff --git a/e2e/common/config/config_test.go b/e2e/common/config/config_test.go
index ece48fa..8512a46 100644
--- a/e2e/common/config/config_test.go
+++ b/e2e/common/config/config_test.go
@@ -50,7 +50,7 @@ func TestRunConfigExamples(t *testing.T) {
 		})
 
 		t.Run("Property file", func(t *testing.T) {
-			Expect(Kamel("run", "-n", ns, "./files/property-file-route.groovy", "--property-file", "./files/my.properties").Execute()).To(Succeed())
+			Expect(Kamel("run", "-n", ns, "./files/property-file-route.groovy", "--property", "file:./files/my.properties").Execute()).To(Succeed())
 			Eventually(IntegrationPodPhase(ns, "property-file-route"), TestTimeoutMedium).Should(Equal(v1.PodRunning))
 			Eventually(IntegrationCondition(ns, "property-file-route", camelv1.IntegrationConditionReady), TestTimeoutShort).Should(Equal(v1.ConditionTrue))
 			Eventually(IntegrationLogs(ns, "property-file-route"), TestTimeoutShort).Should(ContainSubstring("hello world"))
@@ -139,5 +139,14 @@ func TestRunConfigExamples(t *testing.T) {
 			Expect(IntegrationKit(ns, "build-property-route")).ShouldNot(Equal(IntegrationKit(ns, "build-property-route-updated")))
 			Expect(Kamel("delete", "--all", "-n", ns).Execute()).To(Succeed())
 		})
+
+		// Build-Properties file
+		t.Run("Build time property file", func(t *testing.T) {
+			Expect(Kamel("run", "-n", ns, "./files/build-property-file-route.groovy", "--build-property", "file:./files/quarkus.properties").Execute()).To(Succeed())
+			Eventually(IntegrationPodPhase(ns, "build-property-file-route"), TestTimeoutMedium).Should(Equal(v1.PodRunning))
+			Eventually(IntegrationCondition(ns, "build-property-file-route", camelv1.IntegrationConditionReady), TestTimeoutShort).Should(Equal(v1.ConditionTrue))
+			Eventually(IntegrationLogs(ns, "build-property-file-route"), TestTimeoutShort).Should(ContainSubstring("my-super-application"))
+			Expect(Kamel("delete", "--all", "-n", ns).Execute()).To(Succeed())
+		})
 	})
 }
diff --git a/e2e/common/config/files/build-property-file-route.groovy b/e2e/common/config/files/build-property-file-route.groovy
new file mode 100644
index 0000000..8427b48
--- /dev/null
+++ b/e2e/common/config/files/build-property-file-route.groovy
@@ -0,0 +1,29 @@
+// camel-k: language=groovy
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+//
+// Provide a build time configuration property file
+//
+// To run this integrations use:
+//
+// kamel run --build-property=file:quarkus.properties build-property-file-route.groovy --dev
+//
+
+from('timer:build-property')
+    .routeId('build-property')
+    .log('The application name: {{quarkus.application.name}}')
diff --git a/e2e/common/config/files/quarkus.properties b/e2e/common/config/files/quarkus.properties
new file mode 100644
index 0000000..882e2ab
--- /dev/null
+++ b/e2e/common/config/files/quarkus.properties
@@ -0,0 +1,3 @@
+quarkus.application.name = my-super-application
+quarkus.banner.enabled = true
+#some.other.configuration = commented!
\ No newline at end of file
diff --git a/pkg/cmd/run.go b/pkg/cmd/run.go
index 61ec35a..8f9c593 100644
--- a/pkg/cmd/run.go
+++ b/pkg/cmd/run.go
@@ -582,7 +582,6 @@ func (o *runCmdOptions) updateIntegrationCode(c client.Client, sources []string,
 	}
 	// convert each build configuration to a builder trait property
 	for _, item := range o.BuildProperties {
-<<<<<<< HEAD
 		props, err := extractProperties(item)
 		if err != nil {
 			return nil, err
@@ -595,9 +594,6 @@ func (o *runCmdOptions) updateIntegrationCode(c client.Client, sources []string,
 				return nil, err
 			}
 		}
-=======
-		o.Traits = append(o.Traits, fmt.Sprintf("builder.properties=%s", item))
->>>>>>> refactor(trait): property names and error condition
 	}
 	for _, item := range o.LoggingLevels {
 		integration.Spec.AddConfiguration("property", "logging.level."+item)
diff --git a/pkg/trait/builder.go b/pkg/trait/builder.go
index dacc00c..bc350c5 100644
--- a/pkg/trait/builder.go
+++ b/pkg/trait/builder.go
@@ -25,13 +25,7 @@ import (
 	v1 "github.com/apache/camel-k/pkg/apis/camel/v1"
 	"github.com/apache/camel-k/pkg/builder"
 	corev1 "k8s.io/api/core/v1"
-<<<<<<< HEAD
-<<<<<<< HEAD
 	metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
-=======
->>>>>>> refactor(trait): property names and error condition
-=======
->>>>>>> refactor(trait): property names and error condition
 )
 
 // The builder trait is internally used to determine the best strategy to
@@ -76,15 +70,10 @@ func (t *builderTrait) Apply(e *Environment) error {
 		e.IntegrationKit.Status.Phase = v1.IntegrationKitPhaseError
 		e.IntegrationKit.Status.SetCondition("IntegrationKitPropertiesFormatValid", corev1.ConditionFalse,
 			"IntegrationKitPropertiesFormatValid", fmt.Sprintf("One or more properties where not formatted as expected: %s", err.Error()))
-<<<<<<< HEAD
-<<<<<<< HEAD
 		if _, err := e.Client.CamelV1().IntegrationKits(e.IntegrationKit.Namespace).UpdateStatus(e.C, e.IntegrationKit, metav1.UpdateOptions{}); err != nil {
 			return err
 		}
-=======
->>>>>>> refactor(trait): property names and error condition
-=======
->>>>>>> refactor(trait): property names and error condition
+
 		return nil
 	}
 

[camel-k] 11/11: chore(doc): modeline build-property and property updates

Posted by nf...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

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

commit e622575e2dc4f1d1370ac962316b51a8ea64f949
Author: Pasquale Congiusti <pa...@gmail.com>
AuthorDate: Wed May 26 14:03:11 2021 +0200

    chore(doc): modeline build-property and property updates
    
    Ref #2003
---
 docs/modules/ROOT/pages/cli/modeline.adoc | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/docs/modules/ROOT/pages/cli/modeline.adoc b/docs/modules/ROOT/pages/cli/modeline.adoc
index c0f0ec6..243c795 100644
--- a/docs/modules/ROOT/pages/cli/modeline.adoc
+++ b/docs/modules/ROOT/pages/cli/modeline.adoc
@@ -66,6 +66,9 @@ The following is a partial list of useful options:
 |===
 |Option | Description
 
+|build-property
+|Add a build time property or properties file (syntax, my-key=my-value \| file:/path/to/my-conf.properties)"
+
 |dependency
 |An external library that should be included, e.g. for Maven dependencies `dependency=mvn:org.my:app:1.0`
 
@@ -85,10 +88,7 @@ The following is a partial list of useful options:
 |Trait profile used for deployment
 
 |property
-|Add a camel property
-
-|property-file
-|Bind a property file to the integration, e.g. `property-file=integration.properties`
+|Add a runtime property or properties file (syntax, my-key=my-value \| file:/path/to/my-conf.properties)
 
 |resource
 |Add a resource

[camel-k] 09/11: feat(cmd): modeline properties support

Posted by nf...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

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

commit d1eebeb54abd73898dd5a7930f6eb6d69cd10ca3
Author: Pasquale Congiusti <pa...@gmail.com>
AuthorDate: Wed May 26 14:02:26 2021 +0200

    feat(cmd): modeline properties support
    
    Ref #2003
---
 pkg/cmd/modeline_test.go | 77 ++++++++++++++++++++++++++++++++++++++++++++++--
 pkg/cmd/run.go           |  4 +--
 2 files changed, 77 insertions(+), 4 deletions(-)

diff --git a/pkg/cmd/modeline_test.go b/pkg/cmd/modeline_test.go
index e748e63..912e741 100644
--- a/pkg/cmd/modeline_test.go
+++ b/pkg/cmd/modeline_test.go
@@ -101,6 +101,28 @@ func TestModelineRunMultipleFiles(t *testing.T) {
 	assert.Equal(t, []string{"run", fileName, fileName2, "--dependency=mvn:org.my:lib1:3.0", "--dependency=mvn:org.my:lib2:3.0"}, flags)
 }
 
+func TestModelineRunProperty(t *testing.T) {
+	dir, err := ioutil.TempDir("", "camel-k-test-")
+	assert.NoError(t, err)
+	defer os.RemoveAll(dir)
+
+	subDir := path.Join(dir, "sub")
+	err = os.Mkdir(subDir, 0777)
+	assert.NoError(t, err)
+
+	file := `
+		// camel-k: property=my-prop=my-val
+	`
+	fileName := path.Join(subDir, "simple.groovy")
+	err = ioutil.WriteFile(fileName, []byte(file), 0777)
+	assert.NoError(t, err)
+
+	cmd, flags, err := NewKamelWithModelineCommand(context.TODO(), []string{"kamel", "run", fileName})
+	assert.NoError(t, err)
+	assert.NotNil(t, cmd)
+	assert.Equal(t, []string{"run", fileName, "--property=my-prop=my-val"}, flags)
+}
+
 func TestModelineRunPropertyFiles(t *testing.T) {
 	dir, err := ioutil.TempDir("", "camel-k-test-")
 	assert.NoError(t, err)
@@ -111,7 +133,58 @@ func TestModelineRunPropertyFiles(t *testing.T) {
 	assert.NoError(t, err)
 
 	file := `
-		// camel-k: property-file=../application.properties
+		// camel-k: property=file:application.properties
+	`
+	fileName := path.Join(subDir, "simple.groovy")
+	err = ioutil.WriteFile(fileName, []byte(file), 0777)
+	assert.NoError(t, err)
+
+	propFile := `
+		a=b
+	`
+	propFileName := path.Join(dir, "application.properties")
+	err = ioutil.WriteFile(propFileName, []byte(propFile), 0777)
+	assert.NoError(t, err)
+
+	cmd, flags, err := NewKamelWithModelineCommand(context.TODO(), []string{"kamel", "run", fileName})
+	assert.NoError(t, err)
+	assert.NotNil(t, cmd)
+	assert.Equal(t, []string{"run", fileName, "--property=file:application.properties"}, flags)
+}
+
+func TestModelineRunBuildProperty(t *testing.T) {
+	dir, err := ioutil.TempDir("", "camel-k-test-")
+	assert.NoError(t, err)
+	defer os.RemoveAll(dir)
+
+	subDir := path.Join(dir, "sub")
+	err = os.Mkdir(subDir, 0777)
+	assert.NoError(t, err)
+
+	file := `
+		// camel-k: build-property=my-build-prop=my-val
+	`
+	fileName := path.Join(subDir, "simple.groovy")
+	err = ioutil.WriteFile(fileName, []byte(file), 0777)
+	assert.NoError(t, err)
+
+	cmd, flags, err := NewKamelWithModelineCommand(context.TODO(), []string{"kamel", "run", fileName})
+	assert.NoError(t, err)
+	assert.NotNil(t, cmd)
+	assert.Equal(t, []string{"run", fileName, "--build-property=my-build-prop=my-val"}, flags)
+}
+
+func TestModelineRunBuildPropertyFiles(t *testing.T) {
+	dir, err := ioutil.TempDir("", "camel-k-test-")
+	assert.NoError(t, err)
+	defer os.RemoveAll(dir)
+
+	subDir := path.Join(dir, "sub")
+	err = os.Mkdir(subDir, 0777)
+	assert.NoError(t, err)
+
+	file := `
+		// camel-k: build-property=file:application.properties
 	`
 	fileName := path.Join(subDir, "simple.groovy")
 	err = ioutil.WriteFile(fileName, []byte(file), 0777)
@@ -127,7 +200,7 @@ func TestModelineRunPropertyFiles(t *testing.T) {
 	cmd, flags, err := NewKamelWithModelineCommand(context.TODO(), []string{"kamel", "run", fileName})
 	assert.NoError(t, err)
 	assert.NotNil(t, cmd)
-	assert.Equal(t, []string{"run", fileName, "--property-file=" + propFileName}, flags)
+	assert.Equal(t, []string{"run", fileName, "--build-property=file:application.properties"}, flags)
 }
 
 func TestModelineInspectSimple(t *testing.T) {
diff --git a/pkg/cmd/run.go b/pkg/cmd/run.go
index 8f9c593..78129a4 100644
--- a/pkg/cmd/run.go
+++ b/pkg/cmd/run.go
@@ -78,8 +78,8 @@ func newCmdRun(rootCmdOptions *RootCmdOptions) (*cobra.Command, *runCmdOptions)
 	cmd.Flags().StringArrayP("dependency", "d", nil, "A dependency that should be included, e.g., \"-d camel-mail\" for a Camel component, or \"-d mvn:org.my:app:1.0\" for a Maven dependency")
 	cmd.Flags().BoolP("wait", "w", false, "Wait for the integration to be running")
 	cmd.Flags().StringP("kit", "k", "", "The kit used to run the integration")
-	cmd.Flags().StringArrayP("property", "p", nil, "Add a runtime property (syntax, my-key=my-value | file:/path/to/my-conf.properties)")
-	cmd.Flags().StringArray("build-property", nil, "Add a build time property (syntax, my-key=my-value | file:/path/to/my-conf.properties)")
+	cmd.Flags().StringArrayP("property", "p", nil, "Add a runtime property or properties file (syntax, my-key=my-value | file:/path/to/my-conf.properties)")
+	cmd.Flags().StringArray("build-property", nil, "Add a build time property or properties file (syntax, my-key=my-value | file:/path/to/my-conf.properties)")
 	cmd.Flags().StringArray("configmap", nil, "Add a ConfigMap")
 	cmd.Flags().StringArray("secret", nil, "Add a Secret")
 	cmd.Flags().StringArray("maven-repository", nil, "Add a maven repository")

[camel-k] 01/11: refactor(trait): property names and error condition

Posted by nf...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

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

commit 7ce7b01a1fb12afc8a9e7d39d66f9a2a85193f08
Author: Pasquale Congiusti <pa...@gmail.com>
AuthorDate: Thu May 20 16:19:00 2021 +0200

    refactor(trait): property names and error condition
---
 pkg/trait/builder.go | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/pkg/trait/builder.go b/pkg/trait/builder.go
index f2d0775..8828d3a 100644
--- a/pkg/trait/builder.go
+++ b/pkg/trait/builder.go
@@ -25,7 +25,10 @@ import (
 	v1 "github.com/apache/camel-k/pkg/apis/camel/v1"
 	"github.com/apache/camel-k/pkg/builder"
 	corev1 "k8s.io/api/core/v1"
+<<<<<<< HEAD
 	metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
+=======
+>>>>>>> refactor(trait): property names and error condition
 )
 
 // The builder trait is internally used to determine the best strategy to
@@ -70,9 +73,12 @@ func (t *builderTrait) Apply(e *Environment) error {
 		e.IntegrationKit.Status.Phase = v1.IntegrationKitPhaseError
 		e.IntegrationKit.Status.SetCondition("IntegrationKitPropertiesFormatValid", corev1.ConditionFalse,
 			"IntegrationKitPropertiesFormatValid", fmt.Sprintf("One or more properties where not formatted as expected: %s", err.Error()))
+<<<<<<< HEAD
 		if _, err := e.Client.CamelV1().IntegrationKits(e.IntegrationKit.Namespace).UpdateStatus(e.C, e.IntegrationKit, metav1.UpdateOptions{}); err != nil {
 			return err
 		}
+=======
+>>>>>>> refactor(trait): property names and error condition
 		return nil
 	}
 

[camel-k] 05/11: refactor(trait): property names and error condition

Posted by nf...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

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

commit 719b158f03dae64af6e8ac993ebf59a3912c26d7
Author: Pasquale Congiusti <pa...@gmail.com>
AuthorDate: Thu May 20 16:19:00 2021 +0200

    refactor(trait): property names and error condition
---
 pkg/cmd/run.go       | 4 ++++
 pkg/trait/builder.go | 6 ++++++
 2 files changed, 10 insertions(+)

diff --git a/pkg/cmd/run.go b/pkg/cmd/run.go
index fc0516e..77e59c9 100644
--- a/pkg/cmd/run.go
+++ b/pkg/cmd/run.go
@@ -571,6 +571,7 @@ func (o *runCmdOptions) updateIntegrationCode(c client.Client, sources []string,
 	}
 	// convert each build configuration to a builder trait property
 	for _, item := range o.BuildProperties {
+<<<<<<< HEAD
 		props, err := extractProperties(item)
 		if err != nil {
 			return nil, err
@@ -583,6 +584,9 @@ func (o *runCmdOptions) updateIntegrationCode(c client.Client, sources []string,
 				return nil, err
 			}
 		}
+=======
+		o.Traits = append(o.Traits, fmt.Sprintf("builder.properties=%s", item))
+>>>>>>> refactor(trait): property names and error condition
 	}
 	for _, item := range o.LoggingLevels {
 		integration.Spec.AddConfiguration("property", "logging.level."+item)
diff --git a/pkg/trait/builder.go b/pkg/trait/builder.go
index 8828d3a..dacc00c 100644
--- a/pkg/trait/builder.go
+++ b/pkg/trait/builder.go
@@ -26,9 +26,12 @@ import (
 	"github.com/apache/camel-k/pkg/builder"
 	corev1 "k8s.io/api/core/v1"
 <<<<<<< HEAD
+<<<<<<< HEAD
 	metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
 =======
 >>>>>>> refactor(trait): property names and error condition
+=======
+>>>>>>> refactor(trait): property names and error condition
 )
 
 // The builder trait is internally used to determine the best strategy to
@@ -74,11 +77,14 @@ func (t *builderTrait) Apply(e *Environment) error {
 		e.IntegrationKit.Status.SetCondition("IntegrationKitPropertiesFormatValid", corev1.ConditionFalse,
 			"IntegrationKitPropertiesFormatValid", fmt.Sprintf("One or more properties where not formatted as expected: %s", err.Error()))
 <<<<<<< HEAD
+<<<<<<< HEAD
 		if _, err := e.Client.CamelV1().IntegrationKits(e.IntegrationKit.Namespace).UpdateStatus(e.C, e.IntegrationKit, metav1.UpdateOptions{}); err != nil {
 			return err
 		}
 =======
 >>>>>>> refactor(trait): property names and error condition
+=======
+>>>>>>> refactor(trait): property names and error condition
 		return nil
 	}
 

[camel-k] 03/11: feat(cmd/run): build-property file support

Posted by nf...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

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

commit d5910edf0bfc4f5a3e25d942182a22ad87e3100e
Author: Pasquale Congiusti <pa...@gmail.com>
AuthorDate: Mon May 24 14:16:48 2021 +0200

    feat(cmd/run): build-property file support
    
    Ref #2003
---
 pkg/cmd/run.go      | 46 ++++++++++++++++++++++++++++++++++++++++++++--
 pkg/cmd/run_test.go | 43 +++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 87 insertions(+), 2 deletions(-)

diff --git a/pkg/cmd/run.go b/pkg/cmd/run.go
index 1c341d9..fc0516e 100644
--- a/pkg/cmd/run.go
+++ b/pkg/cmd/run.go
@@ -79,7 +79,7 @@ func newCmdRun(rootCmdOptions *RootCmdOptions) (*cobra.Command, *runCmdOptions)
 	cmd.Flags().BoolP("wait", "w", false, "Wait for the integration to be running")
 	cmd.Flags().StringP("kit", "k", "", "The kit used to run the integration")
 	cmd.Flags().StringArrayP("property", "p", nil, "Add a camel property")
-	cmd.Flags().StringArray("build-property", nil, "Add a build time property")
+	cmd.Flags().StringArray("build-property", nil, "Add a build time property (syntax, my-key=my-value | file:/path/to/my-conf.properties)")
 	cmd.Flags().StringArray("configmap", nil, "Add a ConfigMap")
 	cmd.Flags().StringArray("secret", nil, "Add a Secret")
 	cmd.Flags().StringArray("maven-repository", nil, "Add a maven repository")
@@ -229,6 +229,12 @@ func (o *runCmdOptions) validate() error {
 		return err
 	}
 
+	buildPropertyFiles := filterBuildPropertyFiles(o.BuildProperties)
+	err = validatePropertyFiles(buildPropertyFiles)
+	if err != nil {
+		return err
+	}
+
 	for _, label := range o.Labels {
 		parts := strings.Split(label, "=")
 		if len(parts) != 2 {
@@ -239,6 +245,17 @@ func (o *runCmdOptions) validate() error {
 	return nil
 }
 
+func filterBuildPropertyFiles(maybePropertyFiles []string) []string {
+	var propertyFiles []string
+	for _, maybePropertyFile := range maybePropertyFiles {
+		if strings.HasPrefix(maybePropertyFile, "file:") {
+			propertyFiles = append(propertyFiles, strings.Replace(maybePropertyFile, "file:", "", 1))
+		}
+	}
+
+	return propertyFiles
+}
+
 func (o *runCmdOptions) run(cmd *cobra.Command, args []string) error {
 	c, err := o.GetCmdClient()
 	if err != nil {
@@ -554,7 +571,18 @@ func (o *runCmdOptions) updateIntegrationCode(c client.Client, sources []string,
 	}
 	// convert each build configuration to a builder trait property
 	for _, item := range o.BuildProperties {
-		o.Traits = append(o.Traits, fmt.Sprintf("builder.properties=%s", item))
+		props, err := extractProperties(item)
+		if err != nil {
+			return nil, err
+		}
+		for _, k := range props.Keys() {
+			v, ok := props.Get(k)
+			if ok {
+				o.Traits = append(o.Traits, fmt.Sprintf("builder.properties=%s", escapePropertyFileItem(k)+"="+escapePropertyFileItem(v)))
+			} else {
+				return nil, err
+			}
+		}
 	}
 	for _, item := range o.LoggingLevels {
 		integration.Spec.AddConfiguration("property", "logging.level."+item)
@@ -642,6 +670,20 @@ func (o *runCmdOptions) updateIntegrationCode(c client.Client, sources []string,
 	return &integration, nil
 }
 
+// The function parse the value and if it is a file (file:/path/), it will parse as property file
+// otherwise return a single property built from the item passed as `key=value`
+func extractProperties(value string) (*properties.Properties, error) {
+	if !strings.HasPrefix(value, "file:") {
+		return keyValueProps(value)
+	}
+	// we already validated the existence of files during validate()
+	return loadPropertyFile(strings.Replace(value, "file:", "", 1))
+}
+
+func keyValueProps(value string) (*properties.Properties, error) {
+	return properties.Load([]byte(value), properties.UTF8)
+}
+
 func binaryOrTextResource(fileName string, data []byte, contentType string, base64Compression bool) (v1.ResourceSpec, error) {
 	resourceSpec := v1.ResourceSpec{
 		DataSpec: v1.DataSpec{
diff --git a/pkg/cmd/run_test.go b/pkg/cmd/run_test.go
index f11e157..7f45795 100644
--- a/pkg/cmd/run_test.go
+++ b/pkg/cmd/run_test.go
@@ -568,3 +568,46 @@ func TestIsLocalFileAndExists(t *testing.T) {
 	assert.NotNil(t, err)
 	assert.False(t, value)
 }
+
+func TestExtractProperties_SingleKeyValue(t *testing.T) {
+	correctValues := []string{"key=val", "key = val", "key= val", " key   =  val"}
+	for _, val := range correctValues {
+		prop, err := extractProperties(val)
+		assert.Nil(t, err)
+		value, ok := prop.Get("key")
+		assert.True(t, ok)
+		assert.Equal(t, "val", value)
+	}
+}
+
+func TestExtractProperties_FromFile(t *testing.T) {
+	var tmpFile1 *os.File
+	var err error
+	if tmpFile1, err = ioutil.TempFile("", "camel-k-*.properties"); err != nil {
+		t.Error(err)
+	}
+
+	assert.Nil(t, tmpFile1.Close())
+	assert.Nil(t, ioutil.WriteFile(tmpFile1.Name(), []byte(`
+	key=value
+	#key2=value2
+	my.key=value
+	`), 0644))
+
+	props, err := extractProperties("file:" + tmpFile1.Name())
+	assert.Nil(t, err)
+	assert.Equal(t, 2, props.Len())
+	for _, prop := range props.Keys() {
+		value, ok := props.Get(prop)
+		assert.True(t, ok)
+		assert.Equal(t, "value", value)
+	}
+}
+
+func TestFilterBuildPropertyFiles(t *testing.T) {
+	inputValues := []string{"file:/tmp/test", "key=val"}
+	outputValues := filterBuildPropertyFiles(inputValues)
+
+	assert.Equal(t, len(outputValues), 1)
+	assert.Equal(t, outputValues[0], "/tmp/test")
+}

[camel-k] 10/11: chore(doc): modeline examples

Posted by nf...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

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

commit 0533bf1454f0557112a87c87edfbb347cad98c68
Author: Pasquale Congiusti <pa...@gmail.com>
AuthorDate: Wed May 26 14:02:46 2021 +0200

    chore(doc): modeline examples
---
 .../modeline-build-property-file-route.groovy      | 31 ++++++++++++++++++++++
 .../modeline/modeline-build-property-route.groovy  | 31 ++++++++++++++++++++++
 .../modeline/modeline-property-file-route.groovy   | 29 ++++++++++++++++++++
 examples/modeline/modeline-property-route.groovy   | 29 ++++++++++++++++++++
 examples/modeline/quarkus.properties               |  3 +++
 5 files changed, 123 insertions(+)

diff --git a/examples/modeline/modeline-build-property-file-route.groovy b/examples/modeline/modeline-build-property-file-route.groovy
new file mode 100644
index 0000000..6892235
--- /dev/null
+++ b/examples/modeline/modeline-build-property-file-route.groovy
@@ -0,0 +1,31 @@
+// camel-k: language=groovy
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+//
+// Provide a build time configuration property file
+//
+// To run this integrations use:
+//
+// kamel run modeline-build-property-file-route.groovy --dev
+//
+
+// camel-k: build-property=file:quarkus.properties
+
+from('timer:build-property')
+    .routeId('build-property')
+    .log('The application name: {{quarkus.application.name}}')
diff --git a/examples/modeline/modeline-build-property-route.groovy b/examples/modeline/modeline-build-property-route.groovy
new file mode 100644
index 0000000..749ad76
--- /dev/null
+++ b/examples/modeline/modeline-build-property-route.groovy
@@ -0,0 +1,31 @@
+// camel-k: language=groovy
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+//
+// Provide a build time configuration property (the application name)
+//
+// To run this integrations use:
+//
+// kamel run modeline-build-property-route.groovy --dev
+//
+
+// camel-k: build-property=quarkus.application.name=my-super-application
+
+from('timer:build-property')
+    .routeId('build-property')
+    .log('The application name: {{quarkus.application.name}}')
diff --git a/examples/modeline/modeline-property-file-route.groovy b/examples/modeline/modeline-property-file-route.groovy
new file mode 100644
index 0000000..e831e21
--- /dev/null
+++ b/examples/modeline/modeline-property-file-route.groovy
@@ -0,0 +1,29 @@
+// camel-k: language=groovy
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+//
+// To run this integrations use:
+//
+// kamel run modeline-property-file-route.groovy --dev
+//
+
+// camel-k: property=file:my.properties
+
+from('timer:property')
+    .routeId('property')
+    .log('property content is: {{my.key.1}} {{my.key.2}}')
diff --git a/examples/modeline/modeline-property-route.groovy b/examples/modeline/modeline-property-route.groovy
new file mode 100644
index 0000000..472096f
--- /dev/null
+++ b/examples/modeline/modeline-property-route.groovy
@@ -0,0 +1,29 @@
+// camel-k: language=groovy
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+//
+// To run this integrations use:
+//
+// kamel run modeline-property-route.groovy --dev
+//
+
+// camel-k: property=my.message=test-property
+
+from('timer:property')
+    .routeId('property')
+    .log('property content is: {{my.message}}')
diff --git a/examples/modeline/quarkus.properties b/examples/modeline/quarkus.properties
new file mode 100644
index 0000000..882e2ab
--- /dev/null
+++ b/examples/modeline/quarkus.properties
@@ -0,0 +1,3 @@
+quarkus.application.name = my-super-application
+quarkus.banner.enabled = true
+#some.other.configuration = commented!
\ No newline at end of file

[camel-k] 04/11: doc(examples): build-property file support

Posted by nf...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

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

commit e93afb244c7beeeca0f6eafdeb1636871e960dcd
Author: Pasquale Congiusti <pa...@gmail.com>
AuthorDate: Mon May 24 14:17:32 2021 +0200

    doc(examples): build-property file support
---
 .../user-config/build-property-file-route.groovy   | 29 ++++++++++++++++++++++
 examples/user-config/quarkus.properties            |  3 +++
 2 files changed, 32 insertions(+)

diff --git a/examples/user-config/build-property-file-route.groovy b/examples/user-config/build-property-file-route.groovy
new file mode 100644
index 0000000..8427b48
--- /dev/null
+++ b/examples/user-config/build-property-file-route.groovy
@@ -0,0 +1,29 @@
+// camel-k: language=groovy
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+//
+// Provide a build time configuration property file
+//
+// To run this integrations use:
+//
+// kamel run --build-property=file:quarkus.properties build-property-file-route.groovy --dev
+//
+
+from('timer:build-property')
+    .routeId('build-property')
+    .log('The application name: {{quarkus.application.name}}')
diff --git a/examples/user-config/quarkus.properties b/examples/user-config/quarkus.properties
new file mode 100644
index 0000000..882e2ab
--- /dev/null
+++ b/examples/user-config/quarkus.properties
@@ -0,0 +1,3 @@
+quarkus.application.name = my-super-application
+quarkus.banner.enabled = true
+#some.other.configuration = commented!
\ No newline at end of file

[camel-k] 06/11: feat(run/property): new file format as build-property

Posted by nf...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

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

commit 0efff02b685f801e0ce2312abf3a7d3e07a31204
Author: Pasquale Congiusti <pa...@gmail.com>
AuthorDate: Mon May 24 16:41:43 2021 +0200

    feat(run/property): new file format as build-property
    
    * Deprecating --property-file flag in favour of --property file: format.
    
    Ref #2003
---
 pkg/cmd/run.go      | 41 ++++++++++++++++++++++++-----------------
 pkg/cmd/run_test.go |  4 +++-
 2 files changed, 27 insertions(+), 18 deletions(-)

diff --git a/pkg/cmd/run.go b/pkg/cmd/run.go
index 77e59c9..61ec35a 100644
--- a/pkg/cmd/run.go
+++ b/pkg/cmd/run.go
@@ -78,7 +78,7 @@ func newCmdRun(rootCmdOptions *RootCmdOptions) (*cobra.Command, *runCmdOptions)
 	cmd.Flags().StringArrayP("dependency", "d", nil, "A dependency that should be included, e.g., \"-d camel-mail\" for a Camel component, or \"-d mvn:org.my:app:1.0\" for a Maven dependency")
 	cmd.Flags().BoolP("wait", "w", false, "Wait for the integration to be running")
 	cmd.Flags().StringP("kit", "k", "", "The kit used to run the integration")
-	cmd.Flags().StringArrayP("property", "p", nil, "Add a camel property")
+	cmd.Flags().StringArrayP("property", "p", nil, "Add a runtime property (syntax, my-key=my-value | file:/path/to/my-conf.properties)")
 	cmd.Flags().StringArray("build-property", nil, "Add a build time property (syntax, my-key=my-value | file:/path/to/my-conf.properties)")
 	cmd.Flags().StringArray("configmap", nil, "Add a ConfigMap")
 	cmd.Flags().StringArray("secret", nil, "Add a Secret")
@@ -96,7 +96,7 @@ func newCmdRun(rootCmdOptions *RootCmdOptions) (*cobra.Command, *runCmdOptions)
 	cmd.Flags().StringArray("open-api", nil, "Add an OpenAPI v2 spec")
 	cmd.Flags().StringArrayP("volume", "v", nil, "Mount a volume into the integration container. E.g \"-v pvcname:/container/path\"")
 	cmd.Flags().StringArrayP("env", "e", nil, "Set an environment variable in the integration container. E.g \"-e MY_VAR=my-value\"")
-	cmd.Flags().StringArray("property-file", nil, "Bind a property file to the integration. E.g. \"--property-file integration.properties\"")
+	cmd.Flags().StringArray("property-file", nil, "[Deprecated] Bind a property file to the integration. E.g. \"--property-file integration.properties\"")
 	cmd.Flags().StringArray("label", nil, "Add a label to the integration. E.g. \"--label my.company=hello\"")
 	cmd.Flags().StringArray("source", nil, "Add source file to your integration, this is added to the list of files listed as arguments of the command")
 	cmd.Flags().String("pod-template", "", "The path of the YAML file containing a PodSpec template to be used for the Integration pods")
@@ -136,9 +136,10 @@ type runCmdOptions struct {
 	LoggingLevels   []string `mapstructure:"logging-levels" yaml:",omitempty"`
 	Volumes         []string `mapstructure:"volumes" yaml:",omitempty"`
 	EnvVars         []string `mapstructure:"envs" yaml:",omitempty"`
-	PropertyFiles   []string `mapstructure:"property-files" yaml:",omitempty"`
-	Labels          []string `mapstructure:"labels" yaml:",omitempty"`
-	Sources         []string `mapstructure:"sources" yaml:",omitempty"`
+	// Deprecated: PropertyFiles has been deprecated in 1.5
+	PropertyFiles []string `mapstructure:"property-files" yaml:",omitempty"`
+	Labels        []string `mapstructure:"labels" yaml:",omitempty"`
+	Sources       []string `mapstructure:"sources" yaml:",omitempty"`
 }
 
 func (o *runCmdOptions) decode(cmd *cobra.Command, args []string) error {
@@ -224,13 +225,18 @@ func (o *runCmdOptions) validate() error {
 		}
 	}
 
+	// Deprecation warning
+	if o.PropertyFiles != nil {
+		fmt.Println("Warn: --property-files has been deprecated. You should use --property file:/path/to/conf.properties instead.")
+	}
 	err := validatePropertyFiles(o.PropertyFiles)
 	if err != nil {
 		return err
 	}
 
-	buildPropertyFiles := filterBuildPropertyFiles(o.BuildProperties)
-	err = validatePropertyFiles(buildPropertyFiles)
+	propertyFiles := filterBuildPropertyFiles(o.Properties)
+	propertyFiles = append(propertyFiles, filterBuildPropertyFiles(o.BuildProperties)...)
+	err = validatePropertyFiles(propertyFiles)
 	if err != nil {
 		return err
 	}
@@ -561,13 +567,18 @@ func (o *runCmdOptions) updateIntegrationCode(c client.Client, sources []string,
 	for _, item := range o.Dependencies {
 		integration.Spec.AddDependency(item)
 	}
-	for _, pf := range o.PropertyFiles {
-		if err := addPropertyFile(pf, &integration.Spec); err != nil {
-			return nil, err
-		}
+	for _, item := range o.PropertyFiles {
+		// Deprecated: making it compatible with newer mechanism
+		o.Properties = append(o.Properties, "file:"+item)
 	}
 	for _, item := range o.Properties {
-		integration.Spec.AddConfiguration("property", item)
+		props, err := extractProperties(item)
+		if err != nil {
+			return nil, err
+		}
+		if err := addIntegrationProperties(props, &integration.Spec); err != nil {
+			return nil, err
+		}
 	}
 	// convert each build configuration to a builder trait property
 	for _, item := range o.BuildProperties {
@@ -756,11 +767,7 @@ func isLocalAndFileExists(fileName string) (bool, error) {
 	return !info.IsDir(), nil
 }
 
-func addPropertyFile(fileName string, spec *v1.IntegrationSpec) error {
-	props, err := loadPropertyFile(fileName)
-	if err != nil {
-		return err
-	}
+func addIntegrationProperties(props *properties.Properties, spec *v1.IntegrationSpec) error {
 	for _, k := range props.Keys() {
 		v, _ := props.Get(k)
 		spec.AddConfiguration(
diff --git a/pkg/cmd/run_test.go b/pkg/cmd/run_test.go
index 7f45795..1d9192f 100644
--- a/pkg/cmd/run_test.go
+++ b/pkg/cmd/run_test.go
@@ -262,7 +262,9 @@ func TestAddPropertyFile(t *testing.T) {
 	assert.Nil(t, ioutil.WriteFile(tmpFile.Name(), []byte(TestPropertyFileContent), 0644))
 
 	spec := v1.IntegrationSpec{}
-	assert.Nil(t, addPropertyFile(tmpFile.Name(), &spec))
+	properties, err := extractProperties("file:" + tmpFile.Name())
+	assert.Nil(t, err)
+	assert.Nil(t, addIntegrationProperties(properties, &spec))
 	assert.Equal(t, 4, len(spec.Configuration))
 	assert.Equal(t, `a=b`, spec.Configuration[0].Value)
 	assert.Equal(t, `c\=d=e`, spec.Configuration[1].Value)

[camel-k] 02/11: refactor(cmd/util): validateProperty files unit test

Posted by nf...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

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

commit eacd8052fb82da4c3c46263adfabd384f51ac90a
Author: Pasquale Congiusti <pa...@gmail.com>
AuthorDate: Mon May 24 14:14:00 2021 +0200

    refactor(cmd/util): validateProperty files unit test
---
 pkg/cmd/util_dependencies.go      | 22 +++++++++----
 pkg/cmd/util_dependencies_test.go | 68 +++++++++++++++++++++++++++++++++++++++
 2 files changed, 83 insertions(+), 7 deletions(-)

diff --git a/pkg/cmd/util_dependencies.go b/pkg/cmd/util_dependencies.go
index be0dfb7..ac6f159 100644
--- a/pkg/cmd/util_dependencies.go
+++ b/pkg/cmd/util_dependencies.go
@@ -362,15 +362,23 @@ func validateIntegrationFiles(args []string) error {
 
 func validatePropertyFiles(propertyFiles []string) error {
 	for _, fileName := range propertyFiles {
-		if !strings.HasSuffix(fileName, ".properties") {
-			return fmt.Errorf("supported property files must have a .properties extension: %s", fileName)
+		if err := validatePropertyFile(fileName); err != nil {
+			return err
 		}
+	}
 
-		if file, err := os.Stat(fileName); err != nil {
-			return errors.Wrapf(err, "unable to access property file %s", fileName)
-		} else if file.IsDir() {
-			return fmt.Errorf("property file %s is a directory", fileName)
-		}
+	return nil
+}
+
+func validatePropertyFile(fileName string) error {
+	if !strings.HasSuffix(fileName, ".properties") {
+		return fmt.Errorf("supported property files must have a .properties extension: %s", fileName)
+	}
+
+	if file, err := os.Stat(fileName); err != nil {
+		return errors.Wrapf(err, "unable to access property file %s", fileName)
+	} else if file.IsDir() {
+		return fmt.Errorf("property file %s is a directory", fileName)
 	}
 
 	return nil
diff --git a/pkg/cmd/util_dependencies_test.go b/pkg/cmd/util_dependencies_test.go
new file mode 100644
index 0000000..0df0cdf
--- /dev/null
+++ b/pkg/cmd/util_dependencies_test.go
@@ -0,0 +1,68 @@
+/*
+Licensed to the Apache Software Foundation (ASF) under one or more
+contributor license agreements.  See the NOTICE file distributed with
+this work for additional information regarding copyright ownership.
+The ASF licenses this file to You under the Apache License, Version 2.0
+(the "License"); you may not use this file except in compliance with
+the License.  You may obtain a copy of the License at
+
+   http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
+package cmd
+
+import (
+	"io/ioutil"
+	"os"
+	"strings"
+	"testing"
+
+	"github.com/stretchr/testify/assert"
+)
+
+func TestValidatePropertyFiles_ShouldSucceed(t *testing.T) {
+	var tmpFile1 *os.File
+	var err error
+	if tmpFile1, err = ioutil.TempFile("", "camel-k-*.properties"); err != nil {
+		t.Error(err)
+	}
+
+	assert.Nil(t, tmpFile1.Close())
+	assert.Nil(t, ioutil.WriteFile(tmpFile1.Name(), []byte("key=value"), 0644))
+
+	inputValues := []string{tmpFile1.Name()}
+	err = validatePropertyFiles(inputValues)
+
+	assert.Nil(t, err)
+}
+
+func TestValidatePropertyFiles_ShouldFailNotAPropertiesFile(t *testing.T) {
+	var tmpFile1 *os.File
+	var err error
+	if tmpFile1, err = ioutil.TempFile("", "camel-k-"); err != nil {
+		t.Error(err)
+	}
+
+	assert.Nil(t, tmpFile1.Close())
+	assert.Nil(t, ioutil.WriteFile(tmpFile1.Name(), []byte("key=value"), 0644))
+
+	inputValues := []string{tmpFile1.Name()}
+	err = validatePropertyFiles(inputValues)
+
+	assert.NotNil(t, err)
+	assert.True(t, strings.HasPrefix(err.Error(), "supported property files must have a .properties extension"))
+}
+
+func TestValidatePropertyFiles_ShouldFailNotFound(t *testing.T) {
+	inputValues := []string{"/tmp/not-found.properties"}
+	err := validatePropertyFiles(inputValues)
+
+	assert.NotNil(t, err)
+	assert.True(t, strings.HasPrefix(err.Error(), "unable to access property file"))
+}

[camel-k] 07/11: refactor(examples): --property file: example

Posted by nf...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

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

commit e51e70d15a692e8599650bdb8e043842ac21a43f
Author: Pasquale Congiusti <pa...@gmail.com>
AuthorDate: Mon May 24 16:43:06 2021 +0200

    refactor(examples): --property file: example
---
 examples/user-config/property-file-route.groovy | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/examples/user-config/property-file-route.groovy b/examples/user-config/property-file-route.groovy
index 13a09fc..6ce6838 100644
--- a/examples/user-config/property-file-route.groovy
+++ b/examples/user-config/property-file-route.groovy
@@ -19,7 +19,7 @@
 //
 // To run this integrations use:
 //
-// kamel run --property-file my.properties property-file-route.groovy --dev
+// kamel run --property file:my.properties property-file-route.groovy --dev
 //
 
 from('timer:property-file')