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 3c886855..fd3eee50 100644 --- a/plugin/src/main/java/org/wildfly/plugin/provision/PackageServerMojo.java +++ b/plugin/src/main/java/org/wildfly/plugin/provision/PackageServerMojo.java @@ -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; @@ -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; /** @@ -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. - *

- * 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}. - *

+ * + * 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 @@ -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 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); + } } } @@ -264,16 +272,6 @@ private List resolveFiles(List files) { return resolvedFiles; } - private List getDeploymentCommands(Path deploymentContent) throws MojoExecutionException { - List 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 wrapOfflineCommands(List commands) { if (commands == null || commands.isEmpty()) { return commands; diff --git a/tests/shared/src/main/java/org/wildfly/plugin/tests/AbstractProvisionConfiguredMojoTestCase.java b/tests/shared/src/main/java/org/wildfly/plugin/tests/AbstractProvisionConfiguredMojoTestCase.java index 9be75aaa..1c7677b7 100644 --- a/tests/shared/src/main/java/org/wildfly/plugin/tests/AbstractProvisionConfiguredMojoTestCase.java +++ b/tests/shared/src/main/java/org/wildfly/plugin/tests/AbstractProvisionConfiguredMojoTestCase.java @@ -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 deployments = new ArrayList<>(); - Files.walkFileTree(rootDir, new SimpleFileVisitor() { - @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));