Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cache applied/extracted classpath from Paperclips instead of Paperclips themselves #93

Draft
wants to merge 7 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions plugin/src/main/kotlin/xyz/jpenilla/runpaper/task/RunServer.kt
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import xyz.jpenilla.runtask.pluginsapi.PluginDownloadService
import xyz.jpenilla.runtask.service.DownloadsAPIService
import xyz.jpenilla.runtask.task.RunWithPlugins
import xyz.jpenilla.runtask.util.FileCopyingPluginHandler
import xyz.jpenilla.runtask.util.spec
import java.io.File
import java.nio.file.Path

Expand Down Expand Up @@ -63,6 +64,15 @@ public abstract class RunServer : RunWithPlugins() {
displayName.convention("Paper")
}

override fun resolveBuild(): List<Path> {
val result = super.resolveBuild()
if (result.size != 1) {
// Default main class to CB main when the applied Paperclip classpath is resolved to multiple files
spec().mainClass.set(mainClass.orElse("org.bukkit.craftbukkit.Main"))
}
return result
}

override fun preExec(workingDir: Path) {
super.preExec(workingDir)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import org.gradle.api.provider.Property
import org.gradle.api.provider.Provider
import org.gradle.api.services.BuildService
import org.gradle.api.services.BuildServiceParameters
import org.gradle.internal.logging.progress.ProgressLoggerFactory
import org.gradle.kotlin.dsl.registerIfAbsent
import xyz.jpenilla.runtask.paperapi.Projects
import xyz.jpenilla.runtask.util.Constants
Expand Down Expand Up @@ -53,7 +54,7 @@ public interface PluginDownloadService : BuildService<PluginDownloadService.Para
* @param project project to use for context
* @param download plugin download
*/
public fun resolvePlugin(project: Project, download: PluginApiDownload): Path
public fun resolvePlugin(progressLoggerFactory: ProgressLoggerFactory, download: PluginApiDownload): Path

public companion object {
public fun registerIfAbsent(namePrefix: String, project: Project, config: Action<in Parameters>): Provider<out PluginDownloadService> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ import com.fasterxml.jackson.databind.SerializationFeature
import com.fasterxml.jackson.databind.json.JsonMapper
import com.fasterxml.jackson.module.kotlin.kotlinModule
import com.fasterxml.jackson.module.kotlin.readValue
import org.gradle.api.Project
import org.gradle.api.logging.Logging
import org.gradle.internal.logging.progress.ProgressLoggerFactory
import xyz.jpenilla.runtask.util.Constants
import xyz.jpenilla.runtask.util.Downloader
import xyz.jpenilla.runtask.util.HashingAlgorithm
Expand Down Expand Up @@ -85,14 +85,14 @@ internal abstract class PluginDownloadServiceImpl : PluginDownloadService {
}

@Synchronized
override fun resolvePlugin(project: Project, download: PluginApiDownload): Path {
override fun resolvePlugin(progressLoggerFactory: ProgressLoggerFactory, download: PluginApiDownload): Path {
manifest = loadOrCreateManifest()

return when (download) {
is HangarApiDownload -> resolveHangarPlugin(project, download)
is ModrinthApiDownload -> resolveModrinthPlugin(project, download)
is GitHubApiDownload -> resolveGitHubPlugin(project, download)
is UrlDownload -> resolveUrl(project, download)
is HangarApiDownload -> resolveHangarPlugin(progressLoggerFactory, download)
is ModrinthApiDownload -> resolveModrinthPlugin(progressLoggerFactory, download)
is GitHubApiDownload -> resolveGitHubPlugin(progressLoggerFactory, download)
is UrlDownload -> resolveUrl(progressLoggerFactory, download)
}
}

Expand All @@ -101,18 +101,18 @@ internal abstract class PluginDownloadServiceImpl : PluginDownloadService {
private val offlineMode: Boolean
get() = parameters.offlineMode.get()

private fun resolveUrl(project: Project, download: UrlDownload): Path {
private fun resolveUrl(progressLoggerFactory: ProgressLoggerFactory, download: UrlDownload): Path {
val cacheDir = parameters.cacheDirectory.get().asFile.toPath()
val targetDir = cacheDir.resolve(Constants.URL_PLUGIN_DIR)
val urlHash = download.urlHash()
val version = manifest.urlProvider[urlHash] ?: PluginVersion(fileName = "$urlHash.jar", displayName = download.url.get())
val targetFile = targetDir.resolve(version.fileName)
val setter: (PluginVersion) -> Unit = { manifest.urlProvider[urlHash] = it }
val ctx = DownloadCtx(project, "url", download.url.get(), targetDir, targetFile, version, setter)
val ctx = DownloadCtx(progressLoggerFactory, "url", download.url.get(), targetDir, targetFile, version, setter)
return download(ctx)
}

private fun resolveHangarPlugin(project: Project, download: HangarApiDownload): Path {
private fun resolveHangarPlugin(progressLoggerFactory: ProgressLoggerFactory, download: HangarApiDownload): Path {
val platformType = parameters.platformType.get()
val cacheDir = parameters.cacheDirectory.get().asFile.toPath()

Expand All @@ -134,11 +134,11 @@ internal abstract class PluginDownloadServiceImpl : PluginDownloadService {
val downloadUrl = "$apiUrl/api/v1/projects/$apiPlugin/versions/$apiVersion/$platformType/download"

val setter: (PluginVersion) -> Unit = { platform[apiVersion] = it }
val ctx = DownloadCtx(project, apiUrl, downloadUrl, targetDir, targetFile, version, setter)
val ctx = DownloadCtx(progressLoggerFactory, apiUrl, downloadUrl, targetDir, targetFile, version, setter)
return download(ctx)
}

private fun resolveModrinthPlugin(project: Project, download: ModrinthApiDownload): Path {
private fun resolveModrinthPlugin(progressLoggerFactory: ProgressLoggerFactory, download: ModrinthApiDownload): Path {
val cacheDir = parameters.cacheDirectory.get().asFile.toPath()

val apiVersion = download.version.get()
Expand All @@ -156,7 +156,7 @@ internal abstract class PluginDownloadServiceImpl : PluginDownloadService {

val versionRequestUrl = "$apiUrl/v2/project/$apiPlugin/version/$apiVersion"
val versionJsonPath = download(
DownloadCtx(project, apiUrl, versionRequestUrl, targetDir, jsonFile, jsonVersion, setter = { plugin[jsonVersionName] = it }, requireValidJar = false)
DownloadCtx(progressLoggerFactory, apiUrl, versionRequestUrl, targetDir, jsonFile, jsonVersion, setter = { plugin[jsonVersionName] = it }, requireValidJar = false)
)
val versionInfo = mapper.readValue<ModrinthVersionResponse>(versionJsonPath.toFile())
val primaryFile = versionInfo.files.find { it.primary } ?: error("Could not find primary file for $download in $versionInfo")
Expand All @@ -169,11 +169,11 @@ internal abstract class PluginDownloadServiceImpl : PluginDownloadService {
val targetFile = targetDir.resolve(version.fileName)

return download(
DownloadCtx(project, apiUrl, primaryFile.url, targetDir, targetFile, version, setter = { plugin[apiVersion] = it })
DownloadCtx(progressLoggerFactory, apiUrl, primaryFile.url, targetDir, targetFile, version, setter = { plugin[apiVersion] = it })
)
}

private fun resolveGitHubPlugin(project: Project, download: GitHubApiDownload): Path {
private fun resolveGitHubPlugin(progressLoggerFactory: ProgressLoggerFactory, download: GitHubApiDownload): Path {
val cacheDir = parameters.cacheDirectory.get().asFile.toPath()

val owner = download.owner.get()
Expand All @@ -192,7 +192,7 @@ internal abstract class PluginDownloadServiceImpl : PluginDownloadService {
val downloadUrl = "https://github.com/$owner/$repo/releases/download/$tag/$asset"

val setter: (PluginVersion) -> Unit = { tagProvider[asset] = it }
val ctx = DownloadCtx(project, "github.com", downloadUrl, targetDir, targetFile, version, setter)
val ctx = DownloadCtx(progressLoggerFactory, "github.com", downloadUrl, targetDir, targetFile, version, setter)
return download(ctx)
}

Expand Down Expand Up @@ -262,7 +262,7 @@ internal abstract class PluginDownloadServiceImpl : PluginDownloadService {
val opName = "${ctx.baseUrl}:${ctx.version.fileName}"
val start = Instant.now()
LOGGER.lifecycle("Downloading {}...", displayName)
when (val res = Downloader(url, ctx.targetFile, displayName, opName).download(ctx.project, connection)) {
when (val res = Downloader(url, ctx.targetFile, displayName, opName).download(ctx.progressLoggerFactory, connection)) {
is Downloader.Result.Success -> LOGGER.lifecycle("Done downloading {}, took {}.", displayName, Duration.between(start, Instant.now()).prettyPrint())
is Downloader.Result.Failure -> throw IllegalStateException("Failed to download $displayName.", res.throwable)
}
Expand Down Expand Up @@ -311,7 +311,7 @@ internal abstract class PluginDownloadServiceImpl : PluginDownloadService {
}

private data class DownloadCtx(
val project: Project,
val progressLoggerFactory: ProgressLoggerFactory,
val baseUrl: String,
val downloadUrl: String,
val targetDir: Path,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,11 @@ package xyz.jpenilla.runtask.service
import org.gradle.api.Action
import org.gradle.api.Project
import org.gradle.api.provider.Provider
import org.gradle.api.provider.ProviderFactory
import org.gradle.internal.logging.progress.ProgressLoggerFactory
import org.gradle.jvm.toolchain.JavaLauncher
import org.gradle.kotlin.dsl.registerIfAbsent
import org.gradle.process.ExecOperations
import xyz.jpenilla.runtask.paperapi.DownloadsAPI
import xyz.jpenilla.runtask.paperapi.Projects
import xyz.jpenilla.runtask.util.Constants
Expand All @@ -43,10 +47,13 @@ public interface DownloadsAPIService {
* @param build build to resolve
*/
public fun resolveBuild(
project: Project,
providers: ProviderFactory,
javaLauncher: JavaLauncher,
execOperations: ExecOperations,
progressLoggerFactory: ProgressLoggerFactory,
version: String,
build: Build
): Path
): List<Path>

public companion object {
/**
Expand Down
Loading
Loading