Skip to content

Commit

Permalink
Add Gradle task for (re)generating test mapping files (#113)
Browse files Browse the repository at this point in the history
  • Loading branch information
NebelNidas authored Aug 31, 2024
1 parent d66f1a5 commit dad2c69
Show file tree
Hide file tree
Showing 14 changed files with 529 additions and 150 deletions.
15 changes: 14 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ allprojects {
spotless {
java {
licenseHeaderFile(rootProject.file("HEADER")).yearSeparator(", ")
targetExclude 'src/test/java/net/fabricmc/mappingio/lib/**/*.java'
}
}

Expand Down Expand Up @@ -183,8 +184,20 @@ jar {
}
}

tasks.register("generateTestMappings", JavaExec) {
dependsOn("testClasses")
classpath = sourceSets.test.runtimeClasspath
mainClass = 'net.fabricmc.mappingio.TestFileUpdater'
}

tasks.register("updateTestMappings", Copy) {
dependsOn("generateTestMappings")
from 'build/resources/test/'
into 'src/test/resources/'
}

// A task to ensure that the version being released has not already been released.
task checkVersion {
tasks.register("checkVersion") {
doFirst {
def xml = new URL("https://maven.fabricmc.net/net/fabricmc/mapping-io/maven-metadata.xml").text
def metadata = new XmlSlurper().parseText(xml)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,20 +19,23 @@
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertThrows;

import java.io.IOException;

import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.objectweb.asm.Type;

import net.fabricmc.mappingio.TestHelper;
import net.fabricmc.mappingio.tree.MappingTree;
import net.fabricmc.mappingio.tree.MemoryMappingTree;

public class MappingTreeRemapperTest {
private static MappingTree mappingTree;
private static MappingTreeRemapper remapper;

@BeforeAll
public static void setup() {
mappingTree = TestHelper.createTestTree();
public static void setup() throws IOException {
mappingTree = TestHelper.acceptTestMappings(new MemoryMappingTree());
remapper = new MappingTreeRemapper(mappingTree, "source", "target");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@ public static void read(Path dir, MappingVisitor visitor) throws IOException {
}

public static void read(Path dir, String sourceNs, String targetNs, MappingVisitor visitor) throws IOException {
if (!Files.exists(dir)) throw new IOException("Directory does not exist: " + dir);
if (!Files.isDirectory(dir)) throw new IOException("Not a directory: " + dir);

Set<MappingFlag> flags = visitor.getFlags();
MappingVisitor parentVisitor = null;

Expand Down
46 changes: 46 additions & 0 deletions src/test/java/net/fabricmc/mappingio/TestFileUpdater.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/*
* Copyright (c) 2024 FabricMC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package net.fabricmc.mappingio;

import java.io.IOException;
import java.nio.file.Path;

import net.fabricmc.mappingio.format.MappingFormat;

public class TestFileUpdater {
public static void main(String[] args) throws IOException {
for (MappingFormat format : MappingFormat.values()) {
if (!format.hasWriter) {
continue;
}

Path defaultPath = TestHelper.MappingDirs.VALID.resolve(TestHelper.getFileName(format));
Path holesPath = TestHelper.MappingDirs.VALID_WITH_HOLES.resolve(TestHelper.getFileName(format));
Path repeatPath = TestHelper.MappingDirs.REPEATED_ELEMENTS.resolve(TestHelper.getFileName(format));

TestHelper.acceptTestMappings(MappingWriter.create(defaultPath, format));
TestHelper.acceptTestMappingsWithHoles(MappingWriter.create(holesPath, format));

if (format != MappingFormat.ENIGMA_DIR) {
TestHelper.acceptTestMappingsWithRepeats(
MappingWriter.create(repeatPath, format),
format != MappingFormat.ENIGMA_FILE,
format != MappingFormat.ENIGMA_FILE);
}
}
}
}
Loading

0 comments on commit dad2c69

Please sign in to comment.