Java Code Examples for org.jboss.forge.furnace.Furnace#getAddonRegistry()

The following examples show how to use org.jboss.forge.furnace.Furnace#getAddonRegistry() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ExportedInstanceApiTest.java    From furnace with Eclipse Public License 1.0 6 votes vote down vote up
@Test
public void testExportedInstanceExposesServiceTypeAndSourceAddon() throws Exception
{
   Furnace furnace = LocalServices.getFurnace(getClass().getClassLoader());
   Assert.assertNotNull(furnace);
   AddonRegistry registry = furnace.getAddonRegistry();
   boolean found = false;
   for (Addon addon : registry.getAddons())
   {
      ExportedInstance<ExportedInstanceApiTest> instance = addon.getServiceRegistry()
               .getExportedInstance(ExportedInstanceApiTest.class);
      if (instance != null)
      {
         found = true;
         Assert.assertEquals(ExportedInstanceApiTest.class, instance.getActualType());
         Assert.assertEquals(addon, instance.getSourceAddon());
         break;
      }
   }
   Assert.assertTrue("Could not locate service in any addon.", found);
}
 
Example 2
Source File: ProjectGenerator.java    From fabric8-forge with Apache License 2.0 5 votes vote down vote up
public ProjectGenerator(Furnace furnace, File projectsOutputFolder, File localMavenRepo) throws Exception {
    this.furnace = furnace;
    this.projectsOutputFolder = projectsOutputFolder;
    this.localMavenRepo = localMavenRepo;
    addonRegistry = furnace.getAddonRegistry();

    resourceFactory = addonRegistry.getServices(ResourceFactory.class).get();
    commandControllerFactory = addonRegistry.getServices(CommandControllerFactory.class).get();
    commandFactory = addonRegistry.getServices(CommandFactory.class).get();

}
 
Example 3
Source File: BootstrapClassLoaderTestCase.java    From furnace with Eclipse Public License 1.0 5 votes vote down vote up
@Test(expected = IllegalStateException.class)
public void shouldBeAbleToUseFactoryDelegateTypesafely() throws Exception
{
   Furnace instance = FurnaceFactory.getInstance();
   Assert.assertNotNull(instance);
   AddonRegistry registry = instance.getAddonRegistry();
   Assert.assertNotNull(registry);
}
 
Example 4
Source File: PostStartupEventTest.java    From furnace with Eclipse Public License 1.0 5 votes vote down vote up
@Test
public void testPostStartupIsCalled() throws Exception
{
   Furnace furnace = LocalServices.getFurnace(getClass().getClassLoader());
   AddonRegistry registry = furnace.getAddonRegistry();
   RecordingEventManager manager = registry.getServices(RecordingEventManager.class).get();
   Assert.assertEquals(2, manager.getPostStartupCount());
}
 
Example 5
Source File: PreShutdownEventTest.java    From furnace with Eclipse Public License 1.0 5 votes vote down vote up
@Test(timeout = 5000)
public void testPreShutdownIsCalled() throws Exception
{
   Furnace furnace = LocalServices.getFurnace(getClass().getClassLoader());
   AddonRegistry registry = furnace.getAddonRegistry();
   Addon dep2 = registry.getAddon(AddonId.from("dep2", "2"));
   RecordingEventManager manager = registry.getServices(RecordingEventManager.class).get();
   Assert.assertEquals(3, manager.getPostStartupCount());
   MutableAddonRepository repository = (MutableAddonRepository) furnace.getRepositories().get(0);
   repository.disable(dep2.getId());
   Addons.waitUntilStopped(dep2);
   Assert.assertEquals(1, manager.getPreShutdownCount());
}
 
Example 6
Source File: AddonRepositoryLoadingTest.java    From furnace with Eclipse Public License 1.0 5 votes vote down vote up
@Test
public void testAddonRepositoryIsCorrectInMultiViewEnvironment() throws Exception
{
   Furnace furnace = LocalServices.getFurnace(getClass().getClassLoader());
   Assert.assertNotNull(furnace);
   AddonRegistry registry = furnace.getAddonRegistry();
   AddonRepository rep1 = registry.getAddon(AddonId.from("dep1", "1")).getRepository();
   AddonRepository rep2 = registry.getAddon(AddonId.from("dep2", "2")).getRepository();
   AddonRepository rep3 = registry.getAddon(AddonId.from("dep3", "3")).getRepository();
   AddonRepository rep4 = registry.getAddon(AddonId.from("dep4", "4")).getRepository();
   AddonRepository rep5 = registry.getAddon(AddonId.from("dep5", "5")).getRepository();
   Assert.assertEquals(rep1, rep2);
   Assert.assertEquals(rep3, rep4);
   Assert.assertEquals(rep4, rep5);
}
 
Example 7
Source File: ImportedTest.java    From furnace with Eclipse Public License 1.0 5 votes vote down vote up
@Test
public void testIsAmbiguous() throws Exception
{
   Furnace furnace = LocalServices.getFurnace(getClass().getClassLoader());
   AddonRegistry registry = furnace.getAddonRegistry();
   Imported<MockInterface> services = registry.getServices(MockInterface.class);
   Assert.assertFalse(services.isUnsatisfied());
   Assert.assertTrue(services.isAmbiguous());
}
 
Example 8
Source File: ImportedTest.java    From furnace with Eclipse Public License 1.0 5 votes vote down vote up
@Test
public void testIsAmbiguousUsingClassName() throws Exception
{
   Furnace furnace = LocalServices.getFurnace(getClass().getClassLoader());
   AddonRegistry registry = furnace.getAddonRegistry();
   Imported<MockInterface> services = registry.getServices(MockInterface.class.getName());
   Assert.assertFalse(services.isUnsatisfied());
   Assert.assertTrue(services.isAmbiguous());
}
 
Example 9
Source File: MultipleRepositoryViewTest.java    From furnace with Eclipse Public License 1.0 4 votes vote down vote up
@Test
public void testAddonsSharedIfSubgraphEquivalent() throws IOException, InterruptedException, TimeoutException
{
   Furnace furnace = FurnaceFactory.getInstance();
   AddonRepository left = furnace.addRepository(AddonRepositoryMode.MUTABLE, leftRepo);
   AddonRepository right = furnace.addRepository(AddonRepositoryMode.MUTABLE, rightRepo);

   AddonDependencyResolver resolver = new MavenAddonDependencyResolver();
   AddonManager manager = new AddonManagerImpl(furnace, resolver);

   AddonId no_dep = AddonId.from("test:no_dep", "1.0.0.Final");
   AddonId one_dep = AddonId.from("test:one_dep", "1.0.0.Final");
   AddonId one_dep_a = AddonId.from("test:one_dep_a", "1.0.0.Final");

   AddonId no_dep2 = AddonId.from("test:no_dep", "2.0.0.Final");

   Assert.assertFalse(left.isDeployed(one_dep_a));
   Assert.assertFalse(left.isDeployed(no_dep));
   Assert.assertFalse(left.isDeployed(no_dep2));
   Assert.assertFalse(left.isDeployed(one_dep));
   Assert.assertFalse(right.isDeployed(one_dep_a));
   Assert.assertFalse(right.isDeployed(no_dep));
   Assert.assertFalse(right.isDeployed(no_dep2));
   Assert.assertFalse(right.isDeployed(one_dep));

   manager.install(no_dep, left).perform();
   manager.deploy(one_dep, left).perform();

   manager.deploy(one_dep_a, right).perform();
   manager.deploy(no_dep2, right).perform();

   Assert.assertFalse(left.isDeployed(one_dep_a));
   Assert.assertFalse(left.isDeployed(no_dep2));
   Assert.assertTrue(left.isDeployed(no_dep));
   Assert.assertTrue(left.isDeployed(one_dep));
   Assert.assertFalse(right.isDeployed(one_dep));
   Assert.assertFalse(right.isDeployed(no_dep));
   Assert.assertTrue(right.isDeployed(one_dep_a));
   Assert.assertTrue(right.isDeployed(no_dep2));

   ConfigurationScanListener listener = new ConfigurationScanListener();
   ListenerRegistration<ContainerLifecycleListener> registration = furnace.addContainerLifecycleListener(listener);

   furnace.startAsync();

   while (!listener.isConfigurationScanned())
      Thread.sleep(100);

   AddonRegistry registry = furnace.getAddonRegistry();
   Addons.waitUntilStarted(registry.getAddon(one_dep_a), 10, TimeUnit.SECONDS);
   AddonRegistry leftRegistry = furnace.getAddonRegistry(left);
   AddonRegistry rightRegistry = furnace.getAddonRegistry(right);

   Addon leftNoDep = leftRegistry.getAddon(no_dep);
   Addon rightNoDep = rightRegistry.getAddon(no_dep);
   Addon rootNoDep = registry.getAddon(no_dep);
   Assert.assertTrue(leftNoDep.getStatus().isStarted());
   Assert.assertFalse(rightNoDep.getStatus().isStarted()); // not deployed to this repository
   Assert.assertFalse(rootNoDep.getStatus().isStarted()); // there is a newer version

   Addon leftNoDep2 = leftRegistry.getAddon(no_dep2);
   Addon rightNoDep2 = rightRegistry.getAddon(no_dep2);
   Addon rootNoDep2 = registry.getAddon(no_dep2);
   Assert.assertFalse(leftNoDep2.getStatus().isStarted()); // not deployed to this repository
   Assert.assertTrue(rightNoDep2.getStatus().isStarted());
   Assert.assertTrue(rootNoDep2.getStatus().isStarted());

   Addon leftOneDep = leftRegistry.getAddon(one_dep);
   Addon rightOneDep = rightRegistry.getAddon(one_dep);
   Addon rootOneDep = registry.getAddon(one_dep);
   Assert.assertTrue(leftOneDep.getStatus().isStarted());
   Assert.assertFalse(rightOneDep.getStatus().isStarted()); // not deployed to this repository
   Assert.assertTrue(rootOneDep.getStatus().isStarted());

   Addon leftOneDepA = leftRegistry.getAddon(one_dep_a);
   Addon rightOneDepA = rightRegistry.getAddon(one_dep_a);
   Addon rootOneDepA = registry.getAddon(one_dep_a);
   Assert.assertFalse(leftOneDepA.getStatus().isStarted()); // not deployed to this repository
   Assert.assertTrue(rightOneDepA.getStatus().isStarted());
   Assert.assertTrue(rootOneDepA.getStatus().isStarted());

   registration.removeListener();

   furnace.stop();
}
 
Example 10
Source File: MultipleRepositoryViewTest.java    From furnace with Eclipse Public License 1.0 4 votes vote down vote up
@Test
public void testAddonsDuplicatedIfSubgraphDiffers() throws IOException, InterruptedException, TimeoutException
{
   Furnace furnace = FurnaceFactory.getInstance();
   AddonRepository left = furnace.addRepository(AddonRepositoryMode.MUTABLE, leftRepo);
   AddonRepository right = furnace.addRepository(AddonRepositoryMode.MUTABLE, rightRepo);
   AddonDependencyResolver resolver = new MavenAddonDependencyResolver();
   AddonManager manager = new AddonManagerImpl(furnace, resolver);

   AddonId no_dep = AddonId.from("test:no_dep", "1.0.0.Final");
   AddonId one_dep = AddonId.from("test:one_dep", "1.0.0.Final");
   AddonId one_dep_a = AddonId.from("test:one_dep_a", "1.0.0.Final");
   AddonId one_dep_lib = AddonId.from("test:one_dep_lib", "1.0.0.Final");

   AddonId one_dep_2 = AddonId.from("test:one_dep", "2.0.0.Final");

   Assert.assertFalse(left.isDeployed(one_dep_lib));
   Assert.assertFalse(left.isDeployed(one_dep_a));
   Assert.assertFalse(left.isDeployed(no_dep));
   Assert.assertFalse(left.isDeployed(one_dep));
   Assert.assertFalse(left.isDeployed(one_dep_2));
   Assert.assertFalse(right.isDeployed(one_dep_lib));
   Assert.assertFalse(right.isDeployed(one_dep_a));
   Assert.assertFalse(right.isDeployed(no_dep));
   Assert.assertFalse(right.isDeployed(one_dep));
   Assert.assertFalse(right.isDeployed(one_dep_2));

   manager.install(no_dep, left).perform();
   manager.deploy(one_dep, left).perform();
   manager.deploy(one_dep_a, left).perform();
   manager.deploy(one_dep_lib, left).perform();

   manager.deploy(one_dep_2, right).perform();

   Assert.assertTrue(left.isDeployed(no_dep));
   Assert.assertTrue(left.isDeployed(one_dep));
   Assert.assertTrue(left.isDeployed(one_dep_a));
   Assert.assertTrue(left.isDeployed(one_dep_lib));
   Assert.assertFalse(left.isDeployed(one_dep_2));

   Assert.assertFalse(right.isDeployed(no_dep));
   Assert.assertFalse(right.isDeployed(one_dep));
   Assert.assertFalse(right.isDeployed(one_dep_a));
   Assert.assertFalse(right.isDeployed(one_dep_lib));
   Assert.assertTrue(right.isDeployed(one_dep_2));

   ConfigurationScanListener listener = new ConfigurationScanListener();
   ListenerRegistration<ContainerLifecycleListener> registration = furnace.addContainerLifecycleListener(listener);

   furnace.startAsync();

   while (!listener.isConfigurationScanned())
      Thread.sleep(100);

   AddonRegistry registry = furnace.getAddonRegistry();
   Addons.waitUntilStarted(registry.getAddon(one_dep_a), 10, TimeUnit.SECONDS);
   AddonRegistry leftRegistry = furnace.getAddonRegistry(left);

   Addon addon = leftRegistry.getAddon(one_dep);
   Assert.assertNotNull(addon);

   registration.removeListener();

   furnace.stop();
}