groovy

SimpleDateFormat setTimeZone not working

橙三吉。 提交于 2020-02-03 08:23:18
问题 I am using the below code to cast time as UTC which is working import java.text.SimpleDateFormat; import static java.util.Calendar.* def dt = "2018-03-19T06:00:00+01:00" def format = "yyyy-MM-dd'T'HH:mm:ssX" TimeZone tz = TimeZone.getDefault(); //getting up local time zone TimeZone.setDefault(TimeZone.getTimeZone("UTC")); SimpleDateFormat sdf = new SimpleDateFormat(format); Date d = sdf.parse(dt); TimeZone.setDefault(tz); println d //output: 2018-03-19T05:00:00Z println d.toTimestamp(); /

Using Groovy(or Java) how can I convert a org.joda.time.LocalDateTime to a java.util.date?

ε祈祈猫儿з 提交于 2020-02-02 11:12:33
问题 Using Groovy (or Java) how can I convert a org.joda.time.LocalDateTime to a java.util.Date ? import org.joda.time.* Calendar cal = Calendar.instance cal.set(Calendar.DATE, 1) cal.set(Calendar.HOUR, 0) cal.set(Calendar.MINUTE, 0) cal.set(Calendar.SECOND, 0) cal.set(Calendar.MILLISECOND, 0) Date startOfTheMonth = cal.time LocalDateTime localDateTime = new LocalDateTime() localDateTime = localDateTime.withDayOfMonth(1) localDateTime = localDateTime.withTime(0,0,0,0) localDateTime.minusMonths(6)

Replacement for Jenkins Scriptler plugin?

被刻印的时光 ゝ 提交于 2020-02-02 05:17:21
问题 It looks like the Jenkins Scriptler plugin is no longer available, due to security reasons: https://wiki.jenkins-ci.org/display/JENKINS/Scriptler+Plugin "Distribution of This Plugin Has Been Suspended" Is there a similar plugin that I could use to run saved Groovy scripts? 回答1: Hi you can store your groovy scripts in Managed Files and pass the parameters to groovy script through Extended Choice Parameters Plugin. Or else you can download Scriptler plugin source code and add it to your /var

Jenkins Groovy - using modified data from readYaml to write back into yml file

安稳与你 提交于 2020-02-02 04:23:06
问题 I am using Jenkins readYaml to read the data as follows: data = readYaml file: "test.yml" //modify data.info = "b" I want to write this modified data back to test.yml in Jenkins. How can this be achieved? 回答1: test.yml: data: info: change me aaa: bbb ddd: ccc pipeline script: @Grab('org.yaml:snakeyaml:1.17') import org.yaml.snakeyaml.Yaml import org.yaml.snakeyaml.DumperOptions import static org.yaml.snakeyaml.DumperOptions.FlowStyle.BLOCK node { def yaml = readYaml file: "test.yml" yaml.data

How to fetch records in grails by max date and group at same time

╄→гoц情女王★ 提交于 2020-02-02 02:20:15
问题 I have a table that looks like this: id name shade date_created ---- ----- ------- --------------- 1 Red bright 10-28-2012 2 Orange light 10-28-2012 3 Red <null> 10-24-2013 4 Orange light 10-24-2013 Desired Result: id name value date_created ---- ----- ------ --------- 3 Red <null> 10-24-2013 4 Orange light 10-24-2013 What can I do with GORM to get this result? In pure sql this is the query that gets me the desired result: SELECT t.name, t.shade, r.MaxTime FROM (SELECT name, MAX(date_created)

gradle入门

被刻印的时光 ゝ 提交于 2020-02-01 19:11:23
了解Groovy语言 说到gradle就不得不谈Groovy语言,gradle中所有的配置使用的是Groovy语言 Groovy语言是一门jvm语言,最终编译成class文件后在jvm上运行,java语言的特性Groovy都支持,可以混写java和Groovy,但是不能混写java和kotlin,kotlin和java可以互相调用,但是不可以混写 说了这么多,那Groovy语言就得比java多点啥,要不用它干啥啊 Groovy优势在于增强了java的一些功能,如文件读写,xml解析,用Groovy几行代码就能搞定,而java就需要几十行 def声明变量、定义函数 def i = 1 def str = "hello world" def d = 3.14 声明变量可以不加类型,编译时会自动判断类型,结尾也可以不加分号 def demoName(){ "hello world" } 最后一行就等于return了,可以不加return String demoName(){ "hello world" } 指定返回值类型就可以不加def了 字符串分为三种 单引号不会对字符串中$进行转义,原样输出 双引号会转义$,输出变量的值 三引号字符(''')支持换行,原样输出 Groovy的数据类型主要包括三种 java中基本数据类型 增强的List、Map、Range容器 闭包

Grails filter syntax, or, How to call a Grails Filter outside Grails

元气小坏坏 提交于 2020-01-31 09:17:04
问题 Grails provides filters that run before your controllers. They're defined in classes that look like this: class SecurityFilters { def filters = { myFilter(controller:'*', action:'*') { // What are those weird colons?? print "I'm filtering!" // Code that does the filtering goes here } } } These work great but I would like to understand the syntax better as it doesn't look like any Groovy code I've seen before. In particular, the line above that starts with myFilter seems very odd. Is this a

Grails filter syntax, or, How to call a Grails Filter outside Grails

天大地大妈咪最大 提交于 2020-01-31 09:14:09
问题 Grails provides filters that run before your controllers. They're defined in classes that look like this: class SecurityFilters { def filters = { myFilter(controller:'*', action:'*') { // What are those weird colons?? print "I'm filtering!" // Code that does the filtering goes here } } } These work great but I would like to understand the syntax better as it doesn't look like any Groovy code I've seen before. In particular, the line above that starts with myFilter seems very odd. Is this a

if condition not displaying correct message after output

試著忘記壹切 提交于 2020-01-30 11:52:52
问题 I am having a little issue with my if condition in groovy. Virtually I want to look at a property value I've set and ensure that is every instance on the response delivered from the JSON contains the same value as the property value, then it should equal a match. Now when I log the location_id and location_id_request , I am getting the values expected. However, in my if statement it seems to still state that that the location id does not match, making me believe that my if condition is

if condition not displaying correct message after output

纵然是瞬间 提交于 2020-01-30 11:52:05
问题 I am having a little issue with my if condition in groovy. Virtually I want to look at a property value I've set and ensure that is every instance on the response delivered from the JSON contains the same value as the property value, then it should equal a match. Now when I log the location_id and location_id_request , I am getting the values expected. However, in my if statement it seems to still state that that the location id does not match, making me believe that my if condition is