package org.forgeide.producer;

import java.io.File;
import java.util.List;
import java.util.ServiceLoader;

import javax.enterprise.context.ApplicationScoped;
import javax.enterprise.inject.Produces;

import org.jboss.forge.furnace.Furnace;
import org.jboss.forge.furnace.repositories.AddonRepository;
import org.jboss.forge.furnace.repositories.AddonRepositoryMode;
import org.jboss.forge.furnace.repositories.MutableAddonRepository;
import org.jboss.forge.furnace.util.OperatingSystemUtils;

/**
 * 
 * @author Shane Bryzak
 * 
 */
@ApplicationScoped
public class FurnaceProducer {

    private final Furnace furnace;


    public FurnaceProducer() {

        furnace = ServiceLoader.load(Furnace.class).iterator().next();

        String[] args = {};

        furnace.setArgs(args);

        if (!containsMutableRepository(furnace.getRepositories()))
            furnace.addRepository(AddonRepositoryMode.MUTABLE, new File(OperatingSystemUtils.getUserForgeDir(),
                    "addons"));

        furnace.start();

    }

    @Produces
    public Furnace getFurnace() {
        return furnace;
    }

    private boolean containsMutableRepository(List<AddonRepository> repositories)
    {
       boolean result = false;
       for (AddonRepository repository : repositories)
       {
          if (repository instanceof MutableAddonRepository)
          {
             result = true;
             break;
          }
       }
       return result;
    }


}

@@ -421,32 +421,82 @@
 ddonRepository;%0A
+import org.jboss.forge.furnace.se.FurnaceFactory;%0A
 import org.jboss
@@ -720,57 +720,34 @@
 e = 
-ServiceLoader.load(Furnace.class).iterator().next
+FurnaceFactory.getInstance
 ();%0A

use FurnaceFactory to create Furnace instance