blob: 818673eb934f7d0298d8225f7d34c3066fba087f [file] [log] [blame]
Thomas Vachuska275d2e82016-07-14 17:41:34 -07001/*
Brian O'Connor0a4e6742016-09-15 23:03:10 -07002 * Copyright 2016-present Open Networking Laboratory
Thomas Vachuska275d2e82016-07-14 17:41:34 -07003 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package org.onosproject.buckdaemon;
18
19import com.google.common.collect.ImmutableList;
20import com.google.common.io.ByteStreams;
21
22import java.io.IOException;
23import java.io.InputStream;
24import java.util.ArrayList;
25import java.util.List;
26
27import static com.google.common.base.Preconditions.checkArgument;
28
29/**
30 * Context for executing a single Buck task.
31 */
32public class BuckTaskContext {
33
34 private final String taskName;
35 private final ImmutableList<String> input;
36 private final List<String> output = new ArrayList<>();
37
38 BuckTaskContext(InputStream inputString) throws IOException {
39 String[] split = new String(ByteStreams.toByteArray(inputString)).split("\n");
40 checkArgument(split.length >= 1, "Request must contain at least task type");
41 this.taskName = split[0];
42 ImmutableList.Builder<String> builder = ImmutableList.builder();
43 for (int i = 1; i < split.length; i++) {
44 builder.add(split[i]);
45 }
46 input = builder.build();
47 }
48
49 /**
50 * Returns the symbolic task name.
51 */
52 public String taskName() {
53 return taskName;
54 }
55
56 /**
57 * Returns the input data a list of strings.
58 *
59 * @return input data
60 */
61 public List<String> input() {
62 return ImmutableList.copyOf(input);
63 }
64
65 /**
66 * Returns the output data a list of strings.
67 *
68 * @return output data
69 */
70 List<String> output() {
71 return ImmutableList.copyOf(output);
72 }
73
74 /**
75 * Adds a line to the output data.
76 *
77 * @param line line of output data
78 */
79 public void output(String line) {
80 output.add(line);
81 }
82
83}