package org.metaborg.sunshine;

import org.apache.commons.vfs2.FileSystemManager;
import org.metaborg.runtime.task.primitives.TaskLibrary;
import org.metaborg.spoofax.core.SpoofaxModule;
import org.metaborg.spoofax.core.stratego.StrategoRuntimeService;
import org.metaborg.sunshine.drivers.SunshineMainDriver;
import org.metaborg.sunshine.environment.LaunchConfiguration;
import org.metaborg.sunshine.environment.SunshineMainArguments;
import org.metaborg.sunshine.prims.SunshineLibrary;
import org.metaborg.sunshine.services.filesource.SunshineFileSystemManagerProvider;
import org.metaborg.sunshine.statistics.Statistics;
import org.spoofax.interpreter.library.IOperatorRegistry;
import org.spoofax.interpreter.library.index.legacy.LegacyIndexLibrary;

import com.google.inject.Singleton;
import com.google.inject.multibindings.Multibinder;
import com.google.inject.name.Names;

public class SunshineModule extends SpoofaxModule {
	private final SunshineMainArguments args;

	public SunshineModule(SunshineMainArguments args) {
		this.args = args;
	}

	@Override
	protected void configure() {
		super.configure();

		bind(SunshineMainArguments.class).toInstance(args);
		bind(LaunchConfiguration.class).asEagerSingleton();
		bind(SunshineMainDriver.class).asEagerSingleton();
		bind(StrategoRuntimeService.class).asEagerSingleton();
		bind(Statistics.class).asEagerSingleton();

		final Multibinder<IOperatorRegistry> strategoLibraryBinder = Multibinder
				.newSetBinder(binder(), IOperatorRegistry.class);
		strategoLibraryBinder.addBinding().toInstance(new TaskLibrary());
		strategoLibraryBinder.addBinding().toInstance(new LegacyIndexLibrary());
		strategoLibraryBinder.addBinding().toInstance(new SunshineLibrary());

		bind(String.class).annotatedWith(
				Names.named("LanguageDiscoveryAnalysisOverride")).toInstance(
				"analysis-cmd");
		bind(ClassLoader.class).annotatedWith(
				Names.named("ResourceClassLoader")).toInstance(
				this.getClass().getClassLoader());
	}

	@Override
	protected void bindFileSystemManager() {
		bind(FileSystemManager.class).toProvider(
				SunshineFileSystemManagerProvider.class).in(Singleton.class);
	}
}

@@ -180,16 +180,135 @@
 Module;%0A
+import org.metaborg.spoofax.core.resource.IResourceService;%0Aimport org.metaborg.spoofax.core.resource.ResourceService;%0A
 import o
@@ -1197,24 +1197,27 @@
 oid 
-config
+bindReso
 ur
+c
 e() %7B%0A%09%09
 supe
@@ -1216,27 +1216,243 @@
 %7B%0A%09%09
-super.configure();%0A
+bind(IResourceService.class).to(ResourceService.class).in(%0A%09%09%09%09Singleton.class);%0A%09%09bind(FileSystemManager.class).toProvider(%0A%09%09%09%09SunshineFileSystemManagerProvider.class).in(Singleton.class);%0A%09%7D%0A%0A%09@Override%0A%09protected void bindOther() %7B
 %0A%09%09b
@@ -2318,174 +2318,7 @@
 ;%0A%09%7D
-%0A%0A%09@Override%0A%09protected void bindFileSystemManager() %7B%0A%09%09bind(FileSystemManager.class).toProvider(%0A%09%09%09%09SunshineFileSystemManagerProvider.class).in(Singleton.class);%0A%09%7D
 %0A%7D%0A

Update to new Spoofax core.