Skip to content

Commit 6ce00ad

Browse files
Merge pull request #1057 from alexarchambault/tweaking
Tweaking
2 parents 8381e63 + bb114d3 commit 6ce00ad

File tree

18 files changed

+215
-68
lines changed

18 files changed

+215
-68
lines changed

build.sc

Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -146,9 +146,6 @@ object packager extends ScalaModule with Bloop.Module {
146146

147147
object `generate-reference-doc` extends SbtModule with ScalaCliScalafixModule {
148148
def scalaVersion = Scala.defaultInternal
149-
def scalacOptions = T {
150-
super.scalacOptions() ++ Seq("-Ywarn-unused")
151-
}
152149
def moduleDeps = Seq(
153150
cli
154151
)
@@ -867,28 +864,25 @@ trait CliIntegration extends SbtModule with ScalaCliPublishModule with HasTests
867864
launcherTask: T[PathRef],
868865
cliKind: String
869866
) {
870-
def doTest(args: String*) =
871-
T.command {
872-
val argsTask = T.task {
873-
val launcher = launcherTask().path
874-
val extraArgs = Seq(
875-
s"-Dtest.scala-cli.path=$launcher",
876-
s"-Dtest.scala-cli.kind=$cliKind"
877-
)
878-
args ++ extraArgs
879-
}
880-
testTask(argsTask, T.task(Seq.empty[String]))
867+
def test(args: String*) = {
868+
val argsTask = T.task {
869+
val launcher = launcherTask().path
870+
val extraArgs = Seq(
871+
s"-Dtest.scala-cli.path=$launcher",
872+
s"-Dtest.scala-cli.kind=$cliKind"
873+
)
874+
args ++ extraArgs
881875
}
882-
def test(args: String*) =
883876
T.command {
884-
val res = doTest(args: _*)()
877+
val res = testTask(argsTask, T.task(Seq.empty[String]))()
885878
val dotScalaInRoot = os.pwd / workspaceDirName
886879
assert(
887880
!os.isDir(dotScalaInRoot),
888881
s"Expected $workspaceDirName ($dotScalaInRoot) not to have been created"
889882
)
890883
res
891884
}
885+
}
892886
}
893887

894888
def test(args: String*) =

modules/cli-options/src/main/scala/scala/cli/commands/publish/PublishOptions.scala

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,11 @@ final case class PublishOptions(
2323

2424
@Group("Publishing")
2525
@Hidden
26-
ivy2LocalLike: Option[Boolean] = None
26+
ivy2LocalLike: Option[Boolean] = None,
27+
28+
@Group("Publishing")
29+
@Hidden
30+
parallelUpload: Option[Boolean] = None
2731
)
2832
// format: on
2933

modules/cli-options/src/main/scala/scala/cli/commands/publish/PublishRepositoryOptions.scala

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,12 @@ final case class PublishRepositoryOptions(
2323
@Group("Publishing")
2424
@HelpMessage("Password to use with publishing repository")
2525
@ValueDescription("value:…")
26-
password: Option[PasswordOption] = None
26+
password: Option[PasswordOption] = None,
27+
28+
@Group("Publishing")
29+
@HelpMessage("Realm to use when passing credentials to publishing repository")
30+
@ValueDescription("realm")
31+
realm: Option[String] = None
2732

2833
)
2934
// format: on

modules/cli-options/src/main/scala/scala/cli/commands/publish/SharedPublishOptions.scala

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,11 @@ final case class SharedPublishOptions(
5656

5757
@Group("Publishing")
5858
@Hidden
59-
forceSigningBinary: Boolean = false
59+
forceSigningBinary: Boolean = false,
6060

61+
@Group("Publishing")
62+
@Hidden
63+
checksum: List[String] = Nil
6164
)
6265
// format: on
6366

modules/cli/src/main/scala/scala/cli/commands/Doc.scala

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -87,15 +87,12 @@ object Doc extends ScalaCommand[DocOptions] {
8787

8888
alreadyExistsCheck()
8989

90-
val outputPath = {
91-
val docJarPath = value(generateScaladocDirPath(build, logger, extraArgs))
92-
alreadyExistsCheck()
93-
if (force) os.copy.over(docJarPath, destPath)
94-
else os.copy(docJarPath, destPath)
95-
destPath
96-
}
90+
val docJarPath = value(generateScaladocDirPath(build, logger, extraArgs))
91+
alreadyExistsCheck()
92+
if (force) os.copy.over(docJarPath, destPath)
93+
else os.copy(docJarPath, destPath)
9794

98-
val printableOutput = CommandUtils.printablePath(outputPath)
95+
val printableOutput = CommandUtils.printablePath(destPath)
9996

10097
logger.message(s"Wrote Scaladoc to $printableOutput")
10198
}
@@ -178,7 +175,7 @@ object Doc extends ScalaCommand[DocOptions] {
178175
"-d",
179176
destDir.toString,
180177
"-classpath",
181-
build.project.classesDir.toString
178+
build.fullClassPath.map(_.toString).mkString(File.pathSeparator)
182179
) ++
183180
javaSources.map(_.toString)
184181
val retCode = Runner.run(

modules/cli/src/main/scala/scala/cli/commands/Run.scala

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,6 @@ object Run extends ScalaCommand[RunOptions] {
6767
allowTerminate: Boolean
6868
): Either[BuildException, (Process, CompletableFuture[_])] = either {
6969
val process = value(maybeRunOnce(
70-
inputs.workspace,
71-
inputs.projectName,
7270
build,
7371
programArgs,
7472
logger,
@@ -166,8 +164,6 @@ object Run extends ScalaCommand[RunOptions] {
166164
}
167165

168166
private def maybeRunOnce(
169-
root: os.Path,
170-
projectName: String,
171167
build: Build.Successful,
172168
args: Seq[String],
173169
logger: Logger,
@@ -190,8 +186,6 @@ object Run extends ScalaCommand[RunOptions] {
190186
if (jvmRunner) (Constants.runnerMainClass, mainClass +: verbosity +: args)
191187
else (mainClass, args)
192188
val res = runOnce(
193-
root,
194-
projectName,
195189
build,
196190
finalMainClass,
197191
finalArgs,
@@ -202,8 +196,6 @@ object Run extends ScalaCommand[RunOptions] {
202196
}
203197

204198
private def runOnce(
205-
root: os.Path,
206-
projectName: String,
207199
build: Build.Successful,
208200
mainClass: String,
209201
args: Seq[String],

modules/cli/src/main/scala/scala/cli/commands/Test.scala

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -84,8 +84,6 @@ object Test extends ScalaCommand[TestOptions] {
8484
System.err.println()
8585
}
8686
val retCodeOrError = testOnce(
87-
inputs.workspace,
88-
inputs.projectName,
8987
s,
9088
options.requireTests,
9189
args.unparsed,
@@ -155,8 +153,6 @@ object Test extends ScalaCommand[TestOptions] {
155153
}
156154

157155
private def testOnce(
158-
root: os.Path,
159-
projectName: String,
160156
build: Build.Successful,
161157
requireTests: Boolean,
162158
args: Seq[String],

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

Lines changed: 49 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,12 @@ import scala.cli.commands.{
4343
SharedOptions,
4444
WatchUtil
4545
}
46-
import scala.cli.errors.{FailedToSignFileError, MissingPublishOptionError, UploadError}
46+
import scala.cli.errors.{
47+
FailedToSignFileError,
48+
MalformedChecksumsError,
49+
MissingPublishOptionError,
50+
UploadError
51+
}
4752
import scala.cli.packaging.Library
4853
import scala.cli.publish.BouncycastleSignerMaker
4954

@@ -111,6 +116,7 @@ object Publish extends ScalaCommand[PublishOptions] {
111116
secretKeyPassword = publishParams.secretKeyPassword,
112117
repoUser = publishRepo.user,
113118
repoPassword = publishRepo.password,
119+
repoRealm = publishRepo.realm,
114120
signer = value {
115121
sharedPublish.signer
116122
.map(Positioned.commandLine(_))
@@ -122,6 +128,11 @@ object Publish extends ScalaCommand[PublishOptions] {
122128
.map(Positioned.commandLine(_))
123129
.map(ComputeVersion.parse(_))
124130
.sequence
131+
},
132+
checksums = {
133+
val input = sharedPublish.checksum.flatMap(_.split(",")).map(_.trim).filter(_.nonEmpty)
134+
if (input.isEmpty) None
135+
else Some(input)
125136
}
126137
)
127138
)
@@ -176,6 +187,7 @@ object Publish extends ScalaCommand[PublishOptions] {
176187
ivy2HomeOpt,
177188
publishLocal = false,
178189
forceSigningBinary = options.sharedPublish.forceSigningBinary,
190+
parallelUpload = options.parallelUpload.getOrElse(true),
179191
options.watch.watch
180192
)
181193
}
@@ -191,6 +203,7 @@ object Publish extends ScalaCommand[PublishOptions] {
191203
ivy2HomeOpt: Option[os.Path],
192204
publishLocal: Boolean,
193205
forceSigningBinary: Boolean,
206+
parallelUpload: Boolean,
194207
watch: Boolean
195208
): Unit = {
196209

@@ -214,7 +227,8 @@ object Publish extends ScalaCommand[PublishOptions] {
214227
publishLocal,
215228
logger,
216229
allowExit = false,
217-
forceSigningBinary = forceSigningBinary
230+
forceSigningBinary = forceSigningBinary,
231+
parallelUpload = parallelUpload
218232
)
219233
}
220234
}
@@ -240,7 +254,8 @@ object Publish extends ScalaCommand[PublishOptions] {
240254
publishLocal,
241255
logger,
242256
allowExit = true,
243-
forceSigningBinary = forceSigningBinary
257+
forceSigningBinary = forceSigningBinary,
258+
parallelUpload = parallelUpload
244259
)
245260
}
246261
}
@@ -259,7 +274,8 @@ object Publish extends ScalaCommand[PublishOptions] {
259274
publishLocal: Boolean,
260275
logger: Logger,
261276
allowExit: Boolean,
262-
forceSigningBinary: Boolean
277+
forceSigningBinary: Boolean,
278+
parallelUpload: Boolean
263279
): Unit = {
264280

265281
val allOk = builds.all.forall {
@@ -286,7 +302,8 @@ object Publish extends ScalaCommand[PublishOptions] {
286302
ivy2HomeOpt,
287303
publishLocal,
288304
logger,
289-
forceSigningBinary
305+
forceSigningBinary,
306+
parallelUpload
290307
)
291308
if (allowExit)
292309
res.orExit(logger)
@@ -526,7 +543,8 @@ object Publish extends ScalaCommand[PublishOptions] {
526543
ivy2HomeOpt: Option[os.Path],
527544
publishLocal: Boolean,
528545
logger: Logger,
529-
forceSigningBinary: Boolean
546+
forceSigningBinary: Boolean,
547+
parallelUpload: Boolean
530548
): Either[BuildException, Unit] = either {
531549

532550
assert(docBuilds.isEmpty || docBuilds.length == builds.length)
@@ -548,10 +566,12 @@ object Publish extends ScalaCommand[PublishOptions] {
548566
Executors.newSingleThreadScheduledExecutor(Util.daemonThreadFactory("publish-retry"))
549567

550568
lazy val authOpt = {
551-
val userOpt = publishOptions.repoUser
552569
val passwordOpt = publishOptions.repoPassword.map(_.get())
553570
passwordOpt.map { password =>
554-
Authentication(userOpt.fold("")(_.get().value), password.value)
571+
val userOpt = publishOptions.repoUser
572+
val realmOpt = publishOptions.repoRealm
573+
val auth = Authentication(userOpt.fold("")(_.get().value), password.value)
574+
realmOpt.fold(auth)(auth.withRealm)
555575
}
556576
}
557577

@@ -613,6 +633,7 @@ object Publish extends ScalaCommand[PublishOptions] {
613633
else os.Path(repoStr, Os.pwd).toNIO.toUri.toASCIIString
614634
MavenRepository(url)
615635
}
636+
.withAuthentication(authOpt)
616637
(
617638
PublishRepository.Simple(repo0),
618639
None,
@@ -689,7 +710,8 @@ object Publish extends ScalaCommand[PublishOptions] {
689710
)
690711
case None => NopSigner
691712
}
692-
case None => NopSigner
713+
case Some(PSigner.Nop) => NopSigner
714+
case None => NopSigner
693715
}
694716
val signerLogger =
695717
new InteractiveSignerLogger(new OutputStreamWriter(System.err), verbosity = 1)
@@ -717,8 +739,19 @@ object Publish extends ScalaCommand[PublishOptions] {
717739

718740
val checksumLogger =
719741
new InteractiveChecksumLogger(new OutputStreamWriter(System.err), verbosity = 1)
742+
val checksumTypes = publishOptions.checksums match {
743+
case None => Seq(ChecksumType.MD5, ChecksumType.SHA1)
744+
case Some(Seq("none")) => Nil
745+
case Some(inputs) =>
746+
value {
747+
inputs
748+
.map(ChecksumType.parse)
749+
.sequence
750+
.left.map(errors => new MalformedChecksumsError(inputs, errors))
751+
}
752+
}
720753
val checksums = Checksums(
721-
Seq(ChecksumType.MD5, ChecksumType.SHA1),
754+
checksumTypes,
722755
fileSet1,
723756
now,
724757
ec,
@@ -747,7 +780,12 @@ object Publish extends ScalaCommand[PublishOptions] {
747780
val uploadLogger = InteractiveUploadLogger.create(System.err, dummy = dummy, isLocal = isLocal)
748781

749782
val errors =
750-
upload.uploadFileSet(retainedRepo, finalFileSet, uploadLogger, Some(ec)).unsafeRun()(ec)
783+
upload.uploadFileSet(
784+
retainedRepo,
785+
finalFileSet,
786+
uploadLogger,
787+
if (parallelUpload) Some(ec) else None
788+
).unsafeRun()(ec)
751789

752790
errors.toList match {
753791
case h :: t =>

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ object PublishLocal extends ScalaCommand[PublishLocalOptions] {
6666
ivy2HomeOpt,
6767
publishLocal = true,
6868
forceSigningBinary = options.sharedPublish.forceSigningBinary,
69+
parallelUpload = true,
6970
options.watch.watch
7071
)
7172
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
package scala.cli.errors
2+
3+
import scala.build.errors.BuildException
4+
5+
final class MalformedChecksumsError(input: Seq[String], errors: ::[String])
6+
extends BuildException(s"Malformed checksums: ${errors.mkString(", ")}")

modules/directives/src/main/scala/scala/build/preprocessing/directives/UsingPublishDirectiveHandler.scala

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,8 @@ case object UsingPublishDirectiveHandler extends UsingDirectiveHandler {
6161
"secretKey",
6262
"secretKeyPassword",
6363
"user",
64-
"password"
64+
"password",
65+
"realm"
6566
).map(prefix + _)
6667

6768
override def getValueNumberBounds(key: String) = key match {
@@ -148,6 +149,8 @@ case object UsingPublishDirectiveHandler extends UsingDirectiveHandler {
148149
PublishOptions(repoUser = Some(value(parsePasswordOption(singleValue.value))))
149150
case "password" =>
150151
PublishOptions(repoPassword = Some(value(parsePasswordOption(singleValue.value))))
152+
case "realm" =>
153+
PublishOptions(repoRealm = Some(singleValue.value))
151154
case _ =>
152155
value(Left(new UnexpectedDirectiveError(scopedDirective.directive.key)))
153156
}

modules/integration/src/test/scala/scala/cli/integration/DocTestDefinitions.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import com.eed3si9n.expecty.Expecty.expect
55
abstract class DocTestDefinitions(val scalaVersionOpt: Option[String])
66
extends munit.FunSuite with TestScalaVersionArgs {
77

8-
private lazy val extraOptions = scalaVersionArgs ++ TestUtil.extraOptions
8+
protected lazy val extraOptions = scalaVersionArgs ++ TestUtil.extraOptions
99

1010
test("generate static scala doc") {
1111
val dest = os.rel / "doc-static"

0 commit comments

Comments
 (0)