Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[2.x] use CollectionConverters instead of deprecated JavaConverters #1414

Merged
merged 1 commit into from
Oct 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ package inc

import verify._
import sbt.io.IO.withTemporaryDirectory
import scala.collection.JavaConverters._
import scala.jdk.CollectionConverters._

/** This is a basic test for compiler bridge, mostly wrapped as
* AnalyzingCompiler.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class ExtractUsedNamesPerformanceSpecification
catch {
case _: FileSystemNotFoundException =>
val env = Map("create" -> "true")
import scala.collection.JavaConverters._
import scala.jdk.CollectionConverters._
Option(FileSystems.newFileSystem(uri, env.asJava))
case _: IllegalArgumentException =>
Option(FileSystems.getDefault)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import java.nio.file.Path

import sbt.internal.inc.zip.ZipCentralDir

import scala.collection.JavaConverters._
import scala.jdk.CollectionConverters._
import scala.collection.immutable.Seq

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package classfile

import java.nio.file._
import java.nio.file.spi.FileSystemProvider
import scala.collection.JavaConverters._
import scala.jdk.CollectionConverters._

class IndexBasedZipFsOpsSpec extends UnitSpec {
private val XL = 0xffff // minimum size to be zip64, which I'm calling "XL"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import xsbti.{ AnalysisCallback, BasicVirtualFileRef, TestCallback, VirtualFile,
import xsbti.TestCallback.ExtractedClassDependencies
import xsbti.compile.SingleOutput

import scala.collection.JavaConverters._
import scala.jdk.CollectionConverters._

object JavaCompilerForUnitTesting {
private class TestVirtualFile(p: Path) extends BasicVirtualFileRef(p.toString) with VirtualFile {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ final class ClasspathFilter(parent: ClassLoader, root: ClassLoader, classpath: S
}

override def getResources(name: String): java.util.Enumeration[URL] = {
import scala.collection.JavaConverters._
import scala.jdk.CollectionConverters._
val us = super.getResources(name)
if (us ne null) us.asScala.filter(onClasspath).asJavaEnumeration else null
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,7 @@ final class AnalyzingCompiler(

// see https://docs.oracle.com/javase/8/docs/api/java/util/ServiceLoader.html
private def loadService[A](cls: Class[A], loader: ClassLoader): Option[A] = {
import scala.collection.JavaConverters._
import scala.jdk.CollectionConverters._
val sl = ServiceLoader.load(cls, loader)
val list = sl.iterator.asScala.toList
list.lastOption
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ final class CompilerArguments(
*/
def createBootClasspath(addLibrary: Boolean): String = {
def findBoot: String = {
import scala.collection.JavaConverters._
import scala.jdk.CollectionConverters._
System.getProperties.asScala.iterator
.collectFirst {
case (k, v) if k.endsWith(".boot.class.path") => v
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ import javax.tools.{
import sbt.internal.util.LoggerWriter
import sbt.util.{ Level, Logger }

import scala.collection.JavaConverters._
import scala.jdk.CollectionConverters._
import scala.util.control.NonFatal
import xsbti.{ Reporter, Logger => XLogger, PathBasedFile, VirtualFile, VirtualFileRef }
import xsbti.compile.{
Expand Down Expand Up @@ -104,7 +104,7 @@ object LocalJava {
): Int = {
(javadocTool, standardDocletClass) match {
case (Some(m), Some(clz)) =>
import scala.collection.JavaConverters._
import scala.jdk.CollectionConverters._
val task = m.getTask(
out,
null,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import xsbti.VirtualFileRef
import scala.collection.immutable.Set

private[inc] class WrappedSet(s: java.util.Set[VirtualFileRef]) extends Set[VirtualFileRef] {
import scala.collection.JavaConverters._
import scala.jdk.CollectionConverters._
def iterator: Iterator[xsbti.VirtualFileRef] = s.asScala.iterator
def contains(elem: xsbti.VirtualFileRef): Boolean = s.contains(elem)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ package sbt
package internal
package inc

import scala.collection.JavaConverters._
import scala.jdk.CollectionConverters._

import xsbti.{ UseScope, VirtualFileRef }
import xsbti.api.NameHash
Expand Down Expand Up @@ -127,7 +127,7 @@ abstract class UnderlyingChanges[A] extends Changes[A] {
def changed: Set[A]
def unmodified: Set[A]

import scala.collection.JavaConverters.setAsJavaSetConverter
import scala.jdk.CollectionConverters._
override def getAdded: java.util.Set[A] = added.asJava
override def getChanged: java.util.Set[A] = changed.asJava
override def getRemoved: java.util.Set[A] = removed.asJava
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import sbt.internal.inc.JavaInterfaceUtil.EnrichOption
import sbt.util.{ InterfaceUtil, Level, Logger }
import sbt.util.InterfaceUtil.{ jl2l, jo2o, l2jl, t2 }

import scala.collection.JavaConverters._
import scala.jdk.CollectionConverters._
import scala.collection.mutable
import scala.util.control.NonFatal
import xsbti.{ FileConverter, Position, Problem, Severity, UseScope, VirtualFile, VirtualFileRef }
Expand Down Expand Up @@ -1010,7 +1010,7 @@ private final class AnalysisCallback(
}

def addProductsAndDeps(base: Analysis): Analysis = {
import scala.collection.JavaConverters._
import scala.jdk.CollectionConverters._
srcs.asScala.foldLeft(base) {
case (a, src) =>
val stamp = stampReader.source(src)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -528,7 +528,7 @@ private[inc] abstract class IncrementalCommon(
): (Set[String], Set[VirtualFileRef]) = {
def classNames(srcs: Set[VirtualFileRef]): Set[String] = srcs.flatMap(previous.classNames)
def toImmutableSet(srcs: java.util.Set[VirtualFileRef]): Set[VirtualFileRef] = {
import scala.collection.JavaConverters.asScalaIteratorConverter
import scala.jdk.CollectionConverters._
srcs.iterator().asScala.toSet
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import xsbti.compile.{ InitialChanges => XInitialChanges }
import xsbti.compile.{ InvalidationProfiler => XInvalidationProfiler }
import xsbti.compile.{ RunProfiler => XRunProfiler }

import scala.collection.JavaConverters._
import scala.jdk.CollectionConverters._
import scala.collection.mutable
import scala.collection.mutable.ArrayBuffer

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ trait Lookup extends ExternalLookup {
*/
trait ExternalLookup extends ExternalHooks.Lookup {
import sbt.internal.inc.JavaInterfaceUtil.EnrichOption
import scala.collection.JavaConverters._
import scala.jdk.CollectionConverters._

/**
* Find the external `AnalyzedClass` (from another analysis) given a class name and, if available,
Expand Down Expand Up @@ -130,7 +130,7 @@ trait ExternalLookup extends ExternalHooks.Lookup {
changedClasses: util.Set[String],
previousAnalysis: CompileAnalysis
): Boolean = {
import scala.collection.JavaConverters._
import scala.jdk.CollectionConverters._
shouldDoIncrementalCompilation(changedClasses.iterator().asScala.toSet, previousAnalysis)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ trait CompilationCache {
case class ProjectRebasedCache(remoteRoot: Path, cacheLocation: Path) extends CompilationCache {
override def loadCache(projectLocation: File): Option[(CompileAnalysis, MiniSetup)] = {
import JavaInterfaceUtil.EnrichOptional
import scala.collection.JavaConverters._
import scala.jdk.CollectionConverters._
val projectLocationPath = projectLocation.toPath
val readMapper = new RebaseReadWriteMapper(remoteRoot, projectLocationPath)
val writeMapper = new RebaseReadWriteMapper(projectLocationPath, remoteRoot)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import java.nio.file.{ Path, Paths }
import sbt.internal.inc.UsedName
import xsbti.{ UseScope, VirtualFileRef }
import xsbti.compile.analysis.Stamp
import scala.collection.JavaConverters._
import scala.jdk.CollectionConverters._

case class Mapper[V](read: String => V, write: V => String)
case class ContextAwareMapper[C, V](read: (C, String) => V, write: (C, V) => String)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -780,7 +780,7 @@ case class ProjectStructure(
}

def loadIncOptions(properties: Properties): (IncOptions, Array[String]) = {
import scala.collection.JavaConverters._
import scala.jdk.CollectionConverters._
val map = new java.util.HashMap[String, String]
properties.asScala foreach { case (k: String, v: String) => map.put(k, v) }
val base = IncOptions
Expand Down
2 changes: 1 addition & 1 deletion zinc/src/test/scala/sbt/inc/cached/CachedHashingSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import sbt.internal.inc.{
}
import sbt.io.IO

import scala.collection.JavaConverters.asScalaIteratorConverter
import scala.jdk.CollectionConverters._

class CachedHashingSpec extends BaseCompilerSpec {
lazy val isWindows: Boolean =
Expand Down