use of org.wildfly.plugin.core.Deployment in project wildfly-maven-plugin by wildfly.
the class RunMojo method execute.
@Override
public void execute() throws MojoExecutionException, MojoFailureException {
if (skip) {
return;
}
MavenRepositoriesEnricher.enrich(mavenSession, project, repositories);
mavenRepoManager = new MavenArtifactRepositoryManager(repoSystem, session, repositories);
final Log log = getLog();
final Path deploymentContent = getDeploymentContent();
// The deployment must exist before we do anything
if (Files.notExists(deploymentContent)) {
throw new MojoExecutionException(String.format("The deployment '%s' could not be found.", deploymentContent.toAbsolutePath()));
}
// Validate the environment
final Path wildflyPath = provisionIfRequired(deploymentContent.getParent().resolve(provisioningDir));
if (!ServerHelper.isValidHomeDirectory(wildflyPath)) {
throw new MojoExecutionException(String.format("JBOSS_HOME '%s' is not a valid directory.", wildflyPath));
}
final StandaloneCommandBuilder commandBuilder = createCommandBuilder(wildflyPath);
// Print some server information
log.info("JAVA_HOME : " + commandBuilder.getJavaHome());
log.info("JBOSS_HOME: " + commandBuilder.getWildFlyHome());
log.info("JAVA_OPTS : " + Utils.toString(commandBuilder.getJavaOptions(), " "));
try {
if (addUser != null && addUser.hasUsers()) {
log.info("Adding users: " + addUser);
addUser.addUsers(commandBuilder.getWildFlyHome(), commandBuilder.getJavaHome());
}
// Start the server
log.info("Server is starting up. Press CTRL + C to stop the server.");
Process process = startContainer(commandBuilder);
try (ModelControllerClient client = createClient()) {
// Execute commands before the deployment is done
final CommandConfiguration cmdConfig = CommandConfiguration.of(this::createClient, this::getClientConfiguration).addCommands(commands).addScripts(scripts).setJBossHome(commandBuilder.getWildFlyHome()).setFork(true).setStdout("none").setTimeout(timeout).build();
commandExecutor.execute(cmdConfig, mavenRepoManager);
// Create the deployment and deploy
final Deployment deployment = Deployment.of(deploymentContent).setName(name).setRuntimeName(runtimeName);
final DeploymentManager deploymentManager = DeploymentManager.Factory.create(client);
deploymentManager.forceDeploy(deployment);
} catch (MojoExecutionException | MojoFailureException e) {
if (process != null) {
process.destroyForcibly().waitFor(10L, TimeUnit.SECONDS);
}
throw e;
}
try {
// Wait for the process to die
boolean keepRunning = true;
while (keepRunning) {
final int exitCode = process.waitFor();
// 10 is the magic code used in the scripts to survive a :shutdown(restart=true) operation
if (exitCode == 10) {
// Ensure the current process is destroyed and restart a new one
process.destroy();
process = startContainer(commandBuilder);
} else {
keepRunning = false;
}
}
} catch (Exception e) {
throw new MojoExecutionException("The server failed to start", e);
} finally {
if (process != null)
process.destroy();
}
} catch (Exception e) {
throw new MojoExecutionException("The server failed to start", e);
}
}
use of org.wildfly.plugin.core.Deployment in project wildfly-maven-plugin by wildfly.
the class AbstractDeployment method execute.
@Override
public final void execute() throws MojoExecutionException, MojoFailureException {
if (skipExecution()) {
getLog().debug(String.format("Skipping deployment of %s:%s", project.getGroupId(), project.getArtifactId()));
return;
}
try (ModelControllerClient client = createClient();
MavenModelControllerClientConfiguration configuration = getClientConfiguration()) {
final boolean isDomain = ServerHelper.getContainerDescription(client).isDomain();
validate(isDomain);
// Deploy the deployment
getLog().debug("Executing deployment");
final Deployment deployment = configureDeployment(createDeployment());
final DeploymentResult result = executeDeployment(DeploymentManager.Factory.create(client), deployment);
if (!result.successful()) {
throw new MojoExecutionException(String.format("Failed to execute goal %s: %s", goal(), result.getFailureMessage()));
}
} catch (IOException e) {
throw new MojoFailureException(String.format("Failed to execute goal %s.", goal()), e);
}
}
Aggregations