Skip to content

Commit 347a359

Browse files
authored
Merge pull request #15 from FabricCompatibilityLayers/feature/sonar-jacoco
Run tests using JUnit and share Coverage + Results to Sonar
2 parents f2fe4cd + d6096b3 commit 347a359

8 files changed

Lines changed: 140 additions & 62 deletions

File tree

.github/workflows/build_and_publish.yml

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,30 @@
1212
with:
1313
java-version: 17
1414
distribution: temurin
15-
- name: Build with Gradle
16-
run: ./gradlew build
15+
16+
- name: Build
17+
run: ./gradlew build -x test
18+
19+
- name: Test
20+
run: ./gradlew test check
21+
22+
- name: Sonar
23+
run: ./gradlew jacocoTestCoverageVerification jacocoTestReport sonar
24+
env:
25+
SONAR_URL: ${{ secrets.SONAR_URL }}
26+
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
27+
1728
- if: github.repository == 'FabricCompatibilityLayers/Mod-Remapping-API' && github.ref_type == 'tag'
1829
name: Publish
1930
run: ./gradlew build modrinth
2031
env:
21-
MODRINTH_TOKEN: ${{ secrets.MODRINTH_TOKEN }}
32+
MODRINTH_TOKEN: ${{ secrets.MODRINTH_TOKEN }}
33+
34+
- name: Store reports if any
35+
if: failure()
36+
uses: actions/upload-artifact@v4
37+
with:
38+
name: reports
39+
path: |
40+
**/build/reports/
41+
**/build/test-results/

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,3 +28,4 @@ run/
2828

2929
./ModLoader*
3030
jars/
31+
mod-remapping-api

build.gradle

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ plugins {
44
id 'maven-publish'
55
id 'com.github.johnrengelman.shadow' version '8.1.1'
66
id "com.modrinth.minotaur" version "2.+"
7+
id 'jacoco'
8+
id "org.sonarqube" version "5.0.0.4638"
79
}
810

911
version = project.mod_version
@@ -54,6 +56,8 @@ dependencies {
5456
implementation(include("io.github.llamalad7:mixinextras-fabric:${project.mixin_extras_version}"))
5557
implementation(include("com.github.thecatcore.CursedMixinExtensions:fabric:1.0.0"))
5658
implementation(include("com.github.thecatcore:WFVAIO:1.1.0"))
59+
60+
testImplementation "net.fabricmc:fabric-loader-junit:${project.loader_version}"
5761
}
5862

5963
base {
@@ -109,13 +113,23 @@ remapJar {
109113
inputFile = file(shadowJar.archivePath)
110114
}
111115

112-
tasks.register('testJar', Jar) {
113-
from sourceSets.test.output
114-
destinationDirectory = new File(project.buildDir, "devlibs")
115-
archiveClassifier = "testmod"
116+
test {
117+
useJUnitPlatform()
118+
}
119+
120+
jacocoTestReport {
121+
reports {
122+
xml.required = true
123+
html.outputLocation = layout.buildDirectory.dir('jacocoHtml')
124+
}
116125
}
117126

118-
tasks.build.dependsOn testJar
127+
sonar {
128+
properties {
129+
property "sonar.host.url", System.getenv("SONAR_URL")
130+
property "sonar.token", System.getenv("SONAR_TOKEN")
131+
}
132+
}
119133

120134
// configure the maven publication
121135
publishing {

src/main/java/fr/catcore/modremapperapi/remapping/RemapUtil.java

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,10 @@
2222

2323
import java.io.*;
2424
import java.net.URL;
25-
import java.nio.charset.StandardCharsets;
2625
import java.nio.file.Files;
2726
import java.nio.file.Path;
28-
import java.nio.file.Paths;
2927
import java.util.*;
3028
import java.util.function.Supplier;
31-
import java.util.stream.Collectors;
3229
import java.util.zip.ZipEntry;
3330
import java.util.zip.ZipInputStream;
3431

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

660-
public static List<Path> getRemapClasspath() throws IOException {
661-
String remapClasspathFile = System.getProperty("fabric.remapClasspathFile");
662-
663-
if (remapClasspathFile == null) {
664-
throw new RuntimeException("No remapClasspathFile provided");
665-
}
666-
667-
String content = new String(Files.readAllBytes(Paths.get(remapClasspathFile)), StandardCharsets.UTF_8);
668-
669-
return Arrays.stream(content.split(File.pathSeparator))
670-
.map(Paths::get)
671-
.collect(Collectors.toList());
672-
}
673-
674658
@Deprecated
675659
public static String getNativeNamespace() {
676660
return MappingsUtils.getNativeNamespace();

src/main/java/fr/catcore/modremapperapi/utils/MappingsUtils.java

Lines changed: 3 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@
33
import fr.catcore.modremapperapi.ModRemappingAPI;
44
import fr.catcore.modremapperapi.remapping.RemapUtil;
55
import io.github.fabriccompatibiltylayers.modremappingapi.impl.MappingsUtilsImpl;
6+
import io.github.fabriccompatibiltylayers.modremappingapi.impl.RemapUtils;
67
import net.fabricmc.api.EnvType;
78
import net.fabricmc.loader.api.*;
8-
import net.fabricmc.loader.impl.launch.FabricLauncherBase;
99
import net.fabricmc.mappingio.MappingReader;
1010
import net.fabricmc.mappingio.MappingVisitor;
1111
import net.fabricmc.mappingio.tree.MappingTree;
@@ -17,7 +17,7 @@
1717
import java.nio.file.Path;
1818
import java.util.*;
1919

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

2222
public class MappingsUtils {
2323
@Deprecated
@@ -132,35 +132,7 @@ public static void addMinecraftJar(TinyRemapper remapper) throws IOException {
132132
throw new RuntimeException("Failed to populate default remap classpath", e);
133133
}
134134
} else {
135-
ObjectShare share = FabricLoader.getInstance().getObjectShare();
136-
Object inputs = share.get("fabric-loader:inputGameJars");
137-
List<Path> list = new ArrayList<>();
138-
139-
Object oldJar = FabricLoader.getInstance().getObjectShare().get("fabric-loader:inputGameJar");
140-
141-
List<Path> classPaths = FabricLauncherBase.getLauncher().getClassPath();
142-
143-
if (inputs instanceof List) {
144-
List<Path> paths = (List<Path>) inputs;
145-
146-
if (oldJar instanceof Path) {
147-
if (paths.get(0).toString().equals(oldJar.toString())) {
148-
list.addAll(paths);
149-
} else {
150-
list.add((Path) oldJar);
151-
}
152-
} else {
153-
list.addAll(paths);
154-
}
155-
} else {
156-
list.add((Path) oldJar);
157-
}
158-
159-
list.addAll(classPaths);
160-
161-
Object realmsJar = share.get("fabric-loader:inputRealmsJar");
162-
163-
if (realmsJar instanceof Path) list.add((Path) realmsJar);
135+
List<Path> list = RemapUtils.getClassPathFromObjectShare();
164136

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

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
package io.github.fabriccompatibiltylayers.modremappingapi.impl;
2+
3+
import net.fabricmc.loader.api.FabricLoader;
4+
import net.fabricmc.loader.api.ObjectShare;
5+
import net.fabricmc.loader.impl.launch.FabricLauncherBase;
6+
import org.jetbrains.annotations.NotNull;
7+
8+
import java.io.File;
9+
import java.io.IOException;
10+
import java.nio.charset.StandardCharsets;
11+
import java.nio.file.Files;
12+
import java.nio.file.Path;
13+
import java.nio.file.Paths;
14+
import java.util.ArrayList;
15+
import java.util.Arrays;
16+
import java.util.List;
17+
import java.util.stream.Collectors;
18+
19+
public class RemapUtils {
20+
public static List<Path> getRemapClasspath() throws IOException {
21+
String remapClasspathFile = System.getProperty("fabric.remapClasspathFile");
22+
23+
if (remapClasspathFile == null) {
24+
System.out.println("remapClasspathFile is null! Falling back to ObjectShare.");
25+
return getClassPathFromObjectShare();
26+
}
27+
28+
String content = new String(Files.readAllBytes(Paths.get(remapClasspathFile)), StandardCharsets.UTF_8);
29+
30+
return Arrays.stream(content.split(File.pathSeparator))
31+
.map(Paths::get)
32+
.collect(Collectors.toList());
33+
}
34+
35+
public static @NotNull List<Path> getClassPathFromObjectShare() {
36+
ObjectShare share = FabricLoader.getInstance().getObjectShare();
37+
Object inputs = share.get("fabric-loader:inputGameJars");
38+
List<Path> list = new ArrayList<>();
39+
40+
Object oldJar = FabricLoader.getInstance().getObjectShare().get("fabric-loader:inputGameJar");
41+
42+
List<Path> classPaths = FabricLauncherBase.getLauncher().getClassPath();
43+
44+
if (inputs instanceof List) {
45+
List<Path> paths = (List<Path>) inputs;
46+
47+
if (oldJar instanceof Path) {
48+
if (paths.get(0).toString().equals(oldJar.toString())) {
49+
list.addAll(paths);
50+
} else {
51+
list.add((Path) oldJar);
52+
}
53+
} else {
54+
list.addAll(paths);
55+
}
56+
} else {
57+
list.add((Path) oldJar);
58+
}
59+
60+
list.addAll(classPaths);
61+
62+
Object realmsJar = share.get("fabric-loader:inputRealmsJar");
63+
64+
if (realmsJar instanceof Path) list.add((Path) realmsJar);
65+
66+
return list;
67+
}
68+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
package io.github.fabriccompatibiltylayers.modremappingapi.test;
2+
3+
import io.github.fabriccompatibiltylayers.modremappingapi.api.MappingUtils;
4+
import net.fabricmc.loader.api.FabricLoader;
5+
import org.junit.jupiter.api.Assertions;
6+
import org.junit.jupiter.api.BeforeAll;
7+
import org.junit.jupiter.api.Test;
8+
9+
public class ModRemapperTests {
10+
@Test
11+
public void differentSourceNamespace() {
12+
Assertions.assertEquals(
13+
MappingUtils.mapClass("net/minecraft/unmapped/C_0760609"),
14+
FabricLoader.getInstance().isDevelopmentEnvironment() ?
15+
"net/minecraft/client/class_785"
16+
: "net/minecraft/class_785"
17+
);
18+
}
19+
}

src/test/java/io/github/fabriccompatibiltylayers/modremappingapi/test/TestModRemapper.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -63,11 +63,11 @@ public Optional<Supplier<InputStream>> getExtraMapping() {
6363

6464
@Override
6565
public void afterRemap() {
66-
assert Objects.equals(
67-
MappingUtils.mapClass("net/minecraft/unmapped/C_0760609"),
68-
FabricLoader.getInstance().isDevelopmentEnvironment() ?
69-
"net/minecraft/client/class_785"
70-
: "net/minecraft/class_785"
71-
);
66+
// assert Objects.equals(
67+
// MappingUtils.mapClass("net/minecraft/unmapped/C_0760609"),
68+
// FabricLoader.getInstance().isDevelopmentEnvironment() ?
69+
// "net/minecraft/client/class_785"
70+
// : "net/minecraft/class_785"
71+
// );
7272
}
7373
}

0 commit comments

Comments
 (0)