Skip to content

Commit

Permalink
revert more changes
Browse files Browse the repository at this point in the history
  • Loading branch information
Luro02 committed Jul 13, 2024
1 parent 396ecff commit af0f922
Show file tree
Hide file tree
Showing 90 changed files with 102 additions and 178 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
import de.firemage.autograder.core.LinterStatus;
import de.firemage.autograder.core.Problem;
import de.firemage.autograder.core.compiler.CompilationFailureException;
import de.firemage.autograder.core.JavaVersion;
import de.firemage.autograder.core.compiler.JavaVersion;
import de.firemage.autograder.core.file.TempLocation;
import de.firemage.autograder.core.file.UploadedFile;
import de.firemage.autograder.span.Formatter;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@

import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.nio.file.Path;
import java.util.ArrayList;
import java.util.Collection;
import java.util.IdentityHashMap;
Expand All @@ -36,55 +35,6 @@ public final class Linter {
private final ClassLoader classLoader;
private final int maxProblemsPerCheck;


public static List<List<Object>> run(
ClassLoader classLoader,
Path submissionSource,
Collection<String> problemTypes,
List<String> excludedClasses,
Consumer<String> statusConsumer,
Locale locale,
int threads,
TempLocation tempLocation,
int maxProblemsPerCheck) throws Exception {
Linter linter = Linter.builder(locale)
.classLoader(classLoader)
.threads(threads)
.tempLocation(TempLocation.random())
.maxProblemsPerCheck(maxProblemsPerCheck)
.build();

Consumer<LinterStatus> statusConsumerWrapper = status -> statusConsumer.accept(linter.translateMessage(status.getMessage()));

List<List<Object>> problems = new ArrayList<>();
try (UploadedFile uploadedFile = UploadedFile.build(
submissionSource,
JavaVersion.latest(),
linter.tempLocation,
statusConsumerWrapper,
null)) {
var autograderProblems = linter.checkFile(uploadedFile, new CheckConfiguration(
problemTypes.stream().map(ProblemType::valueOf).toList(),
excludedClasses
), statusConsumerWrapper);

for (var problem : autograderProblems) {
/*problems.add(new Problem(
problem.getProblemType().toString(),
problem.getPosition(),
linter.translateMessage(problem.getExplanation())
));*/
problems.add(List.of(
problem.getProblemType().toString(),
problem.getPosition(),
linter.translateMessage(problem.getExplanation())
));
}
}

return problems;
}

private Linter(
Locale locale,
TempLocation tempLocation,
Expand Down Expand Up @@ -317,21 +267,15 @@ public String translateMessage(Translatable message) {
return output;
}

private static final Collection<Class<?>> CHECKS = new LinkedHashSet<>(
new Reflections("de.firemage.autograder.", Scanners.TypesAnnotated)
.getTypesAnnotatedWith(ExecutableCheck.class)
);

public List<Check> findChecksForProblemTypes(Collection<ProblemType> problems) {
ClassLoader[] classLoaders = { this.classLoader };

// TODO: is the classLoader stuff necessary? or is it enough to use the old version?
Collection<Class<?>> checks = new LinkedHashSet<>(
new Reflections(new ConfigurationBuilder()
.forPackage("de.firemage.autograder.", classLoaders)
.addScanners(Scanners.TypesAnnotated)
.setClassLoaders(classLoaders)
).getTypesAnnotatedWith(ExecutableCheck.class)
);

return checks
return CHECKS
.stream()
.filter(check -> this.isRequiredCheck(check.getAnnotation(ExecutableCheck.class), problems))
.filter(check -> isRequiredCheck(check.getAnnotation(ExecutableCheck.class), problems))
.map(check -> {
try {
return (Check) check.getConstructor().newInstance();
Expand All @@ -344,20 +288,13 @@ public List<Check> findChecksForProblemTypes(Collection<ProblemType> problems) {
.toList();
}

public List<? extends CodeLinter<?>> findCodeLinter() {
ClassLoader[] classLoaders = { this.classLoader };

// TODO: is the classLoader stuff necessary? or is it enough to use the old version?
Collection<Class<?>> codeLinter = new LinkedHashSet<>(
new Reflections(new ConfigurationBuilder()
.forPackage("de.firemage.autograder.", classLoaders)
.addScanners(Scanners.SubTypes)
.setClassLoaders(classLoaders)
).getSubTypesOf(CodeLinter.class)
);
private static final Collection<Class<?>> CODE_LINTER = new LinkedHashSet<>(
new Reflections("de.firemage.autograder.", Scanners.SubTypes)
.getSubTypesOf(CodeLinter.class)
);


return codeLinter
public List<? extends CodeLinter<?>> findCodeLinter() {
return CODE_LINTER
.stream()
.map(linter -> {
try {
Expand All @@ -373,10 +310,6 @@ public List<? extends CodeLinter<?>> findCodeLinter() {


private boolean isRequiredCheck(ExecutableCheck check, Collection<ProblemType> problems) {
try {
return check.enabled() && problems.stream().anyMatch(p -> List.of(check.reportedProblems()).contains(p));
} catch (EnumConstantNotPresentException e) {
return false;
}
return check.enabled() && problems.stream().anyMatch(p -> List.of(check.reportedProblems()).contains(p));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,6 @@ default boolean isSome() {
return this instanceof Some;
}

default T or(T other) {
if (this.isSome()) {
return this.orElseThrow();
} else {
return other;
}
}

default <U> Option<U> map(Function<T, U> function) {
return switch (this) {
case Some<T>(var value) -> new Some<>(function.apply(value));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import de.firemage.autograder.core.file.CompilationUnit;
import de.firemage.autograder.core.file.SourceInfo;
import de.firemage.autograder.core.JavaVersion;
import de.firemage.autograder.core.file.TempLocation;

import javax.tools.DiagnosticCollector;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package de.firemage.autograder.core;
package de.firemage.autograder.core.compiler;

import java.util.Arrays;
import java.util.Comparator;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package de.firemage.autograder.core.file;

import de.firemage.autograder.core.SerializableCharset;
import de.firemage.autograder.core.JavaVersion;
import de.firemage.autograder.core.compiler.JavaVersion;
import de.firemage.autograder.core.compiler.PhysicalFileObject;
import org.apache.commons.io.FileUtils;
import org.mozilla.universalchardet.UniversalDetector;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package de.firemage.autograder.core.file;

import de.firemage.autograder.core.JavaVersion;
import de.firemage.autograder.core.compiler.JavaVersion;
import spoon.compiler.SpoonResource;

import java.io.IOException;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package de.firemage.autograder.core.file;

import de.firemage.autograder.core.JavaVersion;
import de.firemage.autograder.core.compiler.JavaVersion;
import org.apache.commons.io.FileUtils;
import spoon.compiler.SpoonResource;
import spoon.support.compiler.VirtualFile;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import de.firemage.autograder.core.compiler.CompilationFailureException;
import de.firemage.autograder.core.compiler.CompilationResult;
import de.firemage.autograder.core.compiler.Compiler;
import de.firemage.autograder.core.JavaVersion;
import de.firemage.autograder.core.compiler.JavaVersion;
import de.firemage.autograder.core.integrated.ModelBuildException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package de.firemage.autograder.core;

import de.firemage.autograder.core.check.Check;
import de.firemage.autograder.core.compiler.JavaVersion;
import de.firemage.autograder.core.file.TempLocation;
import de.firemage.autograder.core.file.UploadedFile;
import org.junit.jupiter.api.DynamicTest;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import de.firemage.autograder.core.Problem;
import de.firemage.autograder.core.ProblemType;
import de.firemage.autograder.core.file.StringSourceInfo;
import de.firemage.autograder.core.JavaVersion;
import de.firemage.autograder.core.compiler.JavaVersion;
import org.junit.jupiter.api.Test;

import java.io.IOException;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import de.firemage.autograder.core.Problem;
import de.firemage.autograder.core.ProblemType;
import de.firemage.autograder.core.check.AbstractCheckTest;
import de.firemage.autograder.core.JavaVersion;
import de.firemage.autograder.core.compiler.JavaVersion;
import de.firemage.autograder.core.file.StringSourceInfo;
import org.junit.jupiter.api.Test;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import de.firemage.autograder.core.ProblemType;
import de.firemage.autograder.core.file.StringSourceInfo;
import de.firemage.autograder.core.check.AbstractCheckTest;
import de.firemage.autograder.core.JavaVersion;
import de.firemage.autograder.core.compiler.JavaVersion;
import org.junit.jupiter.api.Test;

import java.io.IOException;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import de.firemage.autograder.core.Problem;
import de.firemage.autograder.core.ProblemType;
import de.firemage.autograder.core.check.AbstractCheckTest;
import de.firemage.autograder.core.JavaVersion;
import de.firemage.autograder.core.compiler.JavaVersion;
import de.firemage.autograder.core.file.StringSourceInfo;
import org.junit.jupiter.api.Test;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import de.firemage.autograder.core.Problem;
import de.firemage.autograder.core.ProblemType;
import de.firemage.autograder.core.check.AbstractCheckTest;
import de.firemage.autograder.core.JavaVersion;
import de.firemage.autograder.core.compiler.JavaVersion;
import de.firemage.autograder.core.file.StringSourceInfo;
import org.junit.jupiter.api.Test;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import de.firemage.autograder.core.Problem;
import de.firemage.autograder.core.ProblemType;
import de.firemage.autograder.core.check.AbstractCheckTest;
import de.firemage.autograder.core.JavaVersion;
import de.firemage.autograder.core.compiler.JavaVersion;
import de.firemage.autograder.core.file.StringSourceInfo;
import org.junit.jupiter.api.Test;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import de.firemage.autograder.core.Problem;
import de.firemage.autograder.core.ProblemType;
import de.firemage.autograder.core.check.AbstractCheckTest;
import de.firemage.autograder.core.JavaVersion;
import de.firemage.autograder.core.compiler.JavaVersion;
import de.firemage.autograder.core.file.StringSourceInfo;
import org.junit.jupiter.api.Test;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import de.firemage.autograder.core.Problem;
import de.firemage.autograder.core.ProblemType;
import de.firemage.autograder.core.check.AbstractCheckTest;
import de.firemage.autograder.core.JavaVersion;
import de.firemage.autograder.core.compiler.JavaVersion;
import de.firemage.autograder.core.file.StringSourceInfo;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import de.firemage.autograder.core.Problem;
import de.firemage.autograder.core.ProblemType;
import de.firemage.autograder.core.check.AbstractCheckTest;
import de.firemage.autograder.core.JavaVersion;
import de.firemage.autograder.core.compiler.JavaVersion;
import de.firemage.autograder.core.file.StringSourceInfo;
import org.junit.jupiter.api.Test;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import de.firemage.autograder.core.Problem;
import de.firemage.autograder.core.ProblemType;
import de.firemage.autograder.core.check.AbstractCheckTest;
import de.firemage.autograder.core.JavaVersion;
import de.firemage.autograder.core.compiler.JavaVersion;
import de.firemage.autograder.core.file.StringSourceInfo;
import org.junit.jupiter.api.Test;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import de.firemage.autograder.core.Problem;
import de.firemage.autograder.core.ProblemType;
import de.firemage.autograder.core.check.AbstractCheckTest;
import de.firemage.autograder.core.JavaVersion;
import de.firemage.autograder.core.compiler.JavaVersion;
import de.firemage.autograder.core.file.StringSourceInfo;
import org.junit.jupiter.api.Test;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import de.firemage.autograder.core.Problem;
import de.firemage.autograder.core.ProblemType;
import de.firemage.autograder.core.check.AbstractCheckTest;
import de.firemage.autograder.core.JavaVersion;
import de.firemage.autograder.core.compiler.JavaVersion;
import de.firemage.autograder.core.file.StringSourceInfo;
import org.junit.jupiter.api.Test;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import de.firemage.autograder.core.Problem;
import de.firemage.autograder.core.ProblemType;
import de.firemage.autograder.core.check.AbstractCheckTest;
import de.firemage.autograder.core.JavaVersion;
import de.firemage.autograder.core.compiler.JavaVersion;
import de.firemage.autograder.core.file.StringSourceInfo;
import org.junit.jupiter.api.Test;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import de.firemage.autograder.core.ProblemType;
import de.firemage.autograder.core.file.StringSourceInfo;
import de.firemage.autograder.core.check.AbstractCheckTest;
import de.firemage.autograder.core.JavaVersion;
import de.firemage.autograder.core.compiler.JavaVersion;
import org.junit.jupiter.api.Test;

import java.io.IOException;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import de.firemage.autograder.core.ProblemType;
import de.firemage.autograder.core.file.StringSourceInfo;
import de.firemage.autograder.core.check.AbstractCheckTest;
import de.firemage.autograder.core.JavaVersion;
import de.firemage.autograder.core.compiler.JavaVersion;
import org.junit.jupiter.api.Test;

import java.io.IOException;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import de.firemage.autograder.core.Problem;
import de.firemage.autograder.core.ProblemType;
import de.firemage.autograder.core.check.AbstractCheckTest;
import de.firemage.autograder.core.JavaVersion;
import de.firemage.autograder.core.compiler.JavaVersion;
import de.firemage.autograder.core.file.StringSourceInfo;
import org.junit.jupiter.api.Test;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import de.firemage.autograder.core.Problem;
import de.firemage.autograder.core.ProblemType;
import de.firemage.autograder.core.check.AbstractCheckTest;
import de.firemage.autograder.core.JavaVersion;
import de.firemage.autograder.core.compiler.JavaVersion;
import de.firemage.autograder.core.file.StringSourceInfo;
import org.junit.jupiter.api.Test;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import de.firemage.autograder.core.Problem;
import de.firemage.autograder.core.ProblemType;
import de.firemage.autograder.core.check.AbstractCheckTest;
import de.firemage.autograder.core.JavaVersion;
import de.firemage.autograder.core.compiler.JavaVersion;
import de.firemage.autograder.core.file.StringSourceInfo;
import org.junit.jupiter.api.Test;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import de.firemage.autograder.core.Problem;
import de.firemage.autograder.core.ProblemType;
import de.firemage.autograder.core.check.AbstractCheckTest;
import de.firemage.autograder.core.JavaVersion;
import de.firemage.autograder.core.compiler.JavaVersion;
import de.firemage.autograder.core.file.StringSourceInfo;
import org.junit.jupiter.api.Test;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import de.firemage.autograder.core.Problem;
import de.firemage.autograder.core.ProblemType;
import de.firemage.autograder.core.check.AbstractCheckTest;
import de.firemage.autograder.core.JavaVersion;
import de.firemage.autograder.core.compiler.JavaVersion;
import de.firemage.autograder.core.file.SourceInfo;
import de.firemage.autograder.core.file.StringSourceInfo;
import org.junit.jupiter.params.ParameterizedTest;
Expand Down
Loading

0 comments on commit af0f922

Please sign in to comment.