Skip to content

Commit

Permalink
Fix tests and update some deps
Browse files Browse the repository at this point in the history
  • Loading branch information
LexManos committed Mar 18, 2024
1 parent e90dd9d commit 5b33e42
Show file tree
Hide file tree
Showing 100 changed files with 111 additions and 153 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ jobs:
build:
uses: MinecraftForge/SharedActions/.github/workflows/gradle.yml@main
with:
java: 8
java: 17
gradle_tasks: "publish"
artifact_name: "JarCompatibilityChecker"
secrets:
Expand Down
16 changes: 0 additions & 16 deletions .teamcity/patches/buildTypes/JarCompatibilityChecker__Build.kts

This file was deleted.

This file was deleted.

This file was deleted.

31 changes: 0 additions & 31 deletions .teamcity/patches/projects/_Self.kts

This file was deleted.

28 changes: 15 additions & 13 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,14 @@ import net.minecraftforge.gradleutils.PomUtils
plugins {
id 'java'
id 'maven-publish'
id 'org.cadixdev.licenser' version '0.6.1'
id 'com.github.ben-manes.versions' version '0.50.0'
id 'com.github.johnrengelman.shadow' version '8.1.1'
id 'net.minecraftforge.gradleutils' version '2.+'
id 'net.minecraftforge.gradleutils' version '[2.3,2.4)'
id 'net.minecraftforge.licenser' version '1.0.1'
}

group = 'net.minecraftforge'
version = gradleutils.getTagOffsetVersion()
version = gradleutils.tagOffsetVersion
println "Version: $version"

java {
Expand All @@ -26,13 +27,14 @@ repositories {
}

dependencies {
implementation 'org.ow2.asm:asm-commons:9.3'
implementation 'net.sf.jopt-simple:jopt-simple:5.0.4'
implementation 'com.google.code.gson:gson:2.9.0'
implementation 'com.google.guava:guava:31.1-jre'
implementation 'org.jetbrains:annotations:23.0.0'

testImplementation 'junit:junit:4.13.2'
implementation(libs.bundles.asm)
implementation(libs.jopt.simple)
implementation(libs.gson)
implementation(libs.guava)
compileOnly(libs.nulls)

testImplementation(libs.junit.api)
testRuntimeOnly(libs.bundles.junit.runtime)
}

tasks.named('jar', Jar).configure {
Expand All @@ -42,8 +44,8 @@ tasks.named('jar', Jar).configure {

manifest {
attributes([
'Main-Class': 'net.minecraftforge.jarcompatibilitychecker.ConsoleTool',
'Implementation-Version': project.version
'Main-Class': 'net.minecraftforge.jarcompatibilitychecker.ConsoleTool',
'Implementation-Version': project.version
])
}
}
Expand All @@ -68,7 +70,7 @@ tasks.withType(JavaCompile).configureEach {
}

changelog {
fromTag '0.1'
from '0.1'
}

license {
Expand Down
23 changes: 23 additions & 0 deletions settings.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,27 @@ plugins {
id 'org.gradle.toolchains.foojay-resolver-convention' version '0.7.0'
}

dependencyResolutionManagement {
versionCatalogs {
libs {
library('nulls', 'org.jetbrains:annotations:23.0.0')
library('jopt-simple', 'net.sf.jopt-simple:jopt-simple:5.0.4')
library('gson', 'com.google.code.gson:gson:2.9.0')
library('guava', 'com.google.guava:guava:31.1-jre')

version('junit', '5.10.1')
library('junit-api', 'org.junit.jupiter', 'junit-jupiter-api').versionRef('junit')
library('junit-engine', 'org.junit.jupiter', 'junit-jupiter-engine').versionRef('junit')
library('junit-platform-launcher', 'org.junit.platform:junit-platform-launcher:1.10.1')
bundle('junit-runtime', ['junit-engine', 'junit-platform-launcher'])

version('asm', '9.6')
library('asm', 'org.ow2.asm', 'asm' ).versionRef('asm')
library('asm-tree', 'org.ow2.asm', 'asm-tree' ).versionRef('asm')
library('asm-commons', 'org.ow2.asm', 'asm-commons').versionRef('asm')
bundle('asm', ['asm', 'asm-tree', 'asm-commons'])
}
}
}

rootProject.name = 'JarCompatibilityChecker'
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,10 @@ public static void readFolder(Path folder, Map<String, ClassInfo> classes) throw
for (Path entryPath : iterable) {
Path namePath = entryPath.getFileName();
String name = namePath == null ? null : namePath.toString();
if (name == null || !name.endsWith(".class") || name.startsWith("."))
if (name == null || name.startsWith("."))
continue;

if (!name.endsWith(".class") && !name.endsWith(".dat"))
continue;

ClassReader reader;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
import net.minecraftforge.jarcompatibilitychecker.core.Incompatibility;
import net.minecraftforge.jarcompatibilitychecker.data.ClassInfo;
import org.jetbrains.annotations.Nullable;
import org.junit.Assert;

import java.io.File;
import java.io.IOException;
Expand All @@ -21,10 +20,12 @@
import java.util.List;
import java.util.Locale;

import static org.junit.jupiter.api.Assertions.*;

public abstract class BaseCompatibilityTest {
protected Path getRoot() {
URL url = this.getClass().getResource("/test.marker");
Assert.assertNotNull("Could not find test.marker", url);
assertNotNull(url, "Could not find test.marker");

try {
return new File(url.toURI()).getParentFile().toPath();
Expand All @@ -38,18 +39,18 @@ protected void assertIncompatible(boolean checkBinary, String folder, String cla
throw new IllegalArgumentException("Must provide at least one incompatibility to test");

ClassInfoComparisonResults comparisonResults = getComparisonResults(checkBinary, folder, className);
Assert.assertFalse(className + " was compatible when incompatibilities were expected", comparisonResults.isCompatible());
assertFalse(comparisonResults.isCompatible(), className + " was compatible when incompatibilities were expected");

List<Incompatibility<?>> incompatibilities = comparisonResults.getIncompatibilities();
Assert.assertEquals(className + " had the wrong number of incompatibilities: " + comparisonResults, testIncompatibilities.length, incompatibilities.size());
assertEquals(testIncompatibilities.length, incompatibilities.size(), className + " had the wrong number of incompatibilities: " + comparisonResults);

for (int i = 0; i < testIncompatibilities.length; i++) {
IncompatibilityData testData = testIncompatibilities[i];
Incompatibility<?> incompatibility = incompatibilities.get(i);
Assert.assertEquals(className + " had an incompatibility with the wrong name: " + incompatibility, testData.getName(), incompatibility.getInfo().getName());
Assert.assertEquals(className + " had an incompatibility with the wrong descriptor: " + incompatibility, testData.getDesc(), incompatibility.getInfo().getDescriptor());
Assert.assertEquals(className + " had an incompatibility with the wrong message: " + incompatibility, testData.getMessage(), incompatibility.getMessage());
Assert.assertEquals(className + " had an incompatibility with mismatch error vs. warning: " + incompatibility, testData.isError(), incompatibility.isError());
assertEquals(testData.getName(), incompatibility.getInfo().getName(), className + " had an incompatibility with the wrong name: " + incompatibility);
assertEquals(testData.getDesc(), incompatibility.getInfo().getDescriptor(), className + " had an incompatibility with the wrong descriptor: " + incompatibility);
assertEquals(testData.getMessage(), incompatibility.getMessage(), className + " had an incompatibility with the wrong message: " + incompatibility);
assertEquals(testData.isError(), incompatibility.isError(), className + " had an incompatibility with mismatch error vs. warning: " + incompatibility);
}
}

Expand All @@ -69,21 +70,21 @@ protected void assertIncompatible(boolean checkBinary, String folder, String cla
if (formatArgs.length > 0)
message = String.format(Locale.ROOT, message, formatArgs);
ClassInfoComparisonResults comparisonResults = getComparisonResults(checkBinary, folder, className);
Assert.assertFalse(className + " was compatible when incompatibilities were expected", comparisonResults.isCompatible());
assertFalse(comparisonResults.isCompatible(), className + " was compatible when incompatibilities were expected");

List<Incompatibility<?>> incompatibilities = comparisonResults.getIncompatibilities();
Assert.assertEquals(className + " had more than one incompatibility when one was expected: " + comparisonResults, 1, incompatibilities.size());
assertEquals(1, incompatibilities.size(), className + " had more than one incompatibility when one was expected: " + comparisonResults);

Incompatibility<?> incompatibility = incompatibilities.get(0);
Assert.assertEquals(className + " had an incompatibility with the wrong name: " + incompatibility, name, incompatibility.getInfo().getName());
Assert.assertEquals(className + " had an incompatibility with the wrong descriptor: " + incompatibility, desc, incompatibility.getInfo().getDescriptor());
Assert.assertEquals(className + " had an incompatibility with the wrong message: " + incompatibility, message, incompatibility.getMessage());
Assert.assertEquals(className + " had an incompatibility with mismatch error vs. warning: " + incompatibility, isError, incompatibility.isError());
assertEquals(name, incompatibility.getInfo().getName(), className + " had an incompatibility with the wrong name: " + incompatibility);
assertEquals(desc, incompatibility.getInfo().getDescriptor(), className + " had an incompatibility with the wrong descriptor: " + incompatibility);
assertEquals(message, incompatibility.getMessage(), className + " had an incompatibility with the wrong message: " + incompatibility);
assertEquals(isError, incompatibility.isError(), className + " had an incompatibility with mismatch error vs. warning: " + incompatibility);
}

protected void assertCompatible(boolean checkBinary, String folder, String className) {
ClassInfoComparisonResults comparisonResults = getComparisonResults(checkBinary, folder, className);
Assert.assertTrue(className + " had incompatibilities when none were expected: " + comparisonResults, comparisonResults.isCompatible());
assertTrue(comparisonResults.isCompatible(), className + " had incompatibilities when none were expected: " + comparisonResults);
}

protected ClassInfoComparisonResults getComparisonResults(boolean checkBinary, String folderName, String className) {
Expand All @@ -93,19 +94,19 @@ protected ClassInfoComparisonResults getComparisonResults(boolean checkBinary, S
throw new IllegalArgumentException("Folder \"" + folderName + "\" does not match the real path \"" + folder.toRealPath().getFileName().toString() + "\"");

Path baseFolder = folder.resolve("base");
Assert.assertTrue(baseFolder + " not found", Files.exists(baseFolder));
Assert.assertEquals("Base folder in " + folderName + " has invalid casing", baseFolder.toAbsolutePath(), baseFolder.toRealPath());
assertTrue(Files.exists(baseFolder), baseFolder + " not found");
assertEquals(baseFolder.toAbsolutePath(), baseFolder.toRealPath(), "Base folder in " + folderName + " has invalid casing");

Path inputFolder = folder.resolve("input");
boolean inputExists = Files.exists(inputFolder); // If it doesn't exist, all base classes got deleted, which is technically valid.
if (inputExists)
Assert.assertEquals("Input folder in " + folderName + " has invalid casing", inputFolder.toAbsolutePath(), inputFolder.toRealPath());
assertEquals(inputFolder.toAbsolutePath(), inputFolder.toRealPath(), "Input folder in " + folderName + " has invalid casing");

ClassInfoCache baseCache = ClassInfoCache.fromFolder(baseFolder);
ClassInfoCache inputCache = inputExists ? ClassInfoCache.fromFolder(inputFolder) : ClassInfoCache.empty();

ClassInfo baseClassInfo = baseCache.getMainClassInfo(className);
Assert.assertNotNull("Class with name " + className + " not found in " + baseFolder, baseClassInfo);
assertNotNull(baseClassInfo, "Class with name " + className + " not found in " + baseFolder);

return ClassInfoComparer.compare(checkBinary, baseCache, baseClassInfo, inputCache, inputCache.getMainClassInfo(className));
} catch (IOException e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,11 @@
package net.minecraftforge.jarcompatibilitychecker.test;

import net.minecraftforge.jarcompatibilitychecker.core.IncompatibilityMessages;
import org.junit.Test;

import java.nio.file.Path;

import org.junit.jupiter.api.Test;

public class ClassTests extends BaseCompatibilityTest {
@Override
protected Path getRoot() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,11 @@
package net.minecraftforge.jarcompatibilitychecker.test;

import net.minecraftforge.jarcompatibilitychecker.core.IncompatibilityMessages;
import org.junit.Test;

import java.nio.file.Path;

import org.junit.jupiter.api.Test;

public class FieldTests extends BaseCompatibilityTest {
@Override
protected Path getRoot() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,11 @@
package net.minecraftforge.jarcompatibilitychecker.test;

import net.minecraftforge.jarcompatibilitychecker.core.IncompatibilityMessages;
import org.junit.Test;

import java.nio.file.Path;

import org.junit.jupiter.api.Test;

public class FunctionalInterfaceTests extends BaseCompatibilityTest {
@Override
protected Path getRoot() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,11 @@
package net.minecraftforge.jarcompatibilitychecker.test;

import net.minecraftforge.jarcompatibilitychecker.core.IncompatibilityMessages;
import org.junit.Test;

import java.nio.file.Path;

import org.junit.jupiter.api.Test;

public class InterfaceTests extends BaseCompatibilityTest {
@Override
protected Path getRoot() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,11 @@
package net.minecraftforge.jarcompatibilitychecker.test;

import net.minecraftforge.jarcompatibilitychecker.core.IncompatibilityMessages;
import org.junit.Test;

import java.nio.file.Path;

import org.junit.jupiter.api.Test;

public class MethodTests extends BaseCompatibilityTest {
@Override
protected Path getRoot() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,11 @@
package net.minecraftforge.jarcompatibilitychecker.test;

import net.minecraftforge.jarcompatibilitychecker.core.IncompatibilityMessages;
import org.junit.Test;

import java.nio.file.Path;

import org.junit.jupiter.api.Test;

public class SuperClassTests extends BaseCompatibilityTest {
@Override
protected Path getRoot() {
Expand Down
Loading

0 comments on commit 5b33e42

Please sign in to comment.