Search in sources :

Example 1 with LegacyBridge

use of org.jboss.as.cli.impl.aesh.cmd.LegacyBridge in project wildfly-core by wildfly.

the class DeployHandler method doHandle.

@Override
protected void doHandle(CommandContext ctx) throws CommandLineException {
    ParsedCommandLine args = ctx.getParsedCommandLine();
    boolean l = this.l.isPresent(args);
    if (!args.hasProperties() || l) {
        try {
            ListCommand.listDeployments(ctx, l);
        } catch (CommandException ex) {
            throw new CommandLineException(ex.getLocalizedMessage());
        }
        return;
    }
    final boolean unmanaged = this.unmanaged.isPresent(args);
    final String path = this.path.getValue(args);
    final String name = this.name.getValue(args);
    final String rtName = this.rtName.getValue(args);
    final String url = this.url.getValue(args);
    final boolean force = this.force.isPresent(args);
    final boolean disabled = this.disabled.isPresent(args);
    final boolean enabled = this.enabled.isPresent(args);
    final String serverGroups = this.serverGroups.getValue(args);
    final boolean allServerGroups = this.allServerGroups.isPresent(args);
    final ModelNode headersNode = headers.toModelNode(ctx);
    if (headersNode != null && headersNode.getType() != ModelType.OBJECT) {
        throw new CommandFormatException("--headers option has wrong value '" + headersNode + "'");
    }
    if (path == null && url == null) {
        if (name == null) {
            throw new CommandLineException("Filesystem path, --url or --name is " + " required.");
        }
        if (name.equals(ALL)) {
            if (force || disabled) {
                throw new CommandLineException("force and disabled can't be used " + "when deploying all disabled deployments");
            }
            EnableAllCommand command = new EnableAllCommand(ctx);
            command.allServerGroups = allServerGroups;
            command.headers = headersNode;
            command.serverGroups = serverGroups;
            try {
                command.execute(ctx);
            } catch (CommandException ex) {
                throw new CommandLineException(ex.getLocalizedMessage());
            }
            return;
        } else {
            EnableCommand command = new EnableCommand(ctx);
            command.allServerGroups = allServerGroups;
            command.headers = headersNode;
            command.serverGroups = serverGroups;
            command.name = name;
            try {
                command.execute(ctx);
            } catch (CommandException ex) {
                throw new CommandLineException(ex.getLocalizedMessage());
            }
            return;
        }
    }
    if (path != null) {
        if (url != null) {
            throw new CommandLineException("Filesystem path and --url can't be used together.");
        }
        File f = new File(path);
        LegacyBridge c;
        if (DeployArchiveCommand.isCliArchive(f)) {
            DeployArchiveCommand command = new DeployArchiveCommand(ctx);
            command.file = f;
            command.script = this.script.getValue(args);
            c = command;
        } else {
            DeployFileCommand command = new DeployFileCommand(ctx, REPLACE_OPTION);
            command.allServerGroups = allServerGroups;
            command.disabled = disabled;
            command.enabled = enabled;
            command.file = f;
            command.replace = force;
            command.headers = headersNode;
            command.name = name;
            command.runtimeName = rtName;
            command.serverGroups = serverGroups;
            command.unmanaged = unmanaged;
            c = command;
        }
        try {
            c.execute(ctx);
        } catch (CommandException ex) {
            throw new CommandLineException(ex.getLocalizedMessage());
        }
        return;
    }
    if (url != null) {
        if (path != null) {
            throw new CommandLineException("Filesystem path and --url can't be " + "used together.");
        }
        DeployUrlCommand command = new DeployUrlCommand(ctx, REPLACE_OPTION);
        command.allServerGroups = allServerGroups;
        command.disabled = disabled;
        command.enabled = enabled;
        try {
            command.deploymentUrl = new URL(url);
        } catch (MalformedURLException ex) {
            throw new CommandLineException(ex);
        }
        command.replace = force;
        command.headers = headersNode;
        command.runtimeName = rtName;
        command.serverGroups = serverGroups;
        try {
            command.execute(ctx);
        } catch (CommandException ex) {
            throw new CommandLineException(ex.getLocalizedMessage());
        }
    }
}
Also used : LegacyBridge(org.jboss.as.cli.impl.aesh.cmd.LegacyBridge) MalformedURLException(java.net.MalformedURLException) CommandException(org.aesh.command.CommandException) CommandLineException(org.jboss.as.cli.CommandLineException) URL(java.net.URL) DeployUrlCommand(org.jboss.as.cli.impl.aesh.cmd.deployment.DeployUrlCommand) EnableAllCommand(org.jboss.as.cli.impl.aesh.cmd.deployment.EnableAllCommand) CommandFormatException(org.jboss.as.cli.CommandFormatException) EnableCommand(org.jboss.as.cli.impl.aesh.cmd.deployment.EnableCommand) DeployFileCommand(org.jboss.as.cli.impl.aesh.cmd.deployment.DeployFileCommand) ParsedCommandLine(org.jboss.as.cli.operation.ParsedCommandLine) DeployArchiveCommand(org.jboss.as.cli.impl.aesh.cmd.deployment.DeployArchiveCommand) ModelNode(org.jboss.dmr.ModelNode) File(java.io.File)

Aggregations

File (java.io.File)1 MalformedURLException (java.net.MalformedURLException)1 URL (java.net.URL)1 CommandException (org.aesh.command.CommandException)1 CommandFormatException (org.jboss.as.cli.CommandFormatException)1 CommandLineException (org.jboss.as.cli.CommandLineException)1 LegacyBridge (org.jboss.as.cli.impl.aesh.cmd.LegacyBridge)1 DeployArchiveCommand (org.jboss.as.cli.impl.aesh.cmd.deployment.DeployArchiveCommand)1 DeployFileCommand (org.jboss.as.cli.impl.aesh.cmd.deployment.DeployFileCommand)1 DeployUrlCommand (org.jboss.as.cli.impl.aesh.cmd.deployment.DeployUrlCommand)1 EnableAllCommand (org.jboss.as.cli.impl.aesh.cmd.deployment.EnableAllCommand)1 EnableCommand (org.jboss.as.cli.impl.aesh.cmd.deployment.EnableCommand)1 ParsedCommandLine (org.jboss.as.cli.operation.ParsedCommandLine)1 ModelNode (org.jboss.dmr.ModelNode)1