Skip to content

Commit 5a9b1ae

Browse files
authored
Merge pull request #130 from nextflow-io/fix/config-validation-multistrings
fix config validation for GString values
2 parents f529e91 + 60ba5a5 commit 5a9b1ae

File tree

7 files changed

+193
-25
lines changed

7 files changed

+193
-25
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
# nextflow-io/nf-schema: Changelog
22

3+
# Version 2.4.1
4+
5+
## Bug fixes
6+
7+
1. Allow `GString` values for all configuration options that allow `String` values.
8+
39
# Version 2.4.0
410

511
## New features

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ Declare the plugin in your Nextflow pipeline configuration file:
2525

2626
```groovy title="nextflow.config"
2727
plugins {
28-
28+
2929
}
3030
```
3131

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ dependencies {
88
implementation 'com.sanctionco.jmail:jmail:1.6.3' // Needed for e-mail format validation
99
}
1010

11-
version = '2.4.0'
11+
version = '2.4.1'
1212

1313
nextflowPlugin {
1414
nextflowVersion = '24.10.0'

src/main/groovy/nextflow/validation/config/HelpConfig.groovy

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,12 @@ class HelpConfig {
1515
final public Boolean enabled = false
1616
final public Boolean showHidden = false
1717

18-
final public String showHiddenParameter = "showHidden"
19-
final public String shortParameter = "help"
20-
final public String fullParameter = "helpFull"
21-
final public String beforeText = ""
22-
final public String afterText = ""
23-
final public String command = ""
18+
final public CharSequence showHiddenParameter = "showHidden"
19+
final public CharSequence shortParameter = "help"
20+
final public CharSequence fullParameter = "helpFull"
21+
final public CharSequence beforeText = ""
22+
final public CharSequence afterText = ""
23+
final public CharSequence command = ""
2424

2525
HelpConfig(Map map, Map params, Boolean monochromeLogs, Boolean showHiddenParams) {
2626
def config = map ?: Collections.emptyMap()
@@ -37,7 +37,7 @@ class HelpConfig {
3737

3838
// showHiddenParameter
3939
if(config.containsKey("showHiddenParameter")) {
40-
if(config.showHiddenParameter instanceof String) {
40+
if(config.showHiddenParameter instanceof CharSequence) {
4141
showHiddenParameter = config.showHiddenParameter
4242
log.debug("Set `validation.help.showHiddenParameter` to ${showHiddenParameter}")
4343
} else {
@@ -60,7 +60,7 @@ class HelpConfig {
6060

6161
// shortParameter
6262
if(config.containsKey("shortParameter")) {
63-
if(config.shortParameter instanceof String) {
63+
if(config.shortParameter instanceof CharSequence) {
6464
shortParameter = config.shortParameter
6565
log.debug("Set `validation.help.shortParameter` to ${shortParameter}")
6666
} else {
@@ -70,7 +70,7 @@ class HelpConfig {
7070

7171
// fullParameter
7272
if(config.containsKey("fullParameter")) {
73-
if(config.fullParameter instanceof String) {
73+
if(config.fullParameter instanceof CharSequence) {
7474
fullParameter = config.fullParameter
7575
log.debug("Set `validation.help.fullParameter` to ${fullParameter}")
7676
} else {
@@ -80,7 +80,7 @@ class HelpConfig {
8080

8181
// beforeText
8282
if(config.containsKey("beforeText")) {
83-
if(config.beforeText instanceof String) {
83+
if(config.beforeText instanceof CharSequence) {
8484
if(monochromeLogs) {
8585
beforeText = config.beforeText
8686
} else {
@@ -94,7 +94,7 @@ class HelpConfig {
9494

9595
// afterText
9696
if(config.containsKey("afterText")) {
97-
if(config.afterText instanceof String) {
97+
if(config.afterText instanceof CharSequence) {
9898
if(monochromeLogs) {
9999
afterText = config.afterText
100100
} else {
@@ -108,7 +108,7 @@ class HelpConfig {
108108

109109
// command
110110
if(config.containsKey("command")) {
111-
if(config.command instanceof String) {
111+
if(config.command instanceof CharSequence) {
112112
if(monochromeLogs) {
113113
command = config.command
114114
} else {

src/main/groovy/nextflow/validation/config/SummaryConfig.groovy

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,17 +13,17 @@ import static nextflow.validation.utils.Colors.removeColors
1313

1414
@Slf4j
1515
class SummaryConfig {
16-
final public String beforeText = ""
17-
final public String afterText = ""
16+
final public CharSequence beforeText = ""
17+
final public CharSequence afterText = ""
1818

19-
final public Set<String> hideParams = []
19+
final public Set<CharSequence> hideParams = []
2020

2121
SummaryConfig(Map map, Boolean monochromeLogs) {
2222
def config = map ?: Collections.emptyMap()
2323

2424
// beforeText
2525
if(config.containsKey("beforeText")) {
26-
if(config.beforeText instanceof String) {
26+
if(config.beforeText instanceof CharSequence) {
2727
if(monochromeLogs) {
2828
beforeText = config.beforeText
2929
} else {
@@ -37,7 +37,7 @@ class SummaryConfig {
3737

3838
// afterText
3939
if(config.containsKey("afterText")) {
40-
if(config.afterText instanceof String) {
40+
if(config.afterText instanceof CharSequence) {
4141
if(monochromeLogs) {
4242
afterText = config.afterText
4343
} else {
@@ -51,7 +51,7 @@ class SummaryConfig {
5151

5252
// hideParams
5353
if(config.containsKey("hideParams")) {
54-
if(config.hideParams instanceof List<String>) {
54+
if(config.hideParams instanceof List<CharSequence>) {
5555
hideParams = config.hideParams
5656
log.debug("Set `validation.summary.hideParams` to ${hideParams}")
5757
} else {

src/main/groovy/nextflow/validation/config/ValidationConfig.groovy

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,9 @@ class ValidationConfig {
2222

2323
final public Integer maxErrValSize = 150
2424

25-
final public String parametersSchema = "nextflow_schema.json"
25+
final public CharSequence parametersSchema = "nextflow_schema.json"
2626

27-
final public Set<String> ignoreParams = ["nf_test_output"] // Always ignore the `--nf_test_output` parameter to avoid warnings when running with nf-test
27+
final public Set<CharSequence> ignoreParams = ["nf_test_output"] // Always ignore the `--nf_test_output` parameter to avoid warnings when running with nf-test
2828

2929
final public HelpConfig help
3030

@@ -96,7 +96,7 @@ class ValidationConfig {
9696

9797
// parameterSchema
9898
if(config.containsKey("parametersSchema")) {
99-
if(config.parametersSchema instanceof String) {
99+
if(config.parametersSchema instanceof CharSequence) {
100100
parametersSchema = config.parametersSchema
101101
log.debug("Set `validation.parametersSchema` to ${parametersSchema}")
102102
} else {
@@ -106,7 +106,7 @@ class ValidationConfig {
106106

107107
// ignoreParams
108108
if(config.containsKey("ignoreParams")) {
109-
if(config.ignoreParams instanceof List<String>) {
109+
if(config.ignoreParams instanceof List<CharSequence>) {
110110
ignoreParams += config.ignoreParams
111111
log.debug("Added the following parameters to the ignored parameters: ${config.ignoreParams}")
112112
} else {
@@ -116,7 +116,7 @@ class ValidationConfig {
116116

117117
// defaultIgnoreParams
118118
if(config.containsKey("defaultIgnoreParams")) {
119-
if(config.defaultIgnoreParams instanceof List<String>) {
119+
if(config.defaultIgnoreParams instanceof List<CharSequence>) {
120120
ignoreParams += config.defaultIgnoreParams
121121
log.debug("Added the following parameters to the ignored parameters: ${config.defaultIgnoreParams}")
122122
} else {
Lines changed: 162 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,162 @@
1+
package nextflow.validation
2+
3+
import java.nio.file.Path
4+
5+
import nextflow.plugin.Plugins
6+
import nextflow.plugin.TestPluginDescriptorFinder
7+
import nextflow.plugin.TestPluginManager
8+
import nextflow.plugin.extension.PluginExtensionProvider
9+
import org.pf4j.PluginDescriptorFinder
10+
import nextflow.Session
11+
import spock.lang.Specification
12+
import spock.lang.Shared
13+
import org.slf4j.Logger
14+
import org.junit.Rule
15+
import test.Dsl2Spec
16+
import test.OutputCapture
17+
18+
import nextflow.validation.config.ValidationConfig
19+
20+
/**
21+
* @author : nvnieuwk <[email protected]>
22+
*/
23+
class ConfigTest extends Dsl2Spec{
24+
25+
@Rule
26+
OutputCapture capture = new OutputCapture()
27+
28+
@Shared String pluginsMode
29+
30+
Path root = Path.of('.').toAbsolutePath().normalize()
31+
Path getRoot() { this.root }
32+
String getRootString() { this.root.toString() }
33+
34+
private Session session
35+
36+
def setup() {
37+
session = Mock(Session)
38+
session.getBaseDir() >> getRoot()
39+
}
40+
41+
def 'test valid config' () {
42+
given:
43+
def config = [
44+
lenientMode: true,
45+
monochromeLogs: true,
46+
failUnrecognisedParams: true,
47+
failUnrecognisedHeaders: true,
48+
maxErrValSize: 20,
49+
parametersSchema: 'src/testResources/nextflow_schema.json',
50+
ignoreParams: ['some_random_param'],
51+
help: [
52+
enabled: true,
53+
showHidden: true,
54+
showHiddenParameter: 'stopHiding',
55+
shortParameter: 'short',
56+
fullParameter: 'full',
57+
beforeText: 'before',
58+
afterText: 'after',
59+
command: 'command'
60+
],
61+
summary: [
62+
beforeText: 'before',
63+
afterText: 'after',
64+
hideParams: ['some_random_param'],
65+
]
66+
]
67+
def params = [:]
68+
69+
when:
70+
new ValidationConfig(config, params)
71+
def stdout = capture
72+
.toString()
73+
.readLines()
74+
.findResults { it.contains('WARN') ? it : null }
75+
76+
then:
77+
noExceptionThrown()
78+
!stdout
79+
}
80+
81+
def 'test valid config - GStrings' () {
82+
given:
83+
def randomString = 'randomString'
84+
def config = [
85+
lenientMode: true,
86+
monochromeLogs: true,
87+
failUnrecognisedParams: true,
88+
failUnrecognisedHeaders: true,
89+
maxErrValSize: 20,
90+
parametersSchema: "${randomString}",
91+
ignoreParams: ["${randomString}"],
92+
help: [
93+
enabled: true,
94+
showHidden: true,
95+
showHiddenParameter: "${randomString}",
96+
shortParameter: "${randomString}",
97+
fullParameter: "${randomString}",
98+
beforeText: "${randomString}",
99+
afterText: "${randomString}",
100+
command: "${randomString}"
101+
],
102+
summary: [
103+
beforeText: "${randomString}",
104+
afterText: "${randomString}",
105+
hideParams: ["${randomString}"],
106+
]
107+
]
108+
def params = [:]
109+
110+
when:
111+
new ValidationConfig(config, params)
112+
def stdout = capture
113+
.toString()
114+
.readLines()
115+
.findResults { it.contains('WARN') ? it : null }
116+
117+
then:
118+
noExceptionThrown()
119+
!stdout
120+
}
121+
122+
def 'test invalid config' () {
123+
given:
124+
def config = [
125+
lenientMode: 'notABoolean',
126+
monochromeLogs: 12,
127+
failUnrecognisedParams: 'notABoolean',
128+
failUnrecognisedHeaders: 'notABoolean',
129+
showHiddenParams: 'notABoolean',
130+
maxErrValSize: ["notAnInteger"],
131+
parametersSchema: 42,
132+
ignoreParams: true,
133+
help: [
134+
enabled: 'notABoolean',
135+
showHidden: 'notABoolean',
136+
showHiddenParameter: 123456789,
137+
shortParameter: false,
138+
fullParameter: [im:'a_map'],
139+
beforeText: true,
140+
afterText: ['im','a','list'],
141+
command: 0
142+
],
143+
summary: [
144+
beforeText: 63,
145+
afterText: false,
146+
hideParams: 'randomString',
147+
]
148+
]
149+
def params = [:]
150+
151+
when:
152+
new ValidationConfig(config, params)
153+
def stdout = capture
154+
.toString()
155+
.readLines()
156+
.findResults { it.contains('WARN') ? it : null }
157+
158+
then:
159+
noExceptionThrown()
160+
stdout
161+
}
162+
}

0 commit comments

Comments
 (0)