fix warnings

This commit is contained in:
xuwei-k 2024-10-05 07:14:07 +09:00
parent ddf3f5ef99
commit fdaa66202d
18 changed files with 69 additions and 50 deletions

View File

@ -44,7 +44,7 @@ object ConflictWarning {
/** Map from (organization, rawName) to set of multiple full names. */ /** Map from (organization, rawName) to set of multiple full names. */
def crossVersionMismatches(report: UpdateReport): Map[(String, String), Set[String]] = { def crossVersionMismatches(report: UpdateReport): Map[(String, String), Set[String]] = {
val mismatches = report.configurations.flatMap { confReport => val mismatches = report.configurations.flatMap { confReport =>
groupByRawName(confReport.allModules).mapValues { modules => groupByRawName(confReport.allModules).view.mapValues { modules =>
val differentFullNames = modules.map(_.name).toSet val differentFullNames = modules.map(_.name).toSet
if (differentFullNames.size > 1) differentFullNames else Set.empty[String] if (differentFullNames.size > 1) differentFullNames else Set.empty[String]
} }

View File

@ -186,8 +186,8 @@ class DependencyResolution private[sbt] (lmEngine: DependencyResolutionInterface
// The artifacts that came from Ivy don't have their classifier set, let's set it according to // The artifacts that came from Ivy don't have their classifier set, let's set it according to
// FIXME: this is only done because IDE plugins depend on `classifier` to determine type. They // FIXME: this is only done because IDE plugins depend on `classifier` to determine type. They
val typeClassifierMap: Map[String, String] = val typeClassifierMap: Map[String, String] =
((sourceArtifactTypes.toIterable map (_ -> Artifact.SourceClassifier)) ((sourceArtifactTypes.toSeq map (_ -> Artifact.SourceClassifier))
:: (docArtifactTypes.toIterable map (_ -> Artifact.DocClassifier)) :: Nil).flatten.toMap :: (docArtifactTypes.toSeq map (_ -> Artifact.DocClassifier)) :: Nil).flatten.toMap
Right(r.substitute { (conf, mid, artFileSeq) => Right(r.substitute { (conf, mid, artFileSeq) =>
artFileSeq map { case (art, f) => artFileSeq map { case (art, f) =>
// Deduce the classifier from the type if no classifier is present already // Deduce the classifier from the type if no classifier is present already

View File

@ -64,7 +64,7 @@ private[librarymanagement] abstract class ModuleIDExtra {
/** Returns the extra attributes except for ones marked as information only (ones that typically would not be used for dependency resolution). */ /** Returns the extra attributes except for ones marked as information only (ones that typically would not be used for dependency resolution). */
def extraDependencyAttributes: Map[String, String] = def extraDependencyAttributes: Map[String, String] =
extraAttributes.filterKeys(!_.startsWith(SbtPomExtraProperties.POM_INFO_KEY_PREFIX)).toMap extraAttributes.view.filterKeys(!_.startsWith(SbtPomExtraProperties.POM_INFO_KEY_PREFIX)).toMap
@deprecated( @deprecated(
"Use `cross(CrossVersion)`, the variant accepting a CrossVersion value constructed by a member of the CrossVersion object instead.", "Use `cross(CrossVersion)`, the variant accepting a CrossVersion value constructed by a member of the CrossVersion object instead.",

View File

@ -35,7 +35,7 @@ import org.apache.ivy.core.module.descriptor.DefaultArtifact
import org.apache.ivy.core.report.DownloadReport import org.apache.ivy.core.report.DownloadReport
import org.apache.ivy.plugins.resolver.util.{ ResolvedResource, ResourceMDParser } import org.apache.ivy.plugins.resolver.util.{ ResolvedResource, ResourceMDParser }
import org.apache.ivy.util.{ ChecksumHelper, FileUtil, Message } import org.apache.ivy.util.{ ChecksumHelper, FileUtil, Message }
import scala.collection.JavaConverters._ import scala.jdk.CollectionConverters._
import sbt.internal.librarymanagement.mavenint.PomExtraDependencyAttributes import sbt.internal.librarymanagement.mavenint.PomExtraDependencyAttributes
import sbt.io.IO import sbt.io.IO
import sbt.util.Logger import sbt.util.Logger

View File

@ -171,7 +171,7 @@ object CustomPomParser {
// The extra sbt plugin metadata in pom.xml does not need to be readable by maven, but the other information may be. // The extra sbt plugin metadata in pom.xml does not need to be readable by maven, but the other information may be.
// However, the pom.xml needs to be valid in all cases because other tools like repository managers may read the pom.xml. // However, the pom.xml needs to be valid in all cases because other tools like repository managers may read the pom.xml.
private[sbt] def getPomProperties(md: ModuleDescriptor): Map[String, String] = { private[sbt] def getPomProperties(md: ModuleDescriptor): Map[String, String] = {
import collection.JavaConverters._ import scala.jdk.CollectionConverters._
PomModuleDescriptorBuilder PomModuleDescriptorBuilder
.extractPomProperties(md.getExtraInfo) .extractPomProperties(md.getExtraInfo)
.asInstanceOf[java.util.Map[String, String]] .asInstanceOf[java.util.Map[String, String]]
@ -182,13 +182,13 @@ object CustomPomParser {
(propertyAttributes - ExtraAttributesKey) map { case (k, v) => ("e:" + k, v) } (propertyAttributes - ExtraAttributesKey) map { case (k, v) => ("e:" + k, v) }
private[this] def shouldBeUnqualified(m: Map[String, String]): Map[String, String] = private[this] def shouldBeUnqualified(m: Map[String, String]): Map[String, String] =
m.filterKeys(unqualifiedKeys).toMap m.view.filterKeys(unqualifiedKeys).toMap
private[this] def addExtra( private[this] def addExtra(
properties: Map[String, String], properties: Map[String, String],
id: ModuleRevisionId id: ModuleRevisionId
): ModuleRevisionId = { ): ModuleRevisionId = {
import collection.JavaConverters._ import scala.jdk.CollectionConverters._
val oldExtra = qualifiedExtra(id) val oldExtra = qualifiedExtra(id)
val newExtra = (oldExtra ++ properties).asJava val newExtra = (oldExtra ++ properties).asJava
// remove the sbt plugin cross version from the resolved ModuleRevisionId // remove the sbt plugin cross version from the resolved ModuleRevisionId
@ -211,9 +211,9 @@ object CustomPomParser {
def qualifiedExtra(item: ExtendableItem): Map[String, String] = def qualifiedExtra(item: ExtendableItem): Map[String, String] =
PomExtraDependencyAttributes.qualifiedExtra(item) PomExtraDependencyAttributes.qualifiedExtra(item)
def filterCustomExtra(item: ExtendableItem, include: Boolean): Map[String, String] = def filterCustomExtra(item: ExtendableItem, include: Boolean): Map[String, String] =
(qualifiedExtra(item) filterKeys { k => qualifiedExtra(item).view.filterKeys { k =>
qualifiedIsExtra(k) == include qualifiedIsExtra(k) == include
}).toMap }.toMap
def writeDependencyExtra(s: Seq[DependencyDescriptor]): Seq[String] = def writeDependencyExtra(s: Seq[DependencyDescriptor]): Seq[String] =
PomExtraDependencyAttributes.writeDependencyExtra(s) PomExtraDependencyAttributes.writeDependencyExtra(s)
@ -275,7 +275,7 @@ object CustomPomParser {
case None => dd case None => dd
} }
import collection.JavaConverters._ import scala.jdk.CollectionConverters._
def addExtra( def addExtra(
properties: Map[String, String], properties: Map[String, String],
dependencyExtra: Map[ModuleRevisionId, Map[String, String]], dependencyExtra: Map[ModuleRevisionId, Map[String, String]],

View File

@ -561,7 +561,7 @@ private[sbt] object IvySbt {
* Clearly, it would be better to have an explicit option in Ivy to control this. * Clearly, it would be better to have an explicit option in Ivy to control this.
*/ */
def hasImplicitClassifier(artifact: IArtifact): Boolean = { def hasImplicitClassifier(artifact: IArtifact): Boolean = {
import scala.collection.JavaConverters._ import scala.jdk.CollectionConverters._
artifact.getQualifiedExtraAttributes.asScala.keys artifact.getQualifiedExtraAttributes.asScala.keys
.exists(_.asInstanceOf[String] startsWith "m:") .exists(_.asInstanceOf[String] startsWith "m:")
} }
@ -795,7 +795,7 @@ private[sbt] object IvySbt {
artifact artifact
} }
def getExtraAttributes(revID: ExtendableItem): Map[String, String] = { def getExtraAttributes(revID: ExtendableItem): Map[String, String] = {
import scala.collection.JavaConverters._ import scala.jdk.CollectionConverters._
revID.getExtraAttributes.asInstanceOf[java.util.Map[String, String]].asScala.toMap revID.getExtraAttributes.asInstanceOf[java.util.Map[String, String]].asScala.toMap
} }
private[sbt] def extra( private[sbt] def extra(
@ -808,7 +808,7 @@ private[sbt] object IvySbt {
javaMap(ea.extraAttributes, unqualify) javaMap(ea.extraAttributes, unqualify)
} }
private[sbt] def javaMap(m: Map[String, String], unqualify: Boolean = false) = { private[sbt] def javaMap(m: Map[String, String], unqualify: Boolean = false) = {
import scala.collection.JavaConverters._ import scala.jdk.CollectionConverters._
val map = if (unqualify) m map { case (k, v) => (k.stripPrefix("e:"), v) } val map = if (unqualify) m map { case (k, v) => (k.stripPrefix("e:"), v) }
else m else m
if (map.isEmpty) null else map.asJava if (map.isEmpty) null else map.asJava
@ -962,9 +962,9 @@ private[sbt] object IvySbt {
deps.put(id, updated) deps.put(id, updated)
} }
import scala.collection.JavaConverters._ import scala.jdk.CollectionConverters._
deps.values.asScala.toSeq.flatMap { dds => deps.values.asScala.toSeq.flatMap { dds =>
val mergeable = (dds, dds.tail).zipped.forall(ivyint.MergeDescriptors.mergeable _) val mergeable = dds.lazyZip(dds.tail).forall(ivyint.MergeDescriptors.mergeable _)
if (mergeable) dds.reverse.reduceLeft(ivyint.MergeDescriptors.apply _) :: Nil else dds if (mergeable) dds.reverse.reduceLeft(ivyint.MergeDescriptors.apply _) :: Nil else dds
} }
} }

View File

@ -236,7 +236,7 @@ object IvyActions {
}.toMap }.toMap
def grouped[T](grouping: ModuleID => T)(mods: Seq[ModuleID]): Map[T, Set[String]] = def grouped[T](grouping: ModuleID => T)(mods: Seq[ModuleID]): Map[T, Set[String]] =
mods.groupBy(grouping).mapValues(_.map(_.revision).toSet).toMap mods.groupBy(grouping).view.mapValues(_.map(_.revision).toSet).toMap
def addExcluded( def addExcluded(
report: UpdateReport, report: UpdateReport,

View File

@ -158,7 +158,7 @@ private[sbt] class CachedResolutionResolveCache {
(md1, IvySbt.isChanging(dd) || internalDependency(dd, prOpt).isDefined, dd) (md1, IvySbt.isChanging(dd) || internalDependency(dd, prOpt).isDefined, dd)
} }
def extractOverrides(md0: ModuleDescriptor): Vector[IvyOverride] = { def extractOverrides(md0: ModuleDescriptor): Vector[IvyOverride] = {
import scala.collection.JavaConverters._ import scala.jdk.CollectionConverters._
md0.getAllDependencyDescriptorMediators.getAllRules.asScala.toSeq.toVector sortBy { md0.getAllDependencyDescriptorMediators.getAllRules.asScala.toSeq.toVector sortBy {
case (k, _) => case (k, _) =>
k.toString k.toString

View File

@ -2,7 +2,7 @@ package sbt.internal.librarymanagement
package ivyint package ivyint
import org.apache.ivy.util.url.CredentialsStore import org.apache.ivy.util.url.CredentialsStore
import collection.JavaConverters._ import scala.jdk.CollectionConverters._
/** A key used to store credentials in the ivy credentials store. */ /** A key used to store credentials in the ivy credentials store. */
private[sbt] sealed trait CredentialKey private[sbt] sealed trait CredentialKey
@ -56,11 +56,16 @@ private[sbt] object IvyCredentialsLookup {
* A mapping of host -> realms in the ivy credentials store. * A mapping of host -> realms in the ivy credentials store.
*/ */
def realmsForHost: Map[String, Set[String]] = def realmsForHost: Map[String, Set[String]] =
(keyringKeys collect { case x: Realm => keyringKeys
.collect { case x: Realm =>
x x
} groupBy { realm => }
.groupBy { realm =>
realm.host realm.host
} mapValues { realms => }
.view
.mapValues { realms =>
realms map (_.realm) realms map (_.realm)
}).toMap }
.toMap
} }

View File

@ -40,7 +40,7 @@ private[sbt] class ParallelResolveEngine(
artifactFilter: Filter, artifactFilter: Filter,
options: DownloadOptions options: DownloadOptions
): Unit = { ): Unit = {
import scala.collection.JavaConverters._ import scala.jdk.CollectionConverters._
val start = System.currentTimeMillis val start = System.currentTimeMillis
report.getArtifacts match { report.getArtifacts match {
case typed: java.util.List[Artifact @unchecked] => case typed: java.util.List[Artifact @unchecked] =>

View File

@ -433,9 +433,9 @@ private[sbt] case class SbtChainResolver(
case _ => case _ =>
None None
} }
val artifactRefs = md.getConfigurations.toIterator flatMap { conf => val artifactRefs = md.getConfigurations.iterator flatMap { conf =>
md.getArtifacts(conf.getName).toIterator flatMap { af => md.getArtifacts(conf.getName).iterator flatMap { af =>
artifactRef(af, data.getDate).toIterator artifactRef(af, data.getDate).iterator
} }
} }
if (artifactRefs.hasNext) Some(artifactRefs.next()) if (artifactRefs.hasNext) Some(artifactRefs.next())

View File

@ -35,7 +35,7 @@ object PomExtraDependencyAttributes {
def readFromAether( def readFromAether(
props: java.util.Map[String, AnyRef] props: java.util.Map[String, AnyRef]
): Map[ModuleRevisionId, Map[String, String]] = { ): Map[ModuleRevisionId, Map[String, String]] = {
import scala.collection.JavaConverters._ import scala.jdk.CollectionConverters._
(props.asScala get ExtraAttributesKey) match { (props.asScala get ExtraAttributesKey) match {
case None => Map.empty case None => Map.empty
case Some(str) => case Some(str) =>
@ -74,13 +74,13 @@ object PomExtraDependencyAttributes {
} }
def qualifiedExtra(item: ExtendableItem): Map[String, String] = { def qualifiedExtra(item: ExtendableItem): Map[String, String] = {
import scala.collection.JavaConverters._ import scala.jdk.CollectionConverters._
item.getQualifiedExtraAttributes.asInstanceOf[java.util.Map[String, String]].asScala.toMap item.getQualifiedExtraAttributes.asInstanceOf[java.util.Map[String, String]].asScala.toMap
} }
def filterCustomExtra(item: ExtendableItem, include: Boolean): Map[String, String] = def filterCustomExtra(item: ExtendableItem, include: Boolean): Map[String, String] =
(qualifiedExtra(item) filterKeys { k => qualifiedExtra(item).view.filterKeys { k =>
qualifiedIsExtra(k) == include qualifiedIsExtra(k) == include
}).toMap }.toMap
def qualifiedIsExtra(k: String): Boolean = def qualifiedIsExtra(k: String): Boolean =
k.endsWith(ScalaVersionKey) || k.endsWith(SbtVersionKey) k.endsWith(ScalaVersionKey) || k.endsWith(SbtVersionKey)
@ -89,7 +89,7 @@ object PomExtraDependencyAttributes {
// This makes the id suitable as a key to associate a dependency parsed from a <dependency> element // This makes the id suitable as a key to associate a dependency parsed from a <dependency> element
// with the extra attributes from the <properties> section // with the extra attributes from the <properties> section
def simplify(id: ModuleRevisionId): ModuleRevisionId = { def simplify(id: ModuleRevisionId): ModuleRevisionId = {
import scala.collection.JavaConverters._ import scala.jdk.CollectionConverters._
ModuleRevisionId.newInstance( ModuleRevisionId.newInstance(
id.getOrganisation, id.getOrganisation,
id.getName, id.getName,

View File

@ -67,7 +67,7 @@ object Credentials {
private[this] val UserKeys = List("user", "user.name", "username") private[this] val UserKeys = List("user", "user.name", "username")
private[this] val PasswordKeys = List("password", "pwd", "pass", "passwd") private[this] val PasswordKeys = List("password", "pwd", "pass", "passwd")
import collection.JavaConverters._ import scala.jdk.CollectionConverters._
private[this] def read(from: File): Map[String, String] = { private[this] def read(from: File): Map[String, String] = {
val properties = new java.util.Properties val properties = new java.util.Properties
IO.load(properties, from) IO.load(properties, from)

View File

@ -34,18 +34,23 @@ object FrozenModeSpec extends BaseIvySpecification {
val toResolve = module(defaultModuleId, stoml, None, normalOptions) val toResolve = module(defaultModuleId, stoml, None, normalOptions)
val onlineResolution = update(toResolve, onlineConf) val onlineResolution = update(toResolve, onlineConf)
assert(onlineResolution.isRight) assert(onlineResolution.isRight)
val numberResolved = onlineResolution.right.get.allModules.size val numberResolved =
val numberReportsResolved = onlineResolution.right.get.allModuleReports.size onlineResolution.fold(e => throw e.resolveException, identity).allModules.size
val numberReportsResolved =
onlineResolution.fold(e => throw e.resolveException, identity).allModuleReports.size
cleanIvyCache() cleanIvyCache()
val singleFrozenResolution = update(toResolve, frozenConf) val singleFrozenResolution = update(toResolve, frozenConf)
assert(singleFrozenResolution.isRight) assert(singleFrozenResolution.isRight)
assert( assert(
singleFrozenResolution.right.get.allModules.size == 1, singleFrozenResolution.fold(e => throw e.resolveException, identity).allModules.size == 1,
s"The number of explicit modules in frozen mode should 1" s"The number of explicit modules in frozen mode should 1"
) )
assert( assert(
singleFrozenResolution.right.get.allModuleReports.size == 1, singleFrozenResolution
.fold(e => throw e.resolveException, identity)
.allModuleReports
.size == 1,
s"The number of explicit module reports in frozen mode should 1" s"The number of explicit module reports in frozen mode should 1"
) )
@ -55,11 +60,17 @@ object FrozenModeSpec extends BaseIvySpecification {
val frozenResolution = update(toExplicitResolve, frozenConf) val frozenResolution = update(toExplicitResolve, frozenConf)
assert(frozenResolution.isRight) assert(frozenResolution.isRight)
assert( assert(
frozenResolution.right.get.allModules.size == numberResolved, frozenResolution
.fold(e => throw e.resolveException, identity)
.allModules
.size == numberResolved,
s"The number of explicit modules in frozen mode should be equal than $numberResolved" s"The number of explicit modules in frozen mode should be equal than $numberResolved"
) )
assert( assert(
frozenResolution.right.get.allModuleReports.size == numberReportsResolved, frozenResolution
.fold(e => throw e.resolveException, identity)
.allModuleReports
.size == numberReportsResolved,
s"The number of explicit module reports in frozen mode should be equal than $numberReportsResolved" s"The number of explicit module reports in frozen mode should be equal than $numberReportsResolved"
) )
} }

View File

@ -84,8 +84,7 @@ object IvyRepoSpec extends BaseIvySpecification {
val report2 = val report2 =
lmEngine() lmEngine()
.updateClassifiers(gcm, UnresolvedWarningConfiguration(), Vector(), log) .updateClassifiers(gcm, UnresolvedWarningConfiguration(), Vector(), log)
.right .fold(e => throw e.resolveException, identity)
.get
import Inside._ import Inside._
inside(report2.configuration(ConfigRef("compile")).map(_.modules)) { case Some(Seq(mr)) => inside(report2.configuration(ConfigRef("compile")).map(_.modules)) { case Some(Seq(mr)) =>

View File

@ -51,7 +51,7 @@ object ManagedChecksumsSpec extends BaseIvySpecification {
val toResolve = module(defaultModuleId, dependencies, None, updateOptions) val toResolve = module(defaultModuleId, dependencies, None, updateOptions)
val res = IvyActions.updateEither(toResolve, onlineConf, warningConf, log) val res = IvyActions.updateEither(toResolve, onlineConf, warningConf, log)
assert(res.isRight, s"Resolution with managed checksums failed! $res") assert(res.isRight, s"Resolution with managed checksums failed! $res")
val updateReport = res.right.get val updateReport = res.fold(e => throw e.resolveException, identity)
val allModuleReports = updateReport.configurations.flatMap(_.modules) val allModuleReports = updateReport.configurations.flatMap(_.modules)
val allArtifacts: Seq[File] = allModuleReports.flatMap(_.artifacts.map(_._2)) val allArtifacts: Seq[File] = allModuleReports.flatMap(_.artifacts.map(_._2))
allArtifacts.foreach(assertChecksumExists) allArtifacts.foreach(assertChecksumExists)

View File

@ -26,7 +26,8 @@ object ModuleResolversTest extends BaseIvySpecification {
val ivyModule = module(stubModule, dependencies, None, updateOptions) val ivyModule = module(stubModule, dependencies, None, updateOptions)
val normalResolution = ivyUpdateEither(ivyModule) val normalResolution = ivyUpdateEither(ivyModule)
assert(normalResolution.isRight) assert(normalResolution.isRight)
val normalResolutionTime = normalResolution.right.get.stats.resolveTime val normalResolutionTime =
normalResolution.fold(e => throw e.resolveException, identity).stats.resolveTime
cleanIvyCache() cleanIvyCache()
val moduleResolvers = Map( val moduleResolvers = Map(
@ -37,7 +38,8 @@ object ModuleResolversTest extends BaseIvySpecification {
val ivyModule2 = module(stubModule, dependencies, None, customUpdateOptions) val ivyModule2 = module(stubModule, dependencies, None, customUpdateOptions)
val fasterResolution = ivyUpdateEither(ivyModule2) val fasterResolution = ivyUpdateEither(ivyModule2)
assert(fasterResolution.isRight) assert(fasterResolution.isRight)
val fasterResolutionTime = fasterResolution.right.get.stats.resolveTime val fasterResolutionTime =
fasterResolution.fold(e => throw e.resolveException, identity).stats.resolveTime
// THis is left on purpose so that in spurious error we see the times // THis is left on purpose so that in spurious error we see the times
println(s"NORMAL RESOLUTION TIME $normalResolutionTime") println(s"NORMAL RESOLUTION TIME $normalResolutionTime")

View File

@ -34,14 +34,16 @@ object OfflineModeSpec extends BaseIvySpecification {
val onlineResolution = val onlineResolution =
IvyActions.updateEither(toResolve, onlineConf, warningConf, log) IvyActions.updateEither(toResolve, onlineConf, warningConf, log)
assert(onlineResolution.isRight) assert(onlineResolution.isRight)
assert(onlineResolution.right.exists(report => report.stats.resolveTime > 0)) assert(onlineResolution.toOption.exists(report => report.stats.resolveTime > 0))
val originalResolveTime = onlineResolution.right.get.stats.resolveTime val originalResolveTime =
onlineResolution.fold(e => throw e.resolveException, identity).stats.resolveTime
val offlineResolution = val offlineResolution =
IvyActions.updateEither(toResolve, offlineConf, warningConf, log) IvyActions.updateEither(toResolve, offlineConf, warningConf, log)
assert(offlineResolution.isRight) assert(offlineResolution.isRight)
val resolveTime = offlineResolution.right.get.stats.resolveTime val resolveTime =
offlineResolution.fold(e => throw e.resolveException, identity).stats.resolveTime
assert(originalResolveTime > resolveTime) assert(originalResolveTime > resolveTime)
} }