groovy

Groovy基础语法

爱⌒轻易说出口 提交于 2020-01-30 10:05:40
1.Groovy中的变量 1.1、变量的类型:基本类型(java中的int,float,double,byte,char,long,short)和对象类型(String等) (Groovy中最终都是对象类型) int x = 10 println x.class //结果为:class java.lang.Integer double y = 3.14 println y.class //结果为:class java.lang.Double //由此可见,Groovy中的基本类型最终会被编译器包装成对象类型 1.2、变量的定义:强类型定义方式和弱类型def定义方式 def x1 = 10 def y1 = 3.14 def str = ‘groovy study’ println x1.class //class java.lang.Integer println y1.class //class java.math.BigDecimal println str.class //class java.lang.String //强类型定义及定义的时候写明变量的类型,而def则由编译器自行推导变量的类型 强类型定义方式和弱类型def定义方式的选择: 变量就是应用于自己的类或者自己的模块而不会应用于其它类或者其他模块,推荐使用def类型,这样可以随时动态的转换为其它类型;

Sonar + JaCoco not counting Groovy code as covered

假如想象 提交于 2020-01-30 05:49:23
问题 I have a Groovy class with a single static method: class ResponseUtil { static String FormatBigDecimalForUI (BigDecimal value){ (value == null || value <= 0) ? '' : roundHalfEven(value) } } It has a test case or few: @Test void shouldFormatValidValue () { assert '1.8' == ResponseUtil.FormatBigDecimalForUI(new BigDecimal(1.7992311)) assert '0.9' == ResponseUtil.FormatBigDecimalForUI(new BigDecimal(0.872342)) } @Test void shouldFormatMissingValue () { assert '' == ResponseUtil

Where to place resources in Grails project?

柔情痞子 提交于 2020-01-29 13:12:39
问题 I am wondering if there is a designated place for resource files in a Grails application? I have a csv file that gets loaded into a map (nothing major) but didn't quite know where to put it in the project. So my question is, is there a dedicated place in the project to place this file? (If so, where?) Or is it better to place it outside of the project? 回答1: If the csv is going to need updating from time to time, I'd put it external to your grails folder, and point to it from config.groovy. If

Where to place resources in Grails project?

廉价感情. 提交于 2020-01-29 13:10:18
问题 I am wondering if there is a designated place for resource files in a Grails application? I have a csv file that gets loaded into a map (nothing major) but didn't quite know where to put it in the project. So my question is, is there a dedicated place in the project to place this file? (If so, where?) Or is it better to place it outside of the project? 回答1: If the csv is going to need updating from time to time, I'd put it external to your grails folder, and point to it from config.groovy. If

Jenkins Matrix Groovy Execution Strategy Plugin hangs if label is offline

大憨熊 提交于 2020-01-25 08:36:20
问题 I am trying to implement a more complex combination filter for Jenkins using the Matrix Groovy Execution Strategy Plugin. See my previous question for more details. It seems to work otherwise but if the nodes where the label is set are offline, the matrix job hangs and does not put the rest of the matrix items into the job queue. This is enough Groovy to cause the same effect in the plugin: combinations.each{ result[it.cfg] = result[it.cfg] ?: [] result[it.cfg] << it } return [result, true]

Using string builder to place XML in single csv/xls column not working

北城以北 提交于 2020-01-25 08:14:45
问题 I am having an issue with an XML response and formatting it into CSV which can then later be opened as an XLS and see the entire response into a single cell. I know.. its not how I would do it either, but they get what they ask for. So far I have tried to use a string builder. This has been successful in formatting the response into a single line string, I have tested this by writing it to a text file and copying it to Eclipse.. when I place single quotes around the XML it turns to a string.

Transform XML into a Map using groovy

陌路散爱 提交于 2020-01-25 08:12:24
问题 I have some XML that I want to transform into a Map. I used the middle way of transforming XML to JSON and then greating a map of the json: import org.json.XML import groovy.json.JsonSlurper Map parseXml(String input) { String json = XML.toJSONObject(input).toString() new JsonSlurper().parseText(json) } But when you have name spacing, it does not get removed. eg. <ns2:someObject xmlns:ns2="http://someLink"> <someOtherObject> <something>SOME_THING</something> </someOtherObject>

Groovy and XML: Not able to insert processing instruction

ぐ巨炮叔叔 提交于 2020-01-25 07:34:28
问题 Scenario Need to update some attributes in an existing XML-file. The file contains a XSL processing instruction, so when the XML is parsed and updated I need to add the instruction before writing it to a file again. Problem is - whatever I do - I'm not able to insert the processing instruction Based on the Java-example found at rgagnon.com I have created the code below Example code ## import groovy.xml.* def xml = '''|<something> | <Settings> | </Settings> |</something>'''.stripMargin() def

How to avoid casting arguments in Spock

99封情书 提交于 2020-01-24 23:31:23
问题 I want to get a List from repository and assert its contents. In following code I get a warning that states that Object cannot be assigned to List Is there any way to add better argument to handle such case? myDomainObjectRepository.save(_) >> { arguments -> final List<MyDomainObject> myDomainObjects = arguments[0] assert myDomainObjects == [new MyDomainObject(someId, someData)] } 回答1: To elaborate on Opals answer: There are two parts and a footnote in the docs that are relevant here: If the

Can't get ECDSA signature to validate with public key

∥☆過路亽.° 提交于 2020-01-24 22:12:29
问题 I'm running out of ideas as to why my sample code won't verify the given EC public key, signature and message. I've converted the signature to ASN.1 format which is 70 bytes and the public key is 64 bytes plus uncompressed byte (0x04). I've also tried converting the message to SHA256 hash but that didn't work as well. The publicKey hex value is used to construct a ECPublicKey with prime256v1 curve. The signature is base64 decoded then formatted to ASN.1. I don't see what I could be doing