Initial commit
This commit is contained in:
commit
4d12aa9fc3
50 changed files with 4582 additions and 0 deletions
8
.gitattributes
vendored
Normal file
8
.gitattributes
vendored
Normal file
|
@ -0,0 +1,8 @@
|
|||
* text=auto
|
||||
|
||||
*.sh text eol=lf
|
||||
gradlew text eol=lf
|
||||
*.bat text eol=crlf
|
||||
|
||||
*.jar binary
|
||||
|
172
.gitignore
vendored
Normal file
172
.gitignore
vendored
Normal file
|
@ -0,0 +1,172 @@
|
|||
### Intellij ###
|
||||
.idea/
|
||||
|
||||
# File-based project format
|
||||
*.iws
|
||||
*.iml
|
||||
|
||||
# IntelliJ
|
||||
out/
|
||||
|
||||
# JIRA plugin
|
||||
atlassian-ide-plugin.xml
|
||||
|
||||
# Crashlytics plugin (for Android Studio and IntelliJ)
|
||||
com_crashlytics_export_strings.xml
|
||||
crashlytics.properties
|
||||
crashlytics-build.properties
|
||||
fabric.properties
|
||||
|
||||
### Eclipse ###
|
||||
|
||||
.metadata
|
||||
bin/
|
||||
tmp/
|
||||
*.tmp
|
||||
*.bak
|
||||
*.swp
|
||||
*~.nib
|
||||
local.properties
|
||||
.settings/
|
||||
.loadpath
|
||||
.recommenders
|
||||
|
||||
# External tool builders
|
||||
.externalToolBuilders/
|
||||
|
||||
# Locally stored "Eclipse launch configurations"
|
||||
*.launch
|
||||
|
||||
# PyDev specific (Python IDE for Eclipse)
|
||||
*.pydevproject
|
||||
|
||||
# CDT-specific (C/C++ Development Tooling)
|
||||
.cproject
|
||||
|
||||
# CDT- autotools
|
||||
.autotools
|
||||
|
||||
# Java annotation processor (APT)
|
||||
.factorypath
|
||||
|
||||
# PDT-specific (PHP Development Tools)
|
||||
.buildpath
|
||||
|
||||
# sbteclipse plugin
|
||||
.target
|
||||
|
||||
# Tern plugin
|
||||
.tern-project
|
||||
|
||||
# TeXlipse plugin
|
||||
.texlipse
|
||||
|
||||
# STS (Spring Tool Suite)
|
||||
.springBeans
|
||||
|
||||
# Code Recommenders
|
||||
.recommenders/
|
||||
|
||||
# Annotation Processing
|
||||
.apt_generated/
|
||||
|
||||
# Scala IDE specific (Scala & Java development for Eclipse)
|
||||
.cache-main
|
||||
.scala_dependencies
|
||||
.worksheet
|
||||
|
||||
### Eclipse Patch ###
|
||||
# Eclipse Core
|
||||
.project
|
||||
|
||||
# JDT-specific (Eclipse Java Development Tools)
|
||||
.classpath
|
||||
|
||||
# Annotation Processing
|
||||
.apt_generated
|
||||
|
||||
.sts4-cache/
|
||||
|
||||
### Linux ###
|
||||
*~
|
||||
|
||||
# temporary files which can be created if a process still has a handle open of a deleted file
|
||||
.fuse_hidden*
|
||||
|
||||
# KDE directory preferences
|
||||
.directory
|
||||
|
||||
# Linux trash folder which might appear on any partition or disk
|
||||
.Trash-*
|
||||
|
||||
# .nfs files are created when an open file is removed but is still being accessed
|
||||
.nfs*
|
||||
|
||||
### macOS ###
|
||||
# General
|
||||
.DS_Store
|
||||
.AppleDouble
|
||||
.LSOverride
|
||||
|
||||
# Icon must end with two \r
|
||||
Icon
|
||||
|
||||
# Thumbnails
|
||||
._*
|
||||
|
||||
# Files that might appear in the root of a volume
|
||||
.DocumentRevisions-V100
|
||||
.fseventsd
|
||||
.Spotlight-V100
|
||||
.TemporaryItems
|
||||
.Trashes
|
||||
.VolumeIcon.icns
|
||||
.com.apple.timemachine.donotpresent
|
||||
|
||||
# Directories potentially created on remote AFP share
|
||||
.AppleDB
|
||||
.AppleDesktop
|
||||
Network Trash Folder
|
||||
Temporary Items
|
||||
.apdisk
|
||||
|
||||
### Windows ###
|
||||
# Windows thumbnail cache files
|
||||
Thumbs.db
|
||||
ehthumbs.db
|
||||
ehthumbs_vista.db
|
||||
|
||||
# Dump file
|
||||
*.stackdump
|
||||
|
||||
# Folder config file
|
||||
[Dd]esktop.ini
|
||||
|
||||
# Recycle Bin used on file shares
|
||||
$RECYCLE.BIN/
|
||||
|
||||
# Windows Installer files
|
||||
*.cab
|
||||
*.msi
|
||||
*.msix
|
||||
*.msm
|
||||
*.msp
|
||||
|
||||
# Windows shortcuts
|
||||
*.lnk
|
||||
|
||||
### Gradle ###
|
||||
.gradle
|
||||
/build/
|
||||
|
||||
# Ignore Gradle GUI config
|
||||
gradle-app.setting
|
||||
|
||||
# Cache of project
|
||||
.gradletasknamecache
|
||||
|
||||
# # Work around https://youtrack.jetbrains.com/issue/IDEA-116898
|
||||
# gradle/wrapper/gradle-wrapper.properties
|
||||
|
||||
# Avoid ignoring Gradle wrapper jar file (.jar files are usually ignored)
|
||||
!gradle-wrapper.ja
|
76
build.gradle.kts
Normal file
76
build.gradle.kts
Normal file
|
@ -0,0 +1,76 @@
|
|||
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
|
||||
|
||||
plugins {
|
||||
idea
|
||||
eclipse
|
||||
maven
|
||||
kotlin("jvm") version "1.3.70"
|
||||
`kotlin-dsl`
|
||||
id("net.minecrell.licenser") version "0.4.1"
|
||||
id("com.github.johnrengelman.shadow") version "6.0.0"
|
||||
}
|
||||
|
||||
group = "io.papermc.paperweight"
|
||||
version = "1.0.0-SNAPSHOT"
|
||||
|
||||
repositories {
|
||||
mavenCentral()
|
||||
maven("https://oss.sonatype.org/content/repositories/snapshots/")
|
||||
maven("https://files.minecraftforge.net/maven/")
|
||||
}
|
||||
|
||||
val mcInjector: Configuration by configurations.creating
|
||||
|
||||
dependencies {
|
||||
implementation(kotlin("stdlib-jdk8"))
|
||||
compileOnly(gradleApi())
|
||||
compileOnly(gradleKotlinDsl())
|
||||
|
||||
implementation("net.sf.opencsv:opencsv:2.3")
|
||||
implementation("com.github.salomonbrys.kotson:kotson:2.5.0")
|
||||
|
||||
// Cadix
|
||||
implementation("org.cadixdev:lorenz:0.5.3")
|
||||
implementation("org.cadixdev:lorenz-asm:0.5.3")
|
||||
implementation("org.cadixdev:mercury:0.1.0-SNAPSHOT")
|
||||
implementation("org.cadixdev:atlas:0.2.0")
|
||||
}
|
||||
|
||||
tasks.withType<KotlinCompile> {
|
||||
kotlinOptions.jvmTarget = "1.8"
|
||||
}
|
||||
|
||||
val mcinjectorJar by tasks.registering(com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar::class) {
|
||||
configurations = listOf(mcInjector)
|
||||
archiveBaseName.set("mcinjector-shadowed")
|
||||
archiveVersion.set("")
|
||||
archiveClassifier.set("")
|
||||
manifest {
|
||||
attributes(mapOf("Main-Class" to "de.oceanlabs.mcp.mcinjector.MCInjector"))
|
||||
}
|
||||
}
|
||||
|
||||
tasks.jar {
|
||||
from(mcinjectorJar)
|
||||
archiveBaseName.set("io.papermc.paperweight.gradle.plugin")
|
||||
}
|
||||
|
||||
idea {
|
||||
module {
|
||||
isDownloadSources = true
|
||||
isDownloadJavadoc = true
|
||||
}
|
||||
}
|
||||
|
||||
eclipse {
|
||||
classpath {
|
||||
isDownloadSources = true
|
||||
isDownloadJavadoc = true
|
||||
}
|
||||
}
|
||||
|
||||
license {
|
||||
header = file("license/copyright.txt")
|
||||
|
||||
include("**/*.kt")
|
||||
}
|
BIN
gradle/wrapper/gradle-wrapper.jar
vendored
Normal file
BIN
gradle/wrapper/gradle-wrapper.jar
vendored
Normal file
Binary file not shown.
5
gradle/wrapper/gradle-wrapper.properties
vendored
Normal file
5
gradle/wrapper/gradle-wrapper.properties
vendored
Normal file
|
@ -0,0 +1,5 @@
|
|||
distributionBase=GRADLE_USER_HOME
|
||||
distributionPath=wrapper/dists
|
||||
distributionUrl=https\://services.gradle.org/distributions/gradle-6.5-all.zip
|
||||
zipStoreBase=GRADLE_USER_HOME
|
||||
zipStorePath=wrapper/dists
|
172
gradlew
vendored
Executable file
172
gradlew
vendored
Executable file
|
@ -0,0 +1,172 @@
|
|||
#!/usr/bin/env sh
|
||||
|
||||
##############################################################################
|
||||
##
|
||||
## Gradle start up script for UN*X
|
||||
##
|
||||
##############################################################################
|
||||
|
||||
# Attempt to set APP_HOME
|
||||
# Resolve links: $0 may be a link
|
||||
PRG="$0"
|
||||
# Need this for relative symlinks.
|
||||
while [ -h "$PRG" ] ; do
|
||||
ls=`ls -ld "$PRG"`
|
||||
link=`expr "$ls" : '.*-> \(.*\)$'`
|
||||
if expr "$link" : '/.*' > /dev/null; then
|
||||
PRG="$link"
|
||||
else
|
||||
PRG=`dirname "$PRG"`"/$link"
|
||||
fi
|
||||
done
|
||||
SAVED="`pwd`"
|
||||
cd "`dirname \"$PRG\"`/" >/dev/null
|
||||
APP_HOME="`pwd -P`"
|
||||
cd "$SAVED" >/dev/null
|
||||
|
||||
APP_NAME="Gradle"
|
||||
APP_BASE_NAME=`basename "$0"`
|
||||
|
||||
# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
|
||||
DEFAULT_JVM_OPTS=""
|
||||
|
||||
# Use the maximum available, or set MAX_FD != -1 to use that value.
|
||||
MAX_FD="maximum"
|
||||
|
||||
warn () {
|
||||
echo "$*"
|
||||
}
|
||||
|
||||
die () {
|
||||
echo
|
||||
echo "$*"
|
||||
echo
|
||||
exit 1
|
||||
}
|
||||
|
||||
# OS specific support (must be 'true' or 'false').
|
||||
cygwin=false
|
||||
msys=false
|
||||
darwin=false
|
||||
nonstop=false
|
||||
case "`uname`" in
|
||||
CYGWIN* )
|
||||
cygwin=true
|
||||
;;
|
||||
Darwin* )
|
||||
darwin=true
|
||||
;;
|
||||
MINGW* )
|
||||
msys=true
|
||||
;;
|
||||
NONSTOP* )
|
||||
nonstop=true
|
||||
;;
|
||||
esac
|
||||
|
||||
CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
|
||||
|
||||
# Determine the Java command to use to start the JVM.
|
||||
if [ -n "$JAVA_HOME" ] ; then
|
||||
if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
|
||||
# IBM's JDK on AIX uses strange locations for the executables
|
||||
JAVACMD="$JAVA_HOME/jre/sh/java"
|
||||
else
|
||||
JAVACMD="$JAVA_HOME/bin/java"
|
||||
fi
|
||||
if [ ! -x "$JAVACMD" ] ; then
|
||||
die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
|
||||
|
||||
Please set the JAVA_HOME variable in your environment to match the
|
||||
location of your Java installation."
|
||||
fi
|
||||
else
|
||||
JAVACMD="java"
|
||||
which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
|
||||
|
||||
Please set the JAVA_HOME variable in your environment to match the
|
||||
location of your Java installation."
|
||||
fi
|
||||
|
||||
# Increase the maximum file descriptors if we can.
|
||||
if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then
|
||||
MAX_FD_LIMIT=`ulimit -H -n`
|
||||
if [ $? -eq 0 ] ; then
|
||||
if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
|
||||
MAX_FD="$MAX_FD_LIMIT"
|
||||
fi
|
||||
ulimit -n $MAX_FD
|
||||
if [ $? -ne 0 ] ; then
|
||||
warn "Could not set maximum file descriptor limit: $MAX_FD"
|
||||
fi
|
||||
else
|
||||
warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
|
||||
fi
|
||||
fi
|
||||
|
||||
# For Darwin, add options to specify how the application appears in the dock
|
||||
if $darwin; then
|
||||
GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
|
||||
fi
|
||||
|
||||
# For Cygwin, switch paths to Windows format before running java
|
||||
if $cygwin ; then
|
||||
APP_HOME=`cygpath --path --mixed "$APP_HOME"`
|
||||
CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
|
||||
JAVACMD=`cygpath --unix "$JAVACMD"`
|
||||
|
||||
# We build the pattern for arguments to be converted via cygpath
|
||||
ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
|
||||
SEP=""
|
||||
for dir in $ROOTDIRSRAW ; do
|
||||
ROOTDIRS="$ROOTDIRS$SEP$dir"
|
||||
SEP="|"
|
||||
done
|
||||
OURCYGPATTERN="(^($ROOTDIRS))"
|
||||
# Add a user-defined pattern to the cygpath arguments
|
||||
if [ "$GRADLE_CYGPATTERN" != "" ] ; then
|
||||
OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
|
||||
fi
|
||||
# Now convert the arguments - kludge to limit ourselves to /bin/sh
|
||||
i=0
|
||||
for arg in "$@" ; do
|
||||
CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
|
||||
CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
|
||||
|
||||
if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
|
||||
eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
|
||||
else
|
||||
eval `echo args$i`="\"$arg\""
|
||||
fi
|
||||
i=$((i+1))
|
||||
done
|
||||
case $i in
|
||||
(0) set -- ;;
|
||||
(1) set -- "$args0" ;;
|
||||
(2) set -- "$args0" "$args1" ;;
|
||||
(3) set -- "$args0" "$args1" "$args2" ;;
|
||||
(4) set -- "$args0" "$args1" "$args2" "$args3" ;;
|
||||
(5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
|
||||
(6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
|
||||
(7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
|
||||
(8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
|
||||
(9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
|
||||
esac
|
||||
fi
|
||||
|
||||
# Escape application args
|
||||
save () {
|
||||
for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done
|
||||
echo " "
|
||||
}
|
||||
APP_ARGS=$(save "$@")
|
||||
|
||||
# Collect all arguments for the java command, following the shell quoting and substitution rules
|
||||
eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS"
|
||||
|
||||
# by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong
|
||||
if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then
|
||||
cd "$(dirname "$0")"
|
||||
fi
|
||||
|
||||
exec "$JAVACMD" "$@"
|
84
gradlew.bat
vendored
Normal file
84
gradlew.bat
vendored
Normal file
|
@ -0,0 +1,84 @@
|
|||
@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 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=
|
||||
|
||||
@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 init
|
||||
|
||||
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 init
|
||||
|
||||
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
|
||||
|
||||
:init
|
||||
@rem Get command-line arguments, handling Windows variants
|
||||
|
||||
if not "%OS%" == "Windows_NT" goto win9xME_args
|
||||
|
||||
:win9xME_args
|
||||
@rem Slurp the command line arguments.
|
||||
set CMD_LINE_ARGS=
|
||||
set _SKIP=2
|
||||
|
||||
:win9xME_args_slurp
|
||||
if "x%~1" == "x" goto execute
|
||||
|
||||
set CMD_LINE_ARGS=%*
|
||||
|
||||
: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 %CMD_LINE_ARGS%
|
||||
|
||||
: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
|
504
license/LGPLv2.1.txt
Normal file
504
license/LGPLv2.1.txt
Normal file
|
@ -0,0 +1,504 @@
|
|||
GNU LESSER GENERAL PUBLIC LICENSE
|
||||
Version 2.1, February 1999
|
||||
|
||||
Copyright (C) 1991, 1999 Free Software Foundation, Inc.
|
||||
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
Everyone is permitted to copy and distribute verbatim copies
|
||||
of this license document, but changing it is not allowed.
|
||||
|
||||
(This is the first released version of the Lesser GPL. It also counts
|
||||
as the successor of the GNU Library Public License, version 2, hence
|
||||
the version number 2.1.)
|
||||
|
||||
Preamble
|
||||
|
||||
The licenses for most software are designed to take away your
|
||||
freedom to share and change it. By contrast, the GNU General Public
|
||||
Licenses are intended to guarantee your freedom to share and change
|
||||
free software--to make sure the software is free for all its users.
|
||||
|
||||
This license, the Lesser General Public License, applies to some
|
||||
specially designated software packages--typically libraries--of the
|
||||
Free Software Foundation and other authors who decide to use it. You
|
||||
can use it too, but we suggest you first think carefully about whether
|
||||
this license or the ordinary General Public License is the better
|
||||
strategy to use in any particular case, based on the explanations below.
|
||||
|
||||
When we speak of free software, we are referring to freedom of use,
|
||||
not price. Our General Public Licenses are designed to make sure that
|
||||
you have the freedom to distribute copies of free software (and charge
|
||||
for this service if you wish); that you receive source code or can get
|
||||
it if you want it; that you can change the software and use pieces of
|
||||
it in new free programs; and that you are informed that you can do
|
||||
these things.
|
||||
|
||||
To protect your rights, we need to make restrictions that forbid
|
||||
distributors to deny you these rights or to ask you to surrender these
|
||||
rights. These restrictions translate to certain responsibilities for
|
||||
you if you distribute copies of the library or if you modify it.
|
||||
|
||||
For example, if you distribute copies of the library, whether gratis
|
||||
or for a fee, you must give the recipients all the rights that we gave
|
||||
you. You must make sure that they, too, receive or can get the source
|
||||
code. If you link other code with the library, you must provide
|
||||
complete object files to the recipients, so that they can relink them
|
||||
with the library after making changes to the library and recompiling
|
||||
it. And you must show them these terms so they know their rights.
|
||||
|
||||
We protect your rights with a two-step method: (1) we copyright the
|
||||
library, and (2) we offer you this license, which gives you legal
|
||||
permission to copy, distribute and/or modify the library.
|
||||
|
||||
To protect each distributor, we want to make it very clear that
|
||||
there is no warranty for the free library. Also, if the library is
|
||||
modified by someone else and passed on, the recipients should know
|
||||
that what they have is not the original version, so that the original
|
||||
author's reputation will not be affected by problems that might be
|
||||
introduced by others.
|
||||
|
||||
Finally, software patents pose a constant threat to the existence of
|
||||
any free program. We wish to make sure that a company cannot
|
||||
effectively restrict the users of a free program by obtaining a
|
||||
restrictive license from a patent holder. Therefore, we insist that
|
||||
any patent license obtained for a version of the library must be
|
||||
consistent with the full freedom of use specified in this license.
|
||||
|
||||
Most GNU software, including some libraries, is covered by the
|
||||
ordinary GNU General Public License. This license, the GNU Lesser
|
||||
General Public License, applies to certain designated libraries, and
|
||||
is quite different from the ordinary General Public License. We use
|
||||
this license for certain libraries in order to permit linking those
|
||||
libraries into non-free programs.
|
||||
|
||||
When a program is linked with a library, whether statically or using
|
||||
a shared library, the combination of the two is legally speaking a
|
||||
combined work, a derivative of the original library. The ordinary
|
||||
General Public License therefore permits such linking only if the
|
||||
entire combination fits its criteria of freedom. The Lesser General
|
||||
Public License permits more lax criteria for linking other code with
|
||||
the library.
|
||||
|
||||
We call this license the "Lesser" General Public License because it
|
||||
does Less to protect the user's freedom than the ordinary General
|
||||
Public License. It also provides other free software developers Less
|
||||
of an advantage over competing non-free programs. These disadvantages
|
||||
are the reason we use the ordinary General Public License for many
|
||||
libraries. However, the Lesser license provides advantages in certain
|
||||
special circumstances.
|
||||
|
||||
For example, on rare occasions, there may be a special need to
|
||||
encourage the widest possible use of a certain library, so that it becomes
|
||||
a de-facto standard. To achieve this, non-free programs must be
|
||||
allowed to use the library. A more frequent case is that a free
|
||||
library does the same job as widely used non-free libraries. In this
|
||||
case, there is little to gain by limiting the free library to free
|
||||
software only, so we use the Lesser General Public License.
|
||||
|
||||
In other cases, permission to use a particular library in non-free
|
||||
programs enables a greater number of people to use a large body of
|
||||
free software. For example, permission to use the GNU C Library in
|
||||
non-free programs enables many more people to use the whole GNU
|
||||
operating system, as well as its variant, the GNU/Linux operating
|
||||
system.
|
||||
|
||||
Although the Lesser General Public License is Less protective of the
|
||||
users' freedom, it does ensure that the user of a program that is
|
||||
linked with the Library has the freedom and the wherewithal to run
|
||||
that program using a modified version of the Library.
|
||||
|
||||
The precise terms and conditions for copying, distribution and
|
||||
modification follow. Pay close attention to the difference between a
|
||||
"work based on the library" and a "work that uses the library". The
|
||||
former contains code derived from the library, whereas the latter must
|
||||
be combined with the library in order to run.
|
||||
|
||||
GNU LESSER GENERAL PUBLIC LICENSE
|
||||
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
|
||||
|
||||
0. This License Agreement applies to any software library or other
|
||||
program which contains a notice placed by the copyright holder or
|
||||
other authorized party saying it may be distributed under the terms of
|
||||
this Lesser General Public License (also called "this License").
|
||||
Each licensee is addressed as "you".
|
||||
|
||||
A "library" means a collection of software functions and/or data
|
||||
prepared so as to be conveniently linked with application programs
|
||||
(which use some of those functions and data) to form executables.
|
||||
|
||||
The "Library", below, refers to any such software library or work
|
||||
which has been distributed under these terms. A "work based on the
|
||||
Library" means either the Library or any derivative work under
|
||||
copyright law: that is to say, a work containing the Library or a
|
||||
portion of it, either verbatim or with modifications and/or translated
|
||||
straightforwardly into another language. (Hereinafter, translation is
|
||||
included without limitation in the term "modification".)
|
||||
|
||||
"Source code" for a work means the preferred form of the work for
|
||||
making modifications to it. For a library, complete source code means
|
||||
all the source code for all modules it contains, plus any associated
|
||||
interface definition files, plus the scripts used to control compilation
|
||||
and installation of the library.
|
||||
|
||||
Activities other than copying, distribution and modification are not
|
||||
covered by this License; they are outside its scope. The act of
|
||||
running a program using the Library is not restricted, and output from
|
||||
such a program is covered only if its contents constitute a work based
|
||||
on the Library (independent of the use of the Library in a tool for
|
||||
writing it). Whether that is true depends on what the Library does
|
||||
and what the program that uses the Library does.
|
||||
|
||||
1. You may copy and distribute verbatim copies of the Library's
|
||||
complete source code as you receive it, in any medium, provided that
|
||||
you conspicuously and appropriately publish on each copy an
|
||||
appropriate copyright notice and disclaimer of warranty; keep intact
|
||||
all the notices that refer to this License and to the absence of any
|
||||
warranty; and distribute a copy of this License along with the
|
||||
Library.
|
||||
|
||||
You may charge a fee for the physical act of transferring a copy,
|
||||
and you may at your option offer warranty protection in exchange for a
|
||||
fee.
|
||||
|
||||
2. You may modify your copy or copies of the Library or any portion
|
||||
of it, thus forming a work based on the Library, and copy and
|
||||
distribute such modifications or work under the terms of Section 1
|
||||
above, provided that you also meet all of these conditions:
|
||||
|
||||
a) The modified work must itself be a software library.
|
||||
|
||||
b) You must cause the files modified to carry prominent notices
|
||||
stating that you changed the files and the date of any change.
|
||||
|
||||
c) You must cause the whole of the work to be licensed at no
|
||||
charge to all third parties under the terms of this License.
|
||||
|
||||
d) If a facility in the modified Library refers to a function or a
|
||||
table of data to be supplied by an application program that uses
|
||||
the facility, other than as an argument passed when the facility
|
||||
is invoked, then you must make a good faith effort to ensure that,
|
||||
in the event an application does not supply such function or
|
||||
table, the facility still operates, and performs whatever part of
|
||||
its purpose remains meaningful.
|
||||
|
||||
(For example, a function in a library to compute square roots has
|
||||
a purpose that is entirely well-defined independent of the
|
||||
application. Therefore, Subsection 2d requires that any
|
||||
application-supplied function or table used by this function must
|
||||
be optional: if the application does not supply it, the square
|
||||
root function must still compute square roots.)
|
||||
|
||||
These requirements apply to the modified work as a whole. If
|
||||
identifiable sections of that work are not derived from the Library,
|
||||
and can be reasonably considered independent and separate works in
|
||||
themselves, then this License, and its terms, do not apply to those
|
||||
sections when you distribute them as separate works. But when you
|
||||
distribute the same sections as part of a whole which is a work based
|
||||
on the Library, the distribution of the whole must be on the terms of
|
||||
this License, whose permissions for other licensees extend to the
|
||||
entire whole, and thus to each and every part regardless of who wrote
|
||||
it.
|
||||
|
||||
Thus, it is not the intent of this section to claim rights or contest
|
||||
your rights to work written entirely by you; rather, the intent is to
|
||||
exercise the right to control the distribution of derivative or
|
||||
collective works based on the Library.
|
||||
|
||||
In addition, mere aggregation of another work not based on the Library
|
||||
with the Library (or with a work based on the Library) on a volume of
|
||||
a storage or distribution medium does not bring the other work under
|
||||
the scope of this License.
|
||||
|
||||
3. You may opt to apply the terms of the ordinary GNU General Public
|
||||
License instead of this License to a given copy of the Library. To do
|
||||
this, you must alter all the notices that refer to this License, so
|
||||
that they refer to the ordinary GNU General Public License, version 2,
|
||||
instead of to this License. (If a newer version than version 2 of the
|
||||
ordinary GNU General Public License has appeared, then you can specify
|
||||
that version instead if you wish.) Do not make any other change in
|
||||
these notices.
|
||||
|
||||
Once this change is made in a given copy, it is irreversible for
|
||||
that copy, so the ordinary GNU General Public License applies to all
|
||||
subsequent copies and derivative works made from that copy.
|
||||
|
||||
This option is useful when you wish to copy part of the code of
|
||||
the Library into a program that is not a library.
|
||||
|
||||
4. You may copy and distribute the Library (or a portion or
|
||||
derivative of it, under Section 2) in object code or executable form
|
||||
under the terms of Sections 1 and 2 above provided that you accompany
|
||||
it with the complete corresponding machine-readable source code, which
|
||||
must be distributed under the terms of Sections 1 and 2 above on a
|
||||
medium customarily used for software interchange.
|
||||
|
||||
If distribution of object code is made by offering access to copy
|
||||
from a designated place, then offering equivalent access to copy the
|
||||
source code from the same place satisfies the requirement to
|
||||
distribute the source code, even though third parties are not
|
||||
compelled to copy the source along with the object code.
|
||||
|
||||
5. A program that contains no derivative of any portion of the
|
||||
Library, but is designed to work with the Library by being compiled or
|
||||
linked with it, is called a "work that uses the Library". Such a
|
||||
work, in isolation, is not a derivative work of the Library, and
|
||||
therefore falls outside the scope of this License.
|
||||
|
||||
However, linking a "work that uses the Library" with the Library
|
||||
creates an executable that is a derivative of the Library (because it
|
||||
contains portions of the Library), rather than a "work that uses the
|
||||
library". The executable is therefore covered by this License.
|
||||
Section 6 states terms for distribution of such executables.
|
||||
|
||||
When a "work that uses the Library" uses material from a header file
|
||||
that is part of the Library, the object code for the work may be a
|
||||
derivative work of the Library even though the source code is not.
|
||||
Whether this is true is especially significant if the work can be
|
||||
linked without the Library, or if the work is itself a library. The
|
||||
threshold for this to be true is not precisely defined by law.
|
||||
|
||||
If such an object file uses only numerical parameters, data
|
||||
structure layouts and accessors, and small macros and small inline
|
||||
functions (ten lines or less in length), then the use of the object
|
||||
file is unrestricted, regardless of whether it is legally a derivative
|
||||
work. (Executables containing this object code plus portions of the
|
||||
Library will still fall under Section 6.)
|
||||
|
||||
Otherwise, if the work is a derivative of the Library, you may
|
||||
distribute the object code for the work under the terms of Section 6.
|
||||
Any executables containing that work also fall under Section 6,
|
||||
whether or not they are linked directly with the Library itself.
|
||||
|
||||
6. As an exception to the Sections above, you may also combine or
|
||||
link a "work that uses the Library" with the Library to produce a
|
||||
work containing portions of the Library, and distribute that work
|
||||
under terms of your choice, provided that the terms permit
|
||||
modification of the work for the customer's own use and reverse
|
||||
engineering for debugging such modifications.
|
||||
|
||||
You must give prominent notice with each copy of the work that the
|
||||
Library is used in it and that the Library and its use are covered by
|
||||
this License. You must supply a copy of this License. If the work
|
||||
during execution displays copyright notices, you must include the
|
||||
copyright notice for the Library among them, as well as a reference
|
||||
directing the user to the copy of this License. Also, you must do one
|
||||
of these things:
|
||||
|
||||
a) Accompany the work with the complete corresponding
|
||||
machine-readable source code for the Library including whatever
|
||||
changes were used in the work (which must be distributed under
|
||||
Sections 1 and 2 above); and, if the work is an executable linked
|
||||
with the Library, with the complete machine-readable "work that
|
||||
uses the Library", as object code and/or source code, so that the
|
||||
user can modify the Library and then relink to produce a modified
|
||||
executable containing the modified Library. (It is understood
|
||||
that the user who changes the contents of definitions files in the
|
||||
Library will not necessarily be able to recompile the application
|
||||
to use the modified definitions.)
|
||||
|
||||
b) Use a suitable shared library mechanism for linking with the
|
||||
Library. A suitable mechanism is one that (1) uses at run time a
|
||||
copy of the library already present on the user's computer system,
|
||||
rather than copying library functions into the executable, and (2)
|
||||
will operate properly with a modified version of the library, if
|
||||
the user installs one, as long as the modified version is
|
||||
interface-compatible with the version that the work was made with.
|
||||
|
||||
c) Accompany the work with a written offer, valid for at
|
||||
least three years, to give the same user the materials
|
||||
specified in Subsection 6a, above, for a charge no more
|
||||
than the cost of performing this distribution.
|
||||
|
||||
d) If distribution of the work is made by offering access to copy
|
||||
from a designated place, offer equivalent access to copy the above
|
||||
specified materials from the same place.
|
||||
|
||||
e) Verify that the user has already received a copy of these
|
||||
materials or that you have already sent this user a copy.
|
||||
|
||||
For an executable, the required form of the "work that uses the
|
||||
Library" must include any data and utility programs needed for
|
||||
reproducing the executable from it. However, as a special exception,
|
||||
the materials to be distributed need not include anything that is
|
||||
normally distributed (in either source or binary form) with the major
|
||||
components (compiler, kernel, and so on) of the operating system on
|
||||
which the executable runs, unless that component itself accompanies
|
||||
the executable.
|
||||
|
||||
It may happen that this requirement contradicts the license
|
||||
restrictions of other proprietary libraries that do not normally
|
||||
accompany the operating system. Such a contradiction means you cannot
|
||||
use both them and the Library together in an executable that you
|
||||
distribute.
|
||||
|
||||
7. You may place library facilities that are a work based on the
|
||||
Library side-by-side in a single library together with other library
|
||||
facilities not covered by this License, and distribute such a combined
|
||||
library, provided that the separate distribution of the work based on
|
||||
the Library and of the other library facilities is otherwise
|
||||
permitted, and provided that you do these two things:
|
||||
|
||||
a) Accompany the combined library with a copy of the same work
|
||||
based on the Library, uncombined with any other library
|
||||
facilities. This must be distributed under the terms of the
|
||||
Sections above.
|
||||
|
||||
b) Give prominent notice with the combined library of the fact
|
||||
that part of it is a work based on the Library, and explaining
|
||||
where to find the accompanying uncombined form of the same work.
|
||||
|
||||
8. You may not copy, modify, sublicense, link with, or distribute
|
||||
the Library except as expressly provided under this License. Any
|
||||
attempt otherwise to copy, modify, sublicense, link with, or
|
||||
distribute the Library is void, and will automatically terminate your
|
||||
rights under this License. However, parties who have received copies,
|
||||
or rights, from you under this License will not have their licenses
|
||||
terminated so long as such parties remain in full compliance.
|
||||
|
||||
9. You are not required to accept this License, since you have not
|
||||
signed it. However, nothing else grants you permission to modify or
|
||||
distribute the Library or its derivative works. These actions are
|
||||
prohibited by law if you do not accept this License. Therefore, by
|
||||
modifying or distributing the Library (or any work based on the
|
||||
Library), you indicate your acceptance of this License to do so, and
|
||||
all its terms and conditions for copying, distributing or modifying
|
||||
the Library or works based on it.
|
||||
|
||||
10. Each time you redistribute the Library (or any work based on the
|
||||
Library), the recipient automatically receives a license from the
|
||||
original licensor to copy, distribute, link with or modify the Library
|
||||
subject to these terms and conditions. You may not impose any further
|
||||
restrictions on the recipients' exercise of the rights granted herein.
|
||||
You are not responsible for enforcing compliance by third parties with
|
||||
this License.
|
||||
|
||||
11. If, as a consequence of a court judgment or allegation of patent
|
||||
infringement or for any other reason (not limited to patent issues),
|
||||
conditions are imposed on you (whether by court order, agreement or
|
||||
otherwise) that contradict the conditions of this License, they do not
|
||||
excuse you from the conditions of this License. If you cannot
|
||||
distribute so as to satisfy simultaneously your obligations under this
|
||||
License and any other pertinent obligations, then as a consequence you
|
||||
may not distribute the Library at all. For example, if a patent
|
||||
license would not permit royalty-free redistribution of the Library by
|
||||
all those who receive copies directly or indirectly through you, then
|
||||
the only way you could satisfy both it and this License would be to
|
||||
refrain entirely from distribution of the Library.
|
||||
|
||||
If any portion of this section is held invalid or unenforceable under any
|
||||
particular circumstance, the balance of the section is intended to apply,
|
||||
and the section as a whole is intended to apply in other circumstances.
|
||||
|
||||
It is not the purpose of this section to induce you to infringe any
|
||||
patents or other property right claims or to contest validity of any
|
||||
such claims; this section has the sole purpose of protecting the
|
||||
integrity of the free software distribution system which is
|
||||
implemented by public license practices. Many people have made
|
||||
generous contributions to the wide range of software distributed
|
||||
through that system in reliance on consistent application of that
|
||||
system; it is up to the author/donor to decide if he or she is willing
|
||||
to distribute software through any other system and a licensee cannot
|
||||
impose that choice.
|
||||
|
||||
This section is intended to make thoroughly clear what is believed to
|
||||
be a consequence of the rest of this License.
|
||||
|
||||
12. If the distribution and/or use of the Library is restricted in
|
||||
certain countries either by patents or by copyrighted interfaces, the
|
||||
original copyright holder who places the Library under this License may add
|
||||
an explicit geographical distribution limitation excluding those countries,
|
||||
so that distribution is permitted only in or among countries not thus
|
||||
excluded. In such case, this License incorporates the limitation as if
|
||||
written in the body of this License.
|
||||
|
||||
13. The Free Software Foundation may publish revised and/or new
|
||||
versions of the Lesser General Public License from time to time.
|
||||
Such new versions will be similar in spirit to the present version,
|
||||
but may differ in detail to address new problems or concerns.
|
||||
|
||||
Each version is given a distinguishing version number. If the Library
|
||||
specifies a version number of this License which applies to it and
|
||||
"any later version", you have the option of following the terms and
|
||||
conditions either of that version or of any later version published by
|
||||
the Free Software Foundation. If the Library does not specify a
|
||||
license version number, you may choose any version ever published by
|
||||
the Free Software Foundation.
|
||||
|
||||
14. If you wish to incorporate parts of the Library into other free
|
||||
programs whose distribution conditions are incompatible with these,
|
||||
write to the author to ask for permission. For software which is
|
||||
copyrighted by the Free Software Foundation, write to the Free
|
||||
Software Foundation; we sometimes make exceptions for this. Our
|
||||
decision will be guided by the two goals of preserving the free status
|
||||
of all derivatives of our free software and of promoting the sharing
|
||||
and reuse of software generally.
|
||||
|
||||
NO WARRANTY
|
||||
|
||||
15. BECAUSE THE LIBRARY IS LICENSED FREE OF CHARGE, THERE IS NO
|
||||
WARRANTY FOR THE LIBRARY, TO THE EXTENT PERMITTED BY APPLICABLE LAW.
|
||||
EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR
|
||||
OTHER PARTIES PROVIDE THE LIBRARY "AS IS" WITHOUT WARRANTY OF ANY
|
||||
KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE
|
||||
LIBRARY IS WITH YOU. SHOULD THE LIBRARY PROVE DEFECTIVE, YOU ASSUME
|
||||
THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
|
||||
|
||||
16. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN
|
||||
WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY
|
||||
AND/OR REDISTRIBUTE THE LIBRARY AS PERMITTED ABOVE, BE LIABLE TO YOU
|
||||
FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR
|
||||
CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE
|
||||
LIBRARY (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING
|
||||
RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A
|
||||
FAILURE OF THE LIBRARY TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF
|
||||
SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH
|
||||
DAMAGES.
|
||||
|
||||
END OF TERMS AND CONDITIONS
|
||||
|
||||
How to Apply These Terms to Your New Libraries
|
||||
|
||||
If you develop a new library, and you want it to be of the greatest
|
||||
possible use to the public, we recommend making it free software that
|
||||
everyone can redistribute and change. You can do so by permitting
|
||||
redistribution under these terms (or, alternatively, under the terms of the
|
||||
ordinary General Public License).
|
||||
|
||||
To apply these terms, attach the following notices to the library. It is
|
||||
safest to attach them to the start of each source file to most effectively
|
||||
convey the exclusion of warranty; and each file should have at least the
|
||||
"copyright" line and a pointer to where the full notice is found.
|
||||
|
||||
{description}
|
||||
Copyright (C) {year} {fullname}
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2.1 of the License, or (at your option) any later version.
|
||||
|
||||
This library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with this library; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
|
||||
USA
|
||||
|
||||
Also add information on how to contact you by electronic and paper mail.
|
||||
|
||||
You should also get your employer (if you work as a programmer) or your
|
||||
school, if any, to sign a "copyright disclaimer" for the library, if
|
||||
necessary. Here is a sample; alter the names:
|
||||
|
||||
Yoyodyne, Inc., hereby disclaims all copyright interest in the
|
||||
library `Frob' (a library for tweaking knobs) written by James Random
|
||||
Hacker.
|
||||
|
||||
{signature of Ty Coon}, 1 April 1990
|
||||
Ty Coon, President of Vice
|
||||
|
||||
That's all there is to it!
|
20
license/copyright.txt
Normal file
20
license/copyright.txt
Normal file
|
@ -0,0 +1,20 @@
|
|||
paperweight is a Gradle plugin for the PaperMC project. It uses
|
||||
some code and systems originally from ForgeGradle.
|
||||
|
||||
Copyright (C) 2020 Kyle Wood
|
||||
Copyright (C) 2018 Forge Development LLC
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2.1 of the License, or (at your option) any later version.
|
||||
|
||||
This library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with this library; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
|
||||
USA
|
81
readme.md
Normal file
81
readme.md
Normal file
|
@ -0,0 +1,81 @@
|
|||
How to use this for testing:
|
||||
|
||||
Install this plugin to Maven Local:
|
||||
|
||||
```bash
|
||||
./gradlew install
|
||||
```
|
||||
|
||||
Clone new Paper repo and checkout the `ver/1.16` branch.
|
||||
|
||||
Copy the `mcp/` directory from the (now very old) `feature/mcp` branch into your working directory. I have no idea
|
||||
if any of the values in this directory are still correct or still apply to 1.16, and they almost certainly don't,
|
||||
but it's a good starting off point to test with until the work can be done to re-create these files for 1.16.
|
||||
|
||||
Create a file called `build.gradle.kts` in the root project directy and copy in this text:
|
||||
```kotlin
|
||||
plugins {
|
||||
id("com.github.johnrengelman.shadow") version "6.0.0" apply false
|
||||
id("io.papermc.paperweight") version "1.0.0-SNAPSHOT"
|
||||
}
|
||||
|
||||
group = "com.destroystokyo.paper"
|
||||
version = "1.16.1-R0.1-SNAPSHOT"
|
||||
|
||||
subprojects {
|
||||
apply(plugin = "java")
|
||||
apply(plugin = "com.github.johnrengelman.shadow")
|
||||
|
||||
tasks.withType<JavaCompile>().configureEach {
|
||||
options.encoding = "UTF-8"
|
||||
}
|
||||
|
||||
repositories {
|
||||
mavenCentral()
|
||||
maven("https://oss.sonatype.org/content/groups/public/")
|
||||
maven("https://repo.md-5.net/content/repositories/releases/")
|
||||
maven("https://ci.emc.gs/nexus/content/groups/aikar/")
|
||||
maven("https://papermc.io/repo/repository/maven-public/")
|
||||
}
|
||||
}
|
||||
|
||||
paperweight {
|
||||
minecraftVersion.set("1.16.1")
|
||||
mcpVersion.set("20200625.160719")
|
||||
mcpMappingsChannel.set("snapshot")
|
||||
mcpMappingsVersion.set("20200702-1.15.1")
|
||||
}
|
||||
```
|
||||
|
||||
Now create a file called `settings.gradle.kts` in the root project directory and copy in this text:
|
||||
```kotlin
|
||||
pluginManagement {
|
||||
repositories {
|
||||
mavenLocal()
|
||||
mavenCentral()
|
||||
jcenter()
|
||||
maven("https://oss.sonatype.org/content/repositories/snapshots/")
|
||||
maven("https://files.minecraftforge.net/maven/")
|
||||
gradlePluginPortal()
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
Now create the Gradle wrapper:
|
||||
```bash
|
||||
gradle wrapper --gradle-version=6.5
|
||||
```
|
||||
|
||||
From this point you can now test the plugin by installing it to Maven Local (`./gradlew install`) and then running
|
||||
the task you want to test in your new MCP Paper repo.
|
||||
|
||||
Other helpful things that you will probably want to do:
|
||||
|
||||
Add the following files to the `.gitignore` file in the Paper repo:
|
||||
```
|
||||
.gradle/
|
||||
build/
|
||||
```
|
||||
|
||||
Either delete or rename the `pom.xml` file to reduce the chance of IntelliJ getting confused
|
||||
(if you decide to open the project in IntelliJ).
|
1
settings.gradle.kts
Normal file
1
settings.gradle.kts
Normal file
|
@ -0,0 +1 @@
|
|||
rootProject.name = "paperweight"
|
342
src/main/kotlin/Paperweight.kt
Normal file
342
src/main/kotlin/Paperweight.kt
Normal file
|
@ -0,0 +1,342 @@
|
|||
/*
|
||||
* paperweight is a Gradle plugin for the PaperMC project. It uses
|
||||
* some code and systems originally from ForgeGradle.
|
||||
*
|
||||
* Copyright (C) 2020 Kyle Wood
|
||||
* Copyright (C) 2018 Forge Development LLC
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
|
||||
* USA
|
||||
*/
|
||||
|
||||
@file:Suppress("DuplicatedCode")
|
||||
|
||||
package io.papermc.paperweight
|
||||
|
||||
import io.papermc.paperweight.ext.PaperweightExtension
|
||||
import io.papermc.paperweight.tasks.ApplyDiffPatches
|
||||
import io.papermc.paperweight.tasks.ApplyGitPatches
|
||||
import io.papermc.paperweight.tasks.DecompileVanillaJar
|
||||
import io.papermc.paperweight.tasks.DownloadServerJar
|
||||
import io.papermc.paperweight.tasks.ExtractMcpData
|
||||
import io.papermc.paperweight.tasks.ExtractMcpMappings
|
||||
import io.papermc.paperweight.tasks.GatherBuildData
|
||||
import io.papermc.paperweight.tasks.GenerateSpigotSrgs
|
||||
import io.papermc.paperweight.tasks.GenerateSrgs
|
||||
import io.papermc.paperweight.tasks.GetRemoteJsons
|
||||
import io.papermc.paperweight.tasks.PatchMcpCsv
|
||||
import io.papermc.paperweight.tasks.RemapSources
|
||||
import io.papermc.paperweight.tasks.RemapVanillaJarSpigot
|
||||
import io.papermc.paperweight.tasks.RemapVanillaJarSrg
|
||||
import io.papermc.paperweight.tasks.RunForgeFlower
|
||||
import io.papermc.paperweight.tasks.RunMcInjector
|
||||
import io.papermc.paperweight.tasks.SetupMcpDependencies
|
||||
import io.papermc.paperweight.tasks.SetupSpigotDependencies
|
||||
import io.papermc.paperweight.tasks.WriteLibrariesFile
|
||||
import io.papermc.paperweight.util.Constants
|
||||
import io.papermc.paperweight.util.Constants.paperTaskOutput
|
||||
import io.papermc.paperweight.util.Git
|
||||
import io.papermc.paperweight.tasks.RemapSrgSources
|
||||
import io.papermc.paperweight.util.cache
|
||||
import io.papermc.paperweight.util.ext
|
||||
import org.gradle.api.Plugin
|
||||
import org.gradle.api.Project
|
||||
import org.gradle.api.Task
|
||||
import org.gradle.api.artifacts.ConfigurationContainer
|
||||
import org.gradle.api.provider.Provider
|
||||
import org.gradle.api.tasks.TaskProvider
|
||||
import org.gradle.api.tasks.bundling.Zip
|
||||
import org.gradle.kotlin.dsl.get
|
||||
import org.gradle.kotlin.dsl.maven
|
||||
import org.gradle.kotlin.dsl.register
|
||||
import util.BuildDataInfo
|
||||
import java.io.File
|
||||
|
||||
class Paperweight : Plugin<Project> {
|
||||
override fun apply(target: Project) {
|
||||
target.extensions.create(Constants.EXTENSION, PaperweightExtension::class.java, target)
|
||||
|
||||
createConfigurations(target)
|
||||
setupMcpDeps(target)
|
||||
|
||||
createTasks(target)
|
||||
|
||||
target.tasks.register("cleanCache").configure {
|
||||
destroyables.register(target.cache)
|
||||
doLast {
|
||||
target.delete(target.cache)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun createConfigurations(project: Project) {
|
||||
project.repositories.apply {
|
||||
maven("https://oss.sonatype.org/content/repositories/snapshots/")
|
||||
maven("https://hub.spigotmc.org/nexus/content/groups/public/")
|
||||
maven {
|
||||
name = "forge"
|
||||
url = project.uri(Constants.FORGE_MAVEN_URL)
|
||||
metadataSources {
|
||||
artifact()
|
||||
}
|
||||
}
|
||||
mavenCentral()
|
||||
maven {
|
||||
name = "minecraft"
|
||||
url = project.uri(Constants.MC_LIBRARY_URL)
|
||||
}
|
||||
}
|
||||
|
||||
project.configurations.register(Constants.MCP_MAPPINGS_CONFIG)
|
||||
project.configurations.register(Constants.MCP_DATA_CONFIG)
|
||||
project.configurations.register(Constants.SPIGOT_DEP_CONFIG)
|
||||
project.configurations.create(Constants.MINECRAFT_DEP_CONFIG)
|
||||
project.configurations.register(Constants.FORGE_FLOWER_CONFIG)
|
||||
project.configurations.create(Constants.MCINJECT_CONFIG)
|
||||
}
|
||||
|
||||
private fun setupMcpDeps(project: Project) {
|
||||
project.dependencies.add(Constants.MCP_DATA_CONFIG, project.provider {
|
||||
mapOf(
|
||||
"group" to "de.oceanlabs.mcp",
|
||||
"name" to "mcp_config",
|
||||
"version" to "${project.ext.mcpMinecraftVersion.get()}-${project.ext.mcpVersion.get()}",
|
||||
"ext" to "zip"
|
||||
)
|
||||
})
|
||||
|
||||
project.dependencies.add(Constants.MCP_MAPPINGS_CONFIG, project.provider {
|
||||
mapOf(
|
||||
"group" to "de.oceanlabs.mcp",
|
||||
"name" to "mcp_${project.ext.mcpMappingsChannel.get()}",
|
||||
"version" to project.ext.mcpMappingsVersion.get(),
|
||||
"ext" to "zip"
|
||||
)
|
||||
})
|
||||
}
|
||||
|
||||
// Types are specified in this method to hopefully improve editor performance a little, though I don't think it helps
|
||||
private fun createTasks(project: Project) {
|
||||
val cache: File = project.cache
|
||||
val extension: PaperweightExtension = project.ext
|
||||
val configs: ConfigurationContainer = project.configurations
|
||||
|
||||
val initGitSubmodules: TaskProvider<Task> = project.tasks.register("initGitSubmodules") {
|
||||
outputs.upToDateWhen { false }
|
||||
doLast {
|
||||
Git(project.projectDir)("submodule", "update", "--init").execute()
|
||||
}
|
||||
}
|
||||
val gatherBuildData: TaskProvider<GatherBuildData> = project.tasks.register<GatherBuildData>("gatherBuildData") {
|
||||
dependsOn(initGitSubmodules)
|
||||
buildDataInfoFile.set(extension.craftBukkit.buildDataInfo)
|
||||
}
|
||||
val buildDataInfo: Provider<BuildDataInfo> = gatherBuildData.flatMap { it.buildDataInfo }
|
||||
|
||||
val extractMcpData: TaskProvider<ExtractMcpData> = project.tasks.register<ExtractMcpData>("extractMcpData") {
|
||||
config.set(Constants.MCP_DATA_CONFIG)
|
||||
outputDir.set(cache.resolve(Constants.MCP_DATA_DIR))
|
||||
}
|
||||
|
||||
val setupMcpDependencies: TaskProvider<SetupMcpDependencies> = project.tasks.register<SetupMcpDependencies>("setupMcpDependencies") {
|
||||
configFile.set(extractMcpData.flatMap { it.configJson })
|
||||
forgeFlowerConfig.set(Constants.FORGE_FLOWER_CONFIG)
|
||||
mcInjectorConfig.set(Constants.MCINJECT_CONFIG)
|
||||
}
|
||||
|
||||
val extractMcpMappings: TaskProvider<ExtractMcpMappings> = project.tasks.register<ExtractMcpMappings>("extractMcpMappings") {
|
||||
config.set(Constants.MCP_MAPPINGS_CONFIG)
|
||||
outputDir.set(cache.resolve(Constants.MCP_MAPPINGS_DIR))
|
||||
}
|
||||
|
||||
val getRemoteJsons: TaskProvider<GetRemoteJsons> = project.tasks.register<GetRemoteJsons>("getRemoteJsons") {
|
||||
config.set(Constants.MINECRAFT_DEP_CONFIG)
|
||||
}
|
||||
|
||||
val mcpRewrites: TaskProvider<PatchMcpCsv> = project.tasks.register<PatchMcpCsv>("mcpRewrites") {
|
||||
fieldsCsv.set(extractMcpMappings.flatMap { it.fieldsCsv })
|
||||
methodsCsv.set(extractMcpMappings.flatMap { it.methodsCsv })
|
||||
paramsCsv.set(extractMcpMappings.flatMap { it.paramsCsv })
|
||||
changesFile.set(extension.paper.mcpRewritesFile)
|
||||
|
||||
paperFieldCsv.set(cache.resolve(Constants.PAPER_FIELDS_CSV))
|
||||
paperMethodCsv.set(cache.resolve(Constants.PAPER_METHODS_CSV))
|
||||
paperParamCsv.set(cache.resolve(Constants.PAPER_PARAMS_CSV))
|
||||
}
|
||||
|
||||
val generateSrgs: TaskProvider<GenerateSrgs> = project.tasks.register<GenerateSrgs>("generateSrgs") {
|
||||
methodsCsv.set(mcpRewrites.flatMap { it.paperMethodCsv })
|
||||
fieldsCsv.set(mcpRewrites.flatMap { it.paperFieldCsv })
|
||||
configFile.set(extractMcpData.flatMap { it.configJson })
|
||||
|
||||
notchToSrg.set(cache.resolve(Constants.NOTCH_TO_SRG))
|
||||
notchToMcp.set(cache.resolve(Constants.NOTCH_TO_MCP))
|
||||
srgToNotch.set(cache.resolve(Constants.SRG_TO_NOTCH))
|
||||
srgToMcp.set(cache.resolve(Constants.SRG_TO_MCP))
|
||||
mcpToNotch.set(cache.resolve(Constants.MCP_TO_NOTCH))
|
||||
mcpToSrg.set(cache.resolve(Constants.MCP_TO_SRG))
|
||||
}
|
||||
|
||||
val generateSpigotSrgs: TaskProvider<GenerateSpigotSrgs> = project.tasks.register<GenerateSpigotSrgs>("generateSpigotSrgs") {
|
||||
notchToSrg.set(generateSrgs.flatMap { it.notchToSrg })
|
||||
srgToMcp.set(generateSrgs.flatMap { it.srgToMcp })
|
||||
classMappings.set(extension.craftBukkit.mappingsDir.file(buildDataInfo.map { it.classMappings }))
|
||||
memberMappings.set(extension.craftBukkit.mappingsDir.file(buildDataInfo.map { it.memberMappings }))
|
||||
packageMappings.set(extension.craftBukkit.mappingsDir.file(buildDataInfo.map { it.packageMappings }))
|
||||
|
||||
spigotToSrg.set(cache.resolve(Constants.SPIGOT_TO_SRG))
|
||||
spigotToMcp.set(cache.resolve(Constants.SPIGOT_TO_MCP))
|
||||
spigotToNotch.set(cache.resolve(Constants.SPIGOT_TO_NOTCH))
|
||||
srgToSpigot.set(cache.resolve(Constants.SRG_TO_SPIGOT))
|
||||
mcpToSpigot.set(cache.resolve(Constants.MCP_TO_SPIGOT))
|
||||
notchToSpigot.set(cache.resolve(Constants.NOTCH_TO_SPIGOT))
|
||||
}
|
||||
|
||||
val downloadServerJar: TaskProvider<DownloadServerJar> = project.tasks.register<DownloadServerJar>("downloadServerJar") {
|
||||
dependsOn(gatherBuildData)
|
||||
downloadUrl.set(buildDataInfo.map { it.serverUrl })
|
||||
hash.set(buildDataInfo.map { it.minecraftHash })
|
||||
}
|
||||
|
||||
val filterVanillaJar: TaskProvider<Zip> = project.tasks.register<Zip>("filterVanillaJar") {
|
||||
dependsOn(downloadServerJar) // the from() block below doesn't set up this dependency
|
||||
archiveFileName.set("filterVanillaJar.jar")
|
||||
destinationDirectory.set(cache.resolve(Constants.TASK_CACHE))
|
||||
|
||||
from(project.zipTree(downloadServerJar.flatMap { it.outputJar })) {
|
||||
include("/*.class")
|
||||
include("/net/minecraft/**")
|
||||
}
|
||||
}
|
||||
|
||||
val remapVanillaJar: TaskProvider<RemapVanillaJarSpigot> = project.tasks.register<RemapVanillaJarSpigot>("remapVanillaJar") {
|
||||
inputJar.set(project.layout.file(filterVanillaJar.map { it.outputs.files.singleFile }))
|
||||
|
||||
classMappings.set(extension.craftBukkit.mappingsDir.file(buildDataInfo.map { it.classMappings }))
|
||||
memberMappings.set(extension.craftBukkit.mappingsDir.file(buildDataInfo.map { it.memberMappings }))
|
||||
packageMappings.set(extension.craftBukkit.mappingsDir.file(buildDataInfo.map { it.packageMappings }))
|
||||
accessTransformers.set(extension.craftBukkit.mappingsDir.file(buildDataInfo.map { it.accessTransforms }))
|
||||
|
||||
workDirName.set(extension.craftBukkit.buildDataInfo.asFile.map { it.parentFile.parentFile.name })
|
||||
|
||||
specialSourceJar.set(extension.craftBukkit.specialSourceJar)
|
||||
specialSource2Jar.set(extension.craftBukkit.specialSource2Jar)
|
||||
|
||||
classMapCommand.set(buildDataInfo.map { it.classMapCommand })
|
||||
memberMapCommand.set(buildDataInfo.map { it.memberMapCommand })
|
||||
finalMapCommand.set(buildDataInfo.map { it.finalMapCommand })
|
||||
}
|
||||
|
||||
val decompileVanillaJarSpigot: TaskProvider<DecompileVanillaJar> = project.tasks.register<DecompileVanillaJar>("decompileVanillaJarSpigot") {
|
||||
inputJar.set(remapVanillaJar.flatMap { it.outputJar })
|
||||
fernFlowerJar.set(extension.craftBukkit.fernFlowerJar)
|
||||
decompileCommand.set(buildDataInfo.map { it.decompileCommand })
|
||||
}
|
||||
|
||||
val patchCraftBukkit: TaskProvider<ApplyDiffPatches> = project.tasks.register<ApplyDiffPatches>("patchCraftBukkit") {
|
||||
sourceJar.set(decompileVanillaJarSpigot.flatMap { it.outputJar })
|
||||
sourceBasePath.set("net/minecraft/server")
|
||||
branch.set("patched")
|
||||
patchDir.set(extension.craftBukkit.patchDir)
|
||||
|
||||
outputDir.set(extension.craftBukkit.craftBukkitDir)
|
||||
}
|
||||
|
||||
val patchSpigotApi: TaskProvider<ApplyGitPatches> = project.tasks.register<ApplyGitPatches>("patchSpigotApi") {
|
||||
branch.set("HEAD")
|
||||
upstreamBranch.set("upstream")
|
||||
upstream.set(extension.craftBukkit.bukkitDir)
|
||||
patchDir.set(extension.spigot.bukkitPatchDir)
|
||||
|
||||
outputDir.set(extension.spigot.spigotApiDir)
|
||||
}
|
||||
|
||||
val patchSpigotServer: TaskProvider<ApplyGitPatches> = project.tasks.register<ApplyGitPatches>("patchSpigotServer") {
|
||||
branch.set(patchCraftBukkit.flatMap { it.branch })
|
||||
upstreamBranch.set("upstream")
|
||||
upstream.set(patchCraftBukkit.flatMap { it.outputDir })
|
||||
patchDir.set(extension.spigot.craftBukkitPatchDir)
|
||||
|
||||
outputDir.set(extension.spigot.spigotServerDir)
|
||||
}
|
||||
|
||||
val patchSpigot: TaskProvider<Task> = project.tasks.register("patchSpigot") {
|
||||
dependsOn(patchSpigotApi, patchSpigotServer)
|
||||
}
|
||||
|
||||
val setupSpigotDependencies: TaskProvider<SetupSpigotDependencies> = project.tasks.register<SetupSpigotDependencies>("setupSpigotDependencies") {
|
||||
dependsOn(patchSpigot)
|
||||
spigotApi.set(patchSpigotApi.flatMap { it.outputDir })
|
||||
spigotServer.set(patchSpigotServer.flatMap { it.outputDir })
|
||||
configurationName.set(Constants.SPIGOT_DEP_CONFIG)
|
||||
}
|
||||
|
||||
val remapVanillaJarSrg: TaskProvider<RemapVanillaJarSrg> = project.tasks.register<RemapVanillaJarSrg>("remapVanillaJarSrg") {
|
||||
inputJar.set(project.layout.file(filterVanillaJar.map { it.outputs.files.singleFile }))
|
||||
mappings.set(generateSrgs.flatMap { it.notchToSrg })
|
||||
}
|
||||
|
||||
val remapSpigotSources: TaskProvider<RemapSources> = project.tasks.register<RemapSources>("remapSpigotSources") {
|
||||
spigotServerDir.set(patchSpigotServer.flatMap { it.outputDir })
|
||||
spigotApiDir.set(patchSpigotApi.flatMap { it.outputDir })
|
||||
spigotToSrg.set(generateSpigotSrgs.flatMap { it.spigotToSrg })
|
||||
vanillaJar.set(downloadServerJar.flatMap { it.outputJar })
|
||||
vanillaRemappedSpigotJar.set(remapVanillaJar.flatMap { it.outputJar })
|
||||
vanillaRemappedSrgJar.set(remapVanillaJarSrg.flatMap { it.outputJar })
|
||||
configuration.set(setupSpigotDependencies.flatMap { it.configurationName })
|
||||
configFile.set(extractMcpData.flatMap { it.configJson })
|
||||
|
||||
generatedAt.set(cache.resolve(paperTaskOutput("at")))
|
||||
}
|
||||
|
||||
val remapSrgSourcesSpigot: TaskProvider<RemapSrgSources> = project.tasks.register<RemapSrgSources>("remapSrgSourcesSpigot") {
|
||||
inputZip.set(remapSpigotSources.flatMap { it.outputZip })
|
||||
methodsCsv.set(mcpRewrites.flatMap { it.methodsCsv })
|
||||
fieldsCsv.set(mcpRewrites.flatMap { it.fieldsCsv })
|
||||
paramsCsv.set(mcpRewrites.flatMap { it.paramsCsv })
|
||||
}
|
||||
|
||||
val injectVanillaJarForge: TaskProvider<RunMcInjector> = project.tasks.register<RunMcInjector>("injectVanillaJarForge") {
|
||||
dependsOn(setupMcpDependencies)
|
||||
configuration.set(setupMcpDependencies.flatMap { it.mcInjectorConfig })
|
||||
inputJar.set(remapVanillaJarSrg.flatMap { it.outputJar })
|
||||
configFile.set(extractMcpData.flatMap { it.configJson })
|
||||
}
|
||||
|
||||
val writeLibrariesFile: TaskProvider<WriteLibrariesFile> = project.tasks.register<WriteLibrariesFile>("writeLibrariesFile") {
|
||||
inputFiles.set(getRemoteJsons.flatMap { it.config.map { conf -> configs[conf].resolve() } })
|
||||
}
|
||||
|
||||
val decompileVanillaJarForge: TaskProvider<RunForgeFlower> = project.tasks.register<RunForgeFlower>("decompileVanillaJarForge") {
|
||||
dependsOn(setupMcpDependencies)
|
||||
configuration.set(setupMcpDependencies.flatMap { it.forgeFlowerConfig })
|
||||
inputJar.set(injectVanillaJarForge.flatMap { it.outputJar })
|
||||
libraries.set(writeLibrariesFile.flatMap { it.outputFile })
|
||||
configFile.set(extractMcpData.flatMap { it.configJson })
|
||||
}
|
||||
|
||||
// val applyMcpPatches: TaskProvider<ApplyMcpPatches> = project.tasks.register<ApplyMcpPatches>("applyMcpPatches") {
|
||||
// inputZips.add(ZipTarget.base(decompileVanillaJarForge.flatMap { it.outputJar }))
|
||||
// serverPatchDir.set(extractMcpData.flatMap { it.patches })
|
||||
// }
|
||||
//
|
||||
// val remapSrgSourcesSpigotVanilla: TaskProvider<RemapSrgSources> = project.tasks.register<RemapSrgSources>("remapSrgSourcesSpigotVanilla") {
|
||||
// inputZips.add(ZipTarget.base(applyMcpPatches.flatMap { outputZip }))
|
||||
// methodsCsv.set(mcpRewrites.flatMap { methodsCsv })
|
||||
// fieldsCsv.set(mcpRewrites.flatMap { fieldsCsv })
|
||||
// paramsCsv.set(mcpRewrites.flatMap { paramsCsv })
|
||||
// }
|
||||
}
|
||||
}
|
29
src/main/kotlin/PaperweightException.kt
Normal file
29
src/main/kotlin/PaperweightException.kt
Normal file
|
@ -0,0 +1,29 @@
|
|||
/*
|
||||
* paperweight is a Gradle plugin for the PaperMC project. It uses
|
||||
* some code and systems originally from ForgeGradle.
|
||||
*
|
||||
* Copyright (C) 2020 Kyle Wood
|
||||
* Copyright (C) 2018 Forge Development LLC
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
|
||||
* USA
|
||||
*/
|
||||
|
||||
package io.papermc.paperweight
|
||||
|
||||
class PaperweightException : Exception {
|
||||
constructor(message: String): super(message)
|
||||
constructor(message: String, cause: Throwable): super(message, cause)
|
||||
}
|
39
src/main/kotlin/ext/CraftBukkitExtension.kt
Normal file
39
src/main/kotlin/ext/CraftBukkitExtension.kt
Normal file
|
@ -0,0 +1,39 @@
|
|||
/*
|
||||
* paperweight is a Gradle plugin for the PaperMC project. It uses
|
||||
* some code and systems originally from ForgeGradle.
|
||||
*
|
||||
* Copyright (C) 2020 Kyle Wood
|
||||
* Copyright (C) 2018 Forge Development LLC
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
|
||||
* USA
|
||||
*/
|
||||
|
||||
package io.papermc.paperweight.ext
|
||||
|
||||
import org.gradle.api.Project
|
||||
import org.gradle.api.file.DirectoryProperty
|
||||
import org.gradle.api.file.RegularFileProperty
|
||||
|
||||
open class CraftBukkitExtension(project: Project) {
|
||||
val bukkitDir: DirectoryProperty = project.dirWithDefault("work/Bukkit")
|
||||
var craftBukkitDir: DirectoryProperty = project.dirWithDefault("work/CraftBukkit")
|
||||
var patchDir: DirectoryProperty = project.dirWithDefault("work/CraftBukkit/nms-patches")
|
||||
var mappingsDir: DirectoryProperty = project.dirWithDefault("work/BuildData/mappings")
|
||||
var buildDataInfo: RegularFileProperty = project.fileWithDefault("work/BuildData/info.json")
|
||||
var fernFlowerJar: RegularFileProperty = project.fileWithDefault("work/BuildData/bin/fernflower.jar")
|
||||
var specialSourceJar: RegularFileProperty = project.fileWithDefault("work/BuildData/bin/SpecialSource.jar")
|
||||
var specialSource2Jar: RegularFileProperty = project.fileWithDefault("work/BuildData/bin/SpecialSource-2.jar")
|
||||
}
|
53
src/main/kotlin/ext/PaperExtension.kt
Normal file
53
src/main/kotlin/ext/PaperExtension.kt
Normal file
|
@ -0,0 +1,53 @@
|
|||
/*
|
||||
* paperweight is a Gradle plugin for the PaperMC project. It uses
|
||||
* some code and systems originally from ForgeGradle.
|
||||
*
|
||||
* Copyright (C) 2020 Kyle Wood
|
||||
* Copyright (C) 2018 Forge Development LLC
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
|
||||
* USA
|
||||
*/
|
||||
|
||||
package io.papermc.paperweight.ext
|
||||
|
||||
import org.gradle.api.Project
|
||||
import org.gradle.api.file.RegularFileProperty
|
||||
import org.gradle.api.provider.Property
|
||||
import org.gradle.kotlin.dsl.property
|
||||
|
||||
open class PaperExtension(project: Project) {
|
||||
val spigotApiPatchDir: Property<String> = project.objects.property<String>().convention("Spigot-API-Patches")
|
||||
val spigotServerPatchDir: Property<String> = project.objects.property<String>().convention("Spigot-Server-Patches")
|
||||
val paperApiDir: Property<String> = project.objects.property<String>().convention("Paper-API")
|
||||
val paperServerDir: Property<String> = project.objects.property<String>().convention("Paper-Server")
|
||||
|
||||
val mcpRewritesFile: RegularFileProperty = project.fileWithDefault("mcp/mcp-rewrites.txt")
|
||||
val preMapSrgFile: RegularFileProperty = project.fileWithDefault("mcp/paper.srg")
|
||||
val removeListFile: RegularFileProperty = project.fileWithDefault("mcp/remove-list.txt")
|
||||
val memberMoveListFile: RegularFileProperty = project.fileWithDefault("mcp/member-moves.txt")
|
||||
|
||||
init {
|
||||
spigotApiPatchDir.disallowUnsafeRead()
|
||||
spigotServerPatchDir.disallowUnsafeRead()
|
||||
paperApiDir.disallowUnsafeRead()
|
||||
paperServerDir.disallowUnsafeRead()
|
||||
|
||||
mcpRewritesFile.disallowUnsafeRead()
|
||||
preMapSrgFile.disallowUnsafeRead()
|
||||
removeListFile.disallowUnsafeRead()
|
||||
memberMoveListFile.disallowUnsafeRead()
|
||||
}
|
||||
}
|
62
src/main/kotlin/ext/PaperweightExtension.kt
Normal file
62
src/main/kotlin/ext/PaperweightExtension.kt
Normal file
|
@ -0,0 +1,62 @@
|
|||
/*
|
||||
* paperweight is a Gradle plugin for the PaperMC project. It uses
|
||||
* some code and systems originally from ForgeGradle.
|
||||
*
|
||||
* Copyright (C) 2020 Kyle Wood
|
||||
* Copyright (C) 2018 Forge Development LLC
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
|
||||
* USA
|
||||
*/
|
||||
|
||||
package io.papermc.paperweight.ext
|
||||
|
||||
import org.gradle.api.Action
|
||||
import org.gradle.api.Project
|
||||
import org.gradle.api.provider.Property
|
||||
import org.gradle.kotlin.dsl.property
|
||||
|
||||
open class PaperweightExtension(project: Project) {
|
||||
|
||||
val minecraftVersion: Property<String> = project.objects.property()
|
||||
val mcpMinecraftVersion: Property<String> = project.objects.property<String>().convention(minecraftVersion)
|
||||
val mcpVersion: Property<String> = project.objects.property()
|
||||
val mcpMappingsChannel: Property<String> = project.objects.property()
|
||||
val mcpMappingsVersion: Property<String> = project.objects.property()
|
||||
|
||||
val craftBukkit = CraftBukkitExtension(project)
|
||||
val spigot = SpigotExtension(project)
|
||||
val paper = PaperExtension(project)
|
||||
|
||||
init {
|
||||
minecraftVersion.disallowUnsafeRead()
|
||||
mcpMinecraftVersion.disallowUnsafeRead()
|
||||
mcpVersion.disallowUnsafeRead()
|
||||
mcpMappingsChannel.disallowUnsafeRead()
|
||||
mcpMappingsVersion.disallowUnsafeRead()
|
||||
}
|
||||
|
||||
fun craftBukkit(action: Action<in CraftBukkitExtension>) {
|
||||
action.execute(craftBukkit)
|
||||
}
|
||||
|
||||
fun spigot(action: Action<in SpigotExtension>) {
|
||||
action.execute(spigot)
|
||||
}
|
||||
|
||||
fun paper(action: Action<in PaperExtension>) {
|
||||
action.execute(paper)
|
||||
}
|
||||
}
|
43
src/main/kotlin/ext/SpigotExtension.kt
Normal file
43
src/main/kotlin/ext/SpigotExtension.kt
Normal file
|
@ -0,0 +1,43 @@
|
|||
/*
|
||||
* paperweight is a Gradle plugin for the PaperMC project. It uses
|
||||
* some code and systems originally from ForgeGradle.
|
||||
*
|
||||
* Copyright (C) 2020 Kyle Wood
|
||||
* Copyright (C) 2018 Forge Development LLC
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
|
||||
* USA
|
||||
*/
|
||||
|
||||
package io.papermc.paperweight.ext
|
||||
|
||||
import org.gradle.api.Project
|
||||
import org.gradle.api.file.DirectoryProperty
|
||||
|
||||
open class SpigotExtension(project: Project) {
|
||||
var spigotDir: DirectoryProperty = project.dirWithDefault("work/Spigot")
|
||||
var spigotApiDir: DirectoryProperty = project.dirWithDefault("work/Spigot/Spigot-API")
|
||||
var spigotServerDir: DirectoryProperty = project.dirWithDefault("work/Spigot/Spigot-Server")
|
||||
var bukkitPatchDir: DirectoryProperty = project.dirWithDefault("work/Spigot/Bukkit-Patches")
|
||||
var craftBukkitPatchDir: DirectoryProperty = project.dirWithDefault("work/Spigot/CraftBukkit-Patches")
|
||||
|
||||
init {
|
||||
spigotDir.disallowUnsafeRead()
|
||||
spigotApiDir.disallowUnsafeRead()
|
||||
spigotServerDir.disallowUnsafeRead()
|
||||
bukkitPatchDir.disallowUnsafeRead()
|
||||
craftBukkitPatchDir.disallowUnsafeRead()
|
||||
}
|
||||
}
|
34
src/main/kotlin/ext/extensions.kt
Normal file
34
src/main/kotlin/ext/extensions.kt
Normal file
|
@ -0,0 +1,34 @@
|
|||
/*
|
||||
* paperweight is a Gradle plugin for the PaperMC project. It uses
|
||||
* some code and systems originally from ForgeGradle.
|
||||
*
|
||||
* Copyright (C) 2020 Kyle Wood
|
||||
* Copyright (C) 2018 Forge Development LLC
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
|
||||
* USA
|
||||
*/
|
||||
|
||||
package io.papermc.paperweight.ext
|
||||
|
||||
import org.gradle.api.Project
|
||||
import org.gradle.api.file.DirectoryProperty
|
||||
import org.gradle.api.file.RegularFileProperty
|
||||
|
||||
fun Project.dirWithDefault(path: String): DirectoryProperty =
|
||||
project.objects.directoryProperty().convention(layout.dir(provider { file(path) }))
|
||||
|
||||
fun Project.fileWithDefault(path: String): RegularFileProperty =
|
||||
project.objects.fileProperty().convention(layout.file(provider { file(path) }))
|
106
src/main/kotlin/tasks/ApplyDiffPatches.kt
Normal file
106
src/main/kotlin/tasks/ApplyDiffPatches.kt
Normal file
|
@ -0,0 +1,106 @@
|
|||
/*
|
||||
* paperweight is a Gradle plugin for the PaperMC project. It uses
|
||||
* some code and systems originally from ForgeGradle.
|
||||
*
|
||||
* Copyright (C) 2020 Kyle Wood
|
||||
* Copyright (C) 2018 Forge Development LLC
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
|
||||
* USA
|
||||
*/
|
||||
|
||||
package io.papermc.paperweight.tasks
|
||||
|
||||
import io.papermc.paperweight.PaperweightException
|
||||
import io.papermc.paperweight.util.Git
|
||||
import io.papermc.paperweight.util.ensureParentExists
|
||||
import io.papermc.paperweight.util.file
|
||||
import org.gradle.api.DefaultTask
|
||||
import org.gradle.api.file.DirectoryProperty
|
||||
import org.gradle.api.file.RegularFileProperty
|
||||
import org.gradle.api.provider.Property
|
||||
import org.gradle.api.tasks.Input
|
||||
import org.gradle.api.tasks.InputDirectory
|
||||
import org.gradle.api.tasks.InputFile
|
||||
import org.gradle.api.tasks.OutputDirectory
|
||||
import org.gradle.api.tasks.TaskAction
|
||||
import org.gradle.kotlin.dsl.property
|
||||
import java.net.URI
|
||||
import java.nio.file.FileSystems
|
||||
import java.nio.file.Files
|
||||
import java.util.Date
|
||||
|
||||
open class ApplyDiffPatches : DefaultTask() {
|
||||
|
||||
@InputFile
|
||||
val sourceJar: RegularFileProperty = project.objects.fileProperty()
|
||||
@Input
|
||||
val sourceBasePath: Property<String> = project.objects.property()
|
||||
@InputDirectory
|
||||
val patchDir: DirectoryProperty = project.objects.directoryProperty()
|
||||
@Input
|
||||
val branch: Property<String> = project.objects.property()
|
||||
|
||||
@OutputDirectory
|
||||
val outputDir: DirectoryProperty = project.objects.directoryProperty()
|
||||
|
||||
@TaskAction
|
||||
fun run() {
|
||||
val git = Git(outputDir.file)
|
||||
git("checkout", "-B", branch.get(), "HEAD").executeSilently(silenceErr = true)
|
||||
|
||||
val uri = URI.create("jar:${sourceJar.file.toURI()}")
|
||||
|
||||
val basePatchDirFile = outputDir.file.resolve("src/main/java")
|
||||
val outputDirFile = basePatchDirFile.resolve(sourceBasePath.get())
|
||||
outputDirFile.deleteRecursively()
|
||||
|
||||
val patchList = patchDir.file.listFiles() ?: throw PaperweightException("Patch directory does not exist ${patchDir.file}")
|
||||
if (patchList.isEmpty()) {
|
||||
throw PaperweightException("No patch files found in ${patchDir.file}")
|
||||
}
|
||||
|
||||
// Copy in patch targets
|
||||
FileSystems.newFileSystem(uri, mapOf<String, Any>()).use { fs ->
|
||||
for (file in patchList) {
|
||||
val javaName = file.name.replaceAfterLast('.', "java")
|
||||
val out = outputDirFile.resolve(javaName)
|
||||
val sourcePath = fs.getPath(sourceBasePath.get(), javaName)
|
||||
|
||||
Files.newInputStream(sourcePath).use { input ->
|
||||
ensureParentExists(out)
|
||||
out.outputStream().use { output ->
|
||||
input.copyTo(output)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
git("add", "src").executeOut()
|
||||
git("commit", "-m", "Vanilla $ ${Date()}", "--author=Vanilla <auto@mated.null>").executeOut()
|
||||
|
||||
// Apply patches
|
||||
for (file in patchList) {
|
||||
val javaName = file.name.replaceAfterLast('.', "java")
|
||||
|
||||
println("Patching ${javaName.removeSuffix(".java")}")
|
||||
git("apply", "--directory=${basePatchDirFile.relativeTo(outputDir.file).path}", file.absolutePath).executeOut()
|
||||
}
|
||||
|
||||
git("add", "src").executeOut()
|
||||
git("commit", "-m", "CraftBukkit $ ${Date()}", "--author=CraftBukkit <auto@mated.null>").executeOut()
|
||||
git("checkout", "-f", "HEAD~2").executeSilently()
|
||||
}
|
||||
}
|
113
src/main/kotlin/tasks/ApplyGitPatches.kt
Normal file
113
src/main/kotlin/tasks/ApplyGitPatches.kt
Normal file
|
@ -0,0 +1,113 @@
|
|||
/*
|
||||
* paperweight is a Gradle plugin for the PaperMC project. It uses
|
||||
* some code and systems originally from ForgeGradle.
|
||||
*
|
||||
* Copyright (C) 2020 Kyle Wood
|
||||
* Copyright (C) 2018 Forge Development LLC
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
|
||||
* USA
|
||||
*/
|
||||
|
||||
package io.papermc.paperweight.tasks
|
||||
|
||||
import io.papermc.paperweight.PaperweightException
|
||||
import io.papermc.paperweight.util.Git
|
||||
import io.papermc.paperweight.util.file
|
||||
import org.gradle.api.DefaultTask
|
||||
import org.gradle.api.file.DirectoryProperty
|
||||
import org.gradle.api.provider.Property
|
||||
import org.gradle.api.tasks.Input
|
||||
import org.gradle.api.tasks.InputDirectory
|
||||
import org.gradle.api.tasks.OutputDirectory
|
||||
import org.gradle.api.tasks.TaskAction
|
||||
import org.gradle.internal.os.OperatingSystem
|
||||
import org.gradle.kotlin.dsl.property
|
||||
|
||||
open class ApplyGitPatches : DefaultTask() {
|
||||
|
||||
@Input
|
||||
val branch: Property<String> = project.objects.property()
|
||||
@Input
|
||||
val upstreamBranch: Property<String> = project.objects.property()
|
||||
@InputDirectory
|
||||
val upstream: DirectoryProperty = project.objects.directoryProperty()
|
||||
@InputDirectory
|
||||
val patchDir: DirectoryProperty = project.objects.directoryProperty()
|
||||
|
||||
@OutputDirectory
|
||||
val outputDir: DirectoryProperty = project.objects.directoryProperty()
|
||||
|
||||
@TaskAction
|
||||
fun run() {
|
||||
Git(upstream.file).let { git ->
|
||||
git("fetch").run()
|
||||
git("branch", "-f", upstreamBranch.get(), branch.get()).runSilently()
|
||||
}
|
||||
|
||||
if (!outputDir.file.exists() || !outputDir.file.resolve(".git").exists()) {
|
||||
outputDir.file.deleteRecursively()
|
||||
Git(outputDir.file.parentFile)("clone", upstream.file.absolutePath, outputDir.file.name).runOut()
|
||||
}
|
||||
|
||||
val target = outputDir.file.name
|
||||
|
||||
println(" Resetting $target to ${upstream.file.name}...")
|
||||
Git(outputDir.file).let { git ->
|
||||
git("remote", "rm", "upstream").runSilently(silenceErr = true)
|
||||
git("remote", "add", "upstream", upstream.file.absolutePath).runSilently(silenceErr = true)
|
||||
if (git("checkout", "master").runSilently(silenceOut = false, silenceErr = true) != 0) {
|
||||
git("checkout", "-b", "master").runOut()
|
||||
}
|
||||
git("fetch", "upstream").runSilently(silenceErr = true)
|
||||
git("reset", "--hard", "upstream/${upstreamBranch.get()}").runOut()
|
||||
|
||||
println(" Applying patches to $target...")
|
||||
|
||||
val statusFile = outputDir.file.resolve(".git/patch-apply-failed")
|
||||
if (statusFile.exists()) {
|
||||
statusFile.delete()
|
||||
}
|
||||
git("am", "--abort").runSilently(silenceErr = true)
|
||||
|
||||
val patches = patchDir.file.listFiles { _, name -> name.endsWith(".patch") } ?: run {
|
||||
println("No patches found")
|
||||
return
|
||||
}
|
||||
|
||||
patches.sort()
|
||||
|
||||
if (git("am", "--3way", "--ignore-whitespace", *patches.map { it.absolutePath }.toTypedArray()).runOut() != 0) {
|
||||
Thread.sleep(100) // Wait for git
|
||||
statusFile.writeText("1")
|
||||
logger.error("*** Something did not apply cleanly to $target.")
|
||||
logger.error("*** Please review above details and finish the apply then")
|
||||
logger.error("*** save the changes with ./gradlew `rebuildPatches`")
|
||||
|
||||
if (OperatingSystem.current().isWindows) {
|
||||
logger.error("")
|
||||
logger.error("*** Because you're on Windows you'll need to finish the AM,")
|
||||
logger.error("*** rebuild all patches, and then re-run the patch apply again.")
|
||||
logger.error("*** Consider using the scripts with Windows Subsystem for Linux.")
|
||||
}
|
||||
|
||||
throw PaperweightException("Failed to apply patches")
|
||||
} else {
|
||||
statusFile.delete()
|
||||
println(" Patches applied cleanly to $target")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
62
src/main/kotlin/tasks/ApplyMcpPatches.kt
Normal file
62
src/main/kotlin/tasks/ApplyMcpPatches.kt
Normal file
|
@ -0,0 +1,62 @@
|
|||
/*
|
||||
* paperweight is a Gradle plugin for the PaperMC project. It uses
|
||||
* some code and systems originally from ForgeGradle.
|
||||
*
|
||||
* Copyright (C) 2020 Kyle Wood
|
||||
* Copyright (C) 2018 Forge Development LLC
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
|
||||
* USA
|
||||
*/
|
||||
|
||||
package io.papermc.paperweight.tasks
|
||||
|
||||
import io.papermc.paperweight.util.Git
|
||||
import io.papermc.paperweight.util.mcpConfig
|
||||
import io.papermc.paperweight.util.mcpFile
|
||||
import org.gradle.api.file.RegularFileProperty
|
||||
import org.gradle.api.tasks.InputFile
|
||||
import java.io.File
|
||||
|
||||
open class ApplyMcpPatches : ZippedTask() {
|
||||
|
||||
@InputFile
|
||||
val configFile: RegularFileProperty = project.objects.fileProperty()
|
||||
|
||||
init {
|
||||
inputs.dir(configFile.map { mcpConfig(configFile) }.map { mcpFile(configFile, it.data.patches.server) })
|
||||
}
|
||||
|
||||
override fun run(rootDir: File) {
|
||||
val config = mcpConfig(configFile)
|
||||
val serverPatchDir = mcpFile(configFile, config.data.patches.server)
|
||||
|
||||
val git = Git(rootDir)
|
||||
|
||||
val extension = ".java.patch"
|
||||
project.fileTree(serverPatchDir).matching {
|
||||
include("*$extension")
|
||||
}.forEach { patch ->
|
||||
val patchName = patch.name
|
||||
print("Patching ${patchName.substring(0, extension.length)}")
|
||||
val exit = git("apply", "--ignore-whitespace", patch.absolutePath).setup(System.out, null).run()
|
||||
if (exit != 0) {
|
||||
println("...Failed")
|
||||
} else {
|
||||
println()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
84
src/main/kotlin/tasks/DecompileVanillaJar.kt
Normal file
84
src/main/kotlin/tasks/DecompileVanillaJar.kt
Normal file
|
@ -0,0 +1,84 @@
|
|||
/*
|
||||
* paperweight is a Gradle plugin for the PaperMC project. It uses
|
||||
* some code and systems originally from ForgeGradle.
|
||||
*
|
||||
* Copyright (C) 2020 Kyle Wood
|
||||
* Copyright (C) 2018 Forge Development LLC
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
|
||||
* USA
|
||||
*/
|
||||
|
||||
package io.papermc.paperweight.tasks
|
||||
|
||||
import io.papermc.paperweight.PaperweightException
|
||||
import io.papermc.paperweight.util.Constants.paperTaskOutput
|
||||
import io.papermc.paperweight.util.cache
|
||||
import io.papermc.paperweight.util.ensureDeleted
|
||||
import io.papermc.paperweight.util.runJar
|
||||
import io.papermc.paperweight.util.toProvider
|
||||
import org.gradle.api.DefaultTask
|
||||
import org.gradle.api.file.RegularFileProperty
|
||||
import org.gradle.api.provider.Property
|
||||
import org.gradle.api.tasks.Input
|
||||
import org.gradle.api.tasks.InputFile
|
||||
import org.gradle.api.tasks.OutputFile
|
||||
import org.gradle.api.tasks.TaskAction
|
||||
import org.gradle.kotlin.dsl.property
|
||||
import java.util.concurrent.ThreadLocalRandom
|
||||
|
||||
open class DecompileVanillaJar : DefaultTask() {
|
||||
|
||||
@InputFile
|
||||
val inputJar: RegularFileProperty = project.objects.fileProperty()
|
||||
@InputFile
|
||||
val fernFlowerJar: RegularFileProperty = project.objects.fileProperty()
|
||||
@Input
|
||||
val decompileCommand: Property<String> = project.objects.property()
|
||||
|
||||
@OutputFile
|
||||
val outputJar: RegularFileProperty = project.objects.run {
|
||||
fileProperty().convention(project.toProvider(project.cache.resolve(paperTaskOutput())))
|
||||
}
|
||||
|
||||
@TaskAction
|
||||
fun run() {
|
||||
val inputJarFile = inputJar.asFile.get()
|
||||
val inputJarPath = inputJarFile.canonicalPath
|
||||
|
||||
val outputJarFile = outputJar.asFile.get()
|
||||
val decomp = outputJarFile.resolveSibling("decomp" + ThreadLocalRandom.current().nextInt())
|
||||
|
||||
try {
|
||||
if (!decomp.exists() && !decomp.mkdirs()) {
|
||||
throw PaperweightException("Failed to create output directory: $decomp")
|
||||
}
|
||||
|
||||
val cmd = decompileCommand.get().split(" ").let { it.subList(3, it.size - 2) }.toMutableList()
|
||||
cmd += inputJarPath
|
||||
cmd += decomp.canonicalPath
|
||||
|
||||
val logFile = project.cache.resolve(paperTaskOutput("log"))
|
||||
logFile.delete()
|
||||
|
||||
runJar(fernFlowerJar, workingDir = project.cache, logFile = logFile, args = *cmd.toTypedArray())
|
||||
|
||||
ensureDeleted(outputJarFile)
|
||||
decomp.resolve(inputJarFile.name).renameTo(outputJarFile)
|
||||
} finally {
|
||||
decomp.deleteRecursively()
|
||||
}
|
||||
}
|
||||
}
|
75
src/main/kotlin/tasks/DownloadServerJar.kt
Normal file
75
src/main/kotlin/tasks/DownloadServerJar.kt
Normal file
|
@ -0,0 +1,75 @@
|
|||
/*
|
||||
* paperweight is a Gradle plugin for the PaperMC project. It uses
|
||||
* some code and systems originally from ForgeGradle.
|
||||
*
|
||||
* Copyright (C) 2020 Kyle Wood
|
||||
* Copyright (C) 2018 Forge Development LLC
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
|
||||
* USA
|
||||
*/
|
||||
|
||||
package io.papermc.paperweight.tasks
|
||||
|
||||
import io.papermc.paperweight.PaperweightException
|
||||
import io.papermc.paperweight.util.Constants.paperTaskOutput
|
||||
import io.papermc.paperweight.util.cache
|
||||
import io.papermc.paperweight.util.ensureDeleted
|
||||
import io.papermc.paperweight.util.ensureParentExists
|
||||
import io.papermc.paperweight.util.toProvider
|
||||
import org.gradle.api.DefaultTask
|
||||
import org.gradle.api.file.RegularFileProperty
|
||||
import org.gradle.api.provider.Property
|
||||
import org.gradle.api.tasks.Input
|
||||
import org.gradle.api.tasks.OutputFile
|
||||
import org.gradle.api.tasks.TaskAction
|
||||
import org.gradle.kotlin.dsl.property
|
||||
import java.math.BigInteger
|
||||
import java.net.URL
|
||||
import java.security.MessageDigest
|
||||
|
||||
open class DownloadServerJar : DefaultTask() {
|
||||
|
||||
@Input
|
||||
val downloadUrl: Property<String> = project.objects.property()
|
||||
@Input
|
||||
val hash: Property<String> = project.objects.property()
|
||||
|
||||
@OutputFile
|
||||
val outputJar: RegularFileProperty = project.objects.run {
|
||||
fileProperty().convention(project.toProvider(project.cache.resolve(paperTaskOutput())))
|
||||
}
|
||||
|
||||
@TaskAction
|
||||
fun run() {
|
||||
val file = outputJar.asFile.get()
|
||||
ensureParentExists(file)
|
||||
ensureDeleted(file)
|
||||
|
||||
file.outputStream().buffered().use { out ->
|
||||
URL(downloadUrl.get()).openStream().copyTo(out)
|
||||
}
|
||||
|
||||
val digest = MessageDigest.getInstance("MD5")
|
||||
|
||||
val data = file.readBytes()
|
||||
val hashResult = digest.digest(data)
|
||||
val hashText = String.format("%032x", BigInteger(1, hashResult))
|
||||
|
||||
if (hash.get() != hashText) {
|
||||
throw PaperweightException("Checksum failed, expected ${hash.get()}, actually got $hashText")
|
||||
}
|
||||
}
|
||||
}
|
73
src/main/kotlin/tasks/Extract.kt
Normal file
73
src/main/kotlin/tasks/Extract.kt
Normal file
|
@ -0,0 +1,73 @@
|
|||
/*
|
||||
* paperweight is a Gradle plugin for the PaperMC project. It uses
|
||||
* some code and systems originally from ForgeGradle.
|
||||
*
|
||||
* Copyright (C) 2020 Kyle Wood
|
||||
* Copyright (C) 2018 Forge Development LLC
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
|
||||
* USA
|
||||
*/
|
||||
|
||||
package io.papermc.paperweight.tasks
|
||||
|
||||
import org.gradle.api.DefaultTask
|
||||
import org.gradle.api.file.DirectoryProperty
|
||||
import org.gradle.api.file.RegularFileProperty
|
||||
import org.gradle.api.provider.Property
|
||||
import org.gradle.api.tasks.Input
|
||||
import org.gradle.api.tasks.InputFile
|
||||
import org.gradle.api.tasks.OutputDirectory
|
||||
import org.gradle.api.tasks.OutputFile
|
||||
import org.gradle.api.tasks.TaskAction
|
||||
import org.gradle.kotlin.dsl.get
|
||||
import org.gradle.kotlin.dsl.property
|
||||
|
||||
open class Extract : DefaultTask() {
|
||||
|
||||
@Input
|
||||
val config: Property<String> = project.objects.property()
|
||||
|
||||
@OutputDirectory
|
||||
val outputDir: DirectoryProperty = project.objects.directoryProperty()
|
||||
|
||||
@TaskAction
|
||||
fun run() {
|
||||
project.copy {
|
||||
from(project.zipTree(project.configurations[config.get()].resolve().single()))
|
||||
into(outputDir)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
open class ExtractMcpMappings : Extract() {
|
||||
|
||||
@OutputFile
|
||||
val fieldsCsv: RegularFileProperty = project.objects.fileProperty()
|
||||
.convention(outputDir.map { it.file("fields.csv") })
|
||||
@OutputFile
|
||||
val methodsCsv: RegularFileProperty = project.objects.fileProperty()
|
||||
.convention(outputDir.map { it.file("methods.csv") })
|
||||
@OutputFile
|
||||
val paramsCsv: RegularFileProperty = project.objects.fileProperty()
|
||||
.convention(outputDir.map { it.file("params.csv") })
|
||||
}
|
||||
|
||||
open class ExtractMcpData : Extract() {
|
||||
|
||||
@OutputFile
|
||||
val configJson: RegularFileProperty = project.objects.fileProperty()
|
||||
.convention(outputDir.map { it.file("config.json") })
|
||||
}
|
44
src/main/kotlin/tasks/GatherBuildData.kt
Normal file
44
src/main/kotlin/tasks/GatherBuildData.kt
Normal file
|
@ -0,0 +1,44 @@
|
|||
/*
|
||||
* paperweight is a Gradle plugin for the PaperMC project. It uses
|
||||
* some code and systems originally from ForgeGradle.
|
||||
*
|
||||
* Copyright (C) 2020 Kyle Wood
|
||||
* Copyright (C) 2018 Forge Development LLC
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
|
||||
* USA
|
||||
*/
|
||||
|
||||
package io.papermc.paperweight.tasks
|
||||
|
||||
import com.github.salomonbrys.kotson.fromJson
|
||||
import io.papermc.paperweight.util.gson
|
||||
import org.gradle.api.DefaultTask
|
||||
import org.gradle.api.file.RegularFileProperty
|
||||
import org.gradle.api.provider.Provider
|
||||
import org.gradle.api.tasks.OutputFile
|
||||
import util.BuildDataInfo
|
||||
|
||||
open class GatherBuildData : DefaultTask() {
|
||||
|
||||
@OutputFile
|
||||
val buildDataInfoFile: RegularFileProperty = project.objects.fileProperty()
|
||||
|
||||
val buildDataInfo: Provider<BuildDataInfo> = buildDataInfoFile.map {
|
||||
it.asFile.bufferedReader().use { reader ->
|
||||
gson.fromJson(reader)
|
||||
}
|
||||
}
|
||||
}
|
95
src/main/kotlin/tasks/GenerateSpigotSrgs.kt
Normal file
95
src/main/kotlin/tasks/GenerateSpigotSrgs.kt
Normal file
|
@ -0,0 +1,95 @@
|
|||
/*
|
||||
* paperweight is a Gradle plugin for the PaperMC project. It uses
|
||||
* some code and systems originally from ForgeGradle.
|
||||
*
|
||||
* Copyright (C) 2020 Kyle Wood
|
||||
* Copyright (C) 2018 Forge Development LLC
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
|
||||
* USA
|
||||
*/
|
||||
|
||||
package io.papermc.paperweight.tasks
|
||||
|
||||
import io.papermc.paperweight.util.writeMappings
|
||||
import org.cadixdev.lorenz.io.MappingFormats
|
||||
import org.gradle.api.DefaultTask
|
||||
import org.gradle.api.file.RegularFileProperty
|
||||
import org.gradle.api.tasks.InputFile
|
||||
import org.gradle.api.tasks.OutputFile
|
||||
import org.gradle.api.tasks.TaskAction
|
||||
|
||||
open class GenerateSpigotSrgs : DefaultTask() {
|
||||
|
||||
@InputFile
|
||||
val notchToSrg: RegularFileProperty = project.objects.fileProperty()
|
||||
@InputFile
|
||||
val srgToMcp: RegularFileProperty = project.objects.fileProperty()
|
||||
@InputFile
|
||||
val classMappings: RegularFileProperty = project.objects.fileProperty()
|
||||
@InputFile
|
||||
val memberMappings: RegularFileProperty = project.objects.fileProperty()
|
||||
@InputFile
|
||||
val packageMappings: RegularFileProperty = project.objects.fileProperty()
|
||||
|
||||
@OutputFile
|
||||
val spigotToSrg: RegularFileProperty = project.objects.fileProperty()
|
||||
@OutputFile
|
||||
val spigotToMcp: RegularFileProperty = project.objects.fileProperty()
|
||||
@OutputFile
|
||||
val spigotToNotch: RegularFileProperty = project.objects.fileProperty()
|
||||
@OutputFile
|
||||
val srgToSpigot: RegularFileProperty = project.objects.fileProperty()
|
||||
@OutputFile
|
||||
val mcpToSpigot: RegularFileProperty = project.objects.fileProperty()
|
||||
@OutputFile
|
||||
val notchToSpigot: RegularFileProperty = project.objects.fileProperty()
|
||||
|
||||
@TaskAction
|
||||
fun run() {
|
||||
val classMappingSet = classMappings.asFile.get().reader().use { MappingFormats.CSRG.createReader(it).read() }
|
||||
val memberMappingSet = memberMappings.asFile.get().reader().use { MappingFormats.CSRG.createReader(it).read() }
|
||||
|
||||
val notchToSpigotSet = classMappingSet.merge(memberMappingSet)
|
||||
|
||||
// Apply the package mappings (Lorenz doesn't currently support this)
|
||||
val newPackage = packageMappings.asFile.get().readLines()[0].split(Regex("\\s+"))[1]
|
||||
for (topLevelClassMapping in notchToSpigotSet.topLevelClassMappings) {
|
||||
topLevelClassMapping.deobfuscatedName = newPackage + topLevelClassMapping.deobfuscatedName
|
||||
}
|
||||
|
||||
val notchToSrgSet = notchToSrg.asFile.get().reader().use { MappingFormats.TSRG.createReader(it).read() }
|
||||
val srgToMcpSet = srgToMcp.asFile.get().reader().use { MappingFormats.TSRG.createReader(it).read() }
|
||||
|
||||
val srgToSpigotSet = notchToSrgSet.reverse().merge(notchToSpigotSet)
|
||||
|
||||
val mcpToNotchSet = notchToSrgSet.merge(srgToMcpSet).reverse()
|
||||
val mcpToSpigotSet = mcpToNotchSet.merge(notchToSpigotSet)
|
||||
|
||||
val spigotToSrgSet = srgToSpigotSet.reverse()
|
||||
val spigotToMcpSet = mcpToSpigotSet.reverse()
|
||||
val spigotToNotchSet = notchToSpigotSet.reverse()
|
||||
|
||||
writeMappings(
|
||||
MappingFormats.TSRG,
|
||||
spigotToSrgSet to spigotToSrg.asFile.get(),
|
||||
spigotToMcpSet to spigotToMcp.asFile.get(),
|
||||
spigotToNotchSet to spigotToNotch.asFile.get(),
|
||||
srgToSpigotSet to srgToSpigot.asFile.get(),
|
||||
mcpToSpigotSet to mcpToSpigot.asFile.get(),
|
||||
notchToSpigotSet to notchToSpigot.asFile.get()
|
||||
)
|
||||
}
|
||||
}
|
146
src/main/kotlin/tasks/GenerateSrgs.kt
Normal file
146
src/main/kotlin/tasks/GenerateSrgs.kt
Normal file
|
@ -0,0 +1,146 @@
|
|||
/*
|
||||
* paperweight is a Gradle plugin for the PaperMC project. It uses
|
||||
* some code and systems originally from ForgeGradle.
|
||||
*
|
||||
* Copyright (C) 2020 Kyle Wood
|
||||
* Copyright (C) 2018 Forge Development LLC
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
|
||||
* USA
|
||||
*/
|
||||
|
||||
package io.papermc.paperweight.tasks
|
||||
|
||||
import io.papermc.paperweight.util.ensureParentExists
|
||||
import io.papermc.paperweight.util.getCsvReader
|
||||
import io.papermc.paperweight.util.mcpConfig
|
||||
import io.papermc.paperweight.util.mcpFile
|
||||
import io.papermc.paperweight.util.writeMappings
|
||||
import org.cadixdev.lorenz.MappingSet
|
||||
import org.cadixdev.lorenz.io.MappingFormats
|
||||
import org.cadixdev.lorenz.model.ClassMapping
|
||||
import org.gradle.api.DefaultTask
|
||||
import org.gradle.api.file.RegularFileProperty
|
||||
import org.gradle.api.tasks.InputFile
|
||||
import org.gradle.api.tasks.OutputFile
|
||||
import org.gradle.api.tasks.TaskAction
|
||||
|
||||
open class GenerateSrgs : DefaultTask() {
|
||||
|
||||
@InputFile
|
||||
val configFile: RegularFileProperty = project.objects.fileProperty()
|
||||
@InputFile
|
||||
val methodsCsv: RegularFileProperty = project.objects.fileProperty()
|
||||
@InputFile
|
||||
val fieldsCsv: RegularFileProperty = project.objects.fileProperty()
|
||||
|
||||
@OutputFile
|
||||
val notchToSrg: RegularFileProperty = project.objects.fileProperty()
|
||||
@OutputFile
|
||||
val notchToMcp: RegularFileProperty = project.objects.fileProperty()
|
||||
@OutputFile
|
||||
val mcpToNotch: RegularFileProperty = project.objects.fileProperty()
|
||||
@OutputFile
|
||||
val mcpToSrg: RegularFileProperty = project.objects.fileProperty()
|
||||
@OutputFile
|
||||
val srgToNotch: RegularFileProperty = project.objects.fileProperty()
|
||||
@OutputFile
|
||||
val srgToMcp: RegularFileProperty = project.objects.fileProperty()
|
||||
|
||||
@TaskAction
|
||||
fun run() {
|
||||
val config = mcpConfig(configFile)
|
||||
val inSrg = mcpFile(configFile, config.data.mappings)
|
||||
|
||||
val methods = HashMap<String, String>()
|
||||
val fields = HashMap<String, String>()
|
||||
readCsvs(methods, fields)
|
||||
|
||||
val inSet = inSrg.reader().use {
|
||||
MappingFormats.TSRG.createReader(it).read()
|
||||
}
|
||||
|
||||
ensureParentExists(notchToSrg, notchToMcp, mcpToNotch, mcpToSrg, srgToNotch, srgToMcp)
|
||||
createMappings(inSet, methods, fields)
|
||||
}
|
||||
|
||||
private fun readCsvs(methods: MutableMap<String, String>, fields: MutableMap<String, String>) {
|
||||
getCsvReader(methodsCsv.asFile.get()).use { reader ->
|
||||
for (line in reader.readAll()) {
|
||||
methods[line[0]] = line[1]
|
||||
}
|
||||
}
|
||||
|
||||
getCsvReader(fieldsCsv.asFile.get()).use { reader ->
|
||||
for (line in reader.readAll()) {
|
||||
fields[line[0]] = line[1]
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun createMappings(notchToSrgSet: MappingSet, methods: Map<String, String>, fields: Map<String, String>) {
|
||||
// We have Notch -> SRG
|
||||
val srgToNotchSet = notchToSrgSet.reverse()
|
||||
|
||||
val notchToMcpSet: MappingSet
|
||||
val mcpToNotchSet: MappingSet
|
||||
val mcpToSrgSet: MappingSet
|
||||
|
||||
val srgToMcpSet = MappingSet.create()
|
||||
|
||||
// Create SRG -> MCP from Notch -> SRG and the CSVs
|
||||
for (topLevelClassMapping in notchToSrgSet.topLevelClassMappings) {
|
||||
// MCP and SRG have the same class names
|
||||
val srgToMcpClass = srgToMcpSet.createTopLevelClassMapping(
|
||||
topLevelClassMapping.deobfuscatedName,
|
||||
topLevelClassMapping.deobfuscatedName
|
||||
)
|
||||
|
||||
mapClass(topLevelClassMapping, srgToMcpClass, methods, fields)
|
||||
}
|
||||
|
||||
// We have Notch->SRG and SRG->MCP mapping sets now
|
||||
// All other sets can be generated from these two
|
||||
notchToMcpSet = notchToSrgSet.merge(srgToMcpSet)
|
||||
mcpToNotchSet = notchToMcpSet.reverse()
|
||||
mcpToSrgSet = srgToMcpSet.reverse()
|
||||
|
||||
writeMappings(
|
||||
MappingFormats.TSRG,
|
||||
notchToSrgSet to notchToSrg.asFile.get(),
|
||||
notchToMcpSet to notchToMcp.asFile.get(),
|
||||
mcpToNotchSet to mcpToNotch.asFile.get(),
|
||||
mcpToSrgSet to mcpToSrg.asFile.get(),
|
||||
srgToNotchSet to srgToNotch.asFile.get(),
|
||||
srgToMcpSet to srgToMcp.asFile.get()
|
||||
)
|
||||
}
|
||||
|
||||
private fun mapClass(inClass: ClassMapping<*, *>, outClass: ClassMapping<*, *>, methods: Map<String, String>, fields: Map<String, String>) {
|
||||
for (fieldMapping in inClass.fieldMappings) {
|
||||
val mcpName = fields[fieldMapping.deobfuscatedName] ?: fieldMapping.deobfuscatedName
|
||||
val mapping = outClass.createFieldMapping(fieldMapping.deobfuscatedSignature, mcpName)
|
||||
mapping.obfuscatedName
|
||||
}
|
||||
for (methodMapping in inClass.methodMappings) {
|
||||
val mcpName = methods[methodMapping.deobfuscatedName] ?: methodMapping.deobfuscatedName
|
||||
outClass.createMethodMapping(methodMapping.deobfuscatedSignature, mcpName)
|
||||
}
|
||||
for (innerClassMapping in inClass.innerClassMappings) {
|
||||
val innerOutClass = outClass.createInnerClassMapping(innerClassMapping.deobfuscatedName)
|
||||
mapClass(innerClassMapping, innerOutClass, methods, fields)
|
||||
}
|
||||
}
|
||||
}
|
76
src/main/kotlin/tasks/GetRemoteJsons.kt
Normal file
76
src/main/kotlin/tasks/GetRemoteJsons.kt
Normal file
|
@ -0,0 +1,76 @@
|
|||
/*
|
||||
* paperweight is a Gradle plugin for the PaperMC project. It uses
|
||||
* some code and systems originally from ForgeGradle.
|
||||
*
|
||||
* Copyright (C) 2020 Kyle Wood
|
||||
* Copyright (C) 2018 Forge Development LLC
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
|
||||
* USA
|
||||
*/
|
||||
|
||||
package io.papermc.paperweight.tasks
|
||||
|
||||
import com.github.salomonbrys.kotson.array
|
||||
import com.github.salomonbrys.kotson.fromJson
|
||||
import com.github.salomonbrys.kotson.get
|
||||
import com.github.salomonbrys.kotson.string
|
||||
import com.google.gson.JsonObject
|
||||
import io.papermc.paperweight.util.Constants
|
||||
import io.papermc.paperweight.util.cache
|
||||
import io.papermc.paperweight.util.ext
|
||||
import io.papermc.paperweight.util.getWithEtag
|
||||
import io.papermc.paperweight.util.gson
|
||||
import org.gradle.api.DefaultTask
|
||||
import org.gradle.api.provider.Property
|
||||
import org.gradle.api.tasks.Input
|
||||
import org.gradle.api.tasks.TaskAction
|
||||
import org.gradle.kotlin.dsl.property
|
||||
import util.MinecraftManifest
|
||||
|
||||
open class GetRemoteJsons : DefaultTask() {
|
||||
|
||||
@Input
|
||||
val config: Property<String> = project.objects.property()
|
||||
|
||||
init {
|
||||
outputs.upToDateWhen { false }
|
||||
}
|
||||
|
||||
@TaskAction
|
||||
fun run() {
|
||||
val cache = project.cache
|
||||
val extension = project.ext
|
||||
|
||||
// McManifest.json
|
||||
val mcManifestJson = cache.resolve(Constants.MC_MANIFEST)
|
||||
val mcManifestEtag = cache.resolve("${Constants.MC_MANIFEST}.etag")
|
||||
getWithEtag(Constants.MC_MANIFEST_URL, mcManifestJson, mcManifestEtag)
|
||||
val mcManifestText = gson.fromJson<MinecraftManifest>(mcManifestJson.readText())
|
||||
|
||||
val mcVersionJson = cache.resolve(Constants.VERSION_JSON)
|
||||
val mcVersionEtag = mcVersionJson.resolveSibling("${mcVersionJson.name}.etag")
|
||||
getWithEtag(mcManifestText.versions.first { it.id == extension.minecraftVersion.get() }.url, mcVersionJson, mcVersionEtag)
|
||||
|
||||
val jsonObject = mcVersionJson.bufferedReader().use { reader ->
|
||||
gson.fromJson<JsonObject>(reader)
|
||||
}
|
||||
|
||||
val conf = config.get()
|
||||
for (library in jsonObject["libraries"].array) {
|
||||
project.dependencies.add(conf, library["name"].string)
|
||||
}
|
||||
}
|
||||
}
|
97
src/main/kotlin/tasks/PatchMcpCsv.kt
Normal file
97
src/main/kotlin/tasks/PatchMcpCsv.kt
Normal file
|
@ -0,0 +1,97 @@
|
|||
/*
|
||||
* paperweight is a Gradle plugin for the PaperMC project. It uses
|
||||
* some code and systems originally from ForgeGradle.
|
||||
*
|
||||
* Copyright (C) 2020 Kyle Wood
|
||||
* Copyright (C) 2018 Forge Development LLC
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
|
||||
* USA
|
||||
*/
|
||||
|
||||
package io.papermc.paperweight.tasks
|
||||
|
||||
import org.gradle.api.DefaultTask
|
||||
import org.gradle.api.file.RegularFileProperty
|
||||
import org.gradle.api.tasks.InputFile
|
||||
import org.gradle.api.tasks.OutputFile
|
||||
import org.gradle.api.tasks.TaskAction
|
||||
import java.io.PrintWriter
|
||||
import java.util.regex.Pattern
|
||||
|
||||
open class PatchMcpCsv : DefaultTask() {
|
||||
|
||||
@InputFile
|
||||
val fieldsCsv: RegularFileProperty = project.objects.fileProperty()
|
||||
@InputFile
|
||||
val methodsCsv: RegularFileProperty = project.objects.fileProperty()
|
||||
@InputFile
|
||||
val paramsCsv: RegularFileProperty = project.objects.fileProperty()
|
||||
@InputFile
|
||||
val changesFile: RegularFileProperty = project.objects.fileProperty()
|
||||
|
||||
@OutputFile
|
||||
val paperFieldCsv: RegularFileProperty = project.objects.fileProperty()
|
||||
@OutputFile
|
||||
val paperMethodCsv: RegularFileProperty = project.objects.fileProperty()
|
||||
@OutputFile
|
||||
val paperParamCsv: RegularFileProperty = project.objects.fileProperty()
|
||||
|
||||
@TaskAction
|
||||
fun run() {
|
||||
val changes = changesFile.asFile.get().readLines()
|
||||
val changeMap = changes.asSequence()
|
||||
.filterNot { l -> l.trim().run { startsWith('#') || isEmpty() } }
|
||||
.map { l -> commentPattern.matcher(l).replaceAll("") }
|
||||
.map { l -> l.split(',').run { get(0) to get(1) } }
|
||||
.toMap()
|
||||
|
||||
val fields = fieldsCsv.asFile.get().readLines().toMutableList()
|
||||
val methods = methodsCsv.asFile.get().readLines().toMutableList()
|
||||
val params = paramsCsv.asFile.get().readLines().toMutableList()
|
||||
|
||||
replaceChanges(changeMap, fields, fieldPattern)
|
||||
replaceChanges(changeMap, methods, methodPattern)
|
||||
replaceChanges(changeMap, params, paramPattern)
|
||||
|
||||
paperFieldCsv.asFile.get().printWriter().use { writeFile(fields, it) }
|
||||
paperMethodCsv.asFile.get().printWriter().use { writeFile(methods, it) }
|
||||
paperParamCsv.asFile.get().printWriter().use { writeFile(params, it) }
|
||||
}
|
||||
|
||||
private fun replaceChanges(changes: Map<String, String>, lines: MutableList<String>, pattern: Pattern) {
|
||||
// Start at 1 to skip csv header row
|
||||
for (i in 1 until lines.size) {
|
||||
val matcher = pattern.matcher(lines[i])
|
||||
matcher.find()
|
||||
val srgName = matcher.group(1) ?: continue
|
||||
val changedName = changes[srgName] ?: continue
|
||||
lines[i] = matcher.replaceFirst("$1,$changedName,$3")
|
||||
}
|
||||
}
|
||||
|
||||
private fun writeFile(lines: List<String>, writer: PrintWriter) {
|
||||
for (line in lines) {
|
||||
writer.println(line)
|
||||
}
|
||||
}
|
||||
|
||||
private companion object {
|
||||
private val fieldPattern = Pattern.compile("(field_\\d+_[a-zA-Z_]+),(\\w+),(\\d,.*)")
|
||||
private val methodPattern = Pattern.compile("(func_\\d+_[a-zA-Z_]+),(\\w+),(\\d,.*)")
|
||||
private val paramPattern = Pattern.compile("(p_i?\\d+_\\d+_),(\\w+),(\\d)")
|
||||
private val commentPattern = Pattern.compile("\\s*#.*")
|
||||
}
|
||||
}
|
270
src/main/kotlin/tasks/RemapSources.kt
Normal file
270
src/main/kotlin/tasks/RemapSources.kt
Normal file
|
@ -0,0 +1,270 @@
|
|||
/*
|
||||
* paperweight is a Gradle plugin for the PaperMC project. It uses
|
||||
* some code and systems originally from ForgeGradle.
|
||||
*
|
||||
* Copyright (C) 2020 Kyle Wood
|
||||
* Copyright (C) 2018 Forge Development LLC
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
|
||||
* USA
|
||||
*/
|
||||
|
||||
package io.papermc.paperweight.tasks
|
||||
|
||||
import io.papermc.paperweight.PaperweightException
|
||||
import io.papermc.paperweight.util.file
|
||||
import io.papermc.paperweight.util.mcpConfig
|
||||
import io.papermc.paperweight.util.mcpFile
|
||||
import org.cadixdev.at.AccessTransformSet
|
||||
import org.cadixdev.at.io.AccessTransformFormats
|
||||
import org.cadixdev.lorenz.io.MappingFormats
|
||||
import org.cadixdev.mercury.Mercury
|
||||
import org.cadixdev.mercury.RewriteContext
|
||||
import org.cadixdev.mercury.SourceProcessor
|
||||
import org.cadixdev.mercury.SourceRewriter
|
||||
import org.cadixdev.mercury.at.AccessTransformerRewriter
|
||||
import org.cadixdev.mercury.extra.AccessAnalyzerProcessor
|
||||
import org.cadixdev.mercury.extra.BridgeMethodRewriter
|
||||
import org.cadixdev.mercury.remapper.MercuryRemapper
|
||||
import org.cadixdev.mercury.util.BombeBindings
|
||||
import org.eclipse.jdt.core.dom.ASTNode
|
||||
import org.eclipse.jdt.core.dom.ASTVisitor
|
||||
import org.eclipse.jdt.core.dom.IMethodBinding
|
||||
import org.eclipse.jdt.core.dom.IVariableBinding
|
||||
import org.eclipse.jdt.core.dom.MethodDeclaration
|
||||
import org.eclipse.jdt.core.dom.Modifier
|
||||
import org.eclipse.jdt.core.dom.SimpleName
|
||||
import org.eclipse.jdt.core.dom.SingleVariableDeclaration
|
||||
import org.gradle.api.file.DirectoryProperty
|
||||
import org.gradle.api.file.RegularFileProperty
|
||||
import org.gradle.api.provider.Property
|
||||
import org.gradle.api.tasks.Input
|
||||
import org.gradle.api.tasks.InputDirectory
|
||||
import org.gradle.api.tasks.InputFile
|
||||
import org.gradle.api.tasks.OutputFile
|
||||
import org.gradle.kotlin.dsl.get
|
||||
import org.gradle.kotlin.dsl.property
|
||||
import java.io.File
|
||||
|
||||
open class RemapSources : ZippedTask() {
|
||||
|
||||
@InputFile
|
||||
val vanillaJar: RegularFileProperty = project.objects.fileProperty()
|
||||
@InputFile
|
||||
val vanillaRemappedSpigotJar: RegularFileProperty = project.objects.fileProperty() // Required for pre-remap pass
|
||||
@InputFile
|
||||
val vanillaRemappedSrgJar: RegularFileProperty = project.objects.fileProperty() // Required for post-remap pass
|
||||
@InputFile
|
||||
val spigotToSrg: RegularFileProperty = project.objects.fileProperty()
|
||||
@Input
|
||||
val configuration: Property<String> = project.objects.property()
|
||||
@InputFile
|
||||
val configFile: RegularFileProperty = project.objects.fileProperty()
|
||||
@InputDirectory
|
||||
val spigotServerDir: DirectoryProperty = project.objects.directoryProperty()
|
||||
@InputDirectory
|
||||
val spigotApiDir: DirectoryProperty = project.objects.directoryProperty()
|
||||
|
||||
@OutputFile
|
||||
val generatedAt: RegularFileProperty = project.objects.fileProperty()
|
||||
|
||||
override fun run(rootDir: File) {
|
||||
val config = mcpConfig(configFile)
|
||||
val constructors = mcpFile(configFile, config.data.constructors)
|
||||
|
||||
val spigotToSrgFile = spigotToSrg.file
|
||||
|
||||
val mappings = spigotToSrgFile.bufferedReader().use { reader ->
|
||||
MappingFormats.TSRG.createReader(reader).read()
|
||||
}
|
||||
|
||||
val srcDir = spigotServerDir.file.resolve("src/main/java")
|
||||
val pass1Dir = rootDir.resolve("pass1")
|
||||
val outDir = rootDir.resolve("out")
|
||||
|
||||
val configuration = project.configurations[configuration.get()]
|
||||
|
||||
val ats = AccessTransformSet.create()
|
||||
|
||||
Mercury().apply {
|
||||
classPath.addAll(listOf(
|
||||
vanillaJar.asFile.get().toPath(),
|
||||
vanillaRemappedSpigotJar.asFile.get().toPath(),
|
||||
spigotApiDir.file.resolve("src/main/java").toPath()
|
||||
))
|
||||
|
||||
for (file in configuration.resolvedConfiguration.files) {
|
||||
classPath.add(file.toPath())
|
||||
}
|
||||
|
||||
// Generate AT
|
||||
processors.add(AccessAnalyzerProcessor.create(ats, mappings))
|
||||
process(srcDir.toPath())
|
||||
|
||||
// Remap
|
||||
processors.clear()
|
||||
processors.addAll(listOf(
|
||||
MercuryRemapper.create(mappings),
|
||||
BridgeMethodRewriter.create(),
|
||||
AccessTransformerRewriter.create(ats)
|
||||
))
|
||||
|
||||
rewrite(srcDir.toPath(), pass1Dir.toPath())
|
||||
}
|
||||
|
||||
Mercury().apply {
|
||||
// Remap SRG parameters
|
||||
classPath.addAll(listOf(
|
||||
vanillaJar.asFile.get().toPath(),
|
||||
vanillaRemappedSrgJar.asFile.get().toPath(),
|
||||
spigotApiDir.file.resolve("src/main/java").toPath()
|
||||
))
|
||||
|
||||
processors.add(SrgParameterRemapper(constructors))
|
||||
|
||||
rewrite(pass1Dir.toPath(), outDir.toPath())
|
||||
}
|
||||
|
||||
// Only leave remapped source
|
||||
val fileList = rootDir.listFiles() ?: throw PaperweightException("Could not list files in $rootDir")
|
||||
for (file in fileList) {
|
||||
if (file != outDir) {
|
||||
file.deleteRecursively()
|
||||
}
|
||||
}
|
||||
|
||||
// Move out/* to base dir
|
||||
val files = outDir.listFiles() ?: throw PaperweightException("No files found in $outDir")
|
||||
for (file in files) {
|
||||
file.renameTo(rootDir.resolve(file.name))
|
||||
}
|
||||
outDir.delete()
|
||||
|
||||
// And write generated AT file
|
||||
AccessTransformFormats.FML.write(generatedAt.asFile.get().toPath(), ats)
|
||||
}
|
||||
}
|
||||
|
||||
class SrgParameterRemapper(constructors: File) : SourceRewriter {
|
||||
|
||||
private val constructorMap = hashMapOf<String, MutableList<ConstructorNode>>()
|
||||
|
||||
init {
|
||||
constructors.useLines { lines ->
|
||||
lines.forEach { line ->
|
||||
val parts = line.split(' ')
|
||||
constructorMap.compute(parts[1].replace('/', '.')) { _, v ->
|
||||
val node = ConstructorNode(parts[0].toInt(), parts[2])
|
||||
if (v == null) {
|
||||
return@compute mutableListOf(node)
|
||||
} else {
|
||||
v += node
|
||||
return@compute v
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (list in constructorMap.values) {
|
||||
// Put bigger numbers first...just trust me
|
||||
list.reverse()
|
||||
}
|
||||
}
|
||||
|
||||
override fun getFlags(): Int = SourceProcessor.FLAG_RESOLVE_BINDINGS
|
||||
|
||||
override fun rewrite(context: RewriteContext) {
|
||||
context.compilationUnit.accept(SrgParameterVisitor(context, constructorMap))
|
||||
}
|
||||
}
|
||||
|
||||
data class ConstructorNode(
|
||||
val id: Int,
|
||||
val signature: String
|
||||
)
|
||||
|
||||
class SrgParameterVisitor(
|
||||
private val context: RewriteContext,
|
||||
private val constructors: Map<String, List<ConstructorNode>>
|
||||
) : ASTVisitor() {
|
||||
|
||||
companion object {
|
||||
private val MATCHER = Regex("func_(\\d+)_.*")
|
||||
}
|
||||
|
||||
override fun visit(node: SimpleName): Boolean {
|
||||
val binding = node.resolveBinding() as? IVariableBinding ?: return false
|
||||
if (!binding.isParameter) {
|
||||
return false
|
||||
}
|
||||
|
||||
val methodDecl = findMethodDeclaration(node) ?: return false
|
||||
val method = binding.declaringMethod ?: return false
|
||||
|
||||
handleMethod(node, methodDecl, method)
|
||||
return false
|
||||
}
|
||||
|
||||
private fun handleMethod(node: SimpleName, methodDecl: MethodDeclaration, method: IMethodBinding) {
|
||||
if (method.isConstructor) {
|
||||
handleConstructor(node, methodDecl, method)
|
||||
return
|
||||
}
|
||||
|
||||
val match = MATCHER.matchEntire(method.name) ?: return
|
||||
val isStatic = method.modifiers and Modifier.STATIC != 0
|
||||
|
||||
val index = getParameterIndex(methodDecl, node)
|
||||
if (index == -1) {
|
||||
return
|
||||
}
|
||||
|
||||
val paramName = "p_${match.groupValues[1]}_${index + if (isStatic) 0 else 1}_"
|
||||
context.createASTRewrite().set(node, SimpleName.IDENTIFIER_PROPERTY, paramName, null)
|
||||
}
|
||||
|
||||
private fun handleConstructor(node: SimpleName, methodDecl: MethodDeclaration, method: IMethodBinding) {
|
||||
val constructorNodes = constructors[method.declaringClass.binaryName] ?: return
|
||||
|
||||
val constructorNode = constructorNodes.firstOrNull { constructorNode ->
|
||||
constructorNode.signature == BombeBindings.convertSignature(method).descriptor.toString()
|
||||
} ?: return
|
||||
|
||||
val id = constructorNode.id
|
||||
|
||||
val index = getParameterIndex(methodDecl, node)
|
||||
if (index == -1) {
|
||||
return
|
||||
}
|
||||
|
||||
val paramName = "p_i${id}_${index + 1}_"
|
||||
context.createASTRewrite().set(node, SimpleName.IDENTIFIER_PROPERTY, paramName, null)
|
||||
}
|
||||
|
||||
private fun findMethodDeclaration(node: ASTNode): MethodDeclaration? {
|
||||
var currentNode: ASTNode? = node
|
||||
while (currentNode != null && currentNode !is MethodDeclaration) {
|
||||
currentNode = currentNode.parent
|
||||
}
|
||||
return currentNode as? MethodDeclaration
|
||||
}
|
||||
|
||||
private fun getParameterIndex(methodDecl: MethodDeclaration, name: SimpleName): Int {
|
||||
// Can't find a better way to get the index..
|
||||
@Suppress("UNCHECKED_CAST")
|
||||
val params = methodDecl.parameters() as List<SingleVariableDeclaration>
|
||||
return params.indexOfFirst { it.name.identifier == name.identifier }
|
||||
}
|
||||
}
|
126
src/main/kotlin/tasks/RemapSrgSources.kt
Normal file
126
src/main/kotlin/tasks/RemapSrgSources.kt
Normal file
|
@ -0,0 +1,126 @@
|
|||
/*
|
||||
* paperweight is a Gradle plugin for the PaperMC project. It uses
|
||||
* some code and systems originally from ForgeGradle.
|
||||
*
|
||||
* Copyright (C) 2020 Kyle Wood
|
||||
* Copyright (C) 2018 Forge Development LLC
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
|
||||
* USA
|
||||
*/
|
||||
|
||||
package io.papermc.paperweight.tasks
|
||||
|
||||
import io.papermc.paperweight.PaperweightException
|
||||
import io.papermc.paperweight.util.getCsvReader
|
||||
import org.gradle.api.file.RegularFileProperty
|
||||
import org.gradle.api.tasks.InputFile
|
||||
import java.io.BufferedReader
|
||||
import java.io.BufferedWriter
|
||||
import java.io.File
|
||||
import java.util.regex.Pattern
|
||||
|
||||
open class RemapSrgSources : ZippedTask() {
|
||||
|
||||
@InputFile
|
||||
val methodsCsv: RegularFileProperty = project.objects.fileProperty()
|
||||
@InputFile
|
||||
val fieldsCsv: RegularFileProperty = project.objects.fileProperty()
|
||||
@InputFile
|
||||
val paramsCsv: RegularFileProperty = project.objects.fileProperty()
|
||||
|
||||
private val methods = hashMapOf<String, String>()
|
||||
private val methodDocs = hashMapOf<String, String>()
|
||||
private val fields = hashMapOf<String, String>()
|
||||
private val fieldDocs = hashMapOf<String, String>()
|
||||
private val params = hashMapOf<String, String>()
|
||||
|
||||
override fun run(rootDir: File) {
|
||||
readCsv()
|
||||
|
||||
rootDir.walkBottomUp()
|
||||
.filter { it.isFile && it.name.endsWith(".java") }
|
||||
.forEach(::processFile)
|
||||
}
|
||||
|
||||
private fun processFile(file: File) {
|
||||
val newFile = file.resolveSibling(file.name + ".bak")
|
||||
file.bufferedReader().use { reader ->
|
||||
newFile.bufferedWriter().use { writer ->
|
||||
writeFile(reader, writer)
|
||||
}
|
||||
}
|
||||
|
||||
if (!file.delete()) {
|
||||
throw PaperweightException("Failed to delete file: $file")
|
||||
}
|
||||
|
||||
newFile.renameTo(file)
|
||||
}
|
||||
|
||||
private fun writeFile(reader: BufferedReader, writer: BufferedWriter) {
|
||||
for (line in reader.lineSequence()) {
|
||||
replaceInLine(line, writer)
|
||||
}
|
||||
}
|
||||
|
||||
private fun replaceInLine(line: String, writer: BufferedWriter) {
|
||||
val buffer = StringBuffer()
|
||||
val matcher = SRG_FINDER.matcher(line)
|
||||
|
||||
while (matcher.find()) {
|
||||
val find = matcher.group()
|
||||
|
||||
val result = when {
|
||||
find.startsWith("p_") -> params[find]
|
||||
find.startsWith("func_") -> methods[find]
|
||||
find.startsWith("field_") -> fields[find]
|
||||
else -> null
|
||||
} ?: matcher.group()
|
||||
|
||||
matcher.appendReplacement(buffer, result)
|
||||
}
|
||||
|
||||
matcher.appendTail(buffer)
|
||||
|
||||
writer.appendln(buffer.toString())
|
||||
}
|
||||
|
||||
private fun readCsv() {
|
||||
readCsvFile(methodsCsv.asFile.get(), methods, methodDocs)
|
||||
readCsvFile(fieldsCsv.asFile.get(), fields, fieldDocs)
|
||||
|
||||
getCsvReader(paramsCsv.asFile.get()).use { reader ->
|
||||
for (line in reader.readAll()) {
|
||||
params[line[0]] = line[1]
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun readCsvFile(file: File, names: MutableMap<String, String>, docs: MutableMap<String, String>) {
|
||||
getCsvReader(file).use { reader ->
|
||||
for (line in reader.readAll()) {
|
||||
names[line[0]] = line[1]
|
||||
if (line[3].isNotEmpty()) {
|
||||
docs[line[0]] = line[3]
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
companion object {
|
||||
private val SRG_FINDER = Pattern.compile("func_[0-9]+_[a-zA-Z_]+|field_[0-9]+_[a-zA-Z_]+|p_[\\w]+_\\d+_\\b")
|
||||
}
|
||||
}
|
142
src/main/kotlin/tasks/RemapVanillaJarSpigot.kt
Normal file
142
src/main/kotlin/tasks/RemapVanillaJarSpigot.kt
Normal file
|
@ -0,0 +1,142 @@
|
|||
/*
|
||||
* paperweight is a Gradle plugin for the PaperMC project. It uses
|
||||
* some code and systems originally from ForgeGradle.
|
||||
*
|
||||
* Copyright (C) 2020 Kyle Wood
|
||||
* Copyright (C) 2018 Forge Development LLC
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
|
||||
* USA
|
||||
*/
|
||||
|
||||
package io.papermc.paperweight.tasks
|
||||
|
||||
import io.papermc.paperweight.util.Constants.paperTaskOutput
|
||||
import io.papermc.paperweight.util.cache
|
||||
import io.papermc.paperweight.util.runJar
|
||||
import io.papermc.paperweight.util.toProvider
|
||||
import io.papermc.paperweight.util.wrapException
|
||||
import org.gradle.api.DefaultTask
|
||||
import org.gradle.api.file.RegularFileProperty
|
||||
import org.gradle.api.provider.Property
|
||||
import org.gradle.api.tasks.Input
|
||||
import org.gradle.api.tasks.InputFile
|
||||
import org.gradle.api.tasks.OutputFile
|
||||
import org.gradle.api.tasks.TaskAction
|
||||
import org.gradle.kotlin.dsl.property
|
||||
|
||||
open class RemapVanillaJarSpigot : DefaultTask() {
|
||||
|
||||
@InputFile
|
||||
val inputJar: RegularFileProperty = project.objects.fileProperty()
|
||||
|
||||
@InputFile
|
||||
val classMappings: RegularFileProperty = project.objects.fileProperty()
|
||||
@InputFile
|
||||
val memberMappings: RegularFileProperty = project.objects.fileProperty()
|
||||
@InputFile
|
||||
val packageMappings: RegularFileProperty = project.objects.fileProperty()
|
||||
@InputFile
|
||||
val accessTransformers: RegularFileProperty = project.objects.fileProperty()
|
||||
|
||||
@Input
|
||||
val workDirName: Property<String> = project.objects.property()
|
||||
|
||||
@InputFile
|
||||
val specialSourceJar: RegularFileProperty = project.objects.fileProperty()
|
||||
@InputFile
|
||||
val specialSource2Jar: RegularFileProperty = project.objects.fileProperty()
|
||||
|
||||
@Input
|
||||
val classMapCommand: Property<String> = project.objects.property()
|
||||
@Input
|
||||
val memberMapCommand: Property<String> = project.objects.property()
|
||||
@Input
|
||||
val finalMapCommand: Property<String> = project.objects.property()
|
||||
|
||||
@OutputFile
|
||||
val outputJar: RegularFileProperty = project.objects.run {
|
||||
fileProperty().convention(project.toProvider(project.cache.resolve(paperTaskOutput())))
|
||||
}
|
||||
|
||||
@TaskAction
|
||||
fun run() {
|
||||
val inputJarPath = inputJar.asFile.get().canonicalPath
|
||||
|
||||
val outputJarFile = outputJar.asFile.get()
|
||||
val outputJarPath = outputJarFile.canonicalPath
|
||||
|
||||
val classJarFile = outputJarFile.resolveSibling(outputJarFile.name + ".classes")
|
||||
val membersJarFile = outputJarFile.resolveSibling(outputJarFile.name + ".members")
|
||||
val classJarPath = classJarFile.canonicalPath
|
||||
val membersJarPath = membersJarFile.canonicalPath
|
||||
|
||||
val classMappingPath = classMappings.asFile.get().canonicalPath
|
||||
val memberMappingsPath = memberMappings.asFile.get().canonicalPath
|
||||
val packageMappingsPath = packageMappings.asFile.get().canonicalPath
|
||||
val accessTransformersPath = accessTransformers.asFile.get().canonicalPath
|
||||
|
||||
try {
|
||||
println("Applying class mappings...")
|
||||
wrapException("Failed to apply class mappings") {
|
||||
val logFile = project.cache.resolve(paperTaskOutput("class.log"))
|
||||
logFile.delete()
|
||||
runJar(
|
||||
specialSource2Jar,
|
||||
workingDir = workDirName.get(),
|
||||
logFile = logFile,
|
||||
args = *doReplacements(classMapCommand.get(), inputJarPath, classMappingPath, classJarPath)
|
||||
)
|
||||
}
|
||||
println("Applying member mappings...")
|
||||
wrapException("Failed to apply member mappings") {
|
||||
val logFile = project.cache.resolve(paperTaskOutput("member.log"))
|
||||
logFile.delete()
|
||||
runJar(
|
||||
specialSource2Jar,
|
||||
workingDir = workDirName.get(),
|
||||
logFile = logFile,
|
||||
args = *doReplacements(memberMapCommand.get(), classJarPath, memberMappingsPath, membersJarPath)
|
||||
)
|
||||
}
|
||||
println("Creating remapped jar...")
|
||||
wrapException("Failed to create remapped jar") {
|
||||
val logFile = project.cache.resolve(paperTaskOutput("final.log"))
|
||||
logFile.delete()
|
||||
runJar(
|
||||
specialSourceJar,
|
||||
workingDir = workDirName.get(),
|
||||
logFile = logFile,
|
||||
args = *doReplacements(finalMapCommand.get(), membersJarPath, accessTransformersPath, packageMappingsPath, outputJarPath)
|
||||
)
|
||||
}
|
||||
} finally {
|
||||
classJarFile.delete()
|
||||
membersJarFile.delete()
|
||||
}
|
||||
}
|
||||
|
||||
private val indexReg = Regex("\\{(\\d)}")
|
||||
private fun doReplacements(command: String, vararg values: String): Array<String> {
|
||||
return command.split(" ").let { it.subList(3, it.size) }.map {
|
||||
val index = indexReg.matchEntire(it)?.groupValues?.get(1)?.toInt()
|
||||
return@map if (index != null) {
|
||||
values[index]
|
||||
} else {
|
||||
it
|
||||
}
|
||||
}.toTypedArray()
|
||||
}
|
||||
}
|
68
src/main/kotlin/tasks/RemapVanillaJarSrg.kt
Normal file
68
src/main/kotlin/tasks/RemapVanillaJarSrg.kt
Normal file
|
@ -0,0 +1,68 @@
|
|||
/*
|
||||
* paperweight is a Gradle plugin for the PaperMC project. It uses
|
||||
* some code and systems originally from ForgeGradle.
|
||||
*
|
||||
* Copyright (C) 2020 Kyle Wood
|
||||
* Copyright (C) 2018 Forge Development LLC
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
|
||||
* USA
|
||||
*/
|
||||
|
||||
package io.papermc.paperweight.tasks
|
||||
|
||||
import io.papermc.paperweight.util.Constants.paperTaskOutput
|
||||
import io.papermc.paperweight.util.cache
|
||||
import io.papermc.paperweight.util.ensureDeleted
|
||||
import io.papermc.paperweight.util.ensureParentExists
|
||||
import io.papermc.paperweight.util.file
|
||||
import io.papermc.paperweight.util.toProvider
|
||||
import org.cadixdev.atlas.Atlas
|
||||
import org.cadixdev.bombe.asm.jar.JarEntryRemappingTransformer
|
||||
import org.cadixdev.lorenz.asm.LorenzRemapper
|
||||
import org.cadixdev.lorenz.io.MappingFormats
|
||||
import org.gradle.api.DefaultTask
|
||||
import org.gradle.api.file.RegularFileProperty
|
||||
import org.gradle.api.tasks.InputFile
|
||||
import org.gradle.api.tasks.OutputFile
|
||||
import org.gradle.api.tasks.TaskAction
|
||||
|
||||
open class RemapVanillaJarSrg : DefaultTask() {
|
||||
|
||||
@InputFile
|
||||
val inputJar: RegularFileProperty = project.objects.fileProperty()
|
||||
|
||||
@InputFile
|
||||
val mappings: RegularFileProperty = project.objects.fileProperty()
|
||||
|
||||
@OutputFile
|
||||
val outputJar: RegularFileProperty = project.objects.run {
|
||||
fileProperty().convention(project.toProvider(project.cache.resolve(paperTaskOutput())))
|
||||
}
|
||||
|
||||
@TaskAction
|
||||
fun run() {
|
||||
ensureParentExists(outputJar.file)
|
||||
ensureDeleted(outputJar.file)
|
||||
|
||||
val mappings = MappingFormats.TSRG.createReader(mappings.file.toPath()).read()
|
||||
Atlas().apply {
|
||||
install { ctx ->
|
||||
JarEntryRemappingTransformer(LorenzRemapper(mappings, ctx.inheritanceProvider()))
|
||||
}
|
||||
run(inputJar.file.toPath(), outputJar.file.toPath())
|
||||
}
|
||||
}
|
||||
}
|
82
src/main/kotlin/tasks/RunForgeFlower.kt
Normal file
82
src/main/kotlin/tasks/RunForgeFlower.kt
Normal file
|
@ -0,0 +1,82 @@
|
|||
/*
|
||||
* paperweight is a Gradle plugin for the PaperMC project. It uses
|
||||
* some code and systems originally from ForgeGradle.
|
||||
*
|
||||
* Copyright (C) 2020 Kyle Wood
|
||||
* Copyright (C) 2018 Forge Development LLC
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
|
||||
* USA
|
||||
*/
|
||||
|
||||
package io.papermc.paperweight.tasks
|
||||
|
||||
import io.papermc.paperweight.util.Constants.paperTaskOutput
|
||||
import io.papermc.paperweight.util.cache
|
||||
import io.papermc.paperweight.util.file
|
||||
import io.papermc.paperweight.util.mcpConfig
|
||||
import io.papermc.paperweight.util.runJar
|
||||
import io.papermc.paperweight.util.toProvider
|
||||
import org.gradle.api.DefaultTask
|
||||
import org.gradle.api.file.RegularFileProperty
|
||||
import org.gradle.api.provider.Property
|
||||
import org.gradle.api.tasks.Input
|
||||
import org.gradle.api.tasks.InputFile
|
||||
import org.gradle.api.tasks.OutputFile
|
||||
import org.gradle.api.tasks.TaskAction
|
||||
import org.gradle.kotlin.dsl.get
|
||||
import org.gradle.kotlin.dsl.property
|
||||
|
||||
open class RunForgeFlower : DefaultTask() {
|
||||
|
||||
@Input
|
||||
val configuration: Property<String> = project.objects.property()
|
||||
|
||||
@InputFile
|
||||
val inputJar: RegularFileProperty = project.objects.fileProperty()
|
||||
@InputFile
|
||||
val libraries: RegularFileProperty = project.objects.fileProperty()
|
||||
|
||||
@InputFile
|
||||
val configFile: RegularFileProperty = project.objects.fileProperty()
|
||||
|
||||
@OutputFile
|
||||
val outputJar: RegularFileProperty = project.objects.run {
|
||||
fileProperty().convention(project.toProvider(project.cache.resolve(paperTaskOutput())))
|
||||
}
|
||||
|
||||
@TaskAction
|
||||
fun run() {
|
||||
val config = mcpConfig(configFile)
|
||||
|
||||
val forgeFlowerArgs = config.functions.getValue("decompile").args
|
||||
val jvmArgs = config.functions.getValue("decompile").jvmargs ?: listOf()
|
||||
|
||||
val argList = forgeFlowerArgs.map {
|
||||
when (it) {
|
||||
"{libraries}" -> libraries.file.absolutePath
|
||||
"{input}" -> inputJar.file.absolutePath
|
||||
"{output}" -> outputJar.file.absolutePath
|
||||
else -> it
|
||||
}
|
||||
}
|
||||
|
||||
val logFile = project.cache.resolve(paperTaskOutput("log"))
|
||||
logFile.delete()
|
||||
|
||||
val forgeFlowerJar = project.configurations[configuration.get()].resolve().single()
|
||||
runJar(forgeFlowerJar, project.cache, logFile, jvmArgs = jvmArgs, args = *argList.toTypedArray())
|
||||
}
|
||||
}
|
87
src/main/kotlin/tasks/RunMcInjector.kt
Normal file
87
src/main/kotlin/tasks/RunMcInjector.kt
Normal file
|
@ -0,0 +1,87 @@
|
|||
/*
|
||||
* paperweight is a Gradle plugin for the PaperMC project. It uses
|
||||
* some code and systems originally from ForgeGradle.
|
||||
*
|
||||
* Copyright (C) 2020 Kyle Wood
|
||||
* Copyright (C) 2018 Forge Development LLC
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
|
||||
* USA
|
||||
*/
|
||||
|
||||
package io.papermc.paperweight.tasks
|
||||
|
||||
import io.papermc.paperweight.util.Constants.paperTaskOutput
|
||||
import io.papermc.paperweight.util.cache
|
||||
import io.papermc.paperweight.util.file
|
||||
import io.papermc.paperweight.util.mcpConfig
|
||||
import io.papermc.paperweight.util.mcpFile
|
||||
import io.papermc.paperweight.util.runJar
|
||||
import io.papermc.paperweight.util.toProvider
|
||||
import org.gradle.api.DefaultTask
|
||||
import org.gradle.api.file.RegularFileProperty
|
||||
import org.gradle.api.provider.Property
|
||||
import org.gradle.api.tasks.Input
|
||||
import org.gradle.api.tasks.InputFile
|
||||
import org.gradle.api.tasks.OutputFile
|
||||
import org.gradle.api.tasks.TaskAction
|
||||
import org.gradle.kotlin.dsl.get
|
||||
import org.gradle.kotlin.dsl.property
|
||||
|
||||
open class RunMcInjector : DefaultTask() {
|
||||
|
||||
@Input
|
||||
val configuration: Property<String> = project.objects.property()
|
||||
@InputFile
|
||||
val inputJar: RegularFileProperty = project.objects.fileProperty()
|
||||
@InputFile
|
||||
val configFile: RegularFileProperty = project.objects.fileProperty()
|
||||
|
||||
@OutputFile
|
||||
val outputJar: RegularFileProperty = project.objects.run {
|
||||
fileProperty().convention(project.toProvider(project.cache.resolve(paperTaskOutput())))
|
||||
}
|
||||
@OutputFile
|
||||
val logFile: RegularFileProperty = project.objects.run {
|
||||
fileProperty().convention(project.toProvider(project.cache.resolve(paperTaskOutput("log"))))
|
||||
}
|
||||
|
||||
@TaskAction
|
||||
fun run() {
|
||||
val config = mcpConfig(configFile)
|
||||
val exceptions = mcpFile(configFile, config.data.exceptions)
|
||||
val access = mcpFile(configFile, config.data.access)
|
||||
val constructors = mcpFile(configFile, config.data.constructors)
|
||||
|
||||
val mcInjectorArgs = config.functions.getValue("mcinject").args
|
||||
val jvmArgs = config.functions.getValue("mcinject").jvmargs ?: listOf()
|
||||
|
||||
val argList = mcInjectorArgs.map {
|
||||
when (it) {
|
||||
"{input}" -> inputJar.file.absolutePath
|
||||
"{output}" -> outputJar.file.absolutePath
|
||||
"{log}" -> logFile.file.absolutePath
|
||||
"{exceptions}" -> exceptions.absolutePath
|
||||
"{access}" -> access.absolutePath
|
||||
"{constructors}" -> constructors.absolutePath
|
||||
else -> it
|
||||
}
|
||||
}
|
||||
|
||||
val mcInjectorJar = project.configurations[configuration.get()].resolve().single()
|
||||
|
||||
runJar(mcInjectorJar, project.cache, logFile = null, jvmArgs = jvmArgs, args = *argList.toTypedArray())
|
||||
}
|
||||
}
|
55
src/main/kotlin/tasks/SetupMcpDependencies.kt
Normal file
55
src/main/kotlin/tasks/SetupMcpDependencies.kt
Normal file
|
@ -0,0 +1,55 @@
|
|||
/*
|
||||
* paperweight is a Gradle plugin for the PaperMC project. It uses
|
||||
* some code and systems originally from ForgeGradle.
|
||||
*
|
||||
* Copyright (C) 2020 Kyle Wood
|
||||
* Copyright (C) 2018 Forge Development LLC
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
|
||||
* USA
|
||||
*/
|
||||
|
||||
package io.papermc.paperweight.tasks
|
||||
|
||||
import io.papermc.paperweight.util.mcpConfig
|
||||
import org.gradle.api.DefaultTask
|
||||
import org.gradle.api.file.RegularFileProperty
|
||||
import org.gradle.api.provider.Property
|
||||
import org.gradle.api.tasks.Input
|
||||
import org.gradle.api.tasks.InputFile
|
||||
import org.gradle.api.tasks.TaskAction
|
||||
import org.gradle.kotlin.dsl.property
|
||||
|
||||
open class SetupMcpDependencies : DefaultTask() {
|
||||
|
||||
@InputFile
|
||||
val configFile: RegularFileProperty = project.objects.fileProperty()
|
||||
@Input
|
||||
val forgeFlowerConfig: Property<String> = project.objects.property()
|
||||
@Input
|
||||
val mcInjectorConfig: Property<String> = project.objects.property()
|
||||
|
||||
init {
|
||||
outputs.upToDateWhen { false }
|
||||
}
|
||||
|
||||
@TaskAction
|
||||
fun run() {
|
||||
val config = mcpConfig(configFile)
|
||||
|
||||
project.dependencies.add(forgeFlowerConfig.get(), config.functions.getValue("decompile").version)
|
||||
project.dependencies.add(mcInjectorConfig.get(), config.functions.getValue("mcinject").version)
|
||||
}
|
||||
}
|
117
src/main/kotlin/tasks/SetupSpigotDependencies.kt
Normal file
117
src/main/kotlin/tasks/SetupSpigotDependencies.kt
Normal file
|
@ -0,0 +1,117 @@
|
|||
/*
|
||||
* paperweight is a Gradle plugin for the PaperMC project. It uses
|
||||
* some code and systems originally from ForgeGradle.
|
||||
*
|
||||
* Copyright (C) 2020 Kyle Wood
|
||||
* Copyright (C) 2018 Forge Development LLC
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
|
||||
* USA
|
||||
*/
|
||||
|
||||
package io.papermc.paperweight.tasks
|
||||
|
||||
import io.papermc.paperweight.util.file
|
||||
import org.gradle.api.DefaultTask
|
||||
import org.gradle.api.file.DirectoryProperty
|
||||
import org.gradle.api.provider.Property
|
||||
import org.gradle.api.tasks.Input
|
||||
import org.gradle.api.tasks.InputDirectory
|
||||
import org.gradle.api.tasks.TaskAction
|
||||
import org.gradle.kotlin.dsl.property
|
||||
import org.w3c.dom.Element
|
||||
import java.io.File
|
||||
import javax.xml.parsers.DocumentBuilderFactory
|
||||
|
||||
open class SetupSpigotDependencies : DefaultTask() {
|
||||
|
||||
@InputDirectory
|
||||
val spigotApi: DirectoryProperty = project.objects.directoryProperty()
|
||||
@InputDirectory
|
||||
val spigotServer: DirectoryProperty = project.objects.directoryProperty()
|
||||
|
||||
@Input
|
||||
val configurationName: Property<String> = project.objects.property()
|
||||
|
||||
init {
|
||||
// we set dependencies here, can't cache this
|
||||
outputs.upToDateWhen { false }
|
||||
}
|
||||
|
||||
@TaskAction
|
||||
fun run() {
|
||||
val apiDeps = parsePom(spigotApi.file.resolve("pom.xml"))
|
||||
val serverDeps = parsePom(spigotServer.file.resolve("pom.xml"))
|
||||
|
||||
for (dep in apiDeps) {
|
||||
project.dependencies.add(configurationName.get(), dep)
|
||||
}
|
||||
for (dep in serverDeps) {
|
||||
project.dependencies.add(configurationName.get(), dep)
|
||||
}
|
||||
}
|
||||
|
||||
private fun parsePom(pomFile: File): List<String> {
|
||||
val depList = arrayListOf<String>()
|
||||
|
||||
val builder = DocumentBuilderFactory.newInstance().newDocumentBuilder()
|
||||
val doc = pomFile.inputStream().buffered().use { stream ->
|
||||
stream.buffered().use { buffered ->
|
||||
builder.parse(buffered)
|
||||
}
|
||||
}
|
||||
|
||||
doc.documentElement.normalize()
|
||||
|
||||
val list = doc.getElementsByTagName("dependencies")
|
||||
for (i in 0 until list.length) {
|
||||
val node = list.item(i) as? Element ?: continue
|
||||
|
||||
val depNode = node.getElementsByTagName("dependency")
|
||||
for (j in 0 until depNode.length) {
|
||||
val dependency = depNode.item(j) as? Element ?: continue
|
||||
val text = getDependency(dependency) ?: continue
|
||||
depList += text
|
||||
}
|
||||
}
|
||||
|
||||
return depList
|
||||
}
|
||||
|
||||
private fun getDependency(node: Element): String? {
|
||||
val scopeNode = node.getElementsByTagName("scope")
|
||||
val scope = if (scopeNode.length == 0) {
|
||||
"compile"
|
||||
} else {
|
||||
scopeNode.item(0).textContent
|
||||
}
|
||||
|
||||
if (scope != "compile") {
|
||||
return null
|
||||
}
|
||||
|
||||
val group = node.getElementsByTagName("groupId").item(0).textContent
|
||||
val artifact = node.getElementsByTagName("artifactId").item(0).textContent
|
||||
val version = node.getElementsByTagName("version").item(0).textContent
|
||||
|
||||
if (version.contains("\${")) {
|
||||
// Don't handle complicated things
|
||||
// We don't need to (for now anyways)
|
||||
return null
|
||||
}
|
||||
|
||||
return "$group:$artifact:$version"
|
||||
}
|
||||
}
|
61
src/main/kotlin/tasks/WriteLibrariesFile.kt
Normal file
61
src/main/kotlin/tasks/WriteLibrariesFile.kt
Normal file
|
@ -0,0 +1,61 @@
|
|||
/*
|
||||
* paperweight is a Gradle plugin for the PaperMC project. It uses
|
||||
* some code and systems originally from ForgeGradle.
|
||||
*
|
||||
* Copyright (C) 2020 Kyle Wood
|
||||
* Copyright (C) 2018 Forge Development LLC
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
|
||||
* USA
|
||||
*/
|
||||
|
||||
package io.papermc.paperweight.tasks
|
||||
|
||||
import io.papermc.paperweight.util.Constants.paperTaskOutput
|
||||
import io.papermc.paperweight.util.cache
|
||||
import io.papermc.paperweight.util.file
|
||||
import io.papermc.paperweight.util.toProvider
|
||||
import org.gradle.api.DefaultTask
|
||||
import org.gradle.api.file.RegularFileProperty
|
||||
import org.gradle.api.provider.ListProperty
|
||||
import org.gradle.api.tasks.Classpath
|
||||
import org.gradle.api.tasks.OutputFile
|
||||
import org.gradle.api.tasks.TaskAction
|
||||
import org.gradle.kotlin.dsl.listProperty
|
||||
import java.io.File
|
||||
|
||||
open class WriteLibrariesFile : DefaultTask() {
|
||||
|
||||
@Classpath
|
||||
val inputFiles: ListProperty<File> = project.objects.listProperty()
|
||||
|
||||
@OutputFile
|
||||
val outputFile: RegularFileProperty = project.objects.run {
|
||||
fileProperty().convention(project.toProvider(project.cache.resolve(paperTaskOutput("txt"))))
|
||||
}
|
||||
|
||||
@TaskAction
|
||||
fun run() {
|
||||
val files = inputFiles.get()
|
||||
files.sort()
|
||||
|
||||
outputFile.file.delete()
|
||||
outputFile.file.bufferedWriter().use { writer ->
|
||||
for (file in files) {
|
||||
writer.appendln("-e=${file.absolutePath}")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
84
src/main/kotlin/tasks/ZippedTask.kt
Normal file
84
src/main/kotlin/tasks/ZippedTask.kt
Normal file
|
@ -0,0 +1,84 @@
|
|||
/*
|
||||
* paperweight is a Gradle plugin for the PaperMC project. It uses
|
||||
* some code and systems originally from ForgeGradle.
|
||||
*
|
||||
* Copyright (C) 2020 Kyle Wood
|
||||
* Copyright (C) 2018 Forge Development LLC
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
|
||||
* USA
|
||||
*/
|
||||
|
||||
package io.papermc.paperweight.tasks
|
||||
|
||||
import io.papermc.paperweight.util.Constants.paperTaskOutput
|
||||
import io.papermc.paperweight.util.cache
|
||||
import io.papermc.paperweight.util.ensureDeleted
|
||||
import io.papermc.paperweight.util.file
|
||||
import io.papermc.paperweight.util.fileOrNull
|
||||
import io.papermc.paperweight.util.toProvider
|
||||
import io.papermc.paperweight.util.unzip
|
||||
import io.papermc.paperweight.util.zip
|
||||
import org.gradle.api.DefaultTask
|
||||
import org.gradle.api.file.RegularFileProperty
|
||||
import org.gradle.api.tasks.InputFile
|
||||
import org.gradle.api.tasks.Optional
|
||||
import org.gradle.api.tasks.OutputFile
|
||||
import org.gradle.api.tasks.TaskAction
|
||||
import java.io.File
|
||||
import java.util.concurrent.ThreadLocalRandom
|
||||
|
||||
abstract class ZippedTask : DefaultTask() {
|
||||
|
||||
@InputFile
|
||||
@Optional
|
||||
val inputZip: RegularFileProperty = project.objects.fileProperty()
|
||||
|
||||
@OutputFile
|
||||
val outputZip: RegularFileProperty = project.objects.run {
|
||||
fileProperty().convention(project.toProvider(project.cache.resolve(paperTaskOutput("zip"))))
|
||||
}
|
||||
|
||||
abstract fun run(rootDir: File)
|
||||
|
||||
@TaskAction
|
||||
fun exec() {
|
||||
val outputZipFile = outputZip.file
|
||||
val outputDir = findOutputDir(outputZipFile)
|
||||
|
||||
try {
|
||||
val input = inputZip.fileOrNull
|
||||
if (input != null) {
|
||||
unzip(input, outputDir)
|
||||
}
|
||||
|
||||
run(outputDir)
|
||||
|
||||
ensureDeleted(outputZipFile)
|
||||
|
||||
zip(outputDir, outputZipFile)
|
||||
} finally {
|
||||
outputDir.deleteRecursively()
|
||||
}
|
||||
}
|
||||
|
||||
private fun findOutputDir(baseFile: File): File {
|
||||
var dir: File
|
||||
do {
|
||||
dir = baseFile.resolveSibling("${baseFile.name}-" + ThreadLocalRandom.current().nextInt())
|
||||
} while (dir.exists())
|
||||
return dir
|
||||
}
|
||||
}
|
69
src/main/kotlin/util/ArtifactDescriptor.kt
Normal file
69
src/main/kotlin/util/ArtifactDescriptor.kt
Normal file
|
@ -0,0 +1,69 @@
|
|||
/*
|
||||
* paperweight is a Gradle plugin for the PaperMC project. It uses
|
||||
* some code and systems originally from ForgeGradle.
|
||||
*
|
||||
* Copyright (C) 2020 Kyle Wood
|
||||
* Copyright (C) 2018 Forge Development LLC
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
|
||||
* USA
|
||||
*/
|
||||
|
||||
package io.papermc.paperweight.util
|
||||
|
||||
import io.papermc.paperweight.PaperweightException
|
||||
|
||||
data class ArtifactDescriptor(
|
||||
val group: String,
|
||||
val artifact: String,
|
||||
val version: String,
|
||||
val classifier: String?,
|
||||
val extension: String
|
||||
) {
|
||||
override fun toString(): String {
|
||||
val path = group.replace('.', '/')
|
||||
val classifierText = classifier?.let { "-$it" } ?: ""
|
||||
val file = "$artifact-$version$classifierText.$extension"
|
||||
return "$path/$artifact/$version/$file"
|
||||
}
|
||||
|
||||
companion object {
|
||||
fun parse(text: String): ArtifactDescriptor {
|
||||
val (group, groupIndex) = text.nextSubstring(0, charArrayOf(':'))
|
||||
val (artifact, artifactIndex) = text.nextSubstring(groupIndex, charArrayOf(':'))
|
||||
val (version, versionIndex) = text.nextSubstring(artifactIndex, charArrayOf(':', '@'), goToEnd = true)
|
||||
val (classifier, classifierIndex) = text.nextSubstring(versionIndex, charArrayOf(':', '@'), goToEnd = true)
|
||||
val (extension, _) = text.nextSubstring(classifierIndex, charArrayOf(), goToEnd = true)
|
||||
|
||||
group ?: throw PaperweightException("Invalid Maven artifact descriptor (no groupId found): $text")
|
||||
artifact ?: throw PaperweightException("Invalid Maven artifact descriptor (no artifactId found): $text")
|
||||
version ?: throw PaperweightException("Invalid Maven artifact descriptor (no version found): $text")
|
||||
|
||||
return ArtifactDescriptor(group, artifact, version, classifier, extension ?: "jar")
|
||||
}
|
||||
|
||||
private fun String.nextSubstring(startIndex: Int, stops: CharArray, goToEnd: Boolean = false): Pair<String?, Int> {
|
||||
if (startIndex == this.length) {
|
||||
return null to startIndex
|
||||
}
|
||||
val endIndex = this.indexOfAny(stops, startIndex)
|
||||
return when {
|
||||
endIndex != -1 -> this.substring(startIndex, endIndex) to endIndex + 1
|
||||
goToEnd -> this.substring(startIndex) to this.length
|
||||
else -> null to startIndex
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
38
src/main/kotlin/util/BuildDataInfo.kt
Normal file
38
src/main/kotlin/util/BuildDataInfo.kt
Normal file
|
@ -0,0 +1,38 @@
|
|||
/*
|
||||
* paperweight is a Gradle plugin for the PaperMC project. It uses
|
||||
* some code and systems originally from ForgeGradle.
|
||||
*
|
||||
* Copyright (C) 2020 Kyle Wood
|
||||
* Copyright (C) 2018 Forge Development LLC
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
|
||||
* USA
|
||||
*/
|
||||
|
||||
package util
|
||||
|
||||
data class BuildDataInfo(
|
||||
val minecraftVersion: String,
|
||||
val serverUrl: String,
|
||||
val minecraftHash: String,
|
||||
val accessTransforms: String,
|
||||
val classMappings: String,
|
||||
val memberMappings: String,
|
||||
val packageMappings: String,
|
||||
val classMapCommand: String,
|
||||
val memberMapCommand: String,
|
||||
val finalMapCommand: String,
|
||||
val decompileCommand: String
|
||||
)
|
78
src/main/kotlin/util/Constants.kt
Normal file
78
src/main/kotlin/util/Constants.kt
Normal file
|
@ -0,0 +1,78 @@
|
|||
/*
|
||||
* paperweight is a Gradle plugin for the PaperMC project. It uses
|
||||
* some code and systems originally from ForgeGradle.
|
||||
*
|
||||
* Copyright (C) 2020 Kyle Wood
|
||||
* Copyright (C) 2018 Forge Development LLC
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
|
||||
* USA
|
||||
*/
|
||||
|
||||
package io.papermc.paperweight.util
|
||||
|
||||
import org.gradle.api.Task
|
||||
|
||||
object Constants {
|
||||
const val EXTENSION = "paperweight"
|
||||
|
||||
const val MCP_MAPPINGS_CONFIG = "mcpConfig"
|
||||
|
||||
const val MCP_DATA_CONFIG = "mcpData"
|
||||
const val SPIGOT_DEP_CONFIG = "spigotDeps"
|
||||
const val MINECRAFT_DEP_CONFIG = "minecraft"
|
||||
const val FORGE_FLOWER_CONFIG = "forgeFlower"
|
||||
const val MCINJECT_CONFIG = "mcinject"
|
||||
|
||||
const val FORGE_MAVEN_URL = "https://files.minecraftforge.net/maven"
|
||||
const val MC_LIBRARY_URL = "https://libraries.minecraft.net/"
|
||||
const val MC_MANIFEST_URL = "https://launchermeta.mojang.com/mc/game/version_manifest.json"
|
||||
|
||||
const val CACHE_PATH = "caches"
|
||||
private const val PAPER_PATH = "paperweight"
|
||||
|
||||
const val MCP_DATA_DIR = "mcp/data"
|
||||
const val MCP_MAPPINGS_DIR = "mcp/mappings"
|
||||
const val SRG_DIR = "$MCP_MAPPINGS_DIR/srgs"
|
||||
|
||||
const val PAPER_FIELDS_CSV = "$MCP_MAPPINGS_DIR/paper_fields.csv"
|
||||
const val PAPER_METHODS_CSV = "$MCP_MAPPINGS_DIR/paper_methods.csv"
|
||||
const val PAPER_PARAMS_CSV = "$MCP_MAPPINGS_DIR/paper_params.csv"
|
||||
|
||||
const val NOTCH_TO_SRG = "$SRG_DIR/notch-srg.tsrg"
|
||||
const val NOTCH_TO_MCP = "$SRG_DIR/notch-mcp.tsrg"
|
||||
const val NOTCH_TO_SPIGOT = "$SRG_DIR/notch-spigot.tsrg"
|
||||
|
||||
const val MCP_TO_NOTCH = "$SRG_DIR/mcp-notch.tsrg"
|
||||
const val MCP_TO_SRG = "$SRG_DIR/mcp-srg.tsrg"
|
||||
const val MCP_TO_SPIGOT = "$SRG_DIR/mcp-spigot.tsrg"
|
||||
|
||||
const val SRG_TO_NOTCH = "$SRG_DIR/srg-notch.tsrg"
|
||||
const val SRG_TO_MCP = "$SRG_DIR/srg-mcp.tsrg"
|
||||
const val SRG_TO_SPIGOT = "$SRG_DIR/srg-spigot.tsrg"
|
||||
|
||||
const val SPIGOT_TO_NOTCH = "$SRG_DIR/spigot-notch.tsrg"
|
||||
const val SPIGOT_TO_SRG = "$SRG_DIR/spigot-srg.tsrg"
|
||||
const val SPIGOT_TO_MCP = "$SRG_DIR/spigot-mcp.tsrg"
|
||||
|
||||
const val MC_MANIFEST = "jsons/McManifest.json"
|
||||
const val VERSION_JSON = "jsons/McVersion.json"
|
||||
|
||||
const val TASK_CACHE = "$PAPER_PATH/taskCache"
|
||||
|
||||
fun Task.paperTaskOutput() = paperTaskOutput("jar")
|
||||
fun Task.paperTaskOutput(ext: String) = paperTaskOutput(name, ext)
|
||||
fun Task.paperTaskOutput(name: String, ext: String) = "$TASK_CACHE/$name.$ext"
|
||||
}
|
55
src/main/kotlin/util/McpConfig.kt
Normal file
55
src/main/kotlin/util/McpConfig.kt
Normal file
|
@ -0,0 +1,55 @@
|
|||
/*
|
||||
* paperweight is a Gradle plugin for the PaperMC project. It uses
|
||||
* some code and systems originally from ForgeGradle.
|
||||
*
|
||||
* Copyright (C) 2020 Kyle Wood
|
||||
* Copyright (C) 2018 Forge Development LLC
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
|
||||
* USA
|
||||
*/
|
||||
|
||||
package io.papermc.paperweight.util
|
||||
|
||||
data class McpConfig(
|
||||
val spec: Int,
|
||||
val version: String,
|
||||
val data: McpConfigData,
|
||||
val steps: Map<String, List<Map<String, String>>>,
|
||||
val functions: Map<String, McpJvmCommand>
|
||||
)
|
||||
|
||||
data class McpConfigData(
|
||||
val access: String,
|
||||
val constructors: String,
|
||||
val exceptions: String,
|
||||
val mappings: String,
|
||||
val inject: String,
|
||||
val statics: String,
|
||||
val patches: McpConfigDataPatches
|
||||
)
|
||||
|
||||
data class McpConfigDataPatches(
|
||||
val client: String,
|
||||
val joined: String,
|
||||
val server: String
|
||||
)
|
||||
|
||||
data class McpJvmCommand(
|
||||
val version: String,
|
||||
val args: List<String>,
|
||||
val repo: String,
|
||||
val jvmargs: List<String>?
|
||||
)
|
37
src/main/kotlin/util/MinecraftManifest.kt
Normal file
37
src/main/kotlin/util/MinecraftManifest.kt
Normal file
|
@ -0,0 +1,37 @@
|
|||
/*
|
||||
* paperweight is a Gradle plugin for the PaperMC project. It uses
|
||||
* some code and systems originally from ForgeGradle.
|
||||
*
|
||||
* Copyright (C) 2020 Kyle Wood
|
||||
* Copyright (C) 2018 Forge Development LLC
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
|
||||
* USA
|
||||
*/
|
||||
|
||||
package util
|
||||
|
||||
data class MinecraftManifest(
|
||||
internal val latest: Map<String, *>,
|
||||
internal val versions: List<ManifestVersion>
|
||||
)
|
||||
|
||||
data class ManifestVersion(
|
||||
internal val id: String,
|
||||
internal val type: String,
|
||||
internal val time: String,
|
||||
internal val releaseTime: String,
|
||||
internal val url: String
|
||||
)
|
106
src/main/kotlin/util/etag-util.kt
Normal file
106
src/main/kotlin/util/etag-util.kt
Normal file
|
@ -0,0 +1,106 @@
|
|||
/*
|
||||
* paperweight is a Gradle plugin for the PaperMC project. It uses
|
||||
* some code and systems originally from ForgeGradle.
|
||||
*
|
||||
* Copyright (C) 2020 Kyle Wood
|
||||
* Copyright (C) 2018 Forge Development LLC
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
|
||||
* USA
|
||||
*/
|
||||
|
||||
package io.papermc.paperweight.util
|
||||
|
||||
import io.papermc.paperweight.PaperweightException
|
||||
import java.io.File
|
||||
import java.net.HttpURLConnection
|
||||
import java.net.URL
|
||||
import java.util.concurrent.TimeUnit
|
||||
|
||||
private const val USER_AGENT = "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.11 (KHTML, like Gecko) Chrome/23.0.1271.95 Safari/537.11"
|
||||
|
||||
fun getWithEtag(urlText: String, cache: File, etagFile: File) {
|
||||
if (cache.exists() && cache.lastModified() + TimeUnit.MINUTES.toMillis(1) >= System.currentTimeMillis()) {
|
||||
return
|
||||
}
|
||||
|
||||
val etag = if (etagFile.exists()) {
|
||||
etagFile.readText()
|
||||
} else {
|
||||
etagFile.parentFile.mkdirs()
|
||||
""
|
||||
}
|
||||
|
||||
var thrown: Throwable? = null
|
||||
|
||||
try {
|
||||
val url = URL(urlText)
|
||||
|
||||
val con = url.openConnection() as HttpURLConnection
|
||||
con.instanceFollowRedirects = true
|
||||
con.setRequestProperty("User-Agent", USER_AGENT)
|
||||
con.ifModifiedSince = cache.lastModified()
|
||||
|
||||
if (etag.isNotEmpty()) {
|
||||
con.setRequestProperty("If-None-Match", etag)
|
||||
}
|
||||
|
||||
try {
|
||||
con.connect()
|
||||
|
||||
when (con.responseCode) {
|
||||
304 -> {
|
||||
cache.setLastModified(System.currentTimeMillis())
|
||||
return
|
||||
}
|
||||
200 -> {
|
||||
val data = con.inputStream.use { stream ->
|
||||
stream.readBytes()
|
||||
}
|
||||
|
||||
cache.writeBytes(data)
|
||||
|
||||
val newEtag = con.getHeaderField("ETag")
|
||||
if (newEtag.isNullOrEmpty()) {
|
||||
if (!etagFile.createNewFile()) {
|
||||
etagFile.setLastModified(System.currentTimeMillis())
|
||||
}
|
||||
} else {
|
||||
etagFile.writeText(newEtag)
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
else -> throw RuntimeException("Etag download for $urlText failed with code ${con.responseCode}")
|
||||
}
|
||||
} finally {
|
||||
con.disconnect()
|
||||
}
|
||||
} catch (e: Exception) {
|
||||
if (thrown == null) {
|
||||
thrown = e
|
||||
} else {
|
||||
thrown.addSuppressed(e)
|
||||
}
|
||||
}
|
||||
|
||||
val errorString = "Unable to download from $urlText with etag"
|
||||
val ex = if (thrown != null) {
|
||||
PaperweightException(errorString, thrown)
|
||||
} else {
|
||||
PaperweightException(errorString)
|
||||
}
|
||||
throw ex
|
||||
}
|
125
src/main/kotlin/util/git.kt
Normal file
125
src/main/kotlin/util/git.kt
Normal file
|
@ -0,0 +1,125 @@
|
|||
/*
|
||||
* paperweight is a Gradle plugin for the PaperMC project. It uses
|
||||
* some code and systems originally from ForgeGradle.
|
||||
*
|
||||
* Copyright (C) 2020 Kyle Wood
|
||||
* Copyright (C) 2018 Forge Development LLC
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
|
||||
* USA
|
||||
*/
|
||||
|
||||
package io.papermc.paperweight.util
|
||||
|
||||
import io.papermc.paperweight.PaperweightException
|
||||
import java.io.ByteArrayOutputStream
|
||||
import java.io.File
|
||||
import java.io.IOException
|
||||
import java.io.OutputStream
|
||||
|
||||
class Git(private var repo: File) {
|
||||
|
||||
init {
|
||||
if (!repo.exists()) {
|
||||
throw PaperweightException("Git directory does not exist: $repo")
|
||||
}
|
||||
}
|
||||
|
||||
val status
|
||||
get() = this("status", "-z").getText()
|
||||
|
||||
val ref
|
||||
get() = this("rev-parse", "HEAD").getText().replace('\n', ' ').replace(Regex("\\s+"), "")
|
||||
|
||||
operator fun invoke(vararg args: String, disableGpg: Boolean = true): Command {
|
||||
val cmd = if (disableGpg) {
|
||||
arrayOf("git", "-c", "commit.gpgsign=false", *args)
|
||||
} else {
|
||||
arrayOf("git", *args)
|
||||
}
|
||||
return try {
|
||||
Command(Runtime.getRuntime().exec(cmd, null, repo), cmd.joinToString(separator = " "))
|
||||
} catch (e: IOException) {
|
||||
throw PaperweightException("Failed to execute command: ${cmd.joinToString(separator = " ")}", e)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class Command(internal val process: Process, private val command: String) {
|
||||
|
||||
var outStream: OutputStream? = null
|
||||
|
||||
fun run(): Int = try {
|
||||
outStream?.let { out ->
|
||||
process.inputStream.copyTo(out)
|
||||
}
|
||||
process.waitFor()
|
||||
} catch (e: Exception) {
|
||||
throw PaperweightException("Failed to call git command: $command", e)
|
||||
}
|
||||
|
||||
fun runSilently(silenceOut: Boolean = true, silenceErr: Boolean = false): Int {
|
||||
silence(silenceOut, silenceErr)
|
||||
return run()
|
||||
}
|
||||
|
||||
fun runOut(): Int {
|
||||
setup(System.out, System.out)
|
||||
return run()
|
||||
}
|
||||
|
||||
fun execute() {
|
||||
val res = run()
|
||||
if (res != 0) {
|
||||
throw PaperweightException("Command finished with $res exit code: $command")
|
||||
}
|
||||
}
|
||||
|
||||
fun executeSilently(silenceOut: Boolean = true, silenceErr: Boolean = false) {
|
||||
silence(silenceOut, silenceErr)
|
||||
execute()
|
||||
}
|
||||
|
||||
private fun silence(silenceOut: Boolean, silenceErr: Boolean) {
|
||||
val out = if (silenceOut) UselessOutputStream else System.out
|
||||
val err = if (silenceErr) UselessOutputStream else System.err
|
||||
setup(out, err)
|
||||
}
|
||||
|
||||
fun executeOut() {
|
||||
setup(System.out, System.err)
|
||||
execute()
|
||||
}
|
||||
|
||||
fun setup(out: OutputStream? = null, err: OutputStream? = null): Command {
|
||||
outStream = out
|
||||
if (err != null) {
|
||||
redirect(process.errorStream, err)
|
||||
}
|
||||
return this
|
||||
}
|
||||
|
||||
fun getText(): String {
|
||||
val out = ByteArrayOutputStream()
|
||||
setup(out, System.err)
|
||||
return String(out.toByteArray(), Charsets.UTF_8)
|
||||
}
|
||||
|
||||
fun readText(): String? {
|
||||
val out = ByteArrayOutputStream()
|
||||
setup(out, System.err)
|
||||
return if (run() == 0) String(out.toByteArray(), Charsets.UTF_8) else null
|
||||
}
|
||||
}
|
70
src/main/kotlin/util/jvm.kt
Normal file
70
src/main/kotlin/util/jvm.kt
Normal file
|
@ -0,0 +1,70 @@
|
|||
/*
|
||||
* paperweight is a Gradle plugin for the PaperMC project. It uses
|
||||
* some code and systems originally from ForgeGradle.
|
||||
*
|
||||
* Copyright (C) 2020 Kyle Wood
|
||||
* Copyright (C) 2018 Forge Development LLC
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
|
||||
* USA
|
||||
*/
|
||||
|
||||
package io.papermc.paperweight.util
|
||||
|
||||
import io.papermc.paperweight.PaperweightException
|
||||
import org.gradle.api.Task
|
||||
import org.gradle.internal.jvm.Jvm
|
||||
import java.io.OutputStream
|
||||
|
||||
fun Task.runJar(
|
||||
jar: Any,
|
||||
workingDir: Any,
|
||||
logFile: Any?,
|
||||
jvmArgs: List<String> = listOf(),
|
||||
vararg args: String
|
||||
) {
|
||||
val jarFile = project.file(jar)
|
||||
val dir = project.file(workingDir)
|
||||
|
||||
val process = ProcessBuilder(
|
||||
Jvm.current().javaExecutable.canonicalPath, *jvmArgs.toTypedArray(),
|
||||
"-jar", jarFile.canonicalPath,
|
||||
*args
|
||||
).directory(dir).start()
|
||||
|
||||
val output = when {
|
||||
logFile is OutputStream -> logFile
|
||||
logFile != null -> {
|
||||
val log = project.file(logFile)
|
||||
log.outputStream().buffered()
|
||||
}
|
||||
else -> null
|
||||
}
|
||||
|
||||
output.use {
|
||||
output?.let {
|
||||
redirect(process.inputStream, it)
|
||||
redirect(process.errorStream, it)
|
||||
} ?: run {
|
||||
redirect(process.inputStream, UselessOutputStream)
|
||||
redirect(process.errorStream, UselessOutputStream)
|
||||
}
|
||||
|
||||
val e = process.waitFor()
|
||||
if (e != 0) {
|
||||
throw PaperweightException("Execution of $jarFile failed with exit code $e")
|
||||
}
|
||||
}
|
||||
}
|
140
src/main/kotlin/util/utils.kt
Normal file
140
src/main/kotlin/util/utils.kt
Normal file
|
@ -0,0 +1,140 @@
|
|||
/*
|
||||
* paperweight is a Gradle plugin for the PaperMC project. It uses
|
||||
* some code and systems originally from ForgeGradle.
|
||||
*
|
||||
* Copyright (C) 2020 Kyle Wood
|
||||
* Copyright (C) 2018 Forge Development LLC
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
|
||||
* USA
|
||||
*/
|
||||
|
||||
package io.papermc.paperweight.util
|
||||
|
||||
import au.com.bytecode.opencsv.CSVParser
|
||||
import au.com.bytecode.opencsv.CSVReader
|
||||
import com.github.salomonbrys.kotson.fromJson
|
||||
import com.google.gson.Gson
|
||||
import io.papermc.paperweight.PaperweightException
|
||||
import io.papermc.paperweight.ext.PaperweightExtension
|
||||
import org.cadixdev.lorenz.MappingSet
|
||||
import org.cadixdev.lorenz.io.TextMappingFormat
|
||||
import org.gradle.api.NamedDomainObjectProvider
|
||||
import org.gradle.api.Project
|
||||
import org.gradle.api.Task
|
||||
import org.gradle.api.artifacts.Configuration
|
||||
import org.gradle.api.file.DirectoryProperty
|
||||
import org.gradle.api.file.RegularFile
|
||||
import org.gradle.api.file.RegularFileProperty
|
||||
import org.gradle.api.provider.Provider
|
||||
import java.io.File
|
||||
import java.io.InputStream
|
||||
import java.io.OutputStream
|
||||
|
||||
val gson: Gson = Gson()
|
||||
|
||||
inline val Project.ext: PaperweightExtension
|
||||
get() = extensions.getByName(Constants.EXTENSION) as PaperweightExtension
|
||||
inline val Project.cache: File
|
||||
get() = file(".gradle").resolve(Constants.CACHE_PATH)
|
||||
|
||||
fun writeMappings(format: TextMappingFormat, vararg mappings: Pair<MappingSet, File>) {
|
||||
for ((set, file) in mappings) {
|
||||
file.bufferedWriter().use { stream ->
|
||||
format.createWriter(stream).write(set)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun redirect(input: InputStream, out: OutputStream) {
|
||||
Thread {
|
||||
try {
|
||||
input.copyTo(out)
|
||||
} catch (e: Exception) {
|
||||
throw PaperweightException("", e)
|
||||
}
|
||||
}.apply {
|
||||
isDaemon = true
|
||||
start()
|
||||
}
|
||||
}
|
||||
|
||||
object UselessOutputStream : OutputStream() {
|
||||
override fun write(b: Int) {
|
||||
}
|
||||
}
|
||||
|
||||
inline fun wrapException(msg: String, func: () -> Unit) {
|
||||
try {
|
||||
func()
|
||||
} catch (e: Exception) {
|
||||
throw PaperweightException(msg, e)
|
||||
}
|
||||
}
|
||||
|
||||
fun getCsvReader(file: File) = CSVReader(
|
||||
file.reader(),
|
||||
CSVParser.DEFAULT_SEPARATOR,
|
||||
CSVParser.DEFAULT_QUOTE_CHARACTER,
|
||||
CSVParser.NULL_CHARACTER,
|
||||
1,
|
||||
false
|
||||
)
|
||||
|
||||
fun Task.ensureParentExists(vararg files: Any) {
|
||||
for (file in files) {
|
||||
val parent = project.file(file).parentFile
|
||||
if (!parent.exists() && !parent.mkdirs()) {
|
||||
throw PaperweightException("Failed to create directory $parent")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun Task.ensureDeleted(vararg files: Any) {
|
||||
for (file in files) {
|
||||
val f = project.file(file)
|
||||
if (f.exists() && !f.deleteRecursively()) {
|
||||
throw PaperweightException("Failed to delete file $f")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun Project.toProvider(file: File): Provider<RegularFile> {
|
||||
return layout.file(provider { file })
|
||||
}
|
||||
|
||||
val RegularFileProperty.file
|
||||
get() = get().asFile
|
||||
val RegularFileProperty.fileOrNull
|
||||
get() = orNull?.asFile
|
||||
val DirectoryProperty.file
|
||||
get() = get().asFile
|
||||
val DirectoryProperty.fileOrNull
|
||||
get() = orNull?.asFile
|
||||
|
||||
|
||||
private var parsedConfig: McpConfig? = null
|
||||
fun mcpConfig(file: Provider<RegularFile>): McpConfig {
|
||||
if (parsedConfig != null) {
|
||||
return parsedConfig as McpConfig
|
||||
}
|
||||
parsedConfig = file.get().asFile.bufferedReader().use { reader ->
|
||||
gson.fromJson(reader)
|
||||
}
|
||||
return parsedConfig as McpConfig
|
||||
}
|
||||
fun mcpFile(configFile: RegularFileProperty, path: String): File {
|
||||
return configFile.file.resolveSibling(path)
|
||||
}
|
75
src/main/kotlin/util/zip.kt
Normal file
75
src/main/kotlin/util/zip.kt
Normal file
|
@ -0,0 +1,75 @@
|
|||
/*
|
||||
* paperweight is a Gradle plugin for the PaperMC project. It uses
|
||||
* some code and systems originally from ForgeGradle.
|
||||
*
|
||||
* Copyright (C) 2020 Kyle Wood
|
||||
* Copyright (C) 2018 Forge Development LLC
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
|
||||
* USA
|
||||
*/
|
||||
|
||||
package io.papermc.paperweight.util
|
||||
|
||||
import io.papermc.paperweight.PaperweightException
|
||||
import org.gradle.api.Task
|
||||
import java.io.File
|
||||
import java.net.URI
|
||||
import java.nio.file.FileSystems
|
||||
import java.nio.file.FileVisitResult
|
||||
import java.nio.file.Files
|
||||
import java.nio.file.Path
|
||||
import java.nio.file.SimpleFileVisitor
|
||||
import java.nio.file.attribute.BasicFileAttributes
|
||||
import java.util.concurrent.ThreadLocalRandom
|
||||
|
||||
fun Task.unzip(zip: Any, target: Any? = null): File {
|
||||
val input = project.file(zip)
|
||||
val outputDir = target?.let { project.file(it) }
|
||||
?: input.resolveSibling("${input.name}-" + ThreadLocalRandom.current().nextInt())
|
||||
|
||||
project.copy {
|
||||
from(project.zipTree(zip))
|
||||
into(outputDir)
|
||||
}
|
||||
|
||||
return outputDir
|
||||
}
|
||||
|
||||
fun Task.zip(inputDir: Any, zip: Any) {
|
||||
val outputZipFile = project.file(zip)
|
||||
if (outputZipFile.exists() && !outputZipFile.delete()) {
|
||||
throw PaperweightException("Could not delete $outputZipFile")
|
||||
}
|
||||
|
||||
val dirPath = project.file(inputDir).toPath()
|
||||
|
||||
val outUri = URI.create("jar:${outputZipFile.toURI()}")
|
||||
FileSystems.newFileSystem(outUri, mapOf("create" to "true")).use { fs ->
|
||||
Files.walkFileTree(dirPath, object : SimpleFileVisitor<Path>() {
|
||||
override fun preVisitDirectory(dir: Path, attrs: BasicFileAttributes): FileVisitResult {
|
||||
if (dir != dirPath) {
|
||||
Files.createDirectories(fs.getPath(dirPath.relativize(dir).toString()))
|
||||
}
|
||||
return FileVisitResult.CONTINUE
|
||||
}
|
||||
|
||||
override fun visitFile(file: Path, attrs: BasicFileAttributes): FileVisitResult {
|
||||
Files.copy(file, fs.getPath(dirPath.relativize(file).toString()))
|
||||
return FileVisitResult.CONTINUE
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
|
@ -0,0 +1 @@
|
|||
implementation-class=io.papermc.paperweight.Paperweight
|
Loading…
Reference in a new issue