Skip to content

Scala 3 support #186

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

Merged
merged 7 commits into from
Mar 8, 2021
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
.idea
**/*.iml
**/target/
.bsp/
release.properties
pom.xml.releaseBackup
pom.xml.versionsBackup
4 changes: 3 additions & 1 deletion .scalafmt.conf
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
version = 2.7.5

preset=default
preset=default

runner.dialect = dotty
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ See also the [CHANGELOG](https://github.com/cucumber/cucumber-jvm/blob/master/CH

### Added

- [Scala] Support Scala 3 RC1
- Check out the [v7.x upgrade guide](./docs/upgrade_v7.md)

### Changed

- [Build] Use Github Actions instead of Travis CI
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ The minor version might differ because Cucumber Scala may add Scala-related feat

- [Installation](./docs/install.md)
- Upgrade notes
- [Version 7.x](docs/upgrade_v7.md)
- [Version 6.x](docs/upgrade_v6.md)
- [Version 5.x](docs/upgrade_v5.md)
- Documentation
Expand Down
35 changes: 29 additions & 6 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ ThisBuild / homepage := Some(
val scala211 = "2.11.12"
val scala212 = "2.12.13"
val scala213 = "2.13.5"
val scala3 = "3.0.0-RC1"

scalaVersion := scala213

Expand All @@ -52,6 +53,7 @@ lazy val commonSettings = Seq(
case Some((2, 11)) => ScalacOptions.scalacOptions211
case Some((2, 12)) => ScalacOptions.scalacOptions212
case Some((2, 13)) => ScalacOptions.scalacOptions213
case Some((3, 0)) => ScalacOptions.scalacOptions3
case _ => Seq()
}
}
Expand All @@ -75,23 +77,44 @@ lazy val cucumberScala = (projectMatrix in file("cucumber-scala"))
libraryDependencies ++= Seq(
"io.cucumber" % "cucumber-core" % cucumberVersion,
// Users have to provide it (for JacksonDefaultDataTableTransformer)
"com.fasterxml.jackson.module" %% "jackson-module-scala" % jacksonVersion % Provided,
("com.fasterxml.jackson.module" %% "jackson-module-scala" % jacksonVersion % Provided)
.withDottyCompat(scalaVersion.value),
"junit" % "junit" % junitVersion % Test,
"io.cucumber" % "cucumber-junit" % cucumberVersion % Test,
"org.mockito" %% "mockito-scala" % mockitoScalaVersion % Test
("org.mockito" %% "mockito-scala" % mockitoScalaVersion % Test)
.withDottyCompat(scalaVersion.value)
),
libraryDependencies ++= {
CrossVersion.partialVersion(scalaVersion.value) match {
case Some((2, n)) if n <= 12 =>
List("org.scala-lang.modules" %% "scala-collection-compat" % "2.4.2")
case Some((3, 0)) =>
List("io.github.gaeljw" %% "typetrees" % "0.2.0")
case _ => Nil
}
},
unmanagedSourceDirectories in Compile ++= {
val sourceDir = (sourceDirectory in Compile).value
CrossVersion.partialVersion(scalaVersion.value) match {
case Some((2, n)) if n <= 11 => Seq(sourceDir / "scala-2.11")
case _ => Seq()
case Some((2, n)) if n <= 11 =>
Seq(sourceDir / "scala-2", sourceDir / "scala-2.11")
case Some((2, n)) if n > 11 =>
Seq(sourceDir / "scala-2")
case Some((3, 0)) =>
Seq(sourceDir / "scala-3")
case _ =>
Seq()
}
},
unmanagedSourceDirectories in Test ++= {
val testSourceDir = (sourceDirectory in Test).value
CrossVersion.partialVersion(scalaVersion.value) match {
case Some((2, _)) =>
Seq(testSourceDir / "scala-2")
case Some((3, 0)) =>
Seq(testSourceDir / "scala-3")
case _ =>
Seq()
}
},
// Generate I18n traits
Expand All @@ -102,7 +125,7 @@ lazy val cucumberScala = (projectMatrix in file("cucumber-scala"))
Seq(file)
}.taskValue
)
.jvmPlatform(scalaVersions = Seq(scala213, scala212, scala211))
.jvmPlatform(scalaVersions = Seq(scala3, scala213, scala212, scala211))

// Examples project
lazy val examples = (projectMatrix in file("examples"))
Expand All @@ -116,7 +139,7 @@ lazy val examples = (projectMatrix in file("examples"))
publishArtifact := false
)
.dependsOn(cucumberScala % Test)
.jvmPlatform(scalaVersions = Seq(scala213, scala212))
.jvmPlatform(scalaVersions = Seq(scala3, scala213, scala212))

// Version policy check

Expand Down
25 changes: 24 additions & 1 deletion cucumber-scala/src/main/codegen/gen.scala
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@

/*
* Generates the evil looking apply methods in ScalaDsl#StepBody for Function1 to Function22
* Generates the evil looking apply methods in StepDsl#StepBody for Function1 to Function22
*/
for (i <- 1 to 22) {
val ts = (1 to i).map("T".+).mkString(", ")
Expand All @@ -15,6 +15,29 @@ for (i <- 1 to 22) {
println(p1 + p2 + ": Unit = { " + register + pf + otherwise + closeRegister + "\n")
}

/*
* Generates the evil looking apply methods in StepDsl#StepBody for Function1 to Function22
* Scala 3
*/
for (i <- 1 to 22) {
val ts = (1 to i).map("T".+).mkString(", ")
val tagsDef = (1 to i).map(n => s"val t$n: TypeTreeTag = typeTreeTag[T$n]").mkString("\n")
val tagsParam = (1 to i).map(n => s"t$n").mkString(", ")
val listParams = (1 to i).map("a" + _ + ":AnyRef").mkString(", ")
val pf = (1 to i).map(n => "a" + n + ".asInstanceOf[T" + n + "]").mkString(",\n ")

println(s"""
|inline def apply[$ts](f: ($ts) => Any): Unit = {
| $tagsDef
| register($tagsParam) {
| case List($listParams) =>
| f($pf)
| case _ =>
| throw new IncorrectStepDefinitionException()
| }
|}""".stripMargin)
}

/*
* Generates the apply methods in ParameterTypeDsl for Function1 to Function22
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package io.cucumber.scala

import io.github.gaeljw.typetrees.TypeTreeTag
import java.lang.reflect.{ParameterizedType, Type}

object ScalaTypeHelper {

def asJavaType(tag: TypeTreeTag): Type = {
if (tag.args.isEmpty) {
tag.self.runtimeClass
} else {
new ScalaParameterizedType(tag)
}
}

}

class ScalaParameterizedType(tag: TypeTreeTag) extends ParameterizedType {

override def getActualTypeArguments: Array[Type] =
tag.args.map(ScalaTypeHelper.asJavaType).toArray

override def getRawType: Type = tag.self.runtimeClass

override def getOwnerType: Type = null

}
Loading