groovy

Create a directory structure from a path in gradle/groovy

浪尽此生 提交于 2020-04-07 05:17:23
问题 I am implementing a diff package generation task in my project's gradle build from the git command line output. Currently I have a method which will give me a list of changed files from git diff --name-only . What I would like to do is create a directory structure in a new directory which matches the paths of each file. For example: inputting the string repo/dir/file.java would create in an output directory if not already created and inside it the directories head/repo/dir with the current

Create a directory structure from a path in gradle/groovy

旧巷老猫 提交于 2020-04-07 05:17:02
问题 I am implementing a diff package generation task in my project's gradle build from the git command line output. Currently I have a method which will give me a list of changed files from git diff --name-only . What I would like to do is create a directory structure in a new directory which matches the paths of each file. For example: inputting the string repo/dir/file.java would create in an output directory if not already created and inside it the directories head/repo/dir with the current

How can I determine if a String is non-null and not only whitespace in Groovy?

核能气质少年 提交于 2020-04-05 07:42:10
问题 Groovy adds the isAllWhitespace() method to Strings, which is great, but there doesn't seem to be a good way of determining if a String has something other than just white space in it. The best I've been able to come up with is: myString && !myString.allWhitespace But that seems too verbose. This seems like such a common thing for validation that there must be a simpler way to determine this. 回答1: Another option is if (myString?.trim()) { ... } 回答2: You could add a method to String to make it

How to add an attribute which contains colon(:)for xml element and then serialize it in groovy?

99封情书 提交于 2020-03-25 19:14:10
问题 I have some test code snippet: ​import groovy.xml.XmlUtil class Greet { Greet() { } def salute() { println "Hello !" def input = """ <manifest xmlns:android="http://schemas.android.com/apk/res/android"> <application > <activity android:name="me.aolphn.MainActivity"> </activity> </application> </manifest> """ // def root = new XmlParser(false, true).parseText(input) def root = new XmlSlurper(false, true).parseText(input) root.'application'.@'android:txt'='this is txt' XmlUtil.serialize(root) }

Expression not correctly identified ( Operators and Operands )

白昼怎懂夜的黑 提交于 2020-03-25 18:23:16
问题 I need to identify top-level expression from a given string and convert it into the left operand, right operand and operator in groovy. I have created a matcher array to match expression and logic is as follow static CONDITION_REGEXPS = [ '(.+) (==) (.+)', '(.+) (!=) (.+)', '(.+) (>) (.+)', '(.+) (>=) (.+)', '(.+) (<) (.+)', '(.+) (<=) (.+)' ] static fromString(def string) { if (string) { string = string.split('\\|\\|'); List<List> list = string.collect({ it.trim().replaceAll(/^\(|\)$/, '')

escaping special character in groovy

前提是你 提交于 2020-03-25 13:51:33
问题 I want to run my command in background.And I am trying this in jenkins pipeline This is my command sh "./node_modules/.bin/selenium-standalone start \&" But when I run this command & gets single quote because of which the command fails. OUTPUT : ./node_modules/.bin/selenium-standalone start '&' Can anyone suggest how I should escape the & in groovy so I just get & without single quote. 回答1: This won't work that easily, first because & is a command for job control in the interactive shell, and

escaping special character in groovy

感情迁移 提交于 2020-03-25 13:50:08
问题 I want to run my command in background.And I am trying this in jenkins pipeline This is my command sh "./node_modules/.bin/selenium-standalone start \&" But when I run this command & gets single quote because of which the command fails. OUTPUT : ./node_modules/.bin/selenium-standalone start '&' Can anyone suggest how I should escape the & in groovy so I just get & without single quote. 回答1: This won't work that easily, first because & is a command for job control in the interactive shell, and

面试刷题1: 简要介绍java平台?java是解释执行的吗?

天涯浪子 提交于 2020-03-24 11:38:45
3 月,跳不动了?>>> 我是李福春,我为面试做准备。今天回答第一个问题。 java平台简要介绍?java是解释执行的吗? java平台 java平台基于jvm具备write once,run everywhere的跨平台能力;<br />具备自动垃圾回收;<br />具有无所不能的生态圈,比如spring,大数据,搜索,maven等; java语言是面向对象的,常见的特性有泛型,反射,lambda; jdk jre包括jvm,java类库,模块; jdk包含jre,还提供了一些工具,比如编译工具,诊断工具,辅助工具; jvm赋能java,使得java具备跨平台的能力,jvm还支持其他的语言,比如常见的groovy,scala等; jvm常见的垃圾收集器有serialGC,parallelGC,CMS,G1<br />常见垃圾回收算法:标记,复制,整理 java核心类库包括 集合,io, 网络,并发,util ;<br />此外还有海量的第三方库。 java的诊断工具有 jmap,jstack,jconsole等; java是解释执行吗? java是综合性的执行,即部分解释执行,部分编译执行;<br /> <br />java的生命周期分为编译期,运行期;<br />编译期是基于类加载器:<br />Bootstrap,Application,Extended,自定义类加载器<br

Nested JSON with duplicate keys

拟墨画扇 提交于 2020-03-23 12:05:02
问题 I will have to process 10 billion Nested JSON records per day using NiFi (version 1.9). As part of the job, am trying to convert the nested JSON to csv using Groovy script. I referred the below Stack Overflow questions related to the same topic and came up with the below code. Groovy collect from map and submap how to convert json into key value pair completely using groovy But am not sure how to retrieve the value of duplicate keys. Sample json is defined in the variable "json" in the below

Nested JSON with duplicate keys

北慕城南 提交于 2020-03-23 12:04:20
问题 I will have to process 10 billion Nested JSON records per day using NiFi (version 1.9). As part of the job, am trying to convert the nested JSON to csv using Groovy script. I referred the below Stack Overflow questions related to the same topic and came up with the below code. Groovy collect from map and submap how to convert json into key value pair completely using groovy But am not sure how to retrieve the value of duplicate keys. Sample json is defined in the variable "json" in the below