Skip to content

Commit

Permalink
Fix terminal width (fixes apache#870)
Browse files Browse the repository at this point in the history
  • Loading branch information
gnodet committed Oct 16, 2023
1 parent 15d622e commit e16794a
Show file tree
Hide file tree
Showing 2 changed files with 72 additions and 25 deletions.
52 changes: 27 additions & 25 deletions daemon-m40/src/main/java/org/apache/maven/cli/DaemonMavenCli.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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();

Expand Down Expand Up @@ -288,10 +287,10 @@ 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.
// 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 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.
// properties will be computed through the RootLocator found in the container.
RootLocator rootLocator =
ServiceLoader.load(RootLocator.class).iterator().next();
Path rootDirectory = rootLocator.findRoot(topDirectory);
Expand Down Expand Up @@ -496,6 +495,7 @@ private void commands(CliRequest cliRequest) {
if (MessageUtils.isColorEnabled()) {
MessageBuilder buff = MessageUtils.builder();
buff.a("Message styles: ");
buff.trace("trace").a(' ');
buff.debug("debug").a(' ');
buff.info("info").a(' ');
buff.warning("warning").a(' ');
Expand Down Expand Up @@ -572,10 +572,11 @@ DefaultPlexusContainer container() throws Exception {
.filter(s -> s != null && !s.isEmpty())
.map(s -> {
String[] parts = s.split(":");
CoreExtension ce = new CoreExtension();
ce.setGroupId(parts[0]);
ce.setArtifactId(parts[1]);
ce.setVersion(parts[2]);
CoreExtension ce = CoreExtension.newBuilder()
.groupId(parts[0])
.artifactId(parts[1])
.version(parts[2])
.build();
return ce;
})
.collect(Collectors.toList());
Expand Down Expand Up @@ -624,11 +625,18 @@ protected void configure() {

container.setLoggerManager(plexusLoggerManager);

AbstractValueSource extensionSource = new AbstractValueSource(false) {
@Override
public Object getValue(String expression) {
return null;
}
};
for (CoreExtensionEntry extension : extensionsEntries) {
container.discoverComponents(
extension.getClassRealm(),
new SessionScopeModule(container),
new MojoExecutionScopeModule(container));
new MojoExecutionScopeModule(container),
new ExtensionConfigurationModule(extension, extensionSource));
}
return container;
}
Expand Down Expand Up @@ -1182,12 +1190,12 @@ private static boolean isRunningOnCI(Properties systemProperties) {
}

private String determineLocalRepositoryPath(final MavenExecutionRequest request) {
String userDefinedLocalRepo = request.getUserProperties().getProperty(MavenCli.LOCAL_REPO_PROPERTY);
String userDefinedLocalRepo = request.getUserProperties().getProperty(DaemonMavenCli.LOCAL_REPO_PROPERTY);
if (userDefinedLocalRepo != null) {
return userDefinedLocalRepo;
}

return request.getSystemProperties().getProperty(MavenCli.LOCAL_REPO_PROPERTY);
return request.getSystemProperties().getProperty(DaemonMavenCli.LOCAL_REPO_PROPERTY);
}

private File determinePom(
Expand All @@ -1200,22 +1208,16 @@ private File determinePom(
alternatePomFile = commandLine.getOptionValue(CLIManager.ALTERNATE_POM_FILE);
}

File current = baseDirectory;
if (alternatePomFile != null) {
File pom = resolveFile(new File(alternatePomFile), workingDirectory);
if (pom.isDirectory()) {
pom = new File(pom, "pom.xml");
}

return pom;
} else if (modelProcessor != null) {
File pom = modelProcessor.locatePom(baseDirectory);

if (pom.isFile()) {
return pom;
}
current = resolveFile(new File(alternatePomFile), workingDirectory);
}

return null;
if (modelProcessor != null) {
return modelProcessor.locateExistingPom(current);
} else {
return current.isFile() ? current : null;
}
}

// Visible for testing
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
}
}

0 comments on commit e16794a

Please sign in to comment.