diff --git a/build.gradle b/build.gradle index 182f8d5..0b48f39 100644 --- a/build.gradle +++ b/build.gradle @@ -1,28 +1,32 @@ -apply plugin: 'java' -apply plugin: 'eclipse' -apply plugin: 'idea' -apply plugin: 'maven-publish' - -buildscript { - repositories { - maven { - url "https://plugins.gradle.org/m2/" - } - jcenter() - } +plugins { + id 'java' + id 'eclipse' + id 'idea' + id 'maven-publish' + id 'net.minecrell.licenser' version '0.4.1' } sourceCompatibility = 1.8 -version = '0.2.2' +targetCompatibility = 1.8 +version = '0.3.0' -def ENV = System.getenv() -if (ENV.BUILD_NUMBER) { - version = version + "." + "${System.getenv().BUILD_NUMBER}" -} +def buildNumber = System.getenv("BUILD_NUMBER") +version = version + "+" + (buildNumber ? "build.$buildNumber" : "local") group = 'net.fabricmc' archivesBaseName = 'tiny-mappings-parser' +license { + header file('HEADER') + include '**/*.java' +} + +sourceSets { + asm + mixin + legacy // old deprecated stuff, to be removed in 0.4 +} + repositories { mavenCentral() maven { @@ -32,47 +36,110 @@ repositories { } dependencies { - testImplementation( - 'org.junit.jupiter:junit-jupiter-api:5.1.0' - ) - testRuntimeOnly( - 'org.junit.jupiter:junit-jupiter-engine:5.1.0' - ) - - compileOnly 'org.checkerframework:checker-qual:2.11.0' - implementation 'org.ow2.asm:asm:8.0' - implementation 'org.ow2.asm:asm-analysis:8.0' - implementation 'org.ow2.asm:asm-commons:8.0' - implementation 'org.ow2.asm:asm-tree:8.0' - implementation 'org.ow2.asm:asm-util:8.0' - implementation 'net.fabricmc:sponge-mixin:0.7.11.17' + compileOnly 'org.checkerframework:checker-qual:3.3.0' + // source-set specific stuff aren't exposed later + asmImplementation 'org.ow2.asm:asm:8.0' + asmImplementation 'org.ow2.asm:asm-analysis:8.0' + asmImplementation 'org.ow2.asm:asm-commons:8.0' + asmImplementation 'org.ow2.asm:asm-tree:8.0' + asmImplementation 'org.ow2.asm:asm-util:8.0' + mixinImplementation('net.fabricmc:sponge-mixin:0.7.11.17') { + transitive = false + } + + testImplementation 'com.google.guava:guava:29.0-jre' + testImplementation 'org.junit.jupiter:junit-jupiter-api:5.1.0' + testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.1.0' +} + +sourceSets { + asm.compileClasspath += main.compileClasspath + asm.compileClasspath += main.output + mixin.compileClasspath += main.compileClasspath + mixin.compileClasspath += main.output + legacy.compileClasspath += main.compileClasspath + legacy.compileClasspath += asm.compileClasspath + legacy.compileClasspath += mixin.compileClasspath + test.compileClasspath += asm.output + test.compileClasspath += mixin.output + test.compileClasspath += legacy.output + test.runtimeClasspath += asm.output + test.runtimeClasspath += mixin.output + test.runtimeClasspath += legacy.output +} + +javadoc { + options { + if (file("README.html").exists()) { + overview = "README.html" + } + source = "8" + encoding = 'UTF-8' + charSet = 'UTF-8' + memberLevel = JavadocMemberLevel.PROTECTED + links( + 'https://checkerframework.org/api/', + 'https://docs.oracle.com/javase/8/docs/api/', + 'https://asm.ow2.io/javadoc/' + ) + // Disable the crazy super-strict doclint tool in Java 8 + addStringOption('Xdoclint:none', '-quiet') + } + source sourceSets.main.allJava.srcDirs, sourceSets.asm.allJava.srcDirs, sourceSets.mixin.allJava.srcDirs + classpath += sourceSets.main.compileClasspath + classpath += sourceSets.asm.compileClasspath + classpath += sourceSets.mixin.compileClasspath +} + +jar { + from sourceSets.main.output + from sourceSets.asm.output + from sourceSets.mixin.output + from sourceSets.legacy.output } task sourcesJar(type: Jar, dependsOn: classes) { - classifier = 'sources' + archiveClassifier.set 'sources' from sourceSets.main.allSource + from sourceSets.asm.allSource + from sourceSets.mixin.allSource + from sourceSets.legacy.allSource +} + +task javadocsJar(type: Jar, dependsOn: javadoc) { + archiveClassifier.set 'javadocs' + from javadoc.destinationDir +} + +artifacts { + archives jar + archives sourcesJar + archives javadocsJar } test { - useJUnitPlatform() + useJUnitPlatform() } publishing { publications { maven(MavenPublication) { - groupId 'net.fabricmc' - artifactId "tiny-mappings-parser" - version version + from components.java - artifact (jar) - artifact (sourcesJar) + artifact sourcesJar + artifact javadocsJar } } -} - -apply from: 'https://github.com/FabricMC/fabric-docs/raw/master/gradle/maven.gradle' -apply from: 'https://github.com/FabricMC/fabric-docs/raw/master/gradle/license.gradle' -uploadArchives.repositories.mavenDeployer.pom.withXml { - asNode().dependencies.'*'.each() { it.parent().remove(it) } + repositories { + if (project.hasProperty('mavenPass')) { + maven { + url = "http://mavenupload.modmuss50.me/" + credentials { + username = "buildslave" + password = project.getProperty('mavenPass') + } + } + } + } } diff --git a/gradle/wrapper/gradle-wrapper.jar b/gradle/wrapper/gradle-wrapper.jar index deedc7f..490fda8 100644 Binary files a/gradle/wrapper/gradle-wrapper.jar and b/gradle/wrapper/gradle-wrapper.jar differ diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 490b55e..a4b4429 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,5 @@ -#Sun Aug 21 10:32:36 EDT 2016 distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists +distributionUrl=https\://services.gradle.org/distributions/gradle-6.3-bin.zip zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-4.9-bin.zip diff --git a/gradlew b/gradlew index 9aa616c..2fe81a7 100755 --- a/gradlew +++ b/gradlew @@ -1,4 +1,20 @@ -#!/usr/bin/env bash +#!/usr/bin/env sh + +# +# Copyright 2015 the original author or authors. +# +# 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 +# +# https://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. +# ############################################################################## ## @@ -28,16 +44,16 @@ APP_NAME="Gradle" APP_BASE_NAME=`basename "$0"` # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. -DEFAULT_JVM_OPTS="" +DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' # Use the maximum available, or set MAX_FD != -1 to use that value. MAX_FD="maximum" -warn ( ) { +warn () { echo "$*" } -die ( ) { +die () { echo echo "$*" echo @@ -109,8 +125,8 @@ if $darwin; then GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" fi -# For Cygwin, switch paths to Windows format before running java -if $cygwin ; then +# For Cygwin or MSYS, switch paths to Windows format before running java +if [ "$cygwin" = "true" -o "$msys" = "true" ] ; then APP_HOME=`cygpath --path --mixed "$APP_HOME"` CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` JAVACMD=`cygpath --unix "$JAVACMD"` @@ -138,32 +154,30 @@ if $cygwin ; then else eval `echo args$i`="\"$arg\"" fi - i=$((i+1)) + i=`expr $i + 1` done case $i in - (0) set -- ;; - (1) set -- "$args0" ;; - (2) set -- "$args0" "$args1" ;; - (3) set -- "$args0" "$args1" "$args2" ;; - (4) set -- "$args0" "$args1" "$args2" "$args3" ;; - (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; - (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; - (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; - (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; - (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; + 0) set -- ;; + 1) set -- "$args0" ;; + 2) set -- "$args0" "$args1" ;; + 3) set -- "$args0" "$args1" "$args2" ;; + 4) set -- "$args0" "$args1" "$args2" "$args3" ;; + 5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; + 6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; + 7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; + 8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; + 9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; esac fi -# Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules -function splitJvmOpts() { - JVM_OPTS=("$@") +# Escape application args +save () { + for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done + echo " " } -eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS -JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME" +APP_ARGS=`save "$@"` -# by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong -if [[ "$(uname)" == "Darwin" ]] && [[ "$HOME" == "$PWD" ]]; then - cd "$(dirname "$0")" -fi +# Collect all arguments for the java command, following the shell quoting and substitution rules +eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS" -exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@" +exec "$JAVACMD" "$@" diff --git a/gradlew.bat b/gradlew.bat index f955316..62bd9b9 100644 --- a/gradlew.bat +++ b/gradlew.bat @@ -1,3 +1,19 @@ +@rem +@rem Copyright 2015 the original author or authors. +@rem +@rem Licensed under the Apache License, Version 2.0 (the "License"); +@rem you may not use this file except in compliance with the License. +@rem You may obtain a copy of the License at +@rem +@rem https://www.apache.org/licenses/LICENSE-2.0 +@rem +@rem Unless required by applicable law or agreed to in writing, software +@rem distributed under the License is distributed on an "AS IS" BASIS, +@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +@rem See the License for the specific language governing permissions and +@rem limitations under the License. +@rem + @if "%DEBUG%" == "" @echo off @rem ########################################################################## @rem @@ -13,8 +29,11 @@ if "%DIRNAME%" == "" set DIRNAME=. set APP_BASE_NAME=%~n0 set APP_HOME=%DIRNAME% +@rem Resolve any "." and ".." in APP_HOME to make it shorter. +for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi + @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. -set DEFAULT_JVM_OPTS= +set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" @rem Find java.exe if defined JAVA_HOME goto findJavaFromJavaHome diff --git a/src/main/java/net/fabricmc/mapping/util/AsmRemapperFactory.java b/src/asm/java/net/fabricmc/mapping/util/AsmRemapperFactory.java similarity index 99% rename from src/main/java/net/fabricmc/mapping/util/AsmRemapperFactory.java rename to src/asm/java/net/fabricmc/mapping/util/AsmRemapperFactory.java index 291ee15..e829cb4 100644 --- a/src/main/java/net/fabricmc/mapping/util/AsmRemapperFactory.java +++ b/src/asm/java/net/fabricmc/mapping/util/AsmRemapperFactory.java @@ -20,7 +20,6 @@ import org.checkerframework.checker.nullness.qual.Nullable; import org.objectweb.asm.commons.Remapper; -import net.fabricmc.mappings.*; import java.lang.ref.SoftReference; import java.util.Collection; import java.util.HashMap; diff --git a/src/main/java/net/fabricmc/mappings/ClassEntry.java b/src/legacy/java/net/fabricmc/mappings/ClassEntry.java similarity index 98% rename from src/main/java/net/fabricmc/mappings/ClassEntry.java rename to src/legacy/java/net/fabricmc/mappings/ClassEntry.java index 1256faa..15ce583 100644 --- a/src/main/java/net/fabricmc/mappings/ClassEntry.java +++ b/src/legacy/java/net/fabricmc/mappings/ClassEntry.java @@ -16,6 +16,7 @@ package net.fabricmc.mappings; +@Deprecated public interface ClassEntry { String get(String namespace); } diff --git a/src/main/java/net/fabricmc/mappings/DummyMappings.java b/src/legacy/java/net/fabricmc/mappings/DummyMappings.java similarity index 99% rename from src/main/java/net/fabricmc/mappings/DummyMappings.java rename to src/legacy/java/net/fabricmc/mappings/DummyMappings.java index 646a64a..818fea2 100644 --- a/src/main/java/net/fabricmc/mappings/DummyMappings.java +++ b/src/legacy/java/net/fabricmc/mappings/DummyMappings.java @@ -19,6 +19,7 @@ import java.util.Collection; import java.util.Collections; +@Deprecated final class DummyMappings implements Mappings { static final DummyMappings INSTANCE = new DummyMappings(); diff --git a/src/main/java/net/fabricmc/mappings/EntryTriple.java b/src/legacy/java/net/fabricmc/mappings/EntryTriple.java similarity index 99% rename from src/main/java/net/fabricmc/mappings/EntryTriple.java rename to src/legacy/java/net/fabricmc/mappings/EntryTriple.java index baf2084..efb2003 100644 --- a/src/main/java/net/fabricmc/mappings/EntryTriple.java +++ b/src/legacy/java/net/fabricmc/mappings/EntryTriple.java @@ -16,6 +16,7 @@ package net.fabricmc.mappings; +@Deprecated public class EntryTriple { private final String owner; private final String name; diff --git a/src/main/java/net/fabricmc/mappings/FieldEntry.java b/src/legacy/java/net/fabricmc/mappings/FieldEntry.java similarity index 98% rename from src/main/java/net/fabricmc/mappings/FieldEntry.java rename to src/legacy/java/net/fabricmc/mappings/FieldEntry.java index 2aedd17..fdd81f2 100644 --- a/src/main/java/net/fabricmc/mappings/FieldEntry.java +++ b/src/legacy/java/net/fabricmc/mappings/FieldEntry.java @@ -16,6 +16,7 @@ package net.fabricmc.mappings; +@Deprecated public interface FieldEntry { EntryTriple get(String namespace); } diff --git a/src/main/java/net/fabricmc/mappings/MappedStringDeduplicator.java b/src/legacy/java/net/fabricmc/mappings/MappedStringDeduplicator.java similarity index 95% rename from src/main/java/net/fabricmc/mappings/MappedStringDeduplicator.java rename to src/legacy/java/net/fabricmc/mappings/MappedStringDeduplicator.java index 89b4d35..e211fa7 100644 --- a/src/main/java/net/fabricmc/mappings/MappedStringDeduplicator.java +++ b/src/legacy/java/net/fabricmc/mappings/MappedStringDeduplicator.java @@ -17,9 +17,8 @@ package net.fabricmc.mappings; import java.util.*; -import java.util.function.Function; -import java.util.function.Supplier; +@Deprecated interface MappedStringDeduplicator { enum Category { NAME, diff --git a/src/main/java/net/fabricmc/mappings/Mappings.java b/src/legacy/java/net/fabricmc/mappings/Mappings.java similarity index 99% rename from src/main/java/net/fabricmc/mappings/Mappings.java rename to src/legacy/java/net/fabricmc/mappings/Mappings.java index e8c9830..7af041c 100644 --- a/src/main/java/net/fabricmc/mappings/Mappings.java +++ b/src/legacy/java/net/fabricmc/mappings/Mappings.java @@ -25,6 +25,7 @@ import java.util.ArrayList; import java.util.Collection; +@Deprecated public interface Mappings { Collection getNamespaces(); diff --git a/src/main/java/net/fabricmc/mappings/MappingsProvider.java b/src/legacy/java/net/fabricmc/mappings/MappingsProvider.java similarity index 99% rename from src/main/java/net/fabricmc/mappings/MappingsProvider.java rename to src/legacy/java/net/fabricmc/mappings/MappingsProvider.java index 93a7c72..6c754f3 100644 --- a/src/main/java/net/fabricmc/mappings/MappingsProvider.java +++ b/src/legacy/java/net/fabricmc/mappings/MappingsProvider.java @@ -19,6 +19,7 @@ import java.io.IOException; import java.io.InputStream; +@Deprecated public final class MappingsProvider { private MappingsProvider() { diff --git a/src/main/java/net/fabricmc/mappings/MethodEntry.java b/src/legacy/java/net/fabricmc/mappings/MethodEntry.java similarity index 98% rename from src/main/java/net/fabricmc/mappings/MethodEntry.java rename to src/legacy/java/net/fabricmc/mappings/MethodEntry.java index 25548d0..cc900b2 100644 --- a/src/main/java/net/fabricmc/mappings/MethodEntry.java +++ b/src/legacy/java/net/fabricmc/mappings/MethodEntry.java @@ -16,6 +16,7 @@ package net.fabricmc.mappings; +@Deprecated public interface MethodEntry { EntryTriple get(String namespace); } diff --git a/src/main/java/net/fabricmc/mappings/TinyMappings.java b/src/legacy/java/net/fabricmc/mappings/TinyMappings.java similarity index 99% rename from src/main/java/net/fabricmc/mappings/TinyMappings.java rename to src/legacy/java/net/fabricmc/mappings/TinyMappings.java index f44847e..642152a 100644 --- a/src/main/java/net/fabricmc/mappings/TinyMappings.java +++ b/src/legacy/java/net/fabricmc/mappings/TinyMappings.java @@ -21,6 +21,7 @@ import java.io.*; import java.util.*; +@Deprecated class TinyMappings implements Mappings { private static class ClassEntryImpl implements ClassEntry { private final Map namespacesToIds; diff --git a/src/main/java/net/fabricmc/mappings/helpers/asm/AsmRemapperCache.java b/src/legacy/java/net/fabricmc/mappings/helpers/asm/AsmRemapperCache.java similarity index 92% rename from src/main/java/net/fabricmc/mappings/helpers/asm/AsmRemapperCache.java rename to src/legacy/java/net/fabricmc/mappings/helpers/asm/AsmRemapperCache.java index b791e83..40b1760 100644 --- a/src/main/java/net/fabricmc/mappings/helpers/asm/AsmRemapperCache.java +++ b/src/legacy/java/net/fabricmc/mappings/helpers/asm/AsmRemapperCache.java @@ -16,13 +16,18 @@ package net.fabricmc.mappings.helpers.asm; +import net.fabricmc.mappings.ClassEntry; +import net.fabricmc.mappings.EntryTriple; +import net.fabricmc.mappings.FieldEntry; +import net.fabricmc.mappings.Mappings; +import net.fabricmc.mappings.MethodEntry; import org.objectweb.asm.commons.Remapper; -import net.fabricmc.mappings.*; import java.lang.ref.SoftReference; import java.util.HashMap; import java.util.Map; +@Deprecated public class AsmRemapperCache { private static class SimpleRemapper extends Remapper { private final Map classNames; diff --git a/src/main/java/net/fabricmc/mappings/helpers/mixin/MixinMappingsRemapper.java b/src/legacy/java/net/fabricmc/mappings/helpers/mixin/MixinMappingsRemapper.java similarity index 92% rename from src/main/java/net/fabricmc/mappings/helpers/mixin/MixinMappingsRemapper.java rename to src/legacy/java/net/fabricmc/mappings/helpers/mixin/MixinMappingsRemapper.java index 6da4bc9..017676b 100644 --- a/src/main/java/net/fabricmc/mappings/helpers/mixin/MixinMappingsRemapper.java +++ b/src/legacy/java/net/fabricmc/mappings/helpers/mixin/MixinMappingsRemapper.java @@ -16,13 +16,18 @@ package net.fabricmc.mappings.helpers.mixin; -import net.fabricmc.mappings.*; +import net.fabricmc.mappings.ClassEntry; +import net.fabricmc.mappings.EntryTriple; +import net.fabricmc.mappings.FieldEntry; +import net.fabricmc.mappings.Mappings; +import net.fabricmc.mappings.MethodEntry; import org.objectweb.asm.commons.Remapper; import org.spongepowered.asm.mixin.extensibility.IRemapper; import java.util.HashMap; import java.util.Map; +@Deprecated public class MixinMappingsRemapper implements IRemapper { private final Map classMap = new HashMap<>(); private final Map classMapInverse = new HashMap<>(); diff --git a/src/main/java/net/fabricmc/mappings/model/CommentEntry.java b/src/legacy/java/net/fabricmc/mappings/model/CommentEntry.java similarity index 99% rename from src/main/java/net/fabricmc/mappings/model/CommentEntry.java rename to src/legacy/java/net/fabricmc/mappings/model/CommentEntry.java index 2198055..81f5a02 100644 --- a/src/main/java/net/fabricmc/mappings/model/CommentEntry.java +++ b/src/legacy/java/net/fabricmc/mappings/model/CommentEntry.java @@ -20,6 +20,7 @@ import java.util.List; +@Deprecated public abstract class CommentEntry { private List comments; diff --git a/src/main/java/net/fabricmc/mappings/model/Comments.java b/src/legacy/java/net/fabricmc/mappings/model/Comments.java similarity index 98% rename from src/main/java/net/fabricmc/mappings/model/Comments.java rename to src/legacy/java/net/fabricmc/mappings/model/Comments.java index 2ed5076..3ee46ed 100644 --- a/src/main/java/net/fabricmc/mappings/model/Comments.java +++ b/src/legacy/java/net/fabricmc/mappings/model/Comments.java @@ -18,6 +18,7 @@ import java.util.Collection; +@Deprecated public interface Comments { Collection getClassComments(); Collection getFieldComments(); diff --git a/src/main/java/net/fabricmc/mappings/model/CommentsImpl.java b/src/legacy/java/net/fabricmc/mappings/model/CommentsImpl.java similarity index 99% rename from src/main/java/net/fabricmc/mappings/model/CommentsImpl.java rename to src/legacy/java/net/fabricmc/mappings/model/CommentsImpl.java index 5d4cfd3..c8cb192 100644 --- a/src/main/java/net/fabricmc/mappings/model/CommentsImpl.java +++ b/src/legacy/java/net/fabricmc/mappings/model/CommentsImpl.java @@ -19,6 +19,7 @@ import java.util.Collection; import java.util.List; +@Deprecated public class CommentsImpl implements Comments { private List classComments; private List fieldComments; diff --git a/src/main/java/net/fabricmc/mappings/model/LocalVariable.java b/src/legacy/java/net/fabricmc/mappings/model/LocalVariable.java similarity index 99% rename from src/main/java/net/fabricmc/mappings/model/LocalVariable.java rename to src/legacy/java/net/fabricmc/mappings/model/LocalVariable.java index 2e9cc30..bf93640 100644 --- a/src/main/java/net/fabricmc/mappings/model/LocalVariable.java +++ b/src/legacy/java/net/fabricmc/mappings/model/LocalVariable.java @@ -20,6 +20,7 @@ import java.util.Objects; +@Deprecated public class LocalVariable { private EntryTriple method; private String name; diff --git a/src/main/java/net/fabricmc/mappings/model/LocalVariableEntry.java b/src/legacy/java/net/fabricmc/mappings/model/LocalVariableEntry.java similarity index 98% rename from src/main/java/net/fabricmc/mappings/model/LocalVariableEntry.java rename to src/legacy/java/net/fabricmc/mappings/model/LocalVariableEntry.java index fa7c065..6a07263 100644 --- a/src/main/java/net/fabricmc/mappings/model/LocalVariableEntry.java +++ b/src/legacy/java/net/fabricmc/mappings/model/LocalVariableEntry.java @@ -16,6 +16,7 @@ package net.fabricmc.mappings.model; +@Deprecated public interface LocalVariableEntry { LocalVariable get(String namespace); } diff --git a/src/main/java/net/fabricmc/mappings/model/MethodParameter.java b/src/legacy/java/net/fabricmc/mappings/model/MethodParameter.java similarity index 99% rename from src/main/java/net/fabricmc/mappings/model/MethodParameter.java rename to src/legacy/java/net/fabricmc/mappings/model/MethodParameter.java index d14c4b4..465d63a 100644 --- a/src/main/java/net/fabricmc/mappings/model/MethodParameter.java +++ b/src/legacy/java/net/fabricmc/mappings/model/MethodParameter.java @@ -20,6 +20,7 @@ import java.util.Objects; +@Deprecated public class MethodParameter { private EntryTriple method; private String name; diff --git a/src/main/java/net/fabricmc/mappings/model/MethodParameterEntry.java b/src/legacy/java/net/fabricmc/mappings/model/MethodParameterEntry.java similarity index 98% rename from src/main/java/net/fabricmc/mappings/model/MethodParameterEntry.java rename to src/legacy/java/net/fabricmc/mappings/model/MethodParameterEntry.java index dce0498..2bde1dc 100644 --- a/src/main/java/net/fabricmc/mappings/model/MethodParameterEntry.java +++ b/src/legacy/java/net/fabricmc/mappings/model/MethodParameterEntry.java @@ -16,6 +16,7 @@ package net.fabricmc.mappings.model; +@Deprecated public interface MethodParameterEntry { MethodParameter get(String namespace); } diff --git a/src/main/java/net/fabricmc/mappings/model/V2MappingsProvider.java b/src/legacy/java/net/fabricmc/mappings/model/V2MappingsProvider.java similarity index 99% rename from src/main/java/net/fabricmc/mappings/model/V2MappingsProvider.java rename to src/legacy/java/net/fabricmc/mappings/model/V2MappingsProvider.java index 15d50f9..aa84e46 100644 --- a/src/main/java/net/fabricmc/mappings/model/V2MappingsProvider.java +++ b/src/legacy/java/net/fabricmc/mappings/model/V2MappingsProvider.java @@ -33,6 +33,7 @@ import java.util.List; import java.util.function.ToIntFunction; +@Deprecated public class V2MappingsProvider { public static Mappings readTinyMappings(BufferedReader reader) throws IOException { Visitor visitor = new Visitor(); diff --git a/src/main/java/net/fabricmc/mapping/reader/v2/TinyMetadata.java b/src/main/java/net/fabricmc/mapping/reader/v2/TinyMetadata.java index 1510c3e..57a4667 100644 --- a/src/main/java/net/fabricmc/mapping/reader/v2/TinyMetadata.java +++ b/src/main/java/net/fabricmc/mapping/reader/v2/TinyMetadata.java @@ -16,11 +16,11 @@ package net.fabricmc.mapping.reader.v2; -import org.checkerframework.checker.nullness.qual.Nullable; - import java.util.List; import java.util.Map; +import org.checkerframework.checker.nullness.qual.Nullable; + /** * Metadata for a Tiny V2 mapping file. * @@ -73,11 +73,12 @@ public interface TinyMetadata { /** * Utility method to efficiently index a namespace's position in this mapping file. * - *

The implementation should be more efficient than calling {@code getNamespaces().indexOf(namespace)}. + *

A custom implementation should be more efficient than calling {@code getNamespaces().indexOf(namespace)}. * * @param namespace the literal namespace - * @return the namespace's index - * @throws IllegalArgumentException if the namespace does not exist in the mapping + * @return the namespace's index, or {@code -1} if the namespace does not exist */ - int index(String namespace) throws IllegalArgumentException; + default int index(String namespace) { + return getNamespaces().indexOf(namespace); + } } diff --git a/src/main/java/net/fabricmc/mapping/reader/v2/TinyV2Factory.java b/src/main/java/net/fabricmc/mapping/reader/v2/TinyV2Factory.java index b16bb73..447a92f 100644 --- a/src/main/java/net/fabricmc/mapping/reader/v2/TinyV2Factory.java +++ b/src/main/java/net/fabricmc/mapping/reader/v2/TinyV2Factory.java @@ -16,12 +16,12 @@ package net.fabricmc.mapping.reader.v2; -import com.google.common.collect.ImmutableList; -import com.google.common.collect.ImmutableMap; - import java.io.BufferedReader; import java.io.IOException; +import java.util.ArrayList; import java.util.Arrays; +import java.util.Collections; +import java.util.HashMap; import java.util.LinkedHashMap; import java.util.List; import java.util.Map; @@ -167,13 +167,13 @@ private static int countIndent(String st) { } private static TinyHeader makeHeader(int major, int minor, String[] parts, Map props) { - ImmutableList.Builder listBuilder = ImmutableList.builder(); - ImmutableMap.Builder mapBuilder = ImmutableMap.builder(); + List list = new ArrayList<>(); + Map map = new HashMap<>(); for (int i = 3; i < parts.length; i++) { - listBuilder.add(parts[i]); - mapBuilder.put(parts[i], i - 3); + list.add(parts[i]); + map.put(parts[i], i - 3); } - return new TinyHeader(major, minor, listBuilder.build(), mapBuilder.build(), ImmutableMap.copyOf(props)); + return new TinyHeader(major, minor, Collections.unmodifiableList(list), Collections.unmodifiableMap(map), Collections.unmodifiableMap(new HashMap<>(props))); } private static String unescapeOpt(String raw, boolean escapedStrings) { @@ -378,10 +378,7 @@ public Map getProperties() { @Override public int index(String namespace) { - final Integer got = mapper.get(namespace); - if (got == null) - throw new IllegalArgumentException("Invalid namespace \"" + namespace + "\"!"); - return got; + return mapper.getOrDefault(namespace, -1); } } diff --git a/src/main/java/net/fabricmc/mapping/tree/EmptyTinyTree.java b/src/main/java/net/fabricmc/mapping/tree/EmptyTinyTree.java index 7c7e664..7a998c5 100644 --- a/src/main/java/net/fabricmc/mapping/tree/EmptyTinyTree.java +++ b/src/main/java/net/fabricmc/mapping/tree/EmptyTinyTree.java @@ -47,8 +47,8 @@ public List getNamespaces() { } @Override - public int index(String namespace) throws IllegalArgumentException { - throw new IllegalArgumentException("No namespace \"" + namespace + "\""); + public int index(String namespace) { + return -1; } } diff --git a/src/main/java/net/fabricmc/mapping/tree/TinyMappingFactory.java b/src/main/java/net/fabricmc/mapping/tree/TinyMappingFactory.java index 717ece8..fe869b0 100644 --- a/src/main/java/net/fabricmc/mapping/tree/TinyMappingFactory.java +++ b/src/main/java/net/fabricmc/mapping/tree/TinyMappingFactory.java @@ -16,15 +16,27 @@ package net.fabricmc.mapping.tree; -import com.google.common.collect.ImmutableList; -import net.fabricmc.mapping.reader.v2.*; -import org.checkerframework.checker.nullness.qual.MonotonicNonNull; - import java.io.BufferedReader; import java.io.IOException; -import java.util.*; +import java.util.ArrayDeque; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collection; +import java.util.Collections; +import java.util.Deque; +import java.util.HashMap; +import java.util.List; +import java.util.Map; import java.util.function.ToIntFunction; +import org.checkerframework.checker.nullness.qual.MonotonicNonNull; + +import net.fabricmc.mapping.reader.v2.MappingGetter; +import net.fabricmc.mapping.reader.v2.MappingParseException; +import net.fabricmc.mapping.reader.v2.TinyMetadata; +import net.fabricmc.mapping.reader.v2.TinyV2Factory; +import net.fabricmc.mapping.reader.v2.TinyVisitor; + /** * The factory class for tree tiny mapping models. */ @@ -42,7 +54,20 @@ public final class TinyMappingFactory { * @throws MappingParseException if there is an issue with the v2 format */ public static TinyTree load(BufferedReader reader) throws IOException, MappingParseException { - Visitor visitor = new Visitor(); + return load(reader, false); + } + + /** + * Loads a tree model from a buffered reader for v2 input. + * + * @param reader the buffered reader + * @param slim whether parameters, local variables, or comments are omitted + * @return the built reader model + * @throws IOException if the reader throws one + * @throws MappingParseException if there is an issue with the v2 format + */ + public static TinyTree load(BufferedReader reader, boolean slim) throws IOException, MappingParseException { + Visitor visitor = new Visitor(slim); TinyV2Factory.visit(reader, visitor); return new Tree(visitor.metadata, visitor.classNames, visitor.classes); } @@ -56,15 +81,28 @@ public static TinyTree load(BufferedReader reader) throws IOException, MappingPa * @throws MappingParseException if there is an issue with the v2 format */ public static TinyTree loadWithDetection(BufferedReader reader) throws IOException, MappingParseException { + return loadWithDetection(reader, false); + } + + /** + * Loads a tree model from a buffered reader and automatically determine the input type. + * + * @param reader the buffered reader + * @param slim whether parameters, local variables, or comments are omitted + * @return the built reader model + * @throws IOException if the reader throws one + * @throws MappingParseException if there is an issue with the v2 format + */ + public static TinyTree loadWithDetection(BufferedReader reader, boolean slim) throws IOException, MappingParseException { reader.mark(8192); String firstLine = reader.readLine(); String[] header = firstLine.split("\t"); reader.reset(); switch (header[0]) { - case "tiny": - return load(reader); - case "v1": - return loadLegacy(reader); + case "tiny": + return load(reader, slim); + case "v1": + return loadLegacy(reader); } throw new UnsupportedOperationException("Unsupported format with header \"" + firstLine + "\"!"); } @@ -141,7 +179,7 @@ public static TinyTree loadLegacy(BufferedReader reader) throws IOException { String className = splitLine[1]; ClassImpl parent = firstNamespaceClassEntries.get(className); if (parent == null) { - parent = new ClassImpl(namespaceMapper, new String[]{className}); // No class for my field, sad! + parent = new ClassImpl(namespaceMapper, new String[] {className}); // No class for my field, sad! firstNamespaceClassEntries.put(className, parent); classEntries.add(parent); } @@ -150,23 +188,30 @@ public static TinyTree loadLegacy(BufferedReader reader) throws IOException { parent.methods.add(method); } - return new Tree(new LegacyMetadata(ImmutableList.copyOf(namespaceList), namespacesToIds), firstNamespaceClassEntries, classEntries); + return new Tree(new LegacyMetadata(Collections.unmodifiableList(Arrays.asList(namespaceList)), namespacesToIds), firstNamespaceClassEntries, classEntries); } private TinyMappingFactory() { } private static final class Visitor implements TinyVisitor { + private static final MappedImpl SLIM_DUMMY = new MappedImpl(s -> 0, new String[0]) { + }; + private final boolean slim; private @MonotonicNonNull TinyMetadata metadata; private @MonotonicNonNull ToIntFunction namespaceMapper; - private Map classNames = new HashMap<>(); - private Collection classes = new ArrayList<>(); - private DescriptorMapper descriptorMapper = new DescriptorMapper(classNames); - private Deque stack = new ArrayDeque<>(4); + private final Map classNames = new HashMap<>(); + private final Collection classes = new ArrayList<>(); + private final DescriptorMapper descriptorMapper = new DescriptorMapper(classNames); + private final Deque stack = new ArrayDeque<>(4); private boolean pushedComment = false; private @MonotonicNonNull ClassImpl inClass = null; private @MonotonicNonNull MethodImpl inMethod = null; + Visitor(boolean slim) { + this.slim = slim; + } + @Override public void start(TinyMetadata metadata) { this.metadata = metadata; @@ -205,8 +250,14 @@ public void pushMethod(MappingGetter name, String descriptor) { @Override public void pushParameter(MappingGetter name, int localVariableIndex) { - if (inMethod == null) + if (inMethod == null) { throw new IllegalStateException(); + } + + if (slim) { + stack.addLast(SLIM_DUMMY); + return; + } ParameterImpl par = new ParameterImpl(namespaceMapper, name.getRawNames(), localVariableIndex); inMethod.parameters.add(par); @@ -215,8 +266,14 @@ public void pushParameter(MappingGetter name, int localVariableIndex) { @Override public void pushLocalVariable(MappingGetter name, int localVariableIndex, int localVariableStartOffset, int localVariableTableIndex) { - if (inMethod == null) + if (inMethod == null) { throw new IllegalStateException(); + } + + if (slim) { + stack.addLast(SLIM_DUMMY); + return; + } LocalVariableImpl var = new LocalVariableImpl(namespaceMapper, name.getRawNames(), localVariableIndex, localVariableStartOffset, localVariableTableIndex); inMethod.localVariables.add(var); @@ -225,15 +282,18 @@ public void pushLocalVariable(MappingGetter name, int localVariableIndex, int lo @Override public void pushComment(String comment) { - if (stack.isEmpty()) + if (stack.isEmpty()) { throw new IllegalStateException("Nothing to append comment on!"); + } if (pushedComment) { throw new IllegalStateException("Commenting on a comment!"); } - stack.peekLast().setComment(comment); + if (!slim) { + stack.peekLast().setComment(comment); + } pushedComment = true; } @@ -308,11 +368,8 @@ public Map getProperties() { } @Override - public int index(String namespace) throws IllegalArgumentException { - Integer t = namespacesToIds.get(namespace); - if (t == null) - throw new IllegalArgumentException("Invalid namespace \"" + namespace + "\"!"); - return t; + public int index(String namespace) { + return namespacesToIds.getOrDefault(namespace, -1); } } } diff --git a/src/main/java/net/fabricmc/mapping/util/ClassMapper.java b/src/main/java/net/fabricmc/mapping/util/ClassMapper.java index fe4a2c0..f692159 100644 --- a/src/main/java/net/fabricmc/mapping/util/ClassMapper.java +++ b/src/main/java/net/fabricmc/mapping/util/ClassMapper.java @@ -17,9 +17,12 @@ package net.fabricmc.mapping.util; import java.util.Map; +import java.util.function.Function; + +import org.checkerframework.checker.nullness.qual.Nullable; /** - * A simple class name mapper backed by a map. + * A simple class name mapper backed by a unary operator. * *

The class name is intended to be in the format like {@code java/lang/String}. * @@ -27,7 +30,7 @@ */ public final class ClassMapper { - private final Map map; + private final Function mapper; /** * Creates the mapper. @@ -35,7 +38,19 @@ public final class ClassMapper { * @param map the map the mapper uses */ public ClassMapper(Map map) { - this.map = map; + this(map::get); + } + + /** + * Creates the mapper. + * + *

The {@code classMapping} can return {@code null}, in which + * this class mapper will return the original class name passed.

+ * + * @param classMapping the simple class name mapper + */ + public ClassMapper(Function classMapping) { + this.mapper = classMapping; } /** @@ -45,7 +60,7 @@ public ClassMapper(Map map) { * @return the mapped name */ public String mapClass(String old) { - String got = map.get(old); + @Nullable String got = mapper.apply(old); return got == null ? old : got; } diff --git a/src/main/java/net/fabricmc/mapping/util/EntryTriple.java b/src/main/java/net/fabricmc/mapping/util/EntryTriple.java new file mode 100644 index 0000000..8163482 --- /dev/null +++ b/src/main/java/net/fabricmc/mapping/util/EntryTriple.java @@ -0,0 +1,87 @@ +/* + * Copyright 2019 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.mapping.util; + +/** + * A reference to methods or fields. + */ +public final class EntryTriple { + private final String owner; + private final String name; + private final String descriptor; + + public EntryTriple(String owner, String name, String descriptor) { + this.owner = owner; + this.name = name; + this.descriptor = descriptor; + } + + /** + * Returns the name of the owner class of the entry in internal form. + */ + public String getOwner() { + return owner; + } + + /** + * Returns the name of the entry. + */ + public String getName() { + return name; + } + + /** + * Returns the descriptor of the entry. + */ + public String getDescriptor() { + return descriptor; + } + + /** + * Returns a new entry as a result of remapping this entry. + * + * @param mapper the mapper that remap class names + * @param newName the new name for the entry + * @return a new entry + */ + public EntryTriple map(ClassMapper mapper, String newName) { + return new EntryTriple(mapper.mapClass(this.owner), newName, mapper.mapDescriptor(this.descriptor)); + } + + @Override + public String toString() { + return "EntryTriple{owner=" + owner + ",name=" + name + ",desc=" + descriptor + "}"; + } + + @Override + public boolean equals(Object o) { + if (!(o instanceof EntryTriple)) { + return false; + } else if (o == this) { + return true; + } else { + EntryTriple other = (EntryTriple) o; + + return other.owner.equals(owner) && other.name.equals(name) && other.descriptor.equals(descriptor); + } + } + + @Override + public int hashCode() { + return owner.hashCode() * 37 + name.hashCode() * 19 + descriptor.hashCode(); + } +} diff --git a/src/main/java/net/fabricmc/mapping/util/MixinRemapper.java b/src/mixin/java/net/fabricmc/mapping/util/MixinRemapper.java similarity index 98% rename from src/main/java/net/fabricmc/mapping/util/MixinRemapper.java rename to src/mixin/java/net/fabricmc/mapping/util/MixinRemapper.java index 8b48ce2..84c08a0 100644 --- a/src/main/java/net/fabricmc/mapping/util/MixinRemapper.java +++ b/src/mixin/java/net/fabricmc/mapping/util/MixinRemapper.java @@ -16,16 +16,16 @@ package net.fabricmc.mapping.util; +import java.util.Collection; +import java.util.HashMap; +import java.util.Map; + +import org.spongepowered.asm.mixin.extensibility.IRemapper; + import net.fabricmc.mapping.tree.ClassDef; import net.fabricmc.mapping.tree.FieldDef; import net.fabricmc.mapping.tree.MethodDef; import net.fabricmc.mapping.tree.TinyTree; -import net.fabricmc.mappings.EntryTriple; -import org.spongepowered.asm.mixin.extensibility.IRemapper; - -import java.util.Collection; -import java.util.HashMap; -import java.util.Map; /** * A simple implementation of a mixin remapper backed by a tree mapping. diff --git a/src/test/java/net/fabricmc/mapping/util/EntryTripleTest.java b/src/test/java/net/fabricmc/mapping/util/EntryTripleTest.java new file mode 100644 index 0000000..4cbdb46 --- /dev/null +++ b/src/test/java/net/fabricmc/mapping/util/EntryTripleTest.java @@ -0,0 +1,30 @@ +/* + * Copyright 2019 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.mapping.util; + +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; + +class EntryTripleTest { + @Test + void equalsTest() { + Assertions.assertEquals( + new EntryTriple("a", "b", "()"), + new EntryTriple(String.valueOf('a'), "b", "(" + ")") + ); + } +} diff --git a/src/test/java/net/fabricmc/mappings/tests/EntryTripleTests.java b/src/test/java/net/fabricmc/mappings/tests/EntryTripleTests.java index 18b66e0..ee9bac9 100644 --- a/src/test/java/net/fabricmc/mappings/tests/EntryTripleTests.java +++ b/src/test/java/net/fabricmc/mappings/tests/EntryTripleTests.java @@ -20,6 +20,7 @@ import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; +@Deprecated class EntryTripleTests { @Test void equalsTest() { diff --git a/src/test/java/net/fabricmc/mapping/reader/v2/MappingsInterfaceTest.java b/src/test/java/net/fabricmc/mappings/tests/MappingsInterfaceTest.java similarity index 96% rename from src/test/java/net/fabricmc/mapping/reader/v2/MappingsInterfaceTest.java rename to src/test/java/net/fabricmc/mappings/tests/MappingsInterfaceTest.java index 81925ec..8908737 100644 --- a/src/test/java/net/fabricmc/mapping/reader/v2/MappingsInterfaceTest.java +++ b/src/test/java/net/fabricmc/mappings/tests/MappingsInterfaceTest.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package net.fabricmc.mapping.reader.v2; +package net.fabricmc.mappings.tests; import net.fabricmc.mappings.Mappings; import net.fabricmc.mappings.model.V2MappingsProvider; @@ -24,6 +24,7 @@ import java.io.InputStreamReader; import java.nio.charset.StandardCharsets; +@Deprecated public class MappingsInterfaceTest { @Test public void testParsingToOldInterface() throws Exception {