Skip to content

Commit cf24f22

Browse files
committed
Deploy staging codeckeck-quarkus
1 parent 9c5be8a commit cf24f22

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+615
-2500
lines changed

app/com/horstmann/codecheck/CLanguage.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ public boolean isSource(Path p) {
2222
private static Pattern MAIN_PATTERN = Pattern.compile("\\s*((int|void)\\s+)?main\\s*\\([^)]*\\)\\s*(\\{\\s*)?");
2323
@Override public Pattern mainPattern() { return MAIN_PATTERN; }
2424

25-
private static Pattern VARIABLE_PATTERN = Pattern.compile(".*\\S\\s+(?<name>[A-Za-z][A-Za-z0-9]*)(\\s*[*\\[\\]]+)?\\s*=\\s*(?<rhs>[^;]+);.*");
25+
private static Pattern VARIABLE_PATTERN = Pattern.compile(".*\\S\\s+(?<name>[A-Za-z][A-Za-z0-9_]*)(\\s*[*\\[\\]]+)?\\s*=\\s*(?<rhs>[^;]+);.*");
2626
@Override public Pattern variableDeclPattern() { return VARIABLE_PATTERN; }
2727

2828
private static Pattern ERROR_PATTERN = Pattern.compile(".+/(?<file>[^/]+\\.cpp):(?<line>[0-9]+):(?<col>[0-9]+): error: (?<msg>.+)");

app/com/horstmann/codecheck/DartLanguage.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ public class DartLanguage implements Language {
1717
@Override public Pattern mainPattern() { return MAIN_PATTERN; }
1818

1919
private static Pattern VARIABLE_DECL_PATTERN
20-
= Pattern.compile(".*\\S\\s+(?<name>[A-Za-z][A-Za-z0-9]*)(\\s*[*\\[\\]]+)?\\s*=\\s*(?<rhs>[^;]+);");
20+
= Pattern.compile(".*\\S\\s+(?<name>[A-Za-z][A-Za-z0-9_]*)(\\s*[*\\[\\]]+)?\\s*=\\s*(?<rhs>[^;]+);");
2121
@Override public Pattern variableDeclPattern() { return VARIABLE_DECL_PATTERN; }
2222

2323
private static Pattern ERROR_PATTERN = Pattern.compile(".+/(?<file>[^/]+\\.cpp):(?<line>[0-9]+):(?<col>[0-9]+): error: (?<msg>.+)");

app/com/horstmann/codecheck/HTMLReport.java

+1-14
Original file line numberDiff line numberDiff line change
@@ -189,23 +189,10 @@ public HTMLReport systemError(Throwable t) {
189189
* @see com.horstmann.codecheck.Report#image(java.lang.String, byte[])
190190
*/
191191
@Override
192-
public HTMLReport image(String captionText, BufferedImage img) {
192+
public HTMLReport image(String captionText, String filename, BufferedImage img) {
193193
if (img == null)
194194
return this;
195195
caption(captionText);
196-
image(img);
197-
return this;
198-
}
199-
200-
/*
201-
* (non-Javadoc)
202-
*
203-
* @see com.horstmann.codecheck.Report#image(byte[])
204-
*/
205-
@Override
206-
public HTMLReport image(BufferedImage img) {
207-
if (img == null)
208-
return this;
209196
try {
210197
ByteArrayOutputStream out = new ByteArrayOutputStream();
211198
ImageIO.write(img, "PNG", out);

app/com/horstmann/codecheck/JSONReport.java

+7-24
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,6 @@
44
import java.io.ByteArrayOutputStream;
55
import java.io.IOException;
66
import java.io.UncheckedIOException;
7-
import java.nio.ByteBuffer;
8-
import java.nio.charset.CharacterCodingException;
9-
import java.nio.charset.StandardCharsets;
107
import java.util.ArrayList;
118
import java.util.Base64;
129
import java.util.HashMap;
@@ -17,10 +14,6 @@
1714

1815
import javax.imageio.ImageIO;
1916

20-
import com.fasterxml.jackson.annotation.JsonInclude.Include;
21-
import com.fasterxml.jackson.core.JsonProcessingException;
22-
import com.fasterxml.jackson.databind.ObjectMapper;
23-
2417
public class JSONReport implements Report {
2518
public static class Item {
2619
public Item() {}
@@ -39,9 +32,10 @@ public Item(String name, String contents, boolean hidden) {
3932

4033
public static class ImageItem {
4134
public ImageItem() {}
42-
public ImageItem(String caption, BufferedImage image) {
35+
public ImageItem(String caption, String filename, BufferedImage image) {
4336
this.caption = caption;
44-
try {
37+
name = filename;
38+
try {
4539
ByteArrayOutputStream out = new ByteArrayOutputStream();
4640
ImageIO.write(image, "PNG", out);
4741
out.close();
@@ -51,6 +45,7 @@ public ImageItem(String caption, BufferedImage image) {
5145
}
5246
}
5347
public String caption;
48+
public String name;
5449
public String data;
5550
}
5651

@@ -193,17 +188,11 @@ public JSONReport input(String input) {
193188
}
194189

195190
@Override
196-
public JSONReport image(String caption, BufferedImage image) {
197-
if (image != null) run.images.add(new ImageItem(caption, image));
191+
public JSONReport image(String caption, String filename, BufferedImage image) {
192+
if (image != null) run.images.add(new ImageItem(caption, filename, image));
198193
return this;
199194
}
200195

201-
@Override
202-
public JSONReport image(BufferedImage image) {
203-
image("", image);
204-
return this;
205-
}
206-
207196
@Override
208197
public JSONReport file(String file, String contents) {
209198
if (!"studentFiles".equals(section.type)) {
@@ -237,13 +226,7 @@ public JSONReport add(Score score) {
237226

238227
@Override
239228
public String getText() {
240-
ObjectMapper mapper = new ObjectMapper();
241-
mapper.setSerializationInclusion(Include.NON_DEFAULT);
242-
try {
243-
return mapper.writeValueAsString(data);
244-
} catch (JsonProcessingException e) {
245-
return null;
246-
}
229+
return Util.toJsonString(data);
247230
}
248231

249232
@Override

app/com/horstmann/codecheck/JavaScriptLanguage.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,6 @@ public Map<Path, String> writeTester(Path file, String contents, List<Call> call
5959
}
6060

6161
private static Pattern VARIABLE_DECL_PATTERN = Pattern.compile(
62-
"(var|const|let)\\s+(?<name>[A-Za-z][A-Za-z0-9]*)\\s*=(?<rhs>[^;]+);?");
62+
"(var|const|let)\\s+(?<name>[A-Za-z][A-Za-z0-9_]*)\\s*=(?<rhs>[^;]+);?");
6363
@Override public Pattern variableDeclPattern() { return VARIABLE_DECL_PATTERN; }
6464
}

app/com/horstmann/codecheck/Main.java

+5-5
Original file line numberDiff line numberDiff line change
@@ -305,7 +305,7 @@ private void testInput(Path mainFile,
305305
for (String f : outFiles) {
306306
if (CompareImages.isImage(f)) {
307307
CompareImages ci = imageComp.get(f);
308-
report.image(null, ci.first());
308+
report.image(null, f, ci.first());
309309
}
310310
else
311311
report.file(f, contents.get(f));
@@ -321,11 +321,11 @@ private void testInput(Path mainFile,
321321
ic.setOtherImage(plan.getOutputBytes(solutionRunID, f));
322322
boolean outcome = ic.getOutcome();
323323
if (outcome) {
324-
report.image(outFiles.size() > 1 ? f : null, ic.first());
324+
report.image(outFiles.size() > 1 ? f : null, f, ic.first());
325325
} else {
326-
report.image(outFiles.size() > 1 ? f : "Actual", ic.first());
327-
report.image("Expected", ic.other());
328-
report.image("Mismatched pixels", ic.diff());
326+
report.image(outFiles.size() > 1 ? f : "Actual", f, ic.first());
327+
report.image("Expected", null, ic.other());
328+
report.image("Mismatched pixels", null, ic.diff());
329329
}
330330
score.pass(outcome, report);
331331
} catch (IOException ex) {

app/com/horstmann/codecheck/MatlabLanguage.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,6 @@ public String[] pseudoCommentDelimiters() {
6464
}
6565

6666
private static Pattern VARIABLE_DECL_PATTERN = Pattern.compile(
67-
"(?<name>[A-Za-z][A-Za-z0-9]*)\\s*=\\s*(?<rhs>.+)");
67+
"(?<name>[A-Za-z][A-Za-z0-9_]*)\\s*=\\s*(?<rhs>.+)");
6868
@Override public Pattern variableDeclPattern() { return VARIABLE_DECL_PATTERN; }
6969
}

app/com/horstmann/codecheck/NJSReport.java

+1-11
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,6 @@
55
import java.util.List;
66
import java.util.Map;
77

8-
import com.fasterxml.jackson.annotation.JsonInclude.Include;
9-
import com.fasterxml.jackson.core.JsonProcessingException;
10-
import com.fasterxml.jackson.databind.ObjectMapper;
11-
128
public class NJSReport extends HTMLReport {
139
public static class ReportData {
1410
public List<Error> errors = new ArrayList<>();
@@ -58,13 +54,7 @@ public NJSReport errors(List<Error> errors) {
5854

5955
@Override
6056
public String getText() {
61-
ObjectMapper mapper = new ObjectMapper();
62-
mapper.setSerializationInclusion(Include.NON_DEFAULT);
63-
try {
64-
return mapper.writeValueAsString(data);
65-
} catch (JsonProcessingException e) {
66-
return null;
67-
}
57+
return Util.toJsonString(data);
6858
}
6959

7060
@Override

app/com/horstmann/codecheck/PHPLanguage.java

+1-2
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
import java.io.IOException;
44
import java.nio.file.Path;
55
import java.util.ArrayList;
6-
import java.util.Collection;
76
import java.util.LinkedHashMap;
87
import java.util.List;
98
import java.util.Map;
@@ -46,7 +45,7 @@ public Map<Path, String> writeTester(Path file, String contents, List<Call> call
4645
}
4746

4847
private static Pattern VARIABLE_DECL_PATTERN = Pattern.compile(
49-
"^\\s*(?<name>\\$[A-Za-z][A-Za-z0-9]*)\\s*=(?<rhs>[^;]+);");
48+
"^\\s*(?<name>\\$[A-Za-z][A-Za-z0-9_]*)\\s*=(?<rhs>[^;]+);");
5049
@Override public Pattern variableDeclPattern() { return VARIABLE_DECL_PATTERN; }
5150

5251
public boolean isUnitTest(Path fileName) { return fileName.toString().matches(".*(T|_t)est[0-9]*.php"); }

app/com/horstmann/codecheck/PythonLanguage.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ public String[] pseudoCommentDelimiters() {
7878
return new String[] { "##", "" };
7979
}
8080

81-
private static Pattern varPattern = Pattern.compile("(?<name>[A-Za-z][A-Za-z0-9]*)\\s*=\\s*(?<rhs>.+)");
81+
private static Pattern varPattern = Pattern.compile("(?<name>[A-Za-z][A-Za-z0-9_]*)\\s*=\\s*(?<rhs>.+)");
8282
@Override public Pattern variableDeclPattern() { return varPattern; }
8383

8484
private static Pattern errPattern = Pattern.compile("(?<msg>.*)[\"(](?<file>[A-Za-z0-9_]+\\.py)\"?, line (?<line>[0-9]+).*");

app/com/horstmann/codecheck/RacketLanguage.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ public Map<Path, String> writeTester(Path file, String contents, List<Calls.Call
7373
// CAUTION: Because the rhs is likely to contain (), there must be a space
7474
// before the final ), e.g. (define l '(1 2 3) )
7575
private static Pattern VARIABLE_DECL_PATTERN = Pattern.compile(
76-
"\\(\\s*define\\s+(?<name>[A-Za-z][A-Za-z0-9]*)\\s+(?<rhs>.+)\\s+\\)");
76+
"\\(\\s*define\\s+(?<name>[A-Za-z][A-Za-z0-9_]*)\\s+(?<rhs>.+)\\s+\\)");
7777
@Override public Pattern variableDeclPattern() { return VARIABLE_DECL_PATTERN; }
7878

7979

app/com/horstmann/codecheck/Report.java

+2-3
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,8 @@ default Report condition(boolean passed, boolean forbidden, Path path, String re
3535
return this;
3636
}
3737

38-
Report image(String caption, BufferedImage image);
39-
Report image(BufferedImage image);
40-
38+
Report image(String caption, String filename, BufferedImage image);
39+
4140
Report file(String file, String contents);
4241
Report file(String file, byte[] contents, boolean hidden);
4342

app/com/horstmann/codecheck/RustLanguage.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ public class RustLanguage implements Language {
1313
private static Pattern mainPattern = Pattern.compile("fn\\s+main\\s*\\([^)]*\\)\\s*(\\{\\s*)?");
1414
@Override public Pattern mainPattern() { return mainPattern; }
1515

16-
private static Pattern VARIABLE_DECL_PATTERN =Pattern.compile("let\\s*(mut\\s*)?(?<name>[A-Za-z][A-Za-z0-9]*)\\s*(:\\s*(((i|u)(8|16|32|64|128|size))|(f32|f64|bool|char)|(\\[(((i|u)(8|16|32|64|128|size))|(f32|f64|bool|char))\\s*;\\s*[0-9]*\\s*\\]))\\s*)?=\\s*(?<rhs>.+);\\s*");
16+
private static Pattern VARIABLE_DECL_PATTERN =Pattern.compile("let\\s*(mut\\s*)?(?<name>[A-Za-z][A-Za-z0-9_]*)\\s*(:\\s*(((i|u)(8|16|32|64|128|size))|(f32|f64|bool|char)|(\\[(((i|u)(8|16|32|64|128|size))|(f32|f64|bool|char))\\s*;\\s*[0-9]*\\s*\\]))\\s*)?=\\s*(?<rhs>.+);\\s*");
1717
@Override public Pattern variableDeclPattern() { return VARIABLE_DECL_PATTERN; }
1818

1919
@Override

app/com/horstmann/codecheck/SetupReport.java

+4-8
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,7 @@
1111
import java.util.List;
1212
import java.util.Map;
1313

14-
import com.fasterxml.jackson.annotation.JsonInclude.Include;
1514
import com.fasterxml.jackson.databind.JsonNode;
16-
import com.fasterxml.jackson.databind.ObjectMapper;
1715
import com.fasterxml.jackson.databind.node.JsonNodeFactory;
1816
import com.fasterxml.jackson.databind.node.ObjectNode;
1917

@@ -70,12 +68,10 @@ public void setProblem(Problem problem) {
7068
}
7169
data.metaData.clear();
7270
data.score = null;
73-
ObjectMapper mapper = new ObjectMapper();
74-
mapper.setSerializationInclusion(Include.NON_DEFAULT);
75-
ObjectNode dataNode = (ObjectNode) mapper.convertValue(data, JsonNode.class);
71+
ObjectNode dataNode = Util.toJson(data);
7672
if (problem != null) {
7773
Problem.DisplayData displayData = problem.getProblemData();
78-
ObjectNode problemNode = (ObjectNode) mapper.convertValue(displayData, JsonNode.class);
74+
ObjectNode problemNode = Util.toJson(displayData);
7975
Iterator<Map.Entry<String, JsonNode>> fields = problemNode.fields();
8076
while (fields.hasNext()) {
8177
Map.Entry<String, JsonNode> entry = fields.next();
@@ -100,10 +96,10 @@ public void setProblem(Problem problem) {
10096
dataNode.set("hiddenFiles", hiddenFiles);
10197
}
10298
if (!attributes.isEmpty()) {
103-
dataNode.set("attributes", mapper.convertValue(attributes, JsonNode.class));
99+
dataNode.set("attributes", Util.toJson(attributes));
104100
}
105101
if (!conditions.isEmpty()) {
106-
dataNode.set("conditions", mapper.convertValue(conditions, JsonNode.class));
102+
dataNode.set("conditions", Util.toJson(conditions));
107103
}
108104
}
109105
return dataNode.toString();

app/com/horstmann/codecheck/TextReport.java

+1-16
Original file line numberDiff line numberDiff line change
@@ -166,22 +166,7 @@ public TextReport systemError(Throwable t) {
166166
* @see com.horstmann.codecheck.Report#image(java.lang.String, byte[])
167167
*/
168168
@Override
169-
public TextReport image(String captionText, BufferedImage img) {
170-
image(img);
171-
return this;
172-
}
173-
174-
@Override
175-
public TextReport image(BufferedImage image) {
176-
/*
177-
try {
178-
imageCount++;
179-
Path out = dir.resolve("report" + imageCount + ".png");
180-
ImageIO.write(image, "PNG", out.toFile());
181-
} catch (IOException ex) {
182-
error("No image");
183-
}
184-
*/
169+
public TextReport image(String captionText, String filename, BufferedImage img) {
185170
return this;
186171
}
187172

app/com/horstmann/codecheck/Util.java

+34-3
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,12 @@
4545
import java.util.zip.ZipInputStream;
4646
import java.util.zip.ZipOutputStream;
4747

48+
import com.fasterxml.jackson.annotation.JsonInclude.Include;
49+
import com.fasterxml.jackson.core.JsonProcessingException;
50+
import com.fasterxml.jackson.databind.JsonNode;
51+
import com.fasterxml.jackson.databind.ObjectMapper;
52+
import com.fasterxml.jackson.databind.node.ObjectNode;
53+
4854
public class Util {
4955
private static Random generator = new Random();
5056

@@ -394,7 +400,7 @@ public FileVisitResult visitFile(Path file,
394400
public static byte[] fileUpload(String urlString, String fieldName, String fileName, byte[] bytes) throws IOException {
395401
final int TIMEOUT = 90000; // 90 seconds
396402
String boundary = "===" + createPrivateUID() + "===";
397-
URL url = new URL(urlString);
403+
URL url = URI.create(urlString).toURL();
398404
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
399405
conn.setConnectTimeout(TIMEOUT);
400406
conn.setReadTimeout(TIMEOUT);
@@ -444,7 +450,7 @@ public static byte[] fileUpload(String urlString, String fieldName, String fileN
444450
public static String httpPost(String urlString, String content, String contentType) {
445451
StringBuilder result = new StringBuilder();
446452
try {
447-
URL url = new URL(urlString);
453+
URL url = URI.create(urlString).toURL();
448454
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
449455
connection.setRequestProperty("Content-Type", contentType);
450456
connection.setDoOutput(true);
@@ -528,7 +534,7 @@ public static Map<String, String> getParams(String url)
528534
public static boolean exists(String url) {
529535
boolean result = false;
530536
try {
531-
HttpURLConnection conn = (HttpURLConnection) new URL(url).openConnection();
537+
HttpURLConnection conn = (HttpURLConnection) URI.create(url).toURL().openConnection();
532538
try {
533539
conn.connect();
534540
result = conn.getHeaderField(null).contains("200");
@@ -592,4 +598,29 @@ private static boolean isBadWord(String word){
592598
public static boolean isPronouncableUID(String s) {
593599
return s.matches("(([aeiouy][bcdfghjklmnpqrstvwxz]){2}|([bcdfghjklmnpqrstvwxz][aeiouy]){2})(-(([aeiouy][bcdfghjklmnpqrstvwxz]){2}|([bcdfghjklmnpqrstvwxz][aeiouy]){2})){3}");
594600
}
601+
602+
private static ObjectMapper mapper = new ObjectMapper();
603+
static {
604+
mapper.setSerializationInclusion(Include.NON_DEFAULT);
605+
}
606+
607+
public static ObjectNode toJson(Object obj) {
608+
return (ObjectNode) mapper.convertValue(obj, JsonNode.class);
609+
}
610+
611+
public static String toJsonString(Object obj) {
612+
try {
613+
return mapper.writeValueAsString(obj);
614+
} catch (JsonProcessingException e) {
615+
return null;
616+
}
617+
}
618+
619+
public static ObjectNode fromJsonString(String jsonString) throws JsonProcessingException {
620+
return (ObjectNode) mapper.readTree(jsonString);
621+
}
622+
623+
public static ObjectNode fromJsonString(byte[] jsonStringBytes) throws JsonProcessingException, IOException {
624+
return (ObjectNode) mapper.readTree(jsonStringBytes);
625+
}
595626
}

0 commit comments

Comments
 (0)