This is an automated email from the ASF dual-hosted git repository. davsclaus pushed a commit to branch main in repository https://gitbox.apache.org/repos/asf/camel.git
commit 0e0ca2fe9c60fa97ac1d7a6041b6dac99b929f94 Author: Claus Ibsen <[email protected]> AuthorDate: Thu Apr 21 21:12:45 2022 +0200 CAMEL-17998: camel-jbang - fat-jar command --- bom/camel-bom/pom.xml | 5 ++ .../org/apache/camel/catalog/others.properties | 1 + .../apache/camel/catalog/others/fatjar-main.json | 15 ++++ dsl/camel-fatjar-main/pom.xml | 83 ++++++++++++++++++++++ .../services/org/apache/camel/other.properties | 7 ++ .../src/generated/resources/fatjar-main.json | 15 ++++ .../org/apache/camel/main/fatjar/FatJarMain.java | 64 +++++++++++++++++ .../org/apache/camel/main/fatjar/RuntimeUtil.java | 64 +++++++++++++++++ .../camel/dsl/jbang/core/commands/FatJar.java | 3 +- dsl/pom.xml | 1 + parent/pom.xml | 5 ++ 11 files changed, 262 insertions(+), 1 deletion(-) diff --git a/bom/camel-bom/pom.xml b/bom/camel-bom/pom.xml index 39faef5b892..c55def261d7 100644 --- a/bom/camel-bom/pom.xml +++ b/bom/camel-bom/pom.xml @@ -757,6 +757,11 @@ <artifactId>camel-fastjson</artifactId> <version>${project.version}</version> </dependency> + <dependency> + <groupId>org.apache.camel</groupId> + <artifactId>camel-fatjar-main</artifactId> + <version>${project.version}</version> + </dependency> <dependency> <groupId>org.apache.camel</groupId> <artifactId>camel-fhir</artifactId> diff --git a/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/others.properties b/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/others.properties index 3ffa5dcfd71..826220e2d8d 100644 --- a/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/others.properties +++ b/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/others.properties @@ -15,6 +15,7 @@ debug elytron endpointdsl etcd3 +fatjar-main groovy-dsl headersmap health diff --git a/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/others/fatjar-main.json b/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/others/fatjar-main.json new file mode 100644 index 00000000000..caabf64766f --- /dev/null +++ b/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/others/fatjar-main.json @@ -0,0 +1,15 @@ +{ + "other": { + "kind": "other", + "name": "fatjar-main", + "title": "Fatjar Main", + "description": "Main to run Camel as Fat-Jar standalone", + "deprecated": false, + "firstVersion": "3.17.0", + "label": "jbang", + "supportLevel": "Experimental", + "groupId": "org.apache.camel", + "artifactId": "camel-fatjar-main", + "version": "3.17.0-SNAPSHOT" + } +} diff --git a/dsl/camel-fatjar-main/pom.xml b/dsl/camel-fatjar-main/pom.xml new file mode 100644 index 00000000000..ee50ce4e293 --- /dev/null +++ b/dsl/camel-fatjar-main/pom.xml @@ -0,0 +1,83 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + + 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. + +--> +<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 http://maven.apache.org/xsd/maven-4.0.0.xsd"> + <modelVersion>4.0.0</modelVersion> + + <parent> + <groupId>org.apache.camel</groupId> + <artifactId>dsl</artifactId> + <version>3.17.0-SNAPSHOT</version> + </parent> + + <artifactId>camel-fatjar-main</artifactId> + <packaging>jar</packaging> + + <name>Camel :: Far-JAR Main</name> + <description>Main to run Camel as Fat-Jar standalone</description> + + <properties> + <firstVersion>3.17.0</firstVersion> + <supportLevel>Experimental</supportLevel> + <label>jbang</label> + </properties> + + <dependencies> + <dependency> + <groupId>org.apache.camel</groupId> + <artifactId>camel-kamelet-main</artifactId> + </dependency> + <dependency> + <groupId>org.apache.logging.log4j</groupId> + <artifactId>log4j-core</artifactId> + </dependency> + </dependencies> + + <build> + <plugins> + + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-jar-plugin</artifactId> + <configuration> + <archive> + <manifest> + <mainClass>org.apache.camel.main.fatjar.FatJarMain</mainClass> + </manifest> + </archive> + </configuration> + </plugin> + + <plugin> + <groupId>org.apache.camel</groupId> + <artifactId>camel-package-maven-plugin</artifactId> + <executions> + <execution> + <id>generate</id> + <goals> + <goal>generate-others-list</goal> + </goals> + </execution> + </executions> + </plugin> + </plugins> + </build> + +</project> diff --git a/dsl/camel-fatjar-main/src/generated/resources/META-INF/services/org/apache/camel/other.properties b/dsl/camel-fatjar-main/src/generated/resources/META-INF/services/org/apache/camel/other.properties new file mode 100644 index 00000000000..6602ddfbc7c --- /dev/null +++ b/dsl/camel-fatjar-main/src/generated/resources/META-INF/services/org/apache/camel/other.properties @@ -0,0 +1,7 @@ +# Generated by camel build tools - do NOT edit this file! +name=fatjar-main +groupId=org.apache.camel +artifactId=camel-fatjar-main +version=3.17.0-SNAPSHOT +projectName=Camel :: Far-JAR Main +projectDescription=Main to run Camel as Fat-Jar standalone diff --git a/dsl/camel-fatjar-main/src/generated/resources/fatjar-main.json b/dsl/camel-fatjar-main/src/generated/resources/fatjar-main.json new file mode 100644 index 00000000000..caabf64766f --- /dev/null +++ b/dsl/camel-fatjar-main/src/generated/resources/fatjar-main.json @@ -0,0 +1,15 @@ +{ + "other": { + "kind": "other", + "name": "fatjar-main", + "title": "Fatjar Main", + "description": "Main to run Camel as Fat-Jar standalone", + "deprecated": false, + "firstVersion": "3.17.0", + "label": "jbang", + "supportLevel": "Experimental", + "groupId": "org.apache.camel", + "artifactId": "camel-fatjar-main", + "version": "3.17.0-SNAPSHOT" + } +} diff --git a/dsl/camel-fatjar-main/src/main/java/org/apache/camel/main/fatjar/FatJarMain.java b/dsl/camel-fatjar-main/src/main/java/org/apache/camel/main/fatjar/FatJarMain.java new file mode 100644 index 00000000000..ca4aafc5772 --- /dev/null +++ b/dsl/camel-fatjar-main/src/main/java/org/apache/camel/main/fatjar/FatJarMain.java @@ -0,0 +1,64 @@ +/* + * 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.main.fatjar; + +import java.io.FileInputStream; + +import org.apache.camel.main.KameletMain; +import org.apache.camel.util.OrderedProperties; + +/** + * Main class to run Camel as a fat-jar packaged by camel-jbang + */ +public class FatJarMain extends KameletMain { + + public static final String RUN_SETTINGS_FILE = "camel-jbang-run.properties"; + + public static void main(String... args) throws Exception { + FatJarMain main = new FatJarMain(); + int code = main.run(args); + if (code != 0) { + System.exit(code); + } + // normal exit + } + + @Override + protected void doBuild() throws Exception { + setAppName("Apache Camel (FatJar)"); + setDownload(false); // no need for download as all is included in fat-jar + + // load configuration file + OrderedProperties prop = new OrderedProperties(); + prop.load(new FileInputStream(RUN_SETTINGS_FILE)); + + // setup embedded log4j logging + String loggingLevel = prop.getProperty("loggingLevel", "info"); + RuntimeUtil.configureLog(loggingLevel); + + // setup configurations + for (String key : prop.stringPropertyNames()) { + String value = prop.getProperty(key); + if (key.startsWith("camel.")) { + addInitialProperty(key, value); + } + } + + super.doBuild(); + } + +} diff --git a/dsl/camel-fatjar-main/src/main/java/org/apache/camel/main/fatjar/RuntimeUtil.java b/dsl/camel-fatjar-main/src/main/java/org/apache/camel/main/fatjar/RuntimeUtil.java new file mode 100644 index 00000000000..aa4e91263e1 --- /dev/null +++ b/dsl/camel-fatjar-main/src/main/java/org/apache/camel/main/fatjar/RuntimeUtil.java @@ -0,0 +1,64 @@ +/* + * 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.main.fatjar; + +import org.apache.logging.log4j.Level; +import org.apache.logging.log4j.core.config.Configurator; +import org.slf4j.LoggerFactory; + +public final class RuntimeUtil { + + static { + Configurator.initialize("CamelFatJar", "log4j2.properties"); + } + + private RuntimeUtil() { + } + + public static void configureLog(String level) { + level = level.toLowerCase(); + + switch (level) { + case "off": + Configurator.setRootLevel(Level.OFF); + break; + case "trace": + Configurator.setRootLevel(Level.TRACE); + break; + case "debug": + Configurator.setRootLevel(Level.DEBUG); + break; + case "info": + Configurator.setRootLevel(Level.INFO); + break; + case "warn": + Configurator.setRootLevel(Level.WARN); + break; + case "error": + Configurator.setRootLevel(Level.ERROR); + break; + case "fatal": + Configurator.setRootLevel(Level.FATAL); + break; + default: { + Configurator.setRootLevel(Level.INFO); + LoggerFactory.getLogger(RuntimeUtil.class).warn("Invalid logging level: {}", level); + } + } + } + +} diff --git a/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/FatJar.java b/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/FatJar.java index ee327ac9140..20d62f96d0c 100644 --- a/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/FatJar.java +++ b/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/FatJar.java @@ -82,7 +82,7 @@ class FatJar implements Callable<Integer> { lines.add("dependency=org.apache.logging.log4j:log4j-slf4j-impl:2.17.2"); lines.add("dependency=org.fusesource.jansi:jansi:2.4.0"); - // include camel-kamelet-main as its a core dependency needed + // include camel-kamelet-main/camel-fatjar-main as they are needed Optional<MavenGav> first = lines.stream() .filter(l -> l.startsWith("dependency=")) .map(l -> MavenGav.parseGav(null, StringHelper.after(l, "dependency="))) @@ -91,6 +91,7 @@ class FatJar implements Callable<Integer> { if (first.isPresent()) { String v = first.get().getVersion(); lines.add(0, "dependency=mvn:org.apache.camel:camel-kamelet-main:" + v); + lines.add(0, "dependency=mvn:org.apache.camel:camel-fatjar-main:" + v); } // JARs should be in lib sub-folder diff --git a/dsl/pom.xml b/dsl/pom.xml index af868959420..ba8659b13ce 100644 --- a/dsl/pom.xml +++ b/dsl/pom.xml @@ -49,6 +49,7 @@ <module>camel-jsh-dsl</module> <module>camel-kotlin-dsl</module> <module>camel-kamelet-main</module> + <module>camel-fatjar-main</module> <module>camel-jbang</module> </modules> diff --git a/parent/pom.xml b/parent/pom.xml index 92c054ee9a5..61795bbf144 100644 --- a/parent/pom.xml +++ b/parent/pom.xml @@ -2786,6 +2786,11 @@ <artifactId>camel-groovy-dsl-common</artifactId> <version>${project.version}</version> </dependency> + <dependency> + <groupId>org.apache.camel</groupId> + <artifactId>camel-fatjar-main</artifactId> + <version>${project.version}</version> + </dependency> <dependency> <groupId>org.apache.camel</groupId> <artifactId>camel-kamelet-main</artifactId>
