[XOM-interest] XOM 1.2.2 beta 4

Paul King paulk at asert.com.au
Thu Jul 16 08:40:18 EDT 2009


Elliotte Harold wrote:
> I've uploaded XOM 1.2.2b4 to the usual location: http://www.xom.nu/unstable.html
> 
> I hope this fixes the various issues with OSGI that have been
> reported, and marks JUnit as optional as numerous folks requested.
> However I still have no plausible means of automatically testing this,
> and thus I have very little confidence. What I need is an automated
> JUnit test that verifies the correctness of the bundle, preferably
> without introducing large additional dependencies. If that's not
> possible, I'm inclined to drop the OSGI support completely. It's been
> a colossal hassle that has significantly delayed this release, and it
> seems likely to continue to cause problems in the future. I'm really
> not sure it's worth the additional complexity.
> 

It seemed to work for me. The exports have no version number which has
sometimes caused me problems in the past but I tested this with felix
this time around and it didn't seem to need them.

You might consider the suggestion on OSGi testing from here:

http://www.talios.com/osgi_based_integration_testing_with_testng_and_apache_felix.htm

I borrowed that concept but wrapped it in a little Groovy script so that I
run without TestNG or Maven. I placed the xom jar in ~/xom/xom-1.2.2b4.jar
and then cut and paste the following script into a recent (1.7-beta-snapshot)
version of GroovyConsole. It downloads felix, creates an activator bundle,
runs the bundle (which prints out an exemplar class name - which hopefully
confirms there are no classloader issues) and then checks that all the
bundles are Active for good measure. Perhaps you can borrow ideas from
this or the above reference to make a suitable test. I also have a
version of this script without the @Grab annotation which is suitable
for use within a more typical source environment where you have downloaded
felix manually. Happy to share that with you if you prefer. 

Output of the script below is something like:

    [javac] Compiling 1 source file to C:\Users\paulk\build
      [jar] Building jar: C:\Users\paulk\build\XomHello.jar
nu.xom.Info

on Windows but hopefully should work cross platform.

Cheers, Paul.

---------------------------->8----------------------------
import org.apache.felix.framework.util.StringMap
import org.apache.felix.framework.Felix
import static org.osgi.framework.Bundle.ACTIVE
import static org.osgi.framework.Constants.FRAMEWORK_SYSTEMPACKAGES

@Grab(group='org.apache.felix', module='org.apache.felix.framework', version='1.8.1')
def getFelixDir(){
     new File(System.getProperty('user.home'),
         '.groovy/grapes/org.apache.felix/org.apache.felix.framework/bundles').toURI().path +
             'org.apache.felix.framework-1.8.1.jar'
}

def userHome = new File(System.getProperty('user.home')).toURI().path
def buildDir = new File(userHome, 'build').canonicalPath
def ant = new AntBuilder()
ant.with {
    mkdir dir:"$buildDir/xom"
    echo file:"$buildDir/xom/XomHelloActivator.java", '''
        package xom;
        import org.osgi.framework.*;
        public class XomHelloActivator implements BundleActivator {
            public void start(BundleContext context) throws Exception {
                System.out.println("Found class: " + Class.forName("nu.xom.Info").getName());
            }
            public void stop(BundleContext context) throws Exception { }
        }
    '''
    javac srcdir:buildDir, includes:'**/*.java', destdir:buildDir, classpath:felixDir
    jar destfile:"$buildDir/XomHello.jar", basedir:buildDir, includes:'**/*.class', {
        manifest {
            attribute name:'Export-Package', value:'xom;version="1.0.0"'
            attribute name:'Bundle-Activator', value:'xom.XomHelloActivator'
            attribute name:'Import-Package',
                value:'xom;version="1.0.0",org.w3c.dom,org.osgi.framework;version="1.3.0",nu.xom;version="1.2.2.b4"'
        }
    }
}

def configMap = new StringMap(false)
configMap[FRAMEWORK_SYSTEMPACKAGES] = '''
    org.osgi.framework; version=1.3.0,
    org.osgi.service.packageadmin; version=1.2.0,
    org.osgi.service.startlevel; version=1.0.0,
    org.osgi.service.url; version=1.0.0,
    org.w3c.dom,
    org.xml.sax,
    org.xml.sax.ext,
    org.xml.sax.helpers,
    javax.xml.transform.sax,
    javax.xml.transform
'''

def m_felix = new Felix(configMap)
m_felix.start()

def bundleContext = m_felix.bundleContext

bundleContext.installBundle("file://${userHome}xom/xom-1.2.2b4.jar").start()
bundleContext.installBundle("file://${userHome}build/XomHello.jar").start()

bundleContext.bundles.each {
    assert it.state == ACTIVE: "Bundle $it.symbolicName is not started."
}

m_felix.stop()
---------------------------->8----------------------------


More information about the XOM-interest mailing list