use of com.google.devtools.build.lib.worker.ExampleWorkerOptions.ExampleWorkOptions in project bazel by bazelbuild.
the class ExampleWorker method processRequest.
private static void processRequest(List<String> args) throws Exception {
ImmutableList.Builder<String> expandedArgs = ImmutableList.builder();
for (String arg : args) {
Matcher flagFileMatcher = FLAG_FILE_PATTERN.matcher(arg);
if (flagFileMatcher.matches()) {
expandedArgs.addAll(Files.readAllLines(Paths.get(flagFileMatcher.group(1)), UTF_8));
} else {
expandedArgs.add(arg);
}
}
OptionsParser parser = OptionsParser.newOptionsParser(ExampleWorkOptions.class);
parser.setAllowResidue(true);
parser.parse(expandedArgs.build());
ExampleWorkOptions options = parser.getOptions(ExampleWorkOptions.class);
List<String> outputs = new ArrayList<>();
if (options.writeUUID) {
outputs.add("UUID " + workerUuid.toString());
}
if (options.writeCounter) {
outputs.add("COUNTER " + workUnitCounter++);
}
String residueStr = Joiner.on(' ').join(parser.getResidue());
if (options.uppercase) {
residueStr = residueStr.toUpperCase();
}
outputs.add(residueStr);
if (options.printInputs) {
for (Entry<String, String> input : inputs.entrySet()) {
outputs.add("INPUT " + input.getKey() + " " + input.getValue());
}
}
if (options.printEnv) {
for (Entry<String, String> entry : System.getenv().entrySet()) {
outputs.add(entry.getKey() + "=" + entry.getValue());
}
}
String outputStr = Joiner.on('\n').join(outputs);
if (options.outputFile.isEmpty()) {
System.out.println(outputStr);
} else {
try (PrintStream outputFile = new PrintStream(options.outputFile)) {
outputFile.println(outputStr);
}
}
}
Aggregations