Skip to content

Commit fabee5b

Browse files
committed
Introduce gwen.logLevel.deprecations to control how deprecations are reported
1 parent b1eb201 commit fabee5b

File tree

8 files changed

+68
-22
lines changed

8 files changed

+68
-22
lines changed

CHANGELOG

+9
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,12 @@
1+
3.63.0
2+
======
3+
19 September 2024
4+
- Introduce `gwen.logLevel.deprecations` to control how deprecations are reported.
5+
- Supported values include:
6+
- `warn` to log deprecations as warnings (default)
7+
- `error` to raise and report deprecations as errors
8+
- `none` to suppress logging or reporting of deprecation messages (no operation)
9+
110
3.62.0
211
======
312
18 September 2024

build.sbt

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
enablePlugins(GitVersioning)
22

33
// gwen core version
4-
val gwenVersion = "3.62.0"
4+
val gwenVersion = "3.63.0"
55

66
git.baseVersion := gwenVersion
77
git.useGitDescribe := true

src/main/resources/gwen.conf

+3
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,9 @@ gwen {
112112
}
113113
mode = "declarative" # declarative|imperative
114114
}
115+
logLevel {
116+
deprecations = "warn" # warn|error|none
117+
}
115118
mask {
116119
char = "*"
117120
}

src/main/scala/gwen/core/GwenOptions.scala

+2-2
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ object GwenOptions {
163163

164164
opt[String]('p', "properties") action {
165165
(ps, c) =>
166-
Deprecation.warn("CLI option", "-p|--properties", Some("-c|--conf"))
166+
Deprecation.log("CLI option", "-p|--properties", Some("-c|--conf"))
167167
c.copy(settingsFiles = c.settingsFiles ++ ps.split(",").toList.map(new File(_)))
168168
} validate { ps =>
169169
((ps.split(",") flatMap { f =>
@@ -184,7 +184,7 @@ object GwenOptions {
184184
(fs, c) =>
185185
val formats = fs.split(",").toList.map(f => ReportFormat.valueOf(f))
186186
formats.find(_ == ReportFormat.rp) foreach { format =>
187-
Deprecation.warn("Report Portal option", s"-f|--format = $format", None)
187+
Deprecation.log("Report Portal option", s"-f|--format = $format", None)
188188
}
189189
c.copy(reportFormats = formats)
190190
} valueName "reports" text s"""|Report formats to include in output (comma separated)

src/main/scala/gwen/core/GwenSettings.scala

+23
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import gwen.core.state.StateLevel
2323
import scala.util.Try
2424

2525
import java.io.File
26+
import java.util.logging.Level
2627

2728
/**
2829
* Provides access to all Gwen settings.
@@ -57,6 +58,7 @@ object GwenSettings {
5758
`gwen.state.level`
5859
`gwen.video.dir`
5960
`gwen.video.timeoutSecs`
61+
`gwen.logLevel.deprecations`
6062
}
6163

6264
/**
@@ -373,4 +375,25 @@ object GwenSettings {
373375
Settings.getBoolean("gwen.error.messages.inline.locators")
374376
}
375377

378+
/**
379+
* Provides access to the `gwen.behavior.rules` setting used to determine whether strict,
380+
* or lenient rules around Given-When-Then usage should be enforced in features (default value is
381+
* `strict`). When strict, scenarios and backgrounds must contain Given-When-Then ordered steps
382+
* and Given steps set context, When steps must perform actions, and Then or But steps must perform
383+
* assertions. When `leneient` no behavioral rules are enforced. Note that `gwen.behavior.rules` is
384+
* an alias for this setting.
385+
*/
386+
def `gwen.logLevel.deprecations`: Level = {
387+
Settings.getOpt("gwen.logLevel.deprecations") map { level =>
388+
level match {
389+
case "warn" => Level.WARNING
390+
case "error" => Level.SEVERE
391+
case "none" => Level.OFF
392+
case _ => Errors.invalidSettingError("gwen.logLevel.deprecations", level, "Valid value are warn|error|none")
393+
}
394+
} getOrElse {
395+
Level.WARNING
396+
}
397+
}
398+
376399
}

src/main/scala/gwen/core/Predefs.scala

+18-9
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ import javax.xml.transform.TransformerFactory
5555
import javax.xml.transform.stream.StreamResult
5656
import javax.xml.transform.stream.StreamSource
5757
import javax.xml.transform.OutputKeys
58+
import java.util.logging.Level
5859

5960
/** Predefs and extension methods avaiable wherever this page is imported. */
6061

@@ -456,18 +457,26 @@ object UUIDGenerator {
456457
}
457458

458459
object Deprecation extends LazyLogging {
459-
def warn(category: String, oldWay: String, newWayOpt: Option[String]): Unit = {
460-
println(
461-
s"""|
462-
|WARNING: $category is deprecated and will be unsupported in next major Gwen 4 release
463-
|${createMsg(category, oldWay, newWayOpt)}
464-
|""".stripMargin
465-
)
460+
import java.util.logging.Level
461+
import org.fusesource.jansi.Ansi._
462+
def log(category: String, oldWay: String, newWayOpt: Option[String]): Unit = {
463+
val level = GwenSettings.`gwen.logLevel.deprecations`
464+
val msg = s"""|${if (level == Level.WARNING) s"$level: " else ""}$category is deprecated and will not be unsupported in next major release
465+
|${createMsg(category, oldWay, newWayOpt)}
466+
|""".stripMargin
467+
level match {
468+
case Level.WARNING =>
469+
val colors = ConsoleColors.isEnabled
470+
println(s"\n${if (colors) ansi.fg(Color.YELLOW) else ""}$msg${if (colors) ansi.reset else ""}")
471+
case Level.SEVERE =>
472+
Errors.deprecatedError(msg)
473+
case _ => // noop
474+
}
466475
}
476+
467477
def fail(category: String, oldWay: String, newWayOpt: Option[String]): Unit = {
468478
Errors.deprecatedError(
469-
s"""|
470-
|$category is deprecated and no longer supported
479+
s"""|$category is deprecated and no longer supported
471480
|${createMsg(category, oldWay, newWayOpt)}
472481
|""".stripMargin
473482
)

src/main/scala/gwen/core/eval/EvalEngine.scala

+10-10
Original file line numberDiff line numberDiff line change
@@ -82,38 +82,38 @@ abstract class EvalEngine[T <: EvalContext] extends NodeEventDispatcher with Uni
8282
case r"""(.+)$doStep if(?:(?!\bif\b))( not)?$negation (.+)$condition""" if !condition.contains('"') =>
8383
Some(new IfCondition(doStep, condition, Option(negation).isDefined, defaultConditionTimeoutSecs, this))
8484
case r"""(.+?)$doStep (until|while)$operation (.+?)$attribute is( not)?$negation defined using no delay and (.+?)$timeoutPeriod (minute|second|millisecond)$timeoutUnit (timeout|wait)$timeoutLiteral""" =>
85-
Deprecation.warn("Step variant", s"using no delay and $timeoutPeriod $timeoutUnit $timeoutLiteral", Some(s"@Delay('0s') @Timeout('$timeoutPeriod${Map("minute" -> "m", "second" -> "s", "millisecond" -> "ms")(timeoutUnit)}') annotations"))
85+
Deprecation.log("Overloaded step", s"using no delay and $timeoutPeriod $timeoutUnit $timeoutLiteral", Some(s"@Delay('0s') @Timeout('$timeoutPeriod${Map("minute" -> "m", "second" -> "s", "millisecond" -> "ms")(timeoutUnit)}') annotations"))
8686
Some(new RepeatIfDefined(doStep, operation, attribute, Option(negation).isDefined, Duration.Zero, Duration(timeoutPeriod.toLong, timeoutUnit), defaultConditionTimeoutSecs, this))
8787
case r"""(.+?)$doStep (until|while)$operation (.+?)$attribute is( not)?$negation defined using no delay""" =>
88-
Deprecation.warn("Step variant", s"using no delay", Some(s"@Delay('0s') annotation"))
88+
Deprecation.log("Overloaded step", s"using no delay", Some(s"@Delay('0s') annotation"))
8989
Some(new RepeatIfDefined(doStep, operation, attribute, Option(negation).isDefined, Duration.Zero, step.timeoutOpt.getOrElse(defaultRepeatTimeout(defaultRepeatDelay)), defaultConditionTimeoutSecs, this))
9090
case r"""(.+?)$doStep (until|while)$operation (.+?)$attribute is( not)?$negation defined using (.+?)$delayPeriod (second|millisecond)$delayUnit delay and (.+?)$timeoutPeriod (minute|second|millisecond)$timeoutUnit (timeout|wait)$timeoutLiteral""" if doStep != "I wait" =>
91-
Deprecation.warn("Step variant", s"using $delayPeriod $delayUnit delay and $timeoutPeriod $timeoutUnit $timeoutLiteral", Some(s"@Delay('$delayPeriod${Map("second" -> "s", "millisecond" -> "ms")(delayUnit)}') @Timeout('$timeoutPeriod${Map("minute" -> "m", "second" -> "s", "millisecond" -> "ms")(timeoutUnit)}') annotations"))
91+
Deprecation.log("Overloaded step", s"using $delayPeriod $delayUnit delay and $timeoutPeriod $timeoutUnit $timeoutLiteral", Some(s"@Delay('$delayPeriod${Map("second" -> "s", "millisecond" -> "ms")(delayUnit)}') @Timeout('$timeoutPeriod${Map("minute" -> "m", "second" -> "s", "millisecond" -> "ms")(timeoutUnit)}') annotations"))
9292
Some(new RepeatIfDefined(doStep, operation, attribute, Option(negation).isDefined, Duration(delayPeriod.toLong, delayUnit), Duration(timeoutPeriod.toLong, timeoutUnit), defaultConditionTimeoutSecs, this))
9393
case r"""(.+?)$doStep (until|while)$operation (.+?)$attribute is( not)?$negation defined using (.+?)$delayPeriod (second|millisecond)$delayUnit delay""" if doStep != "I wait" =>
94-
Deprecation.warn("Step variant", s"using $delayPeriod $delayUnit delay", Some(s"@Delay('$delayPeriod${Map("second" -> "s", "millisecond" -> "ms")(delayUnit)}') annotation"))
94+
Deprecation.log("Overloaded step", s"using $delayPeriod $delayUnit delay", Some(s"@Delay('$delayPeriod${Map("second" -> "s", "millisecond" -> "ms")(delayUnit)}') annotation"))
9595
val delayDuration = Duration(delayPeriod.toLong, delayUnit)
9696
Some(new RepeatIfDefined(doStep, operation, attribute, Option(negation).isDefined, delayDuration, defaultRepeatTimeout(delayDuration), defaultConditionTimeoutSecs, this))
9797
case r"""(.+?)$doStep (until|while)$operation (.+?)$attribute is( not)?$negation defined using (.+?)$timeoutPeriod (minute|second|millisecond)$timeoutUnit (timeout|wait)$timeoutLiteral""" if doStep != "I wait" =>
98-
Deprecation.warn("Step variant", s"using $timeoutPeriod $timeoutUnit $timeoutLiteral", Some(s"@Timeout('$timeoutPeriod${Map("minute" -> "m", "second" -> "s", "millisecond" -> "ms")(timeoutUnit)}') annotation"))
98+
Deprecation.log("Overloaded step", s"using $timeoutPeriod $timeoutUnit $timeoutLiteral", Some(s"@Timeout('$timeoutPeriod${Map("minute" -> "m", "second" -> "s", "millisecond" -> "ms")(timeoutUnit)}') annotation"))
9999
Some(new RepeatIfDefined(doStep, operation, attribute, Option(negation).isDefined, step.delayOpt.getOrElse(defaultRepeatDelay), Duration(timeoutPeriod.toLong, timeoutUnit), defaultConditionTimeoutSecs, this))
100100
case r"""(.+?)$doStep (until|while)$operation (.+?)$attribute is( not)?$negation defined""" if (doStep != "I wait" && !step.expression.matches(""".*".*(until|while).*".*""")) =>
101101
Some(new RepeatIfDefined(doStep, operation, attribute, Option(negation).isDefined, step.delayOpt.getOrElse(defaultRepeatDelay), step.timeoutOpt.getOrElse(defaultRepeatTimeout(defaultRepeatDelay)), defaultConditionTimeoutSecs, this))
102102
case r"""(.+?)$doStep (until|while)$operation (.+?)$condition using no delay and (.+?)$timeoutPeriod (minute|second|millisecond)$timeoutUnit (timeout|wait)$timeoutLiteral""" if !condition.contains('"') =>
103-
Deprecation.warn("Step variant", s"using no delay and $timeoutPeriod $timeoutUnit $timeoutLiteral", Some(s"@Delay('0s') @Timeout('$timeoutPeriod${Map("minute" -> "m", "second" -> "s", "millisecond" -> "ms")(timeoutUnit)}') annotations"))
103+
Deprecation.log("Overloaded step", s"using no delay and $timeoutPeriod $timeoutUnit $timeoutLiteral", Some(s"@Delay('0s') @Timeout('$timeoutPeriod${Map("minute" -> "m", "second" -> "s", "millisecond" -> "ms")(timeoutUnit)}') annotations"))
104104
Some(new RepeatJS(doStep, operation, condition, Duration.Zero, Duration(timeoutPeriod.toLong, timeoutUnit), defaultConditionTimeoutSecs, this))
105105
case r"""(.+?)$doStep (until|while)$operation (.+?)$condition using no delay""" if !condition.contains('"') =>
106-
Deprecation.warn("Step variant", s"using no delay", Some(s"@Delay('0s') annotation"))
106+
Deprecation.log("Overloaded step", s"using no delay", Some(s"@Delay('0s') annotation"))
107107
Some(new RepeatJS(doStep, operation, condition, Duration.Zero, step.timeoutOpt.getOrElse(defaultRepeatTimeout(defaultRepeatDelay)), defaultConditionTimeoutSecs, this))
108108
case r"""(.+?)$doStep (until|while)$operation (.+?)$condition using (.+?)$delayPeriod (second|millisecond)$delayUnit delay and (.+?)$timeoutPeriod (minute|second|millisecond)$timeoutUnit (timeout|wait)$timeoutLiteral""" if doStep != "I wait" && !condition.contains('"') =>
109-
Deprecation.warn("Step variant", s"using $delayPeriod $delayUnit delay and $timeoutPeriod $timeoutUnit $timeoutLiteral", Some(s"@Delay('$delayPeriod${Map("second" -> "s", "millisecond" -> "ms")(delayUnit)}') @Timeout('$timeoutPeriod${Map("minute" -> "m", "second" -> "s", "millisecond" -> "ms")(timeoutUnit)}') annotations"))
109+
Deprecation.log("Overloaded step", s"using $delayPeriod $delayUnit delay and $timeoutPeriod $timeoutUnit $timeoutLiteral", Some(s"@Delay('$delayPeriod${Map("second" -> "s", "millisecond" -> "ms")(delayUnit)}') @Timeout('$timeoutPeriod${Map("minute" -> "m", "second" -> "s", "millisecond" -> "ms")(timeoutUnit)}') annotations"))
110110
Some(new RepeatJS(doStep, operation, condition, Duration(delayPeriod.toLong, delayUnit), Duration(timeoutPeriod.toLong, timeoutUnit), defaultConditionTimeoutSecs, this))
111111
case r"""(.+?)$doStep (until|while)$operation (.+?)$condition using (.+?)$delayPeriod (second|millisecond)$delayUnit delay""" if doStep != "I wait" && !condition.contains('"') =>
112-
Deprecation.warn("Step variant", s"using $delayPeriod $delayUnit delay", Some(s"@Delay('$delayPeriod${Map("second" -> "s", "millisecond" -> "ms")(delayUnit)}') annotation"))
112+
Deprecation.log("Overloaded step", s"using $delayPeriod $delayUnit delay", Some(s"@Delay('$delayPeriod${Map("second" -> "s", "millisecond" -> "ms")(delayUnit)}') annotation"))
113113
val delayDuration = Duration(delayPeriod.toLong, delayUnit)
114114
Some(new RepeatJS(doStep, operation, condition, delayDuration, defaultRepeatTimeout(delayDuration), defaultConditionTimeoutSecs, this))
115115
case r"""(.+?)$doStep (until|while)$operation (.+?)$condition using (.+?)$timeoutPeriod (minute|second|millisecond)$timeoutUnit (timeout|wait)$timeoutLiteral""" if doStep != "I wait" && !condition.contains('"') =>
116-
Deprecation.warn("Step variant", s"using $timeoutPeriod $timeoutUnit $timeoutLiteral", Some(s"@Timeout('$timeoutPeriod${Map("minute" -> "m", "second" -> "s", "millisecond" -> "ms")(timeoutUnit)}') annotation"))
116+
Deprecation.log("Overloaded step", s"using $timeoutPeriod $timeoutUnit $timeoutLiteral", Some(s"@Timeout('$timeoutPeriod${Map("minute" -> "m", "second" -> "s", "millisecond" -> "ms")(timeoutUnit)}') annotation"))
117117
Some(new RepeatJS(doStep, operation, condition, step.delayOpt.getOrElse(defaultRepeatDelay), Duration(timeoutPeriod.toLong, timeoutUnit), defaultConditionTimeoutSecs, this))
118118
case r"""(.+?)$doStep (until|while)$operation (.+?)$condition""" if (doStep != "I wait" && !condition.contains('"') && !step.expression.matches(""".*".*(until|while).*".*""")) =>
119119
Some(new RepeatJS(doStep, operation, condition, step.delayOpt.getOrElse(defaultRepeatDelay), step.timeoutOpt.getOrElse(defaultRepeatTimeout(defaultRepeatDelay)), defaultConditionTimeoutSecs, this))

src/test/scala/gwen/core/GwenSettingsTest.scala

+2
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ import gwen.core.report.rp.RPSettings
2727
import gwen.core.state.StateLevel
2828

2929
import org.scalatest.matchers.should.Matchers
30+
import java.util.logging.Level
3031

3132
class GwenSettingsTest extends BaseTest with Matchers {
3233

@@ -66,6 +67,7 @@ class GwenSettingsTest extends BaseTest with Matchers {
6667
GwenSettings.`gwen.video.timeoutSecs` should be (10)
6768
GwenSettings.`gwen.dryRun.limit.tableData.outline.examples.records` should be (Integer.MAX_VALUE)
6869
GwenSettings.`gwen.error.messages.inline.locators` should be (false)
70+
GwenSettings.`gwen.logLevel.deprecations` should be (Level.WARNING)
6971
}
7072
}
7173

0 commit comments

Comments
 (0)