Skip to content

Commit a9934f9

Browse files
authored
Extract JLine support into its own module (#1426)
1 parent ce15193 commit a9934f9

File tree

16 files changed

+144
-19
lines changed

16 files changed

+144
-19
lines changed

maven-embedder/pom.xml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,10 @@ under the License.
4848
<groupId>org.apache.maven</groupId>
4949
<artifactId>maven-core</artifactId>
5050
</dependency>
51+
<dependency>
52+
<groupId>org.apache.maven</groupId>
53+
<artifactId>maven-jline</artifactId>
54+
</dependency>
5155
<dependency>
5256
<groupId>org.apache.maven</groupId>
5357
<artifactId>maven-plugin-api</artifactId>

maven-embedder/src/main/java/org/apache/maven/cli/CLIManager.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
import org.apache.commons.cli.Option;
2929
import org.apache.commons.cli.Options;
3030
import org.apache.commons.cli.ParseException;
31-
import org.apache.maven.cli.jline.MessageUtils;
31+
import org.apache.maven.jline.MessageUtils;
3232

3333
/**
3434
*/

maven-embedder/src/main/java/org/apache/maven/cli/CLIReportingUtils.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
import java.util.Locale;
2626
import java.util.Properties;
2727

28-
import org.apache.maven.cli.jline.MessageUtils;
28+
import org.apache.maven.jline.MessageUtils;
2929
import org.apache.maven.utils.Os;
3030
import org.slf4j.Logger;
3131

maven-embedder/src/main/java/org/apache/maven/cli/MavenCli.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,6 @@
5858
import org.apache.maven.cli.internal.BootstrapCoreExtensionManager;
5959
import org.apache.maven.cli.internal.extension.io.CoreExtensionsStaxReader;
6060
import org.apache.maven.cli.internal.extension.model.CoreExtension;
61-
import org.apache.maven.cli.jline.JLineMessageBuilderFactory;
62-
import org.apache.maven.cli.jline.MessageUtils;
6361
import org.apache.maven.cli.logging.Slf4jConfiguration;
6462
import org.apache.maven.cli.logging.Slf4jConfigurationFactory;
6563
import org.apache.maven.cli.logging.Slf4jLoggerManager;
@@ -81,6 +79,8 @@
8179
import org.apache.maven.execution.scope.internal.MojoExecutionScopeModule;
8280
import org.apache.maven.extension.internal.CoreExports;
8381
import org.apache.maven.extension.internal.CoreExtensionEntry;
82+
import org.apache.maven.jline.JLineMessageBuilderFactory;
83+
import org.apache.maven.jline.MessageUtils;
8484
import org.apache.maven.lifecycle.LifecycleExecutionException;
8585
import org.apache.maven.logwrapper.LogLevelRecorder;
8686
import org.apache.maven.logwrapper.MavenSlf4jWrapperFactory;

maven-embedder/src/main/java/org/fusesource/jansi/Ansi.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ public interface Consumer {
160160
}
161161

162162
public static boolean isEnabled() {
163-
return org.apache.maven.cli.jline.MessageUtils.isColorEnabled() && org.jline.jansi.Ansi.isEnabled();
163+
return org.apache.maven.jline.MessageUtils.isColorEnabled() && org.jline.jansi.Ansi.isEnabled();
164164
}
165165

166166
public static Ansi ansi() {

maven-embedder/src/test/java/org/apache/maven/cli/MavenCliTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@
3535
import org.apache.commons.cli.Options;
3636
import org.apache.commons.cli.ParseException;
3737
import org.apache.maven.Maven;
38-
import org.apache.maven.cli.jline.MessageUtils;
3938
import org.apache.maven.cli.transfer.ConsoleMavenTransferListener;
4039
import org.apache.maven.cli.transfer.QuietMavenTransferListener;
4140
import org.apache.maven.cli.transfer.SimplexTransferListener;
@@ -44,6 +43,7 @@
4443
import org.apache.maven.execution.MavenExecutionRequest;
4544
import org.apache.maven.execution.ProfileActivation;
4645
import org.apache.maven.execution.ProjectActivation;
46+
import org.apache.maven.jline.MessageUtils;
4747
import org.apache.maven.model.root.DefaultRootLocator;
4848
import org.apache.maven.project.MavenProject;
4949
import org.apache.maven.toolchain.building.ToolchainsBuildingRequest;

maven-embedder/src/test/java/org/apache/maven/cli/event/ExecutionEventLoggerTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,10 @@
2222

2323
import com.google.common.collect.ImmutableList;
2424
import org.apache.commons.io.FilenameUtils;
25-
import org.apache.maven.cli.jline.JLineMessageBuilderFactory;
26-
import org.apache.maven.cli.jline.MessageUtils;
2725
import org.apache.maven.execution.ExecutionEvent;
2826
import org.apache.maven.execution.MavenSession;
27+
import org.apache.maven.jline.JLineMessageBuilderFactory;
28+
import org.apache.maven.jline.MessageUtils;
2929
import org.apache.maven.project.MavenProject;
3030
import org.junit.jupiter.api.AfterAll;
3131
import org.junit.jupiter.api.BeforeAll;

maven-embedder/src/test/java/org/apache/maven/cli/transfer/ConsoleMavenTransferListenerTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
import java.util.concurrent.ExecutorService;
2727
import java.util.concurrent.Executors;
2828

29-
import org.apache.maven.cli.jline.JLineMessageBuilderFactory;
29+
import org.apache.maven.jline.JLineMessageBuilderFactory;
3030
import org.eclipse.aether.DefaultRepositorySystemSession;
3131
import org.eclipse.aether.transfer.TransferCancelledException;
3232
import org.eclipse.aether.transfer.TransferEvent;

maven-jline/pom.xml

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!--
3+
Licensed to the Apache Software Foundation (ASF) under one
4+
or more contributor license agreements. See the NOTICE file
5+
distributed with this work for additional information
6+
regarding copyright ownership. The ASF licenses this file
7+
to you under the Apache License, Version 2.0 (the
8+
"License"); you may not use this file except in compliance
9+
with the License. You may obtain a copy of the License at
10+
11+
http://www.apache.org/licenses/LICENSE-2.0
12+
13+
Unless required by applicable law or agreed to in writing,
14+
software distributed under the License is distributed on an
15+
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16+
KIND, either express or implied. See the License for the
17+
specific language governing permissions and limitations
18+
under the License.
19+
-->
20+
<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">
21+
<modelVersion>4.0.0</modelVersion>
22+
<parent>
23+
<groupId>org.apache.maven</groupId>
24+
<artifactId>maven</artifactId>
25+
<version>4.0.0-alpha-13-SNAPSHOT</version>
26+
</parent>
27+
28+
<artifactId>maven-jline</artifactId>
29+
<name>Maven JLine integration</name>
30+
<description>Provides the JLine integration in Maven</description>
31+
32+
<dependencies>
33+
<dependency>
34+
<groupId>org.apache.maven</groupId>
35+
<artifactId>maven-api-core</artifactId>
36+
</dependency>
37+
<dependency>
38+
<groupId>org.jline</groupId>
39+
<artifactId>jline</artifactId>
40+
</dependency>
41+
<dependency>
42+
<groupId>javax.inject</groupId>
43+
<artifactId>javax.inject</artifactId>
44+
</dependency>
45+
<dependency>
46+
<groupId>javax.annotation</groupId>
47+
<artifactId>javax.annotation-api</artifactId>
48+
</dependency>
49+
<dependency>
50+
<groupId>org.codehaus.plexus</groupId>
51+
<artifactId>plexus-interactivity-api</artifactId>
52+
<exclusions>
53+
<exclusion>
54+
<groupId>org.codehaus.plexus</groupId>
55+
<artifactId>plexus-container-default</artifactId>
56+
</exclusion>
57+
</exclusions>
58+
</dependency>
59+
</dependencies>
60+
61+
</project>

maven-embedder/src/main/java/org/apache/maven/cli/jline/JLineMessageBuilderFactory.java renamed to maven-jline/src/main/java/org/apache/maven/jline/JLineMessageBuilderFactory.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
* specific language governing permissions and limitations
1717
* under the License.
1818
*/
19-
package org.apache.maven.cli.jline;
19+
package org.apache.maven.jline;
2020

2121
import javax.annotation.Priority;
2222
import javax.inject.Named;
@@ -40,8 +40,6 @@
4040
import org.jline.utils.AttributedStyle;
4141
import org.jline.utils.StyleResolver;
4242

43-
import static org.jline.utils.AttributedStyle.DEFAULT;
44-
4543
@Experimental
4644
@Named
4745
@Singleton
@@ -223,7 +221,7 @@ public MessageBuilder style(String style) {
223221

224222
@Override
225223
public MessageBuilder resetStyle() {
226-
builder.style(DEFAULT);
224+
builder.style(AttributedStyle.DEFAULT);
227225
return this;
228226
}
229227

maven-embedder/src/main/java/org/apache/maven/cli/jline/MessageUtils.java renamed to maven-jline/src/main/java/org/apache/maven/jline/MessageUtils.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
* specific language governing permissions and limitations
1717
* under the License.
1818
*/
19-
package org.apache.maven.cli.jline;
19+
package org.apache.maven.jline;
2020

2121
import java.io.IOError;
2222
import java.io.IOException;

maven-slf4j-provider/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ under the License.
4747
</dependency>
4848
<dependency>
4949
<groupId>org.apache.maven</groupId>
50-
<artifactId>maven-embedder</artifactId>
50+
<artifactId>maven-jline</artifactId>
5151
</dependency>
5252
</dependencies>
5353

maven-slf4j-provider/src/main/java/org/apache/maven/slf4j/MavenSimpleLogger.java

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,26 +19,33 @@
1919
package org.apache.maven.slf4j;
2020

2121
import java.io.PrintStream;
22+
import java.util.function.Consumer;
2223

2324
import org.apache.maven.api.services.MessageBuilder;
24-
import org.slf4j.simple.SimpleLogger;
25+
import org.slf4j.simple.ExtSimpleLogger;
2526

26-
import static org.apache.maven.cli.jline.MessageUtils.builder;
27+
import static org.apache.maven.jline.MessageUtils.builder;
2728

2829
/**
2930
* Logger for Maven, that support colorization of levels and stacktraces. This class implements 2 methods introduced in
3031
* slf4j-simple provider local copy.
3132
*
3233
* @since 3.5.0
3334
*/
34-
public class MavenSimpleLogger extends SimpleLogger {
35+
public class MavenSimpleLogger extends ExtSimpleLogger {
3536

3637
private final String traceRenderedLevel = builder().trace("TRACE").build();
3738
private final String debugRenderedLevel = builder().debug("DEBUG").build();
3839
private final String infoRenderedLevel = builder().info("INFO").build();
3940
private final String warnRenderedLevel = builder().warning("WARNING").build();
4041
private final String errorRenderedLevel = builder().error("ERROR").build();
4142

43+
static Consumer<String> logSink;
44+
45+
public static void setLogSink(Consumer<String> logSink) {
46+
MavenSimpleLogger.logSink = logSink;
47+
}
48+
4249
MavenSimpleLogger(String name) {
4350
super(name);
4451
}
@@ -60,6 +67,16 @@ protected String renderLevel(int level) {
6067
}
6168
}
6269

70+
@Override
71+
protected void doWrite(StringBuilder buf, Throwable t) {
72+
Consumer<String> sink = logSink;
73+
if (sink != null) {
74+
sink.accept(buf.toString());
75+
} else {
76+
super.doWrite(buf, t);
77+
}
78+
}
79+
6380
@Override
6481
protected void writeThrowable(Throwable t, PrintStream stream) {
6582
if (t == null) {
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
package org.slf4j.simple;
20+
21+
/**
22+
* Class inheriting SimpleLogger to work around the fact that the {@link #write(StringBuilder, Throwable)}
23+
* method is package private.
24+
*/
25+
public class ExtSimpleLogger extends SimpleLogger {
26+
27+
public ExtSimpleLogger(String name) {
28+
super(name);
29+
}
30+
31+
@Override
32+
void write(StringBuilder buf, Throwable t) {
33+
doWrite(buf, t);
34+
}
35+
36+
protected void doWrite(StringBuilder buf, Throwable t) {
37+
super.write(buf, t);
38+
}
39+
}

maven-slf4j-provider/src/test/java/org/apache/maven/slf4j/MavenSimpleLoggerTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
import java.util.List;
2525
import java.util.NoSuchElementException;
2626

27-
import org.apache.maven.cli.jline.MessageUtils;
27+
import org.apache.maven.jline.MessageUtils;
2828
import org.junit.jupiter.api.AfterEach;
2929
import org.junit.jupiter.api.BeforeEach;
3030
import org.junit.jupiter.api.Test;

pom.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@ under the License.
107107
<module>maven-model-builder</module>
108108
<module>maven-di</module>
109109
<module>maven-xml-impl</module>
110+
<module>maven-jline</module>
110111
<module>maven-core</module>
111112
<module>maven-settings</module>
112113
<module>maven-settings-builder</module>
@@ -203,6 +204,11 @@ under the License.
203204
<artifactId>maven-builder-support</artifactId>
204205
<version>${project.version}</version>
205206
</dependency>
207+
<dependency>
208+
<groupId>org.apache.maven</groupId>
209+
<artifactId>maven-jline</artifactId>
210+
<version>${project.version}</version>
211+
</dependency>
206212
<dependency>
207213
<groupId>org.apache.maven</groupId>
208214
<artifactId>maven-core</artifactId>

0 commit comments

Comments
 (0)