use of com.google.devtools.build.lib.shell.ShellUtils.TokenizationException in project bazel by bazelbuild.
the class RunUnderConverter method convert.
@Override
public RunUnder convert(final String input) throws OptionsParsingException {
final List<String> runUnderList = new ArrayList<>();
try {
ShellUtils.tokenize(runUnderList, input);
} catch (TokenizationException e) {
throw new OptionsParsingException("Not a valid command prefix " + e.getMessage());
}
if (runUnderList.isEmpty()) {
throw new OptionsParsingException("Empty command");
}
final String runUnderCommand = runUnderList.get(0);
if (runUnderCommand.startsWith("//")) {
try {
final Label runUnderLabel = Label.parseAbsolute(runUnderCommand);
return new RunUnderLabel(input, runUnderLabel, runUnderList);
} catch (LabelSyntaxException e) {
throw new OptionsParsingException("Not a valid label " + e.getMessage());
}
} else {
return new RunUnderCommand(input, runUnderCommand, runUnderList);
}
}
use of com.google.devtools.build.lib.shell.ShellUtils.TokenizationException in project bazel by bazelbuild.
the class OptionFileExpander method expandArgument.
/**
* Expands a single argument, expanding options &at;filename to read in
* the content of the file and add it to the list of processed arguments.
*
* @param arg the argument to pre-process.
* @param expanded the List of pre-processed arguments.
* @throws IOException if one of the files containing options cannot be read.
*/
private void expandArgument(String arg, List<String> expanded) throws IOException {
if (arg.startsWith("@")) {
InputStream in = fileSystem.getInputStream(arg.substring(1));
try {
// ShellUtils doesn't support them either.
for (String line : readAllLines(new InputStreamReader(in, ISO_8859_1))) {
List<String> parsedTokens = new ArrayList<>();
try {
ShellUtils.tokenize(parsedTokens, line);
} catch (TokenizationException e) {
throw new IOException("Could not tokenize parameter file!", e);
}
for (String token : parsedTokens) {
expandArgument(token, expanded);
}
}
InputStream inToClose = in;
in = null;
inToClose.close();
} finally {
if (in != null) {
try {
in.close();
} catch (IOException e) {
// Ignore the exception. It can only occur if an exception already
// happened and in that case, we want to preserve the original one.
}
}
}
} else {
expanded.add(arg);
}
}
Aggregations