From 430b1748f535d3e5af3b2b55e1f7871c95ae4cad Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maximilian=20Pa=C3=9F?= <22845248+mpass99@users.noreply.github.com> Date: Mon, 18 Apr 2022 15:43:36 +0200 Subject: [PATCH] Allow the CR character as part of a newline. Since CodeOcean may send the `\r\n` newline. --- .../main/java/poseidon/SimpleMakefile.java | 2 +- .../java/poseidon/SimpleMakefileTest.java | 26 +++++++++++++++++++ internal/runner/aws_runner.go | 1 + 3 files changed, 28 insertions(+), 1 deletion(-) diff --git a/deploy/aws/java11Exec/src/main/java/poseidon/SimpleMakefile.java b/deploy/aws/java11Exec/src/main/java/poseidon/SimpleMakefile.java index d59e5a5..316a694 100644 --- a/deploy/aws/java11Exec/src/main/java/poseidon/SimpleMakefile.java +++ b/deploy/aws/java11Exec/src/main/java/poseidon/SimpleMakefile.java @@ -24,7 +24,7 @@ class SimpleMakefile { private static final Pattern isMakeCommand = Pattern.compile("^make(?:\\s+(?\\w*))?$"); // This pattern identifies the rules in a makefile. - private static final Pattern makeRules = Pattern.compile("(?.*):\\n(?(?:\\t.+\\n?)*)"); + private static final Pattern makeRules = Pattern.compile("(?.*):\\r?\\n(?(?:\\t.+\\r?\\n?)*)"); // The first rule of the makefile. private String firstRule = null; diff --git a/deploy/aws/java11Exec/src/test/java/poseidon/SimpleMakefileTest.java b/deploy/aws/java11Exec/src/test/java/poseidon/SimpleMakefileTest.java index ac183b9..bc1e78e 100644 --- a/deploy/aws/java11Exec/src/test/java/poseidon/SimpleMakefileTest.java +++ b/deploy/aws/java11Exec/src/test/java/poseidon/SimpleMakefileTest.java @@ -22,6 +22,15 @@ public class SimpleMakefileTest { "\techo Hi\n" ).getBytes(StandardCharsets.UTF_8)); + static final String SuccessfulWindowsMakefile = Base64.getEncoder().encodeToString( + ("run:\r\n" + + "\tjavac org/example/RecursiveMath.java\r\n" + + "\tjava org/example/RecursiveMath\r\n" + + "\r\n" + + "test:\r\n" + + "\techo Hi\r\n" + ).getBytes(StandardCharsets.UTF_8)); + static final String NotSupportedMakefile = Base64.getEncoder().encodeToString( ("run: test\n" + "\tjavac org/example/RecursiveMath.java\n" + @@ -48,6 +57,23 @@ public class SimpleMakefileTest { } } + @Test + public void sucessfullMakeWithCR() { + Map files = new HashMap<>(); + files.put("Makefile", SuccessfulWindowsMakefile); + files.put("org/example/RecursiveMath.java", RecursiveMathContent); + + try { + String command = "make run"; + SimpleMakefile makefile = new SimpleMakefile(files); + String cmd = makefile.parseCommand(command); + + assertEquals("javac org/example/RecursiveMath.java && java org/example/RecursiveMath", cmd); + } catch (NoMakefileFoundException | InvalidMakefileException | NoMakeCommandException ignored) { + fail(); + } + } + @Test public void withoutMake() { Map files = new HashMap<>(); diff --git a/internal/runner/aws_runner.go b/internal/runner/aws_runner.go index 318c456..037fdb5 100644 --- a/internal/runner/aws_runner.go +++ b/internal/runner/aws_runner.go @@ -127,6 +127,7 @@ func (w *AWSFunctionWorkload) executeCommand(ctx context.Context, command []stri Cmd: command, Files: w.fs, } + log.WithField("request", data).Trace("Sending request to AWS") rawData, err := json.Marshal(data) if err != nil { exit <- ExitInfo{uint8(1), fmt.Errorf("cannot stingify aws function request: %w", err)}