ant,groovy,unzip , ant unzip task: Why does it not fail, if unzipping fails?


ant unzip task: Why does it not fail, if unzipping fails?

Question:

Tag: ant,groovy,unzip

I use the groovy AntBuilder in a custom written installer, eg. to unpack the installation package. One thing I cannot figure out, is how to detect, whether the unzip task failed, eg. I have the following code:

...
AntBuilder antBuilder = new AntBuilder()
antBuilder.mkdir(dir:installationPath)
antBuilder.unzip(src:zipFileName, dest:installationPath,overwrite:"yes")
...

If the destination path ("installationPath") is write protected, the unzip reports errors ("unable to expand..."), but the task itself does not fail. There is also no "failOnError" attribute for unzip.

Is there a way to force a unzip task to fail, if the target is writeprotected (or the drive is full, etc.)?


Answer:

It seems there is no way to catch the exception.

According to the source code from ant

    protected void extractFile(FileUtils fileUtils, File srcF, File dir,
                               InputStream compressedInputStream,
                               String entryName, Date entryDate,
                               boolean isDirectory, FileNameMapper mapper)
                               throws IOException {

...........................
...........................
...........................


        } catch (FileNotFoundException ex) {
            log("Unable to expand to file " + f.getPath(),
                    ex,
                    Project.MSG_WARN);
        }

    }

It silently catches the exception without re-throwing it further.


Related:


Write Spock test cases for Spring boot application


java,spring,groovy,spock
I am working on spring boot application. I have to write test cases for it. I haven't written test cases before, so someone suggested using spock framework for it. I explored spock and i think it is more related to groovy language. Can i write spock test cases for my...

list of test step results in groovy script


groovy,automated-tests,soapui
I'm trying to figure out a way to get a list of (names) of just the failed test steps, currently the below code is giving me all the names def TestCase = testRunner.getTestCase() def StepList = TestCase.getTestStepList() StepList.each { log.info (it.name) } Now I'm not sure how to move on...

Model to LazyMap


dictionary,groovy,deserialization
How do I convert/deserialize these models public class AccessCredentials { String userName = '' String password = '' LoginOptions loginOptions = new LoginOptions() } public class LoginOptions { String partnerId = '' String applicationId = '' } into a LazyMap like : [ userName : userName, password : password, loginOptions...

Groovy - timestamp from minutes


oracle,grails,groovy,timestamp
I have an array or times/values coming back to be in an array like: [0, 60] Which are times in minutes, 0 = 12:00 a.m, 60 = 1:00 a.m. I am wanting to store these in an oracle database as timestamps. How do I convert minutes into timestamps in groovy?...

Groovy's @CompileStatic and map constructors


groovy
I'm using @CompileStatic for the first time, and confused as to how Groovy's map constructors work in this situation. @CompileStatic class SomeClass { Long id String name public static void main(String[] args) { Map map = new HashMap() map.put("id", 123L) map.put("name", "test file") SomeClass someClass1 = new SomeClass(map) // Does...

Cannot compile Java adapter using adapter-builder task (ANT) in MFP v7


java,ant,mobilefirst,mobilefirst-adapters
We have been using the adapter-builder task (com.worklight.ant.builders.AdapterBuilderTask) to compile our MFP adapters for several weeks. We just started now adopting Java adapters in our MFP apps but we cannot compile them with the adapter-builder task. Looking at the compilation errors in the output, it seems the adapter-builder task does...

Elasticsearch : _score always 0 in Groovy script


groovy,elasticsearch
I have this kind of Groovy script: def multiplier = doc['data'].value if (multiplier <= 0) { multiplier = 1 } multiplier * _score I use it as a script_score, and my score is always 0. It seems like _score is always 0. With a mvel script, it works. mvel script...

Unexpected top level exception: bad class file magic, in Android


java,android,intellij-idea,ant
I am trying to compile my android program via command line, using ANT. And the code compiles fine. But when the target -dex is executed, I get the following error: [dex] input: /Users/aditya/Desktop/workspace/Java/Play/bin/classes [dex] input: /Library/Java/Android/tools/support/annotations.jar [dex] Using Pre-Dexed annotations-5bd0afe28d834ceff67df1063f0f145b.jar <- /Library/Java/Android/tools/support/annotations.jar [dex] Converting compiled files and external libraries into...

gremlin outputs different from as seen on the internet, I think in bytes


groovy,titan,gremlin
How to get gremlin output normal indices along with v Currently it outputs something like this gremlin> g.V WARN com.thinkaurelius.titan.graphdb.transaction.StandardTitanTx - Query requires iterating over all vertices [()]. For better performance, use indexes gremlin> juno = g.addVertex(null); ==>v[128824] gremlin> june = g.addVertex(null); ==>v[128828] gremlin> jape = g.addVertex(null); ==>v[128832] But as...

How to use multiple classes in multiple files in scripts?


groovy,scripting
I need to make a standalone Groovy script that does not require compilation and runs without Groovy installed. It works well, but it fails to recognize any other script than the main script. My folder structure is the following: libs\ groovy-all-2.4.3.jar ivy-2.4.0.jar src\ makeRelease.groovy ReleaseHelper.groovy I am launching the script...

Special Groovy magic re property access and collections / iterables?


groovy
I understand what is happening here with the spread operator *. in Groovy (2.4.3): [].class.methods*.name => [add, add, remove, remove, get, ... But why does the leaving the * out produce the same results? [].class.methods.name => [add, add, remove, remove, get, ... I'd have expected that to be interpreted as...

how do you download files via ant though proxy [duplicate]


java,maven,ant,proxy
This question already has an answer here: Ant GET task and proxy 1 answer I am using ant which uses an build.xml file. This is the command: java version : 1.8.0 ant version: 1.7.1 CLASSPATH=/app/hbase-0.94.27/lib/hadoop-core-1.0.4.jar CFLAGS=-m64 CXXFLAGS=-m64 ant compile-native tar it hangs here: Buildfile: build.xml ivy-download: [get] Getting: http://repo2.maven.org/maven2/org/apache/ivy/ivy/2.2.0/ivy-2.2.0.jar...

Creating an ANT macro to combine two properties file


ant,properties-file,build.xml
Suppose that I have two properties file (say a.properties and b.properties) which contains key value pair. How to write ANT task to create a new properties file (say c.properties) which contains the key value pair of both these files(a and b). Please help.

Decode base64 image in Grails [duplicate]


grails,groovy
This question already has an answer here: Convert base64 string to image 3 answers I have a post api where I am sending a json string which contain the base64 encoded image.Below is the json string { "imageData":"base64encoded string", "status":"1" } where base64encode string is iVBORw0KGgoAAAANSUhEUgAAAHgAAACgCAIAAABIaz/HAAAAAXNSR0IArs4c6QAA\r\nABxpRE9UAAAAAgAAAAAAAABQAAAAKAAAAFAAAABQAABWL3xrAqoAAEAASURBVHgB\r\nlL2Fe1t7mueZme6uewNGMUu2LNkyySSjDJKZmZkSO8zM7CTmmJnZYbxUVbdgsKp7\r\nqqdrdp I cant post...

groovy/XML: Replace a node by another one


xml,groovy,xml-parsing,xmlslurper
I try to replace an XML node by another one by using XmlSlurper (or XmlParser). The original XML: <myXml> ... <myNode> <Name>name1</Name> <Name>name2</Name> <Name>name3</Name> </myNode> ... </myXml> The list that contains the items to build my new node def namelist = ['name4','name5','name6','name7'] What I want to have <myXml> ... <myNode>...

Spock Framework: problems with spying


java,unit-testing,groovy,spock,spock-spy
I have an issue with using Spy in Spock, it either doesn't work as it should or my understanding is wrong so I'm trying to clarify this. Consider this code (Java): public class CallingClass { public String functionOne() { //does stuff return "one"; } public String functionTwo() { String one...

Running an Ant target under certain conditions


ant
I have the following Ant targets in my project.xml: <target name="to.run.under.conditions"> </target> <target name="deploy1"> <antcall target="deploy2"/> </target> <target name="deploy2"> <antcall target="to.run.under.conditions"/> </target> <target name="another.target"> <antcall target="deploy1"/> </target> My intent is to be able to exclude the target to.run.under.conditions when running another.target. I am not very familiar with ANT and I...

Chaining Null-Safe Operator


groovy,nullpointerexception
My project has code like the following: params.stringValue?.trim().replaceAll('aa', 'a') We expected that if params.stringValue was null, that both trim() and replaceAll() would not be called. However we were getting a NullPointerException on this line saying that replaceAll() cannot be called on a null Object. We had to change the code...

Class fields as method parameters


oop,groovy
My method needs to be strictly typed. If possible, I wanted to save some line of codes, setting the model properties from the parameter input by putting the model properties setter directly at the function definition. The current working code: class Connector { static def entityQuery( String httpMethod, String typeName,...

Match string beginning with ([*>@]|--) ending with one of these


regex,groovy
I do have a String like *Task @Context >Delegation --Date and I'd like to extract the strings between the separators *@> and --. *Task @Context >Delegation --Date should yield the four strings Task, Context, Delegation and Date and *Task 9-5 @Co-ntext >Dele-gation --Date 12-5 Task 9-5, Co-ntext, Dele-gation and Date...

Parse RSS with groovy


parsing,groovy,rss,xmlslurper
I am trying to parse RSS feeds with groovy. I just wanted to extract the title and description tags' value. I used following code snippet to achieve this: rss = new XmlSlurper().parse(url) rss.channel.item.each { titleList.add(it.title) descriptionList.add(it.description) } After this, I am accessing these values in my JSP page. What is...

Restrict allowed httpMethods using enum


rest,groovy,enums
I am creating connectors for REST API methods. Some methods has the same method name but performs different HTTP methods. For example, createEntity( HttpMethod httpMethod, CreateEntity model ) can perform POST and GET only. What I want is to have an error when httpMethod is supplied with PUT or DELETE....

Ant build should wait for a child process to complete


java,ant
Hi I am new to ant and I have written a target which spawns a child process . Here I want the ant to wait until the child process is completed. How can I do that ? Can anyone please help me <target name = "buildtarget" depends="load-props"> <property name="targetname" value="build"/>...

create email list of all users


groovy,jenkins,jenkins-scriptler
On occasion I need to email all Jenkins users, for example warning them Jenkins will be offline for maintenance. The script below gives me email addresses for all people that Jenkins knows about, but it includes people that don’t have accounts, these are people that have committed changes that triggered...

null object error when calling code from script assertion - soapui


groovy,soapui
In a soapui groovy script test step I've this. context.setProperty("searchChange", new searchChange()); class searchChange{ def testRunner def searchChange(testRunner){ this.testRunner=testRunner } def search(a,b){ def search_TestCase = testRunner.testCase.testSuite.getTestCaseByName("Search") search_TestCase.setPropertyValue("Search_cID", a) search_TestCase.setPropertyValue("Search_sID", b) search_TestCase.run(new com.eviware.soapui.support.types.StringToObjectMap(), false) } } and in an assertion script in a different test suite I am...

Confused about the invokeMethod method in the Groovy MOP


groovy,mop
First look at the following Groovy code: class Car { def check() { System.out.println "check called..." } def start() { System.out.println "start called..." } } Car.metaClass.invokeMethod = { String name, args -> System.out.print("Call to $name intercepted... ") if (name != 'check') { System.out.print("running filter... ") Car.metaClass.getMetaMethod('check').invoke(delegate, null) } def validMethod...

how do you run ant


java,ant
I am trying to build a jar file using ant like this: CLASSPATH=/files/hadoop-core-1.0.4.jar CFLAGS=-m64 CXXFLAGS=-m64 ant compile-native tar I keep getting this error: Error: Could not find or load main class org.apache.tools.ant.launch.Launcher ant --execdebug show this: exec "/usr/java/jdk1.8.0_25/bin/java" -classpath "/usr/bin/build-classpath: error: JAVAVER_LIBDIR /usr/share/java-1.8.0 does not exist or is not a...

Using ant.replace in gradle


replace,ant,gradle
I want to use ant's replace task to replace token in one of the files like this: version.txt version.number=${versionNumber} build.gradle task writeVersion { ant.replace { file 'version.txt' token 'versionNumber' value '1.0.0' } } but it is giving me following error :- A problem occurred evaluating root project '1.01-Exercise-RunYourFirstTask'. > replace...

using classes in jenkins job dsl


groovy,jenkins,jenkins-job-dsl
Hi all I have a problem and I can't seem to figure it out. So I'm creating some helper classes for my dsl to use, but it just does not seem to execute any method within these classes. I have created a job with the following dsl in it: class...

How does the Groovy compiler work?


groovy
Can anyone explain the Groovy compiler works? Does it compile: Groovy code -> Java code -> Bytecode Groovy code -> Bytecode Some other method ...

Get nth child node without knowing node name Groovy


xml,groovy
I have xml like this: <node1> <node2> <node3> <node4> <node5> <node6> </node6> <node7> </node7> </node5> </node4> </node3> </node2> </node1> How can I get the name of the 6th node - assuming I don't know the node's name is "node6"? I currently have: def text = <xml from above> def list...

Cordova build fails, can't find ${appt}


android,cordova,ant
The command cordova build android fails with the following output BUILD FAILED F:\Programs\SDK\tools\ant\build.xml:597: The following error occurred while executing this line: F:\Programs\SDK\tools\ant\build.xml:649: The following error occurred while executing this line: F:\Programs\SDK\tools\ant\build.xml:694: Execute failed: java.io.IOException: Cannot run program "F:\code\asistenciaBT\platforms\android\CordovaLib\${aapt}" (in directory "F:\code\asistenciaBT\platforms\android\CordovaLib"): CreateProcess error=2, El sistema no puede...

How to get testStep responseAsXml in groovyScript


groovy,soapui
Concerning soapUI and groovy, I'm trying to get assertion (working) and response both in XML into a variable. I get the error groovy.lang.MissingMethodException: No signature of method: com.eviware.soapui.impl.wsdl.teststeps.WsdlTestRequestStep.getResponseAsXml() is applicable for argument types: () values: [] error at line: 6 I have tried adding import com.eviware.soapui.impl.wsdl.teststeps.WsdlTestRequestStep but still cant figure...

Java - Check properties file at compile time


java,maven,ant,properties
I need some advices from you today. I am working on a project which uses a huge constants holding class. There are lots of public static final String CONST_NAME = "const_value"; I am getting those using MyConstClass.CONST_NAME but now I need to externalise them in order to configure the project....

Spock's @Narrative and @Title annotations


groovy,spock
Spock provides @Narrative and @Title annotations that you can use to provide a class-level description of your test, e.g. @Narrative('description of spec') @Title('title of spec') class ExampleSpec extends Specification { // tests omitted } What is the difference between these two? In other words, why do we need both of...

Groovy String.toURL is deprecated - why and what should we use instead?


groovy
In current groovy versions, the method DefaultGroovyMethods.toURL(String) is marked as deprecated, but without any explanation. Why is it deprecated and what should we use instead? I wanted to use it to easily get a file from HTTP like this: def xml = "http://url.to/file.xml".toURL().text ...

Ant debug and ant release failed


java,android,eclipse,ant,compilation
I am trying to generate apk on command line using ant. I am able to use ant clean but for ant debug and ant release command I am getting following error. BUILD FAILED C:\Android\sdk\tools\ant\build.xml:649: The following error occurred while executing this line: C:\Android\sdk\tools\ant\build.xml:694: Execute failed: java.io.IOException: Cannot run program "C:\Workspace\SampleApp\${aapt}":...

Groovy: run SQL SELECT LIKE from file with params


sql,select,groovy
The groovy code is import groovy.sql.* dbUrl = 'jdbc:sqlserver://server' dbUser = 'username' dbPassword = 'password' dbDriver = 'com.microsoft.sqlserver.jdbc.SQLServerDriver' sql = Sql.newInstance(dbUrl, dbUser, dbPassword, dbDriver) def sqlfromfile = new SqlFromFile() sqlfromfile.sql_filename='select_query.sql' sqlfromfile.read() try{ def result = sql.rows(sqlfromfile.result,[id:'01']) println result }catch(e){ println e } class SqlFromFile { def sql_filename def read(){ result=...

Why isn't split working here?


regex,groovy
I'm trying to take a filename that's being passed from a tsv and split it into an array, like so: new File("filenames.tsv").eachLine( { String file_iter -> println file_iter def details = file_iter.split(".") println details }) The output of the printlns: stad.all.16jan15.TP.pwpv [] Why is the array empty? I'm sure I'm...

Why does DriverManager.getConnection() lookup fail in GroovyConsole?


mysql,jdbc,groovy,groovy-console
The following Groovy script works correctly from the command line. (I successfully get a Connection.) // ---- jdbc_test.groovy import java.sql.* Class.forName("com.mysql.jdbc.Driver") def con = DriverManager.getConnection( "jdbc:mysql://localhost:3306/test", "root", "password") println con > groovy -cp lib\mysql-connector-java-5.1.25-bin.jar script\jdbc_test.groovy [email protected] But if the same script is loaded into GroovyConsole (2.4.3) and run - after...

ant LinkageError without includeantruntime


java,ant,junit
How can I prevent the AntClassLoader and URLClassLoader from causing a linkage error? Due to an older project, junit and hamcrest.core are put into ANT_HOME and our build uses includeantruntime=true in order to run unit tests. I am now working on a project built with ant where I don't want...

Via Windows command line, how can we compile a Netbeans C/C++ application?


c++,netbeans,command-line,ant,compilation
Let's take this simple C/C++ application Netbeans project folder. In Netbeans IDE, we just hit build button on the toolbar to build the application. I want to do that automatically via Windows command line, how can I do that? I did google, and found some related posts though not very...

Grails JAX-RS Calling a class in src/groovy giving error - Message: No signature of method: is applicable for argument types


grails,groovy,jax-rs
While developing the rest api using jaxrs plugin I need to create some common class which I have created in "src/groovy". Below is the class class ValidateToken { String validate(String token){ println(token) return "test" } //... In resource file(jaxrs) this is what I am doing def instance=ValidateToken.validate("test") This throws error...

set an annotation attribute from an environment variable?


spring,groovy,spring-boot
I'm trying to set an annotation value from an environment variable: @Configuration @ComponentScan @EnableAutoConfiguration @EnableScheduling class Application { @Scheduled(cron = "${DB_CRON}") def void schedule() { ... } public static void main(String... args) { SpringApplication.run(Application, args) } ... } However, I get the following compile time error: Attribute 'cron' should have...

Groovy TimeDuration Argument Types


date,groovy
I'm quite new to groovy (and haven't any experience with Java) - but I'm running into a problem that doesn't make sense to me. My guess is that its my misunderstanding of how objects and classes work in these languages. My question is probably very basic - any help is...

sonar maven analysis only picks .java file


maven,groovy,sonarqube,sonarqube-5.0
I am trying to run a sonar maven analysis on my multilanguage project which contains many languages like *.java, *.groovy, *.js etc. I have installed all the languages plugin in my sonar and configured my pom sonar.sources parameter as src/main,src/test but still it picks up only java files. In the...

Get just content of soap response in Groovy


xml,soap,groovy
I have following soap response: <?xml version="1.0" encoding="utf-8"?> <soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"> <soap:Body> <GetHTMLResponse xmlns="http://www.webserviceX.NET"> <GetHTMLResult> TEST </GetHTMLResult> </GetHTMLResponse> </soap:Body> </soap:Envelope> Now I want a method which deliverys me this xml: <root> <GetHTMLResponse...

Java syntax to Groovy syntax


java,groovy,syntax
I am not really sure how to translate this to groovy syntax. Have checked this differences with java page already. Thanks! TrustManager[] trustAllCerts = new TrustManager[] { new X509TrustManager() { public java.security.cert.X509Certificate[] getAcceptedIssuers() { return null; } public void checkClientTrusted(X509Certificate[] certs, String authType) { } public void checkServerTrusted(X509Certificate[] certs, String...

spring-integration-dsl-groovy-http return null when i use httpGet method


spring,groovy,spring-integration
I use spring integration 4.1.4 and spring integration dsl groovy 1.1.0 I included spring integration core, http in dependency. When i am executing spring integration dsl groovy http sample, it throwing null value in console. I am not sure what i missed. Here is my code looks like IntegrationBuilder builder...

Cron expression must consist of 6 fields (found 1 in “#{systemEnvironment['db_cron']}”)


spring,groovy,cron,spring-el
I'm trying to set a cron Scheduled annotation as follows: @Scheduled(cron = "#{systemEnvironment['db_cron']}") def void schedule() { } Next set the environment variable as: export db_cron="0 19 21 * * *" However, I get the runtime error: Cron expression must consist of 6 fields (found 1 in "#{systemEnvironment['db_cron']}") What can...