@@ -56,7 +56,14 @@ import scala.cli.commands.shared.{
56
56
import scala .cli .commands .util .{BuildCommandHelpers , ScalaCliSttpBackend }
57
57
import scala .cli .commands .{ScalaCommand , SpecificationLevel , WatchUtil }
58
58
import scala .cli .config .{ConfigDb , Keys , PasswordOption , PublishCredentials }
59
- import scala .cli .errors ._
59
+ import scala .cli .errors .{
60
+ FailedToSignFileError ,
61
+ InvalidSonatypePublishCredentials ,
62
+ MalformedChecksumsError ,
63
+ MissingPublishOptionError ,
64
+ UploadError ,
65
+ WrongSonatypeServerError
66
+ }
60
67
import scala .cli .packaging .Library
61
68
import scala .cli .publish .BouncycastleSignerMaker
62
69
import scala .cli .util .ArgHelpers .*
@@ -70,12 +77,16 @@ object Publish extends ScalaCommand[PublishOptions] with BuildCommandHelpers {
70
77
override def scalaSpecificationLevel : SpecificationLevel = SpecificationLevel .EXPERIMENTAL
71
78
72
79
import scala .cli .commands .shared .HelpGroup .*
80
+
73
81
val primaryHelpGroups : Seq [HelpGroup ] = Seq (Publishing , Signing , PGP )
74
82
val hiddenHelpGroups : Seq [HelpGroup ] = Seq (Scala , Java , Entrypoint , Dependency , Watch )
83
+
75
84
override def helpFormat : HelpFormat = super .helpFormat
76
85
.withHiddenGroups(hiddenHelpGroups)
77
86
.withPrimaryGroups(primaryHelpGroups)
87
+
78
88
override def group : String = HelpCommandGroup .Main .toString
89
+
79
90
override def sharedOptions (options : PublishOptions ): Option [SharedOptions ] =
80
91
Some (options.shared)
81
92
@@ -364,18 +375,22 @@ object Publish extends ScalaCommand[PublishOptions] with BuildCommandHelpers {
364
375
" publish.organization"
365
376
))
366
377
}
378
+
367
379
private def defaultName (workspace : os.Path , logger : Logger ): String = {
368
380
val name = workspace.last
369
381
logger.message(
370
382
s " Using directive publish.name not specified, using workspace directory name $name as default name "
371
383
)
372
384
name
373
385
}
386
+
374
387
def defaultComputeVersion (mayDefaultToGitTag : Boolean ): Option [ComputeVersion ] =
375
388
if (mayDefaultToGitTag) Some (ComputeVersion .GitTag (os.rel, dynVer = false , positions = Nil ))
376
389
else None
390
+
377
391
def defaultVersionError =
378
392
new MissingPublishOptionError (" version" , " --project-version" , " publish.version" )
393
+
379
394
def defaultVersion : Either [BuildException , String ] =
380
395
Left (defaultVersionError)
381
396
@@ -490,7 +505,8 @@ object Publish extends ScalaCommand[PublishOptions] with BuildCommandHelpers {
490
505
case None =>
491
506
val computeVer = publishOptions.contextual(isCi).computeVersion.orElse {
492
507
def isGitRepo = GitRepo .gitRepoOpt(workspace).isDefined
493
- val default = defaultComputeVersion(! isCi && isGitRepo)
508
+
509
+ val default = defaultComputeVersion(! isCi && isGitRepo)
494
510
if (default.isDefined)
495
511
logger.message(
496
512
s " Using directive ${defaultVersionError.directiveName} not set, assuming git:tag as publish.computeVersion "
@@ -1018,8 +1034,12 @@ object Publish extends ScalaCommand[PublishOptions] with BuildCommandHelpers {
1018
1034
if (repoParams.isIvy2LocalLike) fileSet2
1019
1035
else fileSet2.order(ec).unsafeRun()(ec)
1020
1036
1021
- val isSnapshot0 = modVersionOpt.exists(_._2.endsWith(" SNAPSHOT" ))
1022
- val authOpt0 = value(authOpt(repoParams.repo.repo(isSnapshot0).root, isSonatype))
1037
+ val isSnapshot0 = modVersionOpt.exists(_._2.endsWith(" SNAPSHOT" ))
1038
+ val authOpt0 = value(authOpt(repoParams.repo.repo(isSnapshot0).root, isSonatype))
1039
+ val asciiRegex = """ [\u0000 -\u007f ]*""" .r
1040
+ val usernameOnlyAscii = authOpt0.exists(auth => asciiRegex.matches(auth.user))
1041
+ val passwordOnlyAscii = authOpt0.exists(_.passwordOpt.exists(pass => asciiRegex.matches(pass)))
1042
+
1023
1043
if (repoParams.shouldAuthenticate && authOpt0.isEmpty)
1024
1044
logger.diagnostic(
1025
1045
" Publishing to a repository that needs authentication, but no credentials are available." ,
@@ -1039,7 +1059,7 @@ object Publish extends ScalaCommand[PublishOptions] with BuildCommandHelpers {
1039
1059
if " Failed to get .*oss\\ .sonatype\\ .org.*/staging/profiles \\ (http status: 401," .r.unanchored.matches(
1040
1060
e.getMessage
1041
1061
) =>
1042
- logger.exit(new InvalidPublishCredentials )
1062
+ logger.exit(new InvalidSonatypePublishCredentials (usernameOnlyAscii, passwordOnlyAscii) )
1043
1063
case NonFatal (e) =>
1044
1064
throw new Exception (e)
1045
1065
}
@@ -1112,7 +1132,6 @@ object Publish extends ScalaCommand[PublishOptions] with BuildCommandHelpers {
1112
1132
|Uploading files failed!
1113
1133
|Possible causes:
1114
1134
|- incorrect Sonatype credentials
1115
- |- your Sonatype password or username may contain unsupported characters
1116
1135
|- incorrect Sonatype server was used, try ${
1117
1136
if isLegacySonatype then " 'central-s01'" else " 'central'"
1118
1137
}
0 commit comments