Skip to content

Commit

Permalink
Execute Quarkus JVM mode before native mode
Browse files Browse the repository at this point in the history
  • Loading branch information
michalvavrik committed Jan 15, 2024
1 parent 4b7efdb commit 874dc73
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
4 changes: 4 additions & 0 deletions pkg/trait/quarkus.go
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,10 @@ func (t *quarkusTrait) applyWhileBuildingKit(e *Environment) {
kit := t.newIntegrationKit(e, packageType(t.Modes[0]))
e.IntegrationKits = append(e.IntegrationKits, *kit)
default:
// execute jvm mode before native mode
sort.Slice(t.Modes, func(i, j int) bool {
return t.Modes[i] != traitv1.NativeQuarkusMode
})
for _, md := range t.Modes {
kit := t.newIntegrationKit(e, packageType(md))
if kit.Spec.Traits.Quarkus == nil {
Expand Down
20 changes: 20 additions & 0 deletions pkg/trait/quarkus_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ package trait
import (
"testing"

traitv1 "github.com/apache/camel-k/v2/pkg/apis/camel/v1/trait"

"github.com/stretchr/testify/assert"

v1 "github.com/apache/camel-k/v2/pkg/apis/camel/v1"
Expand Down Expand Up @@ -84,6 +86,24 @@ func TestApplyQuarkusTraitAnnotationKitConfiguration(t *testing.T) {

}

func TestQuarkusTraitBuildModeOrder(t *testing.T) {
quarkusTrait, environment := createNominalQuarkusTest()
quarkusTrait.Modes = []traitv1.QuarkusMode{traitv1.NativeQuarkusMode, traitv1.JvmQuarkusMode}
environment.Integration.Status.Phase = v1.IntegrationPhaseBuildingKit
environment.Integration.Spec.Sources = []v1.SourceSpec{
{
Language: v1.LanguageYaml,
},
}

err := quarkusTrait.Apply(environment)
assert.Nil(t, err)
assert.Len(t, environment.IntegrationKits, 2)
// assure jvm mode is executed before native mode
assert.Equal(t, environment.IntegrationKits[0].Labels[v1.IntegrationKitLayoutLabel], v1.IntegrationKitLayoutFastJar)
assert.Equal(t, environment.IntegrationKits[1].Labels[v1.IntegrationKitLayoutLabel], v1.IntegrationKitLayoutNativeSources)
}

func createNominalQuarkusTest() (*quarkusTrait, *Environment) {
trait, _ := newQuarkusTrait().(*quarkusTrait)
client, _ := test.NewFakeClient()
Expand Down

0 comments on commit 874dc73

Please sign in to comment.