org.springframework.shell.ShellException Java Examples

The following examples show how to use org.springframework.shell.ShellException. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: BootShim.java    From spring-data-dev-tools with Apache License 2.0 6 votes vote down vote up
public BootShim(String[] args, ConfigurableApplicationContext context) {
	this.ctx = context;

	try {
		commandLine = SimpleShellCommandLineOptions.parseCommandLine(args);
	} catch (IOException var5) {
		throw new ShellException(var5.getMessage(), var5);
	}

	this.configureApplicationContext(this.ctx);
	ClassPathBeanDefinitionScanner scanner = new ClassPathBeanDefinitionScanner((BeanDefinitionRegistry) this.ctx);
	if (commandLine.getDisableInternalCommands()) {
		scanner.scan(new String[] { "org.springframework.shell.converters", "org.springframework.shell.plugin.support" });
	} else {
		scanner.scan(new String[] { "org.springframework.shell.commands", "org.springframework.shell.converters",
				"org.springframework.shell.plugin.support" });
	}

}
 
Example #2
Source File: ColumnNameValueConverter.java    From Decision with Apache License 2.0 6 votes vote down vote up
@Override
public ColumnNameValueList convertFromText(String shellValue, Class<?> targetType, String optionContext) {
    String[] keyValueArray = shellValue.split(",");
    ColumnNameValueList result = new ColumnNameValueList();
    for (String keyValueString : keyValueArray) {
        String[] nameValueArray = keyValueString.split("\\.");
        if (nameValueArray.length != 2) {
            throw new ShellException("Error processing (".concat(keyValueString).concat(")"));
        }

        String name = nameValueArray[0].trim();
        String value = nameValueArray[1].trim();
        result.add(new ColumnNameValue(name, value));
    }
    return result;

}
 
Example #3
Source File: ColumnNameTypeConverter.java    From Decision with Apache License 2.0 6 votes vote down vote up
@Override
public ColumnNameTypeList convertFromText(String value, Class<?> targetType, String optionContext) {

    String[] keyValueArray = value.split(",");
    ColumnNameTypeList result = new ColumnNameTypeList();
    for (String keyValueString : keyValueArray) {
        String[] keyTypeArray = keyValueString.split("\\.");
        if (keyTypeArray.length != 2) {
            throw new ShellException("Error processing (".concat(keyValueString).concat(")"));
        }

        String key = keyTypeArray[0].trim();
        String type = keyTypeArray[1].trim();
        try {
            result.add(new ColumnNameType(key, ColumnType.valueOf(type.toUpperCase())));
        } catch (IllegalArgumentException e) {
            StringBuilder sb = new StringBuilder();
            sb.append("Type not found");
            sb.append(" (".concat(type).concat(") "));
            sb.append(" Available types: ".concat(Arrays.asList(ColumnType.values()).toString()));
            throw new ShellException(sb.toString());
        }
    }
    return result;

}
 
Example #4
Source File: StreamListRenderer.java    From Decision with Apache License 2.0 6 votes vote down vote up
@Override
public String render(List<StratioStream> streams) throws ShellException {
    StringBuilder queryTables = new StringBuilder();
    List<Map<String, Object>> data = new ArrayList<>();
    for (StratioStream stratioStream : streams) {
        Map<String, Object> row = new HashMap<>();
        row.put(STREAM_NAME, stratioStream.getStreamName());
        row.put(USER_DEFINED, stratioStream.getUserDefined());
        row.put(QUERIES, stratioStream.getQueries().size());
        row.put(ELEMENTS, stratioStream.getColumns().size());
        row.put(ACTIVE_ACTIONS, stratioStream.getActiveActions().toString());

        queryTables.append(renderQueriesTable(stratioStream.getQueries(), stratioStream.getStreamName()));

        data.add(row);
    }

    StringBuilder result = new StringBuilder();
    result.append(TableRenderer.renderMapDataAsTable(data, columns));
    result.append(OsUtils.LINE_SEPARATOR);
    result.append(queryTables);

    return result.toString();
}
 
Example #5
Source File: BootShim.java    From hdfs-shell with Apache License 2.0 5 votes vote down vote up
public BootShim(String[] args, ConfigurableApplicationContext context) {
    this.ctx = context;
    try {
        commandLine = SimpleShellCommandLineOptions.parseCommandLine(args);
    } catch (IOException var5) {
        throw new ShellException(var5.getMessage(), var5);
    }
    this.configureApplicationContext(this.ctx);
    ClassPathBeanDefinitionScanner scanner = new ClassPathBeanDefinitionScanner((BeanDefinitionRegistry) this.ctx);
    if (commandLine.getDisableInternalCommands()) {
        scanner.scan("org.springframework.shell.converters", "org.springframework.shell.plugin.support");
    } else {
        scanner.scan("org.springframework.shell.commands", "org.springframework.shell.converters", "org.springframework.shell.plugin.support");
    }
}
 
Example #6
Source File: QualifiedApplicationNameConverter.java    From spring-cloud-dashboard with Apache License 2.0 5 votes vote down vote up
@Override
public AppRegistryCommands.QualifiedApplicationName convertFromText(String value, Class<?> targetType, String optionContext) {
	int colonIndex = value.indexOf(':');
	if (colonIndex == -1) {
		throw new ShellException("Incorrect syntax. Valid syntax is '<ApplicationType>:<ApplicationName>'.");
	}
	String applicationType = value.substring(0, colonIndex);
	return new AppRegistryCommands.QualifiedApplicationName(value.substring(colonIndex + 1), applicationType);
}
 
Example #7
Source File: QualifiedApplicationNameConverter.java    From spring-cloud-dataflow with Apache License 2.0 5 votes vote down vote up
@Override
public AppRegistryCommands.QualifiedApplicationName convertFromText(String value, Class<?> targetType,
		String optionContext) {
	int colonIndex = value.indexOf(':');
	if (colonIndex == -1) {
		throw new ShellException("Incorrect syntax. Valid syntax is '<ApplicationType>:<ApplicationName>'.");
	}
	ApplicationType applicationType = ApplicationType.valueOf(value.substring(0, colonIndex));
	return new AppRegistryCommands.QualifiedApplicationName(value.substring(colonIndex + 1), applicationType);
}
 
Example #8
Source File: ShellCommandLineRunner.java    From spring-cloud-dashboard with Apache License 2.0 4 votes vote down vote up
private ExitShellRequest doRun() {
    this.stopWatch.start();
    try {

        String[] commandsToExecuteAndThenQuit = this.commandLine.getShellCommandsToExecute();
        ExitShellRequest exitShellRequest;
        if (null != commandsToExecuteAndThenQuit) {

            boolean successful = false;
            exitShellRequest = ExitShellRequest.FATAL_EXIT;

            for (String cmd : commandsToExecuteAndThenQuit) {
                if (!(successful = this.lineShellComponent.executeCommand(cmd).isSuccess()))
                    break;
            }

            if (successful) {
                exitShellRequest = ExitShellRequest.NORMAL_EXIT;
            }
        }
        else if (this.applicationArguments.containsOption("help")) {
            System.out.println(FileUtils.readBanner(ShellCommandLineRunner.class, "/usage.txt"));
            exitShellRequest = ExitShellRequest.NORMAL_EXIT;
        } else {
            this.lineShellComponent.start();
            this.lineShellComponent.promptLoop();
            exitShellRequest = this.lineShellComponent.getExitShellRequest();
            if (exitShellRequest == null) {
                exitShellRequest = ExitShellRequest.NORMAL_EXIT;
            }
            this.lineShellComponent.waitForComplete();
        }

        if (this.lineShellComponent.isDevelopmentMode()) {
            System.out.println("Total execution time: " + this.stopWatch
                    .getLastTaskTimeMillis() + " ms");
        }

        return exitShellRequest;
    } catch (Exception ex) {
        throw new ShellException(ex.getMessage(), ex);
    } finally {
        HandlerUtils.flushAllHandlers(this.logger);
        this.stopWatch.stop();
    }
}
 
Example #9
Source File: ShellCommandLineRunner.java    From spring-cloud-dataflow with Apache License 2.0 4 votes vote down vote up
private ExitShellRequest doRun() {
	this.stopWatch.start();
	try {

		String[] commandsToExecuteAndThenQuit = this.commandLine.getShellCommandsToExecute();
		ExitShellRequest exitShellRequest;
		if (null != commandsToExecuteAndThenQuit) {

			boolean successful = false;
			exitShellRequest = ExitShellRequest.FATAL_EXIT;

			for (String cmd : commandsToExecuteAndThenQuit) {
				if (!(successful = this.lineShellComponent.executeCommand(cmd).isSuccess()))
					break;
			}

			if (successful) {
				exitShellRequest = ExitShellRequest.NORMAL_EXIT;
			}
		}
		else if (this.applicationArguments.containsOption("help")) {
			System.out.println(FileUtils.readBanner(ShellCommandLineRunner.class, "/usage.txt"));
			exitShellRequest = ExitShellRequest.NORMAL_EXIT;
		}
		else {
			this.lineShellComponent.start();
			this.lineShellComponent.promptLoop();
			exitShellRequest = this.lineShellComponent.getExitShellRequest();
			if (exitShellRequest == null) {
				exitShellRequest = ExitShellRequest.NORMAL_EXIT;
			}
			this.lineShellComponent.waitForComplete();
		}

		if (this.lineShellComponent.isDevelopmentMode()) {
			System.out.println("Total execution time: " + this.stopWatch.getLastTaskTimeMillis() + " ms");
		}

		return exitShellRequest;
	}
	catch (Exception ex) {
		throw new ShellException(ex.getMessage(), ex);
	}
	finally {
		HandlerUtils.flushAllHandlers(this.logger);
		this.stopWatch.stop();
	}
}
 
Example #10
Source File: Renderer.java    From Decision with Apache License 2.0 votes vote down vote up
String render(POJO pojo) throws ShellException;