diff --git a/client/src/main/java-mvnd/org/mvndaemon/mvnd/client/DefaultClient.java b/client/src/main/java-mvnd/org/mvndaemon/mvnd/client/DefaultClient.java index ee5f9ae09..d617c5d8d 100644 --- a/client/src/main/java-mvnd/org/mvndaemon/mvnd/client/DefaultClient.java +++ b/client/src/main/java-mvnd/org/mvndaemon/mvnd/client/DefaultClient.java @@ -41,9 +41,9 @@ import java.util.stream.Collectors; import java.util.stream.Stream; -import org.fusesource.jansi.Ansi; -import org.fusesource.jansi.internal.CLibrary; +import org.jline.nativ.CLibrary; import org.jline.utils.AttributedString; +import org.jline.utils.AttributedStringBuilder; import org.jline.utils.AttributedStyle; import org.mvndaemon.mvnd.common.DaemonException; import org.mvndaemon.mvnd.common.DaemonInfo; @@ -57,11 +57,10 @@ import org.mvndaemon.mvnd.common.TimeUtils; import org.mvndaemon.mvnd.common.logging.ClientOutput; import org.mvndaemon.mvnd.common.logging.TerminalOutput; +import org.mvndaemon.mvnd.logging.slf4j.MvndLoggerFactory; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.slf4j.bridge.SLF4JBridgeHandler; -import org.slf4j.impl.MvndLoggerFactory; -import org.slf4j.impl.StaticLoggerBinder; import static org.mvndaemon.mvnd.client.DaemonParameters.LOG_EXTENSION; @@ -115,8 +114,8 @@ public static void main(String[] argv) throws Exception { // System properties setSystemPropertiesFromCommandLine(args); - if (StaticLoggerBinder.getSingleton().getLoggerFactory() instanceof MvndLoggerFactory) { - ((MvndLoggerFactory) StaticLoggerBinder.getSingleton().getLoggerFactory()).reconfigure(); + if (LoggerFactory.getILoggerFactory() instanceof MvndLoggerFactory) { + ((MvndLoggerFactory) LoggerFactory.getILoggerFactory()).reconfigure(); } DaemonParameters parameters = new DaemonParameters(); @@ -251,8 +250,12 @@ public ExecutionResult execute(ClientOutput output, List argv) { + " (" + buildProperties.getRevision() + ")"; boolean isColored = !"never".equals(Environment.MAVEN_COLOR.getCommandLineOption(args)); - final String v = - isColored ? Ansi.ansi().bold().a(mvndVersionString).reset().toString() : mvndVersionString; + final String v = isColored + ? new AttributedStringBuilder() + .style(AttributedStyle.BOLD) + .append(mvndVersionString) + .toAnsi() + : mvndVersionString; output.accept(Message.log(v)); // Print terminal information output.describeTerminal(); diff --git a/client/src/main/java/org/mvndaemon/mvnd/client/DaemonConnector.java b/client/src/main/java/org/mvndaemon/mvnd/client/DaemonConnector.java index 912a05e92..8367f06c0 100644 --- a/client/src/main/java/org/mvndaemon/mvnd/client/DaemonConnector.java +++ b/client/src/main/java/org/mvndaemon/mvnd/client/DaemonConnector.java @@ -55,9 +55,9 @@ import org.mvndaemon.mvnd.common.Os; import org.mvndaemon.mvnd.common.SocketFamily; import org.mvndaemon.mvnd.common.logging.ClientOutput; +import org.mvndaemon.mvnd.logging.slf4j.MvndBaseLogger; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import org.slf4j.impl.SimpleLogger; import static java.lang.Thread.sleep; import static org.mvndaemon.mvnd.common.DaemonState.Canceled; @@ -434,7 +434,7 @@ private Process startDaemonProcess(String daemonId, ClientOutput output) { args.add("-Dmaven.conf=" + mvndHome.resolve("mvn").resolve("conf")); args.add("-Dclassworlds.conf=" + mvndHome.resolve("bin").resolve("mvnd-daemon.conf")); - args.add("-D" + SimpleLogger.LOG_FILE_KEY + "=" + args.add("-D" + MvndBaseLogger.LOG_FILE_KEY + "=" + parameters.daemonStorage().resolve("daemon-" + daemonId + ".log")); Environment.MVND_JAVA_HOME.addSystemProperty( diff --git a/client/src/main/java/org/mvndaemon/mvnd/client/svm/StaticMDCBinderSubstitution.java b/client/src/main/java/org/mvndaemon/mvnd/client/svm/StaticMDCBinderSubstitution.java deleted file mode 100644 index e23714749..000000000 --- a/client/src/main/java/org/mvndaemon/mvnd/client/svm/StaticMDCBinderSubstitution.java +++ /dev/null @@ -1,34 +0,0 @@ -/* - * 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.mvndaemon.mvnd.client.svm; - -import com.oracle.svm.core.annotate.Substitute; -import com.oracle.svm.core.annotate.TargetClass; -import org.slf4j.MDC; -import org.slf4j.impl.StaticMDCBinder; -import org.slf4j.spi.MDCAdapter; - -@TargetClass(MDC.class) -final class StaticMDCBinderSubstitution { - - @Substitute - private static MDCAdapter bwCompatibleGetMDCAdapterFromBinder() throws NoClassDefFoundError { - return StaticMDCBinder.SINGLETON.getMDCA(); - } -} diff --git a/common/pom.xml b/common/pom.xml index 5df322ca5..fbc261d66 100644 --- a/common/pom.xml +++ b/common/pom.xml @@ -43,7 +43,7 @@ org.jline - jline-terminal-jansi + jline-terminal-jni diff --git a/daemon/pom.xml b/daemon/pom.xml index 6f3766b9b..2575fd01a 100644 --- a/daemon/pom.xml +++ b/daemon/pom.xml @@ -98,6 +98,12 @@ compile + + com.google.inject + guice + 6.0.0 + + org.junit.jupiter junit-jupiter diff --git a/daemon/src/main/java/org/apache/maven/cli/DaemonMavenCli.java b/daemon/src/main/java/org/apache/maven/cli/DaemonMavenCli.java index e74404225..b8e461f19 100644 --- a/daemon/src/main/java/org/apache/maven/cli/DaemonMavenCli.java +++ b/daemon/src/main/java/org/apache/maven/cli/DaemonMavenCli.java @@ -18,12 +18,15 @@ */ package org.apache.maven.cli; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; import java.io.File; import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.IOException; import java.io.PrintStream; import java.nio.charset.Charset; +import java.nio.charset.StandardCharsets; import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.Paths; @@ -52,7 +55,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.MessageUtils; import org.apache.maven.cli.logging.Slf4jConfiguration; import org.apache.maven.cli.logging.Slf4jConfigurationFactory; import org.apache.maven.cli.transfer.QuietMavenTransferListener; @@ -62,10 +64,12 @@ import org.apache.maven.exception.ExceptionHandler; import org.apache.maven.exception.ExceptionSummary; import org.apache.maven.execution.*; +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.CoreExportsProvider; import org.apache.maven.extension.internal.CoreExtensionEntry; +import org.apache.maven.jline.MessageUtils; import org.apache.maven.lifecycle.LifecycleExecutionException; import org.apache.maven.model.building.ModelProcessor; import org.apache.maven.model.root.RootLocator; @@ -74,6 +78,7 @@ import org.apache.maven.project.MavenProject; import org.apache.maven.project.artifact.ProjectArtifactsCache; import org.apache.maven.properties.internal.SystemProperties; +import org.apache.maven.session.scope.internal.SessionScope; import org.apache.maven.session.scope.internal.SessionScopeModule; import org.apache.maven.toolchain.building.DefaultToolchainsBuildingRequest; import org.apache.maven.toolchain.building.ToolchainsBuilder; @@ -90,6 +95,8 @@ import org.codehaus.plexus.interpolation.BasicInterpolator; import org.codehaus.plexus.interpolation.StringSearchInterpolator; import org.eclipse.aether.transfer.TransferListener; +import org.jline.terminal.Terminal; +import org.jline.terminal.impl.ExternalTerminal; import org.mvndaemon.mvnd.cache.invalidating.InvalidatingExtensionRealmCache; import org.mvndaemon.mvnd.cache.invalidating.InvalidatingPluginArtifactsCache; import org.mvndaemon.mvnd.cache.invalidating.InvalidatingProjectArtifactsCache; @@ -97,6 +104,7 @@ import org.mvndaemon.mvnd.common.Environment; import org.mvndaemon.mvnd.common.Os; import org.mvndaemon.mvnd.logging.internal.Slf4jLoggerManager; +import org.mvndaemon.mvnd.logging.slf4j.MvndSimpleLogger; import org.mvndaemon.mvnd.logging.smart.BuildEventListener; import org.mvndaemon.mvnd.logging.smart.LoggingExecutionListener; import org.mvndaemon.mvnd.logging.smart.LoggingOutputStream; @@ -104,7 +112,6 @@ import org.slf4j.ILoggerFactory; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import org.slf4j.impl.MvndSimpleLogger; import org.slf4j.spi.LocationAwareLogger; import org.sonatype.plexus.components.sec.dispatcher.DefaultSecDispatcher; import org.sonatype.plexus.components.sec.dispatcher.SecDispatcher; @@ -204,6 +211,13 @@ public int main( Map clientEnv, BuildEventListener buildEventListener) throws Exception { + Terminal terminal = new ExternalTerminal( + "Maven", + "ansi", + new ByteArrayInputStream(new byte[0]), + new ByteArrayOutputStream(), + StandardCharsets.UTF_8); + MessageUtils.systemInstall(terminal); this.buildEventListener = buildEventListener; try { CliRequest req = new CliRequest(null, null); @@ -634,8 +648,8 @@ public Object getValue(String expression) { for (CoreExtensionEntry extension : extensionsEntries) { container.discoverComponents( extension.getClassRealm(), - new SessionScopeModule(container), - new MojoExecutionScopeModule(container), + new SessionScopeModule(container.lookup(SessionScope.class)), + new MojoExecutionScopeModule(container.lookup(MojoExecutionScope.class)), new ExtensionConfigurationModule(extension, extensionSource)); } return container; diff --git a/daemon/src/main/java/org/apache/maven/cli/DaemonMessageBuilderFactory.java b/daemon/src/main/java/org/apache/maven/cli/DaemonMessageBuilderFactory.java index afc74b35d..ebadddd5e 100644 --- a/daemon/src/main/java/org/apache/maven/cli/DaemonMessageBuilderFactory.java +++ b/daemon/src/main/java/org/apache/maven/cli/DaemonMessageBuilderFactory.java @@ -23,14 +23,14 @@ import javax.inject.Singleton; import org.apache.maven.api.annotations.Experimental; -import org.apache.maven.cli.jansi.JansiMessageBuilderFactory; +import org.apache.maven.jline.JLineMessageBuilderFactory; import org.mvndaemon.mvnd.common.Environment; @Named @Singleton @Priority(10) @Experimental -public class DaemonMessageBuilderFactory extends JansiMessageBuilderFactory { +public class DaemonMessageBuilderFactory extends JLineMessageBuilderFactory { @Override public int getTerminalWidth() { diff --git a/daemon/src/main/java/org/apache/maven/project/SnapshotModelCache.java b/daemon/src/main/java/org/apache/maven/project/SnapshotModelCache.java index 275fc97fb..e27bf76e8 100644 --- a/daemon/src/main/java/org/apache/maven/project/SnapshotModelCache.java +++ b/daemon/src/main/java/org/apache/maven/project/SnapshotModelCache.java @@ -19,6 +19,7 @@ package org.apache.maven.project; import java.util.Objects; +import java.util.function.Supplier; import org.apache.maven.building.Source; import org.apache.maven.model.building.ModelCache; @@ -33,22 +34,14 @@ public SnapshotModelCache(ModelCache globalCache, ModelCache reactorCache) { this.reactorCache = Objects.requireNonNull(reactorCache); } - public Object get(Source path, String tag) { - return reactorCache.get(path, tag); - } - - public void put(Source path, String tag, Object data) { - reactorCache.put(path, tag, data); - } - @Override - public void put(String groupId, String artifactId, String version, String tag, Object data) { - getDelegate(version).put(groupId, artifactId, version, tag, data); + public T computeIfAbsent(String groupId, String artifactId, String version, String tag, Supplier data) { + return getDelegate(version).computeIfAbsent(groupId, artifactId, version, tag, data); } @Override - public Object get(String groupId, String artifactId, String version, String tag) { - return getDelegate(version).get(groupId, artifactId, version, tag); + public T computeIfAbsent(Source path, String tag, Supplier data) { + return reactorCache.computeIfAbsent(path, tag, data); } private ModelCache getDelegate(String version) { diff --git a/dist/pom.xml b/dist/pom.xml index af840c93d..cdf46b1cd 100644 --- a/dist/pom.xml +++ b/dist/pom.xml @@ -31,8 +31,8 @@ Maven Daemon - Distribution - 11 - 11 + 17 + 17 @@ -52,6 +52,16 @@ org.apache.maven.daemon mvnd-daemon + + org.apache.maven.daemon + mvnd-logging + + + com.google.inject + guice + 6.0.0 + provided + diff --git a/dist/src/main/provisio/maven-distro.xml b/dist/src/main/provisio/maven-distro.xml index 29e23b5fa..f37ff8250 100644 --- a/dist/src/main/provisio/maven-distro.xml +++ b/dist/src/main/provisio/maven-distro.xml @@ -61,12 +61,14 @@ + diff --git a/integration-tests/pom.xml b/integration-tests/pom.xml index d07ea6f74..a4ae7ab99 100644 --- a/integration-tests/pom.xml +++ b/integration-tests/pom.xml @@ -30,8 +30,8 @@ Maven Daemon - Integration Tests - 11 - 11 + 17 + 17 ${project.basedir}/../dist/target/maven-mvnd-${project.version}-${os.detected.name}-${os.detected.arch} org/apache/maven/surefire/surefire-providers/${surefire.version} org/apache/maven/surefire/surefire-junit-platform/${surefire.version} diff --git a/integration-tests/src/test/java/org/mvndaemon/mvnd/it/MaxHeapNativeIT.java b/integration-tests/src/test/java/org/mvndaemon/mvnd/it/MaxHeapNativeIT.java index 43a08c206..d6defd889 100644 --- a/integration-tests/src/test/java/org/mvndaemon/mvnd/it/MaxHeapNativeIT.java +++ b/integration-tests/src/test/java/org/mvndaemon/mvnd/it/MaxHeapNativeIT.java @@ -30,8 +30,8 @@ import org.mvndaemon.mvnd.assertj.TestClientOutput; import org.mvndaemon.mvnd.client.Client; import org.mvndaemon.mvnd.junit.MvndNativeTest; +import org.mvndaemon.mvnd.logging.slf4j.MvndSimpleLogger; import org.slf4j.LoggerFactory; -import org.slf4j.impl.MvndSimpleLogger; import org.slf4j.spi.LocationAwareLogger; import static org.junit.jupiter.api.Assertions.assertTrue; diff --git a/integration-tests/src/test/projects/exec-output/pom.xml b/integration-tests/src/test/projects/exec-output/pom.xml index 393768fae..be3c971fd 100644 --- a/integration-tests/src/test/projects/exec-output/pom.xml +++ b/integration-tests/src/test/projects/exec-output/pom.xml @@ -34,7 +34,7 @@ 3.1.0 3.3.0 3.0.0-M8 - 3.1.0 + 3.2.0 diff --git a/integration-tests/src/test/projects/invoker/pom.xml b/integration-tests/src/test/projects/invoker/pom.xml index aa21167d0..7f42c6775 100644 --- a/integration-tests/src/test/projects/invoker/pom.xml +++ b/integration-tests/src/test/projects/invoker/pom.xml @@ -84,7 +84,7 @@ maven-invoker-plugin - 3.2.1 + 3.6.1 ${project.build.directory}/it ${project.build.directory}/local-repo diff --git a/integration-tests/src/test/projects/invoker/src/it/invoke-hello/verify.groovy b/integration-tests/src/test/projects/invoker/src/it/invoke-hello/verify.groovy index 26c2935e4..61b715f27 100644 --- a/integration-tests/src/test/projects/invoker/src/it/invoke-hello/verify.groovy +++ b/integration-tests/src/test/projects/invoker/src/it/invoke-hello/verify.groovy @@ -21,4 +21,4 @@ Path helloPath = basePath.resolve('target/hello.txt') assert Files.exists(helloPath) -assert helloPath.text.equals('Hello') +assert Files.readString(helloPath).equals('Hello') diff --git a/integration-tests/src/test/projects/type-description/pom.xml b/integration-tests/src/test/projects/type-description/pom.xml index ed8c9b344..2ab964e02 100644 --- a/integration-tests/src/test/projects/type-description/pom.xml +++ b/integration-tests/src/test/projects/type-description/pom.xml @@ -42,7 +42,7 @@ gnu - 2.14.1.Final + 3.10.0 3.0.3 diff --git a/integration-tests/src/test/projects/type-description/server/src/main/java/org/mvndaemon/mvnd/test/type/description/server/domain/AbstractEntity.java b/integration-tests/src/test/projects/type-description/server/src/main/java/org/mvndaemon/mvnd/test/type/description/server/domain/AbstractEntity.java index e9bacdf4c..2a91c2160 100644 --- a/integration-tests/src/test/projects/type-description/server/src/main/java/org/mvndaemon/mvnd/test/type/description/server/domain/AbstractEntity.java +++ b/integration-tests/src/test/projects/type-description/server/src/main/java/org/mvndaemon/mvnd/test/type/description/server/domain/AbstractEntity.java @@ -15,10 +15,10 @@ */ package org.mvndaemon.mvnd.test.type.description.server.domain; -import javax.persistence.GeneratedValue; -import javax.persistence.GenerationType; -import javax.persistence.Id; -import javax.persistence.MappedSuperclass; +import jakarta.persistence.GeneratedValue; +import jakarta.persistence.GenerationType; +import jakarta.persistence.Id; +import jakarta.persistence.MappedSuperclass; import java.io.Serializable; /** diff --git a/integration-tests/src/test/projects/type-description/server/src/main/java/org/mvndaemon/mvnd/test/type/description/server/domain/Image.java b/integration-tests/src/test/projects/type-description/server/src/main/java/org/mvndaemon/mvnd/test/type/description/server/domain/Image.java index a05464dc3..3c3f82f12 100644 --- a/integration-tests/src/test/projects/type-description/server/src/main/java/org/mvndaemon/mvnd/test/type/description/server/domain/Image.java +++ b/integration-tests/src/test/projects/type-description/server/src/main/java/org/mvndaemon/mvnd/test/type/description/server/domain/Image.java @@ -15,11 +15,11 @@ */ package org.mvndaemon.mvnd.test.type.description.server.domain; -import javax.persistence.Column; -import javax.persistence.Entity; -import javax.persistence.Lob; -import javax.persistence.Table; -import javax.persistence.UniqueConstraint; +import jakarta.persistence.Column; +import jakarta.persistence.Entity; +import jakarta.persistence.Lob; +import jakarta.persistence.Table; +import jakarta.persistence.UniqueConstraint; import javax.sql.rowset.serial.SerialBlob; import java.io.IOException; import java.io.InputStream; diff --git a/logging/pom.xml b/logging/pom.xml index d895072c4..aa9bb186b 100644 --- a/logging/pom.xml +++ b/logging/pom.xml @@ -35,6 +35,15 @@ org.apache.maven maven-embedder + + org.apache.maven + maven-jline + + + org.eclipse.sisu + org.eclipse.sisu.inject + provided + org.apache.maven.shared maven-shared-utils @@ -79,15 +88,8 @@ ${maven.version} sources - - org.slf4j - slf4j-simple - ${slf4j.version} - sources - - org/apache/maven/logwrapper/*.java,org/slf4j/impl/*.java - **/StaticLoggerBinder.java,**/StaticMDCBinder.java + org/apache/maven/logwrapper/*.java ${project.build.directory}/generated-sources/unpack diff --git a/logging/src/main/java/org/mvndaemon/mvnd/logging/slf4j/MvndBaseLogger.java b/logging/src/main/java/org/mvndaemon/mvnd/logging/slf4j/MvndBaseLogger.java new file mode 100644 index 000000000..18b4e5c14 --- /dev/null +++ b/logging/src/main/java/org/mvndaemon/mvnd/logging/slf4j/MvndBaseLogger.java @@ -0,0 +1,466 @@ +/* + * 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.mvndaemon.mvnd.logging.slf4j; + +import java.io.PrintStream; +import java.util.ArrayList; +import java.util.Date; +import java.util.List; + +import org.slf4j.Logger; +import org.slf4j.Marker; +import org.slf4j.event.Level; +import org.slf4j.event.LoggingEvent; +import org.slf4j.helpers.LegacyAbstractLogger; +import org.slf4j.helpers.MessageFormatter; +import org.slf4j.helpers.NormalizedParameters; +import org.slf4j.spi.LocationAwareLogger; + +/** + *

+ * Simple implementation of {@link Logger} that sends all enabled log messages, + * for all defined loggers, to the console ({@code System.err}). The following + * system properties are supported to configure the behavior of this logger: + * + * + *

    + *
  • org.slf4j.simpleLogger.logFile - The output target which can + * be the path to a file, or the special values "System.out" and + * "System.err". Default is "System.err".
  • + * + *
  • org.slf4j.simpleLogger.cacheOutputStream - If the output + * target is set to "System.out" or "System.err" (see preceding entry), by + * default, logs will be output to the latest value referenced by + * System.out/err variables. By setting this parameter to true, the + * output stream will be cached, i.e. assigned once at initialization time and + * re-used independently of the current value referenced by + * System.out/err.
  • + * + *
  • org.slf4j.simpleLogger.defaultLogLevel - Default log level + * for all instances of SimpleLogger. Must be one of ("trace", "debug", "info", + * "warn", "error" or "off"). If not specified, defaults to "info".
  • + * + *
  • org.slf4j.simpleLogger.log.a.b.c - Logging detail + * level for a SimpleLogger instance named "a.b.c". Right-side value must be one + * of "trace", "debug", "info", "warn", "error" or "off". When a SimpleLogger + * named "a.b.c" is initialized, its level is assigned from this property. If + * unspecified, the level of nearest parent logger will be used, and if none is + * set, then the value specified by + * org.slf4j.simpleLogger.defaultLogLevel will be used.
  • + * + *
  • org.slf4j.simpleLogger.showDateTime - Set to + * true if you want the current date and time to be included in + * output messages. Default is false
  • + * + *
  • org.slf4j.simpleLogger.dateTimeFormat - The date and time + * format to be used in the output messages. The pattern describing the date and + * time format is defined by + * SimpleDateFormat. If the format is not specified or is + * invalid, the number of milliseconds since start up will be output.
  • + * + *
  • org.slf4j.simpleLogger.showThreadName -Set to + * true if you want to output the current thread name. Defaults to + * true.
  • + * + *
  • (since version 1.7.33 and 2.0.0-alpha6) org.slf4j.simpleLogger.showThreadId - + * If you would like to output the current thread id, then set to + * true. Defaults to false.
  • + * + *
  • org.slf4j.simpleLogger.showLogName - Set to + * true if you want the Logger instance name to be included in + * output messages. Defaults to true.
  • + * + *
  • org.slf4j.simpleLogger.showShortLogName - Set to + * true if you want the last component of the name to be included + * in output messages. Defaults to false.
  • + * + *
  • org.slf4j.simpleLogger.levelInBrackets - Should the level + * string be output in brackets? Defaults to false.
  • + * + *
  • org.slf4j.simpleLogger.warnLevelString - The string value + * output for the warn level. Defaults to WARN.
  • + * + *
+ * + *

+ * In addition to looking for system properties with the names specified above, + * this implementation also checks for a class loader resource named + * "simplelogger.properties", and includes any matching definitions + * from this resource (if it exists). + * + * + *

+ * With no configuration, the default output includes the relative time in + * milliseconds, thread name, the level, logger name, and the message followed + * by the line separator for the host. In log4j terms it amounts to the "%r [%t] + * %level %logger - %m%n" pattern. + * + *

+ * Sample output follows. + * + * + *

+ * 176 [main] INFO examples.Sort - Populating an array of 2 elements in reverse order.
+ * 225 [main] INFO examples.SortAlgo - Entered the sort method.
+ * 304 [main] INFO examples.SortAlgo - Dump of integer array:
+ * 317 [main] INFO examples.SortAlgo - Element [0] = 0
+ * 331 [main] INFO examples.SortAlgo - Element [1] = 1
+ * 343 [main] INFO examples.Sort - The next log statement should be an error message.
+ * 346 [main] ERROR examples.SortAlgo - Tried to dump an uninitialized array.
+ *   at org.log4j.examples.SortAlgo.dump(SortAlgo.java:58)
+ *   at org.log4j.examples.Sort.main(Sort.java:64)
+ * 467 [main] INFO  examples.Sort - Exiting main method.
+ * 
+ * + *

+ * This implementation is heavily inspired by + * Apache Commons Logging's + * SimpleLog. + * + * + * @author Ceki Gülcü + * @author Scott Sanders + * @author Rod Waldhoff + * @author Robert Burrell Donkin + * @author Cédrik LIME + */ +public class MvndBaseLogger extends LegacyAbstractLogger { + + private static final long serialVersionUID = -632788891211436180L; + + private static final long START_TIME = System.currentTimeMillis(); + + protected static final int LOG_LEVEL_TRACE = LocationAwareLogger.TRACE_INT; + protected static final int LOG_LEVEL_DEBUG = LocationAwareLogger.DEBUG_INT; + protected static final int LOG_LEVEL_INFO = LocationAwareLogger.INFO_INT; + protected static final int LOG_LEVEL_WARN = LocationAwareLogger.WARN_INT; + protected static final int LOG_LEVEL_ERROR = LocationAwareLogger.ERROR_INT; + + static char SP = ' '; + static final String TID_PREFIX = "tid="; + + // The OFF level can only be used in configuration files to disable logging. + // It has + // no printing method associated with it in o.s.Logger interface. + protected static final int LOG_LEVEL_OFF = LOG_LEVEL_ERROR + 10; + + private static boolean INITIALIZED = false; + static final SimpleLoggerConfiguration CONFIG_PARAMS = new SimpleLoggerConfiguration(); + + static void lazyInit() { + if (INITIALIZED) { + return; + } + INITIALIZED = true; + init(); + } + + // external software might be invoking this method directly. Do not rename + // or change its semantics. + static void init() { + CONFIG_PARAMS.init(); + } + + /** The current log level */ + protected int currentLogLevel = LOG_LEVEL_INFO; + /** The short name of this simple log instance */ + private transient String shortLogName = null; + + /** + * All system properties used by SimpleLogger start with this + * prefix + */ + public static final String SYSTEM_PREFIX = "org.slf4j.simpleLogger."; + + public static final String LOG_KEY_PREFIX = MvndBaseLogger.SYSTEM_PREFIX + "log."; + + public static final String CACHE_OUTPUT_STREAM_STRING_KEY = MvndBaseLogger.SYSTEM_PREFIX + "cacheOutputStream"; + + public static final String WARN_LEVEL_STRING_KEY = MvndBaseLogger.SYSTEM_PREFIX + "warnLevelString"; + + public static final String LEVEL_IN_BRACKETS_KEY = MvndBaseLogger.SYSTEM_PREFIX + "levelInBrackets"; + + public static final String LOG_FILE_KEY = MvndBaseLogger.SYSTEM_PREFIX + "logFile"; + + public static final String SHOW_SHORT_LOG_NAME_KEY = MvndBaseLogger.SYSTEM_PREFIX + "showShortLogName"; + + public static final String SHOW_LOG_NAME_KEY = MvndBaseLogger.SYSTEM_PREFIX + "showLogName"; + + public static final String SHOW_THREAD_NAME_KEY = MvndBaseLogger.SYSTEM_PREFIX + "showThreadName"; + + public static final String SHOW_THREAD_ID_KEY = MvndBaseLogger.SYSTEM_PREFIX + "showThreadId"; + + public static final String DATE_TIME_FORMAT_KEY = MvndBaseLogger.SYSTEM_PREFIX + "dateTimeFormat"; + + public static final String SHOW_DATE_TIME_KEY = MvndBaseLogger.SYSTEM_PREFIX + "showDateTime"; + + public static final String DEFAULT_LOG_LEVEL_KEY = MvndBaseLogger.SYSTEM_PREFIX + "defaultLogLevel"; + + /** + * Protected access allows only {@link MvndLoggerFactory} and also derived classes to instantiate + * MvndBaseLogger instances. + */ + protected MvndBaseLogger(String name) { + this.name = name; + + String levelString = recursivelyComputeLevelString(); + if (levelString != null) { + this.currentLogLevel = SimpleLoggerConfiguration.stringToLevel(levelString); + } else { + this.currentLogLevel = CONFIG_PARAMS.defaultLogLevel; + } + } + + String recursivelyComputeLevelString() { + String tempName = name; + String levelString = null; + int indexOfLastDot = tempName.length(); + while ((levelString == null) && (indexOfLastDot > -1)) { + tempName = tempName.substring(0, indexOfLastDot); + levelString = CONFIG_PARAMS.getStringProperty(MvndBaseLogger.LOG_KEY_PREFIX + tempName, null); + indexOfLastDot = String.valueOf(tempName).lastIndexOf("."); + } + return levelString; + } + + /** + * To avoid intermingling of log messages and associated stack traces, the two + * operations are done in a synchronized block. + * + * @param buf + * @param t + */ + void write(StringBuilder buf, Throwable t) { + PrintStream targetStream = CONFIG_PARAMS.outputChoice.getTargetPrintStream(); + + synchronized (CONFIG_PARAMS) { + targetStream.println(buf.toString()); + writeThrowable(t, targetStream); + targetStream.flush(); + } + } + + protected void writeThrowable(Throwable t, PrintStream targetStream) { + if (t != null) { + t.printStackTrace(targetStream); + } + } + + private String getFormattedDate() { + Date now = new Date(); + String dateText; + synchronized (CONFIG_PARAMS.dateFormatter) { + dateText = CONFIG_PARAMS.dateFormatter.format(now); + } + return dateText; + } + + private String computeShortName() { + return name.substring(name.lastIndexOf(".") + 1); + } + + // /** + // * For formatted messages, first substitute arguments and then log. + // * + // * @param level + // * @param format + // * @param arg1 + // * @param arg2 + // */ + // private void formatAndLog(int level, String format, Object arg1, Object arg2) { + // if (!isLevelEnabled(level)) { + // return; + // } + // FormattingTuple tp = MessageFormatter.format(format, arg1, arg2); + // log(level, tp.getMessage(), tp.getThrowable()); + // } + + // /** + // * For formatted messages, first substitute arguments and then log. + // * + // * @param level + // * @param format + // * @param arguments + // * a list of 3 ore more arguments + // */ + // private void formatAndLog(int level, String format, Object... arguments) { + // if (!isLevelEnabled(level)) { + // return; + // } + // FormattingTuple tp = MessageFormatter.arrayFormat(format, arguments); + // log(level, tp.getMessage(), tp.getThrowable()); + // } + + /** + * Is the given log level currently enabled? + * + * @param logLevel is this level enabled? + * @return whether the logger is enabled for the given level + */ + protected boolean isLevelEnabled(int logLevel) { + // log level are numerically ordered so can use simple numeric + // comparison + return (logLevel >= currentLogLevel); + } + + /** Are {@code trace} messages currently enabled? */ + public boolean isTraceEnabled() { + return isLevelEnabled(LOG_LEVEL_TRACE); + } + + /** Are {@code debug} messages currently enabled? */ + public boolean isDebugEnabled() { + return isLevelEnabled(LOG_LEVEL_DEBUG); + } + + /** Are {@code info} messages currently enabled? */ + public boolean isInfoEnabled() { + return isLevelEnabled(LOG_LEVEL_INFO); + } + + /** Are {@code warn} messages currently enabled? */ + public boolean isWarnEnabled() { + return isLevelEnabled(LOG_LEVEL_WARN); + } + + /** Are {@code error} messages currently enabled? */ + public boolean isErrorEnabled() { + return isLevelEnabled(LOG_LEVEL_ERROR); + } + + /** + * SimpleLogger's implementation of + * {@link org.slf4j.helpers.AbstractLogger#handleNormalizedLoggingCall(Level, Marker, String, Object[], Throwable) AbstractLogger#handleNormalizedLoggingCall} + * } + * + * @param level the SLF4J level for this event + * @param marker The marker to be used for this event, may be null. + * @param messagePattern The message pattern which will be parsed and formatted + * @param arguments the array of arguments to be formatted, may be null + * @param throwable The exception whose stack trace should be logged, may be null + */ + @Override + protected void handleNormalizedLoggingCall( + Level level, Marker marker, String messagePattern, Object[] arguments, Throwable throwable) { + + List markers = null; + + if (marker != null) { + markers = new ArrayList<>(); + markers.add(marker); + } + + innerHandleNormalizedLoggingCall(level, markers, messagePattern, arguments, throwable); + } + + private void innerHandleNormalizedLoggingCall( + Level level, List markers, String messagePattern, Object[] arguments, Throwable t) { + + StringBuilder buf = new StringBuilder(32); + + // Append date-time if so configured + if (CONFIG_PARAMS.showDateTime) { + if (CONFIG_PARAMS.dateFormatter != null) { + buf.append(getFormattedDate()); + buf.append(SP); + } else { + buf.append(System.currentTimeMillis() - START_TIME); + buf.append(SP); + } + } + + // Append current thread name if so configured + if (CONFIG_PARAMS.showThreadName) { + buf.append('['); + buf.append(Thread.currentThread().getName()); + buf.append("] "); + } + + if (CONFIG_PARAMS.showThreadId) { + buf.append(TID_PREFIX); + buf.append(Thread.currentThread().getId()); + buf.append(SP); + } + + if (CONFIG_PARAMS.levelInBrackets) buf.append('['); + + // Append a readable representation of the log level + String levelStr = renderLevel(level.toInt()); + buf.append(levelStr); + if (CONFIG_PARAMS.levelInBrackets) buf.append(']'); + buf.append(SP); + + // Append the name of the log instance if so configured + if (CONFIG_PARAMS.showShortLogName) { + if (shortLogName == null) shortLogName = computeShortName(); + buf.append(String.valueOf(shortLogName)).append(" - "); + } else if (CONFIG_PARAMS.showLogName) { + buf.append(String.valueOf(name)).append(" - "); + } + + if (markers != null) { + buf.append(SP); + for (Marker marker : markers) { + buf.append(marker.getName()).append(SP); + } + } + + String formattedMessage = MessageFormatter.basicArrayFormat(messagePattern, arguments); + + // Append the message + buf.append(formattedMessage); + + write(buf, t); + } + + protected String renderLevel(int levelInt) { + switch (levelInt) { + case LOG_LEVEL_TRACE: + return "TRACE"; + case LOG_LEVEL_DEBUG: + return ("DEBUG"); + case LOG_LEVEL_INFO: + return "INFO"; + case LOG_LEVEL_WARN: + return "WARN"; + case LOG_LEVEL_ERROR: + return "ERROR"; + } + throw new IllegalStateException("Unrecognized level [" + levelInt + "]"); + } + + public void log(LoggingEvent event) { + int levelInt = event.getLevel().toInt(); + + if (!isLevelEnabled(levelInt)) { + return; + } + + NormalizedParameters np = NormalizedParameters.normalize(event); + + innerHandleNormalizedLoggingCall( + event.getLevel(), event.getMarkers(), np.getMessage(), np.getArguments(), event.getThrowable()); + } + + @Override + protected String getFullyQualifiedCallerName() { + return null; + } +} diff --git a/logging/src/main/java/org/slf4j/impl/MvndConfiguration.java b/logging/src/main/java/org/mvndaemon/mvnd/logging/slf4j/MvndConfiguration.java similarity index 91% rename from logging/src/main/java/org/slf4j/impl/MvndConfiguration.java rename to logging/src/main/java/org/mvndaemon/mvnd/logging/slf4j/MvndConfiguration.java index e075a03e1..1da3cc840 100644 --- a/logging/src/main/java/org/slf4j/impl/MvndConfiguration.java +++ b/logging/src/main/java/org/mvndaemon/mvnd/logging/slf4j/MvndConfiguration.java @@ -16,10 +16,11 @@ * specific language governing permissions and limitations * under the License. */ -package org.slf4j.impl; +package org.mvndaemon.mvnd.logging.slf4j; import org.apache.maven.cli.logging.Slf4jConfiguration; import org.slf4j.ILoggerFactory; +import org.slf4j.LoggerFactory; public class MvndConfiguration implements Slf4jConfiguration { @Override @@ -43,7 +44,7 @@ public void setRootLoggerLevel(Level level) { @Override public void activate() { - ILoggerFactory lf = StaticLoggerBinder.getSingleton().getLoggerFactory(); + ILoggerFactory lf = LoggerFactory.getILoggerFactory(); if (lf instanceof MvndLoggerFactory) { ((MvndLoggerFactory) lf).reconfigure(); } diff --git a/logging/src/main/java/org/slf4j/impl/MvndDaemonLogger.java b/logging/src/main/java/org/mvndaemon/mvnd/logging/slf4j/MvndDaemonLogger.java similarity index 69% rename from logging/src/main/java/org/slf4j/impl/MvndDaemonLogger.java rename to logging/src/main/java/org/mvndaemon/mvnd/logging/slf4j/MvndDaemonLogger.java index 02977aea4..e4c1d6e63 100644 --- a/logging/src/main/java/org/slf4j/impl/MvndDaemonLogger.java +++ b/logging/src/main/java/org/mvndaemon/mvnd/logging/slf4j/MvndDaemonLogger.java @@ -16,7 +16,7 @@ * specific language governing permissions and limitations * under the License. */ -package org.slf4j.impl; +package org.mvndaemon.mvnd.logging.slf4j; import java.io.PrintStream; import java.io.PrintWriter; @@ -25,6 +25,10 @@ import java.time.format.DateTimeFormatter; import java.time.format.DateTimeFormatterBuilder; +import org.slf4j.Marker; +import org.slf4j.event.Level; +import org.slf4j.helpers.MessageFormatter; + public class MvndDaemonLogger extends MvndBaseLogger { final DateTimeFormatter dateTimeFormatter = @@ -37,32 +41,35 @@ public MvndDaemonLogger(String name) { } @Override - protected void doLog(int level, String message, Throwable t) { - StringWriter sw = new StringWriter(); - PrintWriter pw = new PrintWriter(sw); - pw.append(dateTimeFormatter.format(LocalTime.now())); - pw.append(" "); - switch (level) { + protected String renderLevel(int levelInt) { + switch (levelInt) { case LOG_LEVEL_ERROR: - pw.append("E"); - break; + return "E"; case LOG_LEVEL_WARN: - pw.append("W"); - break; + return "W"; case LOG_LEVEL_INFO: - pw.append("I"); - break; + return "I"; case LOG_LEVEL_DEBUG: - pw.append("D"); - break; + return "D"; case LOG_LEVEL_TRACE: - pw.append("T"); - break; + return "T"; } + throw new IllegalStateException("Unrecognized level [" + levelInt + "]"); + } + + @Override + protected void handleNormalizedLoggingCall( + Level level, Marker marker, String messagePattern, Object[] arguments, Throwable throwable) { + StringWriter sw = new StringWriter(); + PrintWriter pw = new PrintWriter(sw); + pw.append(dateTimeFormatter.format(LocalTime.now())); + pw.append(" "); + pw.append(renderLevel(level.toInt())); pw.append(" "); + String message = MessageFormatter.basicArrayFormat(messagePattern, arguments); pw.append(message); - if (t != null) { - t.printStackTrace(pw); + if (throwable != null) { + throwable.printStackTrace(pw); } PrintStream printStream = MvndSimpleLogger.CONFIG_PARAMS.outputChoice.getTargetPrintStream(); printStream.println(sw); diff --git a/logging/src/main/java/org/slf4j/impl/MvndFailOnSeverityLogger.java b/logging/src/main/java/org/mvndaemon/mvnd/logging/slf4j/MvndFailOnSeverityLogger.java similarity index 99% rename from logging/src/main/java/org/slf4j/impl/MvndFailOnSeverityLogger.java rename to logging/src/main/java/org/mvndaemon/mvnd/logging/slf4j/MvndFailOnSeverityLogger.java index 27b43fd68..8d0704d30 100644 --- a/logging/src/main/java/org/slf4j/impl/MvndFailOnSeverityLogger.java +++ b/logging/src/main/java/org/mvndaemon/mvnd/logging/slf4j/MvndFailOnSeverityLogger.java @@ -16,7 +16,7 @@ * specific language governing permissions and limitations * under the License. */ -package org.slf4j.impl; +package org.mvndaemon.mvnd.logging.slf4j; import org.apache.maven.logwrapper.LogLevelRecorder; import org.slf4j.event.Level; diff --git a/logging/src/main/java/org/slf4j/impl/MvndLoggerFactory.java b/logging/src/main/java/org/mvndaemon/mvnd/logging/slf4j/MvndLoggerFactory.java similarity index 98% rename from logging/src/main/java/org/slf4j/impl/MvndLoggerFactory.java rename to logging/src/main/java/org/mvndaemon/mvnd/logging/slf4j/MvndLoggerFactory.java index 7de5cba31..0767d68df 100644 --- a/logging/src/main/java/org/slf4j/impl/MvndLoggerFactory.java +++ b/logging/src/main/java/org/mvndaemon/mvnd/logging/slf4j/MvndLoggerFactory.java @@ -16,7 +16,7 @@ * specific language governing permissions and limitations * under the License. */ -package org.slf4j.impl; +package org.mvndaemon.mvnd.logging.slf4j; import java.util.Optional; import java.util.concurrent.ConcurrentHashMap; diff --git a/logging/src/main/java/org/mvndaemon/mvnd/logging/slf4j/MvndServiceProvider.java b/logging/src/main/java/org/mvndaemon/mvnd/logging/slf4j/MvndServiceProvider.java new file mode 100644 index 000000000..7bcfeeca6 --- /dev/null +++ b/logging/src/main/java/org/mvndaemon/mvnd/logging/slf4j/MvndServiceProvider.java @@ -0,0 +1,65 @@ +/* + * 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.mvndaemon.mvnd.logging.slf4j; + +import org.slf4j.ILoggerFactory; +import org.slf4j.IMarkerFactory; +import org.slf4j.helpers.BasicMDCAdapter; +import org.slf4j.helpers.BasicMarkerFactory; +import org.slf4j.spi.MDCAdapter; +import org.slf4j.spi.SLF4JServiceProvider; + +public class MvndServiceProvider implements SLF4JServiceProvider { + + /** + * Declare the version of the SLF4J API this implementation is compiled against. + * The value of this field is modified with each major release. + */ + // to avoid constant folding by the compiler, this field must *not* be final + @SuppressWarnings({"checkstyle:StaticVariableName", "checkstyle:VisibilityModifier"}) + public static String REQUESTED_API_VERSION = "2.0.99"; // !final + + private MvndLoggerFactory loggerFactory = new MvndLoggerFactory(); + private IMarkerFactory markerFactory = new BasicMarkerFactory(); + private MDCAdapter mdcAdapter = new BasicMDCAdapter(); + + public ILoggerFactory getLoggerFactory() { + return loggerFactory; + } + + @Override + public IMarkerFactory getMarkerFactory() { + return markerFactory; + } + + @Override + public MDCAdapter getMDCAdapter() { + return mdcAdapter; + } + + @Override + public String getRequestedApiVersion() { + return REQUESTED_API_VERSION; + } + + @Override + public void initialize() { + // already initialized + } +} diff --git a/logging/src/main/java/org/slf4j/impl/MvndSimpleLogger.java b/logging/src/main/java/org/mvndaemon/mvnd/logging/slf4j/MvndSimpleLogger.java similarity index 61% rename from logging/src/main/java/org/slf4j/impl/MvndSimpleLogger.java rename to logging/src/main/java/org/mvndaemon/mvnd/logging/slf4j/MvndSimpleLogger.java index f2041a53f..7952dcda0 100644 --- a/logging/src/main/java/org/slf4j/impl/MvndSimpleLogger.java +++ b/logging/src/main/java/org/mvndaemon/mvnd/logging/slf4j/MvndSimpleLogger.java @@ -16,15 +16,14 @@ * specific language governing permissions and limitations * under the License. */ -package org.slf4j.impl; +package org.mvndaemon.mvnd.logging.slf4j; -import java.util.Date; import java.util.function.Consumer; -import org.apache.maven.shared.utils.logging.MessageBuilder; -import org.apache.maven.shared.utils.logging.MessageUtils; +import org.apache.maven.api.services.MessageBuilder; +import org.apache.maven.jline.MessageUtils; -import static org.apache.maven.shared.utils.logging.MessageUtils.level; +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 @@ -34,12 +33,12 @@ */ public class MvndSimpleLogger extends MvndBaseLogger { + /* static final String TID_PREFIX = "tid="; static long START_TIME = System.currentTimeMillis(); static boolean INITIALIZED = false; - static final SimpleLoggerConfiguration CONFIG_PARAMS = new SimpleLoggerConfiguration(); static void lazyInit() { if (INITIALIZED) { @@ -55,6 +54,8 @@ static void init() { CONFIG_PARAMS.init(); } + */ + static Consumer LOG_SINK; public static void setLogSink(Consumer logSink) { @@ -64,72 +65,20 @@ public static void setLogSink(Consumer logSink) { /** The short name of this simple log instance */ private transient String shortLogName = null; + private String traceRenderedLevel; + private String debugRenderedLevel; + private String infoRenderedLevel; + private String warnRenderedLevel; + private String errorRenderedLevel; + MvndSimpleLogger(String name) { super(name); configure(CONFIG_PARAMS.defaultLogLevel); } - String recursivelyComputeLevelString() { - String tempName = name; - String levelString = null; - int indexOfLastDot = tempName.length(); - while ((levelString == null) && (indexOfLastDot > -1)) { - tempName = tempName.substring(0, indexOfLastDot); - levelString = CONFIG_PARAMS.getStringProperty(SimpleLogger.LOG_KEY_PREFIX + tempName, null); - indexOfLastDot = tempName.lastIndexOf("."); - } - return levelString; - } - @Override - protected void doLog(int level, String message, Throwable t) { - StringBuilder buf = new StringBuilder(32); - - // Append date-time if so configured - if (CONFIG_PARAMS.showDateTime) { - if (CONFIG_PARAMS.dateFormatter != null) { - buf.append(getFormattedDate()); - buf.append(' '); - } else { - buf.append(System.currentTimeMillis() - START_TIME); - buf.append(' '); - } - } - - // Append current thread name if so configured - if (CONFIG_PARAMS.showThreadName) { - buf.append('['); - buf.append(Thread.currentThread().getName()); - buf.append("] "); - } - - if (CONFIG_PARAMS.showThreadId) { - buf.append(TID_PREFIX); - buf.append(Thread.currentThread().getId()); - buf.append(' '); - } - - if (CONFIG_PARAMS.levelInBrackets) buf.append('['); - - // Append a readable representation of the log level - String levelStr = renderLevel(level); - buf.append(levelStr); - if (CONFIG_PARAMS.levelInBrackets) buf.append(']'); - buf.append(' '); - - // Append the name of the log instance if so configured - if (CONFIG_PARAMS.showShortLogName) { - if (shortLogName == null) shortLogName = computeShortName(); - buf.append(String.valueOf(shortLogName)).append(" - "); - } else if (CONFIG_PARAMS.showLogName) { - buf.append(String.valueOf(name)).append(" - "); - } - - // Append the message - buf.append(message); - + void write(StringBuilder buf, Throwable t) { writeThrowable(t, buf); - Consumer sink = LOG_SINK; if (sink != null) { sink.accept(buf.toString()); @@ -138,28 +87,26 @@ protected void doLog(int level, String message, Throwable t) { } } - protected String getFormattedDate() { - Date now = new Date(); - return CONFIG_PARAMS.dateFormatter.format(now); - } - - private String computeShortName() { - return name.substring(name.lastIndexOf(".") + 1); - } - protected String renderLevel(int level) { + if (traceRenderedLevel == null) { + traceRenderedLevel = builder().trace("TRACE").build(); + debugRenderedLevel = builder().debug("DEBUG").build(); + infoRenderedLevel = builder().info("INFO").build(); + warnRenderedLevel = builder().warning("WARNING").build(); + errorRenderedLevel = builder().error("ERROR").build(); + } switch (level) { case LOG_LEVEL_TRACE: - return level().debug("TRACE").toString(); + return traceRenderedLevel; case LOG_LEVEL_DEBUG: - return level().debug("DEBUG").toString(); + return debugRenderedLevel; case LOG_LEVEL_INFO: - return level().info("INFO").toString(); + return infoRenderedLevel; case LOG_LEVEL_WARN: - return level().warning("WARNING").toString(); + return warnRenderedLevel; case LOG_LEVEL_ERROR: default: - return level().error("ERROR").toString(); + return errorRenderedLevel; } } @@ -167,13 +114,14 @@ protected void writeThrowable(Throwable t, StringBuilder sb) { if (t == null) { return; } - MessageBuilder builder = MessageUtils.buffer(sb); + MessageBuilder builder = MessageUtils.builder(); builder.failure(t.getClass().getName()); if (t.getMessage() != null) { builder.a(": "); builder.failure(t.getMessage()); } builder.newline(); + sb.append(builder); printStackTrace(t, builder, ""); } diff --git a/logging/src/main/java/org/mvndaemon/mvnd/logging/slf4j/OutputChoice.java b/logging/src/main/java/org/mvndaemon/mvnd/logging/slf4j/OutputChoice.java new file mode 100644 index 000000000..98a0d9815 --- /dev/null +++ b/logging/src/main/java/org/mvndaemon/mvnd/logging/slf4j/OutputChoice.java @@ -0,0 +1,75 @@ +/* + * 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.mvndaemon.mvnd.logging.slf4j; + +import java.io.PrintStream; + +/** + * This class encapsulates the user's choice of output target. + * + * @author Ceki Gülcü + * + */ +class OutputChoice { + + enum OutputChoiceType { + SYS_OUT, + CACHED_SYS_OUT, + SYS_ERR, + CACHED_SYS_ERR, + FILE; + } + + final OutputChoiceType outputChoiceType; + final PrintStream targetPrintStream; + + OutputChoice(OutputChoiceType outputChoiceType) { + if (outputChoiceType == OutputChoiceType.FILE) { + throw new IllegalArgumentException(); + } + this.outputChoiceType = outputChoiceType; + if (outputChoiceType == OutputChoiceType.CACHED_SYS_OUT) { + this.targetPrintStream = System.out; + } else if (outputChoiceType == OutputChoiceType.CACHED_SYS_ERR) { + this.targetPrintStream = System.err; + } else { + this.targetPrintStream = null; + } + } + + OutputChoice(PrintStream printStream) { + this.outputChoiceType = OutputChoiceType.FILE; + this.targetPrintStream = printStream; + } + + PrintStream getTargetPrintStream() { + switch (outputChoiceType) { + case SYS_OUT: + return System.out; + case SYS_ERR: + return System.err; + case CACHED_SYS_ERR: + case CACHED_SYS_OUT: + case FILE: + return targetPrintStream; + default: + throw new IllegalArgumentException(); + } + } +} diff --git a/logging/src/main/java/org/mvndaemon/mvnd/logging/slf4j/SimpleLoggerConfiguration.java b/logging/src/main/java/org/mvndaemon/mvnd/logging/slf4j/SimpleLoggerConfiguration.java new file mode 100644 index 000000000..0413149fa --- /dev/null +++ b/logging/src/main/java/org/mvndaemon/mvnd/logging/slf4j/SimpleLoggerConfiguration.java @@ -0,0 +1,207 @@ +/* + * 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.mvndaemon.mvnd.logging.slf4j; + +import java.io.FileNotFoundException; +import java.io.FileOutputStream; +import java.io.InputStream; +import java.io.PrintStream; +import java.security.AccessController; +import java.security.PrivilegedAction; +import java.text.DateFormat; +import java.text.SimpleDateFormat; +import java.util.Properties; + +import org.mvndaemon.mvnd.logging.slf4j.OutputChoice.OutputChoiceType; +import org.slf4j.helpers.Reporter; + +/** + * This class holds configuration values for {@link MvndBaseLogger}. The + * values are computed at runtime. See {@link MvndBaseLogger} documentation for + * more information. + * + * + * @author Ceki Gülcü + * @author Scott Sanders + * @author Rod Waldhoff + * @author Robert Burrell Donkin + * @author Cédrik LIME + * + * @since 1.7.25 + */ +public class SimpleLoggerConfiguration { + + private static final String CONFIGURATION_FILE = "simplelogger.properties"; + + static int DEFAULT_LOG_LEVEL_DEFAULT = MvndBaseLogger.LOG_LEVEL_INFO; + int defaultLogLevel = DEFAULT_LOG_LEVEL_DEFAULT; + + private static final boolean SHOW_DATE_TIME_DEFAULT = false; + boolean showDateTime = SHOW_DATE_TIME_DEFAULT; + + private static final String DATE_TIME_FORMAT_STR_DEFAULT = null; + private static String dateTimeFormatStr = DATE_TIME_FORMAT_STR_DEFAULT; + + DateFormat dateFormatter = null; + + private static final boolean SHOW_THREAD_NAME_DEFAULT = true; + boolean showThreadName = SHOW_THREAD_NAME_DEFAULT; + + /** + * See https://jira.qos.ch/browse/SLF4J-499 + * @since 1.7.33 and 2.0.0-alpha6 + */ + private static final boolean SHOW_THREAD_ID_DEFAULT = false; + + boolean showThreadId = SHOW_THREAD_ID_DEFAULT; + + static final boolean SHOW_LOG_NAME_DEFAULT = true; + boolean showLogName = SHOW_LOG_NAME_DEFAULT; + + private static final boolean SHOW_SHORT_LOG_NAME_DEFAULT = false; + boolean showShortLogName = SHOW_SHORT_LOG_NAME_DEFAULT; + + private static final boolean LEVEL_IN_BRACKETS_DEFAULT = false; + boolean levelInBrackets = LEVEL_IN_BRACKETS_DEFAULT; + + private static final String LOG_FILE_DEFAULT = "System.err"; + private String logFile = LOG_FILE_DEFAULT; + OutputChoice outputChoice = null; + + private static final boolean CACHE_OUTPUT_STREAM_DEFAULT = false; + private boolean cacheOutputStream = CACHE_OUTPUT_STREAM_DEFAULT; + + private static final String WARN_LEVELS_STRING_DEFAULT = "WARN"; + String warnLevelString = WARN_LEVELS_STRING_DEFAULT; + + private final Properties properties = new Properties(); + + void init() { + loadProperties(); + + String defaultLogLevelString = getStringProperty(MvndBaseLogger.DEFAULT_LOG_LEVEL_KEY, null); + if (defaultLogLevelString != null) defaultLogLevel = stringToLevel(defaultLogLevelString); + + showLogName = + getBooleanProperty(MvndBaseLogger.SHOW_LOG_NAME_KEY, SimpleLoggerConfiguration.SHOW_LOG_NAME_DEFAULT); + showShortLogName = getBooleanProperty(MvndBaseLogger.SHOW_SHORT_LOG_NAME_KEY, SHOW_SHORT_LOG_NAME_DEFAULT); + showDateTime = getBooleanProperty(MvndBaseLogger.SHOW_DATE_TIME_KEY, SHOW_DATE_TIME_DEFAULT); + showThreadName = getBooleanProperty(MvndBaseLogger.SHOW_THREAD_NAME_KEY, SHOW_THREAD_NAME_DEFAULT); + showThreadId = getBooleanProperty(MvndBaseLogger.SHOW_THREAD_ID_KEY, SHOW_THREAD_ID_DEFAULT); + dateTimeFormatStr = getStringProperty(MvndBaseLogger.DATE_TIME_FORMAT_KEY, DATE_TIME_FORMAT_STR_DEFAULT); + levelInBrackets = getBooleanProperty(MvndBaseLogger.LEVEL_IN_BRACKETS_KEY, LEVEL_IN_BRACKETS_DEFAULT); + warnLevelString = getStringProperty(MvndBaseLogger.WARN_LEVEL_STRING_KEY, WARN_LEVELS_STRING_DEFAULT); + + logFile = getStringProperty(MvndBaseLogger.LOG_FILE_KEY, logFile); + + cacheOutputStream = + getBooleanProperty(MvndBaseLogger.CACHE_OUTPUT_STREAM_STRING_KEY, CACHE_OUTPUT_STREAM_DEFAULT); + outputChoice = computeOutputChoice(logFile, cacheOutputStream); + + if (dateTimeFormatStr != null) { + try { + dateFormatter = new SimpleDateFormat(dateTimeFormatStr); + } catch (IllegalArgumentException e) { + Reporter.error("Bad date format in " + CONFIGURATION_FILE + "; will output relative time", e); + } + } + } + + private void loadProperties() { + // Add props from the resource simplelogger.properties + InputStream in = AccessController.doPrivileged((PrivilegedAction) () -> { + ClassLoader threadCL = Thread.currentThread().getContextClassLoader(); + if (threadCL != null) { + return threadCL.getResourceAsStream(CONFIGURATION_FILE); + } else { + return ClassLoader.getSystemResourceAsStream(CONFIGURATION_FILE); + } + }); + if (null != in) { + try { + properties.load(in); + } catch (java.io.IOException e) { + // ignored + } finally { + try { + in.close(); + } catch (java.io.IOException e) { + // ignored + } + } + } + } + + String getStringProperty(String name, String defaultValue) { + String prop = getStringProperty(name); + return (prop == null) ? defaultValue : prop; + } + + boolean getBooleanProperty(String name, boolean defaultValue) { + String prop = getStringProperty(name); + return (prop == null) ? defaultValue : "true".equalsIgnoreCase(prop); + } + + String getStringProperty(String name) { + String prop = null; + try { + prop = System.getProperty(name); + } catch (SecurityException e) { + ; // Ignore + } + return (prop == null) ? properties.getProperty(name) : prop; + } + + static int stringToLevel(String levelStr) { + if ("trace".equalsIgnoreCase(levelStr)) { + return MvndBaseLogger.LOG_LEVEL_TRACE; + } else if ("debug".equalsIgnoreCase(levelStr)) { + return MvndBaseLogger.LOG_LEVEL_DEBUG; + } else if ("info".equalsIgnoreCase(levelStr)) { + return MvndBaseLogger.LOG_LEVEL_INFO; + } else if ("warn".equalsIgnoreCase(levelStr)) { + return MvndBaseLogger.LOG_LEVEL_WARN; + } else if ("error".equalsIgnoreCase(levelStr)) { + return MvndBaseLogger.LOG_LEVEL_ERROR; + } else if ("off".equalsIgnoreCase(levelStr)) { + return MvndBaseLogger.LOG_LEVEL_OFF; + } + // assume INFO by default + return MvndBaseLogger.LOG_LEVEL_INFO; + } + + private static OutputChoice computeOutputChoice(String logFile, boolean cacheOutputStream) { + if ("System.err".equalsIgnoreCase(logFile)) + if (cacheOutputStream) return new OutputChoice(OutputChoiceType.CACHED_SYS_ERR); + else return new OutputChoice(OutputChoiceType.SYS_ERR); + else if ("System.out".equalsIgnoreCase(logFile)) { + if (cacheOutputStream) return new OutputChoice(OutputChoiceType.CACHED_SYS_OUT); + else return new OutputChoice(OutputChoiceType.SYS_OUT); + } else { + try { + FileOutputStream fos = new FileOutputStream(logFile); + PrintStream printStream = new PrintStream(fos); + return new OutputChoice(printStream); + } catch (FileNotFoundException e) { + Reporter.error("Could not open [" + logFile + "]. Defaulting to System.err", e); + return new OutputChoice(OutputChoiceType.SYS_ERR); + } + } + } +} diff --git a/logging/src/main/java/org/mvndaemon/mvnd/logging/smart/ProjectBuildLogAppender.java b/logging/src/main/java/org/mvndaemon/mvnd/logging/smart/ProjectBuildLogAppender.java index 15177c7da..4f908e708 100644 --- a/logging/src/main/java/org/mvndaemon/mvnd/logging/smart/ProjectBuildLogAppender.java +++ b/logging/src/main/java/org/mvndaemon/mvnd/logging/smart/ProjectBuildLogAppender.java @@ -18,8 +18,8 @@ */ package org.mvndaemon.mvnd.logging.smart; +import org.mvndaemon.mvnd.logging.slf4j.MvndSimpleLogger; import org.slf4j.MDC; -import org.slf4j.impl.MvndSimpleLogger; /** * Forwards log messages to the client. diff --git a/logging/src/main/java/org/slf4j/impl/MvndBaseLogger.java b/logging/src/main/java/org/slf4j/impl/MvndBaseLogger.java deleted file mode 100644 index 5e44cefbd..000000000 --- a/logging/src/main/java/org/slf4j/impl/MvndBaseLogger.java +++ /dev/null @@ -1,299 +0,0 @@ -/* - * 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.impl; - -import org.slf4j.event.LoggingEvent; -import org.slf4j.helpers.FormattingTuple; -import org.slf4j.helpers.MarkerIgnoringBase; -import org.slf4j.helpers.MessageFormatter; -import org.slf4j.spi.LocationAwareLogger; - -public abstract class MvndBaseLogger extends MarkerIgnoringBase { - - protected static final int LOG_LEVEL_TRACE = LocationAwareLogger.TRACE_INT; - protected static final int LOG_LEVEL_DEBUG = LocationAwareLogger.DEBUG_INT; - protected static final int LOG_LEVEL_INFO = LocationAwareLogger.INFO_INT; - protected static final int LOG_LEVEL_WARN = LocationAwareLogger.WARN_INT; - protected static final int LOG_LEVEL_ERROR = LocationAwareLogger.ERROR_INT; - - /** The current log level */ - protected int currentLogLevel = LOG_LEVEL_INFO; - - public MvndBaseLogger(String name) { - this.name = name; - } - - protected void formatAndLog(int level, String format, Object arg1, Object arg2) { - if (!isLevelEnabled(level)) { - return; - } - FormattingTuple tp = MessageFormatter.format(format, arg1, arg2); - log(level, tp.getMessage(), tp.getThrowable()); - } - - protected void formatAndLog(int level, String format, Object... arguments) { - if (!isLevelEnabled(level)) { - return; - } - FormattingTuple tp = MessageFormatter.arrayFormat(format, arguments); - log(level, tp.getMessage(), tp.getThrowable()); - } - - protected void log(int level, String message, Throwable t) { - if (!isLevelEnabled(level)) { - return; - } - doLog(level, message, t); - } - - protected abstract void doLog(int level, String message, Throwable t); - - /** - * Is the given log level currently enabled? - * - * @param logLevel - * is this level enabled? - */ - protected boolean isLevelEnabled(int logLevel) { - // log level are numerically ordered so can use simple numeric - // comparison - return (logLevel >= currentLogLevel); - } - - /** Are {@code trace} messages currently enabled? */ - public boolean isTraceEnabled() { - return isLevelEnabled(LOG_LEVEL_TRACE); - } - - /** - * A simple implementation which logs messages of level TRACE according to - * the format outlined above. - */ - public void trace(String msg) { - log(LOG_LEVEL_TRACE, msg, null); - } - - /** - * Perform single parameter substitution before logging the message of level - * TRACE according to the format outlined above. - */ - public void trace(String format, Object param1) { - formatAndLog(LOG_LEVEL_TRACE, format, param1, null); - } - - /** - * Perform double parameter substitution before logging the message of level - * TRACE according to the format outlined above. - */ - public void trace(String format, Object param1, Object param2) { - formatAndLog(LOG_LEVEL_TRACE, format, param1, param2); - } - - /** - * Perform double parameter substitution before logging the message of level - * TRACE according to the format outlined above. - */ - public void trace(String format, Object... argArray) { - formatAndLog(LOG_LEVEL_TRACE, format, argArray); - } - - /** Log a message of level TRACE, including an exception. */ - public void trace(String msg, Throwable t) { - log(LOG_LEVEL_TRACE, msg, t); - } - - /** Are {@code debug} messages currently enabled? */ - public boolean isDebugEnabled() { - return isLevelEnabled(LOG_LEVEL_DEBUG); - } - - /** - * A simple implementation which logs messages of level DEBUG according to - * the format outlined above. - */ - public void debug(String msg) { - log(LOG_LEVEL_DEBUG, msg, null); - } - - /** - * Perform single parameter substitution before logging the message of level - * DEBUG according to the format outlined above. - */ - public void debug(String format, Object param1) { - formatAndLog(LOG_LEVEL_DEBUG, format, param1, null); - } - - /** - * Perform double parameter substitution before logging the message of level - * DEBUG according to the format outlined above. - */ - public void debug(String format, Object param1, Object param2) { - formatAndLog(LOG_LEVEL_DEBUG, format, param1, param2); - } - - /** - * Perform double parameter substitution before logging the message of level - * DEBUG according to the format outlined above. - */ - public void debug(String format, Object... argArray) { - formatAndLog(LOG_LEVEL_DEBUG, format, argArray); - } - - /** Log a message of level DEBUG, including an exception. */ - public void debug(String msg, Throwable t) { - log(LOG_LEVEL_DEBUG, msg, t); - } - - /** Are {@code info} messages currently enabled? */ - public boolean isInfoEnabled() { - return isLevelEnabled(LOG_LEVEL_INFO); - } - - /** - * A simple implementation which logs messages of level INFO according to - * the format outlined above. - */ - public void info(String msg) { - log(LOG_LEVEL_INFO, msg, null); - } - - /** - * Perform single parameter substitution before logging the message of level - * INFO according to the format outlined above. - */ - public void info(String format, Object arg) { - formatAndLog(LOG_LEVEL_INFO, format, arg, null); - } - - /** - * Perform double parameter substitution before logging the message of level - * INFO according to the format outlined above. - */ - public void info(String format, Object arg1, Object arg2) { - formatAndLog(LOG_LEVEL_INFO, format, arg1, arg2); - } - - /** - * Perform double parameter substitution before logging the message of level - * INFO according to the format outlined above. - */ - public void info(String format, Object... argArray) { - formatAndLog(LOG_LEVEL_INFO, format, argArray); - } - - /** Log a message of level INFO, including an exception. */ - public void info(String msg, Throwable t) { - log(LOG_LEVEL_INFO, msg, t); - } - - /** Are {@code warn} messages currently enabled? */ - public boolean isWarnEnabled() { - return isLevelEnabled(LOG_LEVEL_WARN); - } - - /** - * A simple implementation which always logs messages of level WARN - * according to the format outlined above. - */ - public void warn(String msg) { - log(LOG_LEVEL_WARN, msg, null); - } - - /** - * Perform single parameter substitution before logging the message of level - * WARN according to the format outlined above. - */ - public void warn(String format, Object arg) { - formatAndLog(LOG_LEVEL_WARN, format, arg, null); - } - - /** - * Perform double parameter substitution before logging the message of level - * WARN according to the format outlined above. - */ - public void warn(String format, Object arg1, Object arg2) { - formatAndLog(LOG_LEVEL_WARN, format, arg1, arg2); - } - - /** - * Perform double parameter substitution before logging the message of level - * WARN according to the format outlined above. - */ - public void warn(String format, Object... argArray) { - formatAndLog(LOG_LEVEL_WARN, format, argArray); - } - - /** Log a message of level WARN, including an exception. */ - public void warn(String msg, Throwable t) { - log(LOG_LEVEL_WARN, msg, t); - } - - /** Are {@code error} messages currently enabled? */ - public boolean isErrorEnabled() { - return isLevelEnabled(LOG_LEVEL_ERROR); - } - - /** - * A simple implementation which always logs messages of level ERROR - * according to the format outlined above. - */ - public void error(String msg) { - log(LOG_LEVEL_ERROR, msg, null); - } - - /** - * Perform single parameter substitution before logging the message of level - * ERROR according to the format outlined above. - */ - public void error(String format, Object arg) { - formatAndLog(LOG_LEVEL_ERROR, format, arg, null); - } - - /** - * Perform double parameter substitution before logging the message of level - * ERROR according to the format outlined above. - */ - public void error(String format, Object arg1, Object arg2) { - formatAndLog(LOG_LEVEL_ERROR, format, arg1, arg2); - } - - /** - * Perform double parameter substitution before logging the message of level - * ERROR according to the format outlined above. - */ - public void error(String format, Object... argArray) { - formatAndLog(LOG_LEVEL_ERROR, format, argArray); - } - - /** Log a message of level ERROR, including an exception. */ - public void error(String msg, Throwable t) { - log(LOG_LEVEL_ERROR, msg, t); - } - - public void log(LoggingEvent event) { - int levelInt = event.getLevel().toInt(); - - if (!isLevelEnabled(levelInt)) { - return; - } - FormattingTuple tp = - MessageFormatter.arrayFormat(event.getMessage(), event.getArgumentArray(), event.getThrowable()); - log(levelInt, tp.getMessage(), event.getThrowable()); - } -} diff --git a/logging/src/main/java/org/slf4j/impl/StaticLoggerBinder.java b/logging/src/main/java/org/slf4j/impl/StaticLoggerBinder.java deleted file mode 100644 index 2ebf87ba2..000000000 --- a/logging/src/main/java/org/slf4j/impl/StaticLoggerBinder.java +++ /dev/null @@ -1,82 +0,0 @@ -/* - * 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.impl; - -import org.slf4j.ILoggerFactory; -import org.slf4j.spi.LoggerFactoryBinder; - -/** - * SLF4J LoggerFactoryBinder implementation using MavenSimpleLogger. - * This class is part of the required classes used to specify an - * SLF4J logger provider implementation. - * - * @since 3.5.1 - */ -public final class StaticLoggerBinder implements LoggerFactoryBinder { - /** - * Declare the version of the SLF4J API this implementation is compiled - * against. The value of this field is usually modified with each release. - */ - // to avoid constant folding by the compiler, this field must *not* be final - @SuppressWarnings({"checkstyle:staticvariablename", "checkstyle:visibilitymodifier"}) - public static String REQUESTED_API_VERSION = "1.7.25"; // !final - - private static final String LOGGER_FACTORY_CLASS_STR = MvndLoggerFactory.class.getName(); - - /** - * The unique instance of this class. - */ - private static final StaticLoggerBinder SINGLETON = new StaticLoggerBinder(); - - /** - * The ILoggerFactory instance returned by the {@link #getLoggerFactory} - * method should always be the same object - */ - private final ILoggerFactory loggerFactory; - - /** - * Private constructor to prevent instantiation - */ - private StaticLoggerBinder() { - loggerFactory = new MvndLoggerFactory(); - } - - /** - * Returns the singleton of this class. - */ - public static StaticLoggerBinder getSingleton() { - return SINGLETON; - } - - /** - * Returns the factory. - */ - @Override - public ILoggerFactory getLoggerFactory() { - return loggerFactory; - } - - /** - * Returns the class name. - */ - @Override - public String getLoggerFactoryClassStr() { - return LOGGER_FACTORY_CLASS_STR; - } -} diff --git a/logging/src/main/java/org/slf4j/impl/StaticMDCBinder.java b/logging/src/main/java/org/slf4j/impl/StaticMDCBinder.java deleted file mode 100644 index c264b1d1b..000000000 --- a/logging/src/main/java/org/slf4j/impl/StaticMDCBinder.java +++ /dev/null @@ -1,57 +0,0 @@ -/* - * 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.impl; - -import org.slf4j.helpers.BasicMDCAdapter; -import org.slf4j.spi.MDCAdapter; - -/** - * This implementation is bound to {@link BasicMDCAdapter}. - */ -public class StaticMDCBinder { - - /** - * The unique instance of this class. - */ - public static final StaticMDCBinder SINGLETON = new StaticMDCBinder(); - - private StaticMDCBinder() {} - - /** - * Return the singleton of this class. - * - * @return the StaticMDCBinder singleton - * @since 1.7.14 - */ - public static final StaticMDCBinder getSingleton() { - return SINGLETON; - } - - /** - * Currently this method always returns an instance of - * {@link StaticMDCBinder}. - */ - public MDCAdapter getMDCA() { - return new BasicMDCAdapter(); - } - - public String getMDCAdapterClassStr() { - return BasicMDCAdapter.class.getName(); - } -} diff --git a/logging/src/main/resources/META-INF/maven/slf4j-configuration.properties b/logging/src/main/resources/META-INF/maven/slf4j-configuration.properties index ee6529b86..5e922b771 100644 --- a/logging/src/main/resources/META-INF/maven/slf4j-configuration.properties +++ b/logging/src/main/resources/META-INF/maven/slf4j-configuration.properties @@ -17,4 +17,4 @@ # key = Slf4j effective logger factory implementation # value = corresponding o.a.m.cli.logging.Slf4jConfiguration class -org.slf4j.impl.MvndLoggerFactory org.slf4j.impl.MvndConfiguration +org.mvndaemon.mvnd.logging.slf4j.MvndLoggerFactory org.mvndaemon.mvnd.logging.slf4j.MvndConfiguration diff --git a/logging/src/main/resources/META-INF/services/org.slf4j.spi.SLF4JServiceProvider b/logging/src/main/resources/META-INF/services/org.slf4j.spi.SLF4JServiceProvider new file mode 100644 index 000000000..24253555f --- /dev/null +++ b/logging/src/main/resources/META-INF/services/org.slf4j.spi.SLF4JServiceProvider @@ -0,0 +1 @@ +org.mvndaemon.mvnd.logging.slf4j.MvndServiceProvider \ No newline at end of file diff --git a/pom.xml b/pom.xml index d29537a98..831551727 100644 --- a/pom.xml +++ b/pom.xml @@ -65,6 +65,8 @@ UTF-8 + 17 + 17 17 17 2024-04-23T19:44:34Z @@ -82,11 +84,11 @@ 4.0.21 1.0 2.4.1 - 3.25.1 - 4.0.0-alpha-8 + 3.26.1 + 4.0.0-beta-1-SNAPSHOT 1.9.18 - 1.7.36 + 2.0.11 0.9.0.M2 @@ -161,6 +163,11 @@ maven-embedder ${maven.version} + + org.apache.maven + maven-jline + ${maven.version} + org.apache.maven apache-maven @@ -261,6 +268,11 @@ ${sisu.version} + + org.jline + jline + ${jline.version} + org.jline jline-terminal @@ -272,9 +284,9 @@ ${jline.version} - org.fusesource.jansi - jansi - ${jansi.version} + org.jline + jline-terminal-jni + ${jline.version} @@ -354,6 +366,7 @@ src/test/projects/**/.project src/test/projects/**/.settings/** src/test/projects/**/target/** + **/META-INF/services/** @@ -453,7 +466,7 @@ [17,) - ${maven.compiler.release} + ${maven-dist.required.jdk} test