Skip to content

Commit f23fda8

Browse files
authored
NIT Fix miscellaneous warnings (#3913)
* NIT Fix miscellaneous warnings * Update modules/cli/src/main/scala/scala/cli/commands/repl/Repl.scala * Update modules/cli/src/main/scala/scala/cli/commands/publish/Ivy.scala
1 parent 916a4c8 commit f23fda8

File tree

53 files changed

+464
-367
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

53 files changed

+464
-367
lines changed

build.mill.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -917,7 +917,7 @@ trait Cli extends CrossSbtModule with ProtoBuildModule with CliLaunchers
917917
}
918918

919919
override def scalacOptions: T[Seq[String]] = Task {
920-
super.scalacOptions() ++ asyncScalacOptions(crossScalaVersion)
920+
super.scalacOptions() ++ asyncScalacOptions(crossScalaVersion) ++ Seq("-deprecation")
921921
}
922922
override def javacOptions: T[Seq[String]] = Task {
923923
super.javacOptions() ++ Seq("--release", "16")

modules/build/src/main/java/scala/build/internal/Chdir.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package scala.build.internal;
22

3-
import coursier.jvm.ErrnoException;
3+
import coursier.exec.ErrnoException;
44

55
public final class Chdir {
66

modules/build/src/main/java/scala/build/internal/ChdirGraalvm.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
import com.oracle.svm.core.annotate.Substitute;
66
import com.oracle.svm.core.annotate.TargetClass;
77
import com.oracle.svm.core.headers.LibC;
8-
import coursier.jvm.ErrnoException;
9-
import coursier.jvm.GraalvmErrnoExtras;
8+
import coursier.exec.ErrnoException;
9+
import coursier.exec.GraalvmErrnoExtras;
1010
import org.graalvm.nativeimage.c.type.CTypeConversion;
1111
import org.graalvm.nativeimage.Platform;
1212
import org.graalvm.nativeimage.Platforms;

modules/build/src/main/scala/scala/build/Build.scala

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -909,7 +909,6 @@ object Build {
909909
sources: Sources,
910910
generatedSources: Seq[GeneratedSource],
911911
options: BuildOptions,
912-
compilerJvmVersionOpt: Option[Positioned[Int]],
913912
scope: Scope,
914913
logger: Logger,
915914
artifacts: Artifacts,
@@ -929,7 +928,13 @@ object Build {
929928

930929
val scalaCompilerParamsOpt = artifacts.scalaOpt match {
931930
case Some(scalaArtifacts) =>
932-
val params = value(options.scalaParams).getOrElse {
931+
val params = value {
932+
options.scalaParams match {
933+
case Left(buildException) if maybeRecoverOnError(buildException).isEmpty =>
934+
Right(None) // this will effectively try to fall back to a pure Java build
935+
case otherwise => otherwise
936+
}
937+
}.getOrElse {
933938
sys.error(
934939
"Should not happen (inconsistency between Scala parameters in BuildOptions and ScalaArtifacts)"
935940
)
@@ -1051,7 +1056,7 @@ object Build {
10511056
scalaCompiler = scalaCompilerParamsOpt,
10521057
scalaJsOptions =
10531058
if (options.platform.value == Platform.JS)
1054-
Some(value(options.scalaJsOptions.config(logger)))
1059+
Some(value(options.scalaJsOptions.config(logger, maybeRecoverOnError)))
10551060
else None,
10561061
scalaNativeOptions =
10571062
if (options.platform.value == Platform.Native)
@@ -1074,7 +1079,6 @@ object Build {
10741079
sources: Sources,
10751080
generatedSources: Seq[GeneratedSource],
10761081
options: BuildOptions,
1077-
compilerJvmVersionOpt: Option[Positioned[Int]],
10781082
scope: Scope,
10791083
compiler: ScalaCompiler,
10801084
logger: Logger,
@@ -1115,7 +1119,6 @@ object Build {
11151119
sources,
11161120
generatedSources,
11171121
options0,
1118-
compilerJvmVersionOpt,
11191122
scope,
11201123
logger,
11211124
artifacts,
@@ -1168,17 +1171,16 @@ object Build {
11681171
case Some(error) => value(Left(error))
11691172
}
11701173

1171-
val (classesDir0, scalaParams, artifacts, project, projectChanged) = value {
1174+
val (classesDir0, scalaParams, artifacts, project, _) = value {
11721175
prepareBuild(
1173-
inputs,
1174-
sources,
1175-
generatedSources,
1176-
options,
1177-
compiler.jvmVersion,
1178-
scope,
1179-
compiler,
1180-
logger,
1181-
buildClient
1176+
inputs = inputs,
1177+
sources = sources,
1178+
generatedSources = generatedSources,
1179+
options = options,
1180+
scope = scope,
1181+
compiler = compiler,
1182+
logger = logger,
1183+
buildClient = buildClient
11821184
)
11831185
}
11841186

modules/build/src/main/scala/scala/build/LocalRepo.scala

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ object LocalRepo {
5656
loader: ClassLoader = Thread.currentThread().getContextClassLoader
5757
): Option[String] = {
5858
val archiveUrl = loader.getResource(resourcePath)
59+
logger.debug(s"archive url: $archiveUrl")
5960

6061
if archiveUrl == null then None
6162
else {
@@ -70,13 +71,15 @@ object LocalRepo {
7071
}
7172

7273
val repoDir = baseDir / version
74+
logger.debug(s"repo dir: $repoDir")
7375

7476
if !os.exists(repoDir) then
7577
withLock((repoDir / os.up).toNIO, version) {
7678
// Post-lock validation: Recheck repository directory existence to handle
7779
// potential race conditions between initial check and lock acquisition
7880
if !os.exists(repoDir) then
7981
val tmpRepoDir = repoDir / os.up / s".$version.tmp"
82+
logger.debug(s"tmp repo dir: $tmpRepoDir")
8083
os.remove.all(tmpRepoDir)
8184
using(archiveUrl.openStream()) { is =>
8285
using(WrappedZipInputStream.create(new BufferedInputStream(is))) { zis =>
@@ -87,6 +90,7 @@ object LocalRepo {
8790
}
8891

8992
val repo = "ivy:" + repoDir.toNIO.toUri.toASCIIString + "/[defaultPattern]"
93+
logger.debug(s"local repo (ivy): $repo")
9094
Some(repo)
9195
}
9296
}

modules/build/src/main/scala/scala/build/ReplArtifacts.scala

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,6 @@ object ReplArtifacts {
4949
extraRepositories: Seq[Repository],
5050
logger: Logger,
5151
cache: FileCache[Task],
52-
directories: Directories,
5352
addScalapy: Option[String]
5453
): Either[BuildException, ReplArtifacts] = either {
5554
val scalapyDeps =

modules/build/src/main/scala/scala/build/ScalafixArtifacts.scala

Lines changed: 23 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,12 @@ import coursier.core.Repository
55
import coursier.util.Task
66
import dependency.*
77
import org.apache.commons.compress.archivers.zip.ZipFile
8-
import os.Path
98

10-
import java.io.ByteArrayInputStream
9+
import java.io.{ByteArrayInputStream, IOException}
1110
import java.util.Properties
1211

1312
import scala.build.EitherCps.{either, value}
14-
import scala.build.errors.BuildException
13+
import scala.build.errors.{BuildException, ScalafixPropertiesError}
1514
import scala.build.internal.Constants
1615
import scala.build.internal.CsLoggerUtil.*
1716

@@ -98,7 +97,7 @@ object ScalafixArtifacts {
9897
extraRepositories: Seq[Repository],
9998
logger: Logger,
10099
cache: FileCache[Task]
101-
): Either[BuildException, Path] =
100+
): Either[BuildException, os.Path] =
102101
either {
103102
val scalafixInterfaces = dep"ch.epfl.scala:scalafix-interfaces:${Constants.scalafixVersion}"
104103

@@ -123,22 +122,26 @@ object ScalafixArtifacts {
123122
)
124123
}
125124

126-
private def readScalafixProperties(jar: Path): Either[BuildException, String] = {
127-
import scala.jdk.CollectionConverters.*
128-
val zipFile = new ZipFile(jar.toNIO)
129-
val entry = zipFile.getEntries().asScala.find(entry =>
130-
entry.getName() == "scalafix-interfaces.properties"
131-
)
132-
val out =
133-
entry.toRight(new BuildException("Failed to found scalafix properties") {})
134-
.map { entry =>
135-
val stream = zipFile.getInputStream(entry)
136-
val bytes = stream.readAllBytes()
137-
new String(bytes)
138-
}
139-
zipFile.close()
140-
out
141-
}
125+
private def readScalafixProperties(jar: os.Path): Either[BuildException, String] =
126+
try {
127+
import scala.jdk.CollectionConverters.*
128+
val zipFile = ZipFile.builder().setPath(jar.toNIO).get()
129+
val entry = zipFile.getEntries().asScala.find(entry =>
130+
entry.getName == "scalafix-interfaces.properties"
131+
)
132+
val out =
133+
entry.toRight(new ScalafixPropertiesError(path = jar))
134+
.map { entry =>
135+
val stream = zipFile.getInputStream(entry)
136+
val bytes = stream.readAllBytes()
137+
new String(bytes)
138+
}
139+
zipFile.close()
140+
out
141+
}
142+
catch {
143+
case e: IOException => Left(new ScalafixPropertiesError(path = jar, cause = Some(e)))
144+
}
142145

143146
private def scalafixPropsKey(scalaVersion: String): Either[BuildException, String] = {
144147
val regex = "(\\d)\\.(\\d+).+".r

modules/build/src/main/scala/scala/build/bsp/BspImpl.scala

Lines changed: 18 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -155,32 +155,30 @@ final class BspImpl(
155155

156156
val (classesDir0Main, scalaParamsMain, artifactsMain, projectMain, buildChangedMain) = value {
157157
val res = Build.prepareBuild(
158-
allInputs,
159-
sourcesMain,
160-
generatedSourcesMain,
161-
options0Main,
162-
None,
163-
Scope.Main,
164-
currentBloopSession.remoteServer,
165-
persistentLogger,
166-
localClient,
167-
maybeRecoverOnError(Scope.Main)
158+
inputs = allInputs,
159+
sources = sourcesMain,
160+
generatedSources = generatedSourcesMain,
161+
options = options0Main,
162+
scope = Scope.Main,
163+
compiler = currentBloopSession.remoteServer,
164+
logger = persistentLogger,
165+
buildClient = localClient,
166+
maybeRecoverOnError = maybeRecoverOnError(Scope.Main)
168167
)
169168
res.left.map((_, Scope.Main))
170169
}
171170

172171
val (classesDir0Test, scalaParamsTest, artifactsTest, projectTest, buildChangedTest) = value {
173172
val res = Build.prepareBuild(
174-
allInputs,
175-
sourcesTest,
176-
generatedSourcesTest,
177-
options0Test,
178-
None,
179-
Scope.Test,
180-
currentBloopSession.remoteServer,
181-
persistentLogger,
182-
localClient,
183-
maybeRecoverOnError(Scope.Test)
173+
inputs = allInputs,
174+
sources = sourcesTest,
175+
generatedSources = generatedSourcesTest,
176+
options = options0Test,
177+
scope = Scope.Test,
178+
compiler = currentBloopSession.remoteServer,
179+
logger = persistentLogger,
180+
buildClient = localClient,
181+
maybeRecoverOnError = maybeRecoverOnError(Scope.Test)
184182
)
185183
res.left.map((_, Scope.Test))
186184
}

modules/build/src/main/scala/scala/build/bsp/BspServer.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ class BspServer(
2626
with JavaBuildServerForwardStubs
2727
with JvmBuildServerForwardStubs
2828
with HasGeneratedSourcesImpl {
29-
private var client: Option[BuildClient] = None
29+
private val client: Option[BuildClient] = None
3030

3131
@volatile private var intelliJ: Boolean = presetIntelliJ
3232
def isIntelliJ: Boolean = intelliJ

modules/build/src/main/scala/scala/build/bsp/BuildServerProxy.scala

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,10 +63,12 @@ class BuildServerProxy(
6363
override def buildTargetScalacOptions(params: b.ScalacOptionsParams)
6464
: CompletableFuture[b.ScalacOptionsResult] = bspServer().buildTargetScalacOptions(params)
6565

66+
@deprecated
6667
override def buildTargetScalaTestClasses(params: b.ScalaTestClassesParams)
6768
: CompletableFuture[b.ScalaTestClassesResult] =
6869
bspServer().buildTargetScalaTestClasses(params)
6970

71+
@deprecated
7072
override def buildTargetScalaMainClasses(params: b.ScalaMainClassesParams)
7173
: CompletableFuture[b.ScalaMainClassesResult] =
7274
bspServer().buildTargetScalaMainClasses(params)

0 commit comments

Comments
 (0)