@@ -751,51 +751,50 @@ object Publish extends ScalaCommand[PublishOptions] with BuildCommandHelpers {
751
751
752
752
val ec = builds.head.options.finalCache.ec
753
753
754
- def authOpt (repo : String ): Either [BuildException , Option [Authentication ]] = either {
755
- val isHttps = {
756
- val uri = new URI (repo)
757
- uri.getScheme == " https"
758
- }
759
- val hostOpt = Option .when(isHttps)(new URI (repo).getHost)
760
- val maybeCredentials : Either [BuildException , Option [PublishCredentials ]] = hostOpt match {
761
- case None => Right (None )
762
- case Some (host) =>
763
- configDb().get(Keys .publishCredentials).wrapConfigException.map { credListOpt =>
764
- credListOpt.flatMap { credList =>
765
- credList.find { cred =>
766
- cred.host == host &&
767
- (isHttps || cred.httpsOnly.contains(false ))
754
+ def authOpt (repo : String , isSonatype : Boolean ): Either [BuildException , Option [Authentication ]] =
755
+ either {
756
+ val isHttps = {
757
+ val uri = new URI (repo)
758
+ uri.getScheme == " https"
759
+ }
760
+ val hostOpt = Option .when(isHttps)(new URI (repo).getHost)
761
+ val maybeCredentials : Either [BuildException , Option [PublishCredentials ]] = hostOpt match {
762
+ case None => Right (None )
763
+ case Some (host) =>
764
+ configDb().get(Keys .publishCredentials).wrapConfigException.map { credListOpt =>
765
+ credListOpt.flatMap { credList =>
766
+ credList.find { cred =>
767
+ cred.host == host &&
768
+ (isHttps || cred.httpsOnly.contains(false ))
769
+ }
768
770
}
769
771
}
770
- }
771
- }
772
- val isSonatype =
773
- hostOpt.exists(host => host == " oss.sonatype.org" || host.endsWith(" .oss.sonatype.org" ))
774
- val passwordOpt = publishOptions.contextual(isCi).repoPassword match {
775
- case None => value(maybeCredentials).flatMap(_.password)
776
- case other => other.map(_.toConfig)
777
- }
778
- passwordOpt.map(_.get()) match {
779
- case None => None
780
- case Some (password) =>
781
- val userOpt = publishOptions.contextual(isCi).repoUser match {
782
- case None => value(maybeCredentials).flatMap(_.user)
783
- case other => other.map(_.toConfig)
784
- }
785
- val realmOpt = publishOptions.contextual(isCi).repoRealm match {
786
- case None =>
787
- value(maybeCredentials)
788
- .flatMap(_.realm)
789
- .orElse {
790
- if (isSonatype) Some (" Sonatype Nexus Repository Manager" )
791
- else None
792
- }
793
- case other => other
794
- }
795
- val auth = Authentication (userOpt.fold(" " )(_.get().value), password.value)
796
- Some (realmOpt.fold(auth)(auth.withRealm))
772
+ }
773
+ val passwordOpt = publishOptions.contextual(isCi).repoPassword match {
774
+ case None => value(maybeCredentials).flatMap(_.password)
775
+ case other => other.map(_.toConfig)
776
+ }
777
+ passwordOpt.map(_.get()) match {
778
+ case None => None
779
+ case Some (password) =>
780
+ val userOpt = publishOptions.contextual(isCi).repoUser match {
781
+ case None => value(maybeCredentials).flatMap(_.user)
782
+ case other => other.map(_.toConfig)
783
+ }
784
+ val realmOpt = publishOptions.contextual(isCi).repoRealm match {
785
+ case None =>
786
+ value(maybeCredentials)
787
+ .flatMap(_.realm)
788
+ .orElse {
789
+ if (isSonatype) Some (" Sonatype Nexus Repository Manager" )
790
+ else None
791
+ }
792
+ case other => other
793
+ }
794
+ val auth = Authentication (userOpt.fold(" " )(_.get().value), password.value)
795
+ Some (realmOpt.fold(auth)(auth.withRealm))
796
+ }
797
797
}
798
- }
799
798
800
799
val repoParams = {
801
800
@@ -831,32 +830,28 @@ object Publish extends ScalaCommand[PublishOptions] with BuildCommandHelpers {
831
830
}
832
831
}
833
832
833
+ val isSonatype : Boolean = {
834
+ val uri = new URI (repoParams.repo.snapshotRepo.root)
835
+ val hostOpt = Option .when(uri.getScheme == " https" )(uri.getHost)
836
+
837
+ hostOpt.exists(host => host == " oss.sonatype.org" || host.endsWith(" .oss.sonatype.org" ))
838
+ }
839
+
834
840
val now = Instant .now()
835
841
val (fileSet0, modVersionOpt) = value {
836
842
it
837
843
// TODO Allow to add test JARs to the main build artifacts
838
844
.filter(_._1.scope != Scope .Test )
839
845
.map {
840
846
case (build, docBuildOpt) =>
841
- val isSonatype = {
842
- val hostOpt = {
843
- val repo = repoParams.repo.snapshotRepo.root
844
- val uri = new URI (repo)
845
- if (uri.getScheme == " https" ) Some (uri.getHost)
846
- else None
847
- }
848
- hostOpt.exists(host =>
849
- host == " oss.sonatype.org" || host.endsWith(" .oss.sonatype.org" )
850
- )
851
- }
852
847
buildFileSet(
853
848
build,
854
849
docBuildOpt,
855
850
workingDir,
856
851
now,
857
852
isIvy2LocalLike = repoParams.isIvy2LocalLike,
858
853
isCi = isCi,
859
- isSonatype = isSonatype ,
854
+ isSonatype,
860
855
logger
861
856
)
862
857
}
@@ -1024,23 +1019,24 @@ object Publish extends ScalaCommand[PublishOptions] with BuildCommandHelpers {
1024
1019
else fileSet2.order(ec).unsafeRun()(ec)
1025
1020
1026
1021
val isSnapshot0 = modVersionOpt.exists(_._2.endsWith(" SNAPSHOT" ))
1027
- val authOpt0 = value(authOpt(repoParams.repo.repo(isSnapshot0).root))
1022
+ val authOpt0 = value(authOpt(repoParams.repo.repo(isSnapshot0).root, isSonatype ))
1028
1023
if (repoParams.shouldAuthenticate && authOpt0.isEmpty)
1029
1024
logger.diagnostic(
1030
1025
" Publishing to a repository that needs authentication, but no credentials are available." ,
1031
1026
Severity .Warning
1032
1027
)
1033
- val repoParams0 = repoParams.withAuth(authOpt0)
1028
+ val repoParams0 : RepoParams = repoParams.withAuth(authOpt0)
1034
1029
val hooksDataOpt = Option .when(! dummy) {
1035
1030
try repoParams0.hooks.beforeUpload(finalFileSet, isSnapshot0).unsafeRun()(ec)
1036
1031
catch {
1037
1032
case NonFatal (e)
1038
- if " Failed to get .*/staging/profiles \\ (http status: 403," .r.unanchored.matches(
1033
+ if " Failed to get .*oss \\ .sonatype \\ .org.* /staging/profiles \\ (http status: 403," .r.unanchored.matches(
1039
1034
e.getMessage
1040
1035
) =>
1041
- logger.exit(new WrongSonatypeServerError )
1036
+ logger.exit(new WrongSonatypeServerError (
1037
+ repoParams0.repo.releaseRepo.root.contains(" s01" )))
1042
1038
case NonFatal (e)
1043
- if " Failed to get .*/staging/profiles \\ (http status: 401," .r.unanchored.matches(
1039
+ if " Failed to get .*oss \\ .sonatype \\ .org.* /staging/profiles \\ (http status: 401," .r.unanchored.matches(
1044
1040
e.getMessage
1045
1041
) =>
1046
1042
logger.exit(new InvalidPublishCredentials )
@@ -1049,15 +1045,6 @@ object Publish extends ScalaCommand[PublishOptions] with BuildCommandHelpers {
1049
1045
}
1050
1046
}
1051
1047
1052
- val isHttps = {
1053
- val uri = new URI (repoParams.repo.repo(isSnapshot0).root)
1054
- uri.getScheme == " https"
1055
- }
1056
- val hostOpt = Option .when(isHttps)(new URI (repoParams.repo.repo(isSnapshot0).root).getHost)
1057
-
1058
- val isSonatype =
1059
- hostOpt.exists(host => host == " oss.sonatype.org" || host.endsWith(" .oss.sonatype.org" ))
1060
-
1061
1048
val retainedRepo = hooksDataOpt match {
1062
1049
case None => // dummy mode
1063
1050
repoParams0.repo.repo(isSnapshot0)
0 commit comments