/*******************************************************************************
 * Copyright (c) 2012-2016 Codenvy, S.A.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *   Codenvy, S.A. - initial API and implementation
 *******************************************************************************/
package org.eclipse.che.plugin.docker.machine.ext;

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

import org.eclipse.che.api.core.model.machine.ServerConf;
import org.eclipse.che.inject.CheBootstrap;
import org.eclipse.che.plugin.docker.machine.ext.provider.WsAgentServerConfProvider;

/**
 * Guice module for extension servers feature in docker machines
 *
 * @author Alexander Garagatyi
 * @author Sergii Leschenko
 */
// Not a DynaModule, install manually
public class DockerExtServerModule extends AbstractModule {
    @Override
    protected void configure() {
        Multibinder<ServerConf> machineServers = Multibinder.newSetBinder(binder(),
                                                                          ServerConf.class,
                                                                          Names.named("machine.docker.dev_machine.machine_servers"));
        machineServers.addBinding().toProvider(WsAgentServerConfProvider.class);

        Multibinder<String> volumesMultibinder = Multibinder.newSetBinder(binder(),
                                                                          String.class,
                                                                          Names.named("machine.docker.dev_machine.machine_volumes"));
        volumesMultibinder.addBinding()
                          .toProvider(org.eclipse.che.plugin.docker.machine.ext.provider.ExtServerVolumeProvider.class);

        Multibinder<String> debMachineEnvVars = Multibinder.newSetBinder(binder(),
                                                                         String.class,
                                                                         Names.named("machine.docker.dev_machine.machine_env"));
        debMachineEnvVars.addBinding().toProvider(org.eclipse.che.plugin.docker.machine.ext.provider.ApiEndpointEnvVariableProvider.class);
        debMachineEnvVars.addBinding().toProvider(org.eclipse.che.plugin.docker.machine.ext.provider.ProjectsRootEnvVariableProvider.class);
        debMachineEnvVars.addBinding()
                         .toInstance(CheBootstrap.CHE_LOCAL_CONF_DIR
                                     + '='
                                     + org.eclipse.che.plugin.docker.machine.ext.provider.DockerExtConfBindingProvider
                                             .EXT_CHE_LOCAL_CONF_DIR);

        org.eclipse.che.plugin.docker.machine.ext.provider.DockerExtConfBindingProvider extConfBindingProvider =
                new org.eclipse.che.plugin.docker.machine.ext.provider.DockerExtConfBindingProvider();
        if (extConfBindingProvider.get() != null) {
            volumesMultibinder.addBinding().toProvider(extConfBindingProvider);
        }
    }
}

@@ -2056,17 +2056,17 @@
 ring%3E de
-b
+v
 MachineE
@@ -2323,16 +2323,95 @@
 e_env%22))
+%0A                                                           .permitDuplicates()
 ;%0A      
@@ -2406,33 +2406,33 @@
 es();%0A        de
-b
+v
 MachineEnvVars.a
@@ -2546,33 +2546,33 @@
 ass);%0A        de
-b
+v
 MachineEnvVars.a
@@ -2695,17 +2695,17 @@
       de
-b
+v
 MachineE
@@ -3026,16 +3026,553 @@
 F_DIR);%0A
+        Multibinder%3CString%3E allMachinesEnvVars = Multibinder.newSetBinder(binder(),%0A                                                                          String.class,%0A                                                                          Names.named(%22machine.docker.machine_env%22))%0A                                                            .permitDuplicates();%0A        allMachinesEnvVars.addBinding()%0A                          .toProvider(org.eclipse.che.plugin.docker.machine.ext.provider.ApiEndpointEnvVariableProvider.class);
 %0A       

Add api endpoint property into each non dev machine environment