Skip to content

Commit

Permalink
fix(jib): inherit maven options
Browse files Browse the repository at this point in the history
  • Loading branch information
squakez committed Jan 16, 2024
1 parent 8fa9209 commit 7b9ed83
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 3 deletions.
3 changes: 3 additions & 0 deletions e2e/commonwithcustominstall/platform_traits_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
15 changes: 12 additions & 3 deletions pkg/util/maven/maven_command.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down Expand Up @@ -286,14 +286,23 @@ 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 {
commandArgs = append(commandArgs, strings.TrimSpace(arg))
}
}

return util.WriteToFile(filepath.Join(path, "MAVEN_CONTEXT"), strings.Join(commandArgs, " "))
mavenContext := strings.Join(commandArgs, " ")
if options != "" {
mavenContext += " " + options
}

return mavenContext
}
36 changes: 36 additions & 0 deletions pkg/util/maven/maven_command_test.go
Original file line number Diff line number Diff line change
@@ -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)
}

0 comments on commit 7b9ed83

Please sign in to comment.