Fix #1536: take modeline changes into account in dev mode (#1634)
* Fix #1536: take modeline changes into account in dev mode
* fix test dev_mode_test
diff --git a/e2e/common/dev_mode_test.go b/e2e/common/dev_mode_test.go
index 252a96b..6c34de7 100644
--- a/e2e/common/dev_mode_test.go
+++ b/e2e/common/dev_mode_test.go
@@ -24,6 +24,7 @@
import (
"context"
"io"
+ "os"
"testing"
. "github.com/apache/camel-k/e2e/support"
@@ -50,6 +51,9 @@
logScanner := util.NewLogScanner(ctx, piper, `integration "yaml" in phase Running`, "Magicstring!", "Magicjordan!")
+ args := os.Args
+ defer func() { os.Args = args }()
+ os.Args = []string{"kamel", "run", "-n", ns, file, "--dev"}
go kamelRun.Execute()
Eventually(logScanner.IsFound(`integration "yaml" in phase Running`), TestTimeoutMedium).Should(BeTrue())
@@ -74,6 +78,9 @@
logScanner := util.NewLogScanner(ctx, piper, "Magicstring!")
+ args := os.Args
+ defer func() { os.Args = args }()
+ os.Args = []string{"kamel", "-n", ns, "run", remoteFile, "--dev"}
go kamelRun.Execute()
Eventually(logScanner.IsFound("Magicstring!"), TestTimeoutMedium).Should(BeTrue())
diff --git a/examples/SampleModeline.java b/examples/SampleModeline.java
new file mode 100644
index 0000000..556eb2a
--- /dev/null
+++ b/examples/SampleModeline.java
@@ -0,0 +1,28 @@
+// camel-k: dependency=mvn:com.google.guava/guava:28.0-jre
+/*
+ *
+ * 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.
+ */
+
+import org.apache.camel.builder.RouteBuilder;
+
+public class SampleModeline extends RouteBuilder {
+ @Override
+ public void configure() throws Exception {
+ from("timer:tick")
+ .log("Hello Camels K!");
+ }
+}
\ No newline at end of file
diff --git a/pkg/cmd/run.go b/pkg/cmd/run.go
index 7d150af..deb845b 100644
--- a/pkg/cmd/run.go
+++ b/pkg/cmd/run.go
@@ -407,7 +407,20 @@
case <-o.Context.Done():
return
case <-changes:
- _, err := o.updateIntegrationCode(c, sources, catalog)
+ // let's create a new command to parse modeline changes and update our integration
+ newCmd, _, err := createKamelWithModelineCommand(o.Context, os.Args[1:], make(map[string]bool))
+ if err != nil {
+ fmt.Println("Unable to sync integration: ", err.Error())
+ continue
+ }
+ newCmd.Args = o.validateArgs
+ newCmd.PreRunE = o.decode
+ newCmd.RunE = func(cmd *cobra.Command, args []string) error {
+ _, err := o.updateIntegrationCode(c, sources, catalog)
+ return err
+ }
+ newCmd.PostRunE = nil
+ err = newCmd.Execute()
if err != nil {
fmt.Println("Unable to sync integration: ", err.Error())
}