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/03/08 13:40:00 UTC
(camel-k) branch main updated: fix(quarkus): don't override application.properties
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
The following commit(s) were added to refs/heads/main by this push:
new 7932a06f1 fix(quarkus): don't override application.properties
7932a06f1 is described below
commit 7932a06f194bd91622d3dfc3a31045ccc98e18ca
Author: Pasquale Congiusti <pa...@gmail.com>
AuthorDate: Fri Mar 8 11:12:15 2024 +0100
fix(quarkus): don't override application.properties
---
pkg/builder/quarkus.go | 19 ++++++++++++--
pkg/builder/quarkus_test.go | 60 +++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 77 insertions(+), 2 deletions(-)
diff --git a/pkg/builder/quarkus.go b/pkg/builder/quarkus.go
index 3568a6b0c..3c074f540 100644
--- a/pkg/builder/quarkus.go
+++ b/pkg/builder/quarkus.go
@@ -221,9 +221,13 @@ func BuildQuarkusRunnerCommon(ctx context.Context, mc maven.Context, project mav
}
func computeApplicationProperties(appPropertiesPath string, applicationProperties map[string]string) error {
- f, err := os.OpenFile(appPropertiesPath, os.O_RDWR|os.O_CREATE, 0666)
+ f, err := os.OpenFile(appPropertiesPath, os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0644)
if err != nil {
- return fmt.Errorf("failure while creating application.properties: %w", err)
+ return fmt.Errorf("failure while opening/creating application.properties: %w", err)
+ }
+ fstat, err := f.Stat()
+ if err != nil {
+ return err
}
if applicationProperties == nil {
// Default build time properties
@@ -231,12 +235,23 @@ func computeApplicationProperties(appPropertiesPath string, applicationPropertie
}
// disable quarkus banner
applicationProperties["quarkus.banner.enabled"] = "false"
+ // camel-quarkus does route discovery at startup, but we don't want
+ // this to happen as routes are loaded at runtime and looking for
+ // routes at build time may try to load camel-k-runtime routes builder
+ // proxies which in some case may fail.
+ applicationProperties["quarkus.camel.routes-discovery.enabled"] = "false"
// 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 {
+ if _, err := f.WriteString("\n"); err != nil {
+ return err
+ }
+ }
// Fill with properties coming from user configuration
for k, v := range applicationProperties {
if _, err := f.WriteString(fmt.Sprintf("%s=%s\n", k, v)); err != nil {
diff --git a/pkg/builder/quarkus_test.go b/pkg/builder/quarkus_test.go
index 791cc24a4..4b994fd4c 100644
--- a/pkg/builder/quarkus_test.go
+++ b/pkg/builder/quarkus_test.go
@@ -162,6 +162,66 @@ func TestGenerateQuarkusProjectWithBuildTimeProperties(t *testing.T) {
require.NoError(t, err)
}
+func TestGenerateQuarkusProjectWithNativeSources(t *testing.T) {
+ tmpDir, err := os.MkdirTemp("", "go-test-camel-k-quarkus-native")
+ require.NoError(t, err)
+ defaultCatalog, err := camel.DefaultCatalog()
+ require.NoError(t, err)
+
+ builderContext := builderContext{
+ C: context.TODO(),
+ Path: tmpDir,
+ Namespace: "test",
+ Build: v1.BuilderTask{
+ Runtime: defaultCatalog.Runtime,
+ Maven: v1.MavenBuildSpec{
+ MavenSpec: v1.MavenSpec{},
+ },
+ Sources: []v1.SourceSpec{v1.NewSourceSpec("Test.java", "bogus, irrelevant for test", v1.LanguageJavaSource)},
+ },
+ }
+ if strings.Contains(defaults.DefaultRuntimeVersion, "SNAPSHOT") {
+ builderContext.Build.Maven.Repositories = []v1.Repository{
+ {
+ ID: "APACHE-SNAPSHOT",
+ Name: "Apache Snapshot",
+ URL: "https://repository.apache.org/content/repositories/snapshots-group",
+ Snapshots: v1.RepositoryPolicy{
+ Enabled: true,
+ UpdatePolicy: "always",
+ ChecksumPolicy: "ignore",
+ },
+ Releases: v1.RepositoryPolicy{
+ Enabled: false,
+ },
+ },
+ }
+ }
+
+ err = prepareProjectWithSources(&builderContext)
+ require.NoError(t, err)
+ err = generateQuarkusProject(&builderContext)
+ require.NoError(t, err)
+ // use local Maven executable in tests
+ t.Setenv("MAVEN_WRAPPER", "false")
+ _, ok := os.LookupEnv("MAVEN_CMD")
+ if !ok {
+ t.Setenv("MAVEN_CMD", "mvn")
+ }
+ err = buildQuarkusRunner(&builderContext)
+ require.NoError(t, err)
+ appProps, err := os.ReadFile(filepath.Join(tmpDir, "maven", "src", "main", "resources", "application.properties"))
+ require.NoError(t, err)
+ assert.Contains(t, string(appProps), "quarkus.camel.routes-discovery.enabled=false\n")
+ assert.Contains(t, string(appProps), "camel.main.routes-include-pattern = classpath:routes/Test.java\n")
+ materializedRoute, err := os.ReadFile(filepath.Join(tmpDir, "maven", "src", "main", "resources", "routes", "Test.java"))
+ require.NoError(t, err)
+ assert.Contains(t, string(materializedRoute), "bogus, irrelevant for test")
+ // 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)
+}
+
func TestBuildQuarkusRunner(t *testing.T) {
tmpDir, err := os.MkdirTemp("", "go-test-camel-k-quarkus")
require.NoError(t, err)