Skip to content

Commit

Permalink
fix(trait): java and JS dsl workarounds
Browse files Browse the repository at this point in the history
* Java DSL requires to circumvent certain limitation of joor
* JS DSL requires a temporary workaround due to a bug in versions < 3.8.4
  • Loading branch information
squakez committed May 22, 2024
1 parent c4573dc commit a9fb9ba
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 4 deletions.
2 changes: 0 additions & 2 deletions pkg/builder/quarkus.go
Original file line number Diff line number Diff line change
Expand Up @@ -249,8 +249,6 @@ func computeApplicationProperties(appPropertiesPath string, applicationPropertie
// required for to resolve data type transformers at runtime with service discovery
// the different Camel runtimes use different resource paths for the service lookup
applicationProperties["quarkus.camel.service.discovery.include-patterns"] = "META-INF/services/org/apache/camel/datatype/converter/*,META-INF/services/org/apache/camel/datatype/transformer/*,META-INF/services/org/apache/camel/transformer/*"
// Workaround to prevent JS runtime errors, see https://github.com/apache/camel-quarkus/issues/5678
applicationProperties["quarkus.class-loading.parent-first-artifacts"] = "org.graalvm.regex:regex"
defer f.Close()
// Add a new line if the file is already containing some value
if fstat.Size() > 0 {
Expand Down
1 change: 0 additions & 1 deletion pkg/builder/quarkus_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,6 @@ func TestBuildQuarkusRunner(t *testing.T) {
assert.Contains(t, string(appProps), "camel.hello=world\n")
assert.Contains(t, string(appProps), "quarkus.banner.enabled=false\n")
assert.Contains(t, string(appProps), "quarkus.camel.service.discovery.include-patterns=META-INF/services/org/apache/camel/datatype/converter/*,META-INF/services/org/apache/camel/datatype/transformer/*,META-INF/services/org/apache/camel/transformer/*\n")
assert.Contains(t, string(appProps), "quarkus.class-loading.parent-first-artifacts=org.graalvm.regex:regex\n")
// At this stage a maven project should have been executed. Verify the package was created.
_, err = os.Stat(filepath.Join(tmpDir, "maven", "target", "camel-k-integration-"+defaults.Version+".jar"))
require.NoError(t, err)
Expand Down
50 changes: 49 additions & 1 deletion pkg/trait/jvm.go
Original file line number Diff line number Diff line change
Expand Up @@ -168,16 +168,48 @@ func (t *jvmTrait) Apply(e *Environment) error {
args = append(args, httpProxyArgs...)
}

// TODO: this is a workaround which we should remove once (if) JooR allow
// fa(s)t-jar execution: https://github.com/jOOQ/jOOR/issues/69
javaJoorSource := hasDSLSources(e.Integration.AllSources(), v1.LanguageJavaSource)
// TODO: this is a workaround which we should remove once we have Quarkus runtime >= 3.8.4
// https://github.com/quarkusio/quarkus/issues/39833
jsSource := hasDSLSources(e.Integration.AllSources(), v1.LanguageJavaScript)

// Will execute on the container something like
// java -Dxyx ... -cp ... -jar my-app.jar
// For this reason it's imporant that the container is a java based container able to run a Camel (hence Java) application
container.Command = []string{"java"}
classpathItems := t.prepareClasspathItems(container)
if classpathItems != nil {
if javaJoorSource || jsSource {
if javaJoorSource {
classpathItems = append(
classpathItems,
fmt.Sprintf("%s/lib/main/*", builder.DependenciesDir),
t.Jar,
)
} else if jsSource {
classpathItems = append(
classpathItems,
fmt.Sprintf("%s/lib/main/*", builder.DependenciesDir),
fmt.Sprintf("%s/lib/boot/*", builder.DependenciesDir),
t.Jar,
)
}
}
args = append(args, "-cp", strings.Join(classpathItems, ":"))
}
container.WorkingDir = builder.DeploymentDir
args = append(args, "-jar", t.Jar)

if javaJoorSource || jsSource {
// The catalog runtime has to provide this configuration.
if e.CamelCatalog == nil {
return fmt.Errorf("cannot execute trait: missing Camel catalog")
}
args = append(args, e.CamelCatalog.Runtime.ApplicationClass)
} else {
args = append(args, "-jar", t.Jar)
}
container.Args = args

return nil
Expand Down Expand Up @@ -277,3 +309,19 @@ func (t *jvmTrait) prepareHTTPProxy(container *corev1.Container) ([]string, erro

return args, nil
}

// hasDSLSources returns true if the sources have a given DSL. This is always returning false
// for "sourceless" Integrations which have no sources attached.
func hasDSLSources(sources []v1.SourceSpec, dsl v1.Language) bool {
for _, s := range sources {
lang := s.Language
if lang == "" {
lang = s.InferLanguage()
}
if lang == dsl {
return true
}
}

return false
}

0 comments on commit a9fb9ba

Please sign in to comment.