Commit acd8c826 authored by Lückemeyer's avatar Lückemeyer
Browse files

removed dtt remnants

parent d1fab229
Pipeline #9064 passed with stage
...@@ -52,7 +52,7 @@ public class TaskUpload { ...@@ -52,7 +52,7 @@ public class TaskUpload {
LOG.info("submission for testing received"); LOG.info("submission for testing received");
LOG.debug("creating new temporary directory"); LOG.debug("creating new temporary directory");
Path workDirectory = Files.createTempDirectory(testTmpPath, "dtt"); Path workDirectory = Files.createTempDirectory(testTmpPath, "dta");
LOG.debug(String.format("working dir for test is: %s", workDirectory.toAbsolutePath().toString())); LOG.debug(String.format("working dir for test is: %s", workDirectory.toAbsolutePath().toString()));
// define paths for the test, the submission and where the result is to be expected afterwards // define paths for the test, the submission and where the result is to be expected afterwards
...@@ -61,7 +61,7 @@ public class TaskUpload { ...@@ -61,7 +61,7 @@ public class TaskUpload {
String mimeInfo = new Tika().detect(taskFileRef.getInputStream()); String mimeInfo = new Tika().detect(taskFileRef.getInputStream());
switch (mimeInfo) { switch (mimeInfo) {
case "text/plain": case "text/plain":
LOG.debug("textfile uploaded, searching for dtt config"); LOG.debug("textfile uploaded, searching for dta config");
// find URI in config file // find URI in config file
Matcher config = RegexUtil.findStudentConfig(taskFileRef.getInputStream()); Matcher config = RegexUtil.findStudentConfig(taskFileRef.getInputStream());
......
package de.hftstuttgart.dtabackend.rest.v1.unittest; package de.hftstuttgart.dtabackend.rest.v1.unittest;
import de.hftstuttgart.dtabackend.utils.JGitUtil; import de.hftstuttgart.dtabackend.utils.JGitUtil;
import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger; import org.apache.logging.log4j.Logger;
import org.springframework.core.env.Environment; import org.springframework.core.env.Environment;
import org.springframework.util.FileSystemUtils; import org.springframework.util.FileSystemUtils;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController; import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile; import org.springframework.web.multipart.MultipartFile;
import jakarta.servlet.annotation.MultipartConfig; import jakarta.servlet.annotation.MultipartConfig;
import java.io.*; import java.io.*;
import java.nio.file.Path; import java.nio.file.Path;
import java.nio.file.Paths; import java.nio.file.Paths;
import java.util.regex.Matcher; import java.util.regex.Matcher;
import java.util.regex.Pattern; import java.util.regex.Pattern;
/** /**
* Rest controller for anything related to the TEST files. * Rest controller for anything related to the TEST files.
*/ */
@RestController @RestController
@RequestMapping("/v1/unittest") @RequestMapping("/v1/unittest")
@MultipartConfig @MultipartConfig
public class UnitTestUpload { public class UnitTestUpload {
private static final Logger LOG = LogManager.getLogger(UnitTestUpload.class); private static final Logger LOG = LogManager.getLogger(UnitTestUpload.class);
public final static String TESTCONFIGREGEX = "^dtt::(.*)::(.*|none)::(.*|none)::(.*)$"; public final static String TESTCONFIGREGEX = "^dtt::(.*)::(.*|none)::(.*|none)::(.*)$";
public final static String SUBMISSIONCONFIGREGEX = "^dtt::(.*)::(.*|none)::(.*|none)$"; public final static String SUBMISSIONCONFIGREGEX = "^dtt::(.*)::(.*|none)::(.*|none)$";
private final JGitUtil jGitUtil; private final JGitUtil jGitUtil;
private final String assignmentBasePath; private final String assignmentBasePath;
public UnitTestUpload(Environment env, JGitUtil jGitUtil) { public UnitTestUpload(Environment env, JGitUtil jGitUtil) {
this.jGitUtil = jGitUtil; this.jGitUtil = jGitUtil;
Path p = Paths.get(env.getProperty("data.dir"), env.getProperty("data.dir.test.folder.name")); Path p = Paths.get(env.getProperty("data.dir"), env.getProperty("data.dir.test.folder.name"));
this.assignmentBasePath = p.toAbsolutePath().toString(); this.assignmentBasePath = p.toAbsolutePath().toString();
} }
/** /**
* Create a subfolder for the specific assignment. * Create a subfolder for the specific assignment.
* This is called when the teacher creates an assignment and uploads the JUnit test files * This is called when the teacher creates an assignment and uploads the JUnit test files
* *
* @param unitTestFileRef The text file which contains the JUnit tests meta data * @param unitTestFileRef The text file which contains the JUnit tests meta data
* @param assignmentId ID of the created assignment. Generated by Moodle * @param assignmentId ID of the created assignment. Generated by Moodle
*/ */
@RequestMapping(method = RequestMethod.POST) @RequestMapping(method = RequestMethod.POST)
public void uploadUnitTestFile( public void uploadUnitTestFile(
@RequestParam("unitTestFile") MultipartFile unitTestFileRef, @RequestParam("unitTestFile") MultipartFile unitTestFileRef,
@RequestParam("assignmentId") String assignmentId @RequestParam("assignmentId") String assignmentId
) throws IOException { ) throws IOException {
LOG.info("received new assignment"); LOG.info("received new assignment");
File file = Paths.get( File file = Paths.get(
this.assignmentBasePath, this.assignmentBasePath,
assignmentId + ".txt") assignmentId + ".txt")
.toFile(); .toFile();
file.mkdirs(); file.mkdirs();
// save assignment config // save assignment config
unitTestFileRef.transferTo(file); unitTestFileRef.transferTo(file);
LOG.debug(String.format("saved config file to: %s", file.getAbsolutePath())); LOG.debug(String.format("saved config file to: %s", file.getAbsolutePath()));
Pattern pattern = Pattern.compile(TESTCONFIGREGEX); Pattern pattern = Pattern.compile(TESTCONFIGREGEX);
Matcher config = null; Matcher config = null;
LOG.debug("reading test configuration file"); LOG.debug("reading test configuration file");
// open saved config in a try-with // open saved config in a try-with
try (BufferedReader br = new BufferedReader( try (BufferedReader br = new BufferedReader(
new InputStreamReader( new InputStreamReader(
new FileInputStream(file)))) { new FileInputStream(file)))) {
String line; String line;
// search for a URI while none is found and there are lines left // search for a URI while none is found and there are lines left
while (config == null && (line = br.readLine()) != null) { while (config == null && (line = br.readLine()) != null) {
Matcher matcher = pattern.matcher(line); Matcher matcher = pattern.matcher(line);
if (matcher.matches()) { if (matcher.matches()) {
LOG.debug(String.format("found dtt test line: %s", line)); LOG.debug(String.format("found dta test line: %s", line));
config = matcher; config = matcher;
} }
} }
} catch (IOException e) { } catch (IOException e) {
LOG.error("Error while reading repo config", e); LOG.error("Error while reading repo config", e);
} }
finally { finally {
if (config == null) { if (config == null) {
throw new RuntimeException("couldn't find repo config for unittest clone"); throw new RuntimeException("couldn't find repo config for unittest clone");
} }
} }
LOG.debug("calling test repo clone"); LOG.debug("calling test repo clone");
// cloning assignment repo to persistent space // cloning assignment repo to persistent space
jGitUtil.cloneRepository( jGitUtil.cloneRepository(
config, config,
Paths.get(this.assignmentBasePath, assignmentId).toAbsolutePath().toString()); Paths.get(this.assignmentBasePath, assignmentId).toAbsolutePath().toString());
LOG.info(String.format("stored new assignment: %s", file.getAbsolutePath())); LOG.info(String.format("stored new assignment: %s", file.getAbsolutePath()));
} }
/** /**
* Delete the folder for the assignment. * Delete the folder for the assignment.
* Called when the teacher deletes the JUnitTest assignment * Called when the teacher deletes the JUnitTest assignment
* <p> * <p>
* {{url}}:8080/v1/unittest?assignmentId=111 * {{url}}:8080/v1/unittest?assignmentId=111
* *
* @param assignmentId ID of the assignment to delete. Generated by Moodle * @param assignmentId ID of the assignment to delete. Generated by Moodle
*/ */
@RequestMapping(method = RequestMethod.DELETE) @RequestMapping(method = RequestMethod.DELETE)
public void deleteUnitTestFiles(@RequestParam("assignmentId") String assignmentId) { public void deleteUnitTestFiles(@RequestParam("assignmentId") String assignmentId) {
LOG.info(String.format("received deletion order for assignment %s", assignmentId)); LOG.info(String.format("received deletion order for assignment %s", assignmentId));
// deleting config file // deleting config file
File file = Paths.get( File file = Paths.get(
this.assignmentBasePath, this.assignmentBasePath,
assignmentId + ".txt") assignmentId + ".txt")
.toFile(); .toFile();
file.delete(); file.delete();
// deleting local copy of repository // deleting local copy of repository
file = Paths.get( file = Paths.get(
this.assignmentBasePath, this.assignmentBasePath,
assignmentId).toFile(); assignmentId).toFile();
FileSystemUtils.deleteRecursively(file); FileSystemUtils.deleteRecursively(file);
LOG.info(String.format("assignment %s deletion complete", assignmentId)); LOG.info(String.format("assignment %s deletion complete", assignmentId));
} }
} }
package de.hftstuttgart.dtabackend.utils; package de.hftstuttgart.dtabackend.utils;
import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger; import org.apache.logging.log4j.Logger;
import de.hftstuttgart.dtabackend.rest.v1.unittest.UnitTestUpload; import de.hftstuttgart.dtabackend.rest.v1.unittest.UnitTestUpload;
import java.io.BufferedReader; import java.io.BufferedReader;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.io.InputStreamReader; import java.io.InputStreamReader;
import java.util.regex.Matcher; import java.util.regex.Matcher;
import java.util.regex.Pattern; import java.util.regex.Pattern;
public class RegexUtil { public class RegexUtil {
public enum ConfigType { public enum ConfigType {
TEACHER, TEACHER,
STUDENT, STUDENT,
} }
private static final Logger LOG = LogManager.getLogger(RegexUtil.class); private static final Logger LOG = LogManager.getLogger(RegexUtil.class);
public static Matcher findStudentConfig(InputStream is) { public static Matcher findStudentConfig(InputStream is) {
return findConfig(is, ConfigType.STUDENT); return findConfig(is, ConfigType.STUDENT);
} }
public static Matcher findProfessorConfig(InputStream is) { public static Matcher findProfessorConfig(InputStream is) {
return findConfig(is, ConfigType.TEACHER); return findConfig(is, ConfigType.TEACHER);
} }
public static Matcher findConfig(InputStream is, ConfigType configType) { public static Matcher findConfig(InputStream is, ConfigType configType) {
Pattern pattern; Pattern pattern;
switch (configType) { switch (configType) {
case TEACHER: case TEACHER:
pattern = Pattern.compile(UnitTestUpload.TESTCONFIGREGEX); pattern = Pattern.compile(UnitTestUpload.TESTCONFIGREGEX);
break; break;
case STUDENT: case STUDENT:
pattern = Pattern.compile(UnitTestUpload.SUBMISSIONCONFIGREGEX); pattern = Pattern.compile(UnitTestUpload.SUBMISSIONCONFIGREGEX);
break; break;
default: default:
String msg = String.format("unknown config type: %s", configType.name()); String msg = String.format("unknown config type: %s", configType.name());
LOG.error(msg); LOG.error(msg);
throw new RuntimeException(msg); throw new RuntimeException(msg);
} }
Matcher config = null; Matcher config = null;
LOG.debug("reading config file"); LOG.debug("reading config file");
// open received file in a try-with // open received file in a try-with
try (BufferedReader br = new BufferedReader( try (BufferedReader br = new BufferedReader(
new InputStreamReader( new InputStreamReader(
is))) { is))) {
String line; String line;
// as long as we haven't found a configuration and have lines left, search // as long as we haven't found a configuration and have lines left, search
while (config == null && (line = br.readLine()) != null) { while (config == null && (line = br.readLine()) != null) {
Matcher matcher = pattern.matcher(line); Matcher matcher = pattern.matcher(line);
if (matcher.matches()) { if (matcher.matches()) {
LOG.debug(String.format("found dtt line: %s", line)); LOG.debug(String.format("found dta line: %s", line));
config = matcher; config = matcher;
} }
} }
} catch (IOException e) { } catch (IOException e) {
LOG.error("Error while reading repo config", e); LOG.error("Error while reading repo config", e);
} }
finally { finally {
if (config == null) { if (config == null) {
throw new RuntimeException("couldn't find repo config for clone"); throw new RuntimeException("couldn't find repo config for clone");
} }
} }
return config; return config;
} }
} }
...@@ -7,7 +7,7 @@ spring.http.multipart.max-file-size=5Mb ...@@ -7,7 +7,7 @@ spring.http.multipart.max-file-size=5Mb
############################################### ###############################################
# Holds the uploaded Zip-Files # Holds the uploaded Zip-Files
tests.tmp.dir=/tmp/dta-tests tests.tmp.dir=~/dta-tests
host.tests.tmp.dir=${tests.tmp.dir} host.tests.tmp.dir=${tests.tmp.dir}
data.dir=/data data.dir=/data
data.dir.test.folder.name=UnitTests data.dir.test.folder.name=UnitTests
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment