Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WFMP-185] Deploy the application by copying it to deployments dir #289

Merged
merged 1 commit into from
Feb 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.nio.file.StandardCopyOption;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
Expand All @@ -43,6 +44,8 @@
import static org.wildfly.plugin.core.Constants.CLI_ECHO_COMMAND_ARG;
import static org.wildfly.plugin.core.Constants.STANDALONE;
import static org.wildfly.plugin.core.Constants.STANDALONE_XML;

import org.wildfly.plugin.deployment.MojoDeploymentException;
import org.wildfly.plugin.deployment.PackageType;

/**
Expand Down Expand Up @@ -115,22 +118,23 @@ public class PackageServerMojo extends AbstractProvisionServerMojo {

/**
* Specifies the name used for the deployment.
*
* When the deployment is copied to the server, it is renamed with this name.
*/
@Parameter(property = PropertyNames.DEPLOYMENT_NAME)
private String name;

/**
* The runtime name for the deployment.
* <p>
* In some cases users may wish to have two deployments with the same
* {@code runtime-name} (e.g. two versions of {@code example.war}) both
* available in the management configuration, in which case the deployments
* would need to have distinct {@code name} values but would have the same
* {@code runtime-name}.
* </p>
*
* When the deployment is copied to the server, it is renamed with the {@code runtime-name}.
* If both {@code name} and {@code runtime-name} are specified, {@code runtime-name} is used.
*
* @deprecated use the {@code name} property instead to change the name of the deployment.
*/
@Deprecated(since="4.1.O")
@Parameter(property = PropertyNames.DEPLOYMENT_RUNTIME_NAME, alias = "runtime-name")
private String runtimeName;
protected String runtimeName;

/**
* Indicates how {@code stdout} and {@code stderr} should be handled for the
Expand Down Expand Up @@ -207,16 +211,20 @@ protected void serverProvisioned(Path jbossHome) throws MojoExecutionException,
if (!skipDeployment) {
final Path deploymentContent = getDeploymentContent();
if (Files.exists(deploymentContent)) {
getLog().info("Deploying " + deploymentContent);
List<String> deploymentCommands = getDeploymentCommands(deploymentContent);
final BaseCommandConfiguration cmdConfigDeployment = new BaseCommandConfiguration.Builder()
.addCommands(deploymentCommands)
.setJBossHome(jbossHome)
.addCLIArguments(CLI_ECHO_COMMAND_ARG)
.setAppend(true)
.setStdout(stdout)
.build();
commandExecutor.execute(cmdConfigDeployment, artifactResolver);
Path standaloneDeploymentDir = Paths.get(project.getBuild().getDirectory(), provisioningDir, "standalone", "deployments").normalize();
try {
String targetName;
if (runtimeName != null) {
targetName = runtimeName;
} else {
targetName = name != null ? name : deploymentContent.getFileName().toString();
}
Path deploymentTarget = standaloneDeploymentDir.resolve(targetName);
getLog().info("Copy deployment " + deploymentContent + " to " + deploymentTarget);
Files.copy(deploymentContent, deploymentTarget, StandardCopyOption.REPLACE_EXISTING);
} catch (IOException e) {
throw new MojoDeploymentException("Could not copy deployment in provisioned server", e);
}
}
}

Expand Down Expand Up @@ -264,16 +272,6 @@ private List<File> resolveFiles(List<File> files) {
return resolvedFiles;
}

private List<String> getDeploymentCommands(Path deploymentContent) throws MojoExecutionException {
List<String> deploymentCommands = new ArrayList<>();
StringBuilder deploymentBuilder = new StringBuilder();
deploymentBuilder.append("deploy ").append(deploymentContent).append(" --name=").
append(name == null ? deploymentContent.getFileName() : name).append(" --runtime-name=").
append(runtimeName == null ? deploymentContent.getFileName() : runtimeName);
deploymentCommands.add(deploymentBuilder.toString());
return wrapOfflineCommands(deploymentCommands);
}

private List<String> wrapOfflineCommands(List<String> commands) {
if (commands == null || commands.isEmpty()) {
return commands;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -158,25 +158,16 @@ public void checkStandaloneWildFlyHome(Path wildflyHome, int numDeployments,
String[] layers, String[] excludedLayers, boolean stateRecorded, String... configTokens) throws Exception {
Assert.assertTrue(TestEnvironment.isValidWildFlyHome(wildflyHome));
if (numDeployments > 0) {
// Must retrieve all content directories.
Path rootDir = wildflyHome.resolve("standalone/data/content");
List<Path> deployments = new ArrayList<>();
Files.walkFileTree(rootDir, new SimpleFileVisitor<Path>() {
@Override
public FileVisitResult visitFile(final Path file, final BasicFileAttributes attrs) throws IOException {
if ("content".equals(file.getFileName().toString())) {
deployments.add(file);
}
return FileVisitResult.CONTINUE;
}
});
assertEquals(numDeployments, deployments.size());
// Must retrieve all deployments.
Path rootDir = wildflyHome.resolve("standalone/deployments");
String[] deployments = rootDir.toFile().list((dir, name) -> !name.equals("README.txt"));
assertEquals(numDeployments, deployments.length);
} else {
// The directory should be empty if no deployment is expected, however in some cases it may not even be
// created.
if (Files.exists(wildflyHome.resolve("standalone/data/content"))) {
assertEquals(0, Files.list(wildflyHome.resolve("standalone/data/content")).count());
}
Path rootDir = wildflyHome.resolve("standalone/deployments");
String[] deployments = rootDir.toFile().list((dir, name) -> !name.equals("README.txt"));
assertEquals(0, deployments.length);
}
Path history = wildflyHome.resolve("standalone").resolve("configuration").resolve("standalone_xml_history");
assertFalse(Files.exists(history));
Expand Down