Skip to content

Commit

Permalink
Merge pull request #1 from NebelNidas/mapping-file-extension-mio-inte…
Browse files Browse the repository at this point in the history
…gration

Merge upstream
  • Loading branch information
Juuxel authored Apr 6, 2024
2 parents e0fdb86 + 146589e commit a8cf4e0
Show file tree
Hide file tree
Showing 29 changed files with 718 additions and 263 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@ jobs:
build:
strategy:
matrix:
java: [ 17-jdk, 19-jdk ]
java: [ 17-ubuntu, 21-ubuntu ]
runs-on: ubuntu-22.04
container:
image: eclipse-temurin:${{ matrix.java }}
image: mcr.microsoft.com/openjdk/jdk:${{ matrix.java }}
options: --user root
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- run: ./gradlew build --stacktrace --warning-mode fail
- uses: Juuxel/publish-checkstyle-report@v1
if: ${{ failure() }}
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ jobs:
build:
runs-on: ubuntu-22.04
container:
image: eclipse-temurin:19-jdk
image: mcr.microsoft.com/openjdk/jdk:21-ubuntu
options: --user root
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- run: ./gradlew checkVersion build publish --stacktrace
env:
MAVEN_URL: ${{ secrets.MAVEN_URL }}
Expand Down
20 changes: 9 additions & 11 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,24 +1,25 @@
plugins {
id 'maven-publish'
id 'com.github.johnrengelman.shadow' version '8.1.1' apply false
}

subprojects {
apply plugin: 'java'
apply plugin: 'maven-publish'
apply plugin: 'checkstyle'

sourceCompatibility = JavaVersion.VERSION_17
targetCompatibility = JavaVersion.VERSION_17

repositories {
mavenLocal()
mavenCentral()
maven { url 'https://maven.fabricmc.net/' }
}

dependencies {
implementation 'com.google.guava:guava:30.1.1-jre'
implementation 'com.google.code.gson:gson:2.8.7'
implementation 'com.google.guava:guava:32.1.2-jre'
implementation 'com.google.code.gson:gson:2.10.1'
implementation 'net.fabricmc:mapping-io:0.5.0'

compileOnly 'org.jetbrains:annotations:24.0.1'

testImplementation 'junit:junit:4.13.2'
testImplementation 'org.hamcrest:hamcrest:2.2'
Expand All @@ -29,13 +30,10 @@ subprojects {

version = version + (System.getenv("GITHUB_ACTIONS") ? "" : "+local")

task sourcesJar(type: Jar, dependsOn: classes) {
classifier = 'sources'
from sourceSets.main.allSource
}

java {
withSourcesJar()
sourceCompatibility = JavaVersion.VERSION_17
targetCompatibility = JavaVersion.VERSION_17
}

tasks.withType(JavaCompile).configureEach {
Expand All @@ -46,7 +44,7 @@ subprojects {

checkstyle {
configFile = rootProject.file('checkstyle.xml')
toolVersion = '10.3.3'
toolVersion = '10.12.4'
}

publishing {
Expand Down
8 changes: 5 additions & 3 deletions enigma-cli/build.gradle
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
plugins {
id 'application'
id 'com.github.johnrengelman.shadow' version '7.0.0'
id 'com.github.johnrengelman.shadow'
}

dependencies {
implementation project(':enigma')
}

mainClassName = 'cuchaz.enigma.command.Main'
application {
mainClass = 'cuchaz.enigma.command.Main'
}

jar.manifest.attributes 'Main-Class': mainClassName
jar.manifest.attributes 'Main-Class': application.mainClass.get()

publishing {
publications {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
import cuchaz.enigma.analysis.index.JarIndex;
import cuchaz.enigma.classprovider.ClasspathClassProvider;
import cuchaz.enigma.translation.mapping.EntryMapping;
import cuchaz.enigma.translation.mapping.serde.MappingFormat;
import cuchaz.enigma.translation.mapping.serde.MappingSaveParameters;
import cuchaz.enigma.translation.mapping.tree.EntryTree;
import cuchaz.enigma.translation.representation.entry.ClassEntry;
Expand Down Expand Up @@ -38,15 +37,12 @@ public void run(String... args) throws Exception {
Enigma enigma = Enigma.create();

System.out.println("Reading JAR...");

EnigmaProject project = enigma.openJar(fileJarIn, new ClasspathClassProvider(), ProgressListener.none());

System.out.println("Reading mappings...");

MappingFormat format = chooseEnigmaFormat(fileMappings);
MappingSaveParameters saveParameters = enigma.getProfile().getMappingSaveParameters();

EntryTree<EntryMapping> mappings = format.read(fileMappings, ProgressListener.none(), saveParameters);
EntryTree<EntryMapping> mappings = readMappings(fileMappings, ProgressListener.none(), saveParameters);
project.setMappings(mappings);

JarIndex idx = project.getJarIndex();
Expand Down
26 changes: 18 additions & 8 deletions enigma-cli/src/main/java/cuchaz/enigma/command/Command.java
Original file line number Diff line number Diff line change
@@ -1,18 +1,24 @@
package cuchaz.enigma.command;

import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;

import com.google.common.io.MoreFiles;
import net.fabricmc.mappingio.MappingReader;
import net.fabricmc.mappingio.tree.MemoryMappingTree;
import net.fabricmc.mappingio.tree.VisitableMappingTree;

import cuchaz.enigma.Enigma;
import cuchaz.enigma.EnigmaProject;
import cuchaz.enigma.ProgressListener;
import cuchaz.enigma.classprovider.ClasspathClassProvider;
import cuchaz.enigma.translation.mapping.EntryMapping;
import cuchaz.enigma.translation.mapping.serde.MappingFormat;
import cuchaz.enigma.translation.mapping.serde.MappingIoConverter;
import cuchaz.enigma.translation.mapping.serde.MappingParseException;
import cuchaz.enigma.translation.mapping.serde.MappingSaveParameters;
import cuchaz.enigma.translation.mapping.tree.EntryTree;

Expand Down Expand Up @@ -41,22 +47,26 @@ protected static EnigmaProject openProject(Path fileJarIn, Path fileMappings) th
System.out.println("Reading mappings...");

MappingSaveParameters saveParameters = enigma.getProfile().getMappingSaveParameters();
EntryTree<EntryMapping> mappings = chooseEnigmaFormat(fileMappings).read(fileMappings, progress, saveParameters);
EntryTree<EntryMapping> mappings = readMappings(fileMappings, progress, saveParameters);

project.setMappings(mappings);
}

return project;
}

protected static MappingFormat chooseEnigmaFormat(Path path) {
if (Files.isDirectory(path)) {
return MappingFormat.ENIGMA_DIRECTORY;
} else if ("zip".equalsIgnoreCase(MoreFiles.getFileExtension(path))) {
return MappingFormat.ENIGMA_ZIP;
} else {
return MappingFormat.ENIGMA_FILE;
protected static EntryTree<EntryMapping> readMappings(Path path, ProgressListener progress, MappingSaveParameters saveParameters) throws IOException, MappingParseException {
// Legacy
if ("zip".equalsIgnoreCase(MoreFiles.getFileExtension(path))) {
return MappingFormat.ENIGMA_ZIP.read(path, progress, saveParameters, null);
}

net.fabricmc.mappingio.format.MappingFormat format = MappingReader.detectFormat(path);
if (format == null) throw new IllegalArgumentException("Unknown mapping format!");

VisitableMappingTree tree = new MemoryMappingTree();
MappingReader.read(path, format, tree);
return MappingIoConverter.fromMappingIo(tree, progress, null);
}

protected static File getWritableFile(String path) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
package cuchaz.enigma.command;

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

import net.fabricmc.mappingio.MappingWriter;
import net.fabricmc.mappingio.tree.VisitableMappingTree;

import cuchaz.enigma.ProgressListener;
import cuchaz.enigma.translation.mapping.EntryMapping;
import cuchaz.enigma.translation.mapping.serde.MappingFormat;
import cuchaz.enigma.translation.mapping.serde.MappingIoConverter;
import cuchaz.enigma.translation.mapping.serde.MappingParseException;
import cuchaz.enigma.translation.mapping.serde.MappingSaveParameters;
import cuchaz.enigma.translation.mapping.serde.enigma.EnigmaMappingsReader;
import cuchaz.enigma.translation.mapping.serde.enigma.EnigmaMappingsWriter;
import cuchaz.enigma.translation.mapping.serde.tiny.TinyMappingsReader;
import cuchaz.enigma.translation.mapping.serde.tiny.TinyMappingsWriter;
import cuchaz.enigma.translation.mapping.serde.tinyv2.TinyV2Writer;
import cuchaz.enigma.translation.mapping.tree.EntryTree;
Expand All @@ -22,11 +24,11 @@ private MappingCommandsUtil() {

public static EntryTree<EntryMapping> read(String type, Path path, MappingSaveParameters saveParameters) throws MappingParseException, IOException {
if (type.equals("enigma")) {
return (Files.isDirectory(path) ? EnigmaMappingsReader.DIRECTORY : EnigmaMappingsReader.ZIP).read(path, ProgressListener.none(), saveParameters);
return (Files.isDirectory(path) ? MappingFormat.ENIGMA_DIRECTORY : MappingFormat.ENIGMA_ZIP).read(path, ProgressListener.none(), saveParameters, null);
}

if (type.equals("tiny")) {
return TinyMappingsReader.INSTANCE.read(path, ProgressListener.none(), saveParameters);
return MappingFormat.TINY_FILE.read(path, ProgressListener.none(), saveParameters, null);
}

MappingFormat format = null;
Expand All @@ -40,15 +42,15 @@ public static EntryTree<EntryMapping> read(String type, Path path, MappingSavePa
}

if (format != null) {
return format.getReader().read(path, ProgressListener.none(), saveParameters);
return format.read(path, ProgressListener.none(), saveParameters, null);
}

throw new IllegalArgumentException("no reader for " + type);
}

public static void write(EntryTree<EntryMapping> mappings, String type, Path path, MappingSaveParameters saveParameters) {
if (type.equals("enigma")) {
EnigmaMappingsWriter.DIRECTORY.write(mappings, path, ProgressListener.none(), saveParameters);
MappingFormat.ENIGMA_DIRECTORY.write(mappings, path, ProgressListener.none(), saveParameters);
return;
}

Expand All @@ -59,7 +61,18 @@ public static void write(EntryTree<EntryMapping> mappings, String type, Path pat
throw new IllegalArgumentException("specify column names as 'tinyv2:from_namespace:to_namespace'");
}

new TinyV2Writer(split[1], split[2]).write(mappings, path, ProgressListener.none(), saveParameters);
if (!System.getProperty("enigma.use_mappingio", "true").equals("true")) {
new TinyV2Writer(split[1], split[2]).write(mappings, path, ProgressListener.none(), saveParameters);
return;
}

try {
VisitableMappingTree tree = MappingIoConverter.toMappingIo(mappings, ProgressListener.none(), split[1], split[2]);
tree.accept(MappingWriter.create(path, net.fabricmc.mappingio.format.MappingFormat.TINY_2_FILE));
} catch (IOException e) {
throw new UncheckedIOException(e);
}

return;
}

Expand All @@ -70,7 +83,18 @@ public static void write(EntryTree<EntryMapping> mappings, String type, Path pat
throw new IllegalArgumentException("specify column names as 'tiny:from_column:to_column'");
}

new TinyMappingsWriter(split[1], split[2]).write(mappings, path, ProgressListener.none(), saveParameters);
if (!System.getProperty("enigma.use_mappingio", "true").equals("true")) {
new TinyMappingsWriter(split[1], split[2]).write(mappings, path, ProgressListener.none(), saveParameters);
return;
}

try {
VisitableMappingTree tree = MappingIoConverter.toMappingIo(mappings, ProgressListener.none(), split[1], split[2]);
tree.accept(MappingWriter.create(path, net.fabricmc.mappingio.format.MappingFormat.TINY_FILE));
} catch (IOException e) {
throw new UncheckedIOException(e);
}

return;
}

Expand All @@ -83,7 +107,7 @@ public static void write(EntryTree<EntryMapping> mappings, String type, Path pat
}

if (format != null) {
format.getWriter().write(mappings, path, ProgressListener.none(), saveParameters);
format.write(mappings, path, ProgressListener.none(), saveParameters);
return;
}

Expand Down
6 changes: 4 additions & 2 deletions enigma-server/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ dependencies {
implementation 'net.sf.jopt-simple:jopt-simple:6.0-alpha-3'
}

mainClassName = 'cuchaz.enigma.network.DedicatedEnigmaServer'
application {
mainClass = 'cuchaz.enigma.network.DedicatedEnigmaServer'
}

jar.manifest.attributes 'Main-Class': mainClassName
jar.manifest.attributes 'Main-Class': application.mainClass.get()
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ public static void main(String[] args) {
mappingFormat = MappingFormat.ENIGMA_FILE;
}

mappings = EntryRemapper.mapped(project.getJarIndex(), mappingFormat.read(mappingsFile, ProgressListener.none(), profile.getMappingSaveParameters()));
mappings = EntryRemapper.mapped(project.getJarIndex(), mappingFormat.read(mappingsFile, ProgressListener.none(), profile.getMappingSaveParameters(), project.getJarIndex()));
}

PrintWriter log = new PrintWriter(Files.newBufferedWriter(logFile));
Expand Down
23 changes: 18 additions & 5 deletions enigma-swing/build.gradle
Original file line number Diff line number Diff line change
@@ -1,23 +1,36 @@
plugins {
id 'application'
id 'com.github.johnrengelman.shadow' version '7.0.0'
id 'com.github.johnrengelman.shadow'
}

def flatLafNatives = [
"windows-arm64@dll",
"windows-x86@dll",
"windows-x86_64@dll",
"linux-x86_64@so",
]

dependencies {
implementation project(':enigma')
implementation project(':enigma-server')

implementation 'net.sf.jopt-simple:jopt-simple:6.0-alpha-3'
implementation 'com.formdev:flatlaf:2.6'
implementation 'com.formdev:flatlaf-extras:2.6' // for SVG icons
implementation 'com.formdev:flatlaf:3.2.5'
implementation 'com.formdev:flatlaf-extras:3.2.5' // for SVG icons
implementation 'de.sciss:syntaxpane:1.2.1'
implementation 'com.github.lukeu:swing-dpi:0.10'
implementation 'org.drjekyll:fontchooser:2.5.2'

flatLafNatives.forEach {
implementation 'com.formdev:flatlaf:3.2.5:' + it
}
}

mainClassName = 'cuchaz.enigma.gui.Main'
application {
mainClass = 'cuchaz.enigma.gui.Main'
}

jar.manifest.attributes 'Main-Class': mainClassName
jar.manifest.attributes 'Main-Class': application.mainClass.get()

publishing {
publications {
Expand Down
Loading

0 comments on commit a8cf4e0

Please sign in to comment.