diff --git a/core/src/main/java/org/wildfly/plugins/core/bootablejar/BootLoggingConfiguration.java b/core/src/main/java/org/wildfly/plugins/core/bootablejar/BootLoggingConfiguration.java index a00d567a..28f3bda3 100644 --- a/core/src/main/java/org/wildfly/plugins/core/bootablejar/BootLoggingConfiguration.java +++ b/core/src/main/java/org/wildfly/plugins/core/bootablejar/BootLoggingConfiguration.java @@ -30,6 +30,7 @@ import org.jboss.dmr.ModelNode; import org.jboss.dmr.ModelType; import org.jboss.dmr.Property; +import org.jboss.logging.Logger; /** * Generates a new {@code logging.properties} file based on the logging subsystem model. @@ -54,9 +55,9 @@ * * @author James R. Perkins */ -// @TODO, we can't use AbstractLogEnabled, it is not in the maven plugin classloader. -public class BootLoggingConfiguration { // extends AbstractLogEnabled { +public class BootLoggingConfiguration { + private static final Logger LOGGER = Logger.getLogger(BootLoggingConfiguration.class); private static final Pattern SIZE_PATTERN = Pattern.compile("(\\d+)([kKmMgGbBtT])?"); private static final String NEW_LINE = System.lineSeparator(); @@ -164,11 +165,8 @@ public void generate(final Path configDir, final ModelControllerClient client) t if (properties.containsKey(key)) { requiredProperties.put(key, properties.get(key)); } else { - // @TODO, we can't use AbstractLogEnabled, it is not in the maven plugin classloader. - // getLogger().warn(String.format("The value for the expression \"%s\" could not be resolved " + - // "and may not be set at boot if no default value is available.", entry.getValue())); - System.err.println(String.format("The value for the expression \"%s\" could not be resolved " - + "and may not be set at boot if no default value is available.", entry.getValue())); + LOGGER.warnf("The value for the expression \"%s\" could not be resolved " + + "and may not be set at boot if no default value is available.", entry.getValue()); } iter.remove(); } @@ -829,12 +827,9 @@ private void resolveRelativeTo(final ModelNode pathModel, final String relativeT for (Expression expression : expressions) { for (String key : expression.getKeys()) { if (!properties.containsKey(key)) { - // @TODO, we can't use AbstractLogEnabled, it is not in the maven plugin classloader. - // getLogger().warn(String.format("The path %s is an undefined property. If not set at boot time - // unexpected results may occur.", pathEntry.asString())); - System.err.println(String.format( + LOGGER.warnf( "The path %s is an undefined property. If not set at boot time unexpected results may occur.", - pathEntry.asString())); + pathEntry.asString()); } else { // We use the property name and value directly rather than referencing the path usedProperties.put(key, properties.get(key)); diff --git a/core/src/main/java/org/wildfly/plugins/core/bootablejar/BootableJarSupport.java b/core/src/main/java/org/wildfly/plugins/core/bootablejar/BootableJarSupport.java index c29f3a75..e037ef43 100644 --- a/core/src/main/java/org/wildfly/plugins/core/bootablejar/BootableJarSupport.java +++ b/core/src/main/java/org/wildfly/plugins/core/bootablejar/BootableJarSupport.java @@ -26,6 +26,7 @@ import org.jboss.galleon.universe.maven.repo.MavenRepoManager; import org.jboss.galleon.util.IoUtils; import org.jboss.galleon.util.ZipUtils; +import org.jboss.logging.Logger; import org.wildfly.plugins.core.cli.CLIForkedBootConfigGenerator; import org.wildfly.plugins.core.cli.ForkedCLIUtil; @@ -50,7 +51,7 @@ public class BootableJarSupport { */ public static void packageBootableJar(Path targetJarFile, Path target, GalleonProvisioningConfig config, Path serverHome, MavenRepoManager resolver, - MessageWriter writer, Log log) throws Exception { + MessageWriter writer, Logger log) throws Exception { Path contentRootDir = target.resolve("bootable-jar-build-artifacts"); if (Files.exists(contentRootDir)) { IoUtils.recursiveDelete(contentRootDir); @@ -109,7 +110,8 @@ private static void cleanupServer(Path jbossHome) throws IOException { Files.deleteIfExists(jbossHome.resolve("README.txt")); } - public static ScannedArtifacts scanArtifacts(Provisioning pm, GalleonProvisioningConfig config, Log log) throws Exception { + public static ScannedArtifacts scanArtifacts(Provisioning pm, GalleonProvisioningConfig config, Logger log) + throws Exception { Set cliArtifacts = new HashSet<>(); MavenArtifact jbossModules = null; MavenArtifact bootArtifact = null; diff --git a/core/src/main/java/org/wildfly/plugins/core/bootablejar/Log.java b/core/src/main/java/org/wildfly/plugins/core/bootablejar/Log.java deleted file mode 100644 index e49e8adf..00000000 --- a/core/src/main/java/org/wildfly/plugins/core/bootablejar/Log.java +++ /dev/null @@ -1,21 +0,0 @@ -/* - * Copyright The WildFly Authors - * SPDX-License-Identifier: Apache-2.0 - */ -package org.wildfly.plugins.core.bootablejar; - -/** - * - * @author jdenise - */ -public interface Log { - - void warn(String msg); - - void debug(String msg); - - void error(String msg); - - void info(String msg); - -} diff --git a/core/src/main/java/org/wildfly/plugins/core/cli/ForkedCLIUtil.java b/core/src/main/java/org/wildfly/plugins/core/cli/ForkedCLIUtil.java index f5eb9788..b482d540 100644 --- a/core/src/main/java/org/wildfly/plugins/core/cli/ForkedCLIUtil.java +++ b/core/src/main/java/org/wildfly/plugins/core/cli/ForkedCLIUtil.java @@ -21,7 +21,7 @@ import org.jboss.galleon.BaseErrors; import org.jboss.galleon.ProvisioningException; -import org.wildfly.plugins.core.bootablejar.Log; +import org.jboss.logging.Logger; /** * @@ -40,7 +40,7 @@ private static String getJavaCmd() { return javaCmd == null ? javaCmd = Paths.get(getJavaHome()).resolve("bin").resolve("java").toString() : javaCmd; } - public static void fork(Log log, String[] artifacts, Class clazz, Path home, Path output, String... args) + public static void fork(Logger log, String[] artifacts, Class clazz, Path home, Path output, String... args) throws Exception { // prepare the classpath final StringBuilder cp = new StringBuilder(); diff --git a/plugin/src/main/java/org/wildfly/plugin/common/AbstractServerConnection.java b/plugin/src/main/java/org/wildfly/plugin/common/AbstractServerConnection.java index ec11390a..c05cd4e5 100644 --- a/plugin/src/main/java/org/wildfly/plugin/common/AbstractServerConnection.java +++ b/plugin/src/main/java/org/wildfly/plugin/common/AbstractServerConnection.java @@ -20,7 +20,6 @@ import org.apache.maven.settings.crypto.SettingsDecryptionResult; import org.jboss.as.controller.client.ModelControllerClient; import org.jboss.as.controller.client.ModelControllerClientConfiguration; -import org.wildfly.security.manager.WildFlySecurityManager; /** * The default implementation for connecting to a running WildFly instance @@ -39,8 +38,11 @@ public abstract class AbstractServerConnection extends AbstractMojo { public static final String DEBUG_MESSAGE_SETTINGS_HAS_ID = "Found the server's id in the settings.xml file"; static { - // Ensure jboss-logging binds to slf4j - WildFlySecurityManager.setPropertyPrivileged("org.jboss.logging.provider", "slf4j"); + // This is odd, but if not set we should set the JBoss Logging provider to slf4j as that is what Maven uses + final String provider = System.getProperty("org.jboss.logging.provider"); + if (provider == null || provider.isBlank()) { + System.setProperty("org.jboss.logging.provider", "slf4j"); + } } /** diff --git a/plugin/src/main/java/org/wildfly/plugin/common/MavenJBossLogger.java b/plugin/src/main/java/org/wildfly/plugin/common/MavenJBossLogger.java new file mode 100644 index 00000000..bbe7a2d4 --- /dev/null +++ b/plugin/src/main/java/org/wildfly/plugin/common/MavenJBossLogger.java @@ -0,0 +1,100 @@ +/* + * Copyright The WildFly Authors + * SPDX-License-Identifier: Apache-2.0 + */ + +package org.wildfly.plugin.common; + +import java.text.MessageFormat; + +import org.apache.maven.plugin.logging.Log; +import org.jboss.logging.Logger; + +/** + * A logger which delegates to a {@link Log}. + *

+ * For {@link #isEnabled(Level)} {@link org.jboss.logging.Logger.Level#TRACE} is ignored and + * {@link org.jboss.logging.Logger.Level#FATAL} + * is treated as an {@link Log#error(CharSequence, Throwable) error}. + *

+ *

+ * For the log methods, {@link org.jboss.logging.Logger.Level#TRACE} is treated as a {@link Log#debug(CharSequence, Throwable) + * debug} + * and {@link org.jboss.logging.Logger.Level#FATAL} is treated as {@link Log#error(CharSequence, Throwable) error}. + *

+ * + * @author James R. Perkins + */ +public class MavenJBossLogger extends Logger { + private final Log mavenLogger; + + public MavenJBossLogger(final Log mavenLogger) { + super(mavenLogger.toString()); + this.mavenLogger = mavenLogger; + } + + @Override + protected void doLog(final Level level, final String loggerClassName, final Object message, final Object[] parameters, + final Throwable thrown) { + final String msg = parameters == null ? String.valueOf(message) + : MessageFormat.format(String.valueOf(message), parameters); + doMavenLog(level, msg, thrown); + } + + @Override + protected void doLogf(final Level level, final String loggerClassName, final String format, final Object[] parameters, + final Throwable thrown) { + final String msg = String.format(format, parameters); + doMavenLog(level, msg, thrown); + } + + @Override + public boolean isEnabled(final Level level) { + switch (level) { + case DEBUG: + return mavenLogger.isDebugEnabled(); + case INFO: + return mavenLogger.isInfoEnabled(); + case WARN: + return mavenLogger.isWarnEnabled(); + case FATAL: + case ERROR: + return mavenLogger.isErrorEnabled(); + } + return false; + } + + private void doMavenLog(final Level level, final String msg, final Throwable thrown) { + switch (level) { + case TRACE: + case DEBUG: + if (thrown == null) { + mavenLogger.debug(msg); + } else { + mavenLogger.debug(msg, thrown); + } + break; + case WARN: + if (thrown == null) { + mavenLogger.warn(msg); + } else { + mavenLogger.warn(msg, thrown); + } + break; + case FATAL: + case ERROR: + if (thrown == null) { + mavenLogger.error(msg); + } else { + mavenLogger.error(msg, thrown); + } + break; + default: + if (thrown == null) { + mavenLogger.info(msg); + } else { + mavenLogger.info(msg, thrown); + } + } + } +} diff --git a/plugin/src/main/java/org/wildfly/plugin/provision/AbstractProvisionServerMojo.java b/plugin/src/main/java/org/wildfly/plugin/provision/AbstractProvisionServerMojo.java index 79375ccd..867e9236 100644 --- a/plugin/src/main/java/org/wildfly/plugin/provision/AbstractProvisionServerMojo.java +++ b/plugin/src/main/java/org/wildfly/plugin/provision/AbstractProvisionServerMojo.java @@ -53,6 +53,13 @@ * @author jfdenise */ abstract class AbstractProvisionServerMojo extends AbstractMojo { + static { + // This is odd, but if not set we should set the JBoss Logging provider to slf4j as that is what Maven uses + final String provider = System.getProperty("org.jboss.logging.provider"); + if (provider == null || provider.isBlank()) { + System.setProperty("org.jboss.logging.provider", "slf4j"); + } + } @Component RepositorySystem repoSystem; diff --git a/plugin/src/main/java/org/wildfly/plugin/provision/PackageServerMojo.java b/plugin/src/main/java/org/wildfly/plugin/provision/PackageServerMojo.java index 71df8495..e7de269c 100644 --- a/plugin/src/main/java/org/wildfly/plugin/provision/PackageServerMojo.java +++ b/plugin/src/main/java/org/wildfly/plugin/provision/PackageServerMojo.java @@ -36,13 +36,13 @@ import org.wildfly.plugin.cli.BaseCommandConfiguration; import org.wildfly.plugin.cli.CliSession; import org.wildfly.plugin.cli.OfflineCommandExecutor; +import org.wildfly.plugin.common.MavenJBossLogger; import org.wildfly.plugin.common.PropertyNames; import org.wildfly.plugin.common.StandardOutput; import org.wildfly.plugin.common.Utils; import org.wildfly.plugin.deployment.MojoDeploymentException; import org.wildfly.plugin.deployment.PackageType; import org.wildfly.plugins.core.bootablejar.BootableJarSupport; -import org.wildfly.plugins.core.bootablejar.Log; /** * Provision a server, copy extra content and deploy primary artifact if it @@ -381,29 +381,7 @@ private void packageBootableJar(Path jbossHome, GalleonProvisioningConfig active BootableJarSupport.packageBootableJar(targetJarFile, targetPath, activeConfig, jbossHome, artifactResolver, - new MvnMessageWriter(getLog()), new Log() { - @Override - public void warn(String string) { - getLog().warn(string); - } - - @Override - public void debug(String string) { - if (getLog().isDebugEnabled()) { - getLog().debug(string); - } - } - - @Override - public void error(String string) { - getLog().error(string); - } - - @Override - public void info(String string) { - getLog().info(string); - } - }); + new MvnMessageWriter(getLog()), new MavenJBossLogger(getLog())); attachJar(targetJarFile); getLog().info("Bootable JAR packaging DONE. To run the server: java -jar " + targetJarFile);