-
Notifications
You must be signed in to change notification settings - Fork 40
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Remove dependency on WildFly Maven Plugin
- Loading branch information
Showing
9 changed files
with
297 additions
and
43 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
191 changes: 191 additions & 0 deletions
191
...n/src/main/java/org/wildfly/plugins/bootablejar/maven/goals/AbstractServerConnection.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,191 @@ | ||
/* | ||
* Copyright The WildFly Authors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package org.wildfly.plugins.bootablejar.maven.goals; | ||
|
||
import java.net.URISyntaxException; | ||
import java.net.URL; | ||
|
||
import javax.inject.Inject; | ||
|
||
import org.apache.maven.plugin.AbstractMojo; | ||
import org.apache.maven.plugin.logging.Log; | ||
import org.apache.maven.plugins.annotations.Parameter; | ||
import org.apache.maven.settings.Server; | ||
import org.apache.maven.settings.Settings; | ||
import org.apache.maven.settings.crypto.DefaultSettingsDecryptionRequest; | ||
import org.apache.maven.settings.crypto.SettingsDecrypter; | ||
import org.apache.maven.settings.crypto.SettingsDecryptionResult; | ||
import org.jboss.as.controller.client.ModelControllerClient; | ||
import org.jboss.as.controller.client.ModelControllerClientConfiguration; | ||
import org.wildfly.plugin.tools.client.ToolsModelControllerClientConfiguration; | ||
|
||
/** | ||
* The default implementation for connecting to a running WildFly instance | ||
* | ||
* @author <a href="mailto:jperkins@redhat.com">James R. Perkins</a> | ||
* @author Stuart Douglas | ||
*/ | ||
public abstract class AbstractServerConnection extends AbstractMojo { | ||
|
||
public static final String DEBUG_MESSAGE_NO_CREDS = "No username and password in settings.xml file - falling back to CLI entry"; | ||
public static final String DEBUG_MESSAGE_NO_ID = "No <id> element was found in the POM - Getting credentials from CLI entry"; | ||
public static final String DEBUG_MESSAGE_NO_SERVER_SECTION = "No <server> section was found for the specified id"; | ||
public static final String DEBUG_MESSAGE_NO_SETTINGS_FILE = "No settings.xml file was found in this Mojo's execution context"; | ||
public static final String DEBUG_MESSAGE_POM_HAS_CREDS = "Getting credentials from the POM"; | ||
public static final String DEBUG_MESSAGE_SETTINGS_HAS_CREDS = "Found username and password in the settings.xml file"; | ||
public static final String DEBUG_MESSAGE_SETTINGS_HAS_ID = "Found the server's id in the settings.xml file"; | ||
|
||
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"); | ||
} | ||
} | ||
|
||
/** | ||
* The protocol used to connect to the server for management. | ||
*/ | ||
@Parameter(property = "protocol") | ||
private String protocol; | ||
|
||
/** | ||
* Specifies the host name of the server where the deployment plan should be executed. | ||
*/ | ||
@Parameter(defaultValue = "localhost", property = "hostname") | ||
private String hostname; | ||
|
||
/** | ||
* Specifies the port number the server is listening on. | ||
*/ | ||
@Parameter(defaultValue = "9990", property = "port") | ||
private int port; | ||
|
||
/** | ||
* Specifies the id of the server if the username and password is to be | ||
* retrieved from the settings.xml file | ||
*/ | ||
@Parameter(property = "id") | ||
private String id; | ||
|
||
/** | ||
* Provides a reference to the settings file. | ||
*/ | ||
@Parameter(property = "settings", readonly = true, required = true, defaultValue = "${settings}") | ||
private Settings settings; | ||
|
||
/** | ||
* Specifies the username to use if prompted to authenticate by the server. | ||
* <p/> | ||
* If no username is specified and the server requests authentication the user | ||
* will be prompted to supply the username, | ||
*/ | ||
@Parameter(property = "username") | ||
private String username; | ||
|
||
/** | ||
* Specifies the password to use if prompted to authenticate by the server. | ||
* <p/> | ||
* If no password is specified and the server requests authentication the user | ||
* will be prompted to supply the password, | ||
*/ | ||
@Parameter(property = "password") | ||
private String password; | ||
|
||
/** | ||
* The timeout, in seconds, to wait for a management connection. | ||
*/ | ||
@Parameter(property = "timeout", defaultValue = "60") | ||
protected int timeout; | ||
|
||
/** | ||
* A URL which points to the authentication configuration ({@code wildfly-config.xml}) the client uses to | ||
* authenticate with the server. | ||
*/ | ||
@Parameter(alias = "authentication-config", property = "auth") | ||
private URL authenticationConfig; | ||
|
||
@Inject | ||
private SettingsDecrypter settingsDecrypter; | ||
|
||
/** | ||
* The goal of the deployment. | ||
* | ||
* @return the goal of the deployment. | ||
*/ | ||
public abstract String goal(); | ||
|
||
/** | ||
* Creates a new client. | ||
* | ||
* @return the client | ||
*/ | ||
protected ModelControllerClient createClient() { | ||
return ModelControllerClient.Factory.create(getClientConfiguration()); | ||
} | ||
|
||
/** | ||
* Gets a client configuration used to create a new {@link ModelControllerClient}. | ||
* | ||
* @return the configuration to use | ||
*/ | ||
protected synchronized ToolsModelControllerClientConfiguration getClientConfiguration() { | ||
final Log log = getLog(); | ||
String username = this.username; | ||
String password = this.password; | ||
if (username == null && password == null) { | ||
if (id != null) { | ||
if (settings != null) { | ||
Server server = settings.getServer(id); | ||
if (server != null) { | ||
log.debug(DEBUG_MESSAGE_SETTINGS_HAS_ID); | ||
password = decrypt(server); | ||
username = server.getUsername(); | ||
if (username != null && password != null) { | ||
log.debug(DEBUG_MESSAGE_SETTINGS_HAS_CREDS); | ||
} else { | ||
log.debug(DEBUG_MESSAGE_NO_CREDS); | ||
} | ||
} else { | ||
log.debug(DEBUG_MESSAGE_NO_SERVER_SECTION); | ||
} | ||
} else { | ||
log.debug(DEBUG_MESSAGE_NO_SETTINGS_FILE); | ||
} | ||
} else { | ||
log.debug(DEBUG_MESSAGE_NO_ID); | ||
} | ||
} else { | ||
log.debug(DEBUG_MESSAGE_POM_HAS_CREDS); | ||
} | ||
final ModelControllerClientConfiguration.Builder builder = new ModelControllerClientConfiguration.Builder() | ||
.setProtocol(protocol) | ||
.setHostName(getManagementHostName()) | ||
.setPort(getManagementPort()) | ||
.setConnectionTimeout(timeout * 1000); | ||
if (authenticationConfig != null) { | ||
try { | ||
builder.setAuthenticationConfigUri(authenticationConfig.toURI()); | ||
} catch (URISyntaxException e) { | ||
throw new RuntimeException("Failed to create URI from " + authenticationConfig, e); | ||
} | ||
} | ||
return new ToolsModelControllerClientConfiguration(builder.build(), username, password); | ||
} | ||
|
||
protected int getManagementPort() { | ||
return port; | ||
} | ||
|
||
protected String getManagementHostName() { | ||
return hostname; | ||
} | ||
|
||
private String decrypt(final Server server) { | ||
SettingsDecryptionResult decrypt = settingsDecrypter.decrypt(new DefaultSettingsDecryptionRequest(server)); | ||
return decrypt.getServer().getPassword(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
100 changes: 100 additions & 0 deletions
100
plugin/src/main/java/org/wildfly/plugins/bootablejar/maven/goals/MavenJBossLogger.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
/* | ||
* Copyright The WildFly Authors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package org.wildfly.plugins.bootablejar.maven.goals; | ||
|
||
import java.text.MessageFormat; | ||
|
||
import org.apache.maven.plugin.logging.Log; | ||
import org.jboss.logging.Logger; | ||
|
||
/** | ||
* A logger which delegates to a {@link Log}. | ||
* <p> | ||
* 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}. | ||
* </p> | ||
* <p> | ||
* 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}. | ||
* </p> | ||
* | ||
* @author <a href="mailto:jperkins@redhat.com">James R. Perkins</a> | ||
*/ | ||
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); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.