@@ -0,0 +1,3984 @@
+/*%0A * JBoss, Home of Professional Open Source%0A * Copyright 2009, Red Hat Middleware LLC, and individual contributors%0A * by the @authors tag. See the copyright.txt in the distribution for a%0A * full listing of individual contributors.%0A *%0A * Licensed under the Apache License, Version 2.0 (the %22License%22);%0A * you may not use this file except in compliance with the License.%0A * You may obtain a copy of the License at%0A * http://www.apache.org/licenses/LICENSE-2.0%0A * Unless required by applicable law or agreed to in writing, software%0A * distributed under the License is distributed on an %22AS IS%22 BASIS,%0A * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.%0A * See the License for the specific language governing permissions and%0A * limitations under the License.%0A */%0Apackage org.jboss.as.controller.client.helpers.standalone;%0A%0Aimport java.io.InputStream;%0Aimport java.util.concurrent.Future;%0A%0Aimport org.jboss.as.controller.client.ModelControllerClient;%0A%0A/**%0A * A simple helper for server deployments.%0A *%0A * @author thomas.diesler@jboss.com%0A * @since 22-Mar-2012%0A */%0Apublic class ServerDeploymentHelper %7B%0A%0A    private final ServerDeploymentManager deploymentManager;%0A%0A    public ServerDeploymentHelper(ModelControllerClient client) %7B%0A        deploymentManager = ServerDeploymentManager.Factory.create(client);%0A    %7D%0A%0A    public ServerDeploymentHelper(ServerDeploymentManager deploymentManager) %7B%0A        this.deploymentManager = deploymentManager;%0A    %7D%0A%0A    public String deploy(String name, InputStream input) throws ServerDeploymentException %7B%0A        String runtimeName;%0A        ServerDeploymentActionResult actionResult;%0A        try %7B%0A            DeploymentPlanBuilder builder = deploymentManager.newDeploymentPlan();%0A            builder = builder.add(name, input).andDeploy();%0A            DeploymentPlan plan = builder.build();%0A            DeploymentAction action = builder.getLastAction();%0A            runtimeName = action.getDeploymentUnitUniqueName();%0A            Future%3CServerDeploymentPlanResult%3E future = deploymentManager.execute(plan);%0A            ServerDeploymentPlanResult planResult = future.get();%0A            actionResult = planResult.getDeploymentActionResult(action.getId());%0A        %7D catch (Exception ex) %7B%0A            throw new ServerDeploymentException(ex);%0A        %7D%0A        if (actionResult.getDeploymentException() != null)%0A            throw new ServerDeploymentException(actionResult);%0A        return runtimeName;%0A    %7D%0A%0A    public void undeploy(String runtimeName) throws ServerDeploymentException %7B%0A        ServerDeploymentActionResult actionResult;%0A        try %7B%0A            DeploymentPlanBuilder builder = deploymentManager.newDeploymentPlan();%0A            builder = builder.undeploy(runtimeName).remove(runtimeName);%0A            DeploymentPlan plan = builder.build();%0A            DeploymentAction action = builder.getLastAction();%0A            Future%3CServerDeploymentPlanResult%3E future = deploymentManager.execute(plan);%0A            ServerDeploymentPlanResult planResult = future.get();%0A            actionResult = planResult.getDeploymentActionResult(action.getId());%0A        %7D catch (Exception ex) %7B%0A            throw new ServerDeploymentException(ex);%0A        %7D%0A        if (actionResult.getDeploymentException() != null)%0A            throw new ServerDeploymentException(actionResult);%0A    %7D%0A%0A    public static class ServerDeploymentException extends Exception %7B%0A        private static final long serialVersionUID = 1L;%0A        private final ServerDeploymentActionResult actionResult;%0A%0A        private ServerDeploymentException(ServerDeploymentActionResult actionResult) %7B%0A            super(actionResult.getDeploymentException());%0A            this.actionResult = actionResult;%0A        %7D%0A%0A        private ServerDeploymentException(Throwable cause) %7B%0A            super(cause);%0A            actionResult = null;%0A        %7D%0A%0A        public ServerDeploymentActionResult getActionResult() %7B%0A            return actionResult;%0A        %7D%0A    %7D%0A%7D%0A

Verify that the deploy operation is guaranteed to wait for the Bundle to get installed