diff --git a/README.md b/README.md index 89eb10b..984a10e 100644 --- a/README.md +++ b/README.md @@ -16,12 +16,13 @@ Using gradle one can include the hcl4j dependency like so: ```groovy dependencies { - compile "com.bertramlabs.plugins:hcl4j:0.8.0" + compile "com.bertramlabs.plugins:hcl4j:0.9.0" } ``` ## What's New +* **0.9.0** HCL Tuple for loop nested improvements. String escapes fixed. anytrue and alltrue methods added. * **0.8.0** HCL For Loop Tuples now evaluated. * **0.7.7** HCL Periods in attribute names referenced from Unicodes ID_Continue, fixed. * **0.7.6** SLF4j 1.7.36 upgrade to reduce CVE's diff --git a/build.gradle b/build.gradle index 8c2e4dc..81ccb8d 100644 --- a/build.gradle +++ b/build.gradle @@ -30,7 +30,7 @@ ext { group = 'com.bertramlabs.plugins' -version = '0.8.0' +version = '0.9.0' ext.isReleaseVersion = !version.endsWith("SNAPSHOT") sourceCompatibility = "1.8" @@ -51,11 +51,11 @@ dependencies { api 'com.fasterxml.jackson.core:jackson-core:2.14.1' api "org.slf4j:slf4j-parent:1.7.36" api "org.slf4j:slf4j-api:1.7.36" - api 'org.apache.httpcomponents:httpclient:4.5.13' + api 'org.apache.httpcomponents:httpclient:4.5.14' api 'org.apache.httpcomponents:httpcore:4.4.15' api 'org.apache.httpcomponents:httpmime:4.5.13' api group: 'commons-beanutils', name: 'commons-beanutils', version: '1.9.4' - api 'commons-net:commons-net:3.7.2' + api 'commons-net:commons-net:3.9.0' testImplementation platform("org.spockframework:spock-bom:2.3-groovy-4.0") testImplementation "org.spockframework:spock-core" testImplementation "org.spockframework:spock-junit4" // you can remove this if your code does not rely on old JUnit 4 rules diff --git a/src/main/java/com/bertramlabs/plugins/hcl4j/HCLBaseFunctions.java b/src/main/java/com/bertramlabs/plugins/hcl4j/HCLBaseFunctions.java index c083b3a..a1705be 100644 --- a/src/main/java/com/bertramlabs/plugins/hcl4j/HCLBaseFunctions.java +++ b/src/main/java/com/bertramlabs/plugins/hcl4j/HCLBaseFunctions.java @@ -339,6 +339,62 @@ static void registerCollectionFunctions(HCLParser parser) { return null; }); + parser.registerFunction("alltrue", (arguments) -> { + if(arguments.size() > 0) { + if(arguments.get(0) instanceof List) { + List elements = ((List)(arguments.get(0))); + if(elements.size() > 0) { + Boolean allTrue = true; + for(Object element : elements) { + if(element instanceof Boolean) { + if(!(Boolean)element) { + allTrue = false; + break; + } + } else if(element instanceof String) { + if(!element.equals("true")) { + allTrue = false; + break; + } + } else { + allTrue = false; + break; + } + } + return allTrue; + } else { + return true; + } + } else { + return true; + } + } + return true; + }); + + + parser.registerFunction("anytrue", (arguments) -> { + if(arguments.size() > 0) { + if(arguments.get(0) instanceof List) { + List elements = ((List)(arguments.get(0))); + if(elements.size() > 0) { + for(Object element : elements) { + if(element instanceof Boolean) { + if((Boolean)element) { + return true; + } + } else if(element instanceof String) { + if(element.equals("true")) { + return true; + } + } + } + } + } + } + return false; + }); + parser.registerFunction("lookup", (arguments) -> { if(arguments.size() > 0) { if(arguments.get(0) instanceof Map) { diff --git a/src/test/groovy/com/bertramlabs/plugins/hcl4j/HCLParserSpec.groovy b/src/test/groovy/com/bertramlabs/plugins/hcl4j/HCLParserSpec.groovy index cbcb9a0..8ba34ba 100644 --- a/src/test/groovy/com/bertramlabs/plugins/hcl4j/HCLParserSpec.groovy +++ b/src/test/groovy/com/bertramlabs/plugins/hcl4j/HCLParserSpec.groovy @@ -1184,10 +1184,26 @@ swagger_path_method_parameters = [for i,my_value in [0,1,2,3]: "${i}:${my_value then: results.locals["swagger_path_method_parameters"] == ["0:1.0","1:2.0","2:3.0","3:4.0"] } - void "it should handle nested for tuples"() { given: def hcl = ''' +locals { + my_array = [for my_value in [1,2,3,4]: + [for sub_value in ["a","b","c","d"]: "${sub_value}${my_value}"]] + +} +''' + HCLParser parser = new HCLParser(); + when: + def results = parser.parse(hcl) + println results + then: + results.locals["my_array"] != null + } + + void "it should handle nested complex for tuples"() { + given: + def hcl = ''' locals { swagger_path_methods_split = [["a","b"],["c","d"]] json_data = {