Skip to content

Commit

Permalink
Merge pull request #745 from jplag/debug-subdir-fix
Browse files Browse the repository at this point in the history
Fix debug mode
  • Loading branch information
tsaglam authored Oct 17, 2022
2 parents 758d4f5 + 4ff45c1 commit de817b7
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 10 deletions.
15 changes: 6 additions & 9 deletions core/src/main/java/de/jplag/Submission.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.Collection;
import java.util.Collections;
import java.util.HashSet;
Expand Down Expand Up @@ -209,23 +210,19 @@ public String toString() {
* This method is used to copy files that can not be parsed to a special folder.
*/
private void copySubmission() {
File rootDirectory = submissionRootFile.getParentFile();
assert rootDirectory != null;
File submissionDirectory = createSubdirectory(rootDirectory, ERROR_FOLDER, language.getIdentifier(), name);
File errorDirectory = createErrorDirectory(language.getIdentifier(), name);
logger.info("Copying erroneous submission to {}", errorDirectory.getAbsolutePath());
for (File file : files) {
try {
Files.copy(file.toPath(), new File(submissionDirectory, file.getName()).toPath());
Files.copy(file.toPath(), new File(errorDirectory, file.getName()).toPath());
} catch (IOException exception) {
logger.error("Error copying file: " + exception.getMessage(), exception);
}
}
}

private static File createSubdirectory(File parent, String... subdirectoryNames) {
File subdirectory = parent;
for (String name : subdirectoryNames) {
subdirectory = new File(subdirectory, name);
}
private static File createErrorDirectory(String... subdirectoryNames) {
File subdirectory = Path.of(ERROR_FOLDER, subdirectoryNames).toFile();
if (!subdirectory.exists()) {
subdirectory.mkdirs();
}
Expand Down
2 changes: 1 addition & 1 deletion core/src/test/java/de/jplag/InvalidSubmissionTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ void testInvalidSubmissionsWithDebug() throws ExitException {
} catch (SubmissionException e) {
System.out.println(e.getMessage());
} finally {
File errorFolder = new File(Path.of(BASE_PATH, SAMPLE_NAME, "errors", "java").toString());
File errorFolder = new File(Path.of("errors", "java").toString());
assertTrue(errorFolder.exists());
String[] errorSubmissions = errorFolder.list();
if (errorSubmissions != null)
Expand Down

0 comments on commit de817b7

Please sign in to comment.