From d7195b683b204bb868d9647a70c16d8688c73944 Mon Sep 17 00:00:00 2001 From: Nino Maruszewski Date: Sun, 13 Jun 2021 08:40:28 -0500 Subject: [PATCH 01/44] Ignore VSCode files --- .gitignore | 3 + gradlew.bat | 178 ++++++++++++++++++++++++++-------------------------- 2 files changed, 92 insertions(+), 89 deletions(-) diff --git a/.gitignore b/.gitignore index 55cf3fb..120d7c8 100644 --- a/.gitignore +++ b/.gitignore @@ -5,8 +5,11 @@ /.settings/ /.classpath /.project +/.factorypath /.gradle *.jar *.tiny .idea/ +.settings/ +.vscode/ !src/test/resources/** diff --git a/gradlew.bat b/gradlew.bat index ac1b06f..107acd3 100644 --- a/gradlew.bat +++ b/gradlew.bat @@ -1,89 +1,89 @@ -@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 -@rem Gradle startup script for Windows -@rem -@rem ########################################################################## - -@rem Set local scope for the variables with windows NT shell -if "%OS%"=="Windows_NT" setlocal - -set DIRNAME=%~dp0 -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="-Xmx64m" "-Xms64m" - -@rem Find java.exe -if defined JAVA_HOME goto findJavaFromJavaHome - -set JAVA_EXE=java.exe -%JAVA_EXE% -version >NUL 2>&1 -if "%ERRORLEVEL%" == "0" goto execute - -echo. -echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. -echo. -echo Please set the JAVA_HOME variable in your environment to match the -echo location of your Java installation. - -goto fail - -:findJavaFromJavaHome -set JAVA_HOME=%JAVA_HOME:"=% -set JAVA_EXE=%JAVA_HOME%/bin/java.exe - -if exist "%JAVA_EXE%" goto execute - -echo. -echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% -echo. -echo Please set the JAVA_HOME variable in your environment to match the -echo location of your Java installation. - -goto fail - -:execute -@rem Setup the command line - -set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar - - -@rem Execute Gradle -"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %* - -:end -@rem End local scope for the variables with windows NT shell -if "%ERRORLEVEL%"=="0" goto mainEnd - -:fail -rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of -rem the _cmd.exe /c_ return code! -if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 -exit /b 1 - -:mainEnd -if "%OS%"=="Windows_NT" endlocal - -:omega +@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 +@rem Gradle startup script for Windows +@rem +@rem ########################################################################## + +@rem Set local scope for the variables with windows NT shell +if "%OS%"=="Windows_NT" setlocal + +set DIRNAME=%~dp0 +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="-Xmx64m" "-Xms64m" + +@rem Find java.exe +if defined JAVA_HOME goto findJavaFromJavaHome + +set JAVA_EXE=java.exe +%JAVA_EXE% -version >NUL 2>&1 +if "%ERRORLEVEL%" == "0" goto execute + +echo. +echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. +echo. +echo Please set the JAVA_HOME variable in your environment to match the +echo location of your Java installation. + +goto fail + +:findJavaFromJavaHome +set JAVA_HOME=%JAVA_HOME:"=% +set JAVA_EXE=%JAVA_HOME%/bin/java.exe + +if exist "%JAVA_EXE%" goto execute + +echo. +echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% +echo. +echo Please set the JAVA_HOME variable in your environment to match the +echo location of your Java installation. + +goto fail + +:execute +@rem Setup the command line + +set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar + + +@rem Execute Gradle +"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %* + +:end +@rem End local scope for the variables with windows NT shell +if "%ERRORLEVEL%"=="0" goto mainEnd + +:fail +rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of +rem the _cmd.exe /c_ return code! +if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 +exit /b 1 + +:mainEnd +if "%OS%"=="Windows_NT" endlocal + +:omega From cc9b54b8ba0c61f8c7af3967e9dfc963851edb01 Mon Sep 17 00:00:00 2001 From: Nino Maruszewski Date: Sun, 13 Jun 2021 08:41:36 -0500 Subject: [PATCH 02/44] Add Picocli --- build.gradle | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/build.gradle b/build.gradle index a98fa0f..d467195 100644 --- a/build.gradle +++ b/build.gradle @@ -28,6 +28,17 @@ dependencies { implementation "org.ow2.asm:asm-tree:$asmVersion" implementation "org.ow2.asm:asm-util:$asmVersion" testImplementation 'org.junit.jupiter:junit-jupiter:5.6.2' + + // CLI tool + def picocliVersion = "4.6.1" + + implementation "info.picocli:picocli:$picocliVersion" + annotationProcessor "info.picocli:picocli-codegen:$picocliVersion" +} + +compileJava { + // For PicoCLI annotation processor + options.compilerArgs += ["-Aproject=${project.group}/${project.name}"] } java { From dbdd278ae67ff77d8c784c6ce0e5c3b74c51f1bb Mon Sep 17 00:00:00 2001 From: Nino Maruszewski Date: Sun, 13 Jun 2021 09:04:19 -0500 Subject: [PATCH 03/44] Start annotating fields --- .../java/net/fabricmc/tinyremapper/Main.java | 70 ++++++++++++++----- 1 file changed, 52 insertions(+), 18 deletions(-) diff --git a/src/main/java/net/fabricmc/tinyremapper/Main.java b/src/main/java/net/fabricmc/tinyremapper/Main.java index 23f4847..7beade1 100644 --- a/src/main/java/net/fabricmc/tinyremapper/Main.java +++ b/src/main/java/net/fabricmc/tinyremapper/Main.java @@ -15,7 +15,6 @@ * You should have received a copy of the GNU Lesser General Public License * along with this program. If not, see . */ - package net.fabricmc.tinyremapper; import java.io.BufferedReader; @@ -31,28 +30,63 @@ import java.util.List; import java.util.Locale; import java.util.Set; +import java.util.concurrent.Callable; import net.fabricmc.tinyremapper.TinyRemapper.LinkedMethodPropagation; +import picocli.CommandLine; +import picocli.CommandLine.Command; +import picocli.CommandLine.Option; +import picocli.CommandLine.Parameters; + +@Command(name = "tiny-remapper", mixinStandardHelpOptions = true, + version = {"Tiny Remapper " + Main.getPackage().getImplementationVersion(), + "Picocli " + picocli.CommandLine.VERSION, + "JVM: ${java.version} (${java.vendor} ${java.vm.name} ${java.vm.version})", + "OS: ${os.name} ${os.version} ${os.arch}"}, + description = "A tool for remapping JAR files using \"Tiny\"-format mappings") +public class Main implements Callable { + @Option(names = {"-V", "--version"}, versionHelp = true, description = "display version info") + boolean versionInfoRequested; + + @Option(names = {"-h", "--help"}, usageHelp = true, description = "display this help message") + boolean usageHelpRequested; + + @Option(names = "--reverse", + description = "Reverse the mapping. @|bold,underline,yellow NOT YET IMPLEMENTED!|@") + boolean reverse = false; + + boolean ignoreFieldDesc = false; + + boolean propagatePrivate = false; + + LinkedMethodPropagation propagateBridges = LinkedMethodPropagation.DISABLED; + + boolean removeFrames = false; + + Set forcePropagation = Collections.emptySet(); + + File forcePropagationFile = null; + + boolean ignoreConflicts = false; + + boolean checkPackageAccess = false; + + boolean fixPackageAccess = false; + + boolean resolveMissing = false; + + boolean rebuildSourceFilenames = false; + + boolean skipLocalVariableMapping = false; + + boolean renameInvalidLocals = false; + + NonClassCopyMode ncCopyMode = NonClassCopyMode.FIX_META_INF; + + int threads = -1; -public class Main { public static void main(String[] rawArgs) { List args = new ArrayList(rawArgs.length); - boolean reverse = false; - boolean ignoreFieldDesc = false; - boolean propagatePrivate = false; - LinkedMethodPropagation propagateBridges = LinkedMethodPropagation.DISABLED; - boolean removeFrames = false; - Set forcePropagation = Collections.emptySet(); - File forcePropagationFile = null; - boolean ignoreConflicts = false; - boolean checkPackageAccess = false; - boolean fixPackageAccess = false; - boolean resolveMissing = false; - boolean rebuildSourceFilenames = false; - boolean skipLocalVariableMapping = false; - boolean renameInvalidLocals = false; - NonClassCopyMode ncCopyMode = NonClassCopyMode.FIX_META_INF; - int threads = -1; for (String arg : rawArgs) { if (arg.startsWith("--")) { From bf69606286e30ad0fed3471347f661d61bf321c4 Mon Sep 17 00:00:00 2001 From: Nino Maruszewski Date: Sun, 13 Jun 2021 09:04:51 -0500 Subject: [PATCH 04/44] Tabs ---> spaces --- .../java/net/fabricmc/tinyremapper/Main.java | 442 +++++++++--------- 1 file changed, 221 insertions(+), 221 deletions(-) diff --git a/src/main/java/net/fabricmc/tinyremapper/Main.java b/src/main/java/net/fabricmc/tinyremapper/Main.java index 7beade1..c015e68 100644 --- a/src/main/java/net/fabricmc/tinyremapper/Main.java +++ b/src/main/java/net/fabricmc/tinyremapper/Main.java @@ -39,226 +39,226 @@ import picocli.CommandLine.Parameters; @Command(name = "tiny-remapper", mixinStandardHelpOptions = true, - version = {"Tiny Remapper " + Main.getPackage().getImplementationVersion(), - "Picocli " + picocli.CommandLine.VERSION, - "JVM: ${java.version} (${java.vendor} ${java.vm.name} ${java.vm.version})", - "OS: ${os.name} ${os.version} ${os.arch}"}, - description = "A tool for remapping JAR files using \"Tiny\"-format mappings") + version = {"Tiny Remapper " + Main.getPackage().getImplementationVersion(), + "Picocli " + picocli.CommandLine.VERSION, + "JVM: ${java.version} (${java.vendor} ${java.vm.name} ${java.vm.version})", + "OS: ${os.name} ${os.version} ${os.arch}"}, + description = "A tool for remapping JAR files using \"Tiny\"-format mappings") public class Main implements Callable { - @Option(names = {"-V", "--version"}, versionHelp = true, description = "display version info") - boolean versionInfoRequested; - - @Option(names = {"-h", "--help"}, usageHelp = true, description = "display this help message") - boolean usageHelpRequested; - - @Option(names = "--reverse", - description = "Reverse the mapping. @|bold,underline,yellow NOT YET IMPLEMENTED!|@") - boolean reverse = false; - - boolean ignoreFieldDesc = false; - - boolean propagatePrivate = false; - - LinkedMethodPropagation propagateBridges = LinkedMethodPropagation.DISABLED; - - boolean removeFrames = false; - - Set forcePropagation = Collections.emptySet(); - - File forcePropagationFile = null; - - boolean ignoreConflicts = false; - - boolean checkPackageAccess = false; - - boolean fixPackageAccess = false; - - boolean resolveMissing = false; - - boolean rebuildSourceFilenames = false; - - boolean skipLocalVariableMapping = false; - - boolean renameInvalidLocals = false; - - NonClassCopyMode ncCopyMode = NonClassCopyMode.FIX_META_INF; - - int threads = -1; - - public static void main(String[] rawArgs) { - List args = new ArrayList(rawArgs.length); - - for (String arg : rawArgs) { - if (arg.startsWith("--")) { - int valueSepPos = arg.indexOf('='); - - String argKey = valueSepPos == -1 ? arg.substring(2) : arg.substring(2, valueSepPos); - argKey = argKey.toLowerCase(Locale.ROOT); - - switch (argKey.toLowerCase()) { - case "reverse": - System.err.println("WARNING: --reverse is not currently implemented!"); - reverse = true; - break; - case "ignorefielddesc": - ignoreFieldDesc = true; - break; - case "forcepropagation": - forcePropagationFile = new File(arg.substring(valueSepPos + 1)); - break; - case "propagateprivate": - propagatePrivate = true; - break; - case "propagatebridges": - switch (arg.substring(valueSepPos + 1).toLowerCase(Locale.ENGLISH)) { - case "disabled": propagateBridges = LinkedMethodPropagation.DISABLED; break; - case "enabled": propagateBridges = LinkedMethodPropagation.ENABLED; break; - case "compatible": propagateBridges = LinkedMethodPropagation.COMPATIBLE; break; - default: - System.out.println("invalid propagateBridges: "+arg.substring(valueSepPos + 1)); - System.exit(1); - } - - break; - case "removeframes": - removeFrames = true; - break; - case "ignoreconflicts": - ignoreConflicts = true; - break; - case "checkpackageaccess": - checkPackageAccess = true; - break; - case "fixpackageaccess": - fixPackageAccess = true; - break; - case "resolvemissing": - resolveMissing = true; - break; - case "rebuildsourcefilenames": - rebuildSourceFilenames = true; - break; - case "skiplocalvariablemapping": - skipLocalVariableMapping = true; - break; - case "renameinvalidlocals": - renameInvalidLocals = true; - break; - case "nonclasscopymode": - switch (arg.substring(valueSepPos + 1).toLowerCase(Locale.ENGLISH)) { - case "unchanged": ncCopyMode = NonClassCopyMode.UNCHANGED; break; - case "fixmeta": ncCopyMode = NonClassCopyMode.FIX_META_INF; break; - case "skipmeta": ncCopyMode = NonClassCopyMode.SKIP_META_INF; break; - default: - System.out.println("invalid nonClassCopyMode: "+arg.substring(valueSepPos + 1)); - System.exit(1); - } - - break; - case "threads": - threads = Integer.parseInt(arg.substring(valueSepPos + 1)); - if (threads <= 0) { - System.out.println("Thread count must be > 0"); - System.exit(1); - } - break; - default: - System.out.println("invalid argument: "+arg+"."); - System.exit(1); - } - } else { - args.add(arg); - } - } - - if (args.size() < 5) { - System.out.println("usage: []... [--reverse] [--forcePropagation=] [--propagatePrivate] [--ignoreConflicts]"); - System.exit(1); - } - - Path input = Paths.get(args.get(0)); - if (!Files.isReadable(input)) { - System.out.println("Can't read input file "+input+"."); - System.exit(1); - } - - Path output = Paths.get(args.get(1)); - - Path mappings = Paths.get(args.get(2)); - if (!Files.isReadable(mappings) || Files.isDirectory(mappings)) { - System.out.println("Can't read mappings file "+mappings+"."); - System.exit(1); - } - - String fromM = args.get(3); - String toM = args.get(4); - - Path[] classpath = new Path[args.size() - 5]; - - for (int i = 0; i < classpath.length; i++) { - classpath[i] = Paths.get(args.get(i + 5)); - if (!Files.isReadable(classpath[i])) { - System.out.println("Can't read classpath file "+i+": "+classpath[i]+"."); - System.exit(1); - } - } - - if (forcePropagationFile != null) { - forcePropagation = new HashSet<>(); - - if (!forcePropagationFile.canRead()) { - System.out.println("Can't read forcePropagation file "+forcePropagationFile+"."); - System.exit(1); - } - - try (BufferedReader reader = new BufferedReader(new FileReader(forcePropagationFile))) { - String line; - - while ((line = reader.readLine()) != null) { - line = line.trim(); - - if (line.isEmpty() || line.charAt(0) == '#') continue; - - forcePropagation.add(line); - } - } catch (IOException e) { - e.printStackTrace(); - System.exit(1); - } - } - - long startTime = System.nanoTime(); - - TinyRemapper remapper = TinyRemapper.newRemapper() - .withMappings(TinyUtils.createTinyMappingProvider(mappings, fromM, toM)) - .ignoreFieldDesc(ignoreFieldDesc) - .withForcedPropagation(forcePropagation) - .propagatePrivate(propagatePrivate) - .propagateBridges(propagateBridges) - .removeFrames(removeFrames) - .ignoreConflicts(ignoreConflicts) - .checkPackageAccess(checkPackageAccess) - .fixPackageAccess(fixPackageAccess) - .resolveMissing(resolveMissing) - .rebuildSourceFilenames(rebuildSourceFilenames) - .skipLocalVariableMapping(skipLocalVariableMapping) - .renameInvalidLocals(renameInvalidLocals) - .threads(threads) - .build(); - - try (OutputConsumerPath outputConsumer = new OutputConsumerPath.Builder(output).build()) { - outputConsumer.addNonClassFiles(input, ncCopyMode, remapper); - - remapper.readInputs(input); - remapper.readClassPath(classpath); - - remapper.apply(outputConsumer); - } catch (IOException e) { - throw new RuntimeException(e); - } finally { - remapper.finish(); - } - - System.out.printf("Finished after %.2f ms.\n", (System.nanoTime() - startTime) / 1e6); - } + @Option(names = {"-V", "--version"}, versionHelp = true, description = "display version info") + boolean versionInfoRequested; + + @Option(names = {"-h", "--help"}, usageHelp = true, description = "display this help message") + boolean usageHelpRequested; + + @Option(names = "--reverse", + description = "Reverse the mapping. @|bold,underline,yellow NOT YET IMPLEMENTED!|@") + boolean reverse = false; + + boolean ignoreFieldDesc = false; + + boolean propagatePrivate = false; + + LinkedMethodPropagation propagateBridges = LinkedMethodPropagation.DISABLED; + + boolean removeFrames = false; + + Set forcePropagation = Collections.emptySet(); + + File forcePropagationFile = null; + + boolean ignoreConflicts = false; + + boolean checkPackageAccess = false; + + boolean fixPackageAccess = false; + + boolean resolveMissing = false; + + boolean rebuildSourceFilenames = false; + + boolean skipLocalVariableMapping = false; + + boolean renameInvalidLocals = false; + + NonClassCopyMode ncCopyMode = NonClassCopyMode.FIX_META_INF; + + int threads = -1; + + public static void main(String[] rawArgs) { + List args = new ArrayList(rawArgs.length); + + for (String arg : rawArgs) { + if (arg.startsWith("--")) { + int valueSepPos = arg.indexOf('='); + + String argKey = valueSepPos == -1 ? arg.substring(2) : arg.substring(2, valueSepPos); + argKey = argKey.toLowerCase(Locale.ROOT); + + switch (argKey.toLowerCase()) { + case "reverse": + System.err.println("WARNING: --reverse is not currently implemented!"); + reverse = true; + break; + case "ignorefielddesc": + ignoreFieldDesc = true; + break; + case "forcepropagation": + forcePropagationFile = new File(arg.substring(valueSepPos + 1)); + break; + case "propagateprivate": + propagatePrivate = true; + break; + case "propagatebridges": + switch (arg.substring(valueSepPos + 1).toLowerCase(Locale.ENGLISH)) { + case "disabled": propagateBridges = LinkedMethodPropagation.DISABLED; break; + case "enabled": propagateBridges = LinkedMethodPropagation.ENABLED; break; + case "compatible": propagateBridges = LinkedMethodPropagation.COMPATIBLE; break; + default: + System.out.println("invalid propagateBridges: "+arg.substring(valueSepPos + 1)); + System.exit(1); + } + + break; + case "removeframes": + removeFrames = true; + break; + case "ignoreconflicts": + ignoreConflicts = true; + break; + case "checkpackageaccess": + checkPackageAccess = true; + break; + case "fixpackageaccess": + fixPackageAccess = true; + break; + case "resolvemissing": + resolveMissing = true; + break; + case "rebuildsourcefilenames": + rebuildSourceFilenames = true; + break; + case "skiplocalvariablemapping": + skipLocalVariableMapping = true; + break; + case "renameinvalidlocals": + renameInvalidLocals = true; + break; + case "nonclasscopymode": + switch (arg.substring(valueSepPos + 1).toLowerCase(Locale.ENGLISH)) { + case "unchanged": ncCopyMode = NonClassCopyMode.UNCHANGED; break; + case "fixmeta": ncCopyMode = NonClassCopyMode.FIX_META_INF; break; + case "skipmeta": ncCopyMode = NonClassCopyMode.SKIP_META_INF; break; + default: + System.out.println("invalid nonClassCopyMode: "+arg.substring(valueSepPos + 1)); + System.exit(1); + } + + break; + case "threads": + threads = Integer.parseInt(arg.substring(valueSepPos + 1)); + if (threads <= 0) { + System.out.println("Thread count must be > 0"); + System.exit(1); + } + break; + default: + System.out.println("invalid argument: "+arg+"."); + System.exit(1); + } + } else { + args.add(arg); + } + } + + if (args.size() < 5) { + System.out.println("usage: []... [--reverse] [--forcePropagation=] [--propagatePrivate] [--ignoreConflicts]"); + System.exit(1); + } + + Path input = Paths.get(args.get(0)); + if (!Files.isReadable(input)) { + System.out.println("Can't read input file "+input+"."); + System.exit(1); + } + + Path output = Paths.get(args.get(1)); + + Path mappings = Paths.get(args.get(2)); + if (!Files.isReadable(mappings) || Files.isDirectory(mappings)) { + System.out.println("Can't read mappings file "+mappings+"."); + System.exit(1); + } + + String fromM = args.get(3); + String toM = args.get(4); + + Path[] classpath = new Path[args.size() - 5]; + + for (int i = 0; i < classpath.length; i++) { + classpath[i] = Paths.get(args.get(i + 5)); + if (!Files.isReadable(classpath[i])) { + System.out.println("Can't read classpath file "+i+": "+classpath[i]+"."); + System.exit(1); + } + } + + if (forcePropagationFile != null) { + forcePropagation = new HashSet<>(); + + if (!forcePropagationFile.canRead()) { + System.out.println("Can't read forcePropagation file "+forcePropagationFile+"."); + System.exit(1); + } + + try (BufferedReader reader = new BufferedReader(new FileReader(forcePropagationFile))) { + String line; + + while ((line = reader.readLine()) != null) { + line = line.trim(); + + if (line.isEmpty() || line.charAt(0) == '#') continue; + + forcePropagation.add(line); + } + } catch (IOException e) { + e.printStackTrace(); + System.exit(1); + } + } + + long startTime = System.nanoTime(); + + TinyRemapper remapper = TinyRemapper.newRemapper() + .withMappings(TinyUtils.createTinyMappingProvider(mappings, fromM, toM)) + .ignoreFieldDesc(ignoreFieldDesc) + .withForcedPropagation(forcePropagation) + .propagatePrivate(propagatePrivate) + .propagateBridges(propagateBridges) + .removeFrames(removeFrames) + .ignoreConflicts(ignoreConflicts) + .checkPackageAccess(checkPackageAccess) + .fixPackageAccess(fixPackageAccess) + .resolveMissing(resolveMissing) + .rebuildSourceFilenames(rebuildSourceFilenames) + .skipLocalVariableMapping(skipLocalVariableMapping) + .renameInvalidLocals(renameInvalidLocals) + .threads(threads) + .build(); + + try (OutputConsumerPath outputConsumer = new OutputConsumerPath.Builder(output).build()) { + outputConsumer.addNonClassFiles(input, ncCopyMode, remapper); + + remapper.readInputs(input); + remapper.readClassPath(classpath); + + remapper.apply(outputConsumer); + } catch (IOException e) { + throw new RuntimeException(e); + } finally { + remapper.finish(); + } + + System.out.printf("Finished after %.2f ms.\n", (System.nanoTime() - startTime) / 1e6); + } } From ede339fabc9bdc26cef08e5c3ad5782b8622f9f9 Mon Sep 17 00:00:00 2001 From: Nino Maruszewski Date: Sun, 13 Jun 2021 17:45:52 -0500 Subject: [PATCH 05/44] Improve version detection --- .../java/net/fabricmc/tinyremapper/Main.java | 170 ++++++++++-------- 1 file changed, 95 insertions(+), 75 deletions(-) diff --git a/src/main/java/net/fabricmc/tinyremapper/Main.java b/src/main/java/net/fabricmc/tinyremapper/Main.java index c015e68..6380c23 100644 --- a/src/main/java/net/fabricmc/tinyremapper/Main.java +++ b/src/main/java/net/fabricmc/tinyremapper/Main.java @@ -15,6 +15,7 @@ * You should have received a copy of the GNU Lesser General Public License * along with this program. If not, see . */ + package net.fabricmc.tinyremapper; import java.io.BufferedReader; @@ -39,7 +40,7 @@ import picocli.CommandLine.Parameters; @Command(name = "tiny-remapper", mixinStandardHelpOptions = true, - version = {"Tiny Remapper " + Main.getPackage().getImplementationVersion(), + version = {"Tiny Remapper " + Main.version == null ? "DEVELOP" : Main.version, "Picocli " + picocli.CommandLine.VERSION, "JVM: ${java.version} (${java.vendor} ${java.vm.name} ${java.vm.version})", "OS: ${os.name} ${os.version} ${os.arch}"}, @@ -47,6 +48,7 @@ public class Main implements Callable { @Option(names = {"-V", "--version"}, versionHelp = true, description = "display version info") boolean versionInfoRequested; + public static String version = getClass().getPackage().getImplementationVersion(); @Option(names = {"-h", "--help"}, usageHelp = true, description = "display this help message") boolean usageHelpRequested; @@ -92,79 +94,94 @@ public static void main(String[] rawArgs) { if (arg.startsWith("--")) { int valueSepPos = arg.indexOf('='); - String argKey = valueSepPos == -1 ? arg.substring(2) : arg.substring(2, valueSepPos); + String argKey = + valueSepPos == -1 ? arg.substring(2) : arg.substring(2, valueSepPos); argKey = argKey.toLowerCase(Locale.ROOT); switch (argKey.toLowerCase()) { - case "reverse": - System.err.println("WARNING: --reverse is not currently implemented!"); - reverse = true; - break; - case "ignorefielddesc": - ignoreFieldDesc = true; - break; - case "forcepropagation": - forcePropagationFile = new File(arg.substring(valueSepPos + 1)); - break; - case "propagateprivate": - propagatePrivate = true; - break; - case "propagatebridges": - switch (arg.substring(valueSepPos + 1).toLowerCase(Locale.ENGLISH)) { - case "disabled": propagateBridges = LinkedMethodPropagation.DISABLED; break; - case "enabled": propagateBridges = LinkedMethodPropagation.ENABLED; break; - case "compatible": propagateBridges = LinkedMethodPropagation.COMPATIBLE; break; - default: - System.out.println("invalid propagateBridges: "+arg.substring(valueSepPos + 1)); - System.exit(1); - } - - break; - case "removeframes": - removeFrames = true; - break; - case "ignoreconflicts": - ignoreConflicts = true; - break; - case "checkpackageaccess": - checkPackageAccess = true; - break; - case "fixpackageaccess": - fixPackageAccess = true; - break; - case "resolvemissing": - resolveMissing = true; - break; - case "rebuildsourcefilenames": - rebuildSourceFilenames = true; - break; - case "skiplocalvariablemapping": - skipLocalVariableMapping = true; - break; - case "renameinvalidlocals": - renameInvalidLocals = true; - break; - case "nonclasscopymode": - switch (arg.substring(valueSepPos + 1).toLowerCase(Locale.ENGLISH)) { - case "unchanged": ncCopyMode = NonClassCopyMode.UNCHANGED; break; - case "fixmeta": ncCopyMode = NonClassCopyMode.FIX_META_INF; break; - case "skipmeta": ncCopyMode = NonClassCopyMode.SKIP_META_INF; break; + case "reverse": + System.err.println("WARNING: --reverse is not currently implemented!"); + reverse = true; + break; + case "ignorefielddesc": + ignoreFieldDesc = true; + break; + case "forcepropagation": + forcePropagationFile = new File(arg.substring(valueSepPos + 1)); + break; + case "propagateprivate": + propagatePrivate = true; + break; + case "propagatebridges": + switch (arg.substring(valueSepPos + 1).toLowerCase(Locale.ENGLISH)) { + case "disabled": + propagateBridges = LinkedMethodPropagation.DISABLED; + break; + case "enabled": + propagateBridges = LinkedMethodPropagation.ENABLED; + break; + case "compatible": + propagateBridges = LinkedMethodPropagation.COMPATIBLE; + break; + default: + System.out.println("invalid propagateBridges: " + + arg.substring(valueSepPos + 1)); + System.exit(1); + } + + break; + case "removeframes": + removeFrames = true; + break; + case "ignoreconflicts": + ignoreConflicts = true; + break; + case "checkpackageaccess": + checkPackageAccess = true; + break; + case "fixpackageaccess": + fixPackageAccess = true; + break; + case "resolvemissing": + resolveMissing = true; + break; + case "rebuildsourcefilenames": + rebuildSourceFilenames = true; + break; + case "skiplocalvariablemapping": + skipLocalVariableMapping = true; + break; + case "renameinvalidlocals": + renameInvalidLocals = true; + break; + case "nonclasscopymode": + switch (arg.substring(valueSepPos + 1).toLowerCase(Locale.ENGLISH)) { + case "unchanged": + ncCopyMode = NonClassCopyMode.UNCHANGED; + break; + case "fixmeta": + ncCopyMode = NonClassCopyMode.FIX_META_INF; + break; + case "skipmeta": + ncCopyMode = NonClassCopyMode.SKIP_META_INF; + break; + default: + System.out.println("invalid nonClassCopyMode: " + + arg.substring(valueSepPos + 1)); + System.exit(1); + } + + break; + case "threads": + threads = Integer.parseInt(arg.substring(valueSepPos + 1)); + if (threads <= 0) { + System.out.println("Thread count must be > 0"); + System.exit(1); + } + break; default: - System.out.println("invalid nonClassCopyMode: "+arg.substring(valueSepPos + 1)); - System.exit(1); - } - - break; - case "threads": - threads = Integer.parseInt(arg.substring(valueSepPos + 1)); - if (threads <= 0) { - System.out.println("Thread count must be > 0"); + System.out.println("invalid argument: " + arg + "."); System.exit(1); - } - break; - default: - System.out.println("invalid argument: "+arg+"."); - System.exit(1); } } else { args.add(arg); @@ -172,13 +189,14 @@ public static void main(String[] rawArgs) { } if (args.size() < 5) { - System.out.println("usage: []... [--reverse] [--forcePropagation=] [--propagatePrivate] [--ignoreConflicts]"); + System.out.println( + "usage: []... [--reverse] [--forcePropagation=] [--propagatePrivate] [--ignoreConflicts]"); System.exit(1); } Path input = Paths.get(args.get(0)); if (!Files.isReadable(input)) { - System.out.println("Can't read input file "+input+"."); + System.out.println("Can't read input file " + input + "."); System.exit(1); } @@ -186,7 +204,7 @@ public static void main(String[] rawArgs) { Path mappings = Paths.get(args.get(2)); if (!Files.isReadable(mappings) || Files.isDirectory(mappings)) { - System.out.println("Can't read mappings file "+mappings+"."); + System.out.println("Can't read mappings file " + mappings + "."); System.exit(1); } @@ -198,7 +216,7 @@ public static void main(String[] rawArgs) { for (int i = 0; i < classpath.length; i++) { classpath[i] = Paths.get(args.get(i + 5)); if (!Files.isReadable(classpath[i])) { - System.out.println("Can't read classpath file "+i+": "+classpath[i]+"."); + System.out.println("Can't read classpath file " + i + ": " + classpath[i] + "."); System.exit(1); } } @@ -207,7 +225,8 @@ public static void main(String[] rawArgs) { forcePropagation = new HashSet<>(); if (!forcePropagationFile.canRead()) { - System.out.println("Can't read forcePropagation file "+forcePropagationFile+"."); + System.out + .println("Can't read forcePropagation file " + forcePropagationFile + "."); System.exit(1); } @@ -217,7 +236,8 @@ public static void main(String[] rawArgs) { while ((line = reader.readLine()) != null) { line = line.trim(); - if (line.isEmpty() || line.charAt(0) == '#') continue; + if (line.isEmpty() || line.charAt(0) == '#') + continue; forcePropagation.add(line); } From ac7ca7b9ef5573fcf01938d0281fbca93acf99bd Mon Sep 17 00:00:00 2001 From: Nino Maruszewski Date: Sun, 13 Jun 2021 19:44:00 -0500 Subject: [PATCH 06/44] Annotate all switches --- .../java/net/fabricmc/tinyremapper/Main.java | 389 +++++++++++------- 1 file changed, 249 insertions(+), 140 deletions(-) diff --git a/src/main/java/net/fabricmc/tinyremapper/Main.java b/src/main/java/net/fabricmc/tinyremapper/Main.java index 6380c23..edf0498 100644 --- a/src/main/java/net/fabricmc/tinyremapper/Main.java +++ b/src/main/java/net/fabricmc/tinyremapper/Main.java @@ -32,161 +32,275 @@ import java.util.Locale; import java.util.Set; import java.util.concurrent.Callable; +import javax.validation.ConstraintViolation; +import javax.validation.Validation; +import javax.validation.Validator; +import javax.validation.constraints.Min; import net.fabricmc.tinyremapper.TinyRemapper.LinkedMethodPropagation; import picocli.CommandLine; import picocli.CommandLine.Command; +import picocli.CommandLine.Mixin; +import picocli.CommandLine.Model.CommandSpec; import picocli.CommandLine.Option; +import picocli.CommandLine.ParameterException; import picocli.CommandLine.Parameters; -@Command(name = "tiny-remapper", mixinStandardHelpOptions = true, - version = {"Tiny Remapper " + Main.version == null ? "DEVELOP" : Main.version, - "Picocli " + picocli.CommandLine.VERSION, - "JVM: ${java.version} (${java.vendor} ${java.vm.name} ${java.vm.version})", - "OS: ${os.name} ${os.version} ${os.arch}"}, - description = "A tool for remapping JAR files using \"Tiny\"-format mappings") + +/* @formatter:off - eclipse formatter doesn't seem to like annotations */ +@Command(name = "tiny-remapper", mixinStandardHelpOptions = true, version = { + "Tiny Remapper " + Main.version == null ? "DEVELOP" : Main.version, + "Picocli " + picocli.CommandLine.VERSION, + "JVM: ${java.version} (${java.vendor} ${java.vm.name} ${java.vm.version})", + "OS: ${os.name} ${os.version} ${os.arch}"}, + description = "A tool for remapping JAR files using \"Tiny\"-format mappings", + usageHelpAutoWidth = true) public class Main implements Callable { - @Option(names = {"-V", "--version"}, versionHelp = true, description = "display version info") + /* @formatter:on */ + @Spec + CommandSpec spec; // injected by picocli + + @Option(names = {"-V", "--version"}, versionHelp = true, description = "Display version info") boolean versionInfoRequested; public static String version = getClass().getPackage().getImplementationVersion(); - @Option(names = {"-h", "--help"}, usageHelp = true, description = "display this help message") + @Option(names = {"-h", "--help"}, usageHelp = true, description = "Display this help message") boolean usageHelpRequested; @Option(names = "--reverse", description = "Reverse the mapping. @|bold,underline,yellow NOT YET IMPLEMENTED!|@") boolean reverse = false; + @Option(names = "--ignore-field-desc", + description = "Ignore the field descriptions in mappings.") boolean ignoreFieldDesc = false; + Set forcePropagation = Collections.emptySet(); + + /** + * Set the forcePropagation variable and validate. + * + * @param value input file from the user + */ + @Option(names = "--force-propagation", + description = "A file with methods to force propagation to.") + public void setForcePropagation(String value) { + File forcePropagationFile = new File(value); + + if (forcePropagationFile != null) { + forcePropagation = new HashSet<>(); + + if (!forcePropagationFile.canRead()) { + throw new ParameterException(spec.commandLine(), + "Cannot read forcePropagation file " + forcePropagationFile + "."); + } + + try (BufferedReader reader = new BufferedReader(new FileReader(forcePropagationFile))) { + String line; + + while ((line = reader.readLine()) != null) { + line = line.trim(); + + if (line.isEmpty() || line.charAt(0) == '#') { + continue; + } + + forcePropagation.add(line); + } + } catch (IOException e) { + e.printStackTrace(); + throw new ParameterException(spec.commandLine(), + "An error occurred while parsing the forcePropagation file."); + } + } + } + + @Option(names = "--propagate-private", + description = "Propagate mappings to private methods.") boolean propagatePrivate = false; LinkedMethodPropagation propagateBridges = LinkedMethodPropagation.DISABLED; - boolean removeFrames = false; - - Set forcePropagation = Collections.emptySet(); + /** + * Set the propagateBridges variable and validate. + * + * @param value input from the user + */ + @Option(names = "propagate-bridges", + description = "Propagate methods to bridge methods. " + + "Must be one of \"disabled\", \"enabled\", or \"compatible\".") + public void setPropagateBridges(String value) { + switch (value.toLowerCase(Locale.ENGLISH)) { + case "disabled": + propagateBridges = LinkedMethodPropagation.DISABLED; + break; + case "enabled": + propagateBridges = LinkedMethodPropagation.ENABLED; + break; + case "compatible": + propagateBridges = LinkedMethodPropagation.COMPATIBLE; + break; + default: + throw new ParameterException(spec.commandLine(), + "Invalid propagateBridges value: " + value); + } + } - File forcePropagationFile = null; + @Option(names = "--remove-frames", + description = "Ignore the StackMap and StackMapTable frames.") + boolean removeFrames = false; + @Option(names = "--ignore-conflicts", + description = "Ignore any mapping conflicts.") boolean ignoreConflicts = false; + @Option(names = "--check-package-access", + description = "Check package access.") boolean checkPackageAccess = false; + @Option(names = "--fix-package-access", + description = "Fix package access. Implies \"--fix-package-access\".") boolean fixPackageAccess = false; + @Option(names = "--resolve-missing", description = "Resolve missing methods.") boolean resolveMissing = false; + @Option(names = "--rebuild-source-filenames", + description = "Rebuild the filenames of sources.") boolean rebuildSourceFilenames = false; + @Option(names = "--skip-local-variable-mapping", description = "Skip remapping local variables") boolean skipLocalVariableMapping = false; + @Option(names = "--rename-invalid-locals", description = "Rename invalid local variables.") boolean renameInvalidLocals = false; NonClassCopyMode ncCopyMode = NonClassCopyMode.FIX_META_INF; + @Option(names = "--non-class-copy-mode", + description = "How to deal with non-class files in a JAR. " + + "Must be one of \"unchanged\", \"fixmeta\", or \"skipmeta\".") + private void setNonClassCopyMode(String value) { + switch (value.toLowerCase(Locale.ENGLISH)) { + case "unchanged": + ncCopyMode = NonClassCopyMode.UNCHANGED; + break; + case "fixmeta": + ncCopyMode = NonClassCopyMode.FIX_META_INF; + break; + case "skipmeta": + ncCopyMode = NonClassCopyMode.SKIP_META_INF; + break; + default: + throw new ParameterException(spec.commandLine(), + "Invalid nonClassCopyMode value: " + value); + } + } + + @Min(value = 1, message = "Thread count must be greater than 0.") + @Option(names = "--threads", + description = "Number of threads to use while remapping. " + + "Defaults to the number of CPU cores available.") int threads = -1; public static void main(String[] rawArgs) { List args = new ArrayList(rawArgs.length); - for (String arg : rawArgs) { - if (arg.startsWith("--")) { - int valueSepPos = arg.indexOf('='); - - String argKey = - valueSepPos == -1 ? arg.substring(2) : arg.substring(2, valueSepPos); - argKey = argKey.toLowerCase(Locale.ROOT); - - switch (argKey.toLowerCase()) { - case "reverse": - System.err.println("WARNING: --reverse is not currently implemented!"); - reverse = true; - break; - case "ignorefielddesc": - ignoreFieldDesc = true; - break; - case "forcepropagation": - forcePropagationFile = new File(arg.substring(valueSepPos + 1)); - break; - case "propagateprivate": - propagatePrivate = true; - break; - case "propagatebridges": - switch (arg.substring(valueSepPos + 1).toLowerCase(Locale.ENGLISH)) { - case "disabled": - propagateBridges = LinkedMethodPropagation.DISABLED; - break; - case "enabled": - propagateBridges = LinkedMethodPropagation.ENABLED; - break; - case "compatible": - propagateBridges = LinkedMethodPropagation.COMPATIBLE; - break; - default: - System.out.println("invalid propagateBridges: " - + arg.substring(valueSepPos + 1)); - System.exit(1); - } - - break; - case "removeframes": - removeFrames = true; - break; - case "ignoreconflicts": - ignoreConflicts = true; - break; - case "checkpackageaccess": - checkPackageAccess = true; - break; - case "fixpackageaccess": - fixPackageAccess = true; - break; - case "resolvemissing": - resolveMissing = true; - break; - case "rebuildsourcefilenames": - rebuildSourceFilenames = true; - break; - case "skiplocalvariablemapping": - skipLocalVariableMapping = true; - break; - case "renameinvalidlocals": - renameInvalidLocals = true; - break; - case "nonclasscopymode": - switch (arg.substring(valueSepPos + 1).toLowerCase(Locale.ENGLISH)) { - case "unchanged": - ncCopyMode = NonClassCopyMode.UNCHANGED; - break; - case "fixmeta": - ncCopyMode = NonClassCopyMode.FIX_META_INF; - break; - case "skipmeta": - ncCopyMode = NonClassCopyMode.SKIP_META_INF; - break; - default: - System.out.println("invalid nonClassCopyMode: " - + arg.substring(valueSepPos + 1)); - System.exit(1); - } - - break; - case "threads": - threads = Integer.parseInt(arg.substring(valueSepPos + 1)); - if (threads <= 0) { - System.out.println("Thread count must be > 0"); - System.exit(1); - } - break; - default: - System.out.println("invalid argument: " + arg + "."); - System.exit(1); - } - } else { - args.add(arg); - } - } + // for (String arg : rawArgs) { + // if (arg.startsWith("--")) { + // int valueSepPos = arg.indexOf('='); + + // String argKey = + // valueSepPos == -1 ? arg.substring(2) : arg.substring(2, valueSepPos); + // argKey = argKey.toLowerCase(Locale.ROOT); + + // switch (argKey.toLowerCase()) { + // case "reverse": + // System.err.println("WARNING: --reverse is not currently implemented!"); + // reverse = true; + // break; + // case "ignorefielddesc": + // ignoreFieldDesc = true; + // break; + // case "forcepropagation": + // forcePropagationFile = new File(arg.substring(valueSepPos + 1)); + // break; + // case "propagateprivate": + // propagatePrivate = true; + // break; + // case "propagatebridges": + // switch (arg.substring(valueSepPos + 1).toLowerCase(Locale.ENGLISH)) { + // case "disabled": + // propagateBridges = LinkedMethodPropagation.DISABLED; + // break; + // case "enabled": + // propagateBridges = LinkedMethodPropagation.ENABLED; + // break; + // case "compatible": + // propagateBridges = LinkedMethodPropagation.COMPATIBLE; + // break; + // default: + // System.out.println("invalid propagateBridges: " + // + arg.substring(valueSepPos + 1)); + // System.exit(1); + // } + // break; + // case "removeframes": + // removeFrames = true; + // break; + // case "ignoreconflicts": + // ignoreConflicts = true; + // break; + // case "checkpackageaccess": + // checkPackageAccess = true; + // break; + // case "fixpackageaccess": + // fixPackageAccess = true; + // break; + // case "resolvemissing": + // resolveMissing = true; + // break; + // case "rebuildsourcefilenames": + // rebuildSourceFilenames = true; + // break; + // case "skiplocalvariablemapping": + // skipLocalVariableMapping = true; + // break; + // case "renameinvalidlocals": + // renameInvalidLocals = true; + // break; + // case "nonclasscopymode": + // switch (arg.substring(valueSepPos + 1).toLowerCase(Locale.ENGLISH)) { + // case "unchanged": + // ncCopyMode = NonClassCopyMode.UNCHANGED; + // break; + // case "fixmeta": + // ncCopyMode = NonClassCopyMode.FIX_META_INF; + // break; + // case "skipmeta": + // ncCopyMode = NonClassCopyMode.SKIP_META_INF; + // break; + // default: + // System.out.println("invalid nonClassCopyMode: " + // + arg.substring(valueSepPos + 1)); + // System.exit(1); + // } + // break; + // case "threads": + // threads = Integer.parseInt(arg.substring(valueSepPos + 1)); + // if (threads <= 0) { + // System.out.println("Thread count must be > 0"); + // System.exit(1); + // } + // break; + // default: + // System.out.println("invalid argument: " + arg + "."); + // System.exit(1); + // } + // } else { + // args.add(arg); + // } + // } if (args.size() < 5) { System.out.println( @@ -221,50 +335,45 @@ public static void main(String[] rawArgs) { } } - if (forcePropagationFile != null) { - forcePropagation = new HashSet<>(); + // if (forcePropagationFile != null) { + // forcePropagation = new HashSet<>(); - if (!forcePropagationFile.canRead()) { - System.out - .println("Can't read forcePropagation file " + forcePropagationFile + "."); - System.exit(1); - } + // if (!forcePropagationFile.canRead()) { + // System.out + // .println("Can't read forcePropagation file " + forcePropagationFile + "."); + // System.exit(1); + // } - try (BufferedReader reader = new BufferedReader(new FileReader(forcePropagationFile))) { - String line; + // try (BufferedReader reader = new BufferedReader(new FileReader(forcePropagationFile))) { + // String line; - while ((line = reader.readLine()) != null) { - line = line.trim(); + // while ((line = reader.readLine()) != null) { + // line = line.trim(); - if (line.isEmpty() || line.charAt(0) == '#') - continue; + // if (line.isEmpty() || line.charAt(0) == '#') { + // continue; + // } - forcePropagation.add(line); - } - } catch (IOException e) { - e.printStackTrace(); - System.exit(1); - } - } + // forcePropagation.add(line); + // } + // } catch (IOException e) { + // e.printStackTrace(); + // System.exit(1); + // } + // } long startTime = System.nanoTime(); TinyRemapper remapper = TinyRemapper.newRemapper() .withMappings(TinyUtils.createTinyMappingProvider(mappings, fromM, toM)) - .ignoreFieldDesc(ignoreFieldDesc) - .withForcedPropagation(forcePropagation) - .propagatePrivate(propagatePrivate) - .propagateBridges(propagateBridges) + .ignoreFieldDesc(ignoreFieldDesc).withForcedPropagation(forcePropagation) + .propagatePrivate(propagatePrivate).propagateBridges(propagateBridges) .removeFrames(removeFrames) - .ignoreConflicts(ignoreConflicts) - .checkPackageAccess(checkPackageAccess) - .fixPackageAccess(fixPackageAccess) - .resolveMissing(resolveMissing) + .ignoreConflicts(ignoreConflicts).checkPackageAccess(checkPackageAccess) + .fixPackageAccess(fixPackageAccess).resolveMissing(resolveMissing) .rebuildSourceFilenames(rebuildSourceFilenames) .skipLocalVariableMapping(skipLocalVariableMapping) - .renameInvalidLocals(renameInvalidLocals) - .threads(threads) - .build(); + .renameInvalidLocals(renameInvalidLocals).threads(threads).build(); try (OutputConsumerPath outputConsumer = new OutputConsumerPath.Builder(output).build()) { outputConsumer.addNonClassFiles(input, ncCopyMode, remapper); From 5c6874eaece68917467c425e937949aab2c6441a Mon Sep 17 00:00:00 2001 From: Nino Maruszewski Date: Sun, 13 Jun 2021 19:47:53 -0500 Subject: [PATCH 07/44] Cleanup --- .../java/net/fabricmc/tinyremapper/Main.java | 123 ------------------ 1 file changed, 123 deletions(-) diff --git a/src/main/java/net/fabricmc/tinyremapper/Main.java b/src/main/java/net/fabricmc/tinyremapper/Main.java index edf0498..e2dd40a 100644 --- a/src/main/java/net/fabricmc/tinyremapper/Main.java +++ b/src/main/java/net/fabricmc/tinyremapper/Main.java @@ -206,102 +206,6 @@ private void setNonClassCopyMode(String value) { public static void main(String[] rawArgs) { List args = new ArrayList(rawArgs.length); - // for (String arg : rawArgs) { - // if (arg.startsWith("--")) { - // int valueSepPos = arg.indexOf('='); - - // String argKey = - // valueSepPos == -1 ? arg.substring(2) : arg.substring(2, valueSepPos); - // argKey = argKey.toLowerCase(Locale.ROOT); - - // switch (argKey.toLowerCase()) { - // case "reverse": - // System.err.println("WARNING: --reverse is not currently implemented!"); - // reverse = true; - // break; - // case "ignorefielddesc": - // ignoreFieldDesc = true; - // break; - // case "forcepropagation": - // forcePropagationFile = new File(arg.substring(valueSepPos + 1)); - // break; - // case "propagateprivate": - // propagatePrivate = true; - // break; - // case "propagatebridges": - // switch (arg.substring(valueSepPos + 1).toLowerCase(Locale.ENGLISH)) { - // case "disabled": - // propagateBridges = LinkedMethodPropagation.DISABLED; - // break; - // case "enabled": - // propagateBridges = LinkedMethodPropagation.ENABLED; - // break; - // case "compatible": - // propagateBridges = LinkedMethodPropagation.COMPATIBLE; - // break; - // default: - // System.out.println("invalid propagateBridges: " - // + arg.substring(valueSepPos + 1)); - // System.exit(1); - // } - // break; - // case "removeframes": - // removeFrames = true; - // break; - // case "ignoreconflicts": - // ignoreConflicts = true; - // break; - // case "checkpackageaccess": - // checkPackageAccess = true; - // break; - // case "fixpackageaccess": - // fixPackageAccess = true; - // break; - // case "resolvemissing": - // resolveMissing = true; - // break; - // case "rebuildsourcefilenames": - // rebuildSourceFilenames = true; - // break; - // case "skiplocalvariablemapping": - // skipLocalVariableMapping = true; - // break; - // case "renameinvalidlocals": - // renameInvalidLocals = true; - // break; - // case "nonclasscopymode": - // switch (arg.substring(valueSepPos + 1).toLowerCase(Locale.ENGLISH)) { - // case "unchanged": - // ncCopyMode = NonClassCopyMode.UNCHANGED; - // break; - // case "fixmeta": - // ncCopyMode = NonClassCopyMode.FIX_META_INF; - // break; - // case "skipmeta": - // ncCopyMode = NonClassCopyMode.SKIP_META_INF; - // break; - // default: - // System.out.println("invalid nonClassCopyMode: " - // + arg.substring(valueSepPos + 1)); - // System.exit(1); - // } - // break; - // case "threads": - // threads = Integer.parseInt(arg.substring(valueSepPos + 1)); - // if (threads <= 0) { - // System.out.println("Thread count must be > 0"); - // System.exit(1); - // } - // break; - // default: - // System.out.println("invalid argument: " + arg + "."); - // System.exit(1); - // } - // } else { - // args.add(arg); - // } - // } - if (args.size() < 5) { System.out.println( "usage: []... [--reverse] [--forcePropagation=] [--propagatePrivate] [--ignoreConflicts]"); @@ -335,33 +239,6 @@ public static void main(String[] rawArgs) { } } - // if (forcePropagationFile != null) { - // forcePropagation = new HashSet<>(); - - // if (!forcePropagationFile.canRead()) { - // System.out - // .println("Can't read forcePropagation file " + forcePropagationFile + "."); - // System.exit(1); - // } - - // try (BufferedReader reader = new BufferedReader(new FileReader(forcePropagationFile))) { - // String line; - - // while ((line = reader.readLine()) != null) { - // line = line.trim(); - - // if (line.isEmpty() || line.charAt(0) == '#') { - // continue; - // } - - // forcePropagation.add(line); - // } - // } catch (IOException e) { - // e.printStackTrace(); - // System.exit(1); - // } - // } - long startTime = System.nanoTime(); TinyRemapper remapper = TinyRemapper.newRemapper() From e543d06389169878b58396b640b9dcd7fad7c485 Mon Sep 17 00:00:00 2001 From: Nino Maruszewski Date: Sun, 13 Jun 2021 21:00:29 -0500 Subject: [PATCH 08/44] Annotate parameters --- .../java/net/fabricmc/tinyremapper/Main.java | 125 ++++++++++++++---- 1 file changed, 100 insertions(+), 25 deletions(-) diff --git a/src/main/java/net/fabricmc/tinyremapper/Main.java b/src/main/java/net/fabricmc/tinyremapper/Main.java index e2dd40a..097a642 100644 --- a/src/main/java/net/fabricmc/tinyremapper/Main.java +++ b/src/main/java/net/fabricmc/tinyremapper/Main.java @@ -57,9 +57,78 @@ usageHelpAutoWidth = true) public class Main implements Callable { /* @formatter:on */ + + /* + * ================== PicoCLI stuff ===================== + */ @Spec CommandSpec spec; // injected by picocli + /* + * ================== Input parameters ================== + */ + + // Input file + Path input; + + /** + * Set the input path variable and validate. + * + * @param value input path from the user + */ + @Parameters(index = "0", description = "Path to input file to remap.", required = true) + private void setInput(Path value) { + if (!Files.isReadable(input)) { + throw new ParameterException(spec.commandLine(), + "Cannot read input file " + value + "."); + } + input = value; + } + + @Parameters(index = "1", description = "Path to output remapped file.", required = true) + Path output; + + // Mappings file + Path mappings; + + /** + * Set the mappings path variable and validate. + * + * @param value input path from the user + */ + @Parameters(index = "2", description = "Path to mappings file.", required = true) + private void setMappings(Path value) { + if (!Files.isReadable(input)) { + throw new ParameterException(spec.commandLine(), + "Cannot read mappings file " + value + "."); + } + mappings = value; + } + + @Parameters(index = "3", description = "Namespace to map from.", required = true) + String fromMapping; + + @Parameters(index = "4", description = "Namespace to map to.", required = true) + String toMapping; + + // Classpath + Path[] classpath; + + @Parameters(index = "5..*", description = "Additional files to add to the classpath.") + private void setClasspath(Path[] value) { + classpath = new Path[value.length]; + for (Path p : value) { + classpath[i] = p; + if (!Files.isReadable(p) { + throw new ParameterException(spec.commandLine(), + "Cannot read classpath file " + p + "."); + } + } + } + + /* + * ================== Options and switches ============== + */ @Option(names = {"-V", "--version"}, versionHelp = true, description = "Display version info") boolean versionInfoRequested; public static String version = getClass().getPackage().getImplementationVersion(); @@ -75,18 +144,17 @@ public class Main implements Callable { description = "Ignore the field descriptions in mappings.") boolean ignoreFieldDesc = false; + // Force propagation option Set forcePropagation = Collections.emptySet(); /** * Set the forcePropagation variable and validate. * - * @param value input file from the user + * @param forcePropagationFile input file from the user */ @Option(names = "--force-propagation", description = "A file with methods to force propagation to.") - public void setForcePropagation(String value) { - File forcePropagationFile = new File(value); - + public void setForcePropagation(File forcePropagationFile) { if (forcePropagationFile != null) { forcePropagation = new HashSet<>(); @@ -119,6 +187,7 @@ public void setForcePropagation(String value) { description = "Propagate mappings to private methods.") boolean propagatePrivate = false; + // Propagate bridges option LinkedMethodPropagation propagateBridges = LinkedMethodPropagation.DISABLED; /** @@ -175,8 +244,14 @@ public void setPropagateBridges(String value) { @Option(names = "--rename-invalid-locals", description = "Rename invalid local variables.") boolean renameInvalidLocals = false; + // Non-class file copy mode option NonClassCopyMode ncCopyMode = NonClassCopyMode.FIX_META_INF; + /** + * Set the setNonClassCopyMode variable and validate. + * + * @param value input from the user + */ @Option(names = "--non-class-copy-mode", description = "How to deal with non-class files in a JAR. " + "Must be one of \"unchanged\", \"fixmeta\", or \"skipmeta\".") @@ -212,32 +287,32 @@ public static void main(String[] rawArgs) { System.exit(1); } - Path input = Paths.get(args.get(0)); - if (!Files.isReadable(input)) { - System.out.println("Can't read input file " + input + "."); - System.exit(1); - } + // Path input = Paths.get(args.get(0)); + // if (!Files.isReadable(input)) { + // System.out.println("Can't read input file " + input + "."); + // System.exit(1); + // } - Path output = Paths.get(args.get(1)); + // Path output = Paths.get(args.get(1)); - Path mappings = Paths.get(args.get(2)); - if (!Files.isReadable(mappings) || Files.isDirectory(mappings)) { - System.out.println("Can't read mappings file " + mappings + "."); - System.exit(1); - } + // Path mappings = Paths.get(args.get(2)); + // if (!Files.isReadable(mappings) || Files.isDirectory(mappings)) { + // System.out.println("Can't read mappings file " + mappings + "."); + // System.exit(1); + // } - String fromM = args.get(3); - String toM = args.get(4); + // String fromM = args.get(3); + // String toM = args.get(4); - Path[] classpath = new Path[args.size() - 5]; + // Path[] classpath = new Path[args.size() - 5]; - for (int i = 0; i < classpath.length; i++) { - classpath[i] = Paths.get(args.get(i + 5)); - if (!Files.isReadable(classpath[i])) { - System.out.println("Can't read classpath file " + i + ": " + classpath[i] + "."); - System.exit(1); - } - } + // for (int i = 0; i < classpath.length; i++) { + // classpath[i] = Paths.get(args.get(i + 5)); + // if (!Files.isReadable(classpath[i])) { + // System.out.println("Can't read classpath file " + i + ": " + classpath[i] + "."); + // System.exit(1); + // } + // } long startTime = System.nanoTime(); From bb3ecece12f4df4a5bab84e1bdb12d711069ec3c Mon Sep 17 00:00:00 2001 From: Nino Maruszewski Date: Sun, 13 Jun 2021 21:03:39 -0500 Subject: [PATCH 09/44] Fix classpath setter --- .../java/net/fabricmc/tinyremapper/Main.java | 41 ++----------------- 1 file changed, 4 insertions(+), 37 deletions(-) diff --git a/src/main/java/net/fabricmc/tinyremapper/Main.java b/src/main/java/net/fabricmc/tinyremapper/Main.java index 097a642..0fdd435 100644 --- a/src/main/java/net/fabricmc/tinyremapper/Main.java +++ b/src/main/java/net/fabricmc/tinyremapper/Main.java @@ -117,11 +117,11 @@ private void setMappings(Path value) { @Parameters(index = "5..*", description = "Additional files to add to the classpath.") private void setClasspath(Path[] value) { classpath = new Path[value.length]; - for (Path p : value) { - classpath[i] = p; - if (!Files.isReadable(p) { + for (int i = 0; i < value.length; i++) { + classpath[i] = value[i]; + if (!Files.isReadable(value[i]) { throw new ParameterException(spec.commandLine(), - "Cannot read classpath file " + p + "."); + "Cannot read classpath file " + value[i] + "."); } } } @@ -281,39 +281,6 @@ private void setNonClassCopyMode(String value) { public static void main(String[] rawArgs) { List args = new ArrayList(rawArgs.length); - if (args.size() < 5) { - System.out.println( - "usage: []... [--reverse] [--forcePropagation=] [--propagatePrivate] [--ignoreConflicts]"); - System.exit(1); - } - - // Path input = Paths.get(args.get(0)); - // if (!Files.isReadable(input)) { - // System.out.println("Can't read input file " + input + "."); - // System.exit(1); - // } - - // Path output = Paths.get(args.get(1)); - - // Path mappings = Paths.get(args.get(2)); - // if (!Files.isReadable(mappings) || Files.isDirectory(mappings)) { - // System.out.println("Can't read mappings file " + mappings + "."); - // System.exit(1); - // } - - // String fromM = args.get(3); - // String toM = args.get(4); - - // Path[] classpath = new Path[args.size() - 5]; - - // for (int i = 0; i < classpath.length; i++) { - // classpath[i] = Paths.get(args.get(i + 5)); - // if (!Files.isReadable(classpath[i])) { - // System.out.println("Can't read classpath file " + i + ": " + classpath[i] + "."); - // System.exit(1); - // } - // } - long startTime = System.nanoTime(); TinyRemapper remapper = TinyRemapper.newRemapper() From 338761c7773edc24776e12fdc6ff44ff1a3689cc Mon Sep 17 00:00:00 2001 From: Nino Maruszewski Date: Sun, 13 Jun 2021 21:18:29 -0500 Subject: [PATCH 10/44] Add validation and runner method --- .../java/net/fabricmc/tinyremapper/Main.java | 51 +++++++++++++++---- 1 file changed, 41 insertions(+), 10 deletions(-) diff --git a/src/main/java/net/fabricmc/tinyremapper/Main.java b/src/main/java/net/fabricmc/tinyremapper/Main.java index 0fdd435..8926e98 100644 --- a/src/main/java/net/fabricmc/tinyremapper/Main.java +++ b/src/main/java/net/fabricmc/tinyremapper/Main.java @@ -114,12 +114,17 @@ private void setMappings(Path value) { // Classpath Path[] classpath; + /** + * Set the classpath variable and validate. + * + * @param value input paths from the user + */ @Parameters(index = "5..*", description = "Additional files to add to the classpath.") private void setClasspath(Path[] value) { classpath = new Path[value.length]; for (int i = 0; i < value.length; i++) { classpath[i] = value[i]; - if (!Files.isReadable(value[i]) { + if (!Files.isReadable(value[i])) { throw new ParameterException(spec.commandLine(), "Cannot read classpath file " + value[i] + "."); } @@ -278,21 +283,30 @@ private void setNonClassCopyMode(String value) { + "Defaults to the number of CPU cores available.") int threads = -1; - public static void main(String[] rawArgs) { - List args = new ArrayList(rawArgs.length); - + /** + * The main function of the CLI. + * + * @return exit code + */ + public Integer call() throws Exception { long startTime = System.nanoTime(); TinyRemapper remapper = TinyRemapper.newRemapper() - .withMappings(TinyUtils.createTinyMappingProvider(mappings, fromM, toM)) - .ignoreFieldDesc(ignoreFieldDesc).withForcedPropagation(forcePropagation) - .propagatePrivate(propagatePrivate).propagateBridges(propagateBridges) + .withMappings(TinyUtils.createTinyMappingProvider(mappings, fromMapping, toMapping)) + .ignoreFieldDesc(ignoreFieldDesc) + .withForcedPropagation(forcePropagation) + .propagatePrivate(propagatePrivate) + .propagateBridges(propagateBridges) .removeFrames(removeFrames) - .ignoreConflicts(ignoreConflicts).checkPackageAccess(checkPackageAccess) - .fixPackageAccess(fixPackageAccess).resolveMissing(resolveMissing) + .ignoreConflicts(ignoreConflicts) + .checkPackageAccess(checkPackageAccess) + .fixPackageAccess(fixPackageAccess) + .resolveMissing(resolveMissing) .rebuildSourceFilenames(rebuildSourceFilenames) .skipLocalVariableMapping(skipLocalVariableMapping) - .renameInvalidLocals(renameInvalidLocals).threads(threads).build(); + .renameInvalidLocals(renameInvalidLocals) + .threads(threads) + .build(); try (OutputConsumerPath outputConsumer = new OutputConsumerPath.Builder(output).build()) { outputConsumer.addNonClassFiles(input, ncCopyMode, remapper); @@ -308,5 +322,22 @@ public static void main(String[] rawArgs) { } System.out.printf("Finished after %.2f ms.\n", (System.nanoTime() - startTime) / 1e6); + return 0; + } + + /** + * Validate some of the command line options using JSR-380. + */ + private void validate() { + Validator validator = Validation.buildDefaultValidatorFactory().getValidator(); + Set> violations = validator.validate(this); + + if (!violations.isEmpty()) { + String errorMsg = ""; + for (ConstraintViolation violation : violations) { + errorMsg += "ERROR: " + violation.getMessage() + "\n"; + } + throw new ParameterException(spec.commandLine(), errorMsg); + } } } From 5fb4b66d4de606562d6ab34a8ab07d4f1f742643 Mon Sep 17 00:00:00 2001 From: Nino Maruszewski Date: Sun, 13 Jun 2021 21:23:14 -0500 Subject: [PATCH 11/44] Make all instance variables private --- .../java/net/fabricmc/tinyremapper/Main.java | 54 +++++++++---------- 1 file changed, 27 insertions(+), 27 deletions(-) diff --git a/src/main/java/net/fabricmc/tinyremapper/Main.java b/src/main/java/net/fabricmc/tinyremapper/Main.java index 8926e98..76aceda 100644 --- a/src/main/java/net/fabricmc/tinyremapper/Main.java +++ b/src/main/java/net/fabricmc/tinyremapper/Main.java @@ -57,19 +57,20 @@ usageHelpAutoWidth = true) public class Main implements Callable { /* @formatter:on */ + public static String version = getClass().getPackage().getImplementationVersion(); /* * ================== PicoCLI stuff ===================== */ @Spec - CommandSpec spec; // injected by picocli + private CommandSpec spec; // injected by picocli /* * ================== Input parameters ================== */ // Input file - Path input; + private Path input; /** * Set the input path variable and validate. @@ -86,10 +87,10 @@ private void setInput(Path value) { } @Parameters(index = "1", description = "Path to output remapped file.", required = true) - Path output; + private Path output; // Mappings file - Path mappings; + private Path mappings; /** * Set the mappings path variable and validate. @@ -106,13 +107,13 @@ private void setMappings(Path value) { } @Parameters(index = "3", description = "Namespace to map from.", required = true) - String fromMapping; + private String fromMapping; @Parameters(index = "4", description = "Namespace to map to.", required = true) - String toMapping; + private String toMapping; // Classpath - Path[] classpath; + private Path[] classpath; /** * Set the classpath variable and validate. @@ -135,22 +136,21 @@ private void setClasspath(Path[] value) { * ================== Options and switches ============== */ @Option(names = {"-V", "--version"}, versionHelp = true, description = "Display version info") - boolean versionInfoRequested; - public static String version = getClass().getPackage().getImplementationVersion(); + private boolean versionInfoRequested; @Option(names = {"-h", "--help"}, usageHelp = true, description = "Display this help message") - boolean usageHelpRequested; + private boolean usageHelpRequested; @Option(names = "--reverse", description = "Reverse the mapping. @|bold,underline,yellow NOT YET IMPLEMENTED!|@") - boolean reverse = false; + private boolean reverse = false; @Option(names = "--ignore-field-desc", description = "Ignore the field descriptions in mappings.") - boolean ignoreFieldDesc = false; + private boolean ignoreFieldDesc = false; // Force propagation option - Set forcePropagation = Collections.emptySet(); + private Set forcePropagation = Collections.emptySet(); /** * Set the forcePropagation variable and validate. @@ -159,7 +159,7 @@ private void setClasspath(Path[] value) { */ @Option(names = "--force-propagation", description = "A file with methods to force propagation to.") - public void setForcePropagation(File forcePropagationFile) { + private void setForcePropagation(File forcePropagationFile) { if (forcePropagationFile != null) { forcePropagation = new HashSet<>(); @@ -190,10 +190,10 @@ public void setForcePropagation(File forcePropagationFile) { @Option(names = "--propagate-private", description = "Propagate mappings to private methods.") - boolean propagatePrivate = false; + private boolean propagatePrivate = false; // Propagate bridges option - LinkedMethodPropagation propagateBridges = LinkedMethodPropagation.DISABLED; + private LinkedMethodPropagation propagateBridges = LinkedMethodPropagation.DISABLED; /** * Set the propagateBridges variable and validate. @@ -203,7 +203,7 @@ public void setForcePropagation(File forcePropagationFile) { @Option(names = "propagate-bridges", description = "Propagate methods to bridge methods. " + "Must be one of \"disabled\", \"enabled\", or \"compatible\".") - public void setPropagateBridges(String value) { + private void setPropagateBridges(String value) { switch (value.toLowerCase(Locale.ENGLISH)) { case "disabled": propagateBridges = LinkedMethodPropagation.DISABLED; @@ -222,35 +222,35 @@ public void setPropagateBridges(String value) { @Option(names = "--remove-frames", description = "Ignore the StackMap and StackMapTable frames.") - boolean removeFrames = false; + private boolean removeFrames = false; @Option(names = "--ignore-conflicts", description = "Ignore any mapping conflicts.") - boolean ignoreConflicts = false; + private boolean ignoreConflicts = false; @Option(names = "--check-package-access", description = "Check package access.") - boolean checkPackageAccess = false; + private boolean checkPackageAccess = false; @Option(names = "--fix-package-access", description = "Fix package access. Implies \"--fix-package-access\".") - boolean fixPackageAccess = false; + private boolean fixPackageAccess = false; @Option(names = "--resolve-missing", description = "Resolve missing methods.") - boolean resolveMissing = false; + private boolean resolveMissing = false; @Option(names = "--rebuild-source-filenames", description = "Rebuild the filenames of sources.") - boolean rebuildSourceFilenames = false; + private boolean rebuildSourceFilenames = false; @Option(names = "--skip-local-variable-mapping", description = "Skip remapping local variables") - boolean skipLocalVariableMapping = false; + private boolean skipLocalVariableMapping = false; @Option(names = "--rename-invalid-locals", description = "Rename invalid local variables.") - boolean renameInvalidLocals = false; + private boolean renameInvalidLocals = false; // Non-class file copy mode option - NonClassCopyMode ncCopyMode = NonClassCopyMode.FIX_META_INF; + private NonClassCopyMode ncCopyMode = NonClassCopyMode.FIX_META_INF; /** * Set the setNonClassCopyMode variable and validate. @@ -281,7 +281,7 @@ private void setNonClassCopyMode(String value) { @Option(names = "--threads", description = "Number of threads to use while remapping. " + "Defaults to the number of CPU cores available.") - int threads = -1; + private int threads = -1; /** * The main function of the CLI. From 022860f98c16bc7757af15748c60432c35c8906d Mon Sep 17 00:00:00 2001 From: Nino Maruszewski Date: Sun, 13 Jun 2021 21:26:03 -0500 Subject: [PATCH 12/44] Add main runner script --- src/main/java/net/fabricmc/tinyremapper/Main.java | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/main/java/net/fabricmc/tinyremapper/Main.java b/src/main/java/net/fabricmc/tinyremapper/Main.java index 76aceda..1617033 100644 --- a/src/main/java/net/fabricmc/tinyremapper/Main.java +++ b/src/main/java/net/fabricmc/tinyremapper/Main.java @@ -340,4 +340,14 @@ private void validate() { throw new ParameterException(spec.commandLine(), errorMsg); } } + + /** + * Main runner function. + * + * @param args args from the user + */ + public static void main(String... args) { + int exitCode = new CommandLine(new Main()).execute(args); + System.exit(exitCode); + } } From b6bb68f061cd8cbdd7e686b84b77f833666a11eb Mon Sep 17 00:00:00 2001 From: Nino Maruszewski Date: Sun, 13 Jun 2021 21:32:36 -0500 Subject: [PATCH 13/44] `javax.validation` is not included by default --- .../java/net/fabricmc/tinyremapper/Main.java | 50 +++++++++++-------- 1 file changed, 29 insertions(+), 21 deletions(-) diff --git a/src/main/java/net/fabricmc/tinyremapper/Main.java b/src/main/java/net/fabricmc/tinyremapper/Main.java index 1617033..24d9d33 100644 --- a/src/main/java/net/fabricmc/tinyremapper/Main.java +++ b/src/main/java/net/fabricmc/tinyremapper/Main.java @@ -32,10 +32,10 @@ import java.util.Locale; import java.util.Set; import java.util.concurrent.Callable; -import javax.validation.ConstraintViolation; -import javax.validation.Validation; -import javax.validation.Validator; -import javax.validation.constraints.Min; +// import javax.validation.ConstraintViolation; +// import javax.validation.Validation; +// import javax.validation.Validator; +// import javax.validation.constraints.Min; import net.fabricmc.tinyremapper.TinyRemapper.LinkedMethodPropagation; import picocli.CommandLine; @@ -277,11 +277,19 @@ private void setNonClassCopyMode(String value) { } } - @Min(value = 1, message = "Thread count must be greater than 0.") + // Threads option + private int threads = -1; + + // @Min(value = 1, message = "Thread count must be greater than 0.") @Option(names = "--threads", description = "Number of threads to use while remapping. " + "Defaults to the number of CPU cores available.") - private int threads = -1; + private static void setThreads(int input) { + if (input <= 0) { + throw new ParameterException(spec.commandLine(), "Threads must be greater than 0."); + } + threads = input; + } /** * The main function of the CLI. @@ -325,21 +333,21 @@ public Integer call() throws Exception { return 0; } - /** - * Validate some of the command line options using JSR-380. - */ - private void validate() { - Validator validator = Validation.buildDefaultValidatorFactory().getValidator(); - Set> violations = validator.validate(this); - - if (!violations.isEmpty()) { - String errorMsg = ""; - for (ConstraintViolation violation : violations) { - errorMsg += "ERROR: " + violation.getMessage() + "\n"; - } - throw new ParameterException(spec.commandLine(), errorMsg); - } - } + // /** + // * Validate some of the command line options using JSR-380. + // */ + // private void validate() { + // Validator validator = Validation.buildDefaultValidatorFactory().getValidator(); + // Set> violations = validator.validate(this); + + // if (!violations.isEmpty()) { + // String errorMsg = ""; + // for (ConstraintViolation violation : violations) { + // errorMsg += "ERROR: " + violation.getMessage() + "\n"; + // } + // throw new ParameterException(spec.commandLine(), errorMsg); + // } + // } /** * Main runner function. From 5ad6c477ffa39da5e49441dd19936030c3235e7f Mon Sep 17 00:00:00 2001 From: Nino Maruszewski Date: Sun, 13 Jun 2021 21:33:22 -0500 Subject: [PATCH 14/44] Fix version detection --- src/main/java/net/fabricmc/tinyremapper/Main.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/net/fabricmc/tinyremapper/Main.java b/src/main/java/net/fabricmc/tinyremapper/Main.java index 24d9d33..e83010e 100644 --- a/src/main/java/net/fabricmc/tinyremapper/Main.java +++ b/src/main/java/net/fabricmc/tinyremapper/Main.java @@ -57,7 +57,7 @@ usageHelpAutoWidth = true) public class Main implements Callable { /* @formatter:on */ - public static String version = getClass().getPackage().getImplementationVersion(); + public static String version = Main.class.getPackage().getImplementationVersion(); /* * ================== PicoCLI stuff ===================== From a544f60d470434e7230e7a9027240d94dc7c2ba4 Mon Sep 17 00:00:00 2001 From: Nino Maruszewski Date: Sun, 13 Jun 2021 21:35:13 -0500 Subject: [PATCH 15/44] Fix thread setter --- src/main/java/net/fabricmc/tinyremapper/Main.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/net/fabricmc/tinyremapper/Main.java b/src/main/java/net/fabricmc/tinyremapper/Main.java index e83010e..4591f61 100644 --- a/src/main/java/net/fabricmc/tinyremapper/Main.java +++ b/src/main/java/net/fabricmc/tinyremapper/Main.java @@ -284,7 +284,7 @@ private void setNonClassCopyMode(String value) { @Option(names = "--threads", description = "Number of threads to use while remapping. " + "Defaults to the number of CPU cores available.") - private static void setThreads(int input) { + private void setThreads(int input) { if (input <= 0) { throw new ParameterException(spec.commandLine(), "Threads must be greater than 0."); } From 702c63c3bc32c3e201974bfa13d94ff356610e74 Mon Sep 17 00:00:00 2001 From: Nino Maruszewski Date: Sun, 13 Jun 2021 21:43:19 -0500 Subject: [PATCH 16/44] Version detection again and spec field --- src/main/java/net/fabricmc/tinyremapper/Main.java | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/main/java/net/fabricmc/tinyremapper/Main.java b/src/main/java/net/fabricmc/tinyremapper/Main.java index 4591f61..99171b7 100644 --- a/src/main/java/net/fabricmc/tinyremapper/Main.java +++ b/src/main/java/net/fabricmc/tinyremapper/Main.java @@ -45,11 +45,12 @@ import picocli.CommandLine.Option; import picocli.CommandLine.ParameterException; import picocli.CommandLine.Parameters; +import picocli.CommandLine.Spec; /* @formatter:off - eclipse formatter doesn't seem to like annotations */ @Command(name = "tiny-remapper", mixinStandardHelpOptions = true, version = { - "Tiny Remapper " + Main.version == null ? "DEVELOP" : Main.version, + "Tiny Remapper " + "0.4.1", "Picocli " + picocli.CommandLine.VERSION, "JVM: ${java.version} (${java.vendor} ${java.vm.name} ${java.vm.version})", "OS: ${os.name} ${os.version} ${os.arch}"}, @@ -57,13 +58,11 @@ usageHelpAutoWidth = true) public class Main implements Callable { /* @formatter:on */ - public static String version = Main.class.getPackage().getImplementationVersion(); /* * ================== PicoCLI stuff ===================== */ - @Spec - private CommandSpec spec; // injected by picocli + @Spec CommandSpec spec; // injected by picocli /* * ================== Input parameters ================== From d3616166d31b1d01aad232300750e03d2f6c8d81 Mon Sep 17 00:00:00 2001 From: Nino Maruszewski Date: Sun, 13 Jun 2021 21:45:38 -0500 Subject: [PATCH 17/44] Remove duplicate stuff - Version and help is already provided - Parameters are required by default --- .../java/net/fabricmc/tinyremapper/Main.java | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-) diff --git a/src/main/java/net/fabricmc/tinyremapper/Main.java b/src/main/java/net/fabricmc/tinyremapper/Main.java index 99171b7..8ed44e2 100644 --- a/src/main/java/net/fabricmc/tinyremapper/Main.java +++ b/src/main/java/net/fabricmc/tinyremapper/Main.java @@ -76,7 +76,7 @@ public class Main implements Callable { * * @param value input path from the user */ - @Parameters(index = "0", description = "Path to input file to remap.", required = true) + @Parameters(index = "0", description = "Path to input file to remap.") private void setInput(Path value) { if (!Files.isReadable(input)) { throw new ParameterException(spec.commandLine(), @@ -85,7 +85,7 @@ private void setInput(Path value) { input = value; } - @Parameters(index = "1", description = "Path to output remapped file.", required = true) + @Parameters(index = "1", description = "Path to output remapped file.") private Path output; // Mappings file @@ -96,7 +96,7 @@ private void setInput(Path value) { * * @param value input path from the user */ - @Parameters(index = "2", description = "Path to mappings file.", required = true) + @Parameters(index = "2", description = "Path to mappings file.") private void setMappings(Path value) { if (!Files.isReadable(input)) { throw new ParameterException(spec.commandLine(), @@ -105,10 +105,10 @@ private void setMappings(Path value) { mappings = value; } - @Parameters(index = "3", description = "Namespace to map from.", required = true) + @Parameters(index = "3", description = "Namespace to map from.") private String fromMapping; - @Parameters(index = "4", description = "Namespace to map to.", required = true) + @Parameters(index = "4", description = "Namespace to map to.") private String toMapping; // Classpath @@ -134,12 +134,6 @@ private void setClasspath(Path[] value) { /* * ================== Options and switches ============== */ - @Option(names = {"-V", "--version"}, versionHelp = true, description = "Display version info") - private boolean versionInfoRequested; - - @Option(names = {"-h", "--help"}, usageHelp = true, description = "Display this help message") - private boolean usageHelpRequested; - @Option(names = "--reverse", description = "Reverse the mapping. @|bold,underline,yellow NOT YET IMPLEMENTED!|@") private boolean reverse = false; From cb8459c897aaedd2a376268e5080f03d11f62e6a Mon Sep 17 00:00:00 2001 From: Nino Maruszewski Date: Wed, 16 Jun 2021 13:24:59 -0500 Subject: [PATCH 18/44] Make a fat jar --- build.gradle | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/build.gradle b/build.gradle index d467195..24e2735 100644 --- a/build.gradle +++ b/build.gradle @@ -2,6 +2,7 @@ plugins { id "java" id "maven-publish" id "com.diffplug.spotless" version "5.10.2" + id 'com.github.johnrengelman.shadow' version '7.0.0' // Make a fat jar // TODO: Apply checkstyle } @@ -82,6 +83,11 @@ jar { } } +shadowJar { + archiveClassifier.set("fat") +} +build.dependsOn shadowJar + publishing { publications { mavenJava(MavenPublication) { From d7b79bffcc3d751edbcb97282c557826919d32d1 Mon Sep 17 00:00:00 2001 From: Nino Maruszewski Date: Wed, 16 Jun 2021 13:25:56 -0500 Subject: [PATCH 19/44] Fix typo --- src/main/java/net/fabricmc/tinyremapper/Main.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/net/fabricmc/tinyremapper/Main.java b/src/main/java/net/fabricmc/tinyremapper/Main.java index 8ed44e2..67535b4 100644 --- a/src/main/java/net/fabricmc/tinyremapper/Main.java +++ b/src/main/java/net/fabricmc/tinyremapper/Main.java @@ -193,7 +193,7 @@ private void setForcePropagation(File forcePropagationFile) { * * @param value input from the user */ - @Option(names = "propagate-bridges", + @Option(names = "--propagate-bridges", description = "Propagate methods to bridge methods. " + "Must be one of \"disabled\", \"enabled\", or \"compatible\".") private void setPropagateBridges(String value) { From af65219eab1c5562ba6216ffc6bbc867318e85b9 Mon Sep 17 00:00:00 2001 From: Nino Maruszewski Date: Wed, 16 Jun 2021 13:45:14 -0500 Subject: [PATCH 20/44] Fix colors on Windows --- build.gradle | 3 +++ src/main/java/net/fabricmc/tinyremapper/Main.java | 7 +++++-- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/build.gradle b/build.gradle index 24e2735..7d11620 100644 --- a/build.gradle +++ b/build.gradle @@ -35,6 +35,9 @@ dependencies { implementation "info.picocli:picocli:$picocliVersion" annotationProcessor "info.picocli:picocli-codegen:$picocliVersion" + + implementation group: "org.fusesource.jansi", name: "jansi", version: "2.3.3" + implementation "info.picocli:picocli-jansi-graalvm:1.2.0" } compileJava { diff --git a/src/main/java/net/fabricmc/tinyremapper/Main.java b/src/main/java/net/fabricmc/tinyremapper/Main.java index 67535b4..34d3a80 100644 --- a/src/main/java/net/fabricmc/tinyremapper/Main.java +++ b/src/main/java/net/fabricmc/tinyremapper/Main.java @@ -46,7 +46,7 @@ import picocli.CommandLine.ParameterException; import picocli.CommandLine.Parameters; import picocli.CommandLine.Spec; - +import picocli.jansi.graalvm.AnsiConsole; /* @formatter:off - eclipse formatter doesn't seem to like annotations */ @Command(name = "tiny-remapper", mixinStandardHelpOptions = true, version = { @@ -348,7 +348,10 @@ public Integer call() throws Exception { * @param args args from the user */ public static void main(String... args) { - int exitCode = new CommandLine(new Main()).execute(args); + int exitCode; + try (AnsiConsole ansi = AnsiConsole.windowsInstall()) { + exitCode = new CommandLine(new Main()).execute(args); + } System.exit(exitCode); } } From fd6dadef5b694cc194da3d72592c80abfb520484 Mon Sep 17 00:00:00 2001 From: Nino Maruszewski Date: Wed, 16 Jun 2021 13:45:31 -0500 Subject: [PATCH 21/44] Fat jar replaces application plugin --- build.gradle | 1 - 1 file changed, 1 deletion(-) diff --git a/build.gradle b/build.gradle index 7d11620..f37793e 100644 --- a/build.gradle +++ b/build.gradle @@ -80,7 +80,6 @@ jar { manifest { attributes "Implementation-Title": "TinyRemapper", "Implementation-Version": archiveVersion, - // TODO: Move to application plugin instead of placing this in the manifest directly "Main-Class": "net.fabricmc.tinyremapper.Main", "Automatic-Module-Name": "org.quiltmc.tinyremapper" } From 583317c53bc1d4bba82a26e4e067822021865930 Mon Sep 17 00:00:00 2001 From: Nino Maruszewski Date: Wed, 16 Jun 2021 13:57:21 -0500 Subject: [PATCH 22/44] Improve the version field Also made the `CommandSpec` private --- src/main/java/net/fabricmc/tinyremapper/Main.java | 7 +++++-- src/main/java/net/fabricmc/tinyremapper/TinyRemapper.java | 3 +++ 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/src/main/java/net/fabricmc/tinyremapper/Main.java b/src/main/java/net/fabricmc/tinyremapper/Main.java index 34d3a80..30e8a32 100644 --- a/src/main/java/net/fabricmc/tinyremapper/Main.java +++ b/src/main/java/net/fabricmc/tinyremapper/Main.java @@ -37,6 +37,7 @@ // import javax.validation.Validator; // import javax.validation.constraints.Min; +import net.fabricmc.tinyremapper.TinyRemapper; import net.fabricmc.tinyremapper.TinyRemapper.LinkedMethodPropagation; import picocli.CommandLine; import picocli.CommandLine.Command; @@ -50,7 +51,8 @@ /* @formatter:off - eclipse formatter doesn't seem to like annotations */ @Command(name = "tiny-remapper", mixinStandardHelpOptions = true, version = { - "Tiny Remapper " + "0.4.1", + "@|bold,underline Tiny Remapper " + TinyRemapper.VERSION + "|@", + "ASM " + "9.1", "Picocli " + picocli.CommandLine.VERSION, "JVM: ${java.version} (${java.vendor} ${java.vm.name} ${java.vm.version})", "OS: ${os.name} ${os.version} ${os.arch}"}, @@ -62,7 +64,8 @@ public class Main implements Callable { /* * ================== PicoCLI stuff ===================== */ - @Spec CommandSpec spec; // injected by picocli + @Spec + private CommandSpec spec; // injected by picocli /* * ================== Input parameters ================== diff --git a/src/main/java/net/fabricmc/tinyremapper/TinyRemapper.java b/src/main/java/net/fabricmc/tinyremapper/TinyRemapper.java index e7af245..59daae0 100644 --- a/src/main/java/net/fabricmc/tinyremapper/TinyRemapper.java +++ b/src/main/java/net/fabricmc/tinyremapper/TinyRemapper.java @@ -68,6 +68,9 @@ import net.fabricmc.tinyremapper.MemberInstance.MemberType; public class TinyRemapper { + // Version field + public static final String VERSION = "0.4.1"; + public static class Builder { private Builder() { } From e2efe8cdbc011f1688e25a5c086447f7ad3ec7c2 Mon Sep 17 00:00:00 2001 From: Nino Maruszewski Date: Wed, 16 Jun 2021 14:27:47 -0500 Subject: [PATCH 23/44] Add a footer and abbreviate the synopsis --- src/main/java/net/fabricmc/tinyremapper/Main.java | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/main/java/net/fabricmc/tinyremapper/Main.java b/src/main/java/net/fabricmc/tinyremapper/Main.java index 30e8a32..8bbbf22 100644 --- a/src/main/java/net/fabricmc/tinyremapper/Main.java +++ b/src/main/java/net/fabricmc/tinyremapper/Main.java @@ -56,8 +56,10 @@ "Picocli " + picocli.CommandLine.VERSION, "JVM: ${java.version} (${java.vendor} ${java.vm.name} ${java.vm.version})", "OS: ${os.name} ${os.version} ${os.arch}"}, - description = "A tool for remapping JAR files using \"Tiny\"-format mappings", - usageHelpAutoWidth = true) + description = "A tool for remapping JAR files using \"Tiny\"-format mappings.", + footer = {"%nCopyright (C) 2016, 2018 Player, asie; 2021 QuiltMC", + "Report bugs at ."}, + usageHelpAutoWidth = true, abbreviateSynopsis = true) public class Main implements Callable { /* @formatter:on */ From fcce21737ed9bb1c7afd9a8f914e90137defdd28 Mon Sep 17 00:00:00 2001 From: Nino Maruszewski Date: Wed, 16 Jun 2021 14:29:17 -0500 Subject: [PATCH 24/44] Remove the old verification stuff --- .../java/net/fabricmc/tinyremapper/Main.java | 20 ------------------- 1 file changed, 20 deletions(-) diff --git a/src/main/java/net/fabricmc/tinyremapper/Main.java b/src/main/java/net/fabricmc/tinyremapper/Main.java index 8bbbf22..a14a662 100644 --- a/src/main/java/net/fabricmc/tinyremapper/Main.java +++ b/src/main/java/net/fabricmc/tinyremapper/Main.java @@ -32,10 +32,6 @@ import java.util.Locale; import java.util.Set; import java.util.concurrent.Callable; -// import javax.validation.ConstraintViolation; -// import javax.validation.Validation; -// import javax.validation.Validator; -// import javax.validation.constraints.Min; import net.fabricmc.tinyremapper.TinyRemapper; import net.fabricmc.tinyremapper.TinyRemapper.LinkedMethodPropagation; @@ -331,22 +327,6 @@ public Integer call() throws Exception { return 0; } - // /** - // * Validate some of the command line options using JSR-380. - // */ - // private void validate() { - // Validator validator = Validation.buildDefaultValidatorFactory().getValidator(); - // Set> violations = validator.validate(this); - - // if (!violations.isEmpty()) { - // String errorMsg = ""; - // for (ConstraintViolation violation : violations) { - // errorMsg += "ERROR: " + violation.getMessage() + "\n"; - // } - // throw new ParameterException(spec.commandLine(), errorMsg); - // } - // } - /** * Main runner function. * From 096ea79a53f4002a9d3d73b4d7c44b19344aa1de Mon Sep 17 00:00:00 2001 From: Nino Maruszewski Date: Wed, 16 Jun 2021 14:40:18 -0500 Subject: [PATCH 25/44] Add man page generation --- build.gradle | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/build.gradle b/build.gradle index f37793e..ed00ab0 100644 --- a/build.gradle +++ b/build.gradle @@ -3,6 +3,7 @@ plugins { id "maven-publish" id "com.diffplug.spotless" version "5.10.2" id 'com.github.johnrengelman.shadow' version '7.0.0' // Make a fat jar + id 'org.asciidoctor.jvm.convert' version '3.1.0' // Make man pages // TODO: Apply checkstyle } @@ -109,3 +110,23 @@ publishing { } } } + +// Manpage generator (included with PicoCLI) +task generateManpageAsciiDoc(type: JavaExec) { + dependsOn(classes) + group = "Documentation" + description = "Generate AsciiDoc manpage" + classpath(configurations.runtimeClasspath, configurations.annotationProcessor, sourceSets.main.runtimeClasspath) + main 'picocli.codegen.docgen.manpage.ManPageGenerator' + args "net.fabricmc.tinyremapper.Main", "--outdir=${project.buildDir}/generated-picocli-docs", "-v" //, "--template-dir=src/docs/mantemplates" +} + +asciidoctor { + dependsOn(generateManpageAsciiDoc) + sourceDir = file("${project.buildDir}/generated-picocli-docs") + outputDir = file("${project.buildDir}/docs") + logDocuments = true + outputOptions { + backends = ['manpage', 'html5'] + } +} From 6d88db6a46cb1dfe183a26d387aab6346eda571d Mon Sep 17 00:00:00 2001 From: Nino Maruszewski Date: Wed, 16 Jun 2021 14:51:04 -0500 Subject: [PATCH 26/44] Add some short switches --- .../java/net/fabricmc/tinyremapper/Main.java | 32 +++++++++---------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/src/main/java/net/fabricmc/tinyremapper/Main.java b/src/main/java/net/fabricmc/tinyremapper/Main.java index a14a662..e7ff2a8 100644 --- a/src/main/java/net/fabricmc/tinyremapper/Main.java +++ b/src/main/java/net/fabricmc/tinyremapper/Main.java @@ -135,11 +135,11 @@ private void setClasspath(Path[] value) { /* * ================== Options and switches ============== */ - @Option(names = "--reverse", + @Option(names = {"-R", "--reverse"}, description = "Reverse the mapping. @|bold,underline,yellow NOT YET IMPLEMENTED!|@") private boolean reverse = false; - @Option(names = "--ignore-field-desc", + @Option(names = {"-i", "--ignore-field-desc"}, description = "Ignore the field descriptions in mappings.") private boolean ignoreFieldDesc = false; @@ -151,7 +151,7 @@ private void setClasspath(Path[] value) { * * @param forcePropagationFile input file from the user */ - @Option(names = "--force-propagation", + @Option(names = {"-f", "--force-propagation"}, description = "A file with methods to force propagation to.") private void setForcePropagation(File forcePropagationFile) { if (forcePropagationFile != null) { @@ -182,7 +182,7 @@ private void setForcePropagation(File forcePropagationFile) { } } - @Option(names = "--propagate-private", + @Option(names = {"-p", "--propagate-private"}, description = "Propagate mappings to private methods.") private boolean propagatePrivate = false; @@ -194,7 +194,7 @@ private void setForcePropagation(File forcePropagationFile) { * * @param value input from the user */ - @Option(names = "--propagate-bridges", + @Option(names = {"-b", "--propagate-bridges"}, description = "Propagate methods to bridge methods. " + "Must be one of \"disabled\", \"enabled\", or \"compatible\".") private void setPropagateBridges(String value) { @@ -218,29 +218,29 @@ private void setPropagateBridges(String value) { description = "Ignore the StackMap and StackMapTable frames.") private boolean removeFrames = false; - @Option(names = "--ignore-conflicts", + @Option(names = {"-I", "--ignore-conflicts"}, description = "Ignore any mapping conflicts.") private boolean ignoreConflicts = false; - @Option(names = "--check-package-access", + @Option(names = {"-C", "--check-package-access"}, description = "Check package access.") private boolean checkPackageAccess = false; - @Option(names = "--fix-package-access", - description = "Fix package access. Implies \"--fix-package-access\".") + @Option(names = {"-F", "--fix-package-access"}, + description = "Fix package access. Implies \"--check-package-access\".") private boolean fixPackageAccess = false; - @Option(names = "--resolve-missing", description = "Resolve missing methods.") + @Option(names = {"-m", "--resolve-missing"}, description = "Resolve missing methods.") private boolean resolveMissing = false; - @Option(names = "--rebuild-source-filenames", + @Option(names = {"-r", "--rebuild-source-filenames"}, description = "Rebuild the filenames of sources.") private boolean rebuildSourceFilenames = false; - @Option(names = "--skip-local-variable-mapping", description = "Skip remapping local variables") + @Option(names = {"-l", "--skip-local-variable-mapping"}, description = "Skip remapping local variables") private boolean skipLocalVariableMapping = false; - @Option(names = "--rename-invalid-locals", description = "Rename invalid local variables.") + @Option(names = {"-L", "--rename-invalid-locals"}, description = "Rename invalid local variables.") private boolean renameInvalidLocals = false; // Non-class file copy mode option @@ -251,8 +251,8 @@ private void setPropagateBridges(String value) { * * @param value input from the user */ - @Option(names = "--non-class-copy-mode", - description = "How to deal with non-class files in a JAR. " + @Option(names = {"-M", "--non-class-copy-mode"}, + description = "How to deal with non-class files in a JAR (i.e. META-INF). " + "Must be one of \"unchanged\", \"fixmeta\", or \"skipmeta\".") private void setNonClassCopyMode(String value) { switch (value.toLowerCase(Locale.ENGLISH)) { @@ -275,7 +275,7 @@ private void setNonClassCopyMode(String value) { private int threads = -1; // @Min(value = 1, message = "Thread count must be greater than 0.") - @Option(names = "--threads", + @Option(names = {"-t", "--threads"}, description = "Number of threads to use while remapping. " + "Defaults to the number of CPU cores available.") private void setThreads(int input) { From a522bc043f3de54065be74458140a84ecd0799c9 Mon Sep 17 00:00:00 2001 From: Nino Maruszewski Date: Wed, 16 Jun 2021 14:52:33 -0500 Subject: [PATCH 27/44] Booleans are false by default --- .../java/net/fabricmc/tinyremapper/Main.java | 28 ++++++++++--------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/src/main/java/net/fabricmc/tinyremapper/Main.java b/src/main/java/net/fabricmc/tinyremapper/Main.java index e7ff2a8..b9ca74d 100644 --- a/src/main/java/net/fabricmc/tinyremapper/Main.java +++ b/src/main/java/net/fabricmc/tinyremapper/Main.java @@ -137,11 +137,11 @@ private void setClasspath(Path[] value) { */ @Option(names = {"-R", "--reverse"}, description = "Reverse the mapping. @|bold,underline,yellow NOT YET IMPLEMENTED!|@") - private boolean reverse = false; + private boolean reverse; @Option(names = {"-i", "--ignore-field-desc"}, description = "Ignore the field descriptions in mappings.") - private boolean ignoreFieldDesc = false; + private boolean ignoreFieldDesc; // Force propagation option private Set forcePropagation = Collections.emptySet(); @@ -184,7 +184,7 @@ private void setForcePropagation(File forcePropagationFile) { @Option(names = {"-p", "--propagate-private"}, description = "Propagate mappings to private methods.") - private boolean propagatePrivate = false; + private boolean propagatePrivate; // Propagate bridges option private LinkedMethodPropagation propagateBridges = LinkedMethodPropagation.DISABLED; @@ -216,32 +216,34 @@ private void setPropagateBridges(String value) { @Option(names = "--remove-frames", description = "Ignore the StackMap and StackMapTable frames.") - private boolean removeFrames = false; + private boolean removeFrames; @Option(names = {"-I", "--ignore-conflicts"}, description = "Ignore any mapping conflicts.") - private boolean ignoreConflicts = false; + private boolean ignoreConflicts; @Option(names = {"-C", "--check-package-access"}, description = "Check package access.") - private boolean checkPackageAccess = false; + private boolean checkPackageAccess; @Option(names = {"-F", "--fix-package-access"}, description = "Fix package access. Implies \"--check-package-access\".") - private boolean fixPackageAccess = false; + private boolean fixPackageAccess; @Option(names = {"-m", "--resolve-missing"}, description = "Resolve missing methods.") - private boolean resolveMissing = false; + private boolean resolveMissing; @Option(names = {"-r", "--rebuild-source-filenames"}, description = "Rebuild the filenames of sources.") - private boolean rebuildSourceFilenames = false; + private boolean rebuildSourceFilenames; - @Option(names = {"-l", "--skip-local-variable-mapping"}, description = "Skip remapping local variables") - private boolean skipLocalVariableMapping = false; + @Option(names = {"-l", "--skip-local-variable-mapping"}, + description = "Skip remapping local variables") + private boolean skipLocalVariableMapping; - @Option(names = {"-L", "--rename-invalid-locals"}, description = "Rename invalid local variables.") - private boolean renameInvalidLocals = false; + @Option(names = {"-L", "--rename-invalid-locals"}, + description = "Rename invalid local variables.") + private boolean renameInvalidLocals; // Non-class file copy mode option private NonClassCopyMode ncCopyMode = NonClassCopyMode.FIX_META_INF; From c2e9af1caf2cf3a8ed39a2b8898bb3b7466d7fb5 Mon Sep 17 00:00:00 2001 From: Nino Maruszewski Date: Wed, 16 Jun 2021 14:56:21 -0500 Subject: [PATCH 28/44] Add `v` in front of version (i.e. `ASM v9.1`) --- src/main/java/net/fabricmc/tinyremapper/Main.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/main/java/net/fabricmc/tinyremapper/Main.java b/src/main/java/net/fabricmc/tinyremapper/Main.java index b9ca74d..7923d7f 100644 --- a/src/main/java/net/fabricmc/tinyremapper/Main.java +++ b/src/main/java/net/fabricmc/tinyremapper/Main.java @@ -47,9 +47,9 @@ /* @formatter:off - eclipse formatter doesn't seem to like annotations */ @Command(name = "tiny-remapper", mixinStandardHelpOptions = true, version = { - "@|bold,underline Tiny Remapper " + TinyRemapper.VERSION + "|@", - "ASM " + "9.1", - "Picocli " + picocli.CommandLine.VERSION, + "@|bold,underline Tiny Remapper v" + TinyRemapper.VERSION + "|@", + "ASM v" + "9.1", + "Picocli v" + picocli.CommandLine.VERSION, "JVM: ${java.version} (${java.vendor} ${java.vm.name} ${java.vm.version})", "OS: ${os.name} ${os.version} ${os.arch}"}, description = "A tool for remapping JAR files using \"Tiny\"-format mappings.", From 780e182b1d41f6d45f3d6f05db7927e18a70eb42 Mon Sep 17 00:00:00 2001 From: Nino Maruszewski Date: Thu, 17 Jun 2021 11:02:25 -0500 Subject: [PATCH 29/44] Use blossom ffor version field --- build.gradle | 15 ++++++++++----- gradle.properties | 2 ++ src/main/java/net/fabricmc/tinyremapper/Main.java | 9 ++++++--- .../net/fabricmc/tinyremapper/TinyRemapper.java | 3 --- 4 files changed, 18 insertions(+), 11 deletions(-) create mode 100644 gradle.properties diff --git a/build.gradle b/build.gradle index ed00ab0..9dbb25a 100644 --- a/build.gradle +++ b/build.gradle @@ -3,7 +3,8 @@ plugins { id "maven-publish" id "com.diffplug.spotless" version "5.10.2" id 'com.github.johnrengelman.shadow' version '7.0.0' // Make a fat jar - id 'org.asciidoctor.jvm.convert' version '3.1.0' // Make man pages + id 'org.asciidoctor.jvm.convert' version '3.1.0' // Make man pages + id 'net.kyori.blossom' version '1.2.0' // Better version (again) // TODO: Apply checkstyle } @@ -23,17 +24,16 @@ repositories { } dependencies { - def asmVersion = "9.1" - + // ASM implementation "org.ow2.asm:asm:$asmVersion" implementation "org.ow2.asm:asm-commons:$asmVersion" implementation "org.ow2.asm:asm-tree:$asmVersion" implementation "org.ow2.asm:asm-util:$asmVersion" + + // Testing testImplementation 'org.junit.jupiter:junit-jupiter:5.6.2' // CLI tool - def picocliVersion = "4.6.1" - implementation "info.picocli:picocli:$picocliVersion" annotationProcessor "info.picocli:picocli-codegen:$picocliVersion" @@ -68,6 +68,11 @@ spotless { } } +blossom { + replaceToken("__TINY_VERSION", project.version) + replaceToken("__ASM_VERSION", asmVersion) +} + test { useJUnitPlatform() testLogging { diff --git a/gradle.properties b/gradle.properties new file mode 100644 index 0000000..20b8f75 --- /dev/null +++ b/gradle.properties @@ -0,0 +1,2 @@ +asmVersion = 9.1 +picocliVersion = 4.6.1 diff --git a/src/main/java/net/fabricmc/tinyremapper/Main.java b/src/main/java/net/fabricmc/tinyremapper/Main.java index 7923d7f..063cc14 100644 --- a/src/main/java/net/fabricmc/tinyremapper/Main.java +++ b/src/main/java/net/fabricmc/tinyremapper/Main.java @@ -33,7 +33,6 @@ import java.util.Set; import java.util.concurrent.Callable; -import net.fabricmc.tinyremapper.TinyRemapper; import net.fabricmc.tinyremapper.TinyRemapper.LinkedMethodPropagation; import picocli.CommandLine; import picocli.CommandLine.Command; @@ -47,8 +46,8 @@ /* @formatter:off - eclipse formatter doesn't seem to like annotations */ @Command(name = "tiny-remapper", mixinStandardHelpOptions = true, version = { - "@|bold,underline Tiny Remapper v" + TinyRemapper.VERSION + "|@", - "ASM v" + "9.1", + "@|bold,underline Tiny Remapper v" + Main.VERSION + "|@", + "ASM v" + Main.ASM_VERSION, "Picocli v" + picocli.CommandLine.VERSION, "JVM: ${java.version} (${java.vendor} ${java.vm.name} ${java.vm.version})", "OS: ${os.name} ${os.version} ${os.arch}"}, @@ -59,6 +58,10 @@ public class Main implements Callable { /* @formatter:on */ + // Version info - done by blossom + public static final String VERSION = "__TINY_VERSION"; + public static final String ASM_VERSION = "__ASM_VERSION"; + /* * ================== PicoCLI stuff ===================== */ diff --git a/src/main/java/net/fabricmc/tinyremapper/TinyRemapper.java b/src/main/java/net/fabricmc/tinyremapper/TinyRemapper.java index 59daae0..e7af245 100644 --- a/src/main/java/net/fabricmc/tinyremapper/TinyRemapper.java +++ b/src/main/java/net/fabricmc/tinyremapper/TinyRemapper.java @@ -68,9 +68,6 @@ import net.fabricmc.tinyremapper.MemberInstance.MemberType; public class TinyRemapper { - // Version field - public static final String VERSION = "0.4.1"; - public static class Builder { private Builder() { } From 7528d1377022d5511a28c53bd90297f0ec8d45f4 Mon Sep 17 00:00:00 2001 From: Nino Maruszewski Date: Thu, 17 Jun 2021 11:05:24 -0500 Subject: [PATCH 30/44] Format build.dependsOn --- build.gradle | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/build.gradle b/build.gradle index 9dbb25a..52e6de4 100644 --- a/build.gradle +++ b/build.gradle @@ -94,7 +94,12 @@ jar { shadowJar { archiveClassifier.set("fat") } -build.dependsOn shadowJar + +build { + dependsOn { + shadowJar + } +} publishing { publications { From 49759e63c55af473bca67dbda1329162ddcbb039 Mon Sep 17 00:00:00 2001 From: Nino Maruszewski Date: Thu, 17 Jun 2021 11:47:44 -0500 Subject: [PATCH 31/44] Debugging pt. 1 --- .../java/net/fabricmc/tinyremapper/Main.java | 29 ++++++++++--------- 1 file changed, 16 insertions(+), 13 deletions(-) diff --git a/src/main/java/net/fabricmc/tinyremapper/Main.java b/src/main/java/net/fabricmc/tinyremapper/Main.java index 063cc14..915a246 100644 --- a/src/main/java/net/fabricmc/tinyremapper/Main.java +++ b/src/main/java/net/fabricmc/tinyremapper/Main.java @@ -73,24 +73,24 @@ public class Main implements Callable { */ // Input file - private Path input; + private Path inputFile; /** - * Set the input path variable and validate. + * Set the input file path variable and validate. * * @param value input path from the user */ @Parameters(index = "0", description = "Path to input file to remap.") - private void setInput(Path value) { - if (!Files.isReadable(input)) { + private void setInputFile(Path value) { + if (!Files.isReadable(value)) { throw new ParameterException(spec.commandLine(), "Cannot read input file " + value + "."); } - input = value; + inputFile = value; } @Parameters(index = "1", description = "Path to output remapped file.") - private Path output; + private Path outputFile; // Mappings file private Path mappings; @@ -102,7 +102,7 @@ private void setInput(Path value) { */ @Parameters(index = "2", description = "Path to mappings file.") private void setMappings(Path value) { - if (!Files.isReadable(input)) { + if (!Files.isReadable(value)) { throw new ParameterException(spec.commandLine(), "Cannot read mappings file " + value + "."); } @@ -283,11 +283,11 @@ private void setNonClassCopyMode(String value) { @Option(names = {"-t", "--threads"}, description = "Number of threads to use while remapping. " + "Defaults to the number of CPU cores available.") - private void setThreads(int input) { - if (input <= 0) { + private void setThreads(int value) { + if (value <= 0) { throw new ParameterException(spec.commandLine(), "Threads must be greater than 0."); } - threads = input; + threads = value; } /** @@ -296,6 +296,8 @@ private void setThreads(int input) { * @return exit code */ public Integer call() throws Exception { + System.out.println(inputFile); + long startTime = System.nanoTime(); TinyRemapper remapper = TinyRemapper.newRemapper() @@ -315,10 +317,11 @@ public Integer call() throws Exception { .threads(threads) .build(); - try (OutputConsumerPath outputConsumer = new OutputConsumerPath.Builder(output).build()) { - outputConsumer.addNonClassFiles(input, ncCopyMode, remapper); + try (OutputConsumerPath outputConsumer = + new OutputConsumerPath.Builder(outputFile).build()) { + outputConsumer.addNonClassFiles(inputFile, ncCopyMode, remapper); - remapper.readInputs(input); + remapper.readInputs(inputFile); remapper.readClassPath(classpath); remapper.apply(outputConsumer); From 7cf05853050376d90960dc6815e4ea6298395fa0 Mon Sep 17 00:00:00 2001 From: Nino Maruszewski Date: Thu, 17 Jun 2021 12:21:40 -0500 Subject: [PATCH 32/44] Debugging pt. 2 --- src/main/java/net/fabricmc/tinyremapper/Main.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/main/java/net/fabricmc/tinyremapper/Main.java b/src/main/java/net/fabricmc/tinyremapper/Main.java index 915a246..3bcbc0e 100644 --- a/src/main/java/net/fabricmc/tinyremapper/Main.java +++ b/src/main/java/net/fabricmc/tinyremapper/Main.java @@ -296,7 +296,9 @@ private void setThreads(int value) { * @return exit code */ public Integer call() throws Exception { - System.out.println(inputFile); + if (classpath == null) { + classpath = new Path[0]; // PicoCLI makes a null array, Tiny wants an empty one + } long startTime = System.nanoTime(); From 58816fc9aee841dea57484010373342aab5ba431 Mon Sep 17 00:00:00 2001 From: Nino Maruszewski Date: Thu, 17 Jun 2021 12:51:30 -0500 Subject: [PATCH 33/44] Couple of Javadocs --- src/main/java/net/fabricmc/tinyremapper/Main.java | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/main/java/net/fabricmc/tinyremapper/Main.java b/src/main/java/net/fabricmc/tinyremapper/Main.java index 3bcbc0e..c160a63 100644 --- a/src/main/java/net/fabricmc/tinyremapper/Main.java +++ b/src/main/java/net/fabricmc/tinyremapper/Main.java @@ -45,6 +45,9 @@ import picocli.jansi.graalvm.AnsiConsole; /* @formatter:off - eclipse formatter doesn't seem to like annotations */ +/** + * The main class for the Tiny-Remapper CLI. + */ @Command(name = "tiny-remapper", mixinStandardHelpOptions = true, version = { "@|bold,underline Tiny Remapper v" + Main.VERSION + "|@", "ASM v" + Main.ASM_VERSION, @@ -279,7 +282,11 @@ private void setNonClassCopyMode(String value) { // Threads option private int threads = -1; - // @Min(value = 1, message = "Thread count must be greater than 0.") + /** + * Set the threads variable and validate. + * + * @param value + */ @Option(names = {"-t", "--threads"}, description = "Number of threads to use while remapping. " + "Defaults to the number of CPU cores available.") @@ -297,7 +304,7 @@ private void setThreads(int value) { */ public Integer call() throws Exception { if (classpath == null) { - classpath = new Path[0]; // PicoCLI makes a null array, Tiny wants an empty one + classpath = new Path[0]; // PicoCLI makes a null array, Tiny wants an empty one } long startTime = System.nanoTime(); From 132b78dedf4d93cef7659959db79a8f3cf8c1ab7 Mon Sep 17 00:00:00 2001 From: Nino Maruszewski Date: Thu, 17 Jun 2021 13:11:37 -0500 Subject: [PATCH 34/44] Gradle be quiet --- build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.gradle b/build.gradle index 52e6de4..d96c707 100644 --- a/build.gradle +++ b/build.gradle @@ -127,7 +127,7 @@ task generateManpageAsciiDoc(type: JavaExec) { group = "Documentation" description = "Generate AsciiDoc manpage" classpath(configurations.runtimeClasspath, configurations.annotationProcessor, sourceSets.main.runtimeClasspath) - main 'picocli.codegen.docgen.manpage.ManPageGenerator' + mainClass = 'picocli.codegen.docgen.manpage.ManPageGenerator' args "net.fabricmc.tinyremapper.Main", "--outdir=${project.buildDir}/generated-picocli-docs", "-v" //, "--template-dir=src/docs/mantemplates" } From c177c8c88837d1bec88d7de11fbce658e8d46515 Mon Sep 17 00:00:00 2001 From: Nino Maruszewski Date: Thu, 17 Jun 2021 16:44:04 -0500 Subject: [PATCH 35/44] Make class final, use ROOT locale --- src/main/java/net/fabricmc/tinyremapper/Main.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/main/java/net/fabricmc/tinyremapper/Main.java b/src/main/java/net/fabricmc/tinyremapper/Main.java index c160a63..fa2d64e 100644 --- a/src/main/java/net/fabricmc/tinyremapper/Main.java +++ b/src/main/java/net/fabricmc/tinyremapper/Main.java @@ -58,7 +58,7 @@ footer = {"%nCopyright (C) 2016, 2018 Player, asie; 2021 QuiltMC", "Report bugs at ."}, usageHelpAutoWidth = true, abbreviateSynopsis = true) -public class Main implements Callable { +public final class Main implements Callable { /* @formatter:on */ // Version info - done by blossom @@ -204,7 +204,7 @@ private void setForcePropagation(File forcePropagationFile) { description = "Propagate methods to bridge methods. " + "Must be one of \"disabled\", \"enabled\", or \"compatible\".") private void setPropagateBridges(String value) { - switch (value.toLowerCase(Locale.ENGLISH)) { + switch (value.toLowerCase(Locale.ROOT)) { case "disabled": propagateBridges = LinkedMethodPropagation.DISABLED; break; @@ -263,7 +263,7 @@ private void setPropagateBridges(String value) { description = "How to deal with non-class files in a JAR (i.e. META-INF). " + "Must be one of \"unchanged\", \"fixmeta\", or \"skipmeta\".") private void setNonClassCopyMode(String value) { - switch (value.toLowerCase(Locale.ENGLISH)) { + switch (value.toLowerCase(Locale.ROOT)) { case "unchanged": ncCopyMode = NonClassCopyMode.UNCHANGED; break; From fa77911eda60e82a326d2069af95b836f9a17f00 Mon Sep 17 00:00:00 2001 From: Nino Maruszewski Date: Thu, 17 Jun 2021 16:44:37 -0500 Subject: [PATCH 36/44] Spaces ---> tabs --- .../java/net/fabricmc/tinyremapper/Main.java | 612 +++++++++--------- 1 file changed, 306 insertions(+), 306 deletions(-) diff --git a/src/main/java/net/fabricmc/tinyremapper/Main.java b/src/main/java/net/fabricmc/tinyremapper/Main.java index fa2d64e..a519c01 100644 --- a/src/main/java/net/fabricmc/tinyremapper/Main.java +++ b/src/main/java/net/fabricmc/tinyremapper/Main.java @@ -49,311 +49,311 @@ * The main class for the Tiny-Remapper CLI. */ @Command(name = "tiny-remapper", mixinStandardHelpOptions = true, version = { - "@|bold,underline Tiny Remapper v" + Main.VERSION + "|@", - "ASM v" + Main.ASM_VERSION, - "Picocli v" + picocli.CommandLine.VERSION, - "JVM: ${java.version} (${java.vendor} ${java.vm.name} ${java.vm.version})", - "OS: ${os.name} ${os.version} ${os.arch}"}, - description = "A tool for remapping JAR files using \"Tiny\"-format mappings.", - footer = {"%nCopyright (C) 2016, 2018 Player, asie; 2021 QuiltMC", - "Report bugs at ."}, - usageHelpAutoWidth = true, abbreviateSynopsis = true) + "@|bold,underline Tiny Remapper v" + Main.VERSION + "|@", + "ASM v" + Main.ASM_VERSION, + "Picocli v" + picocli.CommandLine.VERSION, + "JVM: ${java.version} (${java.vendor} ${java.vm.name} ${java.vm.version})", + "OS: ${os.name} ${os.version} ${os.arch}"}, + description = "A tool for remapping JAR files using \"Tiny\"-format mappings.", + footer = {"%nCopyright (C) 2016, 2018 Player, asie; 2021 QuiltMC", + "Report bugs at ."}, + usageHelpAutoWidth = true, abbreviateSynopsis = true) public final class Main implements Callable { - /* @formatter:on */ - - // Version info - done by blossom - public static final String VERSION = "__TINY_VERSION"; - public static final String ASM_VERSION = "__ASM_VERSION"; - - /* - * ================== PicoCLI stuff ===================== - */ - @Spec - private CommandSpec spec; // injected by picocli - - /* - * ================== Input parameters ================== - */ - - // Input file - private Path inputFile; - - /** - * Set the input file path variable and validate. - * - * @param value input path from the user - */ - @Parameters(index = "0", description = "Path to input file to remap.") - private void setInputFile(Path value) { - if (!Files.isReadable(value)) { - throw new ParameterException(spec.commandLine(), - "Cannot read input file " + value + "."); - } - inputFile = value; - } - - @Parameters(index = "1", description = "Path to output remapped file.") - private Path outputFile; - - // Mappings file - private Path mappings; - - /** - * Set the mappings path variable and validate. - * - * @param value input path from the user - */ - @Parameters(index = "2", description = "Path to mappings file.") - private void setMappings(Path value) { - if (!Files.isReadable(value)) { - throw new ParameterException(spec.commandLine(), - "Cannot read mappings file " + value + "."); - } - mappings = value; - } - - @Parameters(index = "3", description = "Namespace to map from.") - private String fromMapping; - - @Parameters(index = "4", description = "Namespace to map to.") - private String toMapping; - - // Classpath - private Path[] classpath; - - /** - * Set the classpath variable and validate. - * - * @param value input paths from the user - */ - @Parameters(index = "5..*", description = "Additional files to add to the classpath.") - private void setClasspath(Path[] value) { - classpath = new Path[value.length]; - for (int i = 0; i < value.length; i++) { - classpath[i] = value[i]; - if (!Files.isReadable(value[i])) { - throw new ParameterException(spec.commandLine(), - "Cannot read classpath file " + value[i] + "."); - } - } - } - - /* - * ================== Options and switches ============== - */ - @Option(names = {"-R", "--reverse"}, - description = "Reverse the mapping. @|bold,underline,yellow NOT YET IMPLEMENTED!|@") - private boolean reverse; - - @Option(names = {"-i", "--ignore-field-desc"}, - description = "Ignore the field descriptions in mappings.") - private boolean ignoreFieldDesc; - - // Force propagation option - private Set forcePropagation = Collections.emptySet(); - - /** - * Set the forcePropagation variable and validate. - * - * @param forcePropagationFile input file from the user - */ - @Option(names = {"-f", "--force-propagation"}, - description = "A file with methods to force propagation to.") - private void setForcePropagation(File forcePropagationFile) { - if (forcePropagationFile != null) { - forcePropagation = new HashSet<>(); - - if (!forcePropagationFile.canRead()) { - throw new ParameterException(spec.commandLine(), - "Cannot read forcePropagation file " + forcePropagationFile + "."); - } - - try (BufferedReader reader = new BufferedReader(new FileReader(forcePropagationFile))) { - String line; - - while ((line = reader.readLine()) != null) { - line = line.trim(); - - if (line.isEmpty() || line.charAt(0) == '#') { - continue; - } - - forcePropagation.add(line); - } - } catch (IOException e) { - e.printStackTrace(); - throw new ParameterException(spec.commandLine(), - "An error occurred while parsing the forcePropagation file."); - } - } - } - - @Option(names = {"-p", "--propagate-private"}, - description = "Propagate mappings to private methods.") - private boolean propagatePrivate; - - // Propagate bridges option - private LinkedMethodPropagation propagateBridges = LinkedMethodPropagation.DISABLED; - - /** - * Set the propagateBridges variable and validate. - * - * @param value input from the user - */ - @Option(names = {"-b", "--propagate-bridges"}, - description = "Propagate methods to bridge methods. " - + "Must be one of \"disabled\", \"enabled\", or \"compatible\".") - private void setPropagateBridges(String value) { - switch (value.toLowerCase(Locale.ROOT)) { - case "disabled": - propagateBridges = LinkedMethodPropagation.DISABLED; - break; - case "enabled": - propagateBridges = LinkedMethodPropagation.ENABLED; - break; - case "compatible": - propagateBridges = LinkedMethodPropagation.COMPATIBLE; - break; - default: - throw new ParameterException(spec.commandLine(), - "Invalid propagateBridges value: " + value); - } - } - - @Option(names = "--remove-frames", - description = "Ignore the StackMap and StackMapTable frames.") - private boolean removeFrames; - - @Option(names = {"-I", "--ignore-conflicts"}, - description = "Ignore any mapping conflicts.") - private boolean ignoreConflicts; - - @Option(names = {"-C", "--check-package-access"}, - description = "Check package access.") - private boolean checkPackageAccess; - - @Option(names = {"-F", "--fix-package-access"}, - description = "Fix package access. Implies \"--check-package-access\".") - private boolean fixPackageAccess; - - @Option(names = {"-m", "--resolve-missing"}, description = "Resolve missing methods.") - private boolean resolveMissing; - - @Option(names = {"-r", "--rebuild-source-filenames"}, - description = "Rebuild the filenames of sources.") - private boolean rebuildSourceFilenames; - - @Option(names = {"-l", "--skip-local-variable-mapping"}, - description = "Skip remapping local variables") - private boolean skipLocalVariableMapping; - - @Option(names = {"-L", "--rename-invalid-locals"}, - description = "Rename invalid local variables.") - private boolean renameInvalidLocals; - - // Non-class file copy mode option - private NonClassCopyMode ncCopyMode = NonClassCopyMode.FIX_META_INF; - - /** - * Set the setNonClassCopyMode variable and validate. - * - * @param value input from the user - */ - @Option(names = {"-M", "--non-class-copy-mode"}, - description = "How to deal with non-class files in a JAR (i.e. META-INF). " - + "Must be one of \"unchanged\", \"fixmeta\", or \"skipmeta\".") - private void setNonClassCopyMode(String value) { - switch (value.toLowerCase(Locale.ROOT)) { - case "unchanged": - ncCopyMode = NonClassCopyMode.UNCHANGED; - break; - case "fixmeta": - ncCopyMode = NonClassCopyMode.FIX_META_INF; - break; - case "skipmeta": - ncCopyMode = NonClassCopyMode.SKIP_META_INF; - break; - default: - throw new ParameterException(spec.commandLine(), - "Invalid nonClassCopyMode value: " + value); - } - } - - // Threads option - private int threads = -1; - - /** - * Set the threads variable and validate. - * - * @param value - */ - @Option(names = {"-t", "--threads"}, - description = "Number of threads to use while remapping. " - + "Defaults to the number of CPU cores available.") - private void setThreads(int value) { - if (value <= 0) { - throw new ParameterException(spec.commandLine(), "Threads must be greater than 0."); - } - threads = value; - } - - /** - * The main function of the CLI. - * - * @return exit code - */ - public Integer call() throws Exception { - if (classpath == null) { - classpath = new Path[0]; // PicoCLI makes a null array, Tiny wants an empty one - } - - long startTime = System.nanoTime(); - - TinyRemapper remapper = TinyRemapper.newRemapper() - .withMappings(TinyUtils.createTinyMappingProvider(mappings, fromMapping, toMapping)) - .ignoreFieldDesc(ignoreFieldDesc) - .withForcedPropagation(forcePropagation) - .propagatePrivate(propagatePrivate) - .propagateBridges(propagateBridges) - .removeFrames(removeFrames) - .ignoreConflicts(ignoreConflicts) - .checkPackageAccess(checkPackageAccess) - .fixPackageAccess(fixPackageAccess) - .resolveMissing(resolveMissing) - .rebuildSourceFilenames(rebuildSourceFilenames) - .skipLocalVariableMapping(skipLocalVariableMapping) - .renameInvalidLocals(renameInvalidLocals) - .threads(threads) - .build(); - - try (OutputConsumerPath outputConsumer = - new OutputConsumerPath.Builder(outputFile).build()) { - outputConsumer.addNonClassFiles(inputFile, ncCopyMode, remapper); - - remapper.readInputs(inputFile); - remapper.readClassPath(classpath); - - remapper.apply(outputConsumer); - } catch (IOException e) { - throw new RuntimeException(e); - } finally { - remapper.finish(); - } - - System.out.printf("Finished after %.2f ms.\n", (System.nanoTime() - startTime) / 1e6); - return 0; - } - - /** - * Main runner function. - * - * @param args args from the user - */ - public static void main(String... args) { - int exitCode; - try (AnsiConsole ansi = AnsiConsole.windowsInstall()) { - exitCode = new CommandLine(new Main()).execute(args); - } - System.exit(exitCode); - } + /* @formatter:on */ + + // Version info - done by blossom + public static final String VERSION = "__TINY_VERSION"; + public static final String ASM_VERSION = "__ASM_VERSION"; + + /* + * ================== PicoCLI stuff ===================== + */ + @Spec + private CommandSpec spec; // injected by picocli + + /* + * ================== Input parameters ================== + */ + + // Input file + private Path inputFile; + + /** + * Set the input file path variable and validate. + * + * @param value input path from the user + */ + @Parameters(index = "0", description = "Path to input file to remap.") + private void setInputFile(Path value) { + if (!Files.isReadable(value)) { + throw new ParameterException(spec.commandLine(), + "Cannot read input file " + value + "."); + } + inputFile = value; + } + + @Parameters(index = "1", description = "Path to output remapped file.") + private Path outputFile; + + // Mappings file + private Path mappings; + + /** + * Set the mappings path variable and validate. + * + * @param value input path from the user + */ + @Parameters(index = "2", description = "Path to mappings file.") + private void setMappings(Path value) { + if (!Files.isReadable(value)) { + throw new ParameterException(spec.commandLine(), + "Cannot read mappings file " + value + "."); + } + mappings = value; + } + + @Parameters(index = "3", description = "Namespace to map from.") + private String fromMapping; + + @Parameters(index = "4", description = "Namespace to map to.") + private String toMapping; + + // Classpath + private Path[] classpath; + + /** + * Set the classpath variable and validate. + * + * @param value input paths from the user + */ + @Parameters(index = "5..*", description = "Additional files to add to the classpath.") + private void setClasspath(Path[] value) { + classpath = new Path[value.length]; + for (int i = 0; i < value.length; i++) { + classpath[i] = value[i]; + if (!Files.isReadable(value[i])) { + throw new ParameterException(spec.commandLine(), + "Cannot read classpath file " + value[i] + "."); + } + } + } + + /* + * ================== Options and switches ============== + */ + @Option(names = {"-R", "--reverse"}, + description = "Reverse the mapping. @|bold,underline,yellow NOT YET IMPLEMENTED!|@") + private boolean reverse; + + @Option(names = {"-i", "--ignore-field-desc"}, + description = "Ignore the field descriptions in mappings.") + private boolean ignoreFieldDesc; + + // Force propagation option + private Set forcePropagation = Collections.emptySet(); + + /** + * Set the forcePropagation variable and validate. + * + * @param forcePropagationFile input file from the user + */ + @Option(names = {"-f", "--force-propagation"}, + description = "A file with methods to force propagation to.") + private void setForcePropagation(File forcePropagationFile) { + if (forcePropagationFile != null) { + forcePropagation = new HashSet<>(); + + if (!forcePropagationFile.canRead()) { + throw new ParameterException(spec.commandLine(), + "Cannot read forcePropagation file " + forcePropagationFile + "."); + } + + try (BufferedReader reader = new BufferedReader(new FileReader(forcePropagationFile))) { + String line; + + while ((line = reader.readLine()) != null) { + line = line.trim(); + + if (line.isEmpty() || line.charAt(0) == '#') { + continue; + } + + forcePropagation.add(line); + } + } catch (IOException e) { + e.printStackTrace(); + throw new ParameterException(spec.commandLine(), + "An error occurred while parsing the forcePropagation file."); + } + } + } + + @Option(names = {"-p", "--propagate-private"}, + description = "Propagate mappings to private methods.") + private boolean propagatePrivate; + + // Propagate bridges option + private LinkedMethodPropagation propagateBridges = LinkedMethodPropagation.DISABLED; + + /** + * Set the propagateBridges variable and validate. + * + * @param value input from the user + */ + @Option(names = {"-b", "--propagate-bridges"}, + description = "Propagate methods to bridge methods. " + + "Must be one of \"disabled\", \"enabled\", or \"compatible\".") + private void setPropagateBridges(String value) { + switch (value.toLowerCase(Locale.ROOT)) { + case "disabled": + propagateBridges = LinkedMethodPropagation.DISABLED; + break; + case "enabled": + propagateBridges = LinkedMethodPropagation.ENABLED; + break; + case "compatible": + propagateBridges = LinkedMethodPropagation.COMPATIBLE; + break; + default: + throw new ParameterException(spec.commandLine(), + "Invalid propagateBridges value: " + value); + } + } + + @Option(names = "--remove-frames", + description = "Ignore the StackMap and StackMapTable frames.") + private boolean removeFrames; + + @Option(names = {"-I", "--ignore-conflicts"}, + description = "Ignore any mapping conflicts.") + private boolean ignoreConflicts; + + @Option(names = {"-C", "--check-package-access"}, + description = "Check package access.") + private boolean checkPackageAccess; + + @Option(names = {"-F", "--fix-package-access"}, + description = "Fix package access. Implies \"--check-package-access\".") + private boolean fixPackageAccess; + + @Option(names = {"-m", "--resolve-missing"}, description = "Resolve missing methods.") + private boolean resolveMissing; + + @Option(names = {"-r", "--rebuild-source-filenames"}, + description = "Rebuild the filenames of sources.") + private boolean rebuildSourceFilenames; + + @Option(names = {"-l", "--skip-local-variable-mapping"}, + description = "Skip remapping local variables") + private boolean skipLocalVariableMapping; + + @Option(names = {"-L", "--rename-invalid-locals"}, + description = "Rename invalid local variables.") + private boolean renameInvalidLocals; + + // Non-class file copy mode option + private NonClassCopyMode ncCopyMode = NonClassCopyMode.FIX_META_INF; + + /** + * Set the setNonClassCopyMode variable and validate. + * + * @param value input from the user + */ + @Option(names = {"-M", "--non-class-copy-mode"}, + description = "How to deal with non-class files in a JAR (i.e. META-INF). " + + "Must be one of \"unchanged\", \"fixmeta\", or \"skipmeta\".") + private void setNonClassCopyMode(String value) { + switch (value.toLowerCase(Locale.ROOT)) { + case "unchanged": + ncCopyMode = NonClassCopyMode.UNCHANGED; + break; + case "fixmeta": + ncCopyMode = NonClassCopyMode.FIX_META_INF; + break; + case "skipmeta": + ncCopyMode = NonClassCopyMode.SKIP_META_INF; + break; + default: + throw new ParameterException(spec.commandLine(), + "Invalid nonClassCopyMode value: " + value); + } + } + + // Threads option + private int threads = -1; + + /** + * Set the threads variable and validate. + * + * @param value + */ + @Option(names = {"-t", "--threads"}, + description = "Number of threads to use while remapping. " + + "Defaults to the number of CPU cores available.") + private void setThreads(int value) { + if (value <= 0) { + throw new ParameterException(spec.commandLine(), "Threads must be greater than 0."); + } + threads = value; + } + + /** + * The main function of the CLI. + * + * @return exit code + */ + public Integer call() throws Exception { + if (classpath == null) { + classpath = new Path[0]; // PicoCLI makes a null array, Tiny wants an empty one + } + + long startTime = System.nanoTime(); + + TinyRemapper remapper = TinyRemapper.newRemapper() + .withMappings(TinyUtils.createTinyMappingProvider(mappings, fromMapping, toMapping)) + .ignoreFieldDesc(ignoreFieldDesc) + .withForcedPropagation(forcePropagation) + .propagatePrivate(propagatePrivate) + .propagateBridges(propagateBridges) + .removeFrames(removeFrames) + .ignoreConflicts(ignoreConflicts) + .checkPackageAccess(checkPackageAccess) + .fixPackageAccess(fixPackageAccess) + .resolveMissing(resolveMissing) + .rebuildSourceFilenames(rebuildSourceFilenames) + .skipLocalVariableMapping(skipLocalVariableMapping) + .renameInvalidLocals(renameInvalidLocals) + .threads(threads) + .build(); + + try (OutputConsumerPath outputConsumer = + new OutputConsumerPath.Builder(outputFile).build()) { + outputConsumer.addNonClassFiles(inputFile, ncCopyMode, remapper); + + remapper.readInputs(inputFile); + remapper.readClassPath(classpath); + + remapper.apply(outputConsumer); + } catch (IOException e) { + throw new RuntimeException(e); + } finally { + remapper.finish(); + } + + System.out.printf("Finished after %.2f ms.\n", (System.nanoTime() - startTime) / 1e6); + return 0; + } + + /** + * Main runner function. + * + * @param args args from the user + */ + public static void main(String... args) { + int exitCode; + try (AnsiConsole ansi = AnsiConsole.windowsInstall()) { + exitCode = new CommandLine(new Main()).execute(args); + } + System.exit(exitCode); + } } From bd772e4cfc65cf558e37ccd031e780626a9a7641 Mon Sep 17 00:00:00 2001 From: Nino Maruszewski Date: Fri, 18 Jun 2021 16:41:16 -0500 Subject: [PATCH 37/44] Spaces --> tabs, fix the version in META-INF --- build.gradle | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/build.gradle b/build.gradle index d96c707..94fad75 100644 --- a/build.gradle +++ b/build.gradle @@ -43,7 +43,7 @@ dependencies { compileJava { // For PicoCLI annotation processor - options.compilerArgs += ["-Aproject=${project.group}/${project.name}"] + options.compilerArgs += ["-Aproject=${project.group}/${project.name}"] } java { @@ -85,7 +85,7 @@ test { jar { manifest { attributes "Implementation-Title": "TinyRemapper", - "Implementation-Version": archiveVersion, + "Implementation-Version": version, "Main-Class": "net.fabricmc.tinyremapper.Main", "Automatic-Module-Name": "org.quiltmc.tinyremapper" } @@ -123,20 +123,20 @@ publishing { // Manpage generator (included with PicoCLI) task generateManpageAsciiDoc(type: JavaExec) { - dependsOn(classes) - group = "Documentation" - description = "Generate AsciiDoc manpage" - classpath(configurations.runtimeClasspath, configurations.annotationProcessor, sourceSets.main.runtimeClasspath) - mainClass = 'picocli.codegen.docgen.manpage.ManPageGenerator' - args "net.fabricmc.tinyremapper.Main", "--outdir=${project.buildDir}/generated-picocli-docs", "-v" //, "--template-dir=src/docs/mantemplates" + dependsOn(classes) + group = "Documentation" + description = "Generate AsciiDoc manpage" + classpath(configurations.runtimeClasspath, configurations.annotationProcessor, sourceSets.main.runtimeClasspath) + mainClass = 'picocli.codegen.docgen.manpage.ManPageGenerator' + args "net.fabricmc.tinyremapper.Main", "--outdir=${project.buildDir}/generated-picocli-docs", "-v" //, "--template-dir=src/docs/mantemplates" } asciidoctor { - dependsOn(generateManpageAsciiDoc) - sourceDir = file("${project.buildDir}/generated-picocli-docs") - outputDir = file("${project.buildDir}/docs") - logDocuments = true - outputOptions { - backends = ['manpage', 'html5'] - } + dependsOn(generateManpageAsciiDoc) + sourceDir = file("${project.buildDir}/generated-picocli-docs") + outputDir = file("${project.buildDir}/docs") + logDocuments = true + outputOptions { + backends = ['manpage', 'html5'] + } } From a2abf87141381ae0f9950f0168656ae4721e85b5 Mon Sep 17 00:00:00 2001 From: Nino Maruszewski Date: Fri, 18 Jun 2021 16:43:01 -0500 Subject: [PATCH 38/44] Single to double quotes --- build.gradle | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/build.gradle b/build.gradle index 94fad75..764bba9 100644 --- a/build.gradle +++ b/build.gradle @@ -2,22 +2,22 @@ plugins { id "java" id "maven-publish" id "com.diffplug.spotless" version "5.10.2" - id 'com.github.johnrengelman.shadow' version '7.0.0' // Make a fat jar - id 'org.asciidoctor.jvm.convert' version '3.1.0' // Make man pages - id 'net.kyori.blossom' version '1.2.0' // Better version (again) + id "com.github.johnrengelman.shadow" version "7.0.0" // Make a fat jar + id "org.asciidoctor.jvm.convert" version "3.1.0" // Make man pages + id "net.kyori.blossom" version "1.2.0" // Better version (again) // TODO: Apply checkstyle } sourceCompatibility = JavaVersion.VERSION_1_8 targetCompatibility = JavaVersion.VERSION_1_8 -version = '0.4.1' +version = "0.4.1" def ENV = System.getenv() version = version + (ENV.GITHUB_ACTIONS ? "" : "+local") group = "org.quiltmc" -archivesBaseName = 'tiny-remapper' +archivesBaseName = "tiny-remapper" repositories { mavenCentral() @@ -31,7 +31,7 @@ dependencies { implementation "org.ow2.asm:asm-util:$asmVersion" // Testing - testImplementation 'org.junit.jupiter:junit-jupiter:5.6.2' + testImplementation "org.junit.jupiter:junit-jupiter:5.6.2" // CLI tool implementation "info.picocli:picocli:$picocliVersion" @@ -77,8 +77,8 @@ test { useJUnitPlatform() testLogging { showStandardStreams = true - exceptionFormat = 'full' - events = ['passed', 'failed', 'skipped'] + exceptionFormat = "full" + events = ["passed", "failed", "skipped"] } } @@ -127,7 +127,7 @@ task generateManpageAsciiDoc(type: JavaExec) { group = "Documentation" description = "Generate AsciiDoc manpage" classpath(configurations.runtimeClasspath, configurations.annotationProcessor, sourceSets.main.runtimeClasspath) - mainClass = 'picocli.codegen.docgen.manpage.ManPageGenerator' + mainClass = "picocli.codegen.docgen.manpage.ManPageGenerator" args "net.fabricmc.tinyremapper.Main", "--outdir=${project.buildDir}/generated-picocli-docs", "-v" //, "--template-dir=src/docs/mantemplates" } @@ -137,6 +137,6 @@ asciidoctor { outputDir = file("${project.buildDir}/docs") logDocuments = true outputOptions { - backends = ['manpage', 'html5'] + backends = ["manpage", "html5"] } } From ee2244f95c90434dbee8b6c02635a3e64ca2f9bf Mon Sep 17 00:00:00 2001 From: Nino Maruszewski Date: Fri, 18 Jun 2021 16:43:27 -0500 Subject: [PATCH 39/44] Add comment back in --- build.gradle | 1 + 1 file changed, 1 insertion(+) diff --git a/build.gradle b/build.gradle index 764bba9..6108bc7 100644 --- a/build.gradle +++ b/build.gradle @@ -86,6 +86,7 @@ jar { manifest { attributes "Implementation-Title": "TinyRemapper", "Implementation-Version": version, + // TODO: Move to application plugin instead of placing this in the manifest directly "Main-Class": "net.fabricmc.tinyremapper.Main", "Automatic-Module-Name": "org.quiltmc.tinyremapper" } From adafc6d97a8da074587b2657d572f8d7bc426a93 Mon Sep 17 00:00:00 2001 From: Nino Maruszewski Date: Fri, 18 Jun 2021 16:45:22 -0500 Subject: [PATCH 40/44] Change description of switches with options --- src/main/java/net/fabricmc/tinyremapper/Main.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/net/fabricmc/tinyremapper/Main.java b/src/main/java/net/fabricmc/tinyremapper/Main.java index a519c01..4aa5b49 100644 --- a/src/main/java/net/fabricmc/tinyremapper/Main.java +++ b/src/main/java/net/fabricmc/tinyremapper/Main.java @@ -202,7 +202,7 @@ private void setForcePropagation(File forcePropagationFile) { */ @Option(names = {"-b", "--propagate-bridges"}, description = "Propagate methods to bridge methods. " - + "Must be one of \"disabled\", \"enabled\", or \"compatible\".") + + "Must be one of the following: \"disabled\", \"enabled\", or \"compatible\".") private void setPropagateBridges(String value) { switch (value.toLowerCase(Locale.ROOT)) { case "disabled": @@ -261,7 +261,7 @@ private void setPropagateBridges(String value) { */ @Option(names = {"-M", "--non-class-copy-mode"}, description = "How to deal with non-class files in a JAR (i.e. META-INF). " - + "Must be one of \"unchanged\", \"fixmeta\", or \"skipmeta\".") + + "Must be one of the following: \"unchanged\", \"fixmeta\", or \"skipmeta\".") private void setNonClassCopyMode(String value) { switch (value.toLowerCase(Locale.ROOT)) { case "unchanged": From e68e55ecc4025c3d51a4e3826215cb32b7239a0a Mon Sep 17 00:00:00 2001 From: Nino Maruszewski Date: Fri, 18 Jun 2021 17:46:13 -0500 Subject: [PATCH 41/44] Add docs for Github pages --- build.gradle | 11 +- docs/_config.yml | 2 + docs/cli/index.html | 582 ++++++++++++++++++++++++++++++++++++++++++++ docs/index.md | 5 + 4 files changed, 598 insertions(+), 2 deletions(-) create mode 100644 docs/_config.yml create mode 100644 docs/cli/index.html create mode 100644 docs/index.md diff --git a/build.gradle b/build.gradle index 6108bc7..4451742 100644 --- a/build.gradle +++ b/build.gradle @@ -124,7 +124,7 @@ publishing { // Manpage generator (included with PicoCLI) task generateManpageAsciiDoc(type: JavaExec) { - dependsOn(classes) + dependsOn classes group = "Documentation" description = "Generate AsciiDoc manpage" classpath(configurations.runtimeClasspath, configurations.annotationProcessor, sourceSets.main.runtimeClasspath) @@ -133,7 +133,7 @@ task generateManpageAsciiDoc(type: JavaExec) { } asciidoctor { - dependsOn(generateManpageAsciiDoc) + dependsOn generateManpageAsciiDoc sourceDir = file("${project.buildDir}/generated-picocli-docs") outputDir = file("${project.buildDir}/docs") logDocuments = true @@ -141,3 +141,10 @@ asciidoctor { backends = ["manpage", "html5"] } } + +task githubCMDDocs(type: Copy) { + dependsOn asciidoctor + from "./build/docs/html5/tiny-remapper.html" + into "./docs/cli/" + rename "tiny-remapper.html", "index.html" +} diff --git a/docs/_config.yml b/docs/_config.yml new file mode 100644 index 0000000..7df9f32 --- /dev/null +++ b/docs/_config.yml @@ -0,0 +1,2 @@ +exclude: + - "cli" diff --git a/docs/cli/index.html b/docs/cli/index.html new file mode 100644 index 0000000..070b373 --- /dev/null +++ b/docs/cli/index.html @@ -0,0 +1,582 @@ + + + + + + + +tiny-remapper(1) + + + + + +
+
+

Synopsis

+
+
+

tiny-remapper [OPTIONS] <inputFile> <outputFile> <mappings> <fromMapping> <toMapping> [<classpath>…​]

+
+
+
+
+

Description

+
+
+

A tool for remapping JAR files using "Tiny"-format mappings.

+
+
+
+
+

Options

+
+
+
+
-b, --propagate-bridges=<propagateBridges>
+
+

Propagate methods to bridge methods. Must be one of the following: "disabled", "enabled", or "compatible".

+
+
-C, --check-package-access
+
+

Check package access.

+
+
-f, --force-propagation=<forcePropagation>
+
+

A file with methods to force propagation to.

+
+
-F, --fix-package-access
+
+

Fix package access. Implies "--check-package-access".

+
+
-h, --help
+
+

Show this help message and exit.

+
+
-i, --ignore-field-desc
+
+

Ignore the field descriptions in mappings.

+
+
-I, --ignore-conflicts
+
+

Ignore any mapping conflicts.

+
+
-l, --skip-local-variable-mapping
+
+

Skip remapping local variables

+
+
-L, --rename-invalid-locals
+
+

Rename invalid local variables.

+
+
-m, --resolve-missing
+
+

Resolve missing methods.

+
+
-M, --non-class-copy-mode=<nonClassCopyMode>
+
+

How to deal with non-class files in a JAR (i.e. META-INF). Must be one of the following: "unchanged", "fixmeta", or "skipmeta".

+
+
-p, --propagate-private
+
+

Propagate mappings to private methods.

+
+
-r, --rebuild-source-filenames
+
+

Rebuild the filenames of sources.

+
+
-R, --reverse
+
+

Reverse the mapping. NOT YET IMPLEMENTED!

+
+
--remove-frames
+
+

Ignore the StackMap and StackMapTable frames.

+
+
-t, --threads=<threads>
+
+

Number of threads to use while remapping. Defaults to the number of CPU cores available.

+
+
-V, --version
+
+

Print version information and exit.

+
+
+
+
+
+
+

Arguments

+
+
+
+
<inputFile>
+
+

Path to input file to remap.

+
+
<outputFile>
+
+

Path to output remapped file.

+
+
<mappings>
+
+

Path to mappings file.

+
+
<fromMapping>
+
+

Namespace to map from.

+
+
<toMapping>
+
+

Namespace to map to.

+
+
[<classpath>…​]
+
+

Additional files to add to the classpath.

+
+
+
+
+
+
+ + + \ No newline at end of file diff --git a/docs/index.md b/docs/index.md new file mode 100644 index 0000000..ef18550 --- /dev/null +++ b/docs/index.md @@ -0,0 +1,5 @@ +# Tiny Remapper Documentation + +For the API Docs, click [here](https://quiltmc.github.io/tiny-remapper/javadoc). + +For the CLI Manpage, click [here](https://quiltmc.github.io/tiny-remapper/cli). From eb30c855c7c61b6e2a57328ea10ec59f68793ab9 Mon Sep 17 00:00:00 2001 From: Nino Maruszewski Date: Fri, 18 Jun 2021 17:48:11 -0500 Subject: [PATCH 42/44] Add javadoc folder --- docs/_config.yml | 1 + docs/javadoc/.gitkeep | 0 2 files changed, 1 insertion(+) create mode 100644 docs/javadoc/.gitkeep diff --git a/docs/_config.yml b/docs/_config.yml index 7df9f32..afa96a8 100644 --- a/docs/_config.yml +++ b/docs/_config.yml @@ -1,2 +1,3 @@ exclude: - "cli" + - "javadoc" diff --git a/docs/javadoc/.gitkeep b/docs/javadoc/.gitkeep new file mode 100644 index 0000000..e69de29 From 008dee4f72bc4082fb19bffede3cfebe827f2293 Mon Sep 17 00:00:00 2001 From: Nino Maruszewski Date: Fri, 18 Jun 2021 17:54:55 -0500 Subject: [PATCH 43/44] Add Github Action for docs --- .github/workflows/release.yml | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 76bbff1..564f0af 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -15,3 +15,30 @@ jobs: MAVEN_URL: ${{ secrets.MAVEN_URL }} MAVEN_USERNAME: ${{ secrets.MAVEN_USERNAME }} MAVEN_PASSWORD: ${{ secrets.MAVEN_PASSWORD }} + + docs: + name: Generate Docs + runs-on: ubuntu-latest + container: + image: openjdk:16-jdk + options: --user root + steps: + - name: Checkout Repo + uses: actions/checkout@v2 + + - name: Validate Gradle wrapper + uses: gradle/wrapper-validation-action@v1 + + - name: Build docs + run: | + chmod +x ./gradlew + ./gradlew githubCMDDocs --stacktrace + + - name: Create commit + uses: EndBug/add-and-commit@v7 + with: + add: "." + default-author: github_actions + message: Update docs + push: true + signoff: true From 64e621b2f6845fca30b9c3972d4b99ff133fd1fc Mon Sep 17 00:00:00 2001 From: Nino Maruszewski Date: Fri, 18 Jun 2021 18:02:39 -0500 Subject: [PATCH 44/44] Add gitattributes --- .gitattributes | 111 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 111 insertions(+) create mode 100644 .gitattributes diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..5989766 --- /dev/null +++ b/.gitattributes @@ -0,0 +1,111 @@ +# Common settings that generally should always be used with your language specific settings + +# Auto detect text files and perform LF normalization +# https://www.davidlaing.com/2012/09/19/customise-your-gitattributes-to-become-a-git-ninja/ +* text=auto + +# +# The above will handle all files NOT found below +# + +# Documents +*.bibtex text diff=bibtex +*.doc diff=astextplain +*.DOC diff=astextplain +*.docx diff=astextplain +*.DOCX diff=astextplain +*.dot diff=astextplain +*.DOT diff=astextplain +*.pdf diff=astextplain +*.PDF diff=astextplain +*.rtf diff=astextplain +*.RTF diff=astextplain +*.md text diff=markdown +*.tex text diff=tex +*.adoc text +*.textile text +*.mustache text +*.csv text +*.tab text +*.tsv text +*.txt text +*.sql text +*.ps1 text eol=crlf + +# Graphics +*.png binary +*.jpg binary +*.jpeg binary +*.gif binary +*.tif binary +*.tiff binary +*.ico binary +# SVG treated as text by default. +*.svg text +# If you want to treat it as binary, +# use the following line instead. +# *.svg binary +*.eps binary + +# Scripts +*.bash text eol=lf +*.fish text eol=lf +*.sh text eol=lf +# These are explicitly windows files and should use crlf +*.bat text eol=crlf +*.cmd text eol=crlf + +# Serialisation +*.json text +*.toml text +*.xml text +*.yaml text +*.yml text + +# Archives +*.7z binary +*.gz binary +*.tar binary +*.tgz binary +*.zip binary + +# Text files where line endings should be preserved +*.patch -text + +# +# Exclude files from exporting +# + +.gitattributes export-ignore +.gitignore export-ignore +.gitkeep export-ignore + +# Java sources +*.java text diff=java +*.gradle text diff=java +*.gradle.kts text diff=java + +# These files are text and should be normalized (Convert crlf => lf) +*.css text diff=css +*.df text +*.htm text diff=html +*.html text diff=html +*.js text +*.jsp text +*.jspf text +*.jspx text +*.properties text +*.tld text +*.tag text +*.tagx text +*.xml text + +# These files are binary and should be left untouched +# (binary is a macro for -text -diff) +*.class binary +*.dll binary +*.ear binary +*.jar binary +*.so binary +*.war binary +*.jks binary