Skip to content

Commit

Permalink
GH-2254 Convert current implementation of repositories into Maven-spe…
Browse files Browse the repository at this point in the history
…cific sources
  • Loading branch information
dzikoysk committed Nov 1, 2024
1 parent cf0ac2a commit a331f41
Show file tree
Hide file tree
Showing 62 changed files with 418 additions and 416 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ import com.reposilite.configuration.shared.SharedConfigurationFacade
import com.reposilite.journalist.Channel
import com.reposilite.journalist.Logger
import com.reposilite.journalist.backend.PrintStreamLogger
import com.reposilite.maven.application.MavenSettings
import com.reposilite.maven.application.MirroredRepositorySettings
import com.reposilite.maven.application.RepositorySettings
import com.reposilite.packages.maven.application.MavenSettings
import com.reposilite.packages.maven.application.MirroredRepositorySettings
import com.reposilite.packages.maven.application.RepositorySettings
import com.reposilite.storage.StorageProviderSettings
import io.javalin.util.JavalinBindException
import net.dzikoysk.cdn.KCdnFactory
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@

package com.reposilite

import com.reposilite.maven.MavenFacade
import com.reposilite.maven.api.DeployRequest
import com.reposilite.maven.api.Metadata
import com.reposilite.maven.api.SaveMetadataRequest
import com.reposilite.maven.api.Versioning
import com.reposilite.packages.maven.MavenFacade
import com.reposilite.packages.maven.api.DeployRequest
import com.reposilite.packages.maven.api.Metadata
import com.reposilite.packages.maven.api.SaveMetadataRequest
import com.reposilite.packages.maven.api.Versioning
import com.reposilite.plugin.api.Facade
import com.reposilite.shared.ErrorResponse
import com.reposilite.storage.VersionComparator
Expand Down Expand Up @@ -121,7 +121,7 @@ internal abstract class ReposiliteSpecification : ReposiliteRunner() {
if (store) {
mavenFacade.deployFile(
DeployRequest(
repository = mavenFacade.getRepository(repository)!!,
mavenRepository = mavenFacade.getRepository(repository)!!,
gav = "$gav/$file".toLocation(),
by = "junit",
content = content.byteInputStream(Charsets.UTF_8),
Expand All @@ -147,7 +147,7 @@ internal abstract class ReposiliteSpecification : ReposiliteRunner() {

return repository to mavenFacade.saveMetadata(
SaveMetadataRequest(
repository = mavenFacade.getRepository(repository)!!,
mavenRepository = mavenFacade.getRepository(repository)!!,
gav = "$groupId.$artifactId".replace(".", "/").toLocation(),
metadata = metadata
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import com.reposilite.auth.application.AuthenticationSettings
import com.reposilite.auth.application.LdapSettings
import com.reposilite.configuration.shared.SharedConfigurationFacade
import com.reposilite.configuration.specification.SettingsIntegrationSpecification
import com.reposilite.maven.application.MavenSettings
import com.reposilite.packages.maven.application.MavenSettings
import com.reposilite.shared.ErrorResponse
import com.reposilite.statistics.api.ResolvedRequestsInterval.YEARLY
import com.reposilite.statistics.application.StatisticsSettings
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@

@file:Suppress("FunctionName")

package com.reposilite.maven
package com.reposilite.packages.maven

import com.reposilite.RecommendedLocalSpecificationJunitExtension
import com.reposilite.RecommendedRemoteSpecificationJunitExtension
import com.reposilite.maven.specification.MavenIntegrationSpecification
import com.reposilite.packages.maven.specification.MavenIntegrationSpecification
import com.reposilite.token.RoutePermission.READ
import io.javalin.http.HttpStatus.UNAUTHORIZED
import kong.unirest.core.Unirest.get
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@

@file:Suppress("FunctionName")

package com.reposilite.maven
package com.reposilite.packages.maven

import com.reposilite.RecommendedLocalSpecificationJunitExtension
import com.reposilite.RecommendedRemoteSpecificationJunitExtension
import com.reposilite.configuration.local.LocalConfiguration
import com.reposilite.maven.specification.MavenIntegrationSpecification
import com.reposilite.packages.maven.specification.MavenIntegrationSpecification
import com.reposilite.shared.ErrorResponse
import com.reposilite.shared.extensions.maxAge
import com.reposilite.storage.api.DocumentInfo
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
@file:Suppress("FunctionName")

package com.reposilite.maven
package com.reposilite.packages.maven

import com.reposilite.RecommendedLocalSpecificationJunitExtension
import com.reposilite.RecommendedRemoteSpecificationJunitExtension
import com.reposilite.maven.api.LookupRequest
import com.reposilite.maven.specification.MavenIntegrationSpecification
import com.reposilite.packages.maven.api.LookupRequest
import com.reposilite.packages.maven.specification.MavenIntegrationSpecification
import com.reposilite.storage.api.toLocation
import kong.unirest.core.Unirest.get
import kotlinx.coroutines.runBlocking
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* limitations under the License.
*/

package com.reposilite.maven.specification
package com.reposilite.packages.maven.specification

import com.reposilite.ReposiliteSpecification
import io.javalin.Javalin
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import com.reposilite.ExperimentalLocalSpecificationJunitExtension
import com.reposilite.ExperimentalRemoteSpecficiationJunitExtension
import com.reposilite.RecommendedLocalSpecificationJunitExtension
import com.reposilite.RecommendedRemoteSpecificationJunitExtension
import com.reposilite.maven.api.Identifier
import com.reposilite.packages.maven.api.Identifier
import com.reposilite.statistics.api.AllResolvedResponse
import com.reposilite.statistics.api.IntervalRecord
import com.reposilite.statistics.api.RepositoryStatistics
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
package com.reposilite.statistics.specification

import com.reposilite.ReposiliteSpecification
import com.reposilite.maven.api.Identifier
import com.reposilite.packages.maven.api.Identifier
import com.reposilite.statistics.StatisticsFacade
import io.javalin.http.HttpStatus.OK
import kong.unirest.core.Unirest.get
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package com.reposilite.javadocs

import com.reposilite.maven.MavenFacade
import com.reposilite.maven.Repository
import com.reposilite.maven.api.LookupRequest
import com.reposilite.packages.maven.MavenFacade
import com.reposilite.packages.maven.MavenRepository
import com.reposilite.packages.maven.api.LookupRequest
import com.reposilite.shared.ErrorResponse
import com.reposilite.shared.badRequest
import com.reposilite.shared.badRequestError
Expand Down Expand Up @@ -39,22 +39,22 @@ internal class JavadocContainerService(
private val javadocFolder: Path
) {

fun loadContainer(accessToken: AccessTokenIdentifier?, repository: Repository, gav: Location): Result<JavadocContainer, ErrorResponse> {
val javadocJar = this.resolveJavadocJar(repository, gav) ?: return badRequestError("Invalid GAV")
fun loadContainer(accessToken: AccessTokenIdentifier?, mavenRepository: MavenRepository, gav: Location): Result<JavadocContainer, ErrorResponse> {
val javadocJar = this.resolveJavadocJar(mavenRepository, gav) ?: return badRequestError("Invalid GAV")

return mavenFacade.findDetails(LookupRequest(accessToken, repository.name, javadocJar))
return mavenFacade.findDetails(LookupRequest(accessToken, mavenRepository.name, javadocJar))
.filter({ it.type === FILE }, { badRequest("Invalid request") })
.filter({ isJavadocJar(it.name) }, { notFound("Please do not provide a direct link to a non javadoc file! GAV must be pointing to a directory or a javadoc file!") })
.flatMap { loadJavadocJarContainer(accessToken, repository, javadocJar) }
.flatMap { loadJavadocJarContainer(accessToken, mavenRepository, javadocJar) }
}

private fun resolveJavadocJar(repository: Repository, gav: Location): Location? = when {
private fun resolveJavadocJar(mavenRepository: MavenRepository, gav: Location): Location? = when {
gav.endsWith(".jar") -> gav
gav.endsWith("/$INDEX_FILE") -> resolveIndexGav(repository, gav)
else -> resolveJavadocJar(repository, gav.resolve(INDEX_FILE))
gav.endsWith("/$INDEX_FILE") -> resolveIndexGav(mavenRepository, gav)
else -> resolveJavadocJar(mavenRepository, gav.resolve(INDEX_FILE))
}

private fun resolveIndexGav(repository: Repository, gav: Location): Location? {
private fun resolveIndexGav(mavenRepository: MavenRepository, gav: Location): Location? {
val rootGav = gav.locationBeforeLast("/$INDEX_FILE")
val elements = rootGav.toString().split("/")

Expand All @@ -66,7 +66,7 @@ internal class JavadocContainerService(
var version = elements[elements.size - 1]

if (version.contains("-SNAPSHOT")) {
val metadataResult = mavenFacade.findMetadata(repository, rootGav)
val metadataResult = mavenFacade.findMetadata(mavenRepository, rootGav)
val snapshot = if (metadataResult.isOk) metadataResult.get().versioning?.snapshot else null

if (snapshot?.timestamp != null && snapshot.buildNumber != null) {
Expand All @@ -77,8 +77,8 @@ internal class JavadocContainerService(
return rootGav.resolve("${name}-${version}-javadoc.jar")
}

private fun loadJavadocJarContainer(accessToken: AccessTokenIdentifier?, repository: Repository, gav: Location): Result<JavadocContainer, ErrorResponse> {
val container: JavadocContainer = createContainer(javadocFolder, repository, gav)
private fun loadJavadocJarContainer(accessToken: AccessTokenIdentifier?, mavenRepository: MavenRepository, gav: Location): Result<JavadocContainer, ErrorResponse> {
val container: JavadocContainer = createContainer(javadocFolder, mavenRepository, gav)

if (Files.exists(container.javadocContainerIndex)) {
return Result.ok(container)
Expand All @@ -89,16 +89,16 @@ internal class JavadocContainerService(
Files.createDirectories(javadocUnpackPath)
val copyJarPath = javadocUnpackPath.resolve("javadoc.jar")

return mavenFacade.findFile(LookupRequest(accessToken, repository.name, gav))
return mavenFacade.findFile(LookupRequest(accessToken, mavenRepository.name, gav))
.peek { (_, originInput) -> this.copyJavadocJar(originInput, copyJarPath) }
.flatMap { this.unpackJavadocJar(copyJarPath, javadocUnpackPath) }
.peek { this.createDocIndexHtml(container) }
.map { container }
}

internal fun createContainer(javadocFolder: Path, repository: Repository, jarLocation: Location): JavadocContainer {
internal fun createContainer(javadocFolder: Path, mavenRepository: MavenRepository, jarLocation: Location): JavadocContainer {
val javadocContainerPath = javadocFolder
.resolve(repository.name)
.resolve(mavenRepository.name)
.resolve(jarLocation.locationBeforeLast("/").toString())
.resolve(".cache")

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ import com.reposilite.javadocs.api.JavadocRawResponse
import com.reposilite.javadocs.api.JavadocResponse
import com.reposilite.journalist.Journalist
import com.reposilite.journalist.Logger
import com.reposilite.maven.MavenFacade
import com.reposilite.maven.Repository
import com.reposilite.maven.api.VersionLookupRequest
import com.reposilite.packages.maven.MavenFacade
import com.reposilite.packages.maven.MavenRepository
import com.reposilite.packages.maven.api.VersionLookupRequest
import com.reposilite.plugin.api.Facade
import com.reposilite.shared.ErrorResponse
import com.reposilite.shared.notFound
Expand Down Expand Up @@ -65,15 +65,15 @@ class JavadocFacade internal constructor(

fun findJavadocPage(request: JavadocPageRequest): Result<JavadocResponse, ErrorResponse> =
with (request) {
mavenFacade.canAccessResource(accessToken, repository, gav)
.flatMap { createPage(accessToken, repository, resolveGav(request)) }
mavenFacade.canAccessResource(accessToken, mavenRepository, gav)
.flatMap { createPage(accessToken, mavenRepository, resolveGav(request)) }
.onError { logger.error("Cannot extract javadoc: ${it.message} (${it.status})}") }
}

fun findRawJavadocResource(request: JavadocRawRequest): Result<JavadocRawResponse, ErrorResponse> =
with (request) {
mavenFacade.canAccessResource(accessToken, repository, gav)
.flatMap { javadocContainerService.loadContainer(accessToken, repository, gav) }
mavenFacade.canAccessResource(accessToken, mavenRepository, gav)
.flatMap { javadocContainerService.loadContainer(accessToken, mavenRepository, gav) }
.filter({ Files.exists(it.javadocUnpackPath.resolve(resource.toString())) }, { notFound("Resource $resource not found") })
.map {
JavadocRawResponse(
Expand All @@ -83,8 +83,8 @@ class JavadocFacade internal constructor(
}
}

private fun createPage(accessToken: AccessTokenIdentifier?, repository: Repository, gav: Location): Result<JavadocResponse, ErrorResponse> {
val resourcesFile = createPlainFile(javadocFolder, repository, gav)
private fun createPage(accessToken: AccessTokenIdentifier?, mavenRepository: MavenRepository, gav: Location): Result<JavadocResponse, ErrorResponse> {
val resourcesFile = createPlainFile(javadocFolder, mavenRepository, gav)

return when {
/* File not found */
Expand All @@ -103,14 +103,14 @@ class JavadocFacade internal constructor(
/* Load resource */
else ->
javadocContainerService
.loadContainer(accessToken, repository, gav)
.loadContainer(accessToken, mavenRepository, gav)
.map { JavadocResponse(ContentType.HTML, readFile(it.javadocContainerIndex)) }
}
}

private fun createPlainFile(javadocFolder: Path, repository: Repository, gav: Location): JavadocPlainFile? =
private fun createPlainFile(javadocFolder: Path, mavenRepository: MavenRepository, gav: Location): JavadocPlainFile? =
javadocFolder
.resolve(repository.name)
.resolve(mavenRepository.name)
.resolve(gav.toString())
.let { targetPath -> targetPath to supportedExtensions[gav.getExtension()] }
.takeIf { (_, contentType) -> contentType != null }
Expand All @@ -123,7 +123,7 @@ class JavadocFacade internal constructor(
request.gav
.takeIf { it.contains("/latest") }
?.let { request.gav.locationBeforeLast("/latest") }
?.let { gavWithoutVersion -> VersionLookupRequest(request.accessToken, request.repository, gavWithoutVersion) }
?.let { gavWithoutVersion -> VersionLookupRequest(request.accessToken, request.mavenRepository, gavWithoutVersion) }
?.let { mavenFacade.findLatestVersion(it) }
?.map { request.gav.replace(LATEST_PATTERN, "/%s".format(it.version)) }
?.orNull()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
package com.reposilite.javadocs.api

import com.reposilite.maven.Repository
import com.reposilite.packages.maven.MavenRepository
import com.reposilite.storage.api.Location
import com.reposilite.token.AccessTokenIdentifier
import io.javalin.http.ContentType
import java.io.InputStream

data class JavadocPageRequest(
val accessToken: AccessTokenIdentifier?,
val repository: Repository,
val mavenRepository: MavenRepository,
val gav: Location
)

data class JavadocRawRequest(
val accessToken: AccessTokenIdentifier?,
val repository: Repository,
val mavenRepository: MavenRepository,
val gav: Location,
val resource: Location
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ package com.reposilite.javadocs.application
import com.reposilite.javadocs.JavadocContainerService
import com.reposilite.javadocs.JavadocFacade
import com.reposilite.javadocs.infrastructure.JavadocEndpoints
import com.reposilite.maven.MavenFacade
import com.reposilite.maven.api.DeployEvent
import com.reposilite.packages.maven.MavenFacade
import com.reposilite.packages.maven.api.DeployEvent
import com.reposilite.plugin.api.Facade
import com.reposilite.plugin.api.Plugin
import com.reposilite.plugin.api.ReposilitePlugin
Expand Down Expand Up @@ -56,7 +56,7 @@ internal class JavadocPlugin : ReposilitePlugin() {
.takeIf { it.toString().endsWith("-javadoc.jar") }
?: return@event

val container = javadocContainerService.createContainer(javadocFolder, event.repository, gav)
val container = javadocContainerService.createContainer(javadocFolder, event.mavenRepository, gav)
val javadocDirectory = container.javadocContainerPath.toFile()

if (javadocDirectory.exists()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ package com.reposilite.javadocs.infrastructure
import com.reposilite.javadocs.JavadocFacade
import com.reposilite.javadocs.api.JavadocPageRequest
import com.reposilite.javadocs.api.JavadocRawRequest
import com.reposilite.maven.infrastructure.MavenRoutes
import com.reposilite.packages.maven.infrastructure.MavenRoutes
import com.reposilite.shared.extensions.encoding
import com.reposilite.storage.api.toLocation
import com.reposilite.web.api.ReposiliteRoute
Expand Down
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package com.reposilite.packages

interface Repository {
}
Loading

0 comments on commit a331f41

Please sign in to comment.