class IndexUpgraderWrapper implements AutoCloseable {

    public void upgradeIndex( Path indexPath ) throws Throwable
    {
        // since lucene use ServiceLocator to load services, context class loader need to be replaced as well
        ClassLoader contextClassLoader = Thread.currentThread().getContextClassLoader();
        try
        {
            if ( mainMethod == null )
            {
                luceneLoader = jarLoaderSupplier.get();
                Class upgrader = luceneLoader.loadEmbeddedClass( LUCENE_INDEX_UPGRADER_CLASS_NAME );
                MethodHandles.Lookup lookup = MethodHandles.lookup();
                mainMethod = lookup.findStatic( upgrader, "main", MethodType.methodType( void.class, String[].class ) );
            }
            Thread.currentThread().setContextClassLoader( luceneLoader.getJarsClassLoader() );
            mainMethod.invokeExact( new String[]{indexPath.toString()} );
        }
        finally
        {
            Thread.currentThread().setContextClassLoader( contextClassLoader );
        }
    }

      IndexUpgraderWrapper( Supplier<EmbeddedJarLoader> jarLoaderSupplier );

}