A few ideas:
- Disable caching for your groovy script, this will get expensive if it
is called alot: Wrapping your <groovy> task in a <with-attribute
key="Attributes.CACHE_MODEL" value="NONE">
- Cache the declaration of the class, I'm not positive this will work as
expected since the <factory> doesn't actually return anything but all
you're really trying to do here is make sure the class is only declared
once and <cache> will do it in a threadsafe manner. If that fails add a
<return value="dummy"/> after the groovy task just so the cache task has
something to cache.
<cache key="LOGGING_LISTENER" cache-key="groovy.LOGGING_LISTENER"
thread-safe="true">
<factory>
<groovy>
<script>
// imports are up here
public class BasicLoggingListener extends CVSAdapter {
// implementation
}
</script>
</groovy>
</factory>
<subtasks>
<return value="${groovy(new BasicLoggingListener())}"/>
</subtasks>
</cache>
> --~--~---------~--~----~------------~-------~--~----~
> You received this message because you are subscribed to the Google Groups "Cernunnos Discussion" group.
> To post to this group, send email to cernunnos-...@googlegroups.com
> To unsubscribe from this group, send email to cernunnos-discus...@googlegroups.com
> For more options, visit this group at http://groups.google.com/group/cernunnos-discussion?hl=en
> -~----------~----~----~----~------~----~------~--~---
>
>
[ SNIP ] Thank you for the ideas. I tried both of them out but unfortunately neither worked. The stack trace given back was virtually the same as above. Since I'm declaring a class, I wonder if the groovy engine is looking for a file named BasicLoggingListener.groovy? This line in the stack trace is what makes me wonder a little: groovy.lang.GroovyClassLoader.parseClass(GroovyClassLoader.java: 243) The signature of the method for this line is public Class parseClass(final InputStream in, final String fileName) throws CompilationFailedException. So it looks like it's expecting a filename of some kind?. I'll need to try something else for now, but I'd like to keep this discussion going. I'm hopeful Drew can comment on this when he returns. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Cernunnos Discussion" group. To post to this group, send email to cernunnos-...@googlegroups.com
Like a java class? I was going to do that next in a jar file and add
that to my classpath.
I've done some experiments, and what I've seen has been a surprise.
After reading the emails I figured the issue was going to be basically
what Eric described: the Groovy context/engine didn't like being
asked to compile the same class twice. My testing (admittedly
shallow) suggests that this is not a problem.
This works for me:
*****
test.crn
-----------
<for-each items="${groovy(['A', 'B', 'C'])}">
<echo-ln>${Attributes.OBJECT}</echo-ln>
<with-attribute key="sayIt" value="${crn(test2.crn)}">
<groovy><script>sayIt.sayHello()</script></groovy>
</with-attribute>
</for-each>
test2.crn
-----------
<groovy>
<script>
public class SayIt {
public void sayHello() {
println 'Hello World!'
}
public static void main(String[] args) {}
}
</script>
<subtasks><return value="${groovy(new SayIt())}"/></subtasks>
</groovy>
*****
NOTICE: The groovy/jsr-223 stack insisted that I add the main()
method. Before I had that I was getting...
Caused by: groovy.lang.MissingMethodException: No signature of
method: SayIt.main() is applicable for argument types:
([Ljava.lang.String;) values: {[]}
Also notice how (because of the <for-each>) the test2.crn XML file is
being invoked more than once.
Andy --
I know it took me forever to respond... do you still have the original
groovy class? I'd like to try to match up the BasicLoggingListener
impl with the following message (from your stack trace):
Caused by: javax.script.ScriptException:
org.codehaus.groovy.control.MultipleCompilationErrorsException:
startup failed, Script2.groovy: 86: unable to resolve class
BasicLoggingListenter
@ line 86, column 33.
1 error
What is it saying about line 86, column 33?
drew wills
Heh. I'm not sure what to say... this example works perfectly for me:
*****
test.crn
-----------
<for-each items="${groovy(['A', 'B', 'C'])}">
<with-attribute key="sayIt" value="${crn(test2.crn)}">
<echo-ln>${Attributes.OBJECT}</echo-ln>
<groovy><script>println sayIt.toString()</script></groovy>
</with-attribute>
</for-each>
test2.crn
-------------
<groovy>
<script>
import org.apache.commons.logging.Log
import org.apache.commons.logging.LogFactory
import org.netbeans.lib.cvsclient.event.BinaryMessageEvent
import org.netbeans.lib.cvsclient.event.CVSAdapter
import org.netbeans.lib.cvsclient.event.EnhancedMessageEvent
import org.netbeans.lib.cvsclient.event.FileAddedEvent
import org.netbeans.lib.cvsclient.event.FileInfoEvent
import org.netbeans.lib.cvsclient.event.FileRemovedEvent
import org.netbeans.lib.cvsclient.event.FileToRemoveEvent
import org.netbeans.lib.cvsclient.event.FileUpdatedEvent
import org.netbeans.lib.cvsclient.event.MessageEvent
import org.netbeans.lib.cvsclient.event.TerminationEvent
/**
* Logs CVS events at INFO to the named logger.
*
* The logger is from Apache commons-logging since Cernunnos itself uses it for
* its own logging.
*/
public class BasicLoggingListener extends CVSAdapter {
private final logger
static final CR = "\r"
static final LF = "\n"
public BasicLoggingListener(String name) {
logger = LogFactory.getLog(name)
}
private strip(msg) {
msg.replaceAll(CR, "")
msg.replaceAll(LF, "")
return msg
}
/**
*/
public void commandTerminated(TerminationEvent tEvent) {
def buffer = new StringBuilder()
buffer.append("CVS Command Terminated")
if (tEvent.isError()) {
buffer.append(" in error")
} else {
buffer.append(" successfully")
}
logger.info(strip(buffer.toString()))
}
/**
*/
public void messageSent(MessageEvent mEvent) {
if (mEvent instanceof EnhancedMessageEvent) {
return
}
def buffer = new StringBuilder()
if (!mEvent.isTagged()) {
if (mEvent.getMessage().length() > 1) {
buffer.append(mEvent.getMessage())
}
} else {
def taggedMsgBuffer = new StringBuffer()
// Gather the msg into a StringBuffer until we have a complete line.
def line =
MessageEvent.parseTaggedMessage(taggedMsgBuffer, mEvent.getMessage())
if (line != null && line.length() > 0) {
buffer.append(line)
}
}
if (mEvent.isError()) {
logger.error(strip(buffer.toString()))
} else {
logger.info(strip(buffer.toString()))
}
}
}
System.out.println(BasicLoggingListener.class)
</script>
<subtasks><return value="${groovy(new
BasicLoggingListener('foo'))}"/></subtasks>
</groovy>
*****
Here's the only other thing that comes to mind: looking at the stack trace...
Caused by: javax.script.ScriptException:
org.codehaus.groovy.control.MultipleCompilationErrorsException:
startup failed, Script2.groovy: 86: unable to resolve class
BasicLoggingListenter
@ line 86, column 33.
1 error
looks as though It's pointing to the last line:
System.out.println(BasicLoggingListener.class)
But it also says "MultipleCompilationErrorsException" -- I wonder if
the reason it can't find the BasicLoggingListener class is b/c it
didn't compile, and the fact that it didn't compile is causing the
"unable to resolve class BasicLoggingListenter" error. I wonder,
furthermore if they only have room to report 1 error on the stack
trace in the case of "MultipleCompilationErrors" and they're just
choosing the last one.
Maybe try changing that last line to
System.out.println('TEST')
And see if another compilation error comes to light in the stack trace.
drew