package org.metaborg.spoofax.core.resource;

import org.apache.commons.vfs2.CacheStrategy;
import org.apache.commons.vfs2.FileSystemException;
import org.apache.commons.vfs2.FileSystemManager;
import org.apache.commons.vfs2.cache.DefaultFilesCache;
import org.apache.commons.vfs2.impl.DefaultFileSystemManager;
import org.apache.commons.vfs2.provider.local.DefaultLocalFileProvider;
import org.apache.commons.vfs2.provider.ram.RamFileProvider;
import org.apache.commons.vfs2.provider.res.ResourceFileProvider;

import com.google.inject.Provider;

/**
 * Guice provider for the VFS file system manager. Subclass and override the protected methods, and bind the provider in
 * your Guice module, to customize the file providers.
 */
public class DefaultFileSystemManagerProvider implements Provider<FileSystemManager> {
    @Override public FileSystemManager get() {
        try {
            final DefaultFileSystemManager manager = new DefaultFileSystemManager();
            manager.setFilesCache(new DefaultFilesCache());
            manager.setCacheStrategy(CacheStrategy.ON_RESOLVE);

            addDefaultProvider(manager);
            addProviders(manager);

            manager.init();
            return manager;
        } catch(FileSystemException e) {
            throw new RuntimeException("Cannot initialze resource service: " + e.getMessage(), e);
        }
    }

    protected void addDefaultProvider(DefaultFileSystemManager manager) throws FileSystemException {
        final DefaultLocalFileProvider provider = new DefaultLocalFileProvider();
        manager.addProvider("file", provider);
        manager.setDefaultProvider(provider);
    }

    protected void addProviders(DefaultFileSystemManager manager) throws FileSystemException {
        manager.addProvider("res", new ResourceFileProvider());
        manager.addProvider("ram", new RamFileProvider());
    }
}

@@ -348,153 +348,911 @@
 der.
-local.DefaultLocalFileProvider;%0Aimport org.apache.commons.vfs2.provider.ram.RamFileProvider;%0Aimport org.apache.commons.vfs2.provider.res.Resource
+bzip2.Bzip2FileProvider;%0Aimport org.apache.commons.vfs2.provider.ftp.FtpFileProvider;%0Aimport org.apache.commons.vfs2.provider.ftps.FtpsFileProvider;%0Aimport org.apache.commons.vfs2.provider.gzip.GzipFileProvider;%0Aimport org.apache.commons.vfs2.provider.https.HttpsFileProvider;%0Aimport org.apache.commons.vfs2.provider.jar.JarFileProvider;%0Aimport org.apache.commons.vfs2.provider.local.DefaultLocalFileProvider;%0Aimport org.apache.commons.vfs2.provider.ram.RamFileProvider;%0Aimport org.apache.commons.vfs2.provider.res.ResourceFileProvider;%0Aimport org.apache.commons.vfs2.provider.tar.TarFileProvider;%0Aimport org.apache.commons.vfs2.provider.tar.Tbz2FileProvider;%0Aimport org.apache.commons.vfs2.provider.tar.TgzFileProvider;%0Aimport org.apache.commons.vfs2.provider.temp.TemporaryFileProvider;%0Aimport org.apache.commons.vfs2.provider.webdav.WebdavFileProvider;%0Aimport org.apache.commons.vfs2.provider.zip.Zip
 File
@@ -1406,24 +1406,27 @@
 and bind the
+%0A *
  provider in
@@ -1425,19 +1425,16 @@
 vider in
-%0A *
  your Gu
@@ -2500,32 +2500,97 @@
 stemException %7B%0A
+        manager.addProvider(%22tmp%22, new TemporaryFileProvider());%0A
         manager.
@@ -2692,20 +2692,747 @@
 rovider());%0A
+        manager.addProvider(%22zip%22, new ZipFileProvider());%0A        manager.addProvider(%22jar%22, new JarFileProvider());%0A        manager.addProvider(%22tar%22, new TarFileProvider());%0A        manager.addProvider(%22tgz%22, new TgzFileProvider());%0A        manager.addProvider(%22tbz2%22, new Tbz2FileProvider());%0A        manager.addProvider(%22gz%22, new GzipFileProvider());%0A        manager.addProvider(%22bz2%22, new Bzip2FileProvider());%0A        manager.addProvider(%22http%22, new HttpsFileProvider());%0A        manager.addProvider(%22https%22, new HttpsFileProvider());%0A        manager.addProvider(%22webdav%22, new WebdavFileProvider());%0A        manager.addProvider(%22ftp%22, new FtpFileProvider());%0A        manager.addProvider(%22ftps%22, new FtpsFileProvider());%0A
     %7D%0A%7D%0A

Add common VFS file providers.