Fix terminal width (fixes #870) (#891)

This commit is contained in:
Guillaume Nodet
2023-10-16 14:40:52 +02:00
committed by GitHub
parent 345e02b3c0
commit 18d0583304
2 changed files with 47 additions and 3 deletions

View File

@@ -52,7 +52,6 @@ import org.apache.maven.cli.configuration.SettingsXmlConfigurationProcessor;
import org.apache.maven.cli.event.ExecutionEventLogger; import org.apache.maven.cli.event.ExecutionEventLogger;
import org.apache.maven.cli.internal.BootstrapCoreExtensionManager; import org.apache.maven.cli.internal.BootstrapCoreExtensionManager;
import org.apache.maven.cli.internal.extension.model.CoreExtension; 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.jansi.MessageUtils;
import org.apache.maven.cli.logging.Slf4jConfiguration; import org.apache.maven.cli.logging.Slf4jConfiguration;
import org.apache.maven.cli.logging.Slf4jConfigurationFactory; import org.apache.maven.cli.logging.Slf4jConfigurationFactory;
@@ -184,7 +183,7 @@ public class DaemonMavenCli implements DaemonCli {
plexusLoggerManager = new Slf4jLoggerManager(); plexusLoggerManager = new Slf4jLoggerManager();
this.classWorld = ((ClassRealm) Thread.currentThread().getContextClassLoader()).getWorld(); this.classWorld = ((ClassRealm) Thread.currentThread().getContextClassLoader()).getWorld();
this.messageBuilderFactory = new JansiMessageBuilderFactory(); this.messageBuilderFactory = new DaemonMessageBuilderFactory();
container = container(); container = container();
@@ -289,7 +288,7 @@ public class DaemonMavenCli implements DaemonCli {
topDirectory = getCanonicalPath(topDirectory); topDirectory = getCanonicalPath(topDirectory);
cliRequest.topDirectory = topDirectory; cliRequest.topDirectory = topDirectory;
// We're very early in the process and we don't have the container set up yet, // 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} // This is used to compute {@code session.rootDirectory} but all {@code project.rootDirectory}
// properties will be compute through the RootLocator found in the container. // properties will be compute through the RootLocator found in the container.
RootLocator rootLocator = RootLocator rootLocator =

View File

@@ -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;
}
}