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 { 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 { 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 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. 1.4.0 4.0.4 2.0.4 - 4.0.2 + 4.0.3 0.9.0.M3 2.0.16 4.2.2