You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by sl...@apache.org on 2026/10/14 11:46:37 UTC

(maven) branch agent/plus-prefix-trimmed created (now f897156abd)

This is an automated email from the ASF dual-hosted git repository.

slachiewicz pushed a change to branch agent/plus-prefix-trimmed
in repository https://gitbox.apache.org/repos/asf/maven.git


      at f897156abd Read the + prefix of -P and -pl tokens after trimming

This branch includes the following new commits:

     new f897156abd Read the + prefix of -P and -pl tokens after trimming

The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.



(maven) 01/01: Read the + prefix of -P and -pl tokens after trimming

Posted by sl...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

slachiewicz pushed a commit to branch agent/plus-prefix-trimmed
in repository https://gitbox.apache.org/repos/asf/maven.git

commit f897156abd3a1f520bb29d06a9798337b9319fc6
Author: Sylwester Lachiewicz <sl...@apache.org>
AuthorDate: Wed Oct 14 13:46:21 2026 +0200

    Read the + prefix of -P and -pl tokens after trimming
    
    The - and ! checks read the trimmed token but the + check read the raw one, so in
    -P "a, +b" the profile was taken as "+b", and " +?e" lost its optional marker.
---
 .../maven/cling/invoker/mvn/MavenInvoker.java      |  4 +-
 .../invoker/mvn/MavenInvokerActivationTest.java    | 72 ++++++++++++++++++++++
 2 files changed, 74 insertions(+), 2 deletions(-)

diff --git a/impl/maven-cli/src/main/java/org/apache/maven/cling/invoker/mvn/MavenInvoker.java b/impl/maven-cli/src/main/java/org/apache/maven/cling/invoker/mvn/MavenInvoker.java
index e6372ccfd8..a6754d1afe 100644
--- a/impl/maven-cli/src/main/java/org/apache/maven/cling/invoker/mvn/MavenInvoker.java
+++ b/impl/maven-cli/src/main/java/org/apache/maven/cling/invoker/mvn/MavenInvoker.java
@@ -402,7 +402,7 @@ protected void performProjectActivation(MavenContext context, ProjectActivation
                         if (selector.charAt(0) == '-' || selector.charAt(0) == '!') {
                             active = false;
                             selector = selector.substring(1);
-                        } else if (token.charAt(0) == '+') {
+                        } else if (selector.charAt(0) == '+') {
                             selector = selector.substring(1);
                         }
                     }
@@ -429,7 +429,7 @@ protected void performProfileActivation(MavenContext context, ProfileActivation
                         if (profileId.charAt(0) == '-' || profileId.charAt(0) == '!') {
                             active = false;
                             profileId = profileId.substring(1);
-                        } else if (token.charAt(0) == '+') {
+                        } else if (profileId.charAt(0) == '+') {
                             profileId = profileId.substring(1);
                         }
                     }
diff --git a/impl/maven-cli/src/test/java/org/apache/maven/cling/invoker/mvn/MavenInvokerActivationTest.java b/impl/maven-cli/src/test/java/org/apache/maven/cling/invoker/mvn/MavenInvokerActivationTest.java
new file mode 100644
index 0000000000..25061bfb84
--- /dev/null
+++ b/impl/maven-cli/src/test/java/org/apache/maven/cling/invoker/mvn/MavenInvokerActivationTest.java
@@ -0,0 +1,72 @@
+/*
+ * 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.maven.cling.invoker.mvn;
+
+import java.util.List;
+import java.util.Optional;
+import java.util.Set;
+
+import org.apache.maven.api.cli.mvn.MavenOptions;
+import org.apache.maven.api.services.Lookup;
+import org.apache.maven.execution.ProfileActivation;
+import org.apache.maven.execution.ProjectActivation;
+import org.junit.jupiter.api.Test;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
+/**
+ * How {@code -P} and {@code -pl} tokens are split into active, inactive and optional entries.
+ */
+class MavenInvokerActivationTest {
+
+    private static MavenContext context(MavenOptions options) {
+        MavenContext context = mock(MavenContext.class);
+        when(context.options()).thenReturn(options);
+        return context;
+    }
+
+    @Test
+    void profilePrefixesAreReadAfterTrimming() {
+        MavenOptions options = mock(MavenOptions.class);
+        when(options.activatedProfiles()).thenReturn(Optional.of(List.of("a, +b, -c, !d, +?e, -?f")));
+        ProfileActivation activation = new ProfileActivation();
+
+        new MavenInvoker(mock(Lookup.class), null).performProfileActivation(context(options), activation);
+
+        assertEquals(Set.of("a", "b"), activation.getRequiredActiveProfileIds());
+        assertEquals(Set.of("e"), activation.getOptionalActiveProfileIds());
+        assertEquals(Set.of("c", "d"), activation.getRequiredInactiveProfileIds());
+        assertEquals(Set.of("f"), activation.getOptionalInactiveProfileIds());
+    }
+
+    @Test
+    void projectPrefixesAreReadAfterTrimming() {
+        MavenOptions options = mock(MavenOptions.class);
+        when(options.projects()).thenReturn(Optional.of(List.of(":a, +:b, -:c, !:d, +?:e")));
+        ProjectActivation activation = new ProjectActivation();
+
+        new MavenInvoker(mock(Lookup.class), null).performProjectActivation(context(options), activation);
+
+        assertEquals(Set.of(":a", ":b"), activation.getRequiredActiveProjectSelectors());
+        assertEquals(Set.of(":e"), activation.getOptionalActiveProjectSelectors());
+        assertEquals(Set.of(":c", ":d"), activation.getRequiredInactiveProjectSelectors());
+    }
+}