diff --git a/modules/core/shared/src/main/scala/scaladex/core/service/SonatypeClient.scala b/modules/core/shared/src/main/scala/scaladex/core/service/MavenCentralClient.scala similarity index 94% rename from modules/core/shared/src/main/scala/scaladex/core/service/SonatypeClient.scala rename to modules/core/shared/src/main/scala/scaladex/core/service/MavenCentralClient.scala index 662011709..3181da9f7 100644 --- a/modules/core/shared/src/main/scala/scaladex/core/service/SonatypeClient.scala +++ b/modules/core/shared/src/main/scala/scaladex/core/service/MavenCentralClient.scala @@ -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)]] diff --git a/modules/infra/src/main/scala/scaladex/infra/SonatypeClientImpl.scala b/modules/infra/src/main/scala/scaladex/infra/MavenCentralClientImpl.scala similarity index 91% rename from modules/infra/src/main/scala/scaladex/infra/SonatypeClientImpl.scala rename to modules/infra/src/main/scala/scaladex/infra/MavenCentralClientImpl.scala index 5a0e5431e..6ab8c06a4 100644 --- a/modules/infra/src/main/scala/scaladex/infra/SonatypeClientImpl.scala +++ b/modules/infra/src/main/scala/scaladex/infra/MavenCentralClientImpl.scala @@ -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]), @@ -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) @@ -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 { @@ -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) } diff --git a/modules/infra/src/test/scala/scaladex/infra/SonatypeClientImplTests.scala b/modules/infra/src/test/scala/scaladex/infra/MavenCentralClientImplTests.scala similarity index 66% rename from modules/infra/src/test/scala/scaladex/infra/SonatypeClientImplTests.scala rename to modules/infra/src/test/scala/scaladex/infra/MavenCentralClientImplTests.scala index df4b90386..e5e3ce48a 100644 --- a/modules/infra/src/test/scala/scaladex/infra/SonatypeClientImplTests.scala +++ b/modules/infra/src/test/scala/scaladex/infra/MavenCentralClientImplTests.scala @@ -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 ) @@ -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(" 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 } @@ -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 } diff --git a/modules/server/src/main/scala/scaladex/server/service/SonatypeService.scala b/modules/server/src/main/scala/scaladex/server/service/MavenCentralService.scala similarity index 91% rename from modules/server/src/main/scala/scaladex/server/service/SonatypeService.scala rename to modules/server/src/main/scala/scaladex/server/service/MavenCentralService.scala index 2127d7daa..656d92bdb 100644 --- a/modules/server/src/main/scala/scaladex/server/service/SonatypeService.scala +++ b/modules/server/src/main/scala/scaladex/server/service/MavenCentralService.scala @@ -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 { @@ -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) @@ -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 ) @@ -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) }