Skip to content

Commit

Permalink
Merge branch 'main' into ign-endSpaces-stringReplacement
Browse files Browse the repository at this point in the history
  • Loading branch information
mauricioaniche authored Jul 11, 2023
2 parents 724e02f + 734f041 commit a266efb
Show file tree
Hide file tree
Showing 30 changed files with 204 additions and 77 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,3 +42,6 @@ jobs:

# - name: Run Weblab selenium tests
# run: mvn test -pl weblab-runner -Dgroups=selenium

- name: Run Checkstyle
run: mvn checkstyle:check
49 changes: 49 additions & 0 deletions andy-checkstyle-checker.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
<?xml version="1.0"?>
<!DOCTYPE module PUBLIC
"-//Checkstyle//DTD Checkstyle Configuration 1.3//EN"
"https://checkstyle.org/dtds/configuration_1_3.dtd">

<module name="Checker">
<module name="BeforeExecutionExclusionFileFilter">
<property name="fileNamePattern" value="^(?!.*(nl.tudelft.cse1110.andy))" />
</module>

<module name="SuppressWarningsFilter" />

<module name="TreeWalker">
<module name="SuppressWarningsHolder" />

<module name="MethodLength">
<property name="severity" value="error"/>
<property name="tokens" value="METHOD_DEF, CTOR_DEF, COMPACT_CTOR_DEF"/>
<property name="max" value="50"/>
</module>

<module name="CyclomaticComplexity">
<property name="max" value="10"/>
<property name="tokens" value="LITERAL_WHILE, LITERAL_DO"/>
</module>

<module name="NestedIfDepthCheck" >
<property name="max" value="2"/>
</module>

<module name="UnnecessarySemicolonInEnumeration"/>
<module name="UnnecessarySemicolonInTryWithResources"/>
<module name="UnnecessarySemicolonAfterOuterTypeDeclaration"/>
<module name="UnnecessarySemicolonAfterTypeMemberDeclaration"/>

<module name="DeclarationOrderCheck" />
<module name="EmptyStatementCheck" />
<module name="EqualsHashCodeCheck" />
<module name="MissingSwitchDefaultCheck" />
<module name="UnusedLocalVariableCheck" />
<module name="EmptyBlockCheck" />
<module name="EmptyCatchBlockCheck" />
<module name="StringLiteralEqualityCheck" />


</module>

</module>

8 changes: 0 additions & 8 deletions andy/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -46,14 +46,6 @@

<dependencies>

<!-- https://mvnrepository.com/artifact/com.github.mauricioaniche/codesheriff -->
<dependency>
<groupId>com.github.mauricioaniche</groupId>
<artifactId>codesheriff</artifactId>
<version>0.3</version>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-reload4j</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,16 @@

public class JQWikProvideAnnotations extends Check {

private boolean provideAnnotationIdentified = false;

private static Set<String> JQWIK_PROVIDE_ANNOTATIONS = new HashSet<>() {{
add("IntRange");
add("Positive");
add("Negative");
add("IntRange");
add("Positive");
add("Negative");

// TODO: add all annotations here
// TODO: add all annotations here
}};

private boolean provideAnnotationIdentified = false;

@Override
public boolean visit(MarkerAnnotation node) {
checkIfThisIsAJQWikAnnotation(node.getTypeName());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,6 @@
*/
public class TestMethodsHaveAssertions extends WithinTestMethod {

private boolean containsATestWithoutAssertion = false;
private boolean currentMethodContainsAssertion = false;

/**
* This is, for now, a non-exhaustive list.
*/
Expand Down Expand Up @@ -57,6 +54,9 @@ public class TestMethodsHaveAssertions extends WithinTestMethod {

}};

private boolean containsATestWithoutAssertion = false;
private boolean currentMethodContainsAssertion = false;

@Override
public boolean visit(MethodDeclaration md) {
// we reset the flag that stores whether we found a call to an assertion
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,17 +27,17 @@ public class UseOfStringLiterals extends WithinAnnotatedMethod {
add("Provide"); // jqwik
}};

protected Set<String> annotations() {
return TEST_ANNOTATIONS;
}

private boolean literalFound = false;
private int length;

public UseOfStringLiterals(int length) {
this.length = length;
}

protected Set<String> annotations() {
return TEST_ANNOTATIONS;
}

public boolean visit(StringLiteral node) {
if(isInTheAnnotatedMethod() && node.getLiteralValue().length()>=length)
literalFound = true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,6 @@ public class SecureExamRunConfiguration extends RunConfiguration {
private final int numberOfMutationsToConsider;
private final ExternalProcess externalProcess;

public Mode mode() {
return Mode.EXAM;
}

public SecureExamRunConfiguration(RunConfiguration runConfigurationToClone) {
this.classesUnderTest = runConfigurationToClone.classesUnderTest();
this.listOfMutants = runConfigurationToClone.listOfMutants();
Expand All @@ -28,6 +24,10 @@ public SecureExamRunConfiguration(RunConfiguration runConfigurationToClone) {
this.successMessage = runConfigurationToClone.successMessage();
}

public Mode mode() {
return Mode.EXAM;
}

@Override
public Map<String, Float> weights() {
return new HashMap<>() {{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,10 @@ public List<ExecutionStep> getSteps() {
case GRADING -> {
return getGradingMode();
}
default -> {
return Collections.emptyList();
}
}

return Collections.emptyList();
}

public boolean shouldShowFullHints() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,19 +34,16 @@ public class CollectCoverageInformationStep implements ExecutionStep {

@Override
public void execute(Context ctx, ResultBuilder result) {

// Skip step if disabled
if (ctx.getRunConfiguration().skipJacoco()) {
return;
}

if(!ctx.hasJacocoRuntime()) {
throw new RuntimeException("Failed when getting coverage information!");
}

DirectoryConfiguration dirCfg = ctx.getDirectoryConfiguration();
RunConfiguration runCfg = ctx.getRunConfiguration();

RuntimeData data = ctx.getJacocoData();
IRuntime runtime = ctx.getJacocoRuntime();

Expand Down Expand Up @@ -141,4 +138,9 @@ private void generateReport(DirectoryConfiguration dirCfg, String testClass,
public boolean equals(Object other) {
return other instanceof CollectCoverageInformationStep;
}

@Override
public int hashCode() {
return super.hashCode();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -49,20 +49,18 @@ public void execute(Context ctx, ResultBuilder result) {
* So, all the libraries available (JUnit, etc) will be reused here
*/
Collection<File> listOfFiles = FilesUtils.getAllJavaFiles(dirCfg.getWorkingDir());

Iterable<? extends JavaFileObject > sources =
manager.getJavaFileObjectsFromFiles(listOfFiles);
Iterable<? extends JavaFileObject > sources = manager.getJavaFileObjectsFromFiles(listOfFiles);

ClassNameScanner scanner = new ClassNameScanner();
ClassNameProcessor processor = new ClassNameProcessor(scanner);

List<String> options = ctx.hasLibrariesToBeIncluded() ? Arrays.asList(new String[] { "-cp", asClassPath(ctx.getLibrariesToBeIncludedInCompilation()) }) : null;
List<String> options = ctx.hasLibrariesToBeIncluded() ? Arrays.asList(
new String[] { "-cp", asClassPath(ctx.getLibrariesToBeIncludedInCompilation()) }) : null;
JavaCompiler.CompilationTask task = compiler.getTask(null, manager, diagnostics, options, null, sources);
task.setProcessors(Arrays.asList(processor));

/*
* Compiles. The .class files will be saved in the same directory
* as the java files.
* Compiles. The .class files will be saved in the same directory as the java files.
*/
try {
boolean compilationResult = task.call();
Expand Down Expand Up @@ -121,4 +119,8 @@ public boolean equals(Object other) {
return other instanceof CompilationStep;
}

@Override
public int hashCode() {
return super.hashCode();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,9 @@ public void execute(Context ctx, ResultBuilder result) {
public boolean equals(Object other) {
return other instanceof GetRunConfigurationStep;
}

@Override
public int hashCode() {
return super.hashCode();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -102,4 +102,9 @@ private void instrumentAllInDirectory(Instrumenter instr, File directory, FromBy
public boolean equals(Object other) {
return other instanceof InstrumentCodeForCoverageStep;
}

@Override
public int hashCode() {
return super.hashCode();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,9 @@ public void execute(Context ctx, ResultBuilder result) {
public boolean equals(Object other) {
return other instanceof KillExternalProcessStep;
}

@Override
public int hashCode() {
return super.hashCode();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,9 @@ public void execute(Context ctx, ResultBuilder result) {
public boolean equals(Object other) {
return other instanceof OrganizeSourceCodeStep;
}

@Override
public int hashCode() {
return super.hashCode();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -53,4 +53,9 @@ private URL toURL(Path path) {
public boolean equals(Object other) {
return other instanceof ReplaceClassloaderStep;
}

@Override
public int hashCode() {
return super.hashCode();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,9 @@ public void execute(Context ctx, ResultBuilder result) {
public boolean equals(Object other) {
return other instanceof RunCodeChecksStep;
}

@Override
public int hashCode() {
return super.hashCode();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,9 @@ public void execute(Context ctx, ResultBuilder result) {
public boolean equals(Object other) {
return other instanceof RunExternalProcessStep;
}

@Override
public int hashCode() {
return super.hashCode();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,11 @@ public boolean equals(Object other) {
return other instanceof RunJUnitTestsStep;
}

@Override
public int hashCode() {
return super.hashCode();
}

public static class AdditionalReportJUnitListener implements TestExecutionListener {

private ResultBuilder result;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,4 +54,9 @@ public void execute(Context ctx, ResultBuilder result) {
public boolean equals(Object other) {
return other instanceof RunMetaTestsStep;
}

@Override
public int hashCode() {
return super.hashCode();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,9 @@ public void execute(Context ctx, ResultBuilder result) {
public boolean equals(Object other) {
return other instanceof RunPenaltyCodeChecksStep;
}

@Override
public int hashCode() {
return super.hashCode();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -141,4 +141,9 @@ private PrintStream silencePitest() {
public boolean equals(Object other) {
return other instanceof RunPitestStep;
}

@Override
public int hashCode() {
return super.hashCode();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -102,4 +102,9 @@ private boolean checkForKeywords(String code, ResultBuilder result) {
public boolean equals(Object other) {
return other instanceof SourceCodeSecurityCheckStep;
}

@Override
public int hashCode() {
return super.hashCode();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public int getTotalNumberOfChecks() {
}

public int getTotalNumberOfChecks(boolean includeWeight) {
return checkResults.stream().mapToInt(c -> (includeWeight ? c.getWeight() : 1)).sum();
return checkResults.stream().mapToInt(c -> includeWeight ? c.getWeight() : 1).sum();
}

public List<CodeCheckResult> getCheckResults() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,7 @@ public void logJacoco(Collection<IClassCoverage> coverages) {
totalCoveredBranches, totalBranches, coverageLineByLine);
}

@SuppressWarnings("checkstyle:methodLength")
private CoverageLineByLine getCoverageLineByLine(Collection<IClassCoverage> coverages) {
List<Integer> fullyCoveredLines = new ArrayList<>();
List<Integer> partiallyCoveredLines = new ArrayList<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ public static String findSolution(String workdir) throws FileNotFoundException {
.orElseThrow(() -> new FileNotFoundException("Solution file does not exist."));
}

@SuppressWarnings("checkstyle:UnnecessaryParenthesesCheck")
public static String findLibrary(String workdir) throws FileNotFoundException {
return getAllJavaFiles(workdir)
.stream().filter(x -> x.getAbsolutePath().endsWith("Library.java")
Expand Down
Loading

0 comments on commit a266efb

Please sign in to comment.