gnodet-bot commented on code in PR #26660:
URL: https://github.com/apache/camel/pull/26660#discussion_r4060127429
##########
dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/ai/IntegrationLauncher.java:
##########
@@ -165,6 +173,24 @@ static List<String> sourceFiles(Path directory) {
* @param extraArgs further {@code camel run} arguments
* @return the arguments after the camel command itself
*/
+ /** The {@code camel run --source-dir=.} arguments: the directory the
process starts in is the app. */
+ static List<String> sourceDirArguments(String name, boolean dev,
List<String> extraArgs) {
Review Comment:
**Javadoc misplacement**: `sourceDirArguments` was inserted after the
closing `*/` of the old `runArguments` Javadoc block, so the structure is now:
```
/** The camel run arguments for the given files... <-- @param files,
@param name, ...
* @return the arguments after the camel command itself
*/
/** The camel run --source-dir=. arguments: ... <-- one-liner Javadoc
static List<String> sourceDirArguments(...) <-- gets the one-liner
(correct)
static List<String> runArguments(...) <-- now has NO Javadoc
```
Javadoc tooling attaches the immediately-preceding `/**...*/` block, so
`sourceDirArguments` gets the one-liner (fine) and `runArguments` loses its
Javadoc entirely. Move the `sourceDirArguments` method (with its Javadoc) to a
position where the `runArguments` Javadoc stays directly above `runArguments`.
##########
dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/ai/IntegrationLauncher.java:
##########
@@ -56,8 +56,12 @@ private IntegrationLauncher() {
*/
public static JsonObject run(Path directory, List<String> files, String
name, boolean dev, List<String> extraArgs) {
List<String> cmd = new ArrayList<>(LauncherHelper.getCamelCommand());
- List<String> sources = files == null || files.isEmpty() ?
sourceFiles(directory) : files;
- cmd.addAll(runArguments(sources, name, dev, extraArgs));
+ // no files given: the whole directory is the app (camel run
--source-dir), so a file the agent adds later,
+ // a bean file, a Java class under src/main/java, is part of it and
reloaded in dev mode (CAMEL-24861);
+ // with files given only those run, for a directory that holds several
apps
+ boolean sourceDir = files == null || files.isEmpty();
+ List<String> sources = sourceDir ? sourceFiles(directory) : files;
+ cmd.addAll(sourceDir ? sourceDirArguments(name, dev, extraArgs) :
runArguments(sources, name, dev, extraArgs));
JsonObject result = new JsonObject();
if (sources.isEmpty()) {
result.put("directory", directory.toString());
Review Comment:
**Bug: `sources.isEmpty()` guard fires incorrectly when `sourceDir=true`**
`sourceFiles()` only lists top-level files (it uses `Files.list`, not
`Files.walk`). A project where the agent just created a Java class under
`src/main/java/` — which is exactly the scenario the PR describes — will have
`sources=[]` here and hit the "No source files to run" error, even though
`camel run --source-dir=.` would handle it correctly.
When `sourceDir` is true, the guard should be skipped (or the directory
itself should be the fallback):
```java
if (!sourceDir && sources.isEmpty()) {
result.put("directory", directory.toString());
result.put("status", "failed");
result.put("error", "No source files to run in " + directory + " ...");
return result;
}
```
Alternatively keep the guard but use `Files.walk` when `sourceDir` to check
for any `.java` file in subdirs — but skipping it for `sourceDir=true` is
simpler and correct.
--
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]