1 of 2

Name:

PID: (page 1)

  1. class Grade {
  2. static String grade(String repo) throws IOException {
  3. String CPATH = ".:lib/hamcrest-core-1.3.jar:lib/junit-4.13.2.jar";
  4. String r = "";
  5. String[][] cmds = {
  6. {"rm", "-rf", "student-submission"},
  7. {"git", "clone", repo, "student-submission"},
  8. {"echo", "Finished cloning"},
  9. {"cp", "student-submission/ListExamples.java", "./"},
  10. {"bash", "-c", "javac -cp " + CPATH + "*.java"},
  11. {"java", "-cp", CPATH, "org.junit.runner.JUnitCore", "TestListExamples"}
  12. };
  13. for (String[] cmd: cmds) {
  14. r += ExecHelpers.exec(cmd);
  15. }
  16. return r;
  17. }
  18. public static void main(String[] args) throws IOException {
  19. System.out.println(grade(args[0]));
  20. }
  21. }

$ java Grade "https://github.com/ucsd-cse15l-f22/list-methods-lab3"

Cloning into 'student-submission'...

Finished cloning

error: no source files

....

1) initializationError(org.junit.runner.JUnitCommandLineParseResult)

java.lang.IllegalArgumentException: Could not find class [TestListExamples]

...

What is the symptom? What is the failure-inducing input? What is the bug?

Most importantly, what can we do to gather more information to help us understand the issue? What information can we not see, and how can we make it visible to us?

exec(new String[]{"ls", "*.java"}) vs. exec(new String[]{"bash", "-c", "ls *.java"})

Discuss: Now that we have exec(), do we need bash anymore? Can we just write everything in Java?

2 of 2

Name:

PID: (page 2)

class Handler implements URLHandler {

public String handleRequest(URI url) throws IOException {

if (url.getPath().equals("/grade")) {

String[] parameters = url.getQuery().split("=");

if (parameters[0].equals("repo")) {

String[] cmd = {"bash", "grade.sh", parameters[1]};

String result = ExecHelpers.exec(cmd);

return result;

...

CPATH='.:lib/hamcrest-core-1.3.jar:lib/junit-4.13.2.jar'

rm -rf student-submission

git clone $1 student-submission

echo 'Finished cloning'

cp student-submission/ListExamples.java ./

javac -cp $CPATH *.java

java -cp $CPATH org.junit.runner.JUnitCore TestListExamples

is handled by...

which starts this script...

which clones, compiles, and runs tests, and stores output in the result

which returns the

output shown in the

browser

static String exec(String[] cmd) … {

...

InputStream outputOfBash = p.getInputStream();

return String.format("%s\n", streamToString(outputOfBash));

...

How many total processes do you count as being involved in handling this request?

What is parameters[1] for this request?

grade.sh

GradeServer.java

What methods were waiting for return values on the Java stack while the bash script was running?

GradeServer.java