Skip to content

Commit

Permalink
GH-1474 Move to Javalin 5.x (Resolve #1474)
Browse files Browse the repository at this point in the history
  • Loading branch information
dzikoysk committed Jul 23, 2022
1 parent d075eba commit cca3316
Show file tree
Hide file tree
Showing 22 changed files with 75 additions and 75 deletions.
29 changes: 21 additions & 8 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ plugins {
application
`maven-publish`

val kotlinVersion = "1.7.0"
val kotlinVersion = "1.7.10"
kotlin("jvm") version kotlinVersion
kotlin("kapt") version kotlinVersion

Expand Down Expand Up @@ -65,13 +65,26 @@ allprojects {
version = rootProject.scmVersion.version

repositories {
mavenCentral()
// maven {
// url = uri("http://localhost/releases")
// isAllowInsecureProtocol = true
// }
maven { url = uri("https://maven.reposilite.com/releases") }
maven { url = uri("https://jitpack.io") }
mavenCentral() {
mavenContent {
releasesOnly()
}
}
maven("https://maven.reposilite.com/releases") {
mavenContent {
releasesOnly()
}
}
maven("https://maven.reposilite.com/snapshots") {
mavenContent {
snapshotsOnly()
}
}
maven("https://jitpack.io") {
mavenContent {
releasesOnly()
}
}
}
}

Expand Down
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,6 @@

distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-7.3.3-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-7.5-all.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
33 changes: 9 additions & 24 deletions reposilite-backend/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ dependencies {
implementation(project(":reposilite-frontend"))
detektPlugins("io.gitlab.arturbosch.detekt:detekt-formatting:1.20.0")

val kotlin = "1.7.0"
val kotlin = "1.7.10"
implementation("org.jetbrains.kotlin:kotlin-reflect:$kotlin")
implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin")
api("org.jetbrains:annotations:23.0.0")
Expand All @@ -61,9 +61,7 @@ dependencies {
implementation("org.jetbrains.exposed:exposed-jdbc:$exposed")
implementation("org.jetbrains.exposed:exposed-java-time:$exposed")
api("net.dzikoysk:exposed-upsert:1.0.3")
// Threadpool
@Suppress("GradlePackageUpdate")
implementation("com.zaxxer:HikariCP:4.0.3")
implementation("com.zaxxer:HikariCP:5.0.1")
// Drivers
implementation("org.xerial:sqlite-jdbc:3.36.0.3")
implementation("mysql:mysql-connector-java:8.0.29")
Expand All @@ -77,26 +75,12 @@ dependencies {
val ldap = "6.0.5"
testImplementation("com.unboundid:unboundid-ldapsdk:$ldap")

val openapi = "1.1.7"
kapt("io.javalin-rfc:openapi-annotation-processor:$openapi") {
exclude(group = "ch.qos.logback")
}
implementation("io.javalin-rfc:javalin-openapi-plugin:$openapi")

val javalinRfcs = "4.1.0"
api("com.reposilite.javalin-rfcs:javalin-context:$javalinRfcs")
api("com.reposilite.javalin-rfcs:javalin-routing:$javalinRfcs")

@Suppress("GradlePackageUpdate")
//api("io.javalin:javalin:4.1.1")
// api("com.github.dzikoysk.javalin:javalin:97b4481c0a")
// api("com.github.tipsy.javalin:javalin:d00c8512c9")
api("io.javalin:javalin:4.6.3")

@Suppress("GradlePackageUpdate")
implementation("org.eclipse.jetty:jetty-server:9.4.46.v20220331")

implementation("com.github.victools:jsonschema-generator:4.25.0")
val javalin = "5.0.0-SNAPSHOT"
api("io.javalin:javalin:$javalin")
api("io.javalin:javalin-openapi-plugin:$javalin")
kapt("io.javalin:openapi-annotation-processor:$javalin") { exclude(group = "ch.qos.logback") }
api("com.reposilite.javalin-rfcs:javalin-context:$javalin")
api("com.reposilite.javalin-rfcs:javalin-routing:$javalin")

val picocli = "4.6.3"
kapt("info.picocli:picocli-codegen:$picocli")
Expand All @@ -106,6 +90,7 @@ dependencies {
implementation("com.fasterxml.jackson.module:jackson-module-kotlin:$jackson")
implementation("com.fasterxml.jackson.datatype:jackson-datatype-jsr310:$jackson")
implementation("com.fasterxml.jackson.dataformat:jackson-dataformat-xml:$jackson")
implementation("com.github.victools:jsonschema-generator:4.25.0")

val httpClient = "1.42.1"
implementation("com.google.http-client:google-http-client:$httpClient")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import com.reposilite.maven.application.MavenSettings
import com.reposilite.maven.application.ProxiedRepository
import com.reposilite.maven.application.RepositorySettings
import com.reposilite.storage.StorageProviderSettings
import io.javalin.core.util.JavalinBindException
import io.javalin.util.JavalinBindException
import net.dzikoysk.cdn.KCdnFactory
import net.dzikoysk.cdn.source.Source
import org.junit.jupiter.api.AfterEach
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ import com.reposilite.journalist.backend.PublisherLogger
import com.reposilite.journalist.slf4j.Slf4jLogger
import com.reposilite.journalist.tinylog.TinyLogLogger
import com.reposilite.journalist.tinylog.TinyLogWriter
import org.eclipse.jetty.util.log.Log
import org.slf4j.LoggerFactory
import org.tinylog.provider.ProviderRegistry
import panda.std.reactive.Subscriber
Expand Down Expand Up @@ -62,7 +61,7 @@ class ReposiliteJournalist(
init {
if (!testEnv) {
System.setProperty("tinylog.autoshutdown", "false")
Log.getProperties().setProperty("org.eclipse.jetty.util.log.announce", "false")
// Log.setProperty("org.eclipse.jetty.util.log.announce", "false")
}

this.visibleLogger = AggregatedLogger(visibleJournalist.logger, publisherLogger)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ internal class LocalConfigurationProvider(

private val cdn = configurationFile.getSimpleName()
.createCdnByExtension()
.orElseThrow(ThrowingFunction.identity())
.orThrow(ThrowingFunction.identity())

fun initialize() {
workingDirectory.resolve(configurationFile)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,4 +126,4 @@ internal class CustomFrontendHandler(frontendFacade: FrontendFacade, directory:
.let { routes(*it.toTypedArray()) }
}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ internal class RepositoryProvider(
.mapNotNull {
try {
factory.createRepository(it.id, it)
} catch (exception: Exception) {
} catch (exception: Exception) {
failureFacade.throwException("Cannot load ${it.id} repository", exception)
null
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@
*/
String[] dependencies() default {};

/**
* @return custom configuration class used by plugin
*/
Class<? extends SharedSettings> settings() default SharedSettings.class;

}
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ abstract class FileSystemStorageProvider protected constructor(
directory.getSimpleName(),
Files.list(directory).use { directoryStream ->
directoryStream.asSequence()
.map { toSimpleFileDetails(it).orElseThrow { error -> IOException(error.message) } }
.map { toSimpleFileDetails(it).orThrow { error -> IOException(error.message) } }
.sortedWith(FilesComparator({ VersionComparator.asVersion(it.name) }, { it.type == DIRECTORY }))
.toList()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ enum class RoutePermission(val identifier: String, val shortcut: String) {
@JsonCreator
@JvmStatic
fun fromObject(data: Map<String, String>): RoutePermission =
findRoutePermissionByIdentifier(data["identifier"]!!).orElseThrow { IllegalArgumentException(it) }
findRoutePermissionByIdentifier(data["identifier"]!!).orThrow { IllegalArgumentException(it) }

}

Expand Down
30 changes: 14 additions & 16 deletions reposilite-backend/src/main/kotlin/com/reposilite/web/HttpServer.kt
Original file line number Diff line number Diff line change
Expand Up @@ -41,24 +41,22 @@ class HttpServer {
it.start()
}

runWithDisabledLogging {
this.javalin = createJavalin(reposilite, webThreadPool)
.exception(EofException::class.java) { _, _ -> reposilite.logger.warn("Client closed connection") }
.events { listener ->
listener.serverStopping { reposilite.logger.info("Server stopping...") }
listener.serverStopped {
extensionsManagement.emitEvent(HttpServerStoppedEvent)
webThreadPool.stop()
}
this.javalin = createJavalin(reposilite, webThreadPool)
.exception(EofException::class.java) { _, _ -> reposilite.logger.warn("Client closed connection") }
.events { listener ->
listener.serverStopping { reposilite.logger.info("Server stopping...") }
listener.serverStopped {
extensionsManagement.emitEvent(HttpServerStoppedEvent)
webThreadPool.stop()
}
.also {
reposilite.extensions.emitEvent(HttpServerInitializationEvent(reposilite, it))
}

if (!servlet) {
javalin!!.start(reposilite.parameters.hostname, reposilite.parameters.port)
extensionsManagement.emitEvent(HttpServerStarted)
}
.also {
reposilite.extensions.emitEvent(HttpServerInitializationEvent(reposilite, it))
}

if (!servlet) {
javalin!!.start(reposilite.parameters.hostname, reposilite.parameters.port)
extensionsManagement.emitEvent(HttpServerStarted)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ package com.reposilite.web.api
import com.reposilite.Reposilite
import com.reposilite.plugin.api.Event
import io.javalin.Javalin
import io.javalin.core.JavalinConfig
import io.javalin.config.JavalinConfig

class HttpServerConfigurationEvent(val reposilite: Reposilite, val javalinConfig: JavalinConfig) : Event

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,7 @@ import com.reposilite.web.http.response
import com.reposilite.web.http.uri
import com.reposilite.web.infrastructure.CacheBypassHandler
import com.reposilite.web.routing.RoutingPlugin
import io.javalin.core.JavalinConfig
import io.javalin.core.compression.CompressionStrategy
import io.javalin.config.JavalinConfig
import io.javalin.openapi.plugin.OpenApiConfiguration
import io.javalin.openapi.plugin.OpenApiPlugin
import io.javalin.plugin.json.JavalinJackson
Expand All @@ -51,7 +50,7 @@ internal object JavalinConfiguration {

internal fun configure(reposilite: Reposilite, webThreadPool: ThreadPool, config: JavalinConfig) {
val server = Server(webThreadPool)
config.server { server }
config.jetty.server { server }
reposilite.extensions.emitEvent(HttpServerConfigurationEvent(reposilite, config))

val localConfiguration = reposilite.extensions.facade<LocalConfiguration>()
Expand Down Expand Up @@ -82,16 +81,17 @@ internal object JavalinConfiguration {
}

private fun configureJavalin(config: JavalinConfig, localConfiguration: LocalConfiguration, webSettings: Reference<WebSettings>) {
config.showJavalinBanner = false
config.asyncRequestTimeout = 1000L * 60 * 60 * 10 // 10min
config.core.showJavalinBanner = false
config.http.asyncTimeout = 1000L * 60 * 60 * 10 // 10min

config.contextResolvers {
config.core.contextResolvers {
it.ip = { ctx -> ctx.header(webSettings.get().forwardedIp) ?: ctx.req.remoteAddr }
}

when (localConfiguration.compressionStrategy.get().lowercase()) {
"none" -> config.compressionStrategy(CompressionStrategy.NONE)
"gzip" -> config.compressionStrategy(CompressionStrategy.GZIP)
"none" -> config.compression.none()
"gzip" -> config.compression.gzipOnly()
"brotli" -> config.compression.brotliOnly()
else -> throw IllegalStateException("Unknown compression strategy ${localConfiguration.compressionStrategy.get()}")
}
}
Expand Down Expand Up @@ -131,12 +131,12 @@ internal object JavalinConfiguration {
.toSet()
.let { plugin.registerRoutes(it) }

config.registerPlugin(plugin)
config.plugins.register(plugin)
}

private fun configureJsonSerialization(config: JavalinConfig) {
val objectMapper = ReposiliteObjectMapper.DEFAULT_OBJECT_MAPPER
config.jsonMapper(JavalinJackson(objectMapper))
config.core.jsonMapper(JavalinJackson(objectMapper))
}

private fun configureSSL(reposilite: Reposilite, localConfiguration: LocalConfiguration, config: JavalinConfig, server: Server) {
Expand All @@ -159,27 +159,29 @@ internal object JavalinConfiguration {
}
}

config.enforceSsl = localConfiguration.enforceSsl.get()
if (localConfiguration.enforceSsl.get()) {
config.plugins.enableSslRedirects()
}
}

private fun configureCors(config: JavalinConfig) {
config.enableCorsForAllOrigins()
config.plugins.enableCorsForAllOrigins()
}

private fun configureOpenApi(config: JavalinConfig, frontendSettings: FrontendSettings) {
val openApiConfiguration = OpenApiConfiguration()
openApiConfiguration.title = frontendSettings.title
openApiConfiguration.description = frontendSettings.description
openApiConfiguration.version = VERSION
config.registerPlugin(OpenApiPlugin(openApiConfiguration))
config.plugins.register(OpenApiPlugin(openApiConfiguration))
}

private fun configureDebug(journalist: Journalist, localConfiguration: LocalConfiguration, config: JavalinConfig) {
if (localConfiguration.debugEnabled.get()) {
// config.requestCacheSize = FilesUtils.displaySizeToBytesCount(System.getProperty("reposilite.requestCacheSize", "8MB"));
// Reposilite.getLogger().debug("requestCacheSize set to " + config.requestCacheSize + " bytes");
journalist.logger.info("Debug enabled")
config.enableDevLogging()
config.plugins.enableDevLogging()
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@ internal class CacheBypassHandler : ReposiliteRoutes() {

override val routes = routes(bypassCacheRoute)

}
}
Binary file modified reposilite-backend/src/test/workspace/plugins/example-plugin.jar
Binary file not shown.
Binary file modified reposilite-backend/src/test/workspace/plugins/groovy-plugin.jar
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file modified reposilite-backend/src/test/workspace/plugins/swagger-plugin.jar
Binary file not shown.
2 changes: 1 addition & 1 deletion reposilite-plugins/swagger-plugin/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ application {

dependencies {
compileOnly(project(":reposilite-backend"))
implementation("io.javalin-rfc:javalin-swagger-plugin:1.1.3")
implementation("io.javalin:javalin-swagger-plugin:5.0.0-SNAPSHOT")
}

tasks.withType<ShadowJar> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class SwaggerPlugin : ReposilitePlugin() {
event { event: HttpServerConfigurationEvent ->
val swaggerConfiguration = SwaggerConfiguration()
swaggerConfiguration.title = frontendSettings.map { it.title }
event.javalinConfig.registerPlugin(SwaggerPluginForJavalin(swaggerConfiguration))
event.javalinConfig.plugins.register(SwaggerPluginForJavalin(swaggerConfiguration))
}

return null
Expand Down

0 comments on commit cca3316

Please sign in to comment.