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

switch to Scala 3 #5701

Draft
wants to merge 9 commits into
base: branches/rudder/8.1
Choose a base branch
from
4 changes: 2 additions & 2 deletions webapp/sources/ldap-inventory/inventory-repository/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,11 @@ along with Rudder. If not, see <http://www.gnu.org/licenses/>.

<dependency>
<groupId>net.liftweb</groupId>
<artifactId>lift-json_${scala-binary-version}</artifactId>
<artifactId>lift-json_2.13</artifactId>
</dependency>
<dependency>
<groupId>net.liftweb</groupId>
<artifactId>lift-util_${scala-binary-version}</artifactId>
<artifactId>lift-util_2.13</artifactId>
</dependency>
</dependencies>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,7 @@ class FullInventoryRepositoryImpl(
.getTreeFilter(
dit.NODES.dn,
// scala 3.3.3 resolve U as String in NODE unless we tell it it's NodeId
buildSubTreeFilter[NodeId](dit.NODES.dn, nodeIds.toList, id => dit.NODES.NODE.dn(id).toString)
buildSubTreeFilter[NodeId](dit.NODES.dn, nodeIds.toList, id => (dit.NODES.NODE : UUID_ENTRY[NodeId]).dn(id).toString)
)
.notOptional(s"Missing node root tree")

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,8 @@ object CustomPropertiesSerialization {
def toCustomProperty: Either[Throwable, CustomProperty] = {
implicit val formats: Formats = DefaultFormats
try {
Right(Serialization.read[CustomProperty](json))
// avoid Compiler synthesis of Manifest and OptManifest is deprecated
Right(Serialization.read[CustomProperty](json)) : @annotation.nowarn("cat=deprecation")
} catch {
case ex: Exception => Left(ex)
}
Expand Down Expand Up @@ -758,7 +759,8 @@ class InventoryMapper(
implicit class Unserialize(json: String) {
def toCustomProperty: IOResult[CustomProperty] = {
implicit val formats: Formats = DefaultFormats
IOResult.attempt(Serialization.read[CustomProperty](json))
// avoid Compiler synthesis of Manifest and OptManifest is deprecated
IOResult.attempt(Serialization.read[CustomProperty](json) : @annotation.nowarn("cat=deprecation"))
}
}
}
Expand Down Expand Up @@ -1093,8 +1095,9 @@ class InventoryMapper(
lastLoggedUser = entry(A_LAST_LOGGED_USER)
lastLoggedUserTime = entry.getAsGTime(A_LAST_LOGGED_USER_TIME).map(_.dateTime)
publicKeys = entry.valuesFor(A_PKEYS).map(k => PublicKey(k))
ev = entry.valuesFor(A_EV).toSeq.map(Serialization.read[EnvironmentVariable](_))
process = entry.valuesFor(A_PROCESS).toSeq.map(Serialization.read[Process](_))
// avoid Compiler synthesis of Manifest and OptManifest is deprecated
ev = entry.valuesFor(A_EV).toSeq.map(Serialization.read[EnvironmentVariable](_) : @annotation.nowarn("cat=deprecation"))
process = entry.valuesFor(A_PROCESS).toSeq.map(Serialization.read[Process](_) : @annotation.nowarn("cat=deprecation"))
softwareIds = entry.valuesFor(A_SOFTWARE_DN).toSeq.flatMap(x => dit.SOFTWARE.SOFT.idFromDN(new DN(x)).toOption)
machineId <- mapSeqStringToMachineIdAndStatus(entry.valuesFor(A_CONTAINER_DN)).toList match {
case Nil => None.succeed
Expand Down
98 changes: 28 additions & 70 deletions webapp/sources/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -107,23 +107,6 @@ limitations under the License.
</extension>
</extensions>
<plugins>
<plugin>
<groupId>io.github.evis</groupId>
<artifactId>scalafix-maven-plugin_2.13</artifactId>
<version>0.1.8_0.11.0</version>
<dependencies>
<dependency>
<groupId>org.scala-lang</groupId>
<artifactId>scala-rewrites_2.13</artifactId>
<version>0.1.5</version>
</dependency>
<dependency>
<groupId>ch.epfl.scala</groupId>
<artifactId>scala3-migrate-rules_2.13</artifactId>
<version>0.6.2</version>
</dependency>
</dependencies>
</plugin>
<plugin>
<!-- Specify maven resources plugin version because to avoid this bug from plugin 3.2+ https://issues.apache.org/jira/browse/MRESOURCES-269
especially with maven 3.9 that uses version 3.3.0 of this plugin by default, see https://issues.rudder.io/issues/22403
Expand Down Expand Up @@ -166,56 +149,18 @@ limitations under the License.
</executions>
<configuration>
<scalaCompatVersion>${scala-binary-version}</scalaCompatVersion>
<scalaVersion>${scala-version}</scalaVersion>
<recompileMode>all</recompileMode>
<compilerPlugins>
<compilerPlugin>
<groupId>org.scalameta</groupId>
<artifactId>semanticdb-scalac_${scala-version}</artifactId>
<version>4.8.14</version>
</compilerPlugin>
</compilerPlugins>
<args>
<arg>-release:17</arg>
<arg>-dependencyfile</arg>
<arg>${basedir}/.scala_dependencies</arg>
<!-- standard warning, most of the one from https://tpolecat.github.io/2017/04/25/scalac-flags.html -->
<!-- corresponding scala line:
-language:existentials -language:higherKinds -language:implicitConversions
-Xlint:_,-nullary-unit,-missing-interpolator -Yno-adapted-args -Ywarn-dead-code -Ywarn-extra-implicit -Ywarn-inaccessible
-Ywarn-infer-any -Ywarn-nullary-override -Ywarn-numeric-widen -Ywarn-unused:imports -Ywarn-unused:locals -Ywarn-unused:privates
-->
<arg>-Xsource:3</arg>
<arg>-deprecation</arg> <!-- Emit warning and location for usages of deprecated APIs. -->
<arg>-explaintypes</arg> <!-- Explain type errors in more detail. -->
<arg>-feature</arg> <!-- Emit warning and location for usages of features that should be imported explicitly. -->
<arg>-unchecked</arg> <!-- Enable additional warnings where generated code depends on assumptions. -->
<arg>-language:existentials</arg> <!-- Existential types (besides wildcard types) can be written and inferred -->
<arg>-language:higherKinds</arg> <!-- Allow higher-kinded types -->
<arg>-language:implicitConversions</arg> <!-- Allow definition of implicit functions called views -->
<arg>-Xcheckinit</arg> <!-- Wrap field accessors to throw an exception on uninitialized access. -->
<!-- Xlint, minus non-local returns, nullary-units and missing interpolator (which brings false positive in Rudder).
For -byname-implicit, it's because of Doobie, see: https://gitter.im/tpolecat/doobie?at=5f59e618765d633c54e74d52
-->
<arg>-Xfatal-warnings</arg> <!-- Fail the compilation if there are any warnings. -->
<arg>-Xlint:_,-nonlocal-return,-nullary-unit,-missing-interpolator,-byname-implicit</arg>
<arg>-Ywarn-dead-code</arg> <!-- Warn when dead code is identified. -->

<arg>-Ywarn-extra-implicit</arg> <!-- Warn when more than one implicit parameter section is defined. -->
<arg>-Ywarn-numeric-widen</arg> <!-- Warn when numerics are widened. -->
<arg>-Ywarn-unused:imports</arg> <!-- Warn if an import selector is not referenced. -->
<arg>-Ywarn-unused:locals</arg> <!-- Warn if a local definition is unused. -->
<arg>-Ywarn-unused:privates</arg> <!-- Warn if a private member is unused. -->
<arg>-Ywarn-unused:implicits</arg> <!-- Warn if an implicit parameter is unused. -->
<arg>-Ywarn-unused:privates</arg> <!-- Warn if a private member is unused. -->
<arg>-Ybackend-parallelism</arg><arg>8</arg> <!-- Enable parallelization — change to desired number! -->
<arg>-Ycache-plugin-class-loader:last-modified</arg> <!-- Enables caching of classloaders for compiler plugins -->
<arg>-Ycache-macro-class-loader:last-modified</arg> <!-- and macro definitions. This can lead to performance improvements. -->

<!-- fastparse 3.0.1 emits false unused warning. We must silence them on related files. See: https://github.com/com-lihaoyi/fastparse/issues/285-->
<arg>-Wconf:cat=unused-nowarn&amp;src=com/normation/utils/Version.scala:s,cat=unused-nowarn&amp;src=com/normation/rudder/services/policies/InterpolatedValueCompiler.scala:s</arg>

<!-- this warning is no an actual issue, our smart constructor usage is fine with a scala 3 compiler-->
<arg>-Wconf:msg=constructor modifiers are assumed by synthetic:s</arg>
<arg>-Xmax-inlines</arg><arg>100</arg>
</args>
<jvmArgs>
<jvmArg>-Xmx${jvmArg-Xmx}</jvmArg>
Expand Down Expand Up @@ -414,16 +359,16 @@ limitations under the License.
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>

<!-- Maven plugin version -->
<scala-maven-plugin-version>4.7.2</scala-maven-plugin-version>
<scala-maven-plugin-version>4.8.1</scala-maven-plugin-version>

<!-- Libraries version that MUST be used in all children project -->

<current-year>2024</current-year>
<rudder-major-version>8.1</rudder-major-version>
<rudder-version>8.1.3-SNAPSHOT</rudder-version>

<scala-version>2.13.12</scala-version>
<scala-binary-version>2.13</scala-binary-version>
<scala-version>3.3.3</scala-version>
<scala-binary-version>3</scala-binary-version>
<!-- lift force us to remain with 1.3.0 because of
java.lang.NoSuchMethodError: 'scala.collection.mutable.Stack scala.xml.parsing.NoBindingFactoryAdapter.scopeStack()'net.liftweb.util.Html5Parser.$anonfun$parse$1(HtmlParser.scala:373)
And scala-xml 2.1.0 has non-trivial change on parsing semantic, can't
Expand Down Expand Up @@ -465,7 +410,7 @@ limitations under the License.
<reflections-version>0.10.2</reflections-version>
<graalvm-version>23.1.1</graalvm-version>
<chimney-version>0.8.3</chimney-version>
<cron4s-version>0.6.1</cron4s-version>
<cron4s-version>0.7.0</cron4s-version>
<ipaddress-version>5.4.0</ipaddress-version>
<snakeyaml-version>2.2</snakeyaml-version>

Expand Down Expand Up @@ -524,26 +469,31 @@ limitations under the License.
<dependency>
<groupId>org.scala-lang</groupId>
<artifactId>scala-library</artifactId>
<version>${scala-version}</version>
<version>2.13.13</version>
</dependency>
<dependency>
<groupId>org.scala-lang</groupId>
<artifactId>scala-compiler</artifactId>
<artifactId>scala3-library_${scala-binary-version}</artifactId>
<version>${scala-version}</version>
</dependency>
<dependency>
<groupId>org.scala-lang</groupId>
<artifactId>scala-reflect</artifactId>
<artifactId>scala-compiler_${scala-binary-version}</artifactId>
<version>${scala-version}</version>
</dependency>
<dependency>
<groupId>org.scala-lang.modules</groupId>
<artifactId>scala-parser-combinators_3</artifactId>
<version>2.3.0</version>
</dependency>
<dependency>
<groupId>org.scala-lang</groupId>
<artifactId>scalap</artifactId>
<artifactId>scala-reflect_${scala-binary-version}</artifactId>
<version>${scala-version}</version>
</dependency>
<dependency>
<groupId>org.scala-lang.modules</groupId>
<artifactId>scala-xml_${scala-binary-version}</artifactId>
<artifactId>scala-xml_2.13</artifactId>
<version>${scala-xml-version}</version>
</dependency>
<dependency>
Expand Down Expand Up @@ -590,7 +540,7 @@ limitations under the License.
</dependency>
<dependency>
<groupId>net.liftweb</groupId>
<artifactId>lift-common_${scala-binary-version}</artifactId>
<artifactId>lift-common_2.13</artifactId>
<version>${lift-version}</version>
<exclusions>
<exclusion>
Expand All @@ -601,27 +551,35 @@ limitations under the License.
<artifactId>log4j</artifactId>
<groupId>log4j</groupId>
</exclusion>
<exclusion>
<groupId>org.scala-lang.modules</groupId>
<artifactId>scala-parser-combinators_2.13</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>net.liftweb</groupId>
<artifactId>lift-json_${scala-binary-version}</artifactId>
<artifactId>lift-json_2.13</artifactId>
<version>${lift-version}</version>
</dependency>
<dependency>
<groupId>net.liftweb</groupId>
<artifactId>lift-util_${scala-binary-version}</artifactId>
<artifactId>lift-util_2.13</artifactId>
<version>${lift-version}</version>
<exclusions>
<exclusion>
<artifactId>mail</artifactId>
<groupId>javax.mail</groupId>
</exclusion>
<exclusion>
<groupId>org.scala-lang.modules</groupId>
<artifactId>scala-parser-combinators_2.13</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>net.liftweb</groupId>
<artifactId>lift-webkit_${scala-binary-version}</artifactId>
<artifactId>lift-webkit_2.13</artifactId>
<version>${lift-version}</version>
<exclusions>
<exclusion>
Expand Down
4 changes: 2 additions & 2 deletions webapp/sources/rudder/rudder-core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -239,12 +239,12 @@ along with Rudder. If not, see <http://www.gnu.org/licenses/>.

<dependency>
<groupId>net.liftweb</groupId>
<artifactId>lift-webkit_${scala-binary-version}</artifactId>
<artifactId>lift-webkit_2.13</artifactId>
<version>${lift-version}</version>
</dependency>
<dependency>
<groupId>net.liftweb</groupId>
<artifactId>lift-json-ext_${scala-binary-version}</artifactId>
<artifactId>lift-json-ext_2.13</artifactId>
<version>${lift-version}</version>
</dependency>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import io.scalaland.chimney.Transformer
import org.joda.time.DateTime
import scala.xml.*

final case class EventActor(name: String) extends AnyVal
final case class EventActor(name: String) // FIXME: put back AnyVal after fixing json codec

/*
* Some data to hold common information about an event, and that will likely be used
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,8 @@ object AutomaticReportsCleaning {
nodes <- ldap.searchOne(new DN("ou=Nodes,cn=rudder-configuration"), BuildFilter.HAS(runIntervalAttr), runIntervalAttr)
ints <- ZIO.foreach(nodes) { node => // don't fail on parsing error, just return 0
(try {
parse(node(runIntervalAttr).getOrElse("{}")).extract[RunInterval].interval
// avoid Compiler synthesis of Manifest and OptManifest is deprecated
parse(node(runIntervalAttr).getOrElse("{}")).extract[RunInterval].interval : @annotation.nowarn("cat=deprecation")
} catch {
case ex: Exception => 0
}).succeed
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ import org.joda.time.Duration
import zio.json.*
import zio.json.internal.Write

import scala.annotation.nowarn

final case class NodeModeConfig(
globalComplianceMode: ComplianceMode,
nodeHeartbeatPeriod: Option[Int], // if it is defined, then it does override (ie if override = false => None)
Expand Down Expand Up @@ -660,6 +662,7 @@ object NodeConfigIdSerializer {
else {
implicit val formats = DefaultFormats
val configs = parse(ids)
// avoid Compiler synthesis of Manifest and OptManifest is deprecated
.extractOrElse[List[Map[String, String]]](List())
.flatMap {
case map =>
Expand All @@ -670,7 +673,7 @@ object NodeConfigIdSerializer {
}
}
.flatten
.sortBy(_._2.getMillis)
.sortBy(_._2.getMillis) : @nowarn("cat=deprecation")

// build interval
configs match {
Expand Down
Loading