This is an automated email from the ASF dual-hosted git repository. davsclaus pushed a commit to branch dirty in repository https://gitbox.apache.org/repos/asf/camel.git
commit 179200845a28525a09dfa1b7571eacfa534220bd Author: Claus Ibsen <[email protected]> AuthorDate: Mon Nov 10 16:37:26 2025 +0100 CAMEL-22678: camel-jbang - Add a dirty command --- .../dsl/jbang/core/commands/CamelJBangMain.java | 1 + .../dsl/jbang/core/commands/process/Dirty.java | 75 ++++++++++++++++++++++ .../dsl/jbang/core/common/CommandLineHelper.java | 3 - 3 files changed, 76 insertions(+), 3 deletions(-) diff --git a/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/CamelJBangMain.java b/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/CamelJBangMain.java index 775e0d880b2f..ed5147326db2 100644 --- a/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/CamelJBangMain.java +++ b/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/CamelJBangMain.java @@ -170,6 +170,7 @@ public class CamelJBangMain implements Callable<Integer> { .addSubcommand("jolokia", new CommandLine(new Jolokia(main))) .addSubcommand("hawtio", new CommandLine(new Hawtio(main))) .addSubcommand("sbom", new CommandLine(new SBOMGenerator(main))) + .addSubcommand("dirty", new CommandLine(new Dirty(main))) .addSubcommand("completion", new CommandLine(new Complete(main))) .addSubcommand("config", new CommandLine(new ConfigCommand(main)) .addSubcommand("list", new CommandLine(new ConfigList(main))) diff --git a/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/process/Dirty.java b/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/process/Dirty.java new file mode 100644 index 000000000000..671ce152e857 --- /dev/null +++ b/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/process/Dirty.java @@ -0,0 +1,75 @@ +/* + * 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.process; + +import java.io.File; +import java.util.ArrayList; +import java.util.List; + +import org.apache.camel.dsl.jbang.core.commands.CamelJBangMain; +import org.apache.camel.util.FileUtil; +import picocli.CommandLine; + +import static org.apache.camel.dsl.jbang.core.common.CommandLineHelper.getCamelDir; + [email protected](name = "dirty", + description = "Check if there are dirty files from previous Camel runs that did not terminate gracefully") +public class Dirty extends ProcessBaseCommand { + + @CommandLine.Option(names = { "--clean" }, defaultValue = "false", + description = "Clean dirty files which are no longer in use") + boolean clean; + + public Dirty(CamelJBangMain main) { + super(main); + } + + @Override + public Integer doCall() throws Exception { + File[] files = getCamelDir().toFile().listFiles(f -> !"camel-export.log".equals(f.getName())); + if (files == null || files.length == 0) { + return 0; + } + + List<File> dirty = new ArrayList<>(); + List<Long> pids = findPids("*"); + pids.add(ProcessHandle.current().pid()); // include ourselves + for (File f : files) { + // skip running Camel integrations and ourselves + String n = f.getName(); + boolean running = pids.stream().anyMatch(p -> n.startsWith("" + p)); + if (!running) { + dirty.add(f); + } + } + if (dirty.isEmpty()) { + return 0; + } + + if (clean) { + for (File f : dirty) { + FileUtil.deleteFile(f); + } + printer().println("Cleaned " + dirty.size() + " orphan files"); + } else { + printer().println("There are " + dirty.size() + " orphan files"); + } + + return 0; + } + +} diff --git a/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/common/CommandLineHelper.java b/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/common/CommandLineHelper.java index 31736eaa4d0c..368b140967c0 100644 --- a/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/common/CommandLineHelper.java +++ b/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/common/CommandLineHelper.java @@ -108,9 +108,6 @@ public final class CommandLineHelper { /** * Get the config file in current directory (local = true) or the default one - * - * @param local - * @return */ private static Path getUserPropertyFile(boolean local) { if (local) {
