package org.metaborg.spoofax.eclipse.resource;

import java.util.Collection;

import org.apache.commons.vfs2.Capability;
import org.apache.commons.vfs2.FileName;
import org.apache.commons.vfs2.FileObject;
import org.apache.commons.vfs2.FileSystemOptions;
import org.apache.commons.vfs2.provider.AbstractFileName;
import org.apache.commons.vfs2.provider.AbstractFileSystem;
import org.eclipse.core.resources.IWorkspaceRoot;
import org.eclipse.core.resources.ResourcesPlugin;

public class EclipseResourceFileSystem extends AbstractFileSystem {
    private final IWorkspaceRoot root;


    public EclipseResourceFileSystem(FileName rootName, FileObject parentLayer, FileSystemOptions fileSystemOptions) {
        super(rootName, parentLayer, fileSystemOptions);
        this.root = ResourcesPlugin.getWorkspace().getRoot();
    }


    @Override protected FileObject createFile(AbstractFileName name) throws Exception {
        return new EclipseResourceFileObject(name, root, this);
    }

    @Override protected void addCapabilities(Collection<Capability> caps) {
        caps.addAll(EclipseResourceProvider.capabilities);
    }
}

@@ -41,16 +41,65 @@
 ource;%0A%0A
+import java.io.File;%0Aimport java.io.IOException;%0A
 import j
@@ -119,16 +119,16 @@
 ection;%0A
-
 %0Aimport 
@@ -247,16 +247,61 @@
 Object;%0A
+import org.apache.commons.vfs2.FileSelector;%0A
 import o
@@ -460,16 +460,61 @@
 System;%0A
+import org.eclipse.core.resources.IResource;%0A
 import o
@@ -605,16 +605,55 @@
 sPlugin;
+%0Aimport org.eclipse.core.runtime.IPath;
 %0A%0Apublic
@@ -1232,24 +1232,24 @@
 ty%3E caps) %7B%0A
-
         caps
@@ -1300,11 +1300,720 @@
 );%0A    %7D
+%0A%0A    @Override protected File doReplicateFile(FileObject file, FileSelector selector) throws Exception %7B%0A        final EclipseResourceFileObject eclipseResource = (EclipseResourceFileObject) file;%0A        final IResource resource = eclipseResource.resource();%0A        if(resource == null) %7B%0A            throw new IOException(%22Cannot get Eclipse resource corresponding to %22 + file);%0A        %7D%0A        IPath path = resource.getRawLocation();%0A        if(path == null) %7B%0A            path = resource.getLocation();%0A        %7D%0A        if(path == null) %7B%0A            throw new IOException(%22Resource %22 + file + %22 does not reside on the local file system%22);%0A        %7D%0A        return path.makeAbsolute().toFile();%0A    %7D
 %0A%7D%0A

Implement local file replication for the Eclipse file system.