Skip to content

Commit

Permalink
Run tests using JUnit and share Coverage + Results to Sonar
Browse files Browse the repository at this point in the history
  • Loading branch information
thecatcore committed Oct 28, 2024
1 parent f2fe4cd commit 2d1c51c
Show file tree
Hide file tree
Showing 8 changed files with 134 additions and 59 deletions.
11 changes: 11 additions & 0 deletions .github/workflows/build_and_publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,19 @@
with:
java-version: 17
distribution: temurin

- name: Build with Gradle
run: ./gradlew build

- name: run test
run: ./gradlew test check

- name: sonar
run: ./gradlew jacocoTestCoverageVerification jacocoTestReport sonar
env:
SONAR_URL: ${{ secrets.SONAR_URL }}
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}

- if: github.repository == 'FabricCompatibilityLayers/Mod-Remapping-API' && github.ref_type == 'tag'
name: Publish
run: ./gradlew build modrinth
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,4 @@ run/

./ModLoader*
jars/
mod-remapping-api
24 changes: 19 additions & 5 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ plugins {
id 'maven-publish'
id 'com.github.johnrengelman.shadow' version '8.1.1'
id "com.modrinth.minotaur" version "2.+"
id 'jacoco'
id "org.sonarqube" version "5.0.0.4638"
}

version = project.mod_version
Expand Down Expand Up @@ -54,6 +56,8 @@ dependencies {
implementation(include("io.github.llamalad7:mixinextras-fabric:${project.mixin_extras_version}"))
implementation(include("com.github.thecatcore.CursedMixinExtensions:fabric:1.0.0"))
implementation(include("com.github.thecatcore:WFVAIO:1.1.0"))

testImplementation "net.fabricmc:fabric-loader-junit:${project.loader_version}"
}

base {
Expand Down Expand Up @@ -109,13 +113,23 @@ remapJar {
inputFile = file(shadowJar.archivePath)
}

tasks.register('testJar', Jar) {
from sourceSets.test.output
destinationDirectory = new File(project.buildDir, "devlibs")
archiveClassifier = "testmod"
test {
useJUnitPlatform()
}

jacocoTestReport {
reports {
xml.required = true
html.outputLocation = layout.buildDirectory.dir('jacocoHtml')
}
}

tasks.build.dependsOn testJar
sonar {
properties {
property "sonar.host.url", ENV.SONAR_URL
property "sonar.token", ENV.SONAR_TOKEN
}
}

// configure the maven publication
publishing {
Expand Down
18 changes: 1 addition & 17 deletions src/main/java/fr/catcore/modremapperapi/remapping/RemapUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,10 @@

import java.io.*;
import java.net.URL;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.*;
import java.util.function.Supplier;
import java.util.stream.Collectors;
import java.util.zip.ZipEntry;
import java.util.zip.ZipInputStream;

Expand Down Expand Up @@ -653,24 +650,11 @@ public static String getRemappedMethodName(Class<?> owner, String methodName, Cl
/**
* A shortcut to the Fabric Environment getter.
*/
@Deprecated
public static EnvType getEnvironment() {
return FabricLoader.getInstance().getEnvironmentType();
}

public static List<Path> getRemapClasspath() throws IOException {
String remapClasspathFile = System.getProperty("fabric.remapClasspathFile");

if (remapClasspathFile == null) {
throw new RuntimeException("No remapClasspathFile provided");
}

String content = new String(Files.readAllBytes(Paths.get(remapClasspathFile)), StandardCharsets.UTF_8);

return Arrays.stream(content.split(File.pathSeparator))
.map(Paths::get)
.collect(Collectors.toList());
}

@Deprecated
public static String getNativeNamespace() {
return MappingsUtils.getNativeNamespace();
Expand Down
34 changes: 3 additions & 31 deletions src/main/java/fr/catcore/modremapperapi/utils/MappingsUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
import fr.catcore.modremapperapi.ModRemappingAPI;
import fr.catcore.modremapperapi.remapping.RemapUtil;
import io.github.fabriccompatibiltylayers.modremappingapi.impl.MappingsUtilsImpl;
import io.github.fabriccompatibiltylayers.modremappingapi.impl.RemapUtils;
import net.fabricmc.api.EnvType;
import net.fabricmc.loader.api.*;
import net.fabricmc.loader.impl.launch.FabricLauncherBase;
import net.fabricmc.mappingio.MappingReader;
import net.fabricmc.mappingio.MappingVisitor;
import net.fabricmc.mappingio.tree.MappingTree;
Expand All @@ -17,7 +17,7 @@
import java.nio.file.Path;
import java.util.*;

import static fr.catcore.modremapperapi.remapping.RemapUtil.getRemapClasspath;
import static io.github.fabriccompatibiltylayers.modremappingapi.impl.RemapUtils.getRemapClasspath;

public class MappingsUtils {
@Deprecated
Expand Down Expand Up @@ -132,35 +132,7 @@ public static void addMinecraftJar(TinyRemapper remapper) throws IOException {
throw new RuntimeException("Failed to populate default remap classpath", e);
}
} else {
ObjectShare share = FabricLoader.getInstance().getObjectShare();
Object inputs = share.get("fabric-loader:inputGameJars");
List<Path> list = new ArrayList<>();

Object oldJar = FabricLoader.getInstance().getObjectShare().get("fabric-loader:inputGameJar");

List<Path> classPaths = FabricLauncherBase.getLauncher().getClassPath();

if (inputs instanceof List) {
List<Path> paths = (List<Path>) inputs;

if (oldJar instanceof Path) {
if (paths.get(0).toString().equals(oldJar.toString())) {
list.addAll(paths);
} else {
list.add((Path) oldJar);
}
} else {
list.addAll(paths);
}
} else {
list.add((Path) oldJar);
}

list.addAll(classPaths);

Object realmsJar = share.get("fabric-loader:inputRealmsJar");

if (realmsJar instanceof Path) list.add((Path) realmsJar);
List<Path> list = RemapUtils.getClassPathFromObjectShare();

Path[] classPath = list.toArray(new Path[0]);

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
package io.github.fabriccompatibiltylayers.modremappingapi.impl;

import net.fabricmc.loader.api.FabricLoader;
import net.fabricmc.loader.api.ObjectShare;
import net.fabricmc.loader.impl.launch.FabricLauncherBase;
import org.jetbrains.annotations.NotNull;

import java.io.File;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;

public class RemapUtils {
public static List<Path> getRemapClasspath() throws IOException {
String remapClasspathFile = System.getProperty("fabric.remapClasspathFile");

if (remapClasspathFile == null) {
System.out.println("remapClasspathFile is null! Falling back to ObjectShare.");
return getClassPathFromObjectShare();
}

String content = new String(Files.readAllBytes(Paths.get(remapClasspathFile)), StandardCharsets.UTF_8);

return Arrays.stream(content.split(File.pathSeparator))
.map(Paths::get)
.collect(Collectors.toList());
}

public static @NotNull List<Path> getClassPathFromObjectShare() {
ObjectShare share = FabricLoader.getInstance().getObjectShare();
Object inputs = share.get("fabric-loader:inputGameJars");
List<Path> list = new ArrayList<>();

Object oldJar = FabricLoader.getInstance().getObjectShare().get("fabric-loader:inputGameJar");

List<Path> classPaths = FabricLauncherBase.getLauncher().getClassPath();

if (inputs instanceof List) {
List<Path> paths = (List<Path>) inputs;

if (oldJar instanceof Path) {
if (paths.get(0).toString().equals(oldJar.toString())) {
list.addAll(paths);
} else {
list.add((Path) oldJar);
}
} else {
list.addAll(paths);
}
} else {
list.add((Path) oldJar);
}

list.addAll(classPaths);

Object realmsJar = share.get("fabric-loader:inputRealmsJar");

if (realmsJar instanceof Path) list.add((Path) realmsJar);

return list;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package io.github.fabriccompatibiltylayers.modremappingapi.test;

import io.github.fabriccompatibiltylayers.modremappingapi.api.MappingUtils;
import net.fabricmc.loader.api.FabricLoader;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;

public class ModRemapperTests {

@BeforeAll
static void beforeAll() {
// MixinBootstrap.init();
}

@Test
public void differentSourceNamespace() {
Assertions.assertEquals(
MappingUtils.mapClass("net/minecraft/unmapped/C_0760609"),
FabricLoader.getInstance().isDevelopmentEnvironment() ?
"net/minecraft/client/class_785"
: "net/minecraft/class_785"
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,11 @@ public Optional<Supplier<InputStream>> getExtraMapping() {

@Override
public void afterRemap() {
assert Objects.equals(
MappingUtils.mapClass("net/minecraft/unmapped/C_0760609"),
FabricLoader.getInstance().isDevelopmentEnvironment() ?
"net/minecraft/client/class_785"
: "net/minecraft/class_785"
);
// assert Objects.equals(
// MappingUtils.mapClass("net/minecraft/unmapped/C_0760609"),
// FabricLoader.getInstance().isDevelopmentEnvironment() ?
// "net/minecraft/client/class_785"
// : "net/minecraft/class_785"
// );
}
}

0 comments on commit 2d1c51c

Please sign in to comment.