Skip to content

Commit

Permalink
Rename Sonatype to MavenCentral
Browse files Browse the repository at this point in the history
  • Loading branch information
adpi2 committed Aug 21, 2024
1 parent d63478c commit 25ff819
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 36 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import scaladex.core.model.Artifact
import scaladex.core.model.Artifact.MavenReference
import scaladex.core.model.SemanticVersion

trait SonatypeClient {
trait MavenCentralClient {
def getAllArtifactIds(groupId: Artifact.GroupId): Future[Seq[Artifact.ArtifactId]]
def getAllVersions(groupId: Artifact.GroupId, artifactId: Artifact.ArtifactId): Future[Seq[SemanticVersion]]
def getPomFile(mavenReference: MavenReference): Future[Option[(String, Instant)]]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,15 @@ import scaladex.core.model.Artifact
import scaladex.core.model.Artifact.MavenReference
import scaladex.core.model.SbtPlugin
import scaladex.core.model.SemanticVersion
import scaladex.core.service.SonatypeClient
import scaladex.core.service.MavenCentralClient
import scaladex.core.util.JsoupUtils

class SonatypeClientImpl()(implicit val system: ActorSystem)
class MavenCentralClientImpl()(implicit val system: ActorSystem)
extends CommonAkkaHttpClient
with SonatypeClient
with MavenCentralClient
with LazyLogging {
private implicit val ec: ExecutionContextExecutor = system.dispatcher
private val sonatypeUri = "https://repo1.maven.org/maven2"
private val baseUri = "https://repo1.maven.org/maven2"
lazy val poolClientFlow: Flow[
(HttpRequest, Promise[HttpResponse]),
(Try[HttpResponse], Promise[HttpResponse]),
Expand All @@ -46,7 +46,7 @@ class SonatypeClientImpl()(implicit val system: ActorSystem)
)

def getAllArtifactIds(groupId: Artifact.GroupId): Future[Seq[Artifact.ArtifactId]] = {
val uri = s"$sonatypeUri/${groupId.mavenUrl}/"
val uri = s"$baseUri/${groupId.mavenUrl}/"
val request =
HttpRequest(uri = uri)

Expand All @@ -60,7 +60,7 @@ class SonatypeClientImpl()(implicit val system: ActorSystem)
}

def getAllVersions(groupId: Artifact.GroupId, artifactId: Artifact.ArtifactId): Future[Seq[SemanticVersion]] = {
val uri = s"$sonatypeUri/${groupId.mavenUrl}/${artifactId.value}/"
val uri = s"$baseUri/${groupId.mavenUrl}/${artifactId.value}/"
val request = HttpRequest(uri = uri)

val future = for {
Expand Down Expand Up @@ -104,7 +104,7 @@ class SonatypeClientImpl()(implicit val system: ActorSystem)
.parse(mavenReference.artifactId)
.map { artifactId =>
val pomUrl = getPomUrl(artifactId, mavenReference.version)
val uri = s"$sonatypeUri/${groupIdUrl}/${mavenReference.artifactId}/${mavenReference.version}/$pomUrl"
val uri = s"$baseUri/${groupIdUrl}/${mavenReference.artifactId}/${mavenReference.version}/$pomUrl"
val request = HttpRequest(uri = uri)
queueRequest(request).map(Option.apply)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,28 +9,28 @@ import scaladex.core.model.Artifact
import scaladex.core.model.Artifact._
import scaladex.core.model.SemanticVersion

class SonatypeClientImplTests extends AsyncFunSpec with Matchers {
implicit val system: ActorSystem = ActorSystem("sonatype-client-tests")
val sonatypeClient = new SonatypeClientImpl()
class MavenCentralClientImplTests extends AsyncFunSpec with Matchers {
implicit val system: ActorSystem = ActorSystem("maven-central-client-tests")
val client = new MavenCentralClientImpl()
val groupId: GroupId = GroupId("ch.epfl.scala")
val artifactId: ArtifactId = ArtifactId.parse("sbt-scalafix_2.12_1.0").get
val version: SemanticVersion = SemanticVersion.parse("0.9.23").get

it(s"retrieve artifactIds for ${groupId.value}") {
for {
res <- sonatypeClient.getAllArtifactIds(groupId)
res <- client.getAllArtifactIds(groupId)
} yield res should contain(artifactId)
}

it(s"retrieve versions for groupId: ${groupId.value}, artifactId: ${artifactId.value}") {
for {
res <- sonatypeClient.getAllVersions(groupId, artifactId)
res <- client.getAllVersions(groupId, artifactId)
} yield res should contain(version)
}

it(s"retrieve versions for ru.tinkoff:typed-schema-swagger-typesafe_2.12") {
for {
res <- sonatypeClient.getAllVersions(
res <- client.getAllVersions(
GroupId("ru.tinkoff"),
ArtifactId.parse("typed-schema-swagger-typesafe_2.12").get
)
Expand All @@ -39,31 +39,31 @@ class SonatypeClientImplTests extends AsyncFunSpec with Matchers {

it(s"retrieve pomfile for maven reference of sbt plugin") {
for {
res <- sonatypeClient.getPomFile(Artifact.MavenReference("ch.epfl.scala", "sbt-scalafix_2.12_1.0", "0.9.23"))
res <- client.getPomFile(Artifact.MavenReference("ch.epfl.scala", "sbt-scalafix_2.12_1.0", "0.9.23"))
} yield res.get._1.startsWith("<?xml") shouldBe true
}

it(s"retrieve pomfile for maven reference of jvm") {
for {
res <- sonatypeClient.getPomFile(Artifact.MavenReference("ch.epfl.scala", "scalafix-core_2.13", "0.9.23"))
res <- client.getPomFile(Artifact.MavenReference("ch.epfl.scala", "scalafix-core_2.13", "0.9.23"))
} yield res.get._1.startsWith("<?xml") shouldBe true
}

it(s"retrieve pomfile for maven reference of ScalaJs") {
for {
res <- sonatypeClient.getPomFile(Artifact.MavenReference("ch.epfl.scala", "bloop-config_sjs1_2.13", "1.4.11"))
res <- client.getPomFile(Artifact.MavenReference("ch.epfl.scala", "bloop-config_sjs1_2.13", "1.4.11"))
} yield res.get._1.startsWith("<?xml") shouldBe true
}

it(s"retrieve pomfile for maven reference of Scala Native") {
for {
res <- sonatypeClient.getPomFile(
res <- client.getPomFile(
Artifact.MavenReference("ch.epfl.scala", "bloop-native-bridge-0-4_2.12", "1.3.4")
)
} yield res.get._1.startsWith("<?xml") shouldBe true
}

it(s"parse date time") {
sonatypeClient.parseDate("Wed, 23 Sep 2020 11:40:44 GMT") shouldBe Instant.ofEpochSecond(1600861244L)
client.parseDate("Wed, 23 Sep 2020 11:40:44 GMT") shouldBe Instant.ofEpochSecond(1600861244L)
}
}
11 changes: 6 additions & 5 deletions modules/server/src/main/scala/scaladex/server/Server.scala
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,16 @@ import scaladex.infra.DataPaths
import scaladex.infra.ElasticsearchEngine
import scaladex.infra.FilesystemStorage
import scaladex.infra.GithubClientImpl
import scaladex.infra.SonatypeClientImpl
import scaladex.infra.MavenCentralClientImpl
import scaladex.infra.SqlDatabase
import scaladex.infra.sql.DoobieUtils
import scaladex.server.config.ServerConfig
import scaladex.server.route.AuthenticationApi
import scaladex.server.route._
import scaladex.server.route.api._
import scaladex.server.service.AdminService
import scaladex.server.service.MavenCentralService
import scaladex.server.service.PublishProcess
import scaladex.server.service.SonatypeService
import scaladex.view.html.notfound
object Server extends LazyLogging {

Expand Down Expand Up @@ -67,10 +67,11 @@ object Server extends LazyLogging {
val paths = DataPaths.from(config.filesystem)
val filesystem = FilesystemStorage(config.filesystem)
val publishProcess = PublishProcess(paths, filesystem, webDatabase, config.env)(publishPool, system)
val sonatypeClient = new SonatypeClientImpl()
val sonatypeSynchronizer = new SonatypeService(paths, schedulerDatabase, sonatypeClient, publishProcess)
val mavenCentralClient = new MavenCentralClientImpl()
val mavenCentralService =
new MavenCentralService(paths, schedulerDatabase, mavenCentralClient, publishProcess)
val adminService =
new AdminService(config.env, schedulerDatabase, searchEngine, githubClient, sonatypeSynchronizer)
new AdminService(config.env, schedulerDatabase, searchEngine, githubClient, mavenCentralService)

for {
_ <- init(webDatabase, adminService, searchEngine, config.elasticsearch.reset)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class AdminService(
database: SchedulerDatabase,
searchEngine: SearchEngine,
githubClientOpt: Option[GithubClient],
sonatypeSynchronizer: SonatypeService
mavenCentralService: MavenCentralService
)(implicit actorSystem: ActorSystem)
extends LazyLogging {
import actorSystem.dispatcher
Expand All @@ -50,8 +50,8 @@ class AdminService(
} ++ (
if (!env.isLocal) {
Seq(
new JobScheduler(Job.missingMavenArtifacts, sonatypeSynchronizer.findMissing),
new JobScheduler(Job.nonStandardArtifacts, sonatypeSynchronizer.findNonStandard)
new JobScheduler(Job.missingMavenArtifacts, mavenCentralService.findMissing),
new JobScheduler(Job.nonStandardArtifacts, mavenCentralService.findNonStandard)
)
} else Seq.empty
)
Expand Down Expand Up @@ -80,7 +80,7 @@ class AdminService(
val input = Seq("Group ID" -> groupId.value) ++
artifactNameOpt.map(name => "Artifact Name" -> name.value)
val task = TaskRunner.run(Task.findMissingArtifacts, user.info.login, input) { () =>
sonatypeSynchronizer.syncOne(groupId, artifactNameOpt)
mavenCentralService.syncOne(groupId, artifactNameOpt)
}
tasks = tasks :+ task
}
Expand Down Expand Up @@ -139,7 +139,7 @@ class AdminService(

def republishArtifacts(user: UserState): Unit = {
val task = TaskRunner.run(Task.republishArtifacts, user.info.login, input = Seq.empty) { () =>
sonatypeSynchronizer.republishArtifacts()
mavenCentralService.republishArtifacts()
}
tasks = tasks :+ task
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,16 @@ import com.typesafe.scalalogging.LazyLogging
import scaladex.core.model.Artifact
import scaladex.core.model.Artifact._
import scaladex.core.model.Project
import scaladex.core.service.MavenCentralClient
import scaladex.core.service.SchedulerDatabase
import scaladex.core.service.SonatypeClient
import scaladex.core.util.ScalaExtensions._
import scaladex.data.cleanup.NonStandardLib
import scaladex.infra.DataPaths

class SonatypeService(
class MavenCentralService(
dataPaths: DataPaths,
database: SchedulerDatabase,
sonatypeService: SonatypeClient,
mavenCentralClient: MavenCentralClient,
publishProcess: PublishProcess
)(implicit ec: ExecutionContext)
extends LazyLogging {
Expand All @@ -40,14 +40,14 @@ class SonatypeService(
knownRefs: Set[MavenReference]
): Future[Int] =
for {
versions <- sonatypeService.getAllVersions(groupId, artifactId)
versions <- mavenCentralClient.getAllVersions(groupId, artifactId)
mavenReferences = versions.map(v =>
MavenReference(groupId = groupId.value, artifactId = artifactId.value, version = v.toString)
)
missingVersions = mavenReferences.filterNot(knownRefs)
_ = if (missingVersions.nonEmpty)
logger.warn(s"${missingVersions.size} artifacts are missing for ${groupId.value}:${artifactId.value}")
missingPomFiles <- missingVersions.map(ref => sonatypeService.getPomFile(ref).map(_.map(ref -> _))).sequence
missingPomFiles <- missingVersions.map(ref => mavenCentralClient.getPomFile(ref).map(_.map(ref -> _))).sequence
publishResult <- missingPomFiles.flatten.mapSync {
case (mavenRef, (pomFile, creationDate)) =>
publishProcess.publishPom(mavenRef.toString(), pomFile, creationDate, None)
Expand All @@ -71,7 +71,7 @@ class SonatypeService(
knownRefs: Set[MavenReference]
): Future[Int] =
for {
artifactIds <- sonatypeService.getAllArtifactIds(groupId)
artifactIds <- mavenCentralClient.getAllArtifactIds(groupId)
scalaArtifactIds = artifactIds.filter(artifact =>
artifactNameOpt.forall(_ == artifact.name) && artifact.isScala && artifact.binaryVersion.isValid
)
Expand Down Expand Up @@ -108,7 +108,7 @@ class SonatypeService(
}

private def republishArtifact(projectRef: Project.Reference, ref: MavenReference): Future[PublishResult] =
sonatypeService.getPomFile(ref).flatMap {
mavenCentralClient.getPomFile(ref).flatMap {
case Some((pomFile, creationDate)) => publishProcess.republishPom(projectRef, ref, pomFile, creationDate)
case _ => Future.successful(PublishResult.InvalidPom)
}
Expand Down

0 comments on commit 25ff819

Please sign in to comment.