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

Fix new warnings introducted by scala 2.13.13 and -Xsource:3-cross option #5548

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
84acdfa
Enable new Xsource:3-cross compilation flag for scala 2.13.13
mbaechler Apr 4, 2024
f47be6b
Fix new warnings introducted by scala 2.13.13 and -Xsource:3-cross op…
mbaechler Apr 4, 2024
1e91437
Rewrite `private[this]` into `private`
mbaechler Mar 14, 2024
3389e10
A few more rewrite to please scala 3.4 compiler
mbaechler Mar 14, 2024
1f4ec12
spotless formatting
mbaechler Mar 28, 2024
88c697d
remove useless final
mbaechler Mar 28, 2024
130e855
help scala compiler with explicit typing
mbaechler Mar 28, 2024
c5098e0
provide a total function for messageHandler to avoid pattern matching…
mbaechler Mar 28, 2024
613dcfe
rewrite early return function to functional style
mbaechler Mar 28, 2024
2e1bf59
fix an obvious typo that should not compile
mbaechler Mar 28, 2024
7de9c76
changes required for specs2, mostly following the user guide
mbaechler Apr 4, 2024
d2c127d
fix conflicts in implicits resolution
mbaechler Apr 4, 2024
5d73a88
return unit as a result in unused expression
mbaechler Apr 4, 2024
e1470c7
implement compile time introspection with ClassTag instead of depreca…
mbaechler Apr 4, 2024
2274a47
remove unreachable cases in pattern matching
mbaechler Mar 28, 2024
10bcaa1
automatic derivation not longer work with value class (AnyVal style),…
mbaechler Mar 28, 2024
bf68719
protected semantic for case class constructor changed, it requires a …
mbaechler Mar 28, 2024
f129aee
Provide types for implicit to help the compiler
mbaechler Apr 29, 2024
f215d68
provide more types to help the compiler
mbaechler Apr 29, 2024
4dbb145
Spotless reformating
mbaechler Apr 29, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ sealed trait AgentType extends EnumEntry {

object AgentType extends Enum[AgentType] {

final case object CfeEnterprise extends AgentType {
case object CfeEnterprise extends AgentType {
override def id = "cfengine-nova"
override def oldShortName = "nova"
override def displayName = "CFEngine Enterprise"
Expand All @@ -109,7 +109,7 @@ object AgentType extends Enum[AgentType] {
override val defaultPolicyExtension = ".cf"
}

final case object CfeCommunity extends AgentType {
case object CfeCommunity extends AgentType {
override def id = "cfengine-community"
override def oldShortName = "community"
override def displayName = "Rudder"
Expand All @@ -120,7 +120,7 @@ object AgentType extends Enum[AgentType] {
override val defaultPolicyExtension = ".cf"
}

final case object Dsc extends AgentType {
case object Dsc extends AgentType {
override def id = "dsc"
override def oldShortName = "dsc"
override def displayName = "Rudder Windows"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ final class Version(val value: String) extends AnyVal {
override def toString(): String = "[%s]".format(value)
}
object Version {
implicit val ord: Ordering[Version] = _.value compareTo _.value
implicit val ord: Ordering[Version] = Ordering.by(_.value)
}

object InventoryProcessingLogger extends NamedZioLogger {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ final case class MemorySize(size: Long) extends AnyVal {

object MemorySize {

val ord: Ordering[MemorySize] = _.size compareTo _.size
val ord: Ordering[MemorySize] = Ordering.by(_.size)

/*
* We should accept:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -332,39 +332,39 @@ object ParseOSType {
(osType.toLowerCase, osName.toLowerCase, fullName.toLowerCase) match {
case ("mswin32", _, x) =>
// in windows, relevant information are in the fullName string
if (x contains "xp") WindowsXP
else if (x contains "vista") WindowsVista
else if (x contains "seven") WindowsSeven
else if (x contains "10") Windows10
else if (x contains "2000") Windows2000
else if (x contains "2003") Windows2003
else if (x contains "2008 r2") Windows2008R2 // must be before 2008 for obvious reason
else if (x contains "2008") Windows2008
else if (x contains "2012 r2") Windows2012R2
else if (x contains "2012") Windows2012
else if (x contains "2016 r2") Windows2016R2
else if (x contains "2016") Windows2016
else if (x contains "2019") Windows2019
else if (x contains "2022") Windows2022
if (x.contains("xp")) WindowsXP
else if (x.contains("vista")) WindowsVista
else if (x.contains("seven")) WindowsSeven
else if (x.contains("10")) Windows10
else if (x.contains("2000")) Windows2000
else if (x.contains("2003")) Windows2003
else if (x.contains("2008 r2")) Windows2008R2 // must be before 2008 for obvious reason
else if (x.contains("2008")) Windows2008
else if (x.contains("2012 r2")) Windows2012R2
else if (x.contains("2012")) Windows2012
else if (x.contains("2016 r2")) Windows2016R2
else if (x.contains("2016")) Windows2016
else if (x.contains("2019")) Windows2019
else if (x.contains("2022")) Windows2022
else UnknownWindowsType

case ("linux", x, _) =>
if (x contains "debian") Debian
else if (x contains "ubuntu") Ubuntu
else if (x contains "kali") Kali
else if (x contains "redhat") Redhat
else if (x contains "centos") Centos
else if (x contains "fedora") Fedora
else if (x contains "suse") Suse
else if (x contains "android") Android
else if (x contains "oracle") Oracle
else if (x contains "scientific") Scientific
else if (x contains "slackware") Slackware
else if (x contains "mint") Mint
else if (x contains "amazon linux") AmazonLinux
else if (x contains "rocky") RockyLinux
else if (x contains "almalinux") AlmaLinux
else if (x contains "raspbian") Raspbian
if (x.contains("debian")) Debian
else if (x.contains("ubuntu")) Ubuntu
else if (x.contains("kali")) Kali
else if (x.contains("redhat")) Redhat
else if (x.contains("centos")) Centos
else if (x.contains("fedora")) Fedora
else if (x.contains("suse")) Suse
else if (x.contains("android")) Android
else if (x.contains("oracle")) Oracle
else if (x.contains("scientific")) Scientific
else if (x.contains("slackware")) Slackware
else if (x.contains("mint")) Mint
else if (x.contains("amazon linux")) AmazonLinux
else if (x.contains("rocky")) RockyLinux
else if (x.contains("almalinux")) AlmaLinux
else if (x.contains("raspbian")) Raspbian
else UnknownLinuxType

case ("solaris", _, _) => SolarisOS
Expand Down Expand Up @@ -474,10 +474,10 @@ sealed abstract class SoftwareUpdateKind(override val entryName: String) extends
}

object SoftwareUpdateKind extends Enum[SoftwareUpdateKind] {
final case object None extends SoftwareUpdateKind("none")
final case object Defect extends SoftwareUpdateKind("defect")
final case object Security extends SoftwareUpdateKind("security")
final case object Enhancement extends SoftwareUpdateKind("enhancement")
case object None extends SoftwareUpdateKind("none")
case object Defect extends SoftwareUpdateKind("defect")
case object Security extends SoftwareUpdateKind("security")
case object Enhancement extends SoftwareUpdateKind("enhancement")
final case class Other(value: String) extends SoftwareUpdateKind("other")

def values: IndexedSeq[SoftwareUpdateKind] = findValues
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ trait PipelinedInventorySaver[R] extends InventorySaver[R] with Loggable {

val preCommitPipeline: Seq[PreCommit]
val basePostPipeline: Seq[PostCommit[R]]
private[this] val postCommitPipeline: Ref[Seq[PostCommit[R]]] = Ref.make(basePostPipeline).runNow
private val postCommitPipeline: Ref[Seq[PostCommit[R]]] = Ref.make(basePostPipeline).runNow

def registerPostCommitHook(hook: PostCommit[R]): UIO[Unit] = postCommitPipeline.update(hook +: _)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,11 @@ class MemoryTest extends Specification {
"Parsing memory type" should {

"work for all valid value" in {
validMemoryValue.map { case (value, result) => MemorySize.parse(value) mustEqual (Some(result)) }
validMemoryValue.map { case (value, result) => MemorySize.parse(value) must beSome(result) }
}

"fail for all invalid value" in {
invalidMemoryValue.map(MemorySize.parse(_) mustEqual (None))
invalidMemoryValue.map(MemorySize.parse(_) must beNone)
}

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ class FusionInventoryParser(

// extremely specialized convert used for optional field only, that
// log the error in place of using a box
private[this] def convert[T](input: Option[String], tag: String, format: String, conv: String => T): Option[T] = {
private def convert[T](input: Option[String], tag: String, format: String, conv: String => T): Option[T] = {
try {
input.map(s => conv(s))
} catch {
Expand All @@ -90,11 +90,11 @@ class FusionInventoryParser(
}

// same as above, but handle conversion to int
private[this] def optInt(n: NodeSeq, tag: String): Option[Int] =
private def optInt(n: NodeSeq, tag: String): Option[Int] =
convert(optText(n \ tag), tag, "Int", java.lang.Integer.parseInt)
private[this] def optFloat(n: NodeSeq, tag: String): Option[Float] =
private def optFloat(n: NodeSeq, tag: String): Option[Float] =
convert(optText(n \ tag), tag, "Float", java.lang.Float.parseFloat)
private[this] def optDouble(n: NodeSeq, tag: String): Option[Double] =
private def optDouble(n: NodeSeq, tag: String): Option[Double] =
convert(optText(n \ tag), tag, "Double", java.lang.Double.parseDouble)

private def optTextHead(n: NodeSeq): Option[String] = for {
Expand Down Expand Up @@ -517,7 +517,7 @@ class FusionInventoryParser(
* it updates the slotNumber (two memories can not share the same slot), setting position
* in the list as key. And yes, that may be unstable from one inventory to the next one.
*/
private[this] def demux(inventory: Inventory): Inventory = {
private def demux(inventory: Inventory): Inventory = {
// how can that be better ?
var r = inventory
r = r
Expand Down Expand Up @@ -555,7 +555,7 @@ class FusionInventoryParser(
r
}

private[this] def demuxMemories(
private def demuxMemories(
memories: Seq[com.normation.inventory.domain.MemorySlot]
): Seq[com.normation.inventory.domain.MemorySlot] = {
val duplicatedSlotsAndMemory =
Expand All @@ -577,7 +577,7 @@ class FusionInventoryParser(
* One interface can have several IP/mask/gateway/subnets. We have to
* merge them when it's the case.
*/
private[this] def demuxSameInterfaceDifferentIp(inventory: Inventory): Inventory = {
private def demuxSameInterfaceDifferentIp(inventory: Inventory): Inventory = {
val nets = inventory.node.networks
.groupBy(_.name)
.map {
Expand Down Expand Up @@ -613,7 +613,7 @@ class FusionInventoryParser(
* - things with x86_64 / x86 / i*86 in their name => x86_64 / x86 / i*86
* - IA-64, i[3-9]86, x86, x86_64, arm.*, other => identical [lower case]
*/
private[this] def normalizeArch(os: OsDetails)(s: String): String = {
private def normalizeArch(os: OsDetails)(s: String): String = {
val ix86 = """.*(i[3-9]86).*""".r
val x86 = """.*(x86|32-bit).*""".r
val x86_64 = """.*(x86_64|amd64|64-bit).*""".r
Expand Down Expand Up @@ -1068,7 +1068,7 @@ class FusionInventoryParser(
}
}

private[this] val DUMMY_MEM_SLOT_NUMBER = "DUMMY"
private val DUMMY_MEM_SLOT_NUMBER = "DUMMY"

/**
* For memory, the numslot is used for key.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,11 +86,11 @@ class PreInventoryParserCheckConsistency extends PreInventoryParser {
}

// Utilitary method to get only once the RUDDER and the AGENT
private[this] def getInTags(xml: NodeSeq, tag: String): NodeSeq = {
private def getInTags(xml: NodeSeq, tag: String): NodeSeq = {
xml \\ tag
}

private[this] def checkWithinNodeSeq(nodes: NodeSeq, child: String): IOResult[String] = {
private def checkWithinNodeSeq(nodes: NodeSeq, child: String): IOResult[String] = {
val nodes2 = nodes \ child

nodes2 match {
Expand All @@ -103,7 +103,7 @@ class PreInventoryParserCheckConsistency extends PreInventoryParser {
}
}

private[this] def checkNodeSeq(
private def checkNodeSeq(
xml: NodeSeq,
tag: String,
directChildren: Boolean = false,
Expand Down Expand Up @@ -131,12 +131,12 @@ class PreInventoryParserCheckConsistency extends PreInventoryParser {
}
}

private[this] def checkId(rudderNodeSeq: NodeSeq)(inventory: NodeSeq): IOResult[NodeSeq] = {
private def checkId(rudderNodeSeq: NodeSeq)(inventory: NodeSeq): IOResult[NodeSeq] = {
val tag = "UUID"
for {
tagHere <- {
checkWithinNodeSeq(rudderNodeSeq, tag) catchAll { _ =>
checkNodeSeq(inventory, tag, true).chainError(
checkNodeSeq(inventory, tag, directChildren = true).chainError(
s"Missing node ID attribute '${tag}' in inventory. This attribute is mandatory and must contains node ID."
)
}
Expand All @@ -147,7 +147,7 @@ class PreInventoryParserCheckConsistency extends PreInventoryParser {
}
}

private[this] def checkRoot(agentNodeSeq: NodeSeq)(inventory: NodeSeq): IOResult[NodeSeq] = {
private def checkRoot(agentNodeSeq: NodeSeq)(inventory: NodeSeq): IOResult[NodeSeq] = {
val agentTag = "OWNER"
val tag = "USER"
for {
Expand All @@ -163,7 +163,7 @@ class PreInventoryParserCheckConsistency extends PreInventoryParser {
}
}

private[this] def checkPolicyServer(agentNodeSeq: NodeSeq)(inventory: NodeSeq): IOResult[NodeSeq] = {
private def checkPolicyServer(agentNodeSeq: NodeSeq)(inventory: NodeSeq): IOResult[NodeSeq] = {
val agentTag = "POLICY_SERVER_UUID"
val tag = "POLICY_SERVER"
for {
Expand All @@ -179,7 +179,7 @@ class PreInventoryParserCheckConsistency extends PreInventoryParser {
}
}

private[this] def checkOS(inventory: NodeSeq): IOResult[NodeSeq] = {
private def checkOS(inventory: NodeSeq): IOResult[NodeSeq] = {
// VERSION is not mandatory on windows, it can't be added in that list
val tags = "FULL_NAME" :: "KERNEL_NAME" :: "NAME" :: Nil
val error = InventoryError.Inconsistency(
Expand All @@ -191,7 +191,7 @@ class PreInventoryParserCheckConsistency extends PreInventoryParser {
ZIO.foldLeft(tags)(zero)((a, b) => {
a match {
case Right(x) => Right(x).succeed
case Left(_) => checkNodeSeq(inventory, "OPERATINGSYSTEM", false, Some(b)).either
case Left(_) => checkNodeSeq(inventory, "OPERATINGSYSTEM", directChildren = false, optChild = Some(b)).either
}
})
)
Expand All @@ -205,46 +205,48 @@ class PreInventoryParserCheckConsistency extends PreInventoryParser {
* - (on AIX and non empty HARDWARE > OSVERSION )
* Other cases are failure (missing required info)
*/
private[this] def checkKernelVersion(inventory: NodeSeq): IOResult[NodeSeq] = {
private def checkKernelVersion(inventory: NodeSeq): IOResult[NodeSeq] = {

val failure = "Missing attribute OPERATINGSYSTEM>KERNEL_VERSION in inventory. This attribute is mandatory".inconsistency
val aixFailure = "Missing attribute HARDWARE>OSVERSION in inventory. This attribute is mandatory".inconsistency

checkNodeSeq(inventory, "OPERATINGSYSTEM", false, Some("KERNEL_VERSION")).map(_ => inventory).catchAll { _ =>
// perhaps we are on AIX ?
checkNodeSeq(inventory, "OPERATINGSYSTEM", false, Some("KERNEL_NAME"))
.foldZIO(
_ => failure,
x => {
if (x.toLowerCase == "aix") { // ok, check for OSVERSION
checkNodeSeq(inventory, "HARDWARE", false, Some("OSVERSION")).foldZIO(
_ => aixFailure,
kernelVersion => { // update the inventory to put it in the right place
(new scala.xml.transform.RuleTransformer(
new AddChildrenTo("OPERATINGSYSTEM", <KERNEL_VERSION>{kernelVersion}</KERNEL_VERSION>)
).transform(inventory).head).succeed
}
)
} else {
// should not be empty given checkOS, but if so, fails. Also fails is not aix.
failure
checkNodeSeq(inventory, "OPERATINGSYSTEM", directChildren = false, optChild = Some("KERNEL_VERSION"))
.map(_ => inventory)
.catchAll { _ =>
// perhaps we are on AIX ?
checkNodeSeq(inventory, "OPERATINGSYSTEM", directChildren = false, optChild = Some("KERNEL_NAME"))
.foldZIO(
_ => failure,
x => {
if (x.toLowerCase == "aix") { // ok, check for OSVERSION
checkNodeSeq(inventory, "HARDWARE", directChildren = false, optChild = Some("OSVERSION")).foldZIO(
_ => aixFailure,
kernelVersion => { // update the inventory to put it in the right place
(new scala.xml.transform.RuleTransformer(
new AddChildrenTo("OPERATINGSYSTEM", <KERNEL_VERSION>{kernelVersion}</KERNEL_VERSION>)
).transform(inventory).head).succeed
}
)
} else {
// should not be empty given checkOS, but if so, fails. Also fails is not aix.
failure
}
}
}
)
.map(n => n: NodeSeq)
}
)
.map(n => n: NodeSeq)
}
}

// for check kernel version
private[this] class AddChildrenTo(label: String, newChild: scala.xml.Node) extends scala.xml.transform.RewriteRule {
private class AddChildrenTo(label: String, newChild: scala.xml.Node) extends scala.xml.transform.RewriteRule {
override def transform(n: scala.xml.Node): scala.collection.Seq[Node] = n match {
case Elem(prefix, "OPERATINGSYSTEM", attribs, scope, child*) =>
Elem(prefix, label, attribs, scope, false, child ++ newChild: _*)
Elem(prefix, label, attribs, scope, minimizeEmpty = false, child ++ newChild: _*)
case other => other
}
}

private[this] def checkAgentType(agentNodeSeq: NodeSeq)(inventory: NodeSeq): IOResult[NodeSeq] = {
private def checkAgentType(agentNodeSeq: NodeSeq)(inventory: NodeSeq): IOResult[NodeSeq] = {
val agentTag = "AGENT_NAME"
val tag = "AGENTNAME"
for {
Expand All @@ -261,7 +263,7 @@ class PreInventoryParserCheckConsistency extends PreInventoryParser {
}

// since Rudder 6.0, an agent certificate is mandatory
private[this] def checkSecurityToken(agentNodeSeq: NodeSeq)(inventory: NodeSeq): IOResult[NodeSeq] = {
private def checkSecurityToken(agentNodeSeq: NodeSeq)(inventory: NodeSeq): IOResult[NodeSeq] = {
for {
tagHere <- checkWithinNodeSeq(agentNodeSeq, "AGENT_CERT")
.chainError(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ import zio.*
@RunWith(classOf[JUnitRunner])
class TestPreParsing extends Specification {

implicit private[this] class TestParser(pre: PreInventoryParser) {
implicit private class TestParser(pre: PreInventoryParser) {

def fromXml(checkName: String, is: InputStream): IOResult[NodeSeq] = {
ZIO.attempt(XML.load(is)).mapError(SystemError("error in test", _))
Expand Down