This is an automated email from the ASF dual-hosted git repository. slachiewicz pushed a commit to branch mvnd-1.x in repository https://gitbox.apache.org/repos/asf/maven-mvnd.git
commit 1528dcfc62fbfc822524e5ba99b34f9a08969406 Author: Sylwester Lachiewicz <[email protected]> AuthorDate: Sun Nov 15 11:19:32 2026 +0100 Drop empty arguments in the client like Maven does Fixes #865 (cherry picked from commit 29089d832dfda754ac36134bf9f2c0310f518bac) --- .../org/mvndaemon/mvnd/client/DefaultClient.java | 1 + .../org/mvndaemon/mvnd/client/ClientArguments.java | 38 ++++++++++++++++++++++ .../mvndaemon/mvnd/client/ClientArgumentsTest.java | 37 +++++++++++++++++++++ 3 files changed, 76 insertions(+) diff --git a/client/src/main/java-mvnd/org/mvndaemon/mvnd/client/DefaultClient.java b/client/src/main/java-mvnd/org/mvndaemon/mvnd/client/DefaultClient.java index 5d8ecfe5..1b5636d8 100644 --- a/client/src/main/java-mvnd/org/mvndaemon/mvnd/client/DefaultClient.java +++ b/client/src/main/java-mvnd/org/mvndaemon/mvnd/client/DefaultClient.java @@ -75,6 +75,7 @@ public class DefaultClient implements Client { public static void main(String[] argv) throws Exception { final List<String> args = new ArrayList<>(Arrays.asList(argv)); + ClientArguments.removeBlankArguments(args); // What the user typed, before mvnd adds or removes options; MAVEN_CMD_LINE_ARGS is built from it final List<String> userArgs = new ArrayList<>(args); diff --git a/client/src/main/java/org/mvndaemon/mvnd/client/ClientArguments.java b/client/src/main/java/org/mvndaemon/mvnd/client/ClientArguments.java new file mode 100644 index 00000000..25d38676 --- /dev/null +++ b/client/src/main/java/org/mvndaemon/mvnd/client/ClientArguments.java @@ -0,0 +1,38 @@ +/* + * 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.mvndaemon.mvnd.client; + +import java.util.List; + +/** + * Adjustments the client makes to the command line before it is sent to the daemon. + * Kept apart from {@code DefaultClient}, which lives in a separate source root that the unit tests cannot see. + */ +final class ClientArguments { + + private ClientArguments() {} + + /** + * Drops empty and blank arguments, like Maven does, so that e.g. an empty string passed by PowerShell is not + * mistaken for a goal. + */ + static void removeBlankArguments(List<String> args) { + args.removeIf(arg -> arg.trim().isEmpty()); + } +} diff --git a/client/src/test/java/org/mvndaemon/mvnd/client/ClientArgumentsTest.java b/client/src/test/java/org/mvndaemon/mvnd/client/ClientArgumentsTest.java new file mode 100644 index 00000000..e7c5626b --- /dev/null +++ b/client/src/test/java/org/mvndaemon/mvnd/client/ClientArgumentsTest.java @@ -0,0 +1,37 @@ +/* + * 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.mvndaemon.mvnd.client; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertEquals; + +public class ClientArgumentsTest { + + @Test + void blankArgumentsAreDropped() { + List<String> args = new ArrayList<>(Arrays.asList("clean", "", " ", "install")); + ClientArguments.removeBlankArguments(args); + assertEquals(Arrays.asList("clean", "install"), args); + } +}
