Skip to content

Commit

Permalink
Merge pull request #450 from xuwei-k/sbt-2-warnings
Browse files Browse the repository at this point in the history
[2.x] fix warnings
  • Loading branch information
eed3si9n authored Oct 5, 2024
2 parents 44e234b + fdaa662 commit 1cad709
Show file tree
Hide file tree
Showing 18 changed files with 69 additions and 50 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ object ConflictWarning {
/** Map from (organization, rawName) to set of multiple full names. */
def crossVersionMismatches(report: UpdateReport): Map[(String, String), Set[String]] = {
val mismatches = report.configurations.flatMap { confReport =>
groupByRawName(confReport.allModules).mapValues { modules =>
groupByRawName(confReport.allModules).view.mapValues { modules =>
val differentFullNames = modules.map(_.name).toSet
if (differentFullNames.size > 1) differentFullNames else Set.empty[String]
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
// FIXME: this is only done because IDE plugins depend on `classifier` to determine type. They
val typeClassifierMap: Map[String, String] =
((sourceArtifactTypes.toIterable map (_ -> Artifact.SourceClassifier))
:: (docArtifactTypes.toIterable map (_ -> Artifact.DocClassifier)) :: Nil).flatten.toMap
((sourceArtifactTypes.toSeq map (_ -> Artifact.SourceClassifier))
:: (docArtifactTypes.toSeq map (_ -> Artifact.DocClassifier)) :: Nil).flatten.toMap
Right(r.substitute { (conf, mid, artFileSeq) =>
artFileSeq map { case (art, f) =>
// Deduce the classifier from the type if no classifier is present already
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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). */
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(
"Use `cross(CrossVersion)`, the variant accepting a CrossVersion value constructed by a member of the CrossVersion object instead.",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ import org.apache.ivy.core.module.descriptor.DefaultArtifact
import org.apache.ivy.core.report.DownloadReport
import org.apache.ivy.plugins.resolver.util.{ ResolvedResource, ResourceMDParser }
import org.apache.ivy.util.{ ChecksumHelper, FileUtil, Message }
import scala.collection.JavaConverters._
import scala.jdk.CollectionConverters._
import sbt.internal.librarymanagement.mavenint.PomExtraDependencyAttributes
import sbt.io.IO
import sbt.util.Logger
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
// 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] = {
import collection.JavaConverters._
import scala.jdk.CollectionConverters._
PomModuleDescriptorBuilder
.extractPomProperties(md.getExtraInfo)
.asInstanceOf[java.util.Map[String, String]]
Expand All @@ -182,13 +182,13 @@ object CustomPomParser {
(propertyAttributes - ExtraAttributesKey) map { case (k, v) => ("e:" + k, v) }

private[this] def shouldBeUnqualified(m: Map[String, String]): Map[String, String] =
m.filterKeys(unqualifiedKeys).toMap
m.view.filterKeys(unqualifiedKeys).toMap

private[this] def addExtra(
properties: Map[String, String],
id: ModuleRevisionId
): ModuleRevisionId = {
import collection.JavaConverters._
import scala.jdk.CollectionConverters._
val oldExtra = qualifiedExtra(id)
val newExtra = (oldExtra ++ properties).asJava
// remove the sbt plugin cross version from the resolved ModuleRevisionId
Expand All @@ -211,9 +211,9 @@ object CustomPomParser {
def qualifiedExtra(item: ExtendableItem): Map[String, String] =
PomExtraDependencyAttributes.qualifiedExtra(item)
def filterCustomExtra(item: ExtendableItem, include: Boolean): Map[String, String] =
(qualifiedExtra(item) filterKeys { k =>
qualifiedExtra(item).view.filterKeys { k =>
qualifiedIsExtra(k) == include
}).toMap
}.toMap

def writeDependencyExtra(s: Seq[DependencyDescriptor]): Seq[String] =
PomExtraDependencyAttributes.writeDependencyExtra(s)
Expand Down Expand Up @@ -275,7 +275,7 @@ object CustomPomParser {
case None => dd
}

import collection.JavaConverters._
import scala.jdk.CollectionConverters._
def addExtra(
properties: Map[String, String],
dependencyExtra: Map[ModuleRevisionId, Map[String, String]],
Expand Down
10 changes: 5 additions & 5 deletions ivy/src/main/scala/sbt/internal/librarymanagement/Ivy.scala
Original file line number Diff line number Diff line change
Expand Up @@ -561,7 +561,7 @@ private[sbt] object IvySbt {
* Clearly, it would be better to have an explicit option in Ivy to control this.
*/
def hasImplicitClassifier(artifact: IArtifact): Boolean = {
import scala.collection.JavaConverters._
import scala.jdk.CollectionConverters._
artifact.getQualifiedExtraAttributes.asScala.keys
.exists(_.asInstanceOf[String] startsWith "m:")
}
Expand Down Expand Up @@ -795,7 +795,7 @@ private[sbt] object IvySbt {
artifact
}
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
}
private[sbt] def extra(
Expand All @@ -808,7 +808,7 @@ private[sbt] object IvySbt {
javaMap(ea.extraAttributes, unqualify)
}
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) }
else m
if (map.isEmpty) null else map.asJava
Expand Down Expand Up @@ -962,9 +962,9 @@ private[sbt] object IvySbt {
deps.put(id, updated)
}

import scala.collection.JavaConverters._
import scala.jdk.CollectionConverters._
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
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ object IvyActions {
}.toMap

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(
report: UpdateReport,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ private[sbt] class CachedResolutionResolveCache {
(md1, IvySbt.isChanging(dd) || internalDependency(dd, prOpt).isDefined, dd)
}
def extractOverrides(md0: ModuleDescriptor): Vector[IvyOverride] = {
import scala.collection.JavaConverters._
import scala.jdk.CollectionConverters._
md0.getAllDependencyDescriptorMediators.getAllRules.asScala.toSeq.toVector sortBy {
case (k, _) =>
k.toString
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package sbt.internal.librarymanagement
package ivyint

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. */
private[sbt] sealed trait CredentialKey
Expand Down Expand Up @@ -56,11 +56,16 @@ private[sbt] object IvyCredentialsLookup {
* A mapping of host -> realms in the ivy credentials store.
*/
def realmsForHost: Map[String, Set[String]] =
(keyringKeys collect { case x: Realm =>
x
} groupBy { realm =>
realm.host
} mapValues { realms =>
realms map (_.realm)
}).toMap
keyringKeys
.collect { case x: Realm =>
x
}
.groupBy { realm =>
realm.host
}
.view
.mapValues { realms =>
realms map (_.realm)
}
.toMap
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ private[sbt] class ParallelResolveEngine(
artifactFilter: Filter,
options: DownloadOptions
): Unit = {
import scala.collection.JavaConverters._
import scala.jdk.CollectionConverters._
val start = System.currentTimeMillis
report.getArtifacts match {
case typed: java.util.List[Artifact @unchecked] =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -433,9 +433,9 @@ private[sbt] case class SbtChainResolver(
case _ =>
None
}
val artifactRefs = md.getConfigurations.toIterator flatMap { conf =>
md.getArtifacts(conf.getName).toIterator flatMap { af =>
artifactRef(af, data.getDate).toIterator
val artifactRefs = md.getConfigurations.iterator flatMap { conf =>
md.getArtifacts(conf.getName).iterator flatMap { af =>
artifactRef(af, data.getDate).iterator
}
}
if (artifactRefs.hasNext) Some(artifactRefs.next())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ object PomExtraDependencyAttributes {
def readFromAether(
props: java.util.Map[String, AnyRef]
): Map[ModuleRevisionId, Map[String, String]] = {
import scala.collection.JavaConverters._
import scala.jdk.CollectionConverters._
(props.asScala get ExtraAttributesKey) match {
case None => Map.empty
case Some(str) =>
Expand Down Expand Up @@ -74,13 +74,13 @@ object PomExtraDependencyAttributes {
}

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
}
def filterCustomExtra(item: ExtendableItem, include: Boolean): Map[String, String] =
(qualifiedExtra(item) filterKeys { k =>
qualifiedExtra(item).view.filterKeys { k =>
qualifiedIsExtra(k) == include
}).toMap
}.toMap

def qualifiedIsExtra(k: String): Boolean =
k.endsWith(ScalaVersionKey) || k.endsWith(SbtVersionKey)
Expand All @@ -89,7 +89,7 @@ object PomExtraDependencyAttributes {
// 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
def simplify(id: ModuleRevisionId): ModuleRevisionId = {
import scala.collection.JavaConverters._
import scala.jdk.CollectionConverters._
ModuleRevisionId.newInstance(
id.getOrganisation,
id.getName,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ object Credentials {
private[this] val UserKeys = List("user", "user.name", "username")
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] = {
val properties = new java.util.Properties
IO.load(properties, from)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,18 +34,23 @@ object FrozenModeSpec extends BaseIvySpecification {
val toResolve = module(defaultModuleId, stoml, None, normalOptions)
val onlineResolution = update(toResolve, onlineConf)
assert(onlineResolution.isRight)
val numberResolved = onlineResolution.right.get.allModules.size
val numberReportsResolved = onlineResolution.right.get.allModuleReports.size
val numberResolved =
onlineResolution.fold(e => throw e.resolveException, identity).allModules.size
val numberReportsResolved =
onlineResolution.fold(e => throw e.resolveException, identity).allModuleReports.size

cleanIvyCache()
val singleFrozenResolution = update(toResolve, frozenConf)
assert(singleFrozenResolution.isRight)
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"
)
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"
)

Expand All @@ -55,11 +60,17 @@ object FrozenModeSpec extends BaseIvySpecification {
val frozenResolution = update(toExplicitResolve, frozenConf)
assert(frozenResolution.isRight)
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"
)
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"
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,7 @@ object IvyRepoSpec extends BaseIvySpecification {
val report2 =
lmEngine()
.updateClassifiers(gcm, UnresolvedWarningConfiguration(), Vector(), log)
.right
.get
.fold(e => throw e.resolveException, identity)

import Inside._
inside(report2.configuration(ConfigRef("compile")).map(_.modules)) { case Some(Seq(mr)) =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ object ManagedChecksumsSpec extends BaseIvySpecification {
val toResolve = module(defaultModuleId, dependencies, None, updateOptions)
val res = IvyActions.updateEither(toResolve, onlineConf, warningConf, log)
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 allArtifacts: Seq[File] = allModuleReports.flatMap(_.artifacts.map(_._2))
allArtifacts.foreach(assertChecksumExists)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ object ModuleResolversTest extends BaseIvySpecification {
val ivyModule = module(stubModule, dependencies, None, updateOptions)
val normalResolution = ivyUpdateEither(ivyModule)
assert(normalResolution.isRight)
val normalResolutionTime = normalResolution.right.get.stats.resolveTime
val normalResolutionTime =
normalResolution.fold(e => throw e.resolveException, identity).stats.resolveTime

cleanIvyCache()
val moduleResolvers = Map(
Expand All @@ -37,7 +38,8 @@ object ModuleResolversTest extends BaseIvySpecification {
val ivyModule2 = module(stubModule, dependencies, None, customUpdateOptions)
val fasterResolution = ivyUpdateEither(ivyModule2)
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
println(s"NORMAL RESOLUTION TIME $normalResolutionTime")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,16 @@ object OfflineModeSpec extends BaseIvySpecification {
val onlineResolution =
IvyActions.updateEither(toResolve, onlineConf, warningConf, log)
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 =
IvyActions.updateEither(toResolve, offlineConf, warningConf, log)
assert(offlineResolution.isRight)

val resolveTime = offlineResolution.right.get.stats.resolveTime
val resolveTime =
offlineResolution.fold(e => throw e.resolveException, identity).stats.resolveTime
assert(originalResolveTime > resolveTime)
}

Expand Down

0 comments on commit 1cad709

Please sign in to comment.