Skip to content

Commit

Permalink
Clean compile warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
Friendseeker committed Oct 18, 2024
1 parent a6b5a49 commit 5a41ce6
Show file tree
Hide file tree
Showing 20 changed files with 88 additions and 59 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ private[xsbt] object ZincBenchmark {
| // Resolve project dynamically to avoid name clashes/overloading
| val project = LocalProject("$sbtProject")
| Def.task {
| val file = new File("${outputFile.getAbsolutePath.replaceAllLiterally("\\", "/")}")
| val file = new File("${outputFile.getAbsolutePath.replace("\\", "/")}")
| val rawSources = (sources in Compile in project).value
| val sourcesLine = rawSources.map(_.getCanonicalPath).mkString(" ")
| val rawClasspath = (dependencyClasspath in Compile in project).value
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,8 @@ final class AnalyzingCompiler(
log: xLogger
): Unit = {
val progress = if (progressOpt.isPresent) progressOpt.get else IgnoreProgress
val cp = classpath.map(converter.toPath)
val arguments = compArgs.makeArguments(Nil, cp, options).toArray
val cp = classpath.map(converter.toPath).toIndexedSeq
val arguments = compArgs.makeArguments(Nil, cp, options.toIndexedSeq).toArray
// hold reference to compiler bridge class loader to prevent its being evicted
// from the compiler cache (sbt/zinc#914)
val loader = getCompilerLoader(log)
Expand Down Expand Up @@ -454,7 +454,7 @@ object AnalyzingCompiler {
val scalaLibraryJars = compiler.scalaInstance.libraryJars
val restClasspath = xsbtiJars.toSeq ++ sourceJars
val classpath = scalaLibraryJars.map(_.toPath) ++ restClasspath
compiler(sourceFiles, classpath, outputDirectory.toPath, "-nowarn" :: Nil)
compiler(sourceFiles, classpath.toIndexedSeq, outputDirectory.toPath, "-nowarn" :: Nil)

val end = (System.currentTimeMillis - start) / 1000.0
log.info(s" Compilation completed in ${end}s.")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,11 @@ class FilteredReporter(
filters.exists(f => f(value).booleanValue())

severity != Severity.Error && (
(pos.sourceFile.isPresent && isFiltered(fileFilters, pos.sourceFile.get.toPath)) ||
(isFiltered(msgFilters, msg))
(pos.sourceFile.isPresent && isFiltered(
fileFilters.toIndexedSeq,
pos.sourceFile.get.toPath
)) ||
(isFiltered(msgFilters.toIndexedSeq, msg))
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,15 @@ final class ForkedJavaCompiler(javaHome: Option[Path]) extends XJavaCompiler {
reporter: Reporter,
log: XLogger
): Boolean =
ForkedJava.launch(javaHome, "javac", sources, options, output, log, reporter)
ForkedJava.launch(
javaHome,
"javac",
sources.toIndexedSeq,
options.toIndexedSeq,
output,
log,
reporter,
)
}
final class ForkedJavadoc(javaHome: Option[Path]) extends XJavadoc {
def run(
Expand All @@ -111,5 +119,13 @@ final class ForkedJavadoc(javaHome: Option[Path]) extends XJavadoc {
reporter: Reporter,
log: XLogger
): Boolean =
ForkedJava.launch(javaHome, "javadoc", sources, options, output, log, reporter)
ForkedJava.launch(
javaHome,
"javadoc",
sources.toIndexedSeq,
options.toIndexedSeq,
output,
log,
reporter,
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,6 @@ object LocalJava {
): Int = {
(javadocTool, standardDocletClass) match {
case (Some(m), Some(clz)) =>
import scala.collection.JavaConverters._
val task = m.getTask(
out,
null,
Expand Down Expand Up @@ -290,7 +289,6 @@ final class LocalJavaCompiler(compiler: javax.tools.JavaCompiler) extends XJavaC
log0: XLogger
): Boolean = {
val log: Logger = log0
import collection.JavaConverters._
val logger = new LoggerWriter(log)
val logWriter = new PrintWriter(logger)
log.debug("Attempting to call " + compiler + " directly...")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,6 @@ final case class TraitPrivateMembersModified(modified: String) extends APIChange
final case class ModifiedNames(names: Set[UsedName]) {
def in(scope: UseScope): Set[UsedName] = names.filter(_.scopes.contains(scope))

import collection.JavaConverters._
private lazy val lookupMap: Set[(String, UseScope)] =
names.flatMap(n => n.scopes.asScala.map(n.name -> _))

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ sealed trait FileValueCache[T] {
object FileValueCache {
def apply[T](f: Path => T): FileValueCache[T] = make(Stamper.forLastModifiedP)(f)
def make[T](stamp: Path => XStamp)(f: Path => T): FileValueCache[T] =
new FileValueCache0[T](stamp, f)
new FileValueCache0[T](stamp, f)(Equiv.universal)
}

private[this] final class FileValueCache0[T](getStamp: Path => XStamp, make: Path => T)(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ object Incremental {
earlyOutput,
progress,
log
)
)(Equiv.universal)
} catch {
case _: xsbti.CompileCancelled =>
log.info("Compilation has been cancelled")
Expand Down Expand Up @@ -371,7 +371,7 @@ object Incremental {
)
}
}
val pickleJava = isPickleJava(scalacOptions)
val pickleJava = isPickleJava(scalacOptions.toIndexedSeq)
val hasModified = initialInvClasses.nonEmpty || initialInvSources0.nonEmpty
if (javaSources.nonEmpty && earlyOutput.isDefined && !pickleJava) {
log.warn(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ object Locate {
}
}
def find[S](name: String, gets: Stream[String => Either[Boolean, S]]): Either[Boolean, S] =
find[S](name, gets.toIterator)
find[S](name, gets.iterator)

/**
* Returns a function that searches the provided class path for
Expand Down Expand Up @@ -148,6 +148,6 @@ object Locate {
def components(className: String): (Seq[String], String) = {
assume(!className.isEmpty)
val parts = className.split("\\.")
if (parts.length == 1) (Nil, parts(0)) else (parts.init, parts.last)
if (parts.length == 1) (Nil, parts(0)) else (parts.init.toIndexedSeq, parts.last)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,17 @@ object SourceInfos {
): SourceInfo =
new UnderlyingSourceInfo(reported, unreported, mainClasses)

def merge(infos: Traversable[SourceInfos]): SourceInfos =
def merge(infos: Iterable[SourceInfos]): SourceInfos =
infos.foldLeft(SourceInfos.empty)(_ ++ _)

def merge1(info1: SourceInfo, info2: SourceInfo) = {
makeInfo(
mergeProblems(info1.getReportedProblems, info2.getReportedProblems),
mergeProblems(info1.getUnreportedProblems, info2.getUnreportedProblems),
(info1.getMainClasses ++ info2.getMainClasses).distinct,
mergeProblems(info1.getReportedProblems.toIndexedSeq, info2.getReportedProblems.toIndexedSeq),
mergeProblems(
info1.getUnreportedProblems.toIndexedSeq,
info2.getUnreportedProblems.toIndexedSeq,
),
(info1.getMainClasses ++ info2.getMainClasses).distinct.toIndexedSeq,
)
}

Expand Down Expand Up @@ -98,8 +101,8 @@ private final class MSourceInfos(val allInfos: Map[VirtualFileRef, SourceInfo])
allInfos.getOrElse(file, SourceInfos.emptyInfo)

override def getAllSourceInfos: java.util.Map[VirtualFileRef, SourceInfo] = {
import scala.collection.JavaConverters.mapAsJavaMapConverter
mapAsJavaMapConverter(allInfos).asJava
import scala.collection.JavaConverters._
allInfos.asJava
}
}

Expand Down
18 changes: 7 additions & 11 deletions internal/zinc-core/src/main/scala/sbt/internal/inc/Stamp.scala
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import xsbti.{ FileConverter, VirtualFile, VirtualFileRef }
import xsbti.compile.analysis.{ ReadStamps, Stamp => XStamp }

import scala.collection.immutable.TreeMap
import scala.collection.JavaConverters._
import scala.util.matching.Regex

/**
Expand Down Expand Up @@ -240,8 +241,7 @@ object Stamper {
cache: collection.concurrent.Map[VirtualFileRef, (Long, XStamp)],
converter: FileConverter,
getStamp: VirtualFileRef => XStamp
): VirtualFileRef => XStamp = { key: VirtualFileRef =>
import scala.collection.JavaConverters._
): VirtualFileRef => XStamp = { (key: VirtualFileRef) =>
val p = converter.toPath(key)
val ts =
try IO.getModifiedTimeOrZero(p.toFile)
Expand Down Expand Up @@ -311,7 +311,7 @@ object Stamps {
): Stamps =
new MStamps(products, sources, libraries)

def merge(stamps: Traversable[Stamps]): Stamps = stamps.foldLeft(Stamps.empty)(_ ++ _)
def merge(stamps: Iterable[Stamps]): Stamps = stamps.foldLeft(Stamps.empty)(_ ++ _)
}

private class MStamps(
Expand All @@ -320,13 +320,12 @@ private class MStamps(
val libraries: Map[VirtualFileRef, XStamp]
) extends Stamps {

import scala.collection.JavaConverters.mapAsJavaMapConverter
override def getAllLibraryStamps: util.Map[VirtualFileRef, XStamp] =
mapAsJavaMapConverter(libraries).asJava
libraries.asJava
override def getAllProductStamps: util.Map[VirtualFileRef, XStamp] =
mapAsJavaMapConverter(products).asJava
products.asJava
override def getAllSourceStamps: util.Map[VirtualFileRef, XStamp] =
mapAsJavaMapConverter(sources).asJava
sources.asJava

def allSources: collection.Set[VirtualFileRef] = sources.keySet
def allLibraries: collection.Set[VirtualFileRef] = libraries.keySet
Expand Down Expand Up @@ -407,7 +406,6 @@ private class InitialStamps(
) extends ReadStamps {
import collection.concurrent.Map
import java.util.concurrent.ConcurrentHashMap
import scala.collection.JavaConverters._

// cached stamps for files that do not change during compilation
private val libraries: Map[VirtualFileRef, XStamp] = new ConcurrentHashMap().asScala
Expand All @@ -431,7 +429,6 @@ private class TimeWrapBinaryStamps(
) extends ReadStamps {
import collection.concurrent.Map
import java.util.concurrent.ConcurrentHashMap
import scala.collection.JavaConverters._

// cached stamps for files that do not change during compilation
private val libraries: Map[VirtualFileRef, (Long, XStamp)] = new ConcurrentHashMap().asScala
Expand Down Expand Up @@ -460,8 +457,7 @@ private class UncachedStamps(
libStamp: VirtualFileRef => XStamp
) extends ReadStamps {
import VirtualFileUtil._
import scala.collection.JavaConverters.mapAsJavaMapConverter
val eSt = mapAsJavaMapConverter(TreeMap.empty[VirtualFileRef, XStamp]).asJava
val eSt = TreeMap.empty[VirtualFileRef, XStamp].asJava

override def getAllLibraryStamps: util.Map[VirtualFileRef, XStamp] = eSt
override def getAllSourceStamps: util.Map[VirtualFileRef, XStamp] = eSt
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ object UsedName {

private def escapeControlChars(name: String) = {
if (name.indexOf('\n') > 0) // optimize for common case to regex overhead
name.replaceAllLiterally("\n", "\u26680A")
name.replace("\n", "\u26680A")
else
name
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -273,8 +273,8 @@ class ConsistentAnalysisFormat(val mappers: ReadWriteMappers, sort: Boolean) {
) {
val file = readMapper.mapSourceFile(VirtualFileRef.of(in.string()))
val mainClasses = in.readStringSeq()
val reportedProblems = in.readArray()(readProblem())
val unreportedProblems = in.readArray()(readProblem())
val reportedProblems = in.readArray()(readProblem()).toIndexedSeq
val unreportedProblems = in.readArray()(readProblem()).toIndexedSeq
val info = SourceInfos.makeInfo(reportedProblems, unreportedProblems, mainClasses)
(file, info)
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -484,9 +484,21 @@ class TextAnalysisFormat(val mappers: ReadWriteMappers)
.map(fh => fh.withFile(writeMapper.mapClasspathEntry(fh.file)))
writeSeq(out)(Headers.outputMode, mode :: Nil, identity[String])
writeMap(out)(Headers.outputDir, outputAsMap, sourceDirMapper.write, outputDirMapper.write)
writeSeq(out)(Headers.classpathHash, mappedClasspathHash, fileHashToString)
writeSeq(out)(Headers.compileOptions, setup.options.scalacOptions, soptionsMapper.write)
writeSeq(out)(Headers.javacOptions, setup.options.javacOptions, joptionsMapper.write)
writeSeq(out)(
Headers.classpathHash,
mappedClasspathHash.toIndexedSeq,
fileHashToString
)
writeSeq(out)(
Headers.compileOptions,
setup.options.scalacOptions.toIndexedSeq,
soptionsMapper.write
)
writeSeq(out)(
Headers.javacOptions,
setup.options.javacOptions.toIndexedSeq,
joptionsMapper.write
)
writeSeq(out)(Headers.compilerVersion, setup.compilerVersion :: Nil, identity[String])
writeSeq(out)(Headers.compileOrder, setup.order.name :: Nil, identity[String])
writeSeq(out)(Headers.skipApiStoring, setup.storeApis() :: Nil, (b: Boolean) => b.toString)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ object AnalysisGenerators {
private[this] def lzy[T <: AnyRef](x: T) = SafeLazyProxy.strict(x)

def genNameHash(name: String): Gen[NameHash] =
for (scope <- oneOf(UseScope.values()))
for (scope <- oneOf(UseScope.values().toIndexedSeq))
yield NameHash.of(name, scope, (name, scope).hashCode())

def genClass(name: String): Gen[AnalyzedClass] =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -515,7 +515,7 @@ case class ProjectStructure(
case Seq(mainClassName) =>
val jars = i.si.allJars.map(_.toPath)
val cp = (jars ++ (unmanagedJars :+ output) ++ internalClasspath).map(_.toAbsolutePath)
val loader = ClasspathUtil.makeLoader(cp, i.si, baseDirectory)
val loader = ClasspathUtil.makeLoader(cp.toIndexedSeq, i.si, baseDirectory)
val buffer = new ByteArrayOutputStream(8192)
val oldOut = System.out
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,15 +58,15 @@ class IncrementalCompilerImpl extends IncrementalCompiler {
compileIncrementally(
scalac,
javacChosen,
sources,
classpath,
sources.toIndexedSeq,
classpath.toIndexedSeq,
CompileOutput(classesDirectory),
earlyOutput.toOption,
earlyAnalysisStore.toOption,
cache,
progress().toOption,
scalacOptions,
javacOptions,
scalacOptions.toIndexedSeq,
javacOptions.toIndexedSeq,
in.previousResult.analysis.toOption,
in.previousResult.setup.toOption,
perClasspathEntryLookup,
Expand Down Expand Up @@ -113,15 +113,15 @@ class IncrementalCompilerImpl extends IncrementalCompiler {
compileIncrementally(
scalac,
javacChosen,
sources,
classpath,
sources.toIndexedSeq,
classpath.toIndexedSeq,
CompileOutput(classesDirectory),
earlyOutput.toOption,
earlyAnalysisStore.toOption,
cache,
progress().toOption,
scalacOptions,
javacOptions,
scalacOptions.toIndexedSeq,
javacOptions.toIndexedSeq,
in.previousResult.analysis.toOption,
in.previousResult.setup.toOption,
perClasspathEntryLookup,
Expand Down Expand Up @@ -295,7 +295,7 @@ class IncrementalCompilerImpl extends IncrementalCompiler {
compileIncrementally(
scalaCompiler,
javaCompiler,
vs,
vs.toIndexedSeq,
cp,
output,
earlyOutput.toOption,
Expand Down
Loading

0 comments on commit 5a41ce6

Please sign in to comment.