Java Code Examples for org.springframework.shell.support.util.FileUtils

The following examples show how to use org.springframework.shell.support.util.FileUtils. These examples are extracted from open source projects. 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 Project: gemfirexd-oss   Source File: DirConverter.java    License: Apache License 2.0 6 votes vote down vote up
private String convertCompletionBackIntoUserInputStyle(
    final String originalUserInput, final String completion) {
  if (FileUtils.denotesAbsolutePath(originalUserInput)) {
    // Input was originally as a fully-qualified path, so we just keep the
    // completion in that form
    return completion;
  }
  if (originalUserInput.startsWith(HOME_DIRECTORY_SYMBOL)) {
    // Input originally started with this symbol, so replace the user's home
    // directory with it again
    Assert.notNull(home,
        "Home directory could not be determined from system properties");
    return HOME_DIRECTORY_SYMBOL + completion.substring(home.length());
  }
  // The path was working directory specific, so strip the working directory
  // given the user never typed it
  return completion.substring(getWorkingDirectoryAsString().length());
}
 
Example 2
Source Project: gemfirexd-oss   Source File: DirConverter.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * If the user input starts with a tilde character (~), replace the tilde
 * character with the user's home directory. If the user input does not start
 * with a tilde, simply return the original user input without any changes if
 * the input specifies an absolute path, or return an absolute path based on
 * the working directory if the input specifies a relative path.
 * 
 * @param userInput
 *          the user input, which may commence with a tilde (required)
 * @return a string that is guaranteed to no longer contain a tilde as the
 *         first character (never null)
 */
private String convertUserInputIntoAFullyQualifiedPath(final String userInput) {
  if (FileUtils.denotesAbsolutePath(userInput)) {
    // Input is already in a fully-qualified path form
    return userInput;
  }
  if (userInput.startsWith(HOME_DIRECTORY_SYMBOL)) {
    // Replace this symbol with the user's actual home directory
    Assert.notNull(home,
        "Home directory could not be determined from system properties");
    if (userInput.length() > 1) {
      return home + userInput.substring(1);
    }
  }
  // The path is working directory specific, so prepend the working directory
  String fullPath = getWorkingDirectoryAsString() + userInput;
  return fullPath;
}
 
Example 3
Source Project: gemfirexd-oss   Source File: DirConverter.java    License: Apache License 2.0 6 votes vote down vote up
private String convertCompletionBackIntoUserInputStyle(
    final String originalUserInput, final String completion) {
  if (FileUtils.denotesAbsolutePath(originalUserInput)) {
    // Input was originally as a fully-qualified path, so we just keep the
    // completion in that form
    return completion;
  }
  if (originalUserInput.startsWith(HOME_DIRECTORY_SYMBOL)) {
    // Input originally started with this symbol, so replace the user's home
    // directory with it again
    Assert.notNull(home,
        "Home directory could not be determined from system properties");
    return HOME_DIRECTORY_SYMBOL + completion.substring(home.length());
  }
  // The path was working directory specific, so strip the working directory
  // given the user never typed it
  return completion.substring(getWorkingDirectoryAsString().length());
}
 
Example 4
Source Project: gemfirexd-oss   Source File: DirConverter.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * If the user input starts with a tilde character (~), replace the tilde
 * character with the user's home directory. If the user input does not start
 * with a tilde, simply return the original user input without any changes if
 * the input specifies an absolute path, or return an absolute path based on
 * the working directory if the input specifies a relative path.
 * 
 * @param userInput
 *          the user input, which may commence with a tilde (required)
 * @return a string that is guaranteed to no longer contain a tilde as the
 *         first character (never null)
 */
private String convertUserInputIntoAFullyQualifiedPath(final String userInput) {
  if (FileUtils.denotesAbsolutePath(userInput)) {
    // Input is already in a fully-qualified path form
    return userInput;
  }
  if (userInput.startsWith(HOME_DIRECTORY_SYMBOL)) {
    // Replace this symbol with the user's actual home directory
    Assert.notNull(home,
        "Home directory could not be determined from system properties");
    if (userInput.length() > 1) {
      return home + userInput.substring(1);
    }
  }
  // The path is working directory specific, so prepend the working directory
  String fullPath = getWorkingDirectoryAsString() + userInput;
  return fullPath;
}
 
Example 5
@Override
public String getBanner() {

	StringBuilder builder = new StringBuilder();

	builder.append(FileUtils.readBanner(SpringDataReleaseCliBannerProvider.class, "banner.txt"));
	builder.append(getVersion()).append(IOUtils.LINE_SEPARATOR);
	builder.append(IOUtils.LINE_SEPARATOR);

	return builder.toString();
}
 
Example 6
Source Project: Decision   Source File: StratioStreamingBannerProvider.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public String getBanner() {
    StringBuilder sb = new StringBuilder();
    sb.append(FileUtils.readBanner(Main.class, "/banner.txt"));
    sb.append(OsUtils.LINE_SEPARATOR);
    sb.append("Connection urls: " + OsUtils.LINE_SEPARATOR);
    sb.append("    - Kafka: " + kafkaBrokers);
    sb.append("    - Zookeeper: " + zkQuorum);
    sb.append(OsUtils.LINE_SEPARATOR);
    return sb.toString();
}
 
Example 7
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 8
@Override
public String getBanner() {
	return FileUtils.readBanner(DataFlowBannerProvider.class, "/dataflow-banner.txt") +
			"\n" + getVersion() + "\n";
}
 
Example 9
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
@Override
public String getBanner() {
	return FileUtils.readBanner(DataFlowBannerProvider.class, "/dataflow-banner.txt") + "\n" + getVersion() + "\n";
}
 
Example 11
Source Project: ambari-shell   Source File: AmbariBanner.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public String getBanner() {
  return FileUtils.readBanner(AmbariShell.class, "banner.txt");
}
 
Example 12
Source Project: ambari-shell   Source File: ElephantCommand.java    License: Apache License 2.0 2 votes vote down vote up
/**
 * Prints an elephant to the console.
 *
 * @return elephant
 */
@CliCommand(value = "hello", help = "Prints a simple elephant to the console")
public String simple() {
  return FileUtils.readBanner(AmbariShell.class, "elephant.txt");
}