@@ -4,12 +4,8 @@ import scala.build.Logger
4
4
import scala .build .errors .Diagnostic .TextEdit
5
5
import scala .build .internal .Constants
6
6
import scala .build .internal .util .WarningMessages .{deprecatedToolkitLatest , deprecatedWarning }
7
- import scala .build .preprocessing .directives .{
8
- DirectiveHandler ,
9
- DirectiveUtil ,
10
- StrictDirective ,
11
- Toolkit
12
- }
7
+ import scala .build .options .SuppressWarningOptions
8
+ import scala .build .preprocessing .directives .{DirectiveHandler , StrictDirective , Toolkit }
13
9
import scala .build .warnings .DeprecatedWarning
14
10
15
11
object DeprecatedDirectives {
@@ -20,27 +16,27 @@ object DeprecatedDirectives {
20
16
* @param values
21
17
* representation of deprecated value
22
18
*/
23
- case class DirectiveTemplate (keys : Seq [String ], values : Option [Seq [String ]]) {
19
+ private case class DirectiveTemplate (keys : Seq [String ], values : Option [Seq [String ]]) {
24
20
def appliesTo (foundKey : String , foundValues : Seq [String ]): Boolean =
25
21
(keys.isEmpty || keys.contains(foundKey)) &&
26
22
// FIXME values.contains is not perfect, but is enough for now since we don't look for specific multiple values
27
23
(values.isEmpty || values.contains(foundValues))
28
24
}
29
25
30
- type WarningAndReplacement = (String , DirectiveTemplate )
26
+ private type WarningAndReplacement = (String , DirectiveTemplate )
31
27
32
28
private def keyReplacement (replacement : String )(warning : String ): WarningAndReplacement =
33
29
(warning, DirectiveTemplate (Seq (replacement), None ))
34
30
35
31
private def valueReplacement (replacements : String * )(warning : String ): WarningAndReplacement =
36
32
(warning, DirectiveTemplate (Nil , Some (replacements.toSeq)))
37
33
38
- private def allAliasesOf (key : String , handler : DirectiveHandler [_ ]): Seq [String ] =
34
+ private def allAliasesOf (key : String , handler : DirectiveHandler [? ]): Seq [String ] =
39
35
handler.keys.find(_.nameAliases.contains(key))
40
36
.toSeq
41
37
.flatMap(_.nameAliases)
42
38
43
- private def allKeysFrom (handler : DirectiveHandler [_ ]): Seq [String ] =
39
+ private def allKeysFrom (handler : DirectiveHandler [? ]): Seq [String ] =
44
40
handler.keys.flatMap(_.nameAliases)
45
41
46
42
private val deprecatedCombinationsAndReplacements = Map [DirectiveTemplate , WarningAndReplacement ](
@@ -73,33 +69,35 @@ object DeprecatedDirectives {
73
69
)
74
70
)
75
71
76
- def warningAndReplacement (directive : StrictDirective ): Option [WarningAndReplacement ] =
72
+ private def warningAndReplacement (directive : StrictDirective ): Option [WarningAndReplacement ] =
77
73
deprecatedCombinationsAndReplacements
78
74
.find(_._1.appliesTo(directive.key, directive.toStringValues))
79
75
.map(_._2) // grab WarningAndReplacement
80
76
81
77
def issueWarnings (
82
78
path : Either [String , os.Path ],
83
79
directives : Seq [StrictDirective ],
80
+ suppressWarningOptions : SuppressWarningOptions ,
84
81
logger : Logger
85
- ) =
86
- directives.map(d => d -> warningAndReplacement(d))
87
- .foreach {
88
- case (directive, Some (warning, replacement)) =>
89
- val newKey = replacement.keys.headOption.getOrElse(directive.key)
90
- val newValues = replacement.values.getOrElse(directive.toStringValues)
91
- val newText = s " $newKey ${newValues.mkString(" " )}"
82
+ ): Unit =
83
+ if ! suppressWarningOptions.suppressDeprecatedFeatureWarning.getOrElse(false ) then
84
+ directives.map(d => d -> warningAndReplacement(d))
85
+ .foreach {
86
+ case (directive, Some (warning, replacement)) =>
87
+ val newKey = replacement.keys.headOption.getOrElse(directive.key)
88
+ val newValues = replacement.values.getOrElse(directive.toStringValues)
89
+ val newText = s " $newKey ${newValues.mkString(" " )}"
92
90
93
- // TODO use key and/or value positions instead of whole directive
94
- val position = directive.position(path)
91
+ // TODO use key and/or value positions instead of whole directive
92
+ val position = directive.position(path)
95
93
96
- val diagnostic = DeprecatedWarning (
97
- warning,
98
- Seq (position),
99
- Some (TextEdit (s " Change to: $newText" , newText))
100
- )
101
- logger.log(Seq (diagnostic))
102
- case _ => ()
103
- }
94
+ val diagnostic = DeprecatedWarning (
95
+ warning,
96
+ Seq (position),
97
+ Some (TextEdit (s " Change to: $newText" , newText))
98
+ )
99
+ logger.log(Seq (diagnostic))
100
+ case _ => ()
101
+ }
104
102
105
103
}
0 commit comments