This is an automated email from the ASF dual-hosted git repository. cstamas pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/maven.git
The following commit(s) were added to refs/heads/master by this push: new 6cb4482a98 [MNG-8411][MNG-8412][MNG-8416] mvnenc fixes (#1959) 6cb4482a98 is described below commit 6cb4482a9812f8c902a6d6b45367c4642af150a7 Author: Tamas Cservenak <ta...@cservenak.net> AuthorDate: Wed Dec 11 10:13:06 2024 +0100 [MNG-8411][MNG-8412][MNG-8416] mvnenc fixes (#1959) Cumulative mvnenc fixes: * make the 3 goals (sans init) work in batch mode * move the Maven DI SecDispatcher provider to test scope in maven-impl (duplicates components in Maven) * update to SecDisparcher 4.0.3 (contains fix for MNG-8416 and one other bug) --- https://issues.apache.org/jira/browse/MNG-8411 https://issues.apache.org/jira/browse/MNG-8412 https://issues.apache.org/jira/browse/MNG-8416 --- .../maven/cling/invoker/mvnenc/EncryptInvoker.java | 19 +------- .../maven/cling/invoker/mvnenc/goals/Init.java | 4 +- .../mvnenc/goals/InteractiveGoalSupport.java | 52 ++++++++++++++++++++++ .../internal/impl/DefaultSettingsBuilder.java | 2 +- .../impl/secdispatcher/SecDispatcherProvider.java | 0 pom.xml | 2 +- 6 files changed, 57 insertions(+), 22 deletions(-) diff --git a/impl/maven-cli/src/main/java/org/apache/maven/cling/invoker/mvnenc/EncryptInvoker.java b/impl/maven-cli/src/main/java/org/apache/maven/cling/invoker/mvnenc/EncryptInvoker.java index 87e5425495..6ad5b0cbd4 100644 --- a/impl/maven-cli/src/main/java/org/apache/maven/cling/invoker/mvnenc/EncryptInvoker.java +++ b/impl/maven-cli/src/main/java/org/apache/maven/cling/invoker/mvnenc/EncryptInvoker.java @@ -65,18 +65,6 @@ public class EncryptInvoker extends LookupInvoker<EncryptContext> { protected int doExecute(EncryptContext context) throws Exception { try { - if (!context.interactive) { - context.terminal.writer().println("This tool works only in interactive mode!"); - context.terminal - .writer() - .println("Tool purpose is to configure password management on developer workstations."); - context.terminal - .writer() - .println( - "Note: Generated configuration can be moved/copied to headless environments, if configured as such."); - return BAD_OPERATION; - } - context.header = new ArrayList<>(); context.style = new AttributedStyle(); context.addInHeader( @@ -89,12 +77,7 @@ public class EncryptInvoker extends LookupInvoker<EncryptContext> { Thread executeThread = Thread.currentThread(); context.terminal.handle(Terminal.Signal.INT, signal -> executeThread.interrupt()); ConsolePrompt.UiConfig config; - if (context.terminal.getType().equals(Terminal.TYPE_DUMB) - || context.terminal.getType().equals(Terminal.TYPE_DUMB_COLOR)) { - context.terminal.writer().println(context.terminal.getName() + ": " + context.terminal.getType()); - throw new IllegalStateException("Dumb terminal detected.\nThis tool requires real terminal to work!\n" - + "Note: On Windows Jansi or JNA library must be included in classpath."); - } else if (OSUtils.IS_WINDOWS) { + if (OSUtils.IS_WINDOWS) { config = new ConsolePrompt.UiConfig(">", "( )", "(x)", "( )"); } else { config = new ConsolePrompt.UiConfig("❯", "◯ ", "◉ ", "◯ "); diff --git a/impl/maven-cli/src/main/java/org/apache/maven/cling/invoker/mvnenc/goals/Init.java b/impl/maven-cli/src/main/java/org/apache/maven/cling/invoker/mvnenc/goals/Init.java index 3c78188376..7dfd1fba5f 100644 --- a/impl/maven-cli/src/main/java/org/apache/maven/cling/invoker/mvnenc/goals/Init.java +++ b/impl/maven-cli/src/main/java/org/apache/maven/cling/invoker/mvnenc/goals/Init.java @@ -54,7 +54,7 @@ import static org.apache.maven.cling.invoker.mvnenc.EncryptInvoker.OK; */ @Singleton @Named("init") -public class Init extends GoalSupport { +public class Init extends InteractiveGoalSupport { private static final String NONE = "__none__"; @Inject @@ -63,7 +63,7 @@ public class Init extends GoalSupport { } @Override - public int execute(EncryptContext context) throws Exception { + public int doExecute(EncryptContext context) throws Exception { context.addInHeader(context.style.italic().bold().foreground(Colors.rgbColor("yellow")), "goal: init"); context.addInHeader(""); diff --git a/impl/maven-cli/src/main/java/org/apache/maven/cling/invoker/mvnenc/goals/InteractiveGoalSupport.java b/impl/maven-cli/src/main/java/org/apache/maven/cling/invoker/mvnenc/goals/InteractiveGoalSupport.java new file mode 100644 index 0000000000..2c867e1ef4 --- /dev/null +++ b/impl/maven-cli/src/main/java/org/apache/maven/cling/invoker/mvnenc/goals/InteractiveGoalSupport.java @@ -0,0 +1,52 @@ +/* + * 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.mvnenc.goals; + +import org.apache.maven.api.services.MessageBuilderFactory; +import org.apache.maven.cling.invoker.mvnenc.EncryptContext; +import org.apache.maven.cling.invoker.mvnenc.EncryptInvoker; +import org.codehaus.plexus.components.secdispatcher.SecDispatcher; + +/** + * The support class for interactive goal implementations. + */ +public abstract class InteractiveGoalSupport extends GoalSupport { + protected InteractiveGoalSupport(MessageBuilderFactory messageBuilderFactory, SecDispatcher secDispatcher) { + super(messageBuilderFactory, secDispatcher); + } + + @Override + public int execute(EncryptContext context) throws Exception { + if (!context.interactive) { + context.terminal.writer().println("This tool works only in interactive mode!"); + context.terminal + .writer() + .println("Tool purpose is to configure password management on developer workstations."); + context.terminal + .writer() + .println( + "Note: Generated configuration can be moved/copied to headless environments, if configured as such."); + return EncryptInvoker.BAD_OPERATION; + } + + return doExecute(context); + } + + protected abstract int doExecute(EncryptContext context) throws Exception; +} diff --git a/impl/maven-impl/src/main/java/org/apache/maven/internal/impl/DefaultSettingsBuilder.java b/impl/maven-impl/src/main/java/org/apache/maven/internal/impl/DefaultSettingsBuilder.java index 510c026eed..fd1bbfc072 100644 --- a/impl/maven-impl/src/main/java/org/apache/maven/internal/impl/DefaultSettingsBuilder.java +++ b/impl/maven-impl/src/main/java/org/apache/maven/internal/impl/DefaultSettingsBuilder.java @@ -274,7 +274,7 @@ public class DefaultSettingsBuilder implements SettingsBuilder { } SecDispatcher secDispatcher = new DefaultSecDispatcher(dispatchers, getSecuritySettings(request.getSession())); Function<String, String> decryptFunction = str -> { - if (secDispatcher.isAnyEncryptedString(str)) { + if (str != null && !str.isEmpty() && !str.contains("${") && secDispatcher.isAnyEncryptedString(str)) { if (secDispatcher.isLegacyEncryptedString(str)) { // add a problem problems.add(new DefaultBuilderProblem( diff --git a/impl/maven-impl/src/main/java/org/apache/maven/internal/impl/secdispatcher/SecDispatcherProvider.java b/impl/maven-impl/src/test/java/org/apache/maven/internal/impl/secdispatcher/SecDispatcherProvider.java similarity index 100% rename from impl/maven-impl/src/main/java/org/apache/maven/internal/impl/secdispatcher/SecDispatcherProvider.java rename to impl/maven-impl/src/test/java/org/apache/maven/internal/impl/secdispatcher/SecDispatcherProvider.java diff --git a/pom.xml b/pom.xml index 8463f28db1..1e628a340f 100644 --- a/pom.xml +++ b/pom.xml @@ -163,7 +163,7 @@ under the License. <plexusTestingVersion>1.4.0</plexusTestingVersion> <plexusXmlVersion>4.0.4</plexusXmlVersion> <resolverVersion>2.0.4</resolverVersion> - <securityDispatcherVersion>4.0.2</securityDispatcherVersion> + <securityDispatcherVersion>4.0.3</securityDispatcherVersion> <sisuVersion>0.9.0.M3</sisuVersion> <slf4jVersion>2.0.16</slf4jVersion> <stax2ApiVersion>4.2.2</stax2ApiVersion>