Search Results

Search found 595 results on 24 pages for 'groovy'.

Page 9/24 | < Previous Page | 5 6 7 8 9 10 11 12 13 14 15 16  | Next Page >

  • How can I dynamically override a classes "each" method?

    - by rewbs
    Groovy adds each() and a number of other methods to java.lang.Object. I can't figure out how to use the Groovy metaclass to dynamically replace the default each() on a Java class. I can see how to add new methods: MyJavaClass.metaClass.myNewMethod = { closure -> /* custom logic */ } new MyJavaClass().myNewMethod { item -> println item } // runs custom logic But it seems the same approach doesn't work when overriding methods: MyJavaClass.metaClass.each = { closure -> /* custom logic */ } new MyJavaClass().each { item -> println item } // runs Object.each() What am I doing wrong? How can I dynamically override each() in Groovy?

    Read the article

  • A better way to do XML in Java

    - by jboyd
    There are a lot of questions that ask the best XML parser, I am more interested in what is the XML parser that is the most like Groovy for Java? I want: SomeApiDefinedObject o = parseXml( xml ); for( SomeApiDefinedObject it : o.getChildren() ) { System.out.println( it.getAttributes() ); } The most important things are that I don't want to create an object for every type of filed, I'd rather just deal with them all as strings, and that building the XML doesn't require any converters or anything, just a simple object that is already defined If you have used the Groovy XML parser, you will know what I'm talking about Alternatively, would it be better for me to just use Groovy from Java?

    Read the article

  • How to use Enum in grails (not in domain class)

    - by bsreekanth
    Hello, i want to use Enum to represent some selection values. In /src/groovy folder, under the package com.test, I created the Enum. package com.test public enum TabSelectorEnum { A(1), B(2) private final int value public int value() {return value} } Now, I am trying to access it from controller like TabSelectorEnum.B.value() It throws an exception Caused by: org.codehaus.groovy.runtime.InvokerInvocationException: java.lang.NoClassDefFoundError: Could not initialize class com.test.TabSelectorEnum thanks in advance.

    Read the article

  • Is it possible for a java.lang.Process to inherit the environement variables from another java.lang.

    - by Eric Leung
    I am trying to use groovy to do shell scripting on unix, but I am not having any luck having one process retain the environment variables changed by another process. For example, def p1 = ["bash", "-c", "source /some/setEnv.sh"].execute() Now, I would like a second process, p2, to inherit the environment variables that was set in p1. How can I do this? I don't see anything in java.lang.Process or its groovy extension that would spit out the environment variables after the process has executed.

    Read the article

  • groovyx.net.ws.WSClient is having problems with ''soapenc:Array' Any workaround?

    - by ?????
    I'm trying to call a webservice (implemented with a .NET/ASP system) from groovy/grails using WSClient. I have no trouble accessing this service using the SOAPClient debugger (Todd Ditchendorf's program for OSX), but when i try it via groovy/grails, I get the error undefined simple or complex type 'soapenc:Array' Is there any solution? Looking at it with wireshark: It seems to have thrown this error even before it gets a chance to perform the transaction. The error is thrown right after WSClient has downloaded the second of two schemas referenced in he WSDL.

    Read the article

  • replace XmlSlurper tag with arbitrary XML

    - by Misha Koshelev
    Dear All: I am trying to replace specific XmlSlurper tags with arbitrary XML strings. The best way I have managed to come up with to do this is: #!/usr/bin/env groovy import groovy.xml.StreamingMarkupBuilder def page=new XmlSlurper(new org.cyberneko.html.parsers.SAXParser()).parseText(""" <html> <head></head> <body> <one attr1='val1'>asdf</one> <two /> <replacemewithxml /> </body> </html> """.trim()) import groovy.xml.XmlUtil def closure closure={ bind,node-> if (node.name()=="REPLACEMEWITHXML") { bind.mkp.yieldUnescaped "<replacementxml>sometext</replacementxml>" } else { bind."${node.name()}"(node.attributes()) { mkp.yield node.text() node.children().each { child-> closure(bind,child) } } } } println XmlUtil.serialize( new StreamingMarkupBuilder().bind { bind-> closure(bind,page) } ) However, the only problem is the text() element seems to capture all child text nodes, and thus I get: <?xml version="1.0" encoding="UTF-8"?> <HTML>asdf<HEAD/> <BODY>asdf<ONE attr1="val1">asdf</ONE> <TWO/> <replacementxml>sometext</replacementxml> </BODY> </HTML> Any ideas/help much appreciated. Thank you! Misha p.s. Also, out of curiosity, if I change the above to the "Groovier" notation as follows, the groovy compiler thinks I am trying to access the ${node.name()} member of my test class. Is there a way to specify this is not the case while still not passing the actual builder object? Thank you! :) def closure closure={ node-> if (node.name()=="REPLACEMEWITHXML") { mkp.yieldUnescaped "<replacementxml>sometext</replacementxml>" } else { "${node.name()}"(node.attributes()) { mkp.yield node.text() node.children().each { child-> closure(child) } } } } println XmlUtil.serialize( new StreamingMarkupBuilder().bind { closure(page) } )

    Read the article

  • what is this operator called and what is it used for <=>

    - by Scott
    I recently came across this magical operator when digging into Groovy: <= Groovy has really made me happy with elvis operators ?. and ?: which I use constantly now and very much wish were in Java. With this new operator, I have only found this reference. It seems to make comparators much easier. My question is how does it handle null values and how does it compare non Comparable object. Does this operator have a name, I couldn't find it Googling.

    Read the article

  • Unable to resolve class org.codehaus.groovy.grails.plugins.springsecurity.Secured

    - by Alan
    Hi, I'm new to Grails and I'm seeing the error "Groovy:unable to resolve class org.codehaus.groovy.grails.plugins.springsecurity.Secured" when I open a Grails app in SpringSource Tool Suite (STS) and build the project. However the application does run when I issue the run-app command and I can login. Also when I look in my .grails folder I can see that 'grails-acegi-0.5.2.zip' has been downloaded. When I issues the upgrade command from the grails command prompt I get a message telling me that all dependancies have been resolved. Thanks for any help.

    Read the article

  • How can i use 'log' inside a src/groovy/ class

    - by firnnauriel
    I'm encountering this error: groovy.lang.MissingPropertyException: No such property: log for class: org.utils.MyClass Here's the content of the class: package org.utils class MyClass { int organizationCount = 0 public int getOrganizationCount(){ log.debug "There are ${organizationCount} organization(s) found." return organizationCount } } Do i need to add an import statement? What do i need to add? Note that the class is located in src/groovy/org/utils. I know that the 'log' variable is accessible in controllers, services, etc. Not sure in 'src' classes. Thanks.

    Read the article

  • Show progress during a long Ajax call

    - by kousen
    I have a simple web site (http://www.kousenit.com/twitterfollowervalue) that computes a quantity based on a person's Twitter followers. Since the Twitter API only returns followers 100 at a time, a complete process may involve lots of calls. At the moment, I have an Ajax call to a method that runs the Twitter loop. The method looks like (Groovy): def updateFollowers() { def slurper = new XmlSlurper() followers = [] def next = -1 while (next) { def url = "http://api.twitter.com/1/statuses/followers.xml?id=$id&cursor=$next" def response = slurper.parse(url) response.users.user.each { u -> followers << new TwitterUser(... process data ...) } next = response.next_cursor.toBigInteger() } return followers } This is invoked from a controller called renderTTFV.groovy. I call the controller via an Ajax call using the prototype library: On my web page, in the header section (JavaScript): function displayTTFV() { new Ajax.Updater('ttfv','renderTTFV.groovy', {}); } and there's a div in the body of the page that updates when the call is complete. Everything is working, but the updateFollowers method can take a fair amount of time. Is there some way I could return a progress value? For example, I'd like to update the web page on every iteration. I know ahead of time how many iterations there will be. I just can't figure out a way to update the page in the middle of that loop. Any suggestions would be appreciated.

    Read the article

  • Debugging scripts loaded with GroovyShell (in eclipse)

    - by MSh
    I am working with eclipse and groovy plug in. I am building a test harness to debug and test groovy scripts. The scripts are really simple but long, most of them just if/else/return. I figured out that I can call them using GroovyShell and Bindings to pass in the values. The problem is that, while I can call the script and get the results just fine, I CAN NOT step in there with the debugger. Breakpoints in those scripts are not active. Is there a way to debug the scripts? Maybe I should use something other than GroovyShell? I really don't want to modify the scripts by wrapping them into functions, and then calling those functions from my test classes. That's how I am using Binding and GroovyShell: def binding = new Binding(); binding.lineList = [list1]; binding.count = 5; def shell = new GroovyShell(binding); def result = shell.evaluate(new File("src/Rules/checkLimit.groovy"));

    Read the article

  • Grails beginner problem "Failed to invoke Servlet 2.5"

    - by A Lion
    I'm trying to get Groovy on Grails set up on a Snow Leopard machine. I followed all the grails.com install directions and am trying to start the application from Grails: A Quick-Start Guide by Dave Klein. I ran grails create-app TekDays with no apparent problems and was able to cd to the TekDays folder, but when I try to run grails run-app I get the following: Welcome to Grails 1.3.1 - http://grails.org/ Licensed under Apache Standard License 2.0 Grails home is set to: /grails Base Directory: /apps/TekDays Resolving dependencies... Dependencies resolved in 4469ms. Running script /grails/scripts/RunApp.groovy Environment set to development [delete] Deleting directory /Users/name/.grails/1.3.1/projects/TekDays/tomcat Running Grails application.. 2010-05-24 21:42:39,559 [main] ERROR context.GrailsContextLoader - Error executing bootstraps: Failed to invoke Servlet 2.5 getContextPath method java.lang.IllegalStateException: Failed to invoke Servlet 2.5 getContextPath method at org.grails.tomcat.TomcatServer.start(TomcatServer.groovy:164) at grails.web.container.EmbeddableServer$start.call(Unknown Source) at _GrailsRun_groovy$_run_closure5_closure12.doCall(_GrailsRun_groovy:159) at _GrailsRun_groovy$_run_closure5_closure12.doCall(_GrailsRun_groovy) at _GrailsSettings_groovy$_run_closure10.doCall(_GrailsSettings_groovy:282) at _GrailsSettings_groovy$_run_closure10.call(_GrailsSettings_groovy) at _GrailsRun_groovy$_run_closure5.doCall(_GrailsRun_groovy:150) at _GrailsRun_groovy$_run_closure5.call(_GrailsRun_groovy) at _GrailsRun_groovy.runInline(_GrailsRun_groovy:116) at _GrailsRun_groovy.this$4$runInline(_GrailsRun_groovy) at _GrailsRun_groovy$_run_closure1.doCall(_GrailsRun_groovy:59) at RunApp$_run_closure1.doCall(RunApp.groovy:33) at gant.Gant$_dispatch_closure5.doCall(Gant.groovy:381) at gant.Gant$_dispatch_closure7.doCall(Gant.groovy:415) at gant.Gant$_dispatch_closure7.doCall(Gant.groovy) at gant.Gant.withBuildListeners(Gant.groovy:427) at gant.Gant.this$2$withBuildListeners(Gant.groovy) at gant.Gant$this$2$withBuildListeners.callCurrent(Unknown Source) at gant.Gant.dispatch(Gant.groovy:415) at gant.Gant.this$2$dispatch(Gant.groovy) at gant.Gant.invokeMethod(Gant.groovy) at gant.Gant.executeTargets(Gant.groovy:590) at gant.Gant.executeTargets(Gant.groovy:589) Caused by: java.lang.NoSuchMethodException: javax.servlet.ServletContext.getContextPath() at java.lang.Class.getMethod(Class.java:1605) ... 23 more I've googled every derivative of "Failed to invoke Servlet 2.5" that I can think of, but have thus far been unable to find anything that helps me understand, yet alone resolve, the error. Any advice to help me resolve this would be very much appreciated!

    Read the article

  • Grails XOM linkageerror - SAXParserException

    - by Stefan Kendall
    Possibly related: http://stackoverflow.com/questions/2762439/grails-attempting-to-include-htppbuilder-linkage-error I'm trying to include XOM in my grails project. How do I know which dependency library I need to exclude? I'm lost here. dependencies { build('xom:xom:1.1') { excludes "xml-apis" } } Error: java.lang.LinkageError: loader constraint violation: loader (instance of <bootloader>) previously initiated loading for a different type with name "org/xml/sax/SAXParseException" at java.lang.Class.getDeclaredMethods0(Native Method) at java.lang.Class.privateGetDeclaredMethods(Class.java:2427) at java.lang.Class.getDeclaredMethods(Class.java:1791) at java.security.AccessController.doPrivileged(Native Method) at org.codehaus.groovy.util.LazyReference.getLocked(LazyReference.java:33) at org.codehaus.groovy.util.LazyReference.get(LazyReference.java:20) at grails.util.PluginBuildSettings.getPluginInfos(PluginBuildSettings.groovy:124) at grails.util.PluginBuildSettings.getPluginInfos(PluginBuildSettings.groovy) at grails.util.PluginBuildSettings$getPluginInfos.callCurrent(Unknown Source) at grails.util.PluginBuildSettings.getPluginInfo(PluginBuildSettings.groovy:160) at grails.util.PluginBuildSettings$getPluginInfo.callCurrent(Unknown Source) at grails.util.PluginBuildSettings.getPluginInfoForSource(PluginBuildSettings.groovy:195) at org.codehaus.groovy.transform.ASTTransformationVisitor$3.call(ASTTransformationVisitor.java:303) at org.codehaus.groovy.control.CompilationUnit.applyToSourceUnits(CompilationUnit.java:820) at org.codehaus.groovy.control.CompilationUnit.doPhaseOperation(CompilationUnit.java:513) at org.codehaus.groovy.control.CompilationUnit.processPhaseOperations(CompilationUnit.java:489) at org.codehaus.groovy.control.CompilationUnit.compile(CompilationUnit.java:466) at _GrailsEvents_groovy.run(_GrailsEvents_groovy:54) at _GrailsEvents_groovy$run.call(Unknown Source) at _GrailsArgParsing_groovy$run.call(Unknown Source) at _GrailsArgParsing_groovy.run(_GrailsArgParsing_groovy:29) at _GrailsArgParsing_groovy$run.call(Unknown Source) at _GrailsInit_groovy$run.call(Unknown Source) at _GrailsInit_groovy.run(_GrailsInit_groovy:38) at _GrailsInit_groovy$run.call(Unknown Source) at Help_.run(Help_.groovy:27) at Help_$run.call(Unknown Source) at gant.Gant.processTargets(Gant.groovy:494) at gant.Gant.processTargets(Gant.groovy:480)

    Read the article

  • Determine if the "yes" is necessary when doing an SCP

    - by glowcoder
    I'm writing a Groovy script to do an SCP. Note that I haven't ran it yet, because the rest of it isn't finished. Now, if you're doing an scp for the first time, have to authenticate the fingerprint. Future times, you don't. My current solution is, because I get 3 tries for the password, and I really only need 1 (it's not like the script will mistype the password... if it's wrong, it's wrong!) is to pipe in "yes" as the first password attempt. This way, it will accept the fingerprint if necessary, and use the correct password as the first attempt. If it didn't need it, it puts yes as the first attempt and the correct as the second. However, I feel this is not a very robust solution, and I know if I were a customer I would not like seeing "incorrect password" in my output. Especially if it fails for another reason, it would be an incredibly annoying misnomer. What follows is the appropriate section of the script in question. I am open to any tactics that involve using scp (or accomplishing the file transfer) in a different way. I just want to get the job done. I'm even open to shell scripting, although I'm not the best at it. def command = [] command.add('scp') command.add(srcusername + '@' + srcrepo + ':' + srcpath) command.add(tarusername + '@' + tarrepo + ':' + tarpath) def process = command.execute() process.consumeOutput(out) process << "yes" << LS << tarpassword << LS process << "yes" << LS << srcpassword << LS process.waitfor() Thanks so much, glowcoder

    Read the article

  • Remove newlines from MarkupBuilder result

    - by aldrin
    Is there a way to control groovy's MarkupBuilder's output and filter out the newline characters? I have code like below: import groovy.xml.MarkupBuilder def writer = new StringWriter() def xml = new MarkupBuilder(writer) xml.basket(){ fruit (type:"apple", 1) fruit (type:"orange", 2) } which invariably outputs: <basket> <fruit type='apple'>1</fruit> <fruit type='orange'>2</fruit> </basket> I'd really like it in a single line: <basket><fruit type='apple'>1</fruit><fruit type='orange'>2</fruit></basket>

    Read the article

  • xcode scripting language

    - by PurplePilot
    i notice that Java has a number of ancillary scripting languages. Clojure and Groovy for example. My understanding is that these can be used when the full might and power of Java does not need to be applied and a speedy cludge can be hacked in Groovy/Clojure. But at the end of the day the scripting tools contribution gets compiled into the application Question 1) Is there a similar scripting in x-code? I was not so interested in Python or Ruby in this situation as they are languages in their own right added in, as indeed i think can happen in Java, but i was looking for a purpose built tools. Question 2) If there is such a tool would it count the application out vis-a-vis the new Apple guidelines as to what can be used to generate iXxx apps?

    Read the article

  • Accommodating null values in a list?

    - by h259bws
    Hi, I'm new to Java and Groovy and am running into trouble with the following Groovy script. I created this whittled down version of a larger script to facilitate debugging. The script is iterating through a list trying to calc a running total of the values of all objects in the list. Some or all of these objects' values may be null. Script import org.apache.commons.lang.math.NumberUtils class Field { def name def value } def fields = [ new Field(name:'Annuities %', value:75), new Field(name:'Other %', value:null), ] //def totalFunding = fields.inject(0) {int total, Field myField - // total + NumberUtils.toInt(myField.value,0) as Integer def totalFunding = fields.inject(0) {int total, Field myField - total + myField?.value as Integer } It gets this error: Exception thrown: java.lang.NullPointerException java.lang.NullPointerException at Script3$_run_closure1.doCall(Script3:15) at Script3.run(Script3:14) What is the correct way to accomodate null values? Thanks, Betsy

    Read the article

  • Java date processing

    - by Don
    Hi, Given an instance of java.util.Date which is a Sunday. If there are 4 Sundays in the month in question, I need to figure out whether the chosen date is 1st Sunday of month 2nd Sunday of month 2nd last Sunday of month Last Sunday of month If there are 5 Sundays in the month in question, then I need to figure out whether the chosen date is 1st Sunday of month 2nd Sunday of month 3rd Sunday of month 2nd last Sunday of month Last Sunday of month I've had a look in JodaTime, but haven't found the relevant functionality there yet. The project is actually a Groovy project, so I could use either Java or Groovy to solve this. Thanks, Donal

    Read the article

  • How to create datetime string in soapui using groovy

    - by Arunkumar
    Hi am using Soapui for testing web services. i need to create a customer record with email address and password. create customer record service contains emailid and password, wen i click the run(submit request) button in create customer record in soapui, i should get the emailid appended with current time of creation and any password. how to do this with groovy?

    Read the article

  • Utilisez-vous Grails, le framework Web écrit via le langage Groovy ? Venez partager votre expérience

    Grails en est actuellement à la version 2.1. Initié en 2005, ce framework écrit avec le langage Groovy en est donc à sa 7ème année d'existence. Nous aimerions avoir votre avis sur ce framework Web basé sur le patron de conception Modèle-Vue-Contrôleur. Vous pourriez par exemple insister sur :depuis quand vous l'utilisez, votre satisfaction, le soutien de la communauté, évolution des versions, l'apprentissage du langage Groovy. Merci pour votre participation. L'équipe Java...

    Read the article

  • Translate Basic Config.groovy log4j DSL to external log4j.properties

    - by Stephen Swensen
    The following is a basic log4j configuration inside Config.groovy using the log4j DSL with Grails 1.2, it works as expected (log all errors to the given file): log4j = { appenders { file name:'file', file:"c:/error.log" } error 'grails.app' root { error 'file' } } How would one translate this into a properties style log4j configuration file? The following does not work: log4j.rootLogger=ERROR, FA log4j.appender.FA=org.apache.log4j.FileAppender log4j.appender.FA.File=C:/error.log log4j.logger.grails.app=ERROR, FA I suspect it has something to do with the translation of error 'grails.app' but I really don't know. If it makes any difference, the properties file is configured externally: grails.config.locations = ["file:${basedir}/extconf/log4j.properties"] All I really want is an external log4j properties file which logs all application exceptions to a file.

    Read the article

  • How to sort a list so that managers are always ahead of their subordinates

    - by James Black
    I am working on a project using Groovy, and I would like to take an array of employees, so that no manager follows their subordinates in the array. The reason being that I need to add people to a database and I would prefer not to do it in two passes. So, I basically have: <employees> <employee> <employeeid>12</employeeid> <manager>3</manager> </employee> <employee> <employeeid>1</employeeid> <manager></manager> </employee> <employee> <employeeid>3</employeeid> <manager>1</manager> </employee> </employees> So, it should be sorted as such: employeeid = 1 employeeid = 3 employeeid = 12 The first person should have a null for managers. I am thinking about a binary tree representation, but I expect it will be very unbalanced, and I am not certain the best way to do this using Groovy properly. Is there a way to do this that isn't going to involve using nested loops?

    Read the article

  • Getting svn: E170000: Unrecognized URL scheme for my custom Svn Gradle plugin

    - by Ip Doh
    I wrote a custom gradle plugin using groovy to do basic svn tasks like, Checkout, Clean, Tag etc. The groovy class calls the svn command line client to do these operations, It works fine when i run it on my windows system but the same plugin gives the following error when i run it on a linux system (Centos). svn: E170000: Unrecognized URL scheme for '%22https://source.mycompany.net/svn/MyProject/trunk%22' Am able to make the same calls to the command line client through the command prompt or shell script without any issues. So what is the difference with Here is my code sample String command =String.format("svn co -r %d --non-interactive --trust-server-cert -- username %s --password %s --depth infinity \"%s\" \"%s\"", getRevision(), getUserName(), getUserPassword(), getSrcUrl(), getDir()); Process svnProcess = Runtime.getRuntime().exec(command); BufferedReader stdInput = new BufferedReader(new InputStreamReader(svnProcess.getInputStream())); BufferedReader stdError = new BufferedReader(new InputStreamReader(svnProcess.getErrorStream())); String statusOutputLine ="" while ((statusOutputLine = stdInput.readLine()) != null) { logger.quiet(" " + statusOutputLine); } while (( statusOutputLine = stdError.readLine()) != null) { logger.error(statusOutputLine) throw new Exception(statusOutputLine) } logger.quiet("Successfully Checked out the work space") i do have neon installed on the system -bash-4.1$ svn --version svn, version 1.6.11 (r934486) compiled Jun 25 2011, 11:30:15 Copyright (C) 2000-2009 CollabNet. Subversion is open source software, see http://subversion.tigris.org/ This product includes software developed by CollabNet (http://www.Collab.Net/). The following repository access (RA) modules are available: ra_neon : Module for accessing a repository via WebDAV protocol using Neon. handles 'http' scheme handles 'https' scheme ra_svn : Module for accessing a repository using the svn network protocol. with Cyrus SASL authentication handles 'svn' scheme ra_local : Module for accessing a repository on local disk. handles 'file' scheme

    Read the article

< Previous Page | 5 6 7 8 9 10 11 12 13 14 15 16  | Next Page >