private void processResources(final ManagementClient client, final Resource... resources)
      throws IOException {
    for (Resource resource : resources) {
      if (domain != null) {
        // Profiles are required when adding resources in domain mode
        final List<String> profiles = domain.getProfiles();
        if (profiles.isEmpty()) {
          throw new IllegalStateException("Cannot add resources when no profiles were defined.");
        }
        for (String profile : profiles) {
          final CompositeOperationBuilder compositeOperationBuilder =
              CompositeOperationBuilder.create();
          if (addCompositeResource(
              profile, client, resource, address, compositeOperationBuilder, true)) {
            if (resource.hasBeforeAddCommands()) {
              commandExecutor.execute(client, jbossHome, resource.getBeforeAdd());
            }
            // Execute the add resource operation
            reportFailure(client.execute(compositeOperationBuilder.build()));

            if (resource.hasAfterAddCommands()) {
              commandExecutor.execute(client, jbossHome, resource.getAfterAdd());
            }
          }
        }
      } else {
        final CompositeOperationBuilder compositeOperationBuilder =
            CompositeOperationBuilder.create();
        if (addCompositeResource(
            null, client, resource, address, compositeOperationBuilder, true)) {
          if (resource.hasBeforeAddCommands()) {
            commandExecutor.execute(client, jbossHome, resource.getBeforeAdd());
          }
          // Execute the add resource operation
          reportFailure(client.execute(compositeOperationBuilder.build()));

          if (resource.hasAfterAddCommands()) {
            commandExecutor.execute(client, jbossHome, resource.getAfterAdd());
          }
        }
      }
    }
  }
  @Override
  protected void doExecute() throws MojoExecutionException, MojoFailureException {
    final Log log = getLog();
    final File deploymentFile = file();
    // The deployment must exist before we do anything
    if (!deploymentFile.exists()) {
      throw new MojoExecutionException(
          String.format(
              "The deployment '%s' could not be found.", deploymentFile.getAbsolutePath()));
    }
    // Validate the environment
    final Path jbossHome = extractIfRequired(deploymentFile.getParentFile().toPath());
    if (!Files.isDirectory(jbossHome)) {
      throw new MojoExecutionException(
          String.format("JBOSS_HOME '%s' is not a valid directory.", jbossHome));
    }
    final StandaloneCommandBuilder commandBuilder =
        StandaloneCommandBuilder.of(jbossHome)
            .setJavaHome(javaHome)
            .addModuleDirs(modulesPath.getModulePaths());

    // Set the JVM options
    if (javaOpts != null) {
      commandBuilder.setJavaOptions(javaOpts);
    } else if (jvmArgs != null) {
      commandBuilder.setJavaOptions(jvmArgs.split("\\s+"));
    }

    if (serverConfig != null) {
      commandBuilder.setServerConfiguration(serverConfig);
    }

    if (propertiesFile != null) {
      commandBuilder.setPropertiesFile(propertiesFile);
    }

    if (serverArgs != null) {
      commandBuilder.addServerArguments(serverArgs);
    }

    // Check for management overrides
    final ModelControllerClientConfiguration clientConfiguration = getClientConfiguration();
    final String host = clientConfiguration.getHost();
    final int port = clientConfiguration.getPort();
    if (host != null) {
      commandBuilder.setBindAddressHint("management", host);
    }
    if (port > 0) {
      commandBuilder.addServerArguments("-Djboss.management.http.port=" + port);
    }

    // Print some server information
    log.info(String.format("JAVA_HOME=%s", commandBuilder.getJavaHome()));
    log.info(String.format("JBOSS_HOME=%s%n", commandBuilder.getWildFlyHome()));
    Server server = null;
    try (final ManagementClient client = createClient()) {
      // Create the server
      server = Server.create(commandBuilder, client);
      // Start the server
      log.info("Server is starting up. Press CTRL + C to stop the server.");
      server.start(startupTimeout);
      // Deploy the application
      server.checkServerState();
      if (server.isRunning()) {
        log.info(String.format("Deploying application '%s'%n", deploymentFile.getName()));
        final Deployment deployment =
            StandaloneDeployment.create(client, deploymentFile, name, getType(), null, null);
        switch (executeDeployment(client, deployment, jbossHome)) {
          case REQUIRES_RESTART:
            {
              client.execute(ServerOperations.createOperation(ServerOperations.RELOAD));
              break;
            }
          case SUCCESS:
            break;
        }
      } else {
        throw new DeploymentFailureException("Cannot deploy to a server that is not running.");
      }
      while (server.isRunning()) {
        TimeUnit.SECONDS.sleep(1L);
      }
    } catch (Exception e) {
      throw new MojoExecutionException("The server failed to start", e);
    } finally {
      if (server != null) server.stop();
    }
  }