[osmosis-dev] call osmosis from groovy

Brett Henderson brett at bretth.com
Mon Sep 19 13:31:50 BST 2011


Hi Ruediger,

On Mon, Sep 19, 2011 at 9:57 PM, Gubler, Ruediger <rgubler at init-ka.de>wrote:

> Hi,****
>
> ** **
>
> i have now an other problem.****
>
> I must call osmosis in the mid of my process chain and it will do a
> System.exit(0)****
>
> ** **
>
> I found there is a run method in "org.openstreetmap.osmosis.core.Osmosis"
>  but it doesn't work with the following code:
>

The Osmosis.main method does nothing except call the run method and call
System.exit().  If your code works with the main method it should also work
with the run method.  Many of the Osmosis unit tests use the run method
directly.


> ****
>
> ** **
>
>   localDirectory = new
> File(getClass().protectionDomain.codeSource.location.path).parent****
>
>   File libFolder = new File(localDirectory, "/osmosis-0.39/lib/default/")*
> ***
>
>   File[] libs = libFolder.listFiles()****
>
>   List<URL> urlList = new ArrayList<URL>()****
>
>   for(File currLib : libs)****
>
>   {****
>
>     URL currUrl = new URL("file:/" + currLib.canonicalPath)****
>
>     urlList.add(currUrl)****
>
> ** **
>
>     println(currUrl)****
>
>   }****
>
>   URL[] urls = new URL[urlList.size()]****
>
>   urls = urlList.toArray(urls)****
>
>   ClassLoader classLoader = new URLClassLoader(urls,
> getClass().getClassLoader());****
>
>   GroovyShell downloadShell = new GroovyShell(classLoader, binding);****
>
>   processErrorStatus = downloadShell.evaluate(new File(localDirectory,
> "/innerDownloadCall.groovy"))****
>
> ** **
>
> ** **
>
> 19.09.2011 13:48:05 org.openstreetmap.osmosis.core.Osmosis run****
>
> INFO: Osmosis Version 0.39****
>
> 19.09.2011 13:48:05 org.openstreetmap.osmosis.core.Osmosis run****
>
> INFO: Preparing pipeline.****
>
> org.openstreetmap.osmosis.core.OsmosisRuntimeException: Task type read-api
> doesn't exist.****
>
>         at
> org.openstreetmap.osmosis.core.pipeline.common.TaskManagerFactoryRegister.getInstance(TaskManagerFactoryRegister.java:60)
> ****
>
>         at
> org.openstreetmap.osmosis.core.pipeline.common.Pipeline.buildTasks(Pipeline.java:50)
> ****
>
>         at
> org.openstreetmap.osmosis.core.pipeline.common.Pipeline.prepare(Pipeline.java:112)
> ****
>
>         at org.openstreetmap.osmosis.core.Osmosis.run(Osmosis.java:86)
>

For some reason it seems like the "osmosis-plugins.conf" file is not being
found in the osmosis-xml-<version>.jar file.  Every non-core osmosis jar
file is itself a plugin, and the XML tasks are one of these.

Internally, the TaskRegistrar class uses the following line to find all
osmosis-plugins.conf files.
Thread.currentThread().getContextClassLoader().getResources(pluginResourceName)

Note that it uses the thread context class loader to load resources rather
than the class loader used to load the TaskRegistrar class.  This is a
standard technique because it allows you to play well with application
servers, but it relies on calling code to have set the thread context class
loader.  Perhaps this is causing your problem.  Can you try adding the
following line prior to launching Groovy?
Thread.currentThread().setContextClassLoader(classloader)

Note that the above line will only work if Osmosis gets run within the same
thread that you execute the above line in.  If Groovy creates its own
threads you'll have problems.  If the above line does work you should reset
the thread context class loader back to the original value after your Groovy
runtime exits.


> ****
>
> ** **
>
> The class path of the downloadShell contains ****
>
> aopalliance-1.0.jar****
>
> commons-codec-1.4.jar****
>
> commons-compress-1.0.jar****
>
> commons-dbcp-1.4.jar****
>
> commons-logging-1.1.1.jar****
>
> commons-pool-1.5.4.jar****
>
> jpf-1.5.jar****
>
> mysql-connector-java-5.1.10.jar****
>
> osmosis-apidb-0.39.jar****
>
> osmosis-areafilter-0.39.jar****
>
> osmosis-core-0.39.jar****
>
> osmosis-dataset-0.39.jar****
>
> osmosis-extract-0.39.jar****
>
> osmosis-hstore-0.39.jar****
>
> osmosis-pbf-0.39.jar****
>
> osmosis-pgsimple-0.39.jar****
>
> osmosis-pgsnapshot-0.39.jar****
>
> osmosis-replication-0.39.jar****
>
> osmosis-set-0.39.jar****
>
> osmosis-tagfilter-0.39.jar****
>
> osmosis-xml-0.39.jar****
>
> osmpbf-1.1.1-754a33af.jar****
>
> plexus-classworlds-2.2.2.jar****
>
> postgis-jdbc-1.3.3.jar****
>
> postgresql-8.4-701.jdbc4.jar****
>
> protobuf-java-2.3.0.jar****
>
> spring-aop-3.0.3.RELEASE.jar****
>
> spring-asm-3.0.3.RELEASE.jar****
>
> spring-beans-3.0.3.RELEASE.jar****
>
> spring-context-3.0.3.RELEASE.jar****
>
> spring-core-3.0.3.RELEASE.jar****
>
> spring-expression-3.0.3.RELEASE.jar****
>
> spring-jdbc-3.0.3.RELEASE.jar****
>
> spring-tx-3.0.3.RELEASE.jar****
>
> stax2-api-3.0.2.jar****
>
> woodstox-core-lgpl-4.0.3.jar****
>
> xercesImpl-2.9.1.jar
>

These look correct.  Can you try to access the
org.openstreetmap.osmosis.xml.XmlPluginLoader class using your special
classloader to ensure that the XML classes are on the classpath?  Or a
better test is to get a list of all resources with name osmosis-plugins.conf
using your classloader, open them all up and verify that one contains the
line org.openstreetmap.osmosis.xml.XmlPluginLoader.


> ****
>
> ** **
>
> What is going wrong or how can I setup plexus-classworlds to call the run
> not main method?
>

I don't know, but I doubt it.


Brett
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.openstreetmap.org/pipermail/osmosis-dev/attachments/20110919/1c90fec9/attachment.html>


More information about the osmosis-dev mailing list