use of org.jboss.as.cli.operation.ParsedCommandLine in project wildfly-core by wildfly.
the class PatchHandler method doInspect.
protected void doInspect(CommandContext ctx) throws CommandLineException {
final ParsedCommandLine parsedLine = ctx.getParsedCommandLine();
final String patchPath = path.getValue(parsedLine, true);
final File patchFile = new File(patchPath);
if (!patchFile.exists()) {
throw new CommandLineException("Failed to locate " + patchFile.getAbsolutePath());
}
ZipFile patchZip = null;
InputStream is = null;
try {
patchZip = new ZipFile(patchFile);
ZipEntry patchXmlEntry = patchZip.getEntry(PatchBundleXml.MULTI_PATCH_XML);
if (patchXmlEntry == null) {
patchXmlEntry = patchZip.getEntry(PatchXml.PATCH_XML);
if (patchXmlEntry == null) {
throw new CommandLineException("Neither " + PatchBundleXml.MULTI_PATCH_XML + " nor " + PatchXml.PATCH_XML + " were found in " + patchFile.getAbsolutePath());
}
is = patchZip.getInputStream(patchXmlEntry);
final Patch patch = PatchXml.parse(is).resolvePatch(null, null);
displayPatchXml(ctx, patch);
} else {
is = patchZip.getInputStream(patchXmlEntry);
final List<BundledPatchEntry> patches = PatchBundleXml.parse(is).getPatches();
displayPatchBundleXml(ctx, patches, patchZip);
}
} catch (ZipException e) {
throw new CommandLineException("Failed to open " + patchFile.getAbsolutePath(), e);
} catch (IOException e) {
throw new CommandLineException("Failed to open " + patchFile.getAbsolutePath(), e);
} catch (PatchingException e) {
throw new CommandLineException("Failed to resolve parsed patch", e);
} catch (XMLStreamException e) {
throw new CommandLineException("Failed to parse patch.xml", e);
} finally {
if (is != null) {
try {
is.close();
} catch (IOException e) {
}
}
if (patchZip != null) {
try {
patchZip.close();
} catch (IOException e) {
}
}
}
}
use of org.jboss.as.cli.operation.ParsedCommandLine in project wildfly-core by wildfly.
the class SetVariableHandler method doHandle.
/* (non-Javadoc)
* @see org.jboss.as.cli.handlers.CommandHandlerWithHelp#doHandle(org.jboss.as.cli.CommandContext)
*/
@Override
protected void doHandle(CommandContext ctx) throws CommandLineException {
ParsedCommandLine parsedArgs = ctx.getParsedCommandLine();
final List<String> vars = parsedArgs.getOtherProperties();
if (vars.isEmpty()) {
final Collection<String> defined = ctx.getVariables();
if (defined.isEmpty()) {
return;
}
final List<String> pairs = new ArrayList<String>(defined.size());
for (String var : defined) {
pairs.add(var + '=' + ctx.getVariable(var));
}
Collections.sort(pairs);
for (String pair : pairs) {
ctx.printLine(pair);
}
return;
}
for (String arg : vars) {
arg = ArgumentWithValue.resolveValue(arg);
if (arg.charAt(0) == '$') {
arg = arg.substring(1);
if (arg.isEmpty()) {
throw new CommandFormatException("Variable name is missing after '$'");
}
}
final int equals = arg.indexOf('=');
if (equals < 1) {
throw new CommandFormatException("'=' is missing for variable '" + arg + "'");
}
final String name = arg.substring(0, equals);
if (name.isEmpty()) {
throw new CommandFormatException("The name is missing in '" + arg + "'");
}
if (equals == arg.length() - 1) {
ctx.setVariable(name, null);
} else {
String value = arg.substring(equals + 1);
if (value.length() > 2 && value.charAt(0) == '`' && value.charAt(value.length() - 1) == '`') {
value = Util.getResult(ctx, value.substring(1, value.length() - 1));
}
ctx.setVariable(name, value);
}
}
}
use of org.jboss.as.cli.operation.ParsedCommandLine in project wildfly-core by wildfly.
the class ShutdownHandler method buildRequestWithoutHeaders.
@Override
protected ModelNode buildRequestWithoutHeaders(CommandContext ctx) throws CommandFormatException {
final ModelNode op = new ModelNode();
final ParsedCommandLine args = ctx.getParsedCommandLine();
if (ctx.isDomainMode()) {
final String hostName = host.getValue(args);
if (hostName == null) {
throw new CommandFormatException("Missing required argument " + host.getFullName());
}
op.get(Util.ADDRESS).add(Util.HOST, hostName);
if (timeout.isPresent(args)) {
throw new CommandFormatException(timeout.getFullName() + " is not allowed in the domain mode.");
}
} else {
if (host.isPresent(args)) {
throw new CommandFormatException(host.getFullName() + " is not allowed in the standalone mode.");
}
if (timeout.isPresent(args) && suspendTimeout.isPresent(args)) {
throw new CommandFormatException(timeout.getFullName() + " cannot be used in conjunction with suspend-timeout.");
}
op.get(Util.ADDRESS).setEmptyList();
}
op.get(Util.OPERATION).set(Util.SHUTDOWN);
setBooleanArgument(args, op, restart, Util.RESTART);
setIntArgument(args, op, timeout, Util.TIMEOUT);
setIntArgument(args, op, suspendTimeout, Util.SUSPEND_TIMEOUT);
return op;
}
use of org.jboss.as.cli.operation.ParsedCommandLine in project wildfly-core by wildfly.
the class UndeployHandler method buildRequestWithoutHeaders.
@Override
public ModelNode buildRequestWithoutHeaders(CommandContext ctx) throws CommandFormatException {
final ParsedCommandLine args = ctx.getParsedCommandLine();
String p = this.path.getValue(args);
if (p != null) {
File f = new File(p);
if (DeployArchiveCommand.isCliArchive(f)) {
UndeployArchiveCommand command = new UndeployArchiveCommand(ctx);
command.file = f;
command.script = script.getValue(args);
return command.buildRequest(ctx);
}
}
if (name == null) {
throw new CommandFormatException("Deployment name is missing.");
}
UndeployCommand command = null;
boolean keepContent = this.keepContent.isPresent(args);
if (keepContent) {
command = new DisableCommand(ctx);
} else {
command = new UndeployCommand(ctx);
}
final String name = this.name.getValue(ctx.getParsedCommandLine());
command.allRelevantServerGroups = allRelevantServerGroups.isPresent(args);
if (name != null) {
command.name = name;
}
command.serverGroups = serverGroups.getValue(args);
return command.buildRequest(ctx);
}
use of org.jboss.as.cli.operation.ParsedCommandLine in project wildfly-core by wildfly.
the class UndeployHandler method doHandle.
@Override
protected void doHandle(CommandContext ctx) throws CommandLineException {
final ParsedCommandLine args = ctx.getParsedCommandLine();
final 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 String path = this.path.getValue(args);
final File f;
if (path != null) {
f = new File(path);
if (DeployArchiveCommand.isCliArchive(f)) {
UndeployArchiveCommand command = new UndeployArchiveCommand(ctx);
command.file = f;
command.script = script.getValue(args);
try {
command.execute(ctx);
} catch (CommandException ex) {
throw new CommandLineException(ex.getLocalizedMessage());
}
return;
}
}
final String name = this.name.getValue(ctx.getParsedCommandLine());
if (name == null) {
try {
ListCommand.listDeployments(ctx, l);
} catch (CommandException ex) {
throw new CommandLineException(ex.getLocalizedMessage());
}
return;
}
UndeployCommand command = null;
boolean keepContent = this.keepContent.isPresent(args);
if (keepContent) {
command = new DisableCommand(ctx);
} else {
command = new UndeployCommand(ctx);
}
command.allRelevantServerGroups = allRelevantServerGroups.isPresent(args);
final ModelNode headersNode = headers.toModelNode(ctx);
if (headersNode != null && headersNode.getType() != ModelType.OBJECT) {
throw new CommandFormatException("--headers option has wrong value '" + headersNode + "'");
}
command.headers = headersNode;
if (name != null) {
command.name = name;
}
command.serverGroups = serverGroups.getValue(args);
try {
command.execute(ctx);
} catch (CommandException ex) {
throw new CommandLineException(ex.getLocalizedMessage());
}
}
Aggregations