You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by da...@apache.org on 2024/08/22 08:52:02 UTC

(camel) branch jib created (now d2d6ac34663)

This is an automated email from the ASF dual-hosted git repository.

davsclaus pushed a change to branch jib
in repository https://gitbox.apache.org/repos/asf/camel.git


      at d2d6ac34663 CAMEL-21106: camel-jbang - Export to main should keep support for jib/jkube

This branch includes the following new commits:

     new 0db13757042 CAMEL-21106: camel-jbang - Export to main should keep support for jib/jkube
     new 77201e89f78 CAMEL-21106: camel-jbang - Export to main should keep support for jib/jkube
     new d2d6ac34663 CAMEL-21106: camel-jbang - Export to main should keep support for jib/jkube

The 3 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.



(camel) 03/03: CAMEL-21106: camel-jbang - Export to main should keep support for jib/jkube

Posted by da...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

davsclaus pushed a commit to branch jib
in repository https://gitbox.apache.org/repos/asf/camel.git

commit d2d6ac346637122124f2644feba00362625e87e4
Author: Claus Ibsen <cl...@gmail.com>
AuthorDate: Thu Aug 22 10:51:37 2024 +0200

    CAMEL-21106: camel-jbang - Export to main should keep support for jib/jkube
---
 .../dsl/jbang/core/commands/ExportCamelMain.java   |   2 +-
 .../main/resources/templates/main-jkube-pom.tmpl   |  24 +++
 .../resources/templates/main-kubernetes-pom.tmpl   | 208 ---------------------
 .../jbang/core/commands/ExportMainJkubeTest.java   | 105 +++++++++++
 .../src/test/resources/application-jib.properties  |   2 +-
 ...jib.properties => application-jkube.properties} |  11 +-
 6 files changed, 141 insertions(+), 211 deletions(-)

diff --git a/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/ExportCamelMain.java b/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/ExportCamelMain.java
index 507e31157c6..d9d5a86ed61 100644
--- a/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/ExportCamelMain.java
+++ b/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/ExportCamelMain.java
@@ -300,7 +300,7 @@ class ExportCamelMain extends Export {
             sb2.append(context2);
             // jkube is only used for kubernetes
             if (jkube) {
-                is = ExportCamelMain.class.getClassLoader().getResourceAsStream("templates/main-kubernetes-pom.tmpl");
+                is = ExportCamelMain.class.getClassLoader().getResourceAsStream("templates/main-jkube-pom.tmpl");
                 String context3 = IOHelper.loadText(is);
                 IOHelper.close(is);
                 context3 = context3.replaceFirst("\\{\\{ \\.JkubeMavenPluginVersion }}",
diff --git a/dsl/camel-jbang/camel-jbang-core/src/main/resources/templates/main-jkube-pom.tmpl b/dsl/camel-jbang/camel-jbang-core/src/main/resources/templates/main-jkube-pom.tmpl
new file mode 100644
index 00000000000..e016f531a14
--- /dev/null
+++ b/dsl/camel-jbang/camel-jbang-core/src/main/resources/templates/main-jkube-pom.tmpl
@@ -0,0 +1,24 @@
+            <plugin>
+                <groupId>org.eclipse.jkube</groupId>
+                <artifactId>kubernetes-maven-plugin</artifactId>
+                <version>{{ .JkubeMavenPluginVersion }}</version>
+                <configuration>
+                    <images>
+                        <image>
+                            <name>${jib.to.image}</name>
+                            <build>
+                            </build>
+                        </image>
+                    </images>
+                    <resources>
+                        <labels>
+                            <all>
+                                <property>
+                                    <name>${label.runtime}</name>
+                                    <value>camel</value>
+                                </property>
+                            </all>
+                        </labels>
+                    </resources>
+                </configuration>
+            </plugin>
\ No newline at end of file
diff --git a/dsl/camel-jbang/camel-jbang-core/src/main/resources/templates/main-kubernetes-pom.tmpl b/dsl/camel-jbang/camel-jbang-core/src/main/resources/templates/main-kubernetes-pom.tmpl
deleted file mode 100644
index 261ca1ca492..00000000000
--- a/dsl/camel-jbang/camel-jbang-core/src/main/resources/templates/main-kubernetes-pom.tmpl
+++ /dev/null
@@ -1,208 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
-    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
-    <modelVersion>4.0.0</modelVersion>
-
-    <groupId>{{ .GroupId }}</groupId>
-    <artifactId>{{ .ArtifactId }}</artifactId>
-    <version>{{ .Version }}</version>
-
-    <properties>
-        <java.version>{{ .JavaVersion }}</java.version>
-{{ .BuildProperties }}
-    </properties>
-
-    <dependencyManagement>
-        <dependencies>
-            <!-- Camel BOM -->
-            <dependency>
-                <groupId>org.apache.camel</groupId>
-                <artifactId>camel-bom</artifactId>
-                <version>{{ .CamelVersion }}</version>
-                <type>pom</type>
-                <scope>import</scope>
-            </dependency>
-        </dependencies>
-    </dependencyManagement>
-
-{{ .MavenRepositories }}
-
-    <dependencies>
-        <dependency>
-            <groupId>org.apache.camel</groupId>
-            <artifactId>camel-main</artifactId>
-        </dependency>
-        <dependency>
-            <groupId>org.apache.camel</groupId>
-            <artifactId>camel-health</artifactId>
-        </dependency>
-{{ .CamelDependencies }}
-
-        <!-- for logging in color -->
-        <dependency>
-            <groupId>org.fusesource.jansi</groupId>
-            <artifactId>jansi</artifactId>
-            <version>2.4.1</version>
-        </dependency>
-        <dependency>
-            <groupId>org.apache.logging.log4j</groupId>
-            <artifactId>log4j-api</artifactId>
-            <version>2.23.1</version>
-        </dependency>
-        <dependency>
-            <groupId>org.apache.logging.log4j</groupId>
-            <artifactId>log4j-slf4j2-impl</artifactId>
-            <version>2.23.1</version>
-        </dependency>
-        <dependency>
-            <groupId>org.apache.logging.log4j</groupId>
-            <artifactId>log4j-core</artifactId>
-            <version>2.23.1</version>
-        </dependency>
-
-        <dependency>
-            <groupId>org.apache.camel</groupId>
-            <artifactId>camel-test-junit5</artifactId>
-            <scope>test</scope>
-        </dependency>
-    </dependencies>
-
-    <build>
-        <plugins>
-            <plugin>
-                <groupId>org.apache.maven.plugins</groupId>
-                <artifactId>maven-compiler-plugin</artifactId>
-                <version>3.13.0</version>
-                <configuration>
-                    <source>${java.version}</source>
-                    <target>${java.version}</target>
-                </configuration>
-            </plugin>
-            <!-- mvn camel:run or mvn camel:dev -->
-            <plugin>
-                <groupId>org.apache.camel</groupId>
-                <artifactId>camel-maven-plugin</artifactId>
-                <version>{{ .CamelVersion }}</version>
-                <configuration>
-                    <mainClass>{{ .MainClassname }}</mainClass>
-                </configuration>
-                <executions>
-                    <execution>
-                        <goals>
-                            <goal>prepare-fatjar</goal>
-                        </goals>
-                    </execution>
-                </executions>
-            </plugin>
-            <!-- package as runner jar -->
-            <plugin>
-                <groupId>org.apache.maven.plugins</groupId>
-                <artifactId>maven-assembly-plugin</artifactId>
-                <version>3.7.1</version>
-                <configuration>
-                    <descriptors>
-                        <descriptor>src/main/resources/assembly/runner.xml</descriptor>
-                    </descriptors>
-                    <archive>
-                        <manifest>
-                            <mainClass>{{ .MainClassname }}</mainClass>
-                        </manifest>
-                        <manifestEntries>
-                            <Multi-Release>true</Multi-Release>
-                        </manifestEntries>
-                    </archive>
-                    <appendAssemblyId>false</appendAssemblyId>
-                </configuration>
-                <executions>
-                    <execution>
-                        <id>make-assembly</id>
-                        <phase>package</phase>
-                        <goals>
-                            <goal>single</goal>
-                        </goals>
-                    </execution>
-                </executions>
-            </plugin>
-            <plugin>
-                <groupId>org.eclipse.jkube</groupId>
-                <artifactId>kubernetes-maven-plugin</artifactId>
-                <version>${camel.main.jkube.version}</version>
-                <configuration>
-                    <imagePullPolicy>${camel.main.kubernetes.image-pull-policy}</imagePullPolicy>
-                    <buildStrategy>docker</buildStrategy>
-                    <images>
-                        <image>
-                            <name>${camel.main.kubernetes.image-name}</name>
-                            <build>
-                                <from>eclipse-temurin:{{ .JavaVersion }}</from>
-                                <createImageOptions>
-                                    <platform>linux/amd64</platform>
-                                    <platform>linux/arm64</platform>
-                                </createImageOptions>
-                                <ports>
-                                    <port>${camel.main.kubernetes.ports.http.container-port}</port>
-                                </ports>
-                                <entryPoint>
-                                    <exec>
-                                        <arg>java</arg>
-                                        <arg>-jar</arg>
-                                        <arg>/maven/${project.artifactId}-${project.version}.jar</arg>
-                                    </exec>
-                                </entryPoint>
-                            </build>
-                        </image>
-                    </images>
-                </configuration>
-                <executions>
-                    <execution>
-                        <goals>
-                            <goal>build</goal>
-                            <goal>resource</goal>
-                        </goals>
-                        <phase>package</phase>
-                    </execution>
-                </executions>
-            </plugin>
-            <plugin>
-                <groupId>org.apache.maven.plugins</groupId>
-                <artifactId>maven-resources-plugin</artifactId>
-                <executions>
-                    <execution>
-                        <phase>package</phase>
-                        <goals>
-                            <goal>copy-resources</goal>
-                        </goals>
-                        <configuration>
-                            <!-- For symmetry with Quarkus, copy kubernetes.yml to the same target location -->
-                            <outputDirectory>${project.build.directory}/kubernetes</outputDirectory>
-                            <resources>
-                                <resource>
-                                    <directory>${project.build.directory}/classes/META-INF/jkube</directory>
-                                </resource>
-                            </resources>
-                        </configuration>
-                    </execution>
-                </executions>
-            </plugin>
-        </plugins>
-    </build>
-
-    <profiles>
-        <profile>
-            <id>camel.debug</id>
-            <activation>
-                <property>
-                    <name>camel.debug</name>
-                    <value>true</value>
-                </property>
-            </activation>
-            <dependencies>
-                <dependency>
-                    <groupId>org.apache.camel</groupId>
-                    <artifactId>camel-debug</artifactId>
-                </dependency>
-            </dependencies>
-        </profile>
-    </profiles>
-
-</project>
diff --git a/dsl/camel-jbang/camel-jbang-core/src/test/java/org/apache/camel/dsl/jbang/core/commands/ExportMainJkubeTest.java b/dsl/camel-jbang/camel-jbang-core/src/test/java/org/apache/camel/dsl/jbang/core/commands/ExportMainJkubeTest.java
new file mode 100644
index 00000000000..b809c68c11c
--- /dev/null
+++ b/dsl/camel-jbang/camel-jbang-core/src/test/java/org/apache/camel/dsl/jbang/core/commands/ExportMainJkubeTest.java
@@ -0,0 +1,105 @@
+/*
+ * 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 org.apache.camel.dsl.jbang.core.commands;
+
+import java.io.File;
+import java.io.FileReader;
+import java.io.IOException;
+import java.nio.file.Files;
+import java.nio.file.StandardCopyOption;
+import java.util.stream.Stream;
+
+import org.apache.camel.dsl.jbang.core.common.RuntimeType;
+import org.apache.camel.util.FileUtil;
+import org.apache.maven.model.Model;
+import org.apache.maven.model.Plugin;
+import org.apache.maven.model.io.xpp3.MavenXpp3Reader;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.params.ParameterizedTest;
+import org.junit.jupiter.params.provider.Arguments;
+import org.junit.jupiter.params.provider.MethodSource;
+import picocli.CommandLine;
+
+class ExportMainJkubeTest {
+
+    private File workingDir;
+    private File profile = new File(".", "application.properties");
+
+    @BeforeEach
+    public void setup() throws IOException {
+        workingDir = Files.createTempDirectory("camel-export").toFile();
+    }
+
+    @AfterEach
+    public void end() throws IOException {
+        // force removing, since deleteOnExit is not removing.
+        FileUtil.removeDir(workingDir);
+        FileUtil.deleteFile(profile);
+    }
+
+    private static Stream<Arguments> runtimeProvider() {
+        return Stream.of(
+                Arguments.of(RuntimeType.main));
+    }
+
+    @ParameterizedTest
+    @MethodSource("runtimeProvider")
+    public void shouldGenerateProjectWithJib(RuntimeType rt) throws Exception {
+        // prepare as we need application.properties that contains jkube settings
+        Files.copy(new File("src/test/resources/application-jkube.properties").toPath(), profile.toPath(),
+                StandardCopyOption.REPLACE_EXISTING);
+
+        Export command = new ExportCamelMain(new CamelJBangMain());
+        CommandLine.populateCommand(command, "--gav=examples:route:1.0.0", "--dir=" + workingDir,
+                "--runtime=%s".formatted(rt.runtime()), "target/test-classes/route.yaml");
+        int exit = command.doCall();
+
+        Assertions.assertEquals(0, exit);
+        Model model = readMavenModel();
+        Assertions.assertEquals("examples", model.getGroupId());
+        Assertions.assertEquals("route", model.getArtifactId());
+        Assertions.assertEquals("1.0.0", model.getVersion());
+        Assertions.assertEquals("17", model.getProperties().getProperty("java.version"));
+        Assertions.assertEquals("abc", model.getProperties().getProperty("jib.label"));
+        Assertions.assertEquals("eclipse-temurin:17-jre", model.getProperties().getProperty("jib.from.image"));
+
+        // should contain jib and jkube plugin
+        Assertions.assertEquals(5, model.getBuild().getPlugins().size());
+        Plugin p = model.getBuild().getPlugins().get(3);
+        Assertions.assertEquals("com.google.cloud.tools", p.getGroupId());
+        Assertions.assertEquals("jib-maven-plugin", p.getArtifactId());
+        p = model.getBuild().getPlugins().get(4);
+        Assertions.assertEquals("org.eclipse.jkube", p.getGroupId());
+        Assertions.assertEquals("kubernetes-maven-plugin", p.getArtifactId());
+        Assertions.assertEquals("1.17.0", p.getVersion());
+
+        command.printConfigurationValues("export command");
+    }
+
+    private Model readMavenModel() throws Exception {
+        File f = workingDir.toPath().resolve("pom.xml").toFile();
+        Assertions.assertTrue(f.isFile(), "Not a pom.xml file: " + f);
+        MavenXpp3Reader mavenReader = new MavenXpp3Reader();
+        Model model = mavenReader.read(new FileReader(f));
+        model.setPomFile(f);
+        return model;
+    }
+
+}
diff --git a/dsl/camel-jbang/camel-jbang-core/src/test/resources/application-jib.properties b/dsl/camel-jbang/camel-jbang-core/src/test/resources/application-jib.properties
index ab1a3c700f7..dae0d9e7910 100644
--- a/dsl/camel-jbang/camel-jbang-core/src/test/resources/application-jib.properties
+++ b/dsl/camel-jbang/camel-jbang-core/src/test/resources/application-jib.properties
@@ -14,4 +14,4 @@
 ## See the License for the specific language governing permissions and
 ## limitations under the License.
 ## ---------------------------------------------------------------------------
-jib.label=abc
\ No newline at end of file
+jib.label=abc
diff --git a/dsl/camel-jbang/camel-jbang-core/src/test/resources/application-jib.properties b/dsl/camel-jbang/camel-jbang-core/src/test/resources/application-jkube.properties
similarity index 74%
copy from dsl/camel-jbang/camel-jbang-core/src/test/resources/application-jib.properties
copy to dsl/camel-jbang/camel-jbang-core/src/test/resources/application-jkube.properties
index ab1a3c700f7..f9ae1a54da3 100644
--- a/dsl/camel-jbang/camel-jbang-core/src/test/resources/application-jib.properties
+++ b/dsl/camel-jbang/camel-jbang-core/src/test/resources/application-jkube.properties
@@ -14,4 +14,13 @@
 ## See the License for the specific language governing permissions and
 ## limitations under the License.
 ## ---------------------------------------------------------------------------
-jib.label=abc
\ No newline at end of file
+jib.label=abc
+label.runtime=camel-main
+jkube.version=1.17.0
+jkube.skip.build=true
+jkube.imagePullPolicy=Always
+jkube.enricher.jkube-controller.type=Deployment
+jkube.enricher.jkube-service.port=80:8080,443:8080
+jkube.enricher.jkube-project-label.group=foo
+jkube.enricher.jkube-project-label.provider=asf
+jkube.recreate=true
\ No newline at end of file


(camel) 01/03: CAMEL-21106: camel-jbang - Export to main should keep support for jib/jkube

Posted by da...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

davsclaus pushed a commit to branch jib
in repository https://gitbox.apache.org/repos/asf/camel.git

commit 0db13757042f816da4ede990d200de14bc9f7e80
Author: Claus Ibsen <cl...@gmail.com>
AuthorDate: Thu Aug 22 10:25:13 2024 +0200

    CAMEL-21106: camel-jbang - Export to main should keep support for jib/jkube
---
 .../dsl/jbang/core/commands/ExportCamelMain.java   |  83 +++++++++++++++++
 .../src/main/resources/templates/main-pom.tmpl     |   2 +
 .../dsl/jbang/core/commands/ExportMainJibTest.java | 101 +++++++++++++++++++++
 .../src/test/resources/application.properties      |  17 ++++
 4 files changed, 203 insertions(+)

diff --git a/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/ExportCamelMain.java b/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/ExportCamelMain.java
index 4208a5af82c..507e31157c6 100644
--- a/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/ExportCamelMain.java
+++ b/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/ExportCamelMain.java
@@ -232,9 +232,92 @@ class ExportCamelMain extends Export {
 
         context = context.replaceFirst("\\{\\{ \\.CamelDependencies }}", sb.toString());
 
+        // include docker/kubernetes with jib/jkube
+        context = enrichMavenPomJib(context, settings, profile);
+
         IOHelper.writeText(context, new FileOutputStream(pom, false));
     }
 
+    protected String enrichMavenPomJib(String context, File settings, File profile) throws Exception {
+        StringBuilder sb1 = new StringBuilder();
+        StringBuilder sb2 = new StringBuilder();
+
+        // is kubernetes included?
+        Properties prop = new CamelCaseOrderedProperties();
+        if (profile.exists()) {
+            RuntimeUtil.loadProperties(prop, profile);
+        }
+        // include additional build properties
+        boolean jib = prop.stringPropertyNames().stream().anyMatch(s -> s.startsWith("jib."));
+        boolean jkube = prop.stringPropertyNames().stream().anyMatch(s -> s.startsWith("jkube."));
+        // jib is used for docker and kubernetes, jkube is only used for kubernetes
+        if (jib || jkube) {
+            // include all jib/jkube/label properties
+            String fromImage = null;
+            for (String key : prop.stringPropertyNames()) {
+                String value = prop.getProperty(key);
+                if ("jib.from.image".equals(key)) {
+                    fromImage = value;
+                }
+                boolean accept = key.startsWith("jkube.") || key.startsWith("jib.") || key.startsWith("label.");
+                if (accept) {
+                    sb1.append(String.format("        <%s>%s</%s>%n", key, value, key));
+                }
+            }
+            // from image is mandatory so use a default image if none provided
+            if (fromImage == null) {
+                fromImage = "eclipse-temurin:" + javaVersion + "-jre";
+                sb1.append(String.format("        <%s>%s</%s>%n", "jib.from.image", fromImage, "jib.from.image"));
+            }
+
+            InputStream is = ExportCamelMain.class.getClassLoader().getResourceAsStream("templates/main-docker-pom.tmpl");
+            String context2 = IOHelper.loadText(is);
+            IOHelper.close(is);
+
+            context2 = context2.replaceFirst("\\{\\{ \\.JibMavenPluginVersion }}", jibMavenPluginVersion(settings, prop));
+
+            // image from/to auth
+            String auth = "";
+            if (prop.stringPropertyNames().stream().anyMatch(s -> s.startsWith("jib.from.auth."))) {
+                is = ExportCamelMain.class.getClassLoader().getResourceAsStream("templates/main-docker-from-auth-pom.tmpl");
+                auth = IOHelper.loadText(is);
+                IOHelper.close(is);
+            }
+            context2 = context2.replace("{{ .JibFromImageAuth }}", auth);
+            auth = "";
+            if (prop.stringPropertyNames().stream().anyMatch(s -> s.startsWith("jib.to.auth."))) {
+                is = ExportCamelMain.class.getClassLoader().getResourceAsStream("templates/main-docker-to-auth-pom.tmpl");
+                auth = IOHelper.loadText(is);
+                IOHelper.close(is);
+            }
+            context2 = context2.replace("{{ .JibToImageAuth }}", auth);
+            // http port setting
+            int port = httpServerPort(settings);
+            if (port == -1) {
+                port = 8080;
+            }
+            context2 = context2.replaceFirst("\\{\\{ \\.Port }}", String.valueOf(port));
+            sb2.append(context2);
+            // jkube is only used for kubernetes
+            if (jkube) {
+                is = ExportCamelMain.class.getClassLoader().getResourceAsStream("templates/main-kubernetes-pom.tmpl");
+                String context3 = IOHelper.loadText(is);
+                IOHelper.close(is);
+                context3 = context3.replaceFirst("\\{\\{ \\.JkubeMavenPluginVersion }}",
+                        jkubeMavenPluginVersion(settings, prop));
+                sb2.append(context3);
+            }
+        }
+
+        // remove empty lines
+        String s1 = sb1.toString().replaceAll("(\\r?\\n){2,}", "\n");
+        String s2 = sb2.toString().replaceAll("(\\r?\\n){2,}", "\n");
+
+        context = context.replace("{{ .CamelKubernetesProperties }}", s1);
+        context = context.replace("{{ .CamelKubernetesPlugins }}", s2);
+        return context;
+    }
+
     @Override
     protected Set<String> resolveDependencies(File settings, File profile) throws Exception {
         Set<String> answer = super.resolveDependencies(settings, profile);
diff --git a/dsl/camel-jbang/camel-jbang-core/src/main/resources/templates/main-pom.tmpl b/dsl/camel-jbang/camel-jbang-core/src/main/resources/templates/main-pom.tmpl
index 08f5eebc89c..b454ee451ec 100644
--- a/dsl/camel-jbang/camel-jbang-core/src/main/resources/templates/main-pom.tmpl
+++ b/dsl/camel-jbang/camel-jbang-core/src/main/resources/templates/main-pom.tmpl
@@ -10,6 +10,7 @@
     <properties>
         <java.version>{{ .JavaVersion }}</java.version>
 {{ .BuildProperties }}
+{{ .CamelKubernetesProperties }}
     </properties>
 
     <dependencyManagement>
@@ -125,6 +126,7 @@
                     </execution>
                 </executions>
             </plugin>
+{{ .CamelKubernetesPlugins }}
         </plugins>
     </build>
 
diff --git a/dsl/camel-jbang/camel-jbang-core/src/test/java/org/apache/camel/dsl/jbang/core/commands/ExportMainJibTest.java b/dsl/camel-jbang/camel-jbang-core/src/test/java/org/apache/camel/dsl/jbang/core/commands/ExportMainJibTest.java
new file mode 100644
index 00000000000..3a021e7fe7f
--- /dev/null
+++ b/dsl/camel-jbang/camel-jbang-core/src/test/java/org/apache/camel/dsl/jbang/core/commands/ExportMainJibTest.java
@@ -0,0 +1,101 @@
+/*
+ * 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 org.apache.camel.dsl.jbang.core.commands;
+
+import java.io.File;
+import java.io.FileReader;
+import java.io.IOException;
+import java.nio.file.Files;
+import java.nio.file.StandardCopyOption;
+import java.util.stream.Stream;
+
+import org.apache.camel.dsl.jbang.core.common.RuntimeType;
+import org.apache.camel.util.FileUtil;
+import org.apache.maven.model.Model;
+import org.apache.maven.model.Plugin;
+import org.apache.maven.model.io.xpp3.MavenXpp3Reader;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.params.ParameterizedTest;
+import org.junit.jupiter.params.provider.Arguments;
+import org.junit.jupiter.params.provider.MethodSource;
+import picocli.CommandLine;
+
+class ExportMainJibTest {
+
+    private File workingDir;
+    private File profile = new File(".", "application.properties");
+
+    @BeforeEach
+    public void setup() throws IOException {
+        workingDir = Files.createTempDirectory("camel-export").toFile();
+    }
+
+    @AfterEach
+    public void end() throws IOException {
+        // force removing, since deleteOnExit is not removing.
+        FileUtil.removeDir(workingDir);
+        FileUtil.deleteFile(profile);
+    }
+
+    private static Stream<Arguments> runtimeProvider() {
+        return Stream.of(
+                Arguments.of(RuntimeType.main));
+    }
+
+    @ParameterizedTest
+    @MethodSource("runtimeProvider")
+    public void shouldGenerateProjectWithJib(RuntimeType rt) throws Exception {
+        // prepare as we need application.properties that contains jib settings
+        Files.copy(new File("src/test/resources/application.properties").toPath(), profile.toPath(),
+                StandardCopyOption.REPLACE_EXISTING);
+
+        Export command = new ExportCamelMain(new CamelJBangMain());
+        CommandLine.populateCommand(command, "--gav=examples:route:1.0.0", "--dir=" + workingDir,
+                "--runtime=%s".formatted(rt.runtime()), "target/test-classes/route.yaml");
+        int exit = command.doCall();
+
+        Assertions.assertEquals(0, exit);
+        Model model = readMavenModel();
+        Assertions.assertEquals("examples", model.getGroupId());
+        Assertions.assertEquals("route", model.getArtifactId());
+        Assertions.assertEquals("1.0.0", model.getVersion());
+        Assertions.assertEquals("17", model.getProperties().getProperty("java.version"));
+        Assertions.assertEquals("abc", model.getProperties().getProperty("jib.label"));
+        Assertions.assertEquals("eclipse-temurin:17-jre", model.getProperties().getProperty("jib.from.image"));
+
+        // should contain jib plugin
+        Assertions.assertEquals(4, model.getBuild().getPlugins().size());
+        Plugin p = model.getBuild().getPlugins().get(3);
+        Assertions.assertEquals("com.google.cloud.tools", p.getGroupId());
+        Assertions.assertEquals("jib-maven-plugin", p.getArtifactId());
+
+        command.printConfigurationValues("export command");
+    }
+
+    private Model readMavenModel() throws Exception {
+        File f = workingDir.toPath().resolve("pom.xml").toFile();
+        Assertions.assertTrue(f.isFile(), "Not a pom.xml file: " + f);
+        MavenXpp3Reader mavenReader = new MavenXpp3Reader();
+        Model model = mavenReader.read(new FileReader(f));
+        model.setPomFile(f);
+        return model;
+    }
+
+}
diff --git a/dsl/camel-jbang/camel-jbang-core/src/test/resources/application.properties b/dsl/camel-jbang/camel-jbang-core/src/test/resources/application.properties
new file mode 100644
index 00000000000..ab1a3c700f7
--- /dev/null
+++ b/dsl/camel-jbang/camel-jbang-core/src/test/resources/application.properties
@@ -0,0 +1,17 @@
+## ---------------------------------------------------------------------------
+## 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.
+## ---------------------------------------------------------------------------
+jib.label=abc
\ No newline at end of file


(camel) 02/03: CAMEL-21106: camel-jbang - Export to main should keep support for jib/jkube

Posted by da...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

davsclaus pushed a commit to branch jib
in repository https://gitbox.apache.org/repos/asf/camel.git

commit 77201e89f785b83a98a74ddf880963867b3e5337
Author: Claus Ibsen <cl...@gmail.com>
AuthorDate: Thu Aug 22 10:27:07 2024 +0200

    CAMEL-21106: camel-jbang - Export to main should keep support for jib/jkube
---
 .../org/apache/camel/dsl/jbang/core/commands/ExportMainJibTest.java     | 2 +-
 .../resources/{application.properties => application-jib.properties}    | 0
 2 files changed, 1 insertion(+), 1 deletion(-)

diff --git a/dsl/camel-jbang/camel-jbang-core/src/test/java/org/apache/camel/dsl/jbang/core/commands/ExportMainJibTest.java b/dsl/camel-jbang/camel-jbang-core/src/test/java/org/apache/camel/dsl/jbang/core/commands/ExportMainJibTest.java
index 3a021e7fe7f..7737b4dc4e8 100644
--- a/dsl/camel-jbang/camel-jbang-core/src/test/java/org/apache/camel/dsl/jbang/core/commands/ExportMainJibTest.java
+++ b/dsl/camel-jbang/camel-jbang-core/src/test/java/org/apache/camel/dsl/jbang/core/commands/ExportMainJibTest.java
@@ -63,7 +63,7 @@ class ExportMainJibTest {
     @MethodSource("runtimeProvider")
     public void shouldGenerateProjectWithJib(RuntimeType rt) throws Exception {
         // prepare as we need application.properties that contains jib settings
-        Files.copy(new File("src/test/resources/application.properties").toPath(), profile.toPath(),
+        Files.copy(new File("src/test/resources/application-jib.properties").toPath(), profile.toPath(),
                 StandardCopyOption.REPLACE_EXISTING);
 
         Export command = new ExportCamelMain(new CamelJBangMain());
diff --git a/dsl/camel-jbang/camel-jbang-core/src/test/resources/application.properties b/dsl/camel-jbang/camel-jbang-core/src/test/resources/application-jib.properties
similarity index 100%
rename from dsl/camel-jbang/camel-jbang-core/src/test/resources/application.properties
rename to dsl/camel-jbang/camel-jbang-core/src/test/resources/application-jib.properties