Skip to content

Commit 09ed46f

Browse files
committed
Fix missing sonatype requirements test
1 parent 7eafb3d commit 09ed46f

File tree

2 files changed

+30
-19
lines changed

2 files changed

+30
-19
lines changed

modules/cli/src/main/scala/scala/cli/commands/publish/Publish.scala

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -425,7 +425,7 @@ object Publish extends ScalaCommand[PublishOptions] with BuildCommandHelpers {
425425
now: Instant,
426426
isIvy2LocalLike: Boolean,
427427
isCi: Boolean,
428-
isLegacySonatype: Boolean,
428+
isSonatype: Boolean,
429429
withTestScope: Boolean,
430430
logger: Logger
431431
): Either[BuildException, (FileSet, (coursier.core.Module, String))] = either {
@@ -540,7 +540,7 @@ object Publish extends ScalaCommand[PublishOptions] with BuildCommandHelpers {
540540
developers = developers
541541
)
542542

543-
if isLegacySonatype then {
543+
if isSonatype then {
544544
if url.isEmpty then
545545
logger.diagnostic(
546546
"Publishing to Sonatype, but project URL is empty (set it with the '//> using publish.url' directive)."
@@ -750,7 +750,7 @@ object Publish extends ScalaCommand[PublishOptions] with BuildCommandHelpers {
750750
now = now,
751751
isIvy2LocalLike = repoParams.isIvy2LocalLike,
752752
isCi = isCi,
753-
isLegacySonatype = repoParams.isLegacySonatype,
753+
isSonatype = repoParams.isSonatype,
754754
withTestScope = withTestScope,
755755
logger = logger
756756
)
@@ -878,7 +878,7 @@ object Publish extends ScalaCommand[PublishOptions] with BuildCommandHelpers {
878878
val isSnapshot0 = modVersionOpt.exists(_._2.endsWith("SNAPSHOT"))
879879
val authOpt0 = value(authOpt(
880880
repo = repoParams.repo.repo(isSnapshot0).root,
881-
isLegacySonatype = repoParams.isLegacySonatype
881+
isLegacySonatype = repoParams.isSonatype
882882
))
883883
val asciiRegex = """[\u0000-\u007f]*""".r
884884
val usernameOnlyAscii = authOpt0.exists(auth => asciiRegex.matches(auth.user))
@@ -891,7 +891,7 @@ object Publish extends ScalaCommand[PublishOptions] with BuildCommandHelpers {
891891
)
892892
val repoParams0: RepoParams = repoParams.withAuth(authOpt0)
893893
val isLegacySonatype =
894-
repoParams0.isLegacySonatype && !repoParams0.repo.releaseRepo.root.contains("s01")
894+
repoParams0.isSonatype && !repoParams0.repo.releaseRepo.root.contains("s01")
895895
val hooksDataOpt = Option.when(!dummy) {
896896
try repoParams0.hooks.beforeUpload(finalFileSet, isSnapshot0).unsafeRun()(using ec)
897897
catch {
@@ -953,7 +953,7 @@ object Publish extends ScalaCommand[PublishOptions] with BuildCommandHelpers {
953953

954954
errors.toList match {
955955
case (h @ (_, _, e: Upload.Error.HttpError)) :: _
956-
if repoParams0.isLegacySonatype && errors.distinctBy(_._3.getMessage()).size == 1 =>
956+
if repoParams0.isSonatype && errors.distinctBy(_._3.getMessage()).size == 1 =>
957957
val httpCodeRegex = "HTTP (\\d+)\n.*".r
958958
e.getMessage match {
959959
case httpCodeRegex("403") =>
@@ -968,7 +968,7 @@ object Publish extends ScalaCommand[PublishOptions] with BuildCommandHelpers {
968968
)
969969
case _ => throw new UploadError(::(h, Nil))
970970
}
971-
case _ :: _ if repoParams0.isLegacySonatype && errors.forall {
971+
case _ :: _ if repoParams0.isSonatype && errors.forall {
972972
case (_, _, _: Upload.Error.Unauthorized) => true
973973
case _ => false
974974
} =>

modules/cli/src/main/scala/scala/cli/commands/publish/RepoParams.scala

Lines changed: 23 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ final case class RepoParams(
2626
shouldSign: Boolean,
2727
shouldAuthenticate: Boolean
2828
) {
29+
import RepoParams.*
30+
2931
def withAuth(auth: Authentication): RepoParams =
3032
copy(
3133
repo = repo.withAuthentication(auth),
@@ -42,14 +44,26 @@ final case class RepoParams(
4244
)
4345
def withAuth(authOpt: Option[Authentication]): RepoParams = authOpt.fold(this)(withAuth)
4446

45-
lazy val isLegacySonatype: Boolean =
47+
lazy val isSonatype: Boolean =
4648
Option(new URI(repo.snapshotRepo.root))
4749
.filter(_.getScheme == "https")
4850
.map(_.getHost)
49-
.exists(host => host == "oss.sonatype.org" || host.endsWith(".oss.sonatype.org"))
51+
.exists(sonatypeHosts.contains)
5052
}
5153

5254
object RepoParams {
55+
private val sonatypeOssrhStagingApiBase = "https://ossrh-staging-api.central.sonatype.com"
56+
private val sonatypeSnapshotsBase = "https://central.sonatype.com/repository/maven-snapshots/"
57+
private val sonatypeLegacyBase = "https://oss.sonatype.org"
58+
private val sonatypeS01LegacyBase = "https://s01.oss.sonatype.org"
59+
private def sonatypeHosts: Seq[String] =
60+
Seq(
61+
sonatypeLegacyBase,
62+
sonatypeSnapshotsBase,
63+
sonatypeS01LegacyBase,
64+
sonatypeOssrhStagingApiBase
65+
).map(new URI(_).getHost)
66+
5367
def apply(
5468
repo: String,
5569
vcsUrlOpt: Option[String],
@@ -67,10 +81,9 @@ object RepoParams {
6781
case "ivy2-local" =>
6882
RepoParams.ivy2Local(ivy2HomeOpt)
6983
case "sonatype" | "central" | "maven-central" | "mvn-central" =>
70-
val ossrhStagingApiBase = "https://ossrh-staging-api.central.sonatype.com"
71-
logger.message(s"Using Portal OSSRH Staging API: $ossrhStagingApiBase")
84+
logger.message(s"Using Portal OSSRH Staging API: $sonatypeOssrhStagingApiBase")
7285
RepoParams.centralRepo(
73-
base = ossrhStagingApiBase,
86+
base = sonatypeOssrhStagingApiBase,
7487
useLegacySnapshots = false,
7588
connectionTimeoutRetries = connectionTimeoutRetries,
7689
connectionTimeoutSeconds = connectionTimeoutSeconds,
@@ -80,11 +93,10 @@ object RepoParams {
8093
logger = logger
8194
)
8295
case "sonatype-legacy" | "central-legacy" | "maven-central-legacy" | "mvn-central-legacy" =>
83-
val legacyBase = "https://oss.sonatype.org"
84-
logger.message(s"$warnPrefix $legacyBase is EOL since 2025-06-30.")
85-
logger.message(s"$warnPrefix $legacyBase publishing is expected to fail.")
96+
logger.message(s"$warnPrefix $sonatypeLegacyBase is EOL since 2025-06-30.")
97+
logger.message(s"$warnPrefix $sonatypeLegacyBase publishing is expected to fail.")
8698
RepoParams.centralRepo(
87-
base = legacyBase,
99+
base = sonatypeLegacyBase,
88100
useLegacySnapshots = true,
89101
connectionTimeoutRetries = connectionTimeoutRetries,
90102
connectionTimeoutSeconds = connectionTimeoutSeconds,
@@ -94,11 +106,10 @@ object RepoParams {
94106
logger = logger
95107
)
96108
case "sonatype-s01" | "central-s01" | "maven-central-s01" | "mvn-central-s01" =>
97-
val s01SonatypeLegacyBase = "https://s01.oss.sonatype.org"
98-
logger.message(s"$warnPrefix $s01SonatypeLegacyBase is EOL since 2025-06-30.")
109+
logger.message(s"$warnPrefix $sonatypeS01LegacyBase is EOL since 2025-06-30.")
99110
logger.message(s"$warnPrefix it's expected publishing will fail.")
100111
RepoParams.centralRepo(
101-
base = s01SonatypeLegacyBase,
112+
base = sonatypeS01LegacyBase,
102113
useLegacySnapshots = true,
103114
connectionTimeoutRetries = connectionTimeoutRetries,
104115
connectionTimeoutSeconds = connectionTimeoutSeconds,

0 commit comments

Comments
 (0)