Skip to content

Commit

Permalink
Merge pull request #3 from UQTools/gradescope
Browse files Browse the repository at this point in the history
Gradescope
  • Loading branch information
maxcmiller authored Oct 5, 2020
2 parents 88ec092 + 8e6b013 commit b59631d
Show file tree
Hide file tree
Showing 540 changed files with 43,545 additions and 5,463 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/gradle.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Gradle Build and Test
name: Gradle Build

on: [push, pull_request]

Expand All @@ -15,8 +15,8 @@ jobs:
- name: Setup Java
uses: actions/setup-java@v1
with:
java-version: 14
java-version: 11
- name: Run Gradle Test
uses: eskatos/gradle-command-action@v1
with:
arguments: test
arguments: test --debug
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ jobs:
- name: Setup Java
uses: actions/setup-java@v1
with:
java-version: 14
java-version: 11
- name: Checkout Repository
uses: actions/checkout@master
- name: Generate Artifacts
Expand Down
7 changes: 6 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,9 @@ docs/
## VSCode Bullshit
.classpath
.project
.settings
.settings

*.pyc

!test/resources/csse2002/lib/hamcrest-core-1.3.jar
!test/resources/csse2002/lib/junit-4.12.jar
29 changes: 26 additions & 3 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,41 @@ plugins {
id 'org.openjfx.javafxplugin' version '0.0.8'
}

sourceCompatibility = 1.13
targetCompatibility = 1.13
sourceCompatibility = 1.11
targetCompatibility = 1.11

repositories {
mavenCentral()
}

javafx {
version = "14"
version = "11"
modules = [ 'javafx.controls', 'javafx.base', 'javafx.fxml', 'javafx.graphics', 'javafx.media']
}

sourceSets {
main {
java {
srcDir 'src'
}
}

test {
java {
srcDir 'test/chalkbox'
}
resources {
srcDirs "test/resources"
exclude "**/*.java"
}
}
}

sourceSets.test.resources

dependencies {
testCompile group: 'junit', name: 'junit', version: '4.12'
compile group: 'junit', name: 'junit', version: '4.12'
// Library for JSON
compile group: 'com.googlecode.json-simple', name: 'json-simple', version: '1.1'
// Command line argument parsing
Expand All @@ -31,6 +52,8 @@ dependencies {
compile group: 'org.apache.commons', name: 'commons-io', version: '1.3.2'
// Library for parsing the java AST
compile 'com.github.javaparser:javaparser-core:3.5.2'
// YAML parser
compile group: 'org.yaml', name: 'snakeyaml', version: '1.26'

// V2 Dependencies
implementation 'info.picocli:picocli:4.2.0'
Expand Down
22 changes: 22 additions & 0 deletions src/chalkbox/api/ChalkBox.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package chalkbox.api;

import chalkbox.engines.ConfigFormatException;
import chalkbox.engines.Engine;
import chalkbox.engines.EngineLoader;

public class ChalkBox {
private static final String USAGE = "Incorrect usage:" + System.lineSeparator()
+ "\tchalkbox <box file>" + System.lineSeparator()
+ "\tchalkbox help <class>";

public static void main(String[] args) throws ConfigFormatException {

if (args.length != 1) {
System.err.println(USAGE);
return;
}

Engine engine = EngineLoader.load(args[0]);
engine.run();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import java.security.NoSuchAlgorithmException;
import java.util.ArrayList;
import java.util.Base64;
import java.util.Collections;
import java.util.List;
import java.util.stream.Stream;

Expand Down Expand Up @@ -99,6 +100,7 @@ public List<String> getClasses(String sourceRoot) {
for (String filename : sources.getFileNames(".java")) {
classes.add(getClassName(filename));
}
Collections.sort(classes); // deterministic order (alphabetical)
return classes;
}

Expand Down Expand Up @@ -127,7 +129,7 @@ public String getClassName(String filePath) {
if (filePath.startsWith("/test/")) {
filePath = filePath.replace("/test/", "");
}
return filePath.replace(".java", "")
return filePath.replace(".java", "").replace("/", ".")
.replace(File.separator, ".");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@ public Data getResults() {
return results;
}

public void setWorking(Bundle working) {
this.working = working;
}

@Override
public String toString() {
return results.toString() + " " + source.toString() + " " + working.toString();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,15 @@ public void set(String key, Object value) {
json.put(keys[keys.length - 1].replace("\\.", "."), value);
}

/**
* Deletes the value at the given key.
*
* @param key key to delete value at
*/
public void delete(String key) {
this.json.remove(key);
}

@Override
public String toString() {
return this.json.toJSONString();
Expand Down
File renamed without changes.
File renamed without changes.
95 changes: 95 additions & 0 deletions src/chalkbox/api/common/java/JUnitListener.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
package chalkbox.api.common.java;

import chalkbox.api.collections.Data;
import org.junit.runner.Description;
import org.junit.runner.notification.Failure;
import org.junit.runner.notification.RunListener;

import java.util.ArrayList;
import java.util.List;

public class JUnitListener extends RunListener {
private static class TestResult {
private final String testName;
private boolean visible = false;
private boolean passed = true;
private String output = "";

public TestResult(String testName) {
this.testName = testName;
}
}

private List<TestResult> results;
private TestResult currentResult;
private int numFailed = 0;
private StringBuilder output;

public JUnitListener() {
this.results = new ArrayList<>();
this.output = new StringBuilder();
}

@Override
public void testStarted(Description description) throws Exception {
super.testStarted(description);

this.currentResult = new TestResult(
description.getTestClass().getSimpleName()
+ "." + description.getMethodName());

/* Results of this test should be immediately visible */
// TODO create a library containing a custom annotation for this
if (description.getAnnotation(Deprecated.class) != null) {
this.currentResult.visible = true;
}
}

@Override
public void testFinished(Description description) throws Exception {
super.testFinished(description);

if (this.currentResult != null) {
this.results.add(this.currentResult);
}
this.currentResult = null;
}

@Override
public void testFailure(Failure failure) throws Exception {
super.testFailure(failure);

if (this.currentResult != null) {
this.output.append(failure);
this.output.append("\n");
this.currentResult.output = failure.toString();
this.currentResult.passed = false;
}
this.numFailed++;
}

public Data getResultsForClass() {
Data data = new Data();
data.set("extra_data.passes", this.results.size() - this.numFailed);
data.set("extra_data.fails", this.numFailed);
data.set("extra_data.total", this.results.size());
data.set("output", this.output.toString());
return data;
}

public List<Data> getIndividualResults() {
List<Data> results = new ArrayList<>();

for (TestResult result : this.results) {
Data data = new Data();
data.set("extra_data.passes", result.passed ? 1 : 0);
data.set("extra_data.fails", result.passed ? 0 : 1);
data.set("extra_data.total", 1);
data.set("output", result.output);
data.set("name", result.testName);
data.set("visibility", result.visible ? "visible" : "after_due_date");
results.add(data);
}
return results;
}
}
51 changes: 51 additions & 0 deletions src/chalkbox/api/common/java/JUnitRunner.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
package chalkbox.api.common.java;

import chalkbox.api.collections.Data;
import org.junit.runner.JUnitCore;

import java.io.File;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLClassLoader;
import java.util.List;

/**
* Utility class to execute a JUnit test.
*/
public class JUnitRunner {

// Runs all tests in the given class and returns a single output object
public static Data runTestsCombined(String className, String classPath) {
return run(className, classPath).getResultsForClass();
}

// Runs all tests in the given class and returns an output object for each @Test
public static List<Data> runTests(String className, String classPath) {
return run(className, classPath).getIndividualResults();
}

private static JUnitListener run(String className, String classPath) {
JUnitListener listener = new JUnitListener();
JUnitCore runner = new JUnitCore();
runner.addListener(listener);

String[] classPathEntries = classPath.split(
System.getProperty("path.separator"));
URL[] classPathUrls = new URL[classPathEntries.length];
for (int i = 0; i < classPathEntries.length; ++i) {
try {
classPathUrls[i] = new File(classPathEntries[i]).toURI().toURL();
} catch (MalformedURLException e) {
e.printStackTrace();
}
}
URLClassLoader classLoader = new URLClassLoader(classPathUrls);
try {
runner.run(classLoader.loadClass(className));
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
return listener;
}

}
File renamed without changes.
File renamed without changes.
File renamed without changes.
20 changes: 20 additions & 0 deletions src/chalkbox/collectors/GradescopeCollector.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package chalkbox.collectors;

import chalkbox.api.collections.Collection;
import chalkbox.api.collections.Data;

import java.io.File;

public class GradescopeCollector {

public Collection collect(String submissionPath, String outputPath) {
File submissionFolder = new File(submissionPath);

Data metadata = new Data();

metadata.set("root", submissionFolder.getPath());
metadata.set("json", outputPath);

return new Collection(metadata);
}
}
15 changes: 15 additions & 0 deletions src/chalkbox/engines/ConfigFormatException.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package chalkbox.engines;

public class ConfigFormatException extends Exception {
public ConfigFormatException() {
super();
}

public ConfigFormatException(String message) {
super(message);
}

public ConfigFormatException(String message, Exception exception) {
super(message, exception);
}
}
Loading

0 comments on commit b59631d

Please sign in to comment.