Skip to content

Commit

Permalink
Fix jar and class loading
Browse files Browse the repository at this point in the history
  • Loading branch information
freyacodes committed Dec 17, 2021
1 parent 76684e2 commit 5849729
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 7 deletions.
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
*.iml
/logs/
/target/
/application.yml
/LavalinkServer/application.yml
*/dependency-reduced-pom.xml
.gradle/*
build/*
Expand All @@ -16,3 +16,5 @@ build/*
/plugin-api/build/
/plugin-api/out/
gradle.properties
application.yml
plugins
3 changes: 3 additions & 0 deletions LavalinkServer/src/main/java/lavalink/server/Launcher.kt
Original file line number Diff line number Diff line change
Expand Up @@ -137,8 +137,11 @@ object Launcher {
private fun launchMain(parent: ConfigurableApplicationContext, args: Array<String>) {
val properties = Properties()
properties["componentScan"] = PluginManager.pluginManifests.map { it.path }
.toMutableList()
.apply { add("lavalink.server") }
SpringApplicationBuilder()
.sources(LavalinkApplication::class.java)
.resourceLoader()
.properties(properties)
.web(WebApplicationType.SERVLET)
.bannerMode(Banner.Mode.OFF)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@ class PluginManager(config: PluginsConfig) {
}
}

val url = declaration.run { "$repository${group.replace(".", "/")}/$name/$version.jar" }
val file = File(directory, declaration.run { "$group-$version.jar" })
val url = declaration.run { "$repository${group.replace(".", "/")}/$name/$version/$name-$version.jar" }
val file = File(directory, declaration.run { "$name-$version.jar" })
downloadJar(file, url)
}
}
Expand Down Expand Up @@ -104,7 +104,6 @@ class PluginManager(config: PluginsConfig) {

jar.entries().asIterator().forEach { entry ->
if (entry.isDirectory) return@forEach
if (!entry.name.endsWith(".class")) return@forEach
if (!entry.name.startsWith("lavalink-plugins/")) return@forEach
if (!entry.name.endsWith(".properties")) return@forEach
manifests.add(parsePluginManifest(jar.getInputStream(entry)))
Expand All @@ -113,7 +112,7 @@ class PluginManager(config: PluginsConfig) {
if (manifests.isEmpty()) {
throw RuntimeException("No plugin manifest found in ${file.path}")
}
val allowedPaths = manifests.map { it.path }
val allowedPaths = manifests.map { it.path.replace(".", "/") }

jar.entries().asIterator().forEach { entry ->
if (entry.isDirectory) return@forEach
Expand All @@ -134,7 +133,7 @@ class PluginManager(config: PluginsConfig) {
val name = props.getProperty("name") ?: throw RuntimeException("Manifest is missing 'name'")
val path = props.getProperty("path") ?: throw RuntimeException("Manifest is missing 'path'")
val version = props.getProperty("version") ?: throw RuntimeException("Manifest is missing 'version'")
log.info("Found $name version $version")
log.info("Found plugin '$name' version $version")
return PluginManifest(name, path, version)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package lavalink.server.bootstrap
import org.springframework.boot.context.properties.ConfigurationProperties
import org.springframework.stereotype.Component

@ConfigurationProperties(prefix = "lavalink.plugins")
@ConfigurationProperties(prefix = "lavalink")
@Component
class PluginsConfig {
var plugins: List<PluginDeclaration> = emptyList()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ class SocketServer(
val contexts: Collection<SocketContext>
get() = contextMap.values

@Suppress("UastIncorrectHttpHeaderInspection")
override fun afterConnectionEstablished(session: WebSocketSession) {
val userId = session.handshakeHeaders.getFirst("User-Id")!!
val resumeKey = session.handshakeHeaders.getFirst("Resume-Key")
Expand Down

0 comments on commit 5849729

Please sign in to comment.