Classpath issue with groovy-all and APE scriptable datasets

solved

#1

Hi guys,

I’m working on this APE issue and need an advice on how to add groovy-all to enable groovy script in datasets.

To make it work I had to add groovy all to test deployment:

@Deployment
public static Archive<?> createDeploymentPackage() {
    WebArchive war = ShrinkWrap.create(WebArchive.class, "test.war")
            .addPackage(UserAccount.class.getPackage())
            .addClass(Query.class)
            .addPackages(true, "org.assertj.core")
            .addAsWebInfResource(EmptyAsset.INSTANCE, "beans.xml")
            .addAsResource("test-persistence.xml", "META-INF/persistence.xml");
    MavenResolverSystem resolver = Maven.resolver();
    war.addAsLibraries(resolver.loadPomFromFile("pom.xml").resolve("org.codehaus.groovy:groovy-all").withoutTransitivity().asSingleFile());

    return war;
}

But what I would like is to add it automatically when scriptableDatasets property is enabled in arq.xml.

The it-test can be found here. I’ve commented the lines which adds groovy to micro deployment so you can reproduce the issue. When the test is run, the following warnning is logged on server:

07:39:49,385 WARNING [org.jboss.arquillian.persistence.dbunit.data.replacement.DataSetScriptReplacer] (default task-24) Could not find script engine with name groovy in classpath

It happens when we try to get groovy script engine here.

I’ve tried to work on DBUnitArchiveAppender but without success, here is how I’m trying to add it:

if(dbunitConfigurationInstance.get().isScriptableDataSets()){
    dbUnitExtensionArchive.addPackages(true, new String[]{
            "groovy",
            "org.codehaus.groovy",
            "groovyjarjarcommonscli",
            "groovyjarjarasm",
            "groovyjarjarantlr"
    });
    dbUnitExtensionArchive.addAsResource("META-INF/services/javax.script.ScriptEngineFactory", ArchivePaths.create("META-INF/services/javax.script.ScriptEngineFactory"));
    dbUnitExtensionArchive.addAsResource("META-INF/services/org.codehaus.groovy.runtime.ExtensionModule", ArchivePaths.create("META-INF/services/org.codehaus.groovy.runtime.ExtensionModule"));
    dbUnitExtensionArchive.addAsResource("META-INF/services/org.codehaus.groovy.plugins.Runners", ArchivePaths.create("META-INF/services/org.codehaus.groovy.plugins.Runners"));
    dbUnitExtensionArchive.addAsResource("META-INF/services/org.codehaus.groovy.transform.ASTTransformation", ArchivePaths.create("META-INF/services/org.codehaus.groovy.transform.ASTTransformation"));
    dbUnitExtensionArchive.addAsResource("META-INF/services/org.codehaus.groovy.source.Extensions", ArchivePaths.create("META-INF/services/org.codehaus.groovy.source.Extensions"));

}

You can download generated arquilian-persistence-dbunit.jar here.

Any idea on how to solve that?


#2

Looks like its a nasty classloading issue: http://stackoverflow.com/questions/25688639/groovyscriptengine-classloading-in-jboss-7

I also tried to create groovy-all.jar separated from arquillian-dbunit.jar (separated appender) but also didnt worked.


#3

I’m on holidays now, back 22.05. Can’t help with the actual code, but some hints from the top of my head.

Check how we deal with groovy in Spock test runner. There were certain problem, but eventually we made it working.


#4

Now it just works :wink: thank you again @bartoszmajsak!


#5