Skip to content

Commit a6d4691

Browse files
committed
Add Gradle task to regenerate test mapping files
1 parent d66f1a5 commit a6d4691

File tree

14 files changed

+526
-149
lines changed

14 files changed

+526
-149
lines changed

build.gradle

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ allprojects {
4444
spotless {
4545
java {
4646
licenseHeaderFile(rootProject.file("HEADER")).yearSeparator(", ")
47+
targetExclude 'src/test/java/net/fabricmc/mappingio/lib/**/*.java'
4748
}
4849
}
4950

@@ -183,6 +184,16 @@ jar {
183184
}
184185
}
185186

187+
task generateTestMappings(type: JavaExec, dependsOn: testClasses) {
188+
classpath sourceSets.test.runtimeClasspath
189+
mainClass = 'net.fabricmc.mappingio.TestFileUpdater'
190+
}
191+
192+
task updateTestMappings(type: Copy, dependsOn: generateTestMappings) {
193+
from 'build/resources/test/'
194+
into 'src/test/resources/'
195+
}
196+
186197
// A task to ensure that the version being released has not already been released.
187198
task checkVersion {
188199
doFirst {

mapping-io-extras/src/test/java/net/fabricmc/mappingio/extras/MappingTreeRemapperTest.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,20 +19,23 @@
1919
import static org.junit.jupiter.api.Assertions.assertEquals;
2020
import static org.junit.jupiter.api.Assertions.assertThrows;
2121

22+
import java.io.IOException;
23+
2224
import org.junit.jupiter.api.BeforeAll;
2325
import org.junit.jupiter.api.Test;
2426
import org.objectweb.asm.Type;
2527

2628
import net.fabricmc.mappingio.TestHelper;
2729
import net.fabricmc.mappingio.tree.MappingTree;
30+
import net.fabricmc.mappingio.tree.MemoryMappingTree;
2831

2932
public class MappingTreeRemapperTest {
3033
private static MappingTree mappingTree;
3134
private static MappingTreeRemapper remapper;
3235

3336
@BeforeAll
34-
public static void setup() {
35-
mappingTree = TestHelper.createTestTree();
37+
public static void setup() throws IOException {
38+
mappingTree = TestHelper.acceptTestMappings(new MemoryMappingTree());
3639
remapper = new MappingTreeRemapper(mappingTree, "source", "target");
3740
}
3841

src/main/java/net/fabricmc/mappingio/format/enigma/EnigmaDirReader.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,9 @@ public static void read(Path dir, MappingVisitor visitor) throws IOException {
4848
}
4949

5050
public static void read(Path dir, String sourceNs, String targetNs, MappingVisitor visitor) throws IOException {
51+
if (!Files.exists(dir)) throw new IOException("Directory does not exist: " + dir);
52+
if (!Files.isDirectory(dir)) throw new IOException("Not a directory: " + dir);
53+
5154
Set<MappingFlag> flags = visitor.getFlags();
5255
MappingVisitor parentVisitor = null;
5356

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
/*
2+
* Copyright (c) 2024 FabricMC
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package net.fabricmc.mappingio;
18+
19+
import java.io.IOException;
20+
import java.nio.file.Path;
21+
22+
import net.fabricmc.mappingio.format.MappingFormat;
23+
24+
public class TestFileUpdater {
25+
public static void main(String[] args) throws IOException {
26+
for (MappingFormat format : MappingFormat.values()) {
27+
if (!format.hasWriter) {
28+
continue;
29+
}
30+
31+
Path defaultPath = TestHelper.MappingDirs.VALID.resolve(TestHelper.getFileName(format));
32+
Path holesPath = TestHelper.MappingDirs.VALID_WITH_HOLES.resolve(TestHelper.getFileName(format));
33+
Path repeatPath = TestHelper.MappingDirs.REPEATED_ELEMENTS.resolve(TestHelper.getFileName(format));
34+
35+
TestHelper.acceptTestMappings(MappingWriter.create(defaultPath, format));
36+
TestHelper.acceptTestMappingsWithHoles(MappingWriter.create(holesPath, format));
37+
38+
if (format != MappingFormat.ENIGMA_DIR) {
39+
TestHelper.acceptTestMappingsWithRepeats(
40+
MappingWriter.create(repeatPath, format),
41+
format != MappingFormat.ENIGMA_FILE,
42+
format != MappingFormat.ENIGMA_FILE);
43+
}
44+
}
45+
}
46+
}

0 commit comments

Comments
 (0)