Skip to content

Commit

Permalink
FURNACE-66: Added method to return current addon
Browse files Browse the repository at this point in the history
  • Loading branch information
gastaldi committed Aug 6, 2015
1 parent 428eba2 commit 0c5ae99
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,33 @@
*/
public class SimpleContainer
{
private static Map<ClassLoader, Furnace> started = new ConcurrentHashMap<>();
private static Map<Addon, Furnace> started = new ConcurrentHashMap<>();

/**
* Used to retrieve an instance of {@link Furnace}.
*/
public static Furnace getFurnace(ClassLoader loader)
{
return started.get(getAddon(loader));
}

/**
* Returns the {@link Addon} for which the given ClassLoader represents.
*
* @param loader the {@link ClassLoader} this {@link Furnace} runtime can be found
* @return the {@link Addon} for which the given ClassLoader represents
*/
public static Addon getAddon(ClassLoader loader)
{
Assert.notNull(loader, "ClassLoader must not be null");
return started.get(loader);
for (Addon addon : started.keySet())
{
if (addon.getClassLoader() == loader)
{
return addon;
}
}
return null;
}

/**
Expand All @@ -57,12 +75,12 @@ public static <T> Imported<T> getServices(ClassLoader classloader, Class<T> serv

static void start(Addon addon, Furnace furnace)
{
started.put(addon.getClassLoader(), furnace);
started.put(addon, furnace);
}

static void stop(Addon addon)
{
started.remove(addon.getClassLoader());
started.remove(addon);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import org.jboss.arquillian.container.test.api.Deployment;
import org.jboss.arquillian.junit.Arquillian;
import org.jboss.forge.furnace.Furnace;
import org.jboss.forge.furnace.addons.Addon;
import org.jboss.forge.furnace.container.simple.lifecycle.SimpleContainer;
import org.junit.Assert;
import org.junit.Test;
Expand All @@ -26,10 +27,18 @@
public class AddonArchiveDefaultSmokeTest
{
@Test
public void test()
public void testFurnace()
{
Furnace furnace = SimpleContainer.getFurnace(getClass().getClassLoader());
Assert.assertThat(furnace, notNullValue());
}

@Test
public void testAddon()
{
Addon addon = SimpleContainer.getAddon(getClass().getClassLoader());
Assert.assertThat(addon, notNullValue());
Assert.assertEquals("_DEFAULT_", addon.getId().getName());
}

}

0 comments on commit 0c5ae99

Please sign in to comment.