Skip to content

Commit

Permalink
Merge pull request #556 from Luro02/main
Browse files Browse the repository at this point in the history
Implement some things
  • Loading branch information
Luro02 authored Jul 1, 2024
2 parents b773230 + 41e3ede commit 8e513eb
Show file tree
Hide file tree
Showing 107 changed files with 1,957 additions and 1,709 deletions.
5 changes: 5 additions & 0 deletions autograder-cmd/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,11 @@
<artifactId>autograder-core</artifactId>
</dependency>

<dependency>
<groupId>de.firemage.autograder</groupId>
<artifactId>autograder-extra</artifactId>
</dependency>

<dependency>
<groupId>de.firemage.autograder</groupId>
<artifactId>autograder-span</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.dataformat.yaml.YAMLFactory;
import de.firemage.autograder.cmd.output.Annotation;
import de.firemage.autograder.core.ArtemisUtil;
import de.firemage.autograder.core.CheckConfiguration;
Expand All @@ -12,10 +11,9 @@
import de.firemage.autograder.core.LinterException;
import de.firemage.autograder.core.LinterStatus;
import de.firemage.autograder.core.Problem;
import de.firemage.autograder.core.ProblemType;
import de.firemage.autograder.core.compiler.CompilationFailureException;
import de.firemage.autograder.core.compiler.JavaVersion;
import de.firemage.autograder.core.errorprone.TempLocation;
import de.firemage.autograder.core.file.TempLocation;
import de.firemage.autograder.core.file.UploadedFile;
import de.firemage.autograder.span.Formatter;
import de.firemage.autograder.span.Highlight;
Expand All @@ -31,7 +29,6 @@
import picocli.CommandLine.Parameters;
import picocli.CommandLine.Spec;

import java.io.File;
import java.io.FileDescriptor;
import java.io.FileOutputStream;
import java.io.IOException;
Expand All @@ -40,16 +37,12 @@
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashSet;
import java.util.List;
import java.util.Locale;
import java.util.Optional;
import java.util.Set;
import java.util.concurrent.Callable;
import java.util.function.Consumer;
import java.util.stream.Stream;

@Command(mixinStandardHelpOptions = true, version = "codelinter-cmd 1.0",
description = "Static code analysis for student java code")
Expand Down
102 changes: 16 additions & 86 deletions autograder-core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,20 +15,10 @@
<url>https://github.com/Feuermagier/autograder/autograder-core</url>

<properties>
<spoon.version>11.0.0</spoon.version>
<pmd.version>7.0.0-rc3</pmd.version>
<spotbugs.version>6.45.0</spotbugs.version>
<jgraph.version>1.5.2</jgraph.version>
<fluent.version>0.70</fluent.version>
</properties>

<dependencies>
<!-- Internal -->
<dependency>
<groupId>de.firemage.autograder</groupId>
<artifactId>autograder-treeg</artifactId>
</dependency>

<!-- Spoon -->
<dependency>
<groupId>fr.inria.gforge.spoon</groupId>
Expand All @@ -54,49 +44,6 @@
</exclusions>
</dependency>


<!-- PMD -->
<dependency>
<groupId>net.sourceforge.pmd</groupId>
<artifactId>pmd-java</artifactId>
<version>${pmd.version}</version>
</dependency>

<!-- Spotbugs -->
<dependency>
<groupId>com.github.spotbugs</groupId>
<artifactId>spotbugs</artifactId>
<version>4.8.6</version>
<exclusions>
<exclusion>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
</exclusion>
</exclusions>
</dependency>

<!-- Error Prone -->
<dependency>
<groupId>com.google.errorprone</groupId>
<artifactId>error_prone_core</artifactId>
<version>2.28.0</version>
</dependency>

<!-- ASM -->
<dependency>
<groupId>org.ow2.asm</groupId>
<artifactId>asm</artifactId>
<version>${asm.version}</version>
</dependency>

<!-- Apache Commons -->
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>2.16.1</version>
</dependency>


<!-- Config -->
<dependency>
<groupId>com.fasterxml.jackson.dataformat</groupId>
Expand All @@ -115,39 +62,6 @@
<version>${slf4j.version}</version>
</dependency>

<!-- Compression - to unpack tar files extracted from docker containers -->
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-compress</artifactId>
<version>1.26.2</version>
</dependency>

<!-- Language detection -->
<dependency>
<groupId>com.github.pemistahl</groupId>
<artifactId>lingua</artifactId>
<version>1.2.2</version>
</dependency>

<!-- Commons -->
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>3.14.0</version>
</dependency>

<!-- Graphs -->
<dependency>
<groupId>org.jgrapht</groupId>
<artifactId>jgrapht-core</artifactId>
<version>${jgraph.version}</version>
</dependency>
<dependency>
<groupId>org.jgrapht</groupId>
<artifactId>jgrapht-io</artifactId>
<version>${jgraph.version}</version>
</dependency>

<!-- Charsets -->
<dependency>
<groupId>com.github.albfernandez</groupId>
Expand All @@ -174,4 +88,20 @@
<version>0.10.2</version>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>test-jar</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package de.firemage.autograder.core;

import de.firemage.autograder.core.check.Check;
import de.firemage.autograder.core.file.TempLocation;
import de.firemage.autograder.core.file.UploadedFile;

import java.io.IOException;
import java.util.List;
import java.util.function.Consumer;

public interface CodeLinter<T extends Check> {
Class<? super T> supportedCheckType();

/**
* Lints the given submission using the given checks.
*
* @param submission the submission to lint
* @param tempLocation in this location, temporary files can be stored by the linter
* @param classLoader some class loader
* @param checks the checks to use, they are guaranteed to be supported by this linter
* @param statusConsumer a consumer that can be used to report the progress of the linting
* @return a list of problems found in the submission
* @throws IOException if an I/O error occurs
*/
List<Problem> lint(
UploadedFile submission,
TempLocation tempLocation,
ClassLoader classLoader,
List<T> checks,
Consumer<? super LinterStatus> statusConsumer
) throws IOException;
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,18 @@
import spoon.processing.AbstractProcessor;
import spoon.processing.Processor;
import spoon.reflect.CtModel;
import spoon.reflect.code.CtCatchVariable;
import spoon.reflect.code.CtTargetedExpression;
import spoon.reflect.declaration.*;
import spoon.reflect.factory.CodeFactory;
import spoon.reflect.factory.Factory;
import spoon.reflect.factory.FactoryImpl;
import spoon.reflect.reference.CtCatchVariableReference;
import spoon.reflect.reference.CtReference;
import spoon.reflect.visitor.*;
import spoon.reflect.visitor.filter.NamedElementFilter;
import spoon.support.DefaultCoreFactory;
import spoon.support.StandardEnvironment;

import java.io.IOException;
import java.net.MalformedURLException;
Expand Down Expand Up @@ -139,7 +145,36 @@ private void buildModelMaybe() {
return;
}

Launcher launcher = new Launcher();

// Fix for something similar to https://github.com/INRIA/spoon/issues/5868
Factory baseFactory = new FactoryImpl(new DefaultCoreFactory(), new StandardEnvironment()) {
private transient CodeFactory code;

@Override
public CodeFactory Code() {
if (this.code == null) {
this.code = new CodeFactory(this) {
@Override
public <T> CtCatchVariableReference<T> createCatchVariableReference(CtCatchVariable<T> catchVariable) {
// The implementation of the original method is broken, resulting in elements which point to the
// wrong or an invalid parent.
//
// This is a workaround until the issue is fixed in spoon.
CtCatchVariableReference<T> ref = this.factory.Core().createCatchVariableReference();

ref.setType(catchVariable.getType() == null ? null : catchVariable.getType().clone());
ref.setSimpleName(catchVariable.getSimpleName());
ref.setParent(catchVariable);

return ref;
}
};
}
return this.code;
}
};

Launcher launcher = new Launcher(baseFactory);
launcher.addInputResource(file.getSpoonResource());
launcher.getEnvironment().setShouldCompile(false);
launcher.getEnvironment().setSourceClasspath(new String[]{jar.toAbsolutePath().toString()});
Expand Down
Loading

0 comments on commit 8e513eb

Please sign in to comment.