[
https://issues.apache.org/jira/browse/GROOVY-11570?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]
Paul King updated GROOVY-11570:
-------------------------------
Description:
This is a followup to GROOVY-9402 which fixed FRAGMENT HOST in Groovy 3 but not
later versions. It wasn't clear at the time whether the split packaging fixes
would allow us not to have that attribute.
was:
As discussed on the [mailing
list|http://groovy.329449.n5.nabble.com/Problems-with-OSGi-after-upgrading-to-Groovy-3-0-0-td5765283.html],
there might be an issue when using Groovy inside an OSGi container.
---
*Case 1: REST Assured*
REST Assured is trying to update to Groovy 3.0.0 and one of their integration
example is failing:
{code:java}
@RunWith(PaxExam.class)
public class XmlPathOSGiITest {
@Configuration
public static Option[] configure() {
return new Option[]
{
/* System Properties */
systemProperty(EXAM_FAIL_ON_UNRESOLVED_KEY).value("true"),
systemProperty("org.ops4j.pax.logging.DefaultServiceLog.level").value("INFO"),
/* Hamcrest & JUnit bundles */
restAssuredJunitBundles(),
/* Transitive dependencies needed in the Pax Exam
container.
Some of these need to be wrapped because they are not
available as OSGi bundles */
mavenBundle().groupId("org.apache.aries.spifly").artifactId("org.apache.aries.spifly.dynamic.bundle").version("1.2.1"),
mavenBundle().groupId("org.hamcrest").artifactId("hamcrest").versionAsInProject(),
mavenBundle().groupId("org.apache.commons").artifactId("commons-lang3").versionAsInProject(),
mavenBundle().groupId("org.codehaus.groovy").artifactId("groovy-json").versionAsInProject().noStart(),
mavenBundle().groupId("org.codehaus.groovy").artifactId("groovy-xml").versionAsInProject().noStart(),
mavenBundle().groupId("org.codehaus.groovy").artifactId("groovy").versionAsInProject(),
wrappedBundle(mavenBundle().groupId("org.ccil.cowan.tagsoup").artifactId("tagsoup").versionAsInProject()),
wrappedBundle(mavenBundle("jakarta.xml.bind",
"jakarta.xml.bind-api").versionAsInProject()),
wrappedBundle(mavenBundle("javax.activation",
"activation").version("1.1.1")),
wrappedBundle(mavenBundle("org.apache.httpcomponents",
"httpclient").versionAsInProject()),
wrappedBundle(mavenBundle("org.apache.httpcomponents",
"httpmime").versionAsInProject()),
wrappedBundle(mavenBundle("org.apache.httpcomponents",
"httpcore").versionAsInProject()),
/* Rest Assured dependencies needed in the Pax Exam
container to be able to execute the tests below */
mavenBundle("io.rest-assured",
"json-path").versionAsInProject(),
mavenBundle("io.rest-assured",
"xml-path").versionAsInProject(),
mavenBundle("io.rest-assured",
"rest-assured").versionAsInProject(),
mavenBundle("io.rest-assured",
"rest-assured-common").versionAsInProject()
};
}
@Test
public void getUUIDParsesAStringResultToUUID() {
final String UUID_XML = "<some>\n" +
" <thing
id=\"1\">db24eeeb-7fe5-41d3-8f06-986b793ecc91</thing>\n" +
" <thing
id=\"2\">d69ded28-d75c-460f-9cbe-1412c60ed4cc</thing>\n" +
"</some>";
final UUID uuid = from(UUID_XML).getUUID("some.thing[0]");
assertThat(uuid,
Matchers.equalTo(UUID.fromString("db24eeeb-7fe5-41d3-8f06-986b793ecc91")));
}
}
{code}
Project on github:
[rest-assured-itest-java-osgi|https://github.com/rest-assured/rest-assured/tree/master/examples/rest-assured-itest-java-osgi]
Error:
{code}
java.lang.ClassNotFoundException:
org.codehaus.groovy.runtime.ScriptBytecodeAdapter not found by groovy-xml [20]
at
org.apache.felix.framework.BundleWiringImpl.findClassOrResourceByDelegation(BundleWiringImpl.java:1597)
at
org.apache.felix.framework.BundleWiringImpl.access$300(BundleWiringImpl.java:79)
at
org.apache.felix.framework.BundleWiringImpl$BundleClassLoader.loadClass(BundleWiringImpl.java:1982)
at java.lang.ClassLoader.loadClass(ClassLoader.java:521)
at
org.apache.felix.framework.BundleWiringImpl.getClassByDelegation(BundleWiringImpl.java:1375)
at
org.apache.felix.framework.BundleWiringImpl.searchImports(BundleWiringImpl.java:1618)
at
org.apache.felix.framework.BundleWiringImpl.findClassOrResourceByDelegation(BundleWiringImpl.java:1548)
at
org.apache.felix.framework.BundleWiringImpl.access$300(BundleWiringImpl.java:79)
at
org.apache.felix.framework.BundleWiringImpl$BundleClassLoader.loadClass(BundleWiringImpl.java:1982)
at java.lang.ClassLoader.loadClass(ClassLoader.java:521)
at
io.restassured.internal.common.assertion.AssertParameter.notNull(AssertParameter.groovy:25)
at io.restassured.path.xml.XmlPath.get(XmlPath.java:316)
at io.restassured.path.xml.XmlPath.getUUID(XmlPath.java:584)
at
io.restassured.test.osgi.XmlPathOSGiITest.getUUIDParsesAStringResultToUUID(XmlPathOSGiITest.java:84)
at jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at
jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at
jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:566)
at
org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
at
org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
at
org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
at
org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
at
org.ops4j.pax.exam.invoker.junit.internal.ContainerTestRunner.runLeafWithRetry(ContainerTestRunner.java:97)
at
org.ops4j.pax.exam.invoker.junit.internal.ContainerTestRunner.runChildWithRetry(ContainerTestRunner.java:84)
at
org.ops4j.pax.exam.invoker.junit.internal.ContainerTestRunner.runChild(ContainerTestRunner.java:75)
at
org.ops4j.pax.exam.invoker.junit.internal.ContainerTestRunner.runChild(ContainerTestRunner.java:43)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
at org.junit.runner.JUnitCore.run(JUnitCore.java:115)
at
org.ops4j.pax.exam.invoker.junit.internal.JUnitProbeInvoker.invokeViaJUnit(JUnitProbeInvoker.java:124)
at
org.ops4j.pax.exam.invoker.junit.internal.JUnitProbeInvoker.findAndInvoke(JUnitProbeInvoker.java:97)
at
org.ops4j.pax.exam.invoker.junit.internal.JUnitProbeInvoker.call(JUnitProbeInvoker.java:73)
at jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at
jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at
jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:566)
at
org.ops4j.pax.swissbox.framework.RemoteFrameworkImpl.invokeMethodOnService(RemoteFrameworkImpl.java:435)
at
org.ops4j.pax.swissbox.framework.RemoteFrameworkImpl.invokeMethodOnService(RemoteFrameworkImpl.java:408)
at jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at
jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at
jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:566)
at sun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.java:359)
at sun.rmi.transport.Transport$1.run(Transport.java:200)
at sun.rmi.transport.Transport$1.run(Transport.java:197)
at java.security.AccessController.doPrivileged(Native Method)
at sun.rmi.transport.Transport.serviceCall(Transport.java:196)
at sun.rmi.transport.tcp.TCPTransport.handleMessages(TCPTransport.java:562)
at
sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run0(TCPTransport.java:796)
at
sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.lambda$run$0(TCPTransport.java:677)
at java.security.AccessController.doPrivileged(Native Method)
at
sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(TCPTransport.java:676)
at
java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
at
java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
at java.lang.Thread.run(Thread.java:834)
{code}
----
*Case 2: simple unit test using {{XmlParser}}*
To have an other look a the issue a simple unit-test that uses only {{groovy}}
and {{groovy-xml}} was created:
{code:java}
package example;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import groovy.util.Node;
import groovy.xml.XmlParser;
import org.junit.Test;
import org.osgi.framework.Bundle;
import org.osgi.framework.FrameworkUtil;
public class GroovyXmlTest {
private final Bundle bundle = FrameworkUtil.getBundle(this.getClass());
@Test
public void test() throws Exception {
assertNotNull("This test must be run inside an OSGi framework",
bundle);
String text = " <root>\n" +
" <technology>\n" +
" <name>Groovy</name>\n" +
" </technology>\n" +
" </root>";
Node node = new XmlParser().parseText(text);
assertEquals("root", node.name());
}
}
{code}
The unit-test is designed to run inside an OSGi container started with bndtools
(see the pom file).
It works great with version {{2.5.9}}, but does not with {{3.0.0}}. See
projects:
*
[groovy-v3-xml-test|https://github.com/jmini/bnd-experiments/tree/master/groovy-v3-xml-test]
=> not working
*
[groovy-v2-xml-test|https://github.com/jmini/bnd-experiments/tree/master/groovy-v2-xml-test]
=> OK
Stacktrace:
{code}
TEST test(example.GroovyXmlTest) <<< ERROR: groovy/xml/XmlParser
java.lang.NoClassDefFoundError: groovy/xml/XmlParser
at example.GroovyXmlTest.test(GroovyXmlTest.java:26)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at
org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
at
org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
at
org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
at
org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
at
org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)
at
org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
at junit.framework.JUnit4TestAdapter.run(JUnit4TestAdapter.java:38)
at junit.framework.TestSuite.runTest(TestSuite.java:252)
at junit.framework.TestSuite.run(TestSuite.java:247)
at aQute.junit.Activator.test(Activator.java:343)
at aQute.junit.Activator.automatic(Activator.java:234)
at aQute.junit.Activator.run(Activator.java:175)
at aQute.launcher.Launcher$5.call(Launcher.java:1299)
at aQute.launcher.Launcher$5.call(Launcher.java:1297)
at aQute.launcher.Launcher.run(Launcher.java:334)
at aQute.launcher.Launcher.main(Launcher.java:142)
Caused by: java.lang.ClassNotFoundException: groovy.xml.XmlParser cannot be
found by groovy-v3-xml-test_test_1.0.0
at
org.eclipse.osgi.internal.loader.BundleLoader.findClassInternal(BundleLoader.java:463)
at
org.eclipse.osgi.internal.loader.BundleLoader.findClass(BundleLoader.java:425)
at
org.eclipse.osgi.internal.loader.BundleLoader.findClass(BundleLoader.java:417)
at
org.eclipse.osgi.internal.loader.ModuleClassLoader.loadClass(ModuleClassLoader.java:171)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
... 28 more
{code}
> Groovy 4/5 not working in OSGi container
> ----------------------------------------
>
> Key: GROOVY-11570
> URL: https://issues.apache.org/jira/browse/GROOVY-11570
> Project: Groovy
> Issue Type: Bug
> Affects Versions: 5.0.0-alpha-12, 4.0.25
> Reporter: Jeremie Bresson
> Assignee: Paul King
> Priority: Major
>
> This is a followup to GROOVY-9402 which fixed FRAGMENT HOST in Groovy 3 but
> not later versions. It wasn't clear at the time whether the split packaging
> fixes would allow us not to have that attribute.
--
This message was sent by Atlassian Jira
(v8.20.10#820010)