package org.metaborg.core.plugin;

import java.util.Collection;
import java.util.ServiceLoader;

import org.metaborg.core.MetaborgException;

import com.google.common.collect.Iterables;
import com.google.common.collect.Lists;
import com.google.inject.Module;

/**
 * Module plugin loader using Java's {@link ServiceLoader}.
 */
public class ServiceModulePluginLoader implements IModulePluginLoader {
    @Override public Iterable<Module> modules() throws MetaborgException {
        try {
            final ServiceLoader<IServiceModulePlugin> modulePlugins = ServiceLoader.load(IServiceModulePlugin.class);
            final Collection<Module> modules = Lists.newLinkedList();
            for(IServiceModulePlugin plugin : modulePlugins) {
                Iterables.addAll(modules, plugin.modules());
            }
            return modules;
        } catch(Exception e) {
            throw new MetaborgException("Unhandled exception while loading module plugins with Java's ServiceLoader", e);
        }
    }
}

@@ -359,16 +359,48 @@
 inLoader
+%3CT extends IServiceModulePlugin%3E
  impleme
@@ -425,16 +425,187 @@
 oader %7B%0A
+    private final Class%3CT%3E serviceClass;%0A    %0A    %0A    public ServiceModulePluginLoader(Class%3CT%3E serviceClass) %7B%0A        this.serviceClass = serviceClass;%0A    %7D%0A    %0A    %0A
     @Ove
@@ -717,36 +717,17 @@
 eLoader%3C
-IServiceModulePlugin
+T
 %3E module
@@ -759,30 +759,16 @@
 oad(
-IS
+s
 ervice
-ModulePlugin.c
+C
 lass
@@ -856,36 +856,17 @@
     for(
-IServiceModulePlugin
+T
  plugin 

Generalize service module plugin loader, in preparation for same loading mechanism for language specification Module plugins.