Skip to content

Commit 5f3c4dc

Browse files
committed
[WFMP-295] Allow the jboss.home property to be used in the dev goal. Deprecated the provisioningDir parameter in the dev, run, and start goals as we should just use jboss.home.
https://issues.redhat.com/browse/WFMP-295 Signed-off-by: James R. Perkins <jperkins@redhat.com>
1 parent 7eb582c commit 5f3c4dc

File tree

2 files changed

+82
-27
lines changed

2 files changed

+82
-27
lines changed

plugin/src/main/java/org/wildfly/plugin/dev/DevMojo.java

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,6 @@
6767
import org.jboss.galleon.maven.plugin.util.MavenArtifactRepositoryManager;
6868
import org.jboss.galleon.maven.plugin.util.MvnMessageWriter;
6969
import org.jboss.galleon.universe.maven.repo.MavenRepoManager;
70-
import org.jboss.galleon.util.IoUtils;
7170
import org.jboss.logging.Logger;
7271
import org.twdata.maven.mojoexecutor.MojoExecutor;
7372
import org.wildfly.channel.UnresolvedMavenArtifactException;
@@ -305,7 +304,7 @@ public class DevMojo extends AbstractServerStartMojo {
305304
private boolean offlineProvisioning;
306305

307306
/**
308-
* Set to {@code true} if you want to delete the existing server referenced from the {@code provisioningDir} and provision a
307+
* Set to {@code true} if you want to delete the existing server referenced from the {@code jbossHome} and provision a
309308
* new one,
310309
* otherwise {@code false}. When { @code discover-provisioning-info } is set to {@code true}, this option is enforced to be
311310
* {@code true}.
@@ -401,7 +400,6 @@ public class DevMojo extends AbstractServerStartMojo {
401400

402401
private String warGoal = MAVEN_EXPLODED_GOAL;
403402
private ScanResults results;
404-
private Path installDir;
405403
private boolean requiresWarDeletion;
406404
private Logger mavenJBossLogger;
407405

@@ -413,6 +411,7 @@ public void execute() throws MojoExecutionException, MojoFailureException {
413411
}
414412
mavenJBossLogger = new MavenJBossLogger(getLog());
415413
serverConfig = serverConfig == null ? "standalone.xml" : serverConfig;
414+
boolean startServer = false;
416415
ServerContext context = null;
417416
if (remote) {
418417
init();
@@ -424,7 +423,7 @@ public void execute() throws MojoExecutionException, MojoFailureException {
424423
getLog().info("Layer discovery has been enabled, overwriteProvisionedServer has been set to true");
425424
}
426425
} else {
427-
context = startServer(ServerType.STANDALONE);
426+
startServer = true;
428427
}
429428
}
430429
try {
@@ -439,7 +438,7 @@ public void execute() throws MojoExecutionException, MojoFailureException {
439438
requiresWarDeletion = !remote;
440439
}
441440
// We must start the server after compilation occurred to get a deployment to scan
442-
if (!remote && isDiscoveryEnabled()) {
441+
if (startServer) {
443442
context = startServer(ServerType.STANDALONE);
444443
}
445444
try (final WatchService watcher = FileSystems.getDefault().newWatchService()) {
@@ -593,17 +592,18 @@ boolean reprovisionAndStart()
593592
if (newConfig == null) {
594593
return false;
595594
}
595+
final Path jbossHome = resolveJBossHome();
596596
debug("Changes in layers detected, must re-provision the server");
597597
try (ModelControllerClient client = createClient()) {
598598
ServerManager.builder().client(client).standalone().shutdown();
599-
debug("Deleting existing installation " + installDir);
600-
IoUtils.recursiveDelete(installDir);
599+
debug("Deleting existing installation " + jbossHome);
600+
deleteRecursively(jbossHome);
601601
}
602602
GalleonBuilder galleonBuilder = new GalleonBuilder();
603603
galleonBuilder.addArtifactResolver(mavenRepoManager);
604604
ProvisioningBuilder builder = galleonBuilder.newProvisioningBuilder(newConfig);
605605
try (Provisioning pm = builder
606-
.setInstallationHome(installDir)
606+
.setInstallationHome(jbossHome)
607607
.setMessageWriter(new MvnMessageWriter(getLog()))
608608
.build()) {
609609
provisionServer(pm, newConfig);
@@ -614,15 +614,21 @@ boolean reprovisionAndStart()
614614

615615
@Override
616616
protected Path provisionIfRequired(final Path installDir) throws MojoFailureException, MojoExecutionException {
617+
if (!isAllowProvisioning()) {
618+
return installDir;
619+
}
617620
// This is called for the initial start of the server.
618-
this.installDir = installDir;
619621
if (!overwriteProvisionedServer && Files.exists(installDir)) {
620622
getLog().info(String.format("A server already exists in %s, provisioning for %s:%s", installDir,
621623
project.getGroupId(), project.getArtifactId()));
622624
return installDir;
623625
}
624626
if (Files.exists(installDir)) {
625-
IoUtils.recursiveDelete(installDir);
627+
try {
628+
deleteRecursively(installDir);
629+
} catch (IOException ex) {
630+
throw new MojoExecutionException("Failed to delete directory " + installDir, ex);
631+
}
626632
}
627633
try {
628634
GalleonBuilder provider = new GalleonBuilder();
@@ -659,6 +665,11 @@ protected Path provisionIfRequired(final Path installDir) throws MojoFailureExce
659665
return installDir;
660666
}
661667

668+
@Override
669+
protected boolean isAllowProvisioning() {
670+
return overwriteProvisionedServer || super.isAllowProvisioning();
671+
}
672+
662673
private ScanResults scanDeployment(GalleonBuilder pm) throws Exception {
663674
List<Path> lst = new ArrayList<>();
664675
lst.add(resolveWarLocation());
@@ -675,6 +686,7 @@ private ScanResults scanDeployment(GalleonBuilder pm) throws Exception {
675686

676687
private void provisionServer(Provisioning pm, GalleonProvisioningConfig config)
677688
throws ProvisioningException, MojoExecutionException {
689+
final Path installDir = resolveJBossHome();
678690
getLog().info("Provisioning server in " + installDir);
679691
PluginProgressTracker.initTrackers(pm, mavenJBossLogger);
680692
pm.provision(config);

plugin/src/main/java/org/wildfly/plugin/server/AbstractServerStartMojo.java

Lines changed: 60 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,11 @@ public abstract class AbstractServerStartMojo extends AbstractStartMojo {
3636
protected File targetDir;
3737

3838
/**
39-
* The WildFly Application Server's home directory. If not used, WildFly will be downloaded.
39+
* The WildFly Application Server's home directory. If not set, a server will be provisioned in the
40+
* <code>${project.build.directory}/server</code>.
4041
*/
4142
@Parameter(alias = "jboss-home", property = PropertyNames.JBOSS_HOME)
42-
protected String jbossHome;
43+
private String jbossHome;
4344

4445
/**
4546
* The feature pack location. See the <a href="https://docs.wildfly.org/galleon/#_feature_pack_location">documentation</a>
@@ -64,11 +65,17 @@ public abstract class AbstractServerStartMojo extends AbstractStartMojo {
6465

6566
/**
6667
* The directory name inside the buildDir where to provision the default server.
67-
* By default the server is provisioned into the 'server' directory.
68+
* By default, the server is provisioned into the 'server' directory.
69+
* <p>
70+
* This parameter has been deprecated in favor of using the {@code <jbossHome/>} parameter. If both are defined,
71+
* this parameter will be ignored.
72+
* </p>
6873
*
6974
* @since 3.0
75+
* @deprecated use jbossHome setting
7076
*/
71-
@Parameter(alias = "provisioning-dir", property = PropertyNames.WILDFLY_PROVISIONING_DIR, defaultValue = Utils.WILDFLY_DEFAULT_DIR)
77+
@Deprecated(forRemoval = true)
78+
@Parameter(alias = "provisioning-dir", property = PropertyNames.WILDFLY_PROVISIONING_DIR)
7279
private String provisioningDir;
7380

7481
/**
@@ -91,10 +98,12 @@ public abstract class AbstractServerStartMojo extends AbstractStartMojo {
9198
@Parameter(alias = "add-user", property = "wildfly.add-user")
9299
private AddUser addUser;
93100

101+
private Path cachedJBossHome;
102+
private boolean allowProvisioning;
103+
94104
@Override
95105
protected Path getServerHome() throws MojoExecutionException, MojoFailureException {
96-
// Validate the environment
97-
final Path jbossHome = provisionIfRequired(targetDir.toPath().resolve(provisioningDir));
106+
final Path jbossHome = provisionIfRequired(resolveJBossHome());
98107
if (!ServerManager.isValidHomeDirectory(jbossHome)) {
99108
throw new MojoExecutionException(String.format("JBOSS_HOME '%s' is not a valid directory.", jbossHome));
100109
}
@@ -211,19 +220,18 @@ protected DomainCommandBuilder createDomainCommandBuilder(final Path jbossHome,
211220
}
212221

213222
protected Path provisionIfRequired(final Path installDir) throws MojoFailureException, MojoExecutionException {
214-
if (jbossHome != null) {
215-
// we do not need to download WildFly
216-
return Paths.get(jbossHome);
217-
}
218-
try {
219-
if (!Files.exists(installDir)) {
220-
getLog().info("Provisioning default server in " + installDir);
221-
GalleonUtils.provision(installDir, resolveFeaturePackLocation(), version, mavenRepoManager);
223+
if (isAllowProvisioning()) {
224+
try {
225+
if (!Files.exists(installDir)) {
226+
getLog().info("Provisioning default server in " + installDir);
227+
GalleonUtils.provision(installDir, resolveFeaturePackLocation(), version, mavenRepoManager);
228+
}
229+
return installDir;
230+
} catch (ProvisioningException ex) {
231+
throw new MojoFailureException(ex.getLocalizedMessage(), ex);
222232
}
223-
return installDir;
224-
} catch (ProvisioningException ex) {
225-
throw new MojoFailureException(ex.getLocalizedMessage(), ex);
226233
}
234+
return resolveJBossHome();
227235
}
228236

229237
private void addUsers(final Path wildflyHome, final Path javaHome) throws IOException {
@@ -245,4 +253,39 @@ private String resolveFeaturePackLocation() {
245253
protected String getDefaultFeaturePackLocation() {
246254
return "wildfly@maven(org.jboss.universe:community-universe)";
247255
}
256+
257+
/**
258+
* Indicates if provisioning should be allowed or not.
259+
* <p>
260+
* Provisioning is said to be allowed if the JBoss Home directory does not exist and does not already have a server
261+
* provisioned in it.
262+
* </p>
263+
*
264+
* @return {@code true} if provisioning is allowed, otherwise {@code false}
265+
*/
266+
protected boolean isAllowProvisioning() {
267+
resolveJBossHome();
268+
return allowProvisioning;
269+
}
270+
271+
/**
272+
* Resolves the JBoss Home directory.
273+
*
274+
* @return the JBoss Home directory
275+
*/
276+
protected Path resolveJBossHome() {
277+
if (cachedJBossHome == null) {
278+
if (jbossHome == null) {
279+
if (provisioningDir == null) {
280+
cachedJBossHome = Path.of(project.getBuild().getDirectory(), Utils.WILDFLY_DEFAULT_DIR);
281+
} else {
282+
cachedJBossHome = Path.of(project.getBuild().getDirectory(), provisioningDir);
283+
}
284+
} else {
285+
cachedJBossHome = Path.of(jbossHome);
286+
}
287+
allowProvisioning = !ServerManager.isValidHomeDirectory(cachedJBossHome);
288+
}
289+
return cachedJBossHome;
290+
}
248291
}

0 commit comments

Comments
 (0)