mirror of https://github.com/apache/maven.git
Extract JLine support into its own module (#1426)
This commit is contained in:
parent
ce15193394
commit
a9934f91fd
|
@ -48,6 +48,10 @@ under the License.
|
|||
<groupId>org.apache.maven</groupId>
|
||||
<artifactId>maven-core</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.maven</groupId>
|
||||
<artifactId>maven-jline</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.maven</groupId>
|
||||
<artifactId>maven-plugin-api</artifactId>
|
||||
|
|
|
@ -28,7 +28,7 @@ import org.apache.commons.cli.HelpFormatter;
|
|||
import org.apache.commons.cli.Option;
|
||||
import org.apache.commons.cli.Options;
|
||||
import org.apache.commons.cli.ParseException;
|
||||
import org.apache.maven.cli.jline.MessageUtils;
|
||||
import org.apache.maven.jline.MessageUtils;
|
||||
|
||||
/**
|
||||
*/
|
||||
|
|
|
@ -25,7 +25,7 @@ import java.util.Date;
|
|||
import java.util.Locale;
|
||||
import java.util.Properties;
|
||||
|
||||
import org.apache.maven.cli.jline.MessageUtils;
|
||||
import org.apache.maven.jline.MessageUtils;
|
||||
import org.apache.maven.utils.Os;
|
||||
import org.slf4j.Logger;
|
||||
|
||||
|
|
|
@ -58,8 +58,6 @@ import org.apache.maven.cli.event.ExecutionEventLogger;
|
|||
import org.apache.maven.cli.internal.BootstrapCoreExtensionManager;
|
||||
import org.apache.maven.cli.internal.extension.io.CoreExtensionsStaxReader;
|
||||
import org.apache.maven.cli.internal.extension.model.CoreExtension;
|
||||
import org.apache.maven.cli.jline.JLineMessageBuilderFactory;
|
||||
import org.apache.maven.cli.jline.MessageUtils;
|
||||
import org.apache.maven.cli.logging.Slf4jConfiguration;
|
||||
import org.apache.maven.cli.logging.Slf4jConfigurationFactory;
|
||||
import org.apache.maven.cli.logging.Slf4jLoggerManager;
|
||||
|
@ -81,6 +79,8 @@ import org.apache.maven.execution.scope.internal.MojoExecutionScope;
|
|||
import org.apache.maven.execution.scope.internal.MojoExecutionScopeModule;
|
||||
import org.apache.maven.extension.internal.CoreExports;
|
||||
import org.apache.maven.extension.internal.CoreExtensionEntry;
|
||||
import org.apache.maven.jline.JLineMessageBuilderFactory;
|
||||
import org.apache.maven.jline.MessageUtils;
|
||||
import org.apache.maven.lifecycle.LifecycleExecutionException;
|
||||
import org.apache.maven.logwrapper.LogLevelRecorder;
|
||||
import org.apache.maven.logwrapper.MavenSlf4jWrapperFactory;
|
||||
|
|
|
@ -160,7 +160,7 @@ public class Ansi implements Appendable {
|
|||
}
|
||||
|
||||
public static boolean isEnabled() {
|
||||
return org.apache.maven.cli.jline.MessageUtils.isColorEnabled() && org.jline.jansi.Ansi.isEnabled();
|
||||
return org.apache.maven.jline.MessageUtils.isColorEnabled() && org.jline.jansi.Ansi.isEnabled();
|
||||
}
|
||||
|
||||
public static Ansi ansi() {
|
||||
|
|
|
@ -35,7 +35,6 @@ import org.apache.commons.cli.Option;
|
|||
import org.apache.commons.cli.Options;
|
||||
import org.apache.commons.cli.ParseException;
|
||||
import org.apache.maven.Maven;
|
||||
import org.apache.maven.cli.jline.MessageUtils;
|
||||
import org.apache.maven.cli.transfer.ConsoleMavenTransferListener;
|
||||
import org.apache.maven.cli.transfer.QuietMavenTransferListener;
|
||||
import org.apache.maven.cli.transfer.SimplexTransferListener;
|
||||
|
@ -44,6 +43,7 @@ import org.apache.maven.eventspy.internal.EventSpyDispatcher;
|
|||
import org.apache.maven.execution.MavenExecutionRequest;
|
||||
import org.apache.maven.execution.ProfileActivation;
|
||||
import org.apache.maven.execution.ProjectActivation;
|
||||
import org.apache.maven.jline.MessageUtils;
|
||||
import org.apache.maven.model.root.DefaultRootLocator;
|
||||
import org.apache.maven.project.MavenProject;
|
||||
import org.apache.maven.toolchain.building.ToolchainsBuildingRequest;
|
||||
|
|
|
@ -22,10 +22,10 @@ import java.io.File;
|
|||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import org.apache.commons.io.FilenameUtils;
|
||||
import org.apache.maven.cli.jline.JLineMessageBuilderFactory;
|
||||
import org.apache.maven.cli.jline.MessageUtils;
|
||||
import org.apache.maven.execution.ExecutionEvent;
|
||||
import org.apache.maven.execution.MavenSession;
|
||||
import org.apache.maven.jline.JLineMessageBuilderFactory;
|
||||
import org.apache.maven.jline.MessageUtils;
|
||||
import org.apache.maven.project.MavenProject;
|
||||
import org.junit.jupiter.api.AfterAll;
|
||||
import org.junit.jupiter.api.BeforeAll;
|
||||
|
|
|
@ -26,7 +26,7 @@ import java.util.concurrent.CountDownLatch;
|
|||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.Executors;
|
||||
|
||||
import org.apache.maven.cli.jline.JLineMessageBuilderFactory;
|
||||
import org.apache.maven.jline.JLineMessageBuilderFactory;
|
||||
import org.eclipse.aether.DefaultRepositorySystemSession;
|
||||
import org.eclipse.aether.transfer.TransferCancelledException;
|
||||
import org.eclipse.aether.transfer.TransferEvent;
|
||||
|
|
|
@ -0,0 +1,61 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!--
|
||||
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.
|
||||
-->
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<parent>
|
||||
<groupId>org.apache.maven</groupId>
|
||||
<artifactId>maven</artifactId>
|
||||
<version>4.0.0-alpha-13-SNAPSHOT</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>maven-jline</artifactId>
|
||||
<name>Maven JLine integration</name>
|
||||
<description>Provides the JLine integration in Maven</description>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.apache.maven</groupId>
|
||||
<artifactId>maven-api-core</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.jline</groupId>
|
||||
<artifactId>jline</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>javax.inject</groupId>
|
||||
<artifactId>javax.inject</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>javax.annotation</groupId>
|
||||
<artifactId>javax.annotation-api</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.codehaus.plexus</groupId>
|
||||
<artifactId>plexus-interactivity-api</artifactId>
|
||||
<exclusions>
|
||||
<exclusion>
|
||||
<groupId>org.codehaus.plexus</groupId>
|
||||
<artifactId>plexus-container-default</artifactId>
|
||||
</exclusion>
|
||||
</exclusions>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
</project>
|
|
@ -16,7 +16,7 @@
|
|||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
package org.apache.maven.cli.jline;
|
||||
package org.apache.maven.jline;
|
||||
|
||||
import javax.annotation.Priority;
|
||||
import javax.inject.Named;
|
||||
|
@ -40,8 +40,6 @@ import org.jline.utils.AttributedStringBuilder;
|
|||
import org.jline.utils.AttributedStyle;
|
||||
import org.jline.utils.StyleResolver;
|
||||
|
||||
import static org.jline.utils.AttributedStyle.DEFAULT;
|
||||
|
||||
@Experimental
|
||||
@Named
|
||||
@Singleton
|
||||
|
@ -223,7 +221,7 @@ public class JLineMessageBuilderFactory implements MessageBuilderFactory, Prompt
|
|||
|
||||
@Override
|
||||
public MessageBuilder resetStyle() {
|
||||
builder.style(DEFAULT);
|
||||
builder.style(AttributedStyle.DEFAULT);
|
||||
return this;
|
||||
}
|
||||
|
|
@ -16,7 +16,7 @@
|
|||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
package org.apache.maven.cli.jline;
|
||||
package org.apache.maven.jline;
|
||||
|
||||
import java.io.IOError;
|
||||
import java.io.IOException;
|
|
@ -47,7 +47,7 @@ under the License.
|
|||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.maven</groupId>
|
||||
<artifactId>maven-embedder</artifactId>
|
||||
<artifactId>maven-jline</artifactId>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
|
|
|
@ -19,11 +19,12 @@
|
|||
package org.apache.maven.slf4j;
|
||||
|
||||
import java.io.PrintStream;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
import org.apache.maven.api.services.MessageBuilder;
|
||||
import org.slf4j.simple.SimpleLogger;
|
||||
import org.slf4j.simple.ExtSimpleLogger;
|
||||
|
||||
import static org.apache.maven.cli.jline.MessageUtils.builder;
|
||||
import static org.apache.maven.jline.MessageUtils.builder;
|
||||
|
||||
/**
|
||||
* Logger for Maven, that support colorization of levels and stacktraces. This class implements 2 methods introduced in
|
||||
|
@ -31,7 +32,7 @@ import static org.apache.maven.cli.jline.MessageUtils.builder;
|
|||
*
|
||||
* @since 3.5.0
|
||||
*/
|
||||
public class MavenSimpleLogger extends SimpleLogger {
|
||||
public class MavenSimpleLogger extends ExtSimpleLogger {
|
||||
|
||||
private final String traceRenderedLevel = builder().trace("TRACE").build();
|
||||
private final String debugRenderedLevel = builder().debug("DEBUG").build();
|
||||
|
@ -39,6 +40,12 @@ public class MavenSimpleLogger extends SimpleLogger {
|
|||
private final String warnRenderedLevel = builder().warning("WARNING").build();
|
||||
private final String errorRenderedLevel = builder().error("ERROR").build();
|
||||
|
||||
static Consumer<String> logSink;
|
||||
|
||||
public static void setLogSink(Consumer<String> logSink) {
|
||||
MavenSimpleLogger.logSink = logSink;
|
||||
}
|
||||
|
||||
MavenSimpleLogger(String name) {
|
||||
super(name);
|
||||
}
|
||||
|
@ -60,6 +67,16 @@ public class MavenSimpleLogger extends SimpleLogger {
|
|||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void doWrite(StringBuilder buf, Throwable t) {
|
||||
Consumer<String> sink = logSink;
|
||||
if (sink != null) {
|
||||
sink.accept(buf.toString());
|
||||
} else {
|
||||
super.doWrite(buf, t);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void writeThrowable(Throwable t, PrintStream stream) {
|
||||
if (t == null) {
|
||||
|
|
|
@ -0,0 +1,39 @@
|
|||
/*
|
||||
* 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.slf4j.simple;
|
||||
|
||||
/**
|
||||
* Class inheriting SimpleLogger to work around the fact that the {@link #write(StringBuilder, Throwable)}
|
||||
* method is package private.
|
||||
*/
|
||||
public class ExtSimpleLogger extends SimpleLogger {
|
||||
|
||||
public ExtSimpleLogger(String name) {
|
||||
super(name);
|
||||
}
|
||||
|
||||
@Override
|
||||
void write(StringBuilder buf, Throwable t) {
|
||||
doWrite(buf, t);
|
||||
}
|
||||
|
||||
protected void doWrite(StringBuilder buf, Throwable t) {
|
||||
super.write(buf, t);
|
||||
}
|
||||
}
|
|
@ -24,7 +24,7 @@ import java.util.Arrays;
|
|||
import java.util.List;
|
||||
import java.util.NoSuchElementException;
|
||||
|
||||
import org.apache.maven.cli.jline.MessageUtils;
|
||||
import org.apache.maven.jline.MessageUtils;
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
|
6
pom.xml
6
pom.xml
|
@ -107,6 +107,7 @@ under the License.
|
|||
<module>maven-model-builder</module>
|
||||
<module>maven-di</module>
|
||||
<module>maven-xml-impl</module>
|
||||
<module>maven-jline</module>
|
||||
<module>maven-core</module>
|
||||
<module>maven-settings</module>
|
||||
<module>maven-settings-builder</module>
|
||||
|
@ -203,6 +204,11 @@ under the License.
|
|||
<artifactId>maven-builder-support</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.maven</groupId>
|
||||
<artifactId>maven-jline</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.maven</groupId>
|
||||
<artifactId>maven-core</artifactId>
|
||||
|
|
Loading…
Reference in New Issue