Skip to content

Commit

Permalink
Merge pull request #70 from nextflow-io/fix-more-race-conditions
Browse files Browse the repository at this point in the history
Fix race conditions
  • Loading branch information
nvnieuwk authored Oct 29, 2024
2 parents 4c4cd85 + 5053f62 commit 0800dbb
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ import java.util.regex.Matcher
@CompileStatic
public class JsonSchemaValidator {

private static ValidatorFactory validator
private static Pattern uriPattern = Pattern.compile('^#/(\\d*)?/?(.*)$')
private static ValidationConfig config
private ValidatorFactory validator
private Pattern uriPattern = Pattern.compile('^#/(\\d*)?/?(.*)$')
private ValidationConfig config

JsonSchemaValidator(ValidationConfig config) {
this.validator = new ValidatorFactory()
Expand All @@ -34,7 +34,7 @@ public class JsonSchemaValidator {
this.config = config
}

private static List<String> validateObject(JsonNode input, String validationType, Object rawJson, String schemaString) {
private List<String> validateObject(JsonNode input, String validationType, Object rawJson, String schemaString) {
def JSONObject schema = new JSONObject(schemaString)
def String draft = Utils.getValueFromJson("#/\$schema", schema)
if(draft != "https://json-schema.org/draft/2020-12/schema") {
Expand Down Expand Up @@ -104,12 +104,12 @@ public class JsonSchemaValidator {
return errors
}

public static List<String> validate(JSONArray input, String schemaString) {
public List<String> validate(JSONArray input, String schemaString) {
def JsonNode jsonInput = new OrgJsonNode.Factory().wrap(input)
return this.validateObject(jsonInput, "field", input, schemaString)
}

public static List<String> validate(JSONObject input, String schemaString) {
public List<String> validate(JSONObject input, String schemaString) {
def JsonNode jsonInput = new OrgJsonNode.Factory().wrap(input)
return this.validateObject(jsonInput, "parameter", input, schemaString)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,38 +19,38 @@ import nextflow.Nextflow
@CompileStatic
class SamplesheetConverter {

private static ValidationConfig config
private ValidationConfig config

SamplesheetConverter(ValidationConfig config) {
this.config = config
}

private static List<Map> rows = []
private static Map meta = [:]
private List<Map> rows = []
private Map meta = [:]

private static Map getMeta() {
private Map getMeta() {
this.meta
}

private static Map resetMeta() {
private Map resetMeta() {
this.meta = [:]
}

private static addMeta(Map newEntries) {
private addMeta(Map newEntries) {
this.meta = this.meta + newEntries
}

private static Boolean isMeta() {
private Boolean isMeta() {
this.meta.size() > 0
}

private static List unrecognisedHeaders = []
private List unrecognisedHeaders = []

private static addUnrecognisedHeader (String header) {
private addUnrecognisedHeader (String header) {
this.unrecognisedHeaders.add(header)
}

private static logUnrecognisedHeaders(String fileName) {
private logUnrecognisedHeaders(String fileName) {
def Set unrecognisedHeaders = this.unrecognisedHeaders as Set
if(unrecognisedHeaders.size() > 0) {
def String processedHeaders = unrecognisedHeaders.collect { "\t- ${it}" }.join("\n")
Expand All @@ -66,7 +66,7 @@ class SamplesheetConverter {
/*
Convert the samplesheet to a list of entries based on a schema
*/
public static List validateAndConvertToList(
public List validateAndConvertToList(
Path samplesheetFile,
Path schemaFile,
Map options
Expand Down Expand Up @@ -124,7 +124,7 @@ class SamplesheetConverter {
This function processes an input value based on a schema.
The output will be created for addition to the output channel.
*/
private static Object formatEntry(Object input, LinkedHashMap schema, String headerPrefix = "") {
private Object formatEntry(Object input, LinkedHashMap schema, String headerPrefix = "") {

// Add default values for missing entries
input = input != null ? input : schema.containsKey("default") ? schema.default : []
Expand Down Expand Up @@ -172,15 +172,15 @@ class SamplesheetConverter {

}

private static List validPathFormats = ["file-path", "path", "directory-path", "file-path-pattern"]
private static List schemaOptions = ["anyOf", "oneOf", "allOf"]
private List validPathFormats = ["file-path", "path", "directory-path", "file-path-pattern"]
private List schemaOptions = ["anyOf", "oneOf", "allOf"]

/*
This function processes a value that's not a map or list and casts it to a file type if necessary.
When there is uncertainty if the value should be a path, some simple logic is applied that tries
to guess if it should be a file type
*/
private static Object processValue(Object value, Map schemaEntry) {
private Object processValue(Object value, Map schemaEntry) {
if(!(value instanceof String)) {
return value
}
Expand Down Expand Up @@ -234,7 +234,7 @@ class SamplesheetConverter {
This function processes an input value based on a schema.
The output will be created for addition to the meta map.
*/
private static Object processMeta(Object input, LinkedHashMap schema, String headerPrefix) {
private Object processMeta(Object input, LinkedHashMap schema, String headerPrefix) {
// Add default values for missing entries
input = input != null ? input : schema.containsKey("default") ? schema.default : []

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ import org.yaml.snakeyaml.Yaml
@CompileStatic
class SchemaValidator extends PluginExtensionPoint {

static final List<String> NF_OPTIONS = [
final List<String> NF_OPTIONS = [
// Options for base `nextflow` command
'bg',
'c',
Expand Down Expand Up @@ -556,7 +556,7 @@ Please contact the pipeline maintainer(s) if you see this warning as a user.
//
// Clean and check parameters relative to Nextflow native classes
//
private static Map cleanParameters(Map params) {
private Map cleanParameters(Map params) {
def Map new_params = (Map) params.getClass().newInstance(params)
for (p in params) {
// remove anything evaluating to false
Expand Down

0 comments on commit 0800dbb

Please sign in to comment.