-
Notifications
You must be signed in to change notification settings - Fork 270
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rework external library handling. (#846)
* Generate installer jsons * Bump to version2 * Include file size * Add min java version * Exclude signature info from shaded jars * Add a little script to aid installing a test version to the minecraft launcher.
- Loading branch information
Showing
5 changed files
with
433 additions
and
134 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
import groovy.json.JsonOutput | ||
|
||
tasks.register("generateInstallerJson", GenerateInstallerJsonTask) { | ||
configurations = [ common: "installer" ] | ||
outputFile = file("src/main/resources/fabric-installer.json") | ||
options = [ | ||
mainClasses: [ | ||
client: "net.fabricmc.loader.impl.launch.knot.KnotClient", | ||
server: "net.fabricmc.loader.impl.launch.knot.KnotServer" | ||
] | ||
] | ||
} | ||
|
||
tasks.register("generateLaunchWrapperInstallerJson", GenerateInstallerJsonTask) { | ||
configurations = [ common: "installerLaunchWrapper" ] | ||
outputFile = file("src/main/resources/fabric-installer.launchwrapper.json") | ||
options = [ | ||
mainClass: "net.minecraft.launchwrapper.Launch", | ||
arguments: [ | ||
client: [], | ||
common: [], | ||
server: [], | ||
], | ||
launchwrapper: [ | ||
tweakers: [ | ||
client: [ | ||
"net.fabricmc.loader.impl.game.minecraft.launchwrapper.FabricClientTweaker" | ||
], | ||
common: [], | ||
server: [ | ||
"net.fabricmc.loader.impl.game.minecraft.launchwrapper.FabricServerTweaker" | ||
] | ||
] | ||
] | ||
] | ||
} | ||
|
||
abstract class GenerateInstallerJsonTask extends DefaultTask { | ||
@Input | ||
abstract MapProperty<String, String> getConfigurations() | ||
|
||
@Input | ||
abstract MapProperty<String, Object> getOptions() | ||
|
||
@OutputFile | ||
abstract RegularFileProperty getOutputFile() | ||
|
||
GenerateInstallerJsonTask() { | ||
outputs.upToDateWhen { false } | ||
} | ||
|
||
@TaskAction | ||
def run() { | ||
|
||
def json = [ | ||
version: 2, | ||
min_java_version: 8, | ||
libraries: [ | ||
client: [], | ||
common: [], | ||
server: [], | ||
development: [], | ||
] | ||
] | ||
|
||
configurations.get().each { side, name -> | ||
def resolvedArtifacts = project.configurations.getByName(name).resolvedConfiguration.resolvedArtifacts | ||
for (final def artifact in resolvedArtifacts) { | ||
def library = [name: artifact.moduleVersion.toString(), url: "https://maven.fabricmc.net/"] | ||
library.putAll(resolveHashes(artifact.moduleVersion.toString())) | ||
|
||
json.libraries[side].add(library) | ||
} | ||
} | ||
|
||
json.putAll(options.get()) | ||
getOutputFile().get().asFile.text = JsonOutput.prettyPrint(JsonOutput.toJson(json)) | ||
} | ||
|
||
Map<String, Object> resolveHashes(String artifact) { | ||
if (artifact.startsWith("net.minecraft:launchwrapper")) { | ||
// Launch wrapper only has sha1 hashes on its maven. | ||
return [ | ||
md5: resolveHash(artifact, "sha1"), | ||
size: resolveSize(artifact), | ||
] | ||
} | ||
|
||
return [ | ||
md5: resolveHash(artifact, "md5"), | ||
sha1: resolveHash(artifact, "sha1"), | ||
sha256: resolveHash(artifact, "sha256"), | ||
sha512: resolveHash(artifact, "sha512"), | ||
size: resolveSize(artifact), | ||
] | ||
} | ||
|
||
String resolveHash(String artifact, String hash) { | ||
def config = project.configurations.detachedConfiguration(project.dependencies.create("${artifact}@jar.${hash}")) | ||
return config.singleFile.text | ||
} | ||
|
||
long resolveSize(String artifact) { | ||
def config = project.configurations.detachedConfiguration(project.dependencies.create("${artifact}@jar")) | ||
return config.singleFile.size() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
import groovy.json.JsonOutput | ||
import groovy.json.JsonSlurper | ||
|
||
// A task to install the development version of Fabric Loader to the Minecraft launcher | ||
tasks.register("installDevelopmentVersion", InstallDevelopmentVersionTask) { | ||
installerJson = file("src/main/resources/fabric-installer.json") | ||
loaderJar = proguardJar.outputs.files.singleFile | ||
dependsOn proguardJar | ||
} | ||
|
||
abstract class InstallDevelopmentVersionTask extends DefaultTask { | ||
@Input | ||
@Option(option = "mc-version", description = "The Minecraft version to install") | ||
abstract Property<String> getMinecraftVersion() | ||
|
||
@Input | ||
@Option(option = "version-name", description = "The profile name to use") | ||
abstract Property<String> getVersionName() | ||
|
||
@InputFile | ||
abstract RegularFileProperty getInstallerJson() | ||
|
||
@InputFile | ||
abstract RegularFileProperty getLoaderJar() | ||
|
||
@OutputFile | ||
abstract RegularFileProperty getVersionJsonFile() | ||
|
||
@OutputFile | ||
abstract RegularFileProperty getLoaderLibraryFile() | ||
|
||
InstallDevelopmentVersionTask() { | ||
versionName.convention("fabric-loader-${project.version.toString()}") | ||
minecraftVersion.convention("1.20.2") | ||
versionJsonFile.set(project.layout.file(project.provider { | ||
new File(getDotMinecraftDirectory(), "versions/${versionName.get()}/${versionName.get()}.json") | ||
})) | ||
loaderLibraryFile.set(project.layout.file(project.provider { | ||
new File(getDotMinecraftDirectory(), "libraries/net/fabricmc/fabric-loader/${project.version.toString()}/fabric-loader-${project.version.toString()}.jar") | ||
})) | ||
} | ||
|
||
@TaskAction | ||
void runTask() { | ||
loaderLibraryFile.get().getAsFile().parentFile.mkdirs() | ||
loaderLibraryFile.get().getAsFile().bytes = loaderJar.get().getAsFile().bytes | ||
|
||
def installerJson = new JsonSlurper().parse(installerJson.get().getAsFile()) | ||
|
||
// Creates the versions json for the Minecraft launcher | ||
def versionMeta = [ | ||
id: versionName.get(), | ||
time: new Date().format("yyyy-MM-dd'T'HH:mm:ssZ"), | ||
releaseTime: new Date().format("yyyy-MM-dd'T'HH:mm:ssZ"), | ||
type: "release", | ||
inheritsFrom: minecraftVersion.get(), | ||
mainClass: installerJson.mainClasses.client, | ||
libraries: installerJson.libraries.common, | ||
] | ||
|
||
versionMeta.libraries.add([ | ||
name: "net.fabricmc:fabric-loader:${project.version.toString()}", | ||
url: "https://maven.fabricmc.net/", | ||
]) | ||
|
||
versionMeta.libraries.add([ | ||
name: "net.fabricmc:intermediary:${minecraftVersion.get()}", | ||
url: "https://maven.fabricmc.net/", | ||
]) | ||
|
||
versionJsonFile.get().getAsFile().parentFile.mkdirs() | ||
versionJsonFile.get().asFile.text = JsonOutput.prettyPrint(JsonOutput.toJson(versionMeta)) | ||
|
||
project.logger.lifecycle("Installed Fabric Loader ${project.version.toString()} for Minecraft ${minecraftVersion.get()} as ${versionName.get()}") | ||
} | ||
|
||
static File getDotMinecraftDirectory() { | ||
def os = System.getProperty("os.name").toLowerCase(Locale.ROOT) | ||
if (os.contains("win")) { | ||
return new File(System.getenv("APPDATA"), ".minecraft") | ||
} else if (os.contains("mac")) { | ||
return new File(System.getProperty("user.home"), "Library/Application Support/minecraft") | ||
} else { | ||
return new File(System.getProperty("user.home"), ".minecraft") | ||
} | ||
} | ||
} | ||
|
Oops, something went wrong.