use of org.jboss.as.cli.handlers.FilenameTabCompleter in project wildfly-core by wildfly.
the class EmbedHostControllerHandler method create.
static EmbedHostControllerHandler create(final AtomicReference<EmbeddedProcessLaunch> hostControllerReference, final CommandContext ctx, final boolean modular) {
EmbedHostControllerHandler result = new EmbedHostControllerHandler(hostControllerReference);
final FilenameTabCompleter pathCompleter = FilenameTabCompleter.newCompleter(ctx);
if (!modular) {
result.jbossHome = new FileSystemPathArgument(result, pathCompleter, "--jboss-home");
}
result.stdOutHandling = new ArgumentWithValue(result, new SimpleTabCompleter(new String[] { ECHO, DISCARD_STDOUT }), "--std-out");
result.domainConfig = new ArgumentWithValue(result, DOMAIN_CONFIG);
result.hostConfig = new ArgumentWithValue(result, HOST_CONFIG);
result.dashC = new ArgumentWithValue(result, "-c");
result.dashC.addCantAppearAfter(result.domainConfig);
result.domainConfig.addCantAppearAfter(result.dashC);
result.timeout = new ArgumentWithValue(result, "--timeout");
result.emptyDomainConfig = new ArgumentWithoutValue(result, EMPTY_DOMAIN_CONFIG);
result.removeExistingDomainConfig = new ArgumentWithoutValue(result, REMOVE_EXISTING_DOMAIN_CONFIG);
result.emptyHostConfig = new ArgumentWithoutValue(result, EMPTY_HOST_CONFIG);
result.removeExistingHostConfig = new ArgumentWithoutValue(result, REMOVE_EXISTING_HOST_CONFIG);
return result;
}
use of org.jboss.as.cli.handlers.FilenameTabCompleter in project wildfly-core by wildfly.
the class ASModuleHandler method addModule.
protected void addModule(CommandContext ctx, final ParsedCommandLine parsedCmd) throws CommandLineException {
final String moduleName = name.getValue(parsedCmd, true);
// resources required only if we are generating module.xml
if (!moduleArg.isPresent(parsedCmd) && !(resources.isPresent(parsedCmd) || absoluteResources.isPresent(parsedCmd))) {
throw new CommandFormatException("You must specify at least one resource: use --resources or --absolute-resources parameter");
}
final String resourcePaths = resources.getValue(parsedCmd);
final String absoluteResourcePaths = absoluteResources.getValue(parsedCmd);
String pathDelimiter = PATH_SEPARATOR;
if (resourceDelimiter.isPresent(parsedCmd)) {
pathDelimiter = resourceDelimiter.getValue(parsedCmd);
}
final FilenameTabCompleter pathCompleter = Util.isWindows() ? new WindowsFilenameTabCompleter(ctx) : new DefaultFilenameTabCompleter(ctx);
final String[] resourceArr = (resourcePaths == null) ? new String[0] : resourcePaths.split(pathDelimiter);
File[] resourceFiles = new File[resourceArr.length];
boolean allowNonExistent = allowNonExistentResources.isPresent(parsedCmd);
for (int i = 0; i < resourceArr.length; ++i) {
final File f = new File(pathCompleter.translatePath(resourceArr[i]));
if (!f.exists() && !allowNonExistent) {
throw new CommandLineException("Failed to locate " + f.getAbsolutePath() + ", if you defined a nonexistent resource on purpose you should " + "use the " + allowNonExistentResources.getFullName() + " option");
}
resourceFiles[i] = f;
}
final String[] absoluteResourceArr = (absoluteResourcePaths == null) ? new String[0] : absoluteResourcePaths.split(pathDelimiter);
File[] absoluteResourceFiles = new File[absoluteResourceArr.length];
for (int i = 0; i < absoluteResourceArr.length; ++i) {
final File f = new File(pathCompleter.translatePath(absoluteResourceArr[i]));
if (!f.exists()) {
throw new CommandLineException("Failed to locate " + f.getAbsolutePath());
}
absoluteResourceFiles[i] = f;
}
final File moduleDir = getModulePath(getModulesDir(ctx), moduleName, slot.getValue(parsedCmd));
if (moduleDir.exists()) {
throw new CommandLineException("Module " + moduleName + " already exists at " + moduleDir.getAbsolutePath());
}
if (!moduleDir.mkdirs()) {
throw new CommandLineException("Failed to create directory " + moduleDir.getAbsolutePath());
}
final ModuleConfigImpl config;
final String moduleXml = moduleArg.getValue(parsedCmd);
if (moduleXml != null) {
config = null;
final File source = new File(moduleXml);
if (!source.exists()) {
throw new CommandLineException("Failed to locate the file on the filesystem: " + source.getAbsolutePath());
}
copy(source, new File(moduleDir, "module.xml"));
} else {
config = new ModuleConfigImpl(moduleName);
}
for (File f : resourceFiles) {
copyResource(f, new File(moduleDir, f.getName()), ctx, this);
if (config != null) {
config.addResource(new ResourceRoot(f.getName()));
}
}
for (File f : absoluteResourceFiles) {
if (config != null) {
try {
config.addResource(new ResourceRoot(f.getCanonicalPath()));
} catch (IOException ioe) {
throw new CommandLineException("Failed to read path: " + f.getAbsolutePath(), ioe);
}
}
}
if (config != null) {
Set<String> modules = new HashSet<>();
final String dependenciesStr = dependencies.getValue(parsedCmd);
if (dependenciesStr != null) {
final String[] depsArr = dependenciesStr.split(",+");
for (String dep : depsArr) {
// TODO validate dependencies
String depName = dep.trim();
config.addDependency(new ModuleDependency(depName));
modules.add(depName);
}
}
final String exportDependenciesStr = exportDependencies.getValue(parsedCmd);
if (exportDependenciesStr != null) {
final String[] depsArr = exportDependenciesStr.split(",+");
for (String dep : depsArr) {
// TODO validate dependencies
String depName = dep.trim();
if (modules.contains(depName)) {
deleteRecursively(moduleDir);
throw new CommandLineException("Error, duplicated dependency " + depName);
}
modules.add(depName);
config.addDependency(new ModuleDependency(depName, true));
}
}
final String propsStr = props.getValue(parsedCmd);
if (propsStr != null) {
final String[] pairs = propsStr.split(",");
for (String pair : pairs) {
int equals = pair.indexOf('=');
if (equals == -1) {
throw new CommandFormatException("Property '" + pair + "' in '" + propsStr + "' is missing the equals sign.");
}
final String propName = pair.substring(0, equals);
if (propName.isEmpty()) {
throw new CommandFormatException("Property name is missing for '" + pair + "' in '" + propsStr + "'");
}
config.setProperty(propName, pair.substring(equals + 1));
}
}
final String slotVal = slot.getValue(parsedCmd);
if (slotVal != null) {
config.setSlot(slotVal);
}
final String mainCls = mainClass.getValue(parsedCmd);
if (mainCls != null) {
config.setMainClass(mainCls);
}
FileOutputStream fos = null;
final File moduleFile = new File(moduleDir, "module.xml");
try {
fos = new FileOutputStream(moduleFile);
XMLExtendedStreamWriter xmlWriter = create(XMLOutputFactory.newInstance().createXMLStreamWriter(fos, StandardCharsets.UTF_8.name()));
config.writeContent(xmlWriter, null);
xmlWriter.flush();
} catch (IOException e) {
throw new CommandLineException("Failed to create file " + moduleFile.getAbsolutePath(), e);
} catch (XMLStreamException e) {
throw new CommandLineException("Failed to write to " + moduleFile.getAbsolutePath(), e);
} finally {
if (fos != null) {
try {
fos.close();
} catch (IOException e) {
}
}
}
}
}
use of org.jboss.as.cli.handlers.FilenameTabCompleter in project wildfly-core by wildfly.
the class Util method applyReplacements.
static void applyReplacements(CommandContext ctx, String name, ModelNode value, ModelNode description, ModelType mt, Attachments attachments) {
if (value == null || !value.isDefined()) {
return;
}
switch(mt) {
case INT:
// Server side can accept invalid content.
if (!value.getType().equals(ModelType.STRING)) {
break;
}
if (isFileAttachment(description)) {
FilenameTabCompleter completer = FilenameTabCompleter.newCompleter(ctx);
value.set(attachments.addFileAttachment(completer.translatePath(value.asString())));
}
break;
case LIST:
{
// Server side can accept invalid content.
if (!mt.equals(value.getType())) {
break;
}
ModelNode valueType = description.get("value-type");
if (valueType.isDefined()) {
ModelType valueTypeType = valueType.getType();
// of Objects
if (ModelType.OBJECT.equals(valueTypeType)) {
for (int i = 0; i < value.asInt(); i++) {
applyReplacements(ctx, "value-type", value.get(i), valueType, ModelType.OBJECT, attachments);
}
// of INT
} else if (ModelType.INT.equals(valueType.asType())) {
if (isFileAttachment(description)) {
FilenameTabCompleter completer = FilenameTabCompleter.newCompleter(ctx);
for (int i = 0; i < value.asInt(); i++) {
value.get(i).set(attachments.addFileAttachment(completer.translatePath(value.get(i).asString())));
}
}
}
}
break;
}
case OBJECT:
{
// Server side can accept invalid content.
if (!mt.equals(value.getType())) {
break;
}
ModelNode valueType = description.get("value-type");
// This is a value-type value, use the description
if (!valueType.isDefined()) {
valueType = description;
}
// If valueTypeType is an OBJECT, then we can consult the value-type.
// If valueTypeType is not an OBJECT, then we are facing a Map<String, X>
// where X is indicated by the valueTypeType enum value
ModelType valueTypeType = valueType.getType();
if (ModelType.OBJECT.equals(valueTypeType)) {
for (String k : value.keys()) {
if (value.get(k).isDefined() && valueType.hasDefined(k)) {
ModelNode p = valueType.get(k);
if (p.hasDefined("type")) {
applyReplacements(ctx, k, value.get(k), p, p.get("type").asType(), attachments);
}
}
}
}
break;
}
default:
}
}
use of org.jboss.as.cli.handlers.FilenameTabCompleter in project wildfly-core by wildfly.
the class EmbedServerHandler method create.
static EmbedServerHandler create(final AtomicReference<EmbeddedProcessLaunch> serverReference, CommandContext ctx, boolean modular) {
EmbedServerHandler result = new EmbedServerHandler(serverReference);
final FilenameTabCompleter pathCompleter = FilenameTabCompleter.newCompleter(ctx);
if (!modular) {
result.jbossHome = new FileSystemPathArgument(result, pathCompleter, "--jboss-home");
}
result.stdOutHandling = new ArgumentWithValue(result, new SimpleTabCompleter(new String[] { ECHO, DISCARD_STDOUT }), "--std-out");
result.serverConfig = new ArgumentWithValue(result, "--server-config");
result.dashC = new ArgumentWithValue(result, "-c");
result.dashC.addCantAppearAfter(result.serverConfig);
result.serverConfig.addCantAppearAfter(result.dashC);
result.adminOnly = new ArgumentWithValue(result, SimpleTabCompleter.BOOLEAN, "--admin-only");
result.emptyConfig = new ArgumentWithoutValue(result, "--empty-config");
result.removeExisting = new ArgumentWithoutValue(result, "--remove-existing");
result.removeExisting.addRequiredPreceding(result.emptyConfig);
result.timeout = new ArgumentWithValue(result, "--timeout");
return result;
}
Aggregations