예제 #1
0
  /**
   * Invoked by {@link #initialise} to fill the container.
   *
   * @param container the underlying container
   * @throws ContainerException if initialisation fails
   * @throws PicoException for any PicoContainer error
   */
  @Override
  protected void fillContainer(MutablePicoContainer container) {
    super.fillContainer(container);
    addComponent(InstallDataConfiguratorWithRules.class);
    addComponent(Log.class, Mockito.mock(Log.class));

    container.addAdapter(new ProviderAdapter(new GUIInstallDataMockProvider()));
    container.addAdapter(new ProviderAdapter(new IconsProvider()));
  }
  /**
   * {@inheritDoc}
   *
   * @param componentAdapter
   * @return
   * @see org.picocontainer.MutablePicoContainer#addAdapter(org.picocontainer.ComponentAdapter)
   */
  public MutablePicoContainer addAdapter(final ComponentAdapter componentAdapter) {
    if (logger.isDebugEnabled()) {
      logger.debug("Registering component adapter " + componentAdapter);
    }

    return delegate.addAdapter(componentAdapter);
  }
 @SuppressWarnings({"unchecked"})
 public final void testInstancesAreNotSharedBetweenContainers() {
   final MutablePicoContainer picoA = new DefaultPicoContainer();
   final MutablePicoContainer picoB = new DefaultPicoContainer();
   picoA.addAdapter(
       new ThreadLocalizing.ThreadLocalized(
           new ConstructorInjection.ConstructorInjector(List.class, ArrayList.class, null)));
   picoB.addAdapter(
       new ThreadLocalizing.ThreadLocalized(
           new ConstructorInjection.ConstructorInjector(List.class, ArrayList.class, null)));
   final List<String> hello1 = picoA.getComponent(List.class);
   final List hello2 = picoA.getComponent(List.class);
   hello1.add("foo");
   assertEquals(hello1, hello2);
   final List hello3 = picoB.getComponent(List.class);
   assertEquals(0, hello3.size());
 }
예제 #4
0
 /**
  * Register all component factories found in classpath scanning
  *
  * @param container
  * @param componentFactoryMap
  */
 @SuppressWarnings("unchecked")
 private void registerComponentFactories(
     MutablePicoContainer container,
     Map<Class<?>, Class<? extends ComponentFactory>> componentFactoryMap) {
   for (Class<?> targetType : componentFactoryMap.keySet()) {
     container.addAdapter(
         new PicoComponentAdapter(targetType, componentFactoryMap.get(targetType)));
   }
 }
예제 #5
0
 @SuppressWarnings({"rawtypes", "unchecked"})
 public Publisher publish(Object key) {
   if (key == null) {
     throw new NullPointerException("key");
   }
   final ComponentAdapter ca = child.getComponentAdapter(key);
   if (ca == null) {
     throw new IllegalArgumentException(key + " does not appear to exist in container " + child);
   }
   parent.addAdapter(new Publishing<Object>(child, ca));
   return this;
 }
 public void testNonSetterMethodInjectionWithAlternativeAnnotation() {
   MutablePicoContainer pico = new DefaultPicoContainer();
   pico.addAdapter(
       new AnnotatedMethodInjector(
           AnotherAnnotatedBurp.class,
           AnotherAnnotatedBurp.class,
           Parameter.DEFAULT,
           new NullComponentMonitor(),
           new NullLifecycleStrategy(),
           AlternativeInject.class,
           false));
   pico.addComponent(Wind.class, new Wind());
   AnotherAnnotatedBurp burp = pico.getComponent(AnotherAnnotatedBurp.class);
   assertNotNull(burp);
   assertNotNull(burp.wind);
 }
  public void testSetterMethodInjectionToContrastWithThatBelow() {

    MutablePicoContainer pico = new DefaultPicoContainer();
    pico.addAdapter(
        new SetterInjector(
            SetterBurp.class,
            SetterBurp.class,
            Parameter.DEFAULT,
            new NullComponentMonitor(),
            new NullLifecycleStrategy(),
            "set",
            false));
    pico.addComponent(Wind.class, new Wind());
    SetterBurp burp = pico.getComponent(SetterBurp.class);
    assertNotNull(burp);
    assertNotNull(burp.wind);
  }
  public void testMBeanInfoIsDeterminedIfKeyIsType() {
    final PersonMBean person = new OtherPerson();

    final Mock mockComponentAdapter = mock(ComponentAdapter.class);
    mockComponentAdapter.stubs().method("getComponentKey").will(returnValue(Person.class));
    mockComponentAdapter
        .stubs()
        .method("getComponentImplementation")
        .will(returnValue(person.getClass()));

    pico.addAdapter((ComponentAdapter) mockComponentAdapter.proxy());
    pico.addComponent(Person.class.getName() + "MBeanInfo", Person.createMBeanInfo());

    final MBeanInfo info =
        mBeanProvider.provide(pico, (ComponentAdapter) mockComponentAdapter.proxy());
    assertNotNull(info);
    assertEquals(Person.createMBeanInfo().getDescription(), info.getDescription());
  }
예제 #9
0
  /**
   * Fills the container.
   *
   * @param container the underlying container
   * @throws ContainerException if initialisation fails, or the container has already been
   *     initialised
   */
  @Override
  protected void fillContainer(MutablePicoContainer container) {
    addComponent(Properties.class);
    addComponent(DefaultVariables.class);
    addComponent(CompilerContainer.class, this);
    addComponent(CliAnalyzer.class);
    addComponent(CmdlinePackagerListener.class);
    addComponent(Compiler.class);
    addComponent(ResourceFinder.class);
    addComponent(CompilerConfig.class);
    addComponent(ConditionContainer.class, ConditionContainer.class);
    addComponent(AssertionHelper.class);
    addComponent(PropertyManager.class);
    addComponent(VariableSubstitutor.class, VariableSubstitutorImpl.class);
    addComponent(CompilerHelper.class);
    container.addComponent(
        RulesEngine.class,
        RulesEngineImpl.class,
        new ComponentParameter(ConditionContainer.class),
        new ComponentParameter(Platform.class));
    addComponent(MergeManager.class, MergeManagerImpl.class);
    container.addComponent(
        ObjectFactory.class,
        DefaultObjectFactory.class,
        new ComponentParameter(CompilerContainer.class));
    container.addComponent(PlatformModelMatcher.class);
    addComponent(Platforms.class);

    new ResolverContainerFiller().fillContainer(this);
    container
        .addAdapter(new ProviderAdapter(new XmlCompilerHelperProvider()))
        .addAdapter(new ProviderAdapter(new JarOutputStreamProvider()))
        .addAdapter(new ProviderAdapter(new CompressedOutputStreamProvider()))
        .addAdapter(new ProviderAdapter(new PackCompressorProvider()))
        .addAdapter(new ProviderAdapter(new PlatformProvider()));
  }