6767import org .jboss .galleon .maven .plugin .util .MavenArtifactRepositoryManager ;
6868import org .jboss .galleon .maven .plugin .util .MvnMessageWriter ;
6969import org .jboss .galleon .universe .maven .repo .MavenRepoManager ;
70- import org .jboss .galleon .util .IoUtils ;
7170import org .jboss .logging .Logger ;
7271import org .twdata .maven .mojoexecutor .MojoExecutor ;
7372import 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 );
0 commit comments