From 7ec634dc9619e5d1aa6321709cde2018bba9e44d Mon Sep 17 00:00:00 2001 From: Guillaume Nodet Date: Mon, 16 Oct 2023 09:23:55 +0200 Subject: [PATCH] Fix terminal width (fixes #870) --- .../org/apache/maven/cli/DaemonMavenCli.java | 7 ++- .../cli/DaemonMessageBuilderFactory.java | 45 +++++++++++++++++++ 2 files changed, 48 insertions(+), 4 deletions(-) create mode 100644 daemon/src/main/java/org/apache/maven/cli/DaemonMessageBuilderFactory.java diff --git a/daemon-m40/src/main/java/org/apache/maven/cli/DaemonMavenCli.java b/daemon-m40/src/main/java/org/apache/maven/cli/DaemonMavenCli.java index 96ec7b877..e48c56adf 100644 --- a/daemon-m40/src/main/java/org/apache/maven/cli/DaemonMavenCli.java +++ b/daemon-m40/src/main/java/org/apache/maven/cli/DaemonMavenCli.java @@ -52,7 +52,6 @@ import org.apache.maven.cli.event.ExecutionEventLogger; import org.apache.maven.cli.internal.BootstrapCoreExtensionManager; import org.apache.maven.cli.internal.extension.model.CoreExtension; -import org.apache.maven.cli.jansi.JansiMessageBuilderFactory; import org.apache.maven.cli.jansi.MessageUtils; import org.apache.maven.cli.logging.Slf4jConfiguration; import org.apache.maven.cli.logging.Slf4jConfigurationFactory; @@ -184,7 +183,7 @@ public DaemonMavenCli() throws Exception { plexusLoggerManager = new Slf4jLoggerManager(); this.classWorld = ((ClassRealm) Thread.currentThread().getContextClassLoader()).getWorld(); - this.messageBuilderFactory = new JansiMessageBuilderFactory(); + this.messageBuilderFactory = new DaemonMessageBuilderFactory(); container = container(); @@ -289,7 +288,7 @@ void initialize(CliRequest cliRequest) throws ExitException { topDirectory = getCanonicalPath(topDirectory); cliRequest.topDirectory = topDirectory; // We're very early in the process and we don't have the container set up yet, - // so we rely on the JDK services to eventually lookup a custom RootLocator. + // so we rely on the JDK services to eventually look up a custom RootLocator. // This is used to compute {@code session.rootDirectory} but all {@code project.rootDirectory} // properties will be compute through the RootLocator found in the container. RootLocator rootLocator = @@ -1204,7 +1203,7 @@ private File determinePom( File pom = resolveFile(new File(alternatePomFile), workingDirectory); if (pom.isDirectory()) { pom = new File(pom, "pom.xml"); - } + } return pom; } else if (modelProcessor != null) { diff --git a/daemon/src/main/java/org/apache/maven/cli/DaemonMessageBuilderFactory.java b/daemon/src/main/java/org/apache/maven/cli/DaemonMessageBuilderFactory.java new file mode 100644 index 000000000..afc74b35d --- /dev/null +++ b/daemon/src/main/java/org/apache/maven/cli/DaemonMessageBuilderFactory.java @@ -0,0 +1,45 @@ +/* + * 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.cli; + +import javax.annotation.Priority; +import javax.inject.Named; +import javax.inject.Singleton; + +import org.apache.maven.api.annotations.Experimental; +import org.apache.maven.cli.jansi.JansiMessageBuilderFactory; +import org.mvndaemon.mvnd.common.Environment; + +@Named +@Singleton +@Priority(10) +@Experimental +public class DaemonMessageBuilderFactory extends JansiMessageBuilderFactory { + + @Override + public int getTerminalWidth() { + int terminalWidth; + try { + terminalWidth = Environment.MVND_TERMINAL_WIDTH.asInt(); + } catch (Exception e) { + terminalWidth = 80; + } + return terminalWidth; + } +}