davsclaus commented on code in PR #28675:
URL: https://github.com/apache/camel/pull/28675#discussion_r4421159920


##########
docs/user-manual/modules/ROOT/pages/camel-jbang-projects.adoc:
##########
@@ -178,6 +178,39 @@ TIP: Export logs are stored in `~/.camel/camel-export.log` 
by default.
 Export loads configuration from `application.properties`, where you can set 
runtime, Java version, and other parameters.
 See xref:camel-jbang-configuration.adoc[Configuration] for all `camel.jbang.*` 
options.
 
+=== Exporting from Java
+
+*Since Camel 4.24 (preview)*
+
+Tools that create Camel projects, such as an IDE or a visual designer, can 
export from Java instead of running the `camel` command.
+The `camel-jbang-export` module has the same options as `camel export`, as 
public fields of an `ExportRequest`:
+
+[source,java]
+----
+ExportRequest request = new ExportRequest();
+request.files.add("hello.camel.yaml");
+request.runtime = RuntimeType.main; // or springBoot, quarkus
+request.exportDir = "target/hello";
+
+int exit = new ProjectExporter().export(request);
+----

Review Comment:
   Done in e86d19e0e6a1: the sentence before the first example now says that 
camel-jbang-core must be on the classpath as well, and points to the 
explanation below.
   
   _Claude Code on behalf of davsclaus_



##########
dsl/camel-jbang/camel-jbang-export/src/main/java/org/apache/camel/dsl/jbang/export/ExportContext.java:
##########
@@ -0,0 +1,104 @@
+/*
+ * 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.export;
+
+import java.util.Collection;
+import java.util.Iterator;
+import java.util.List;
+import java.util.ServiceLoader;
+import java.util.function.Function;
+import java.util.function.Predicate;
+
+import org.apache.camel.dsl.jbang.export.common.PluginExporter;
+import org.apache.camel.dsl.jbang.export.common.Printer;
+
+/**
+ * What an export uses from its caller: where it prints, how it resolves the 
dependencies, the exporters of the active
+ * plugins, and how it asks for confirmation (such as before it deletes the 
files of the export directory).
+ */
+public class ExportContext {
+
+    private Printer printer = new Printer.SystemOutPrinter();
+    private DependencyResolver dependencyResolver;
+    private Function<String, Collection<PluginExporter>> pluginExporters = 
repos -> List.of();
+    private Predicate<String> confirm = message -> true;
+
+    public Printer getPrinter() {
+        return printer;
+    }
+
+    /**
+     * Where the export prints (default the console).
+     */
+    public ExportContext withPrinter(Printer printer) {
+        this.printer = printer;
+        return this;
+    }
+
+    /**
+     * The resolver of the dependencies; when none is set, the one registered 
with the {@link ServiceLoader} is used.
+     */
+    public DependencyResolver getDependencyResolver() {
+        if (dependencyResolver == null) {

Review Comment:
   Documented in e86d19e0e6a1: the class Javadoc says an ExportContext is not 
thread-safe, to be configured and used for one export at a time. The rest of it 
(the printer, the confirm callback) is per export anyway, so a shared context 
would need more than a synchronized lazy load.
   
   _Claude Code on behalf of davsclaus_



##########
dsl/camel-jbang/camel-jbang-export/src/main/java/org/apache/camel/dsl/jbang/export/ExportRequest.java:
##########
@@ -0,0 +1,376 @@
+/*
+ * 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.export;
+
+import java.nio.file.Path;
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.camel.dsl.jbang.export.common.MavenResolver;
+import org.apache.camel.dsl.jbang.export.common.QuarkusPlatform;
+import org.apache.camel.dsl.jbang.export.common.RuntimeType;
+
+/**
+ * What to export: the Camel files and the options of the Maven project to 
create, the same as the options of camel
+ * export.
+ * <p>
+ * The fields are public and mutable, as the request is filled in by the 
caller and then completed by
+ * {@link ProjectExporter#prepare(ExportRequest)} with the values of 
application.properties and the profile. The copy
+ * constructor is shallow: the copy shares the lists of the original.
+ */
+public class ExportRequest {
+

Review Comment:
   Added `@since 4.24` to ExportRequest, ExportContext, DependencyResolver and 
ProjectExporter in e86d19e0e6a1.
   
   _Claude Code on behalf of davsclaus_



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to