You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by pc...@apache.org on 2024/01/16 11:24:03 UTC
(camel-k) 03/03: fix(jib): inherit maven options
This is an automated email from the ASF dual-hosted git repository.
pcongiusti pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel-k.git
commit 7b9ed83e75d4be9b0f2aca5434f6d2d82cd389c4
Author: Pasquale Congiusti <pa...@gmail.com>
AuthorDate: Mon Jan 15 17:02:32 2024 +0100
fix(jib): inherit maven options
---
.../platform_traits_test.go | 3 ++
pkg/util/maven/maven_command.go | 15 +++++++--
pkg/util/maven/maven_command_test.go | 36 ++++++++++++++++++++++
3 files changed, 51 insertions(+), 3 deletions(-)
diff --git a/e2e/commonwithcustominstall/platform_traits_test.go b/e2e/commonwithcustominstall/platform_traits_test.go
index 7e0d5380b..839cf5a96 100644
--- a/e2e/commonwithcustominstall/platform_traits_test.go
+++ b/e2e/commonwithcustominstall/platform_traits_test.go
@@ -41,12 +41,15 @@ func TestTraitOnIntegrationPlatform(t *testing.T) {
Expect(KamelInstallWithID(operatorID, ns).Execute()).To(Succeed())
containerTestName := "testname"
+
+ Eventually(PlatformPhase(ns), TestTimeoutMedium).Should(Equal(v1.IntegrationPlatformPhaseReady))
ip := Platform(ns)()
ip.Spec.Traits = v1.Traits{Logging: &trait.LoggingTrait{Level: "DEBUG"}, Container: &trait.ContainerTrait{Name: containerTestName}}
if err := TestClient().Update(TestContext, ip); err != nil {
t.Fatal("Can't create IntegrationPlatform", err)
}
+ Eventually(PlatformPhase(ns), TestTimeoutMedium).Should(Equal(v1.IntegrationPlatformPhaseReady))
name := RandomizedSuffixName("java")
t.Run("Run integration with platform traits", func(t *testing.T) {
diff --git a/pkg/util/maven/maven_command.go b/pkg/util/maven/maven_command.go
index 5c01a36fd..922421f98 100644
--- a/pkg/util/maven/maven_command.go
+++ b/pkg/util/maven/maven_command.go
@@ -143,7 +143,7 @@ func (c *Command) Do(ctx context.Context) error {
Log.WithValues("MAVEN_OPTS", mavenOptions).Infof("executing: %s", strings.Join(cmd.Args, " "))
// generate maven file
- if err := generateMavenContext(c.context.Path, args); err != nil {
+ if err := generateMavenContext(c.context.Path, args, mavenOptions); err != nil {
return err
}
@@ -286,8 +286,12 @@ func ParseGAV(gav string) (Dependency, error) {
}
// Create a MAVEN_CONTEXT file containing all arguments for a maven command.
-func generateMavenContext(path string, args []string) error {
+func generateMavenContext(path string, args []string, options string) error {
// TODO refactor maven code to avoid creating a file to pass command args
+ return util.WriteToFile(filepath.Join(path, "MAVEN_CONTEXT"), getMavenContext(args, options))
+}
+
+func getMavenContext(args []string, options string) string {
commandArgs := make([]string, 0)
for _, arg := range args {
if arg != "package" && len(strings.TrimSpace(arg)) != 0 {
@@ -295,5 +299,10 @@ func generateMavenContext(path string, args []string) error {
}
}
- return util.WriteToFile(filepath.Join(path, "MAVEN_CONTEXT"), strings.Join(commandArgs, " "))
+ mavenContext := strings.Join(commandArgs, " ")
+ if options != "" {
+ mavenContext += " " + options
+ }
+
+ return mavenContext
}
diff --git a/pkg/util/maven/maven_command_test.go b/pkg/util/maven/maven_command_test.go
new file mode 100644
index 000000000..9ce2734fa
--- /dev/null
+++ b/pkg/util/maven/maven_command_test.go
@@ -0,0 +1,36 @@
+/*
+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 maven
+
+import (
+ "testing"
+
+ "github.com/stretchr/testify/assert"
+)
+
+func TestGetMavenContext(t *testing.T) {
+ mvnSimpleCompile := getMavenContext([]string{"compile", "-s", "my-settings.xml"}, "")
+ mvnOptionsCompile := getMavenContext([]string{"compile", "-s", "my-settings.xml"}, "-DmyProperty=hello")
+ mvnSimplePackage := getMavenContext([]string{"package", "-s", "my-settings.xml"}, "")
+ mvnOptionsPackage := getMavenContext([]string{"package", "-s", "my-settings.xml"}, "-DmyProperty=hello")
+
+ assert.Equal(t, "compile -s my-settings.xml", mvnSimpleCompile)
+ assert.Equal(t, "compile -s my-settings.xml -DmyProperty=hello", mvnOptionsCompile)
+ assert.Equal(t, "-s my-settings.xml", mvnSimplePackage)
+ assert.Equal(t, "-s my-settings.xml -DmyProperty=hello", mvnOptionsPackage)
+}