private PlexusContainer setupContainer(Class<?> baseClass) {
    // ----------------------------------------------------------------------------
    // Context Setup
    // ----------------------------------------------------------------------------

    Map<Object, Object> context = new HashMap<Object, Object>();

    context.put("basedir", getBasedir());
    context.putAll(TestProperties.getAll());

    boolean hasPlexusHome = context.containsKey("plexus.home");

    if (!hasPlexusHome) {
      File f = new File(getBasedir(), "target/plexus-home");

      if (!f.isDirectory()) {
        f.mkdir();
      }

      context.put("plexus.home", f.getAbsolutePath());
    }

    // ----------------------------------------------------------------------------
    // Configuration
    // ----------------------------------------------------------------------------

    ContainerConfiguration containerConfiguration =
        new DefaultContainerConfiguration()
            .setName("test")
            .setContext(context)
            .setContainerConfiguration(baseClass.getName().replace('.', '/') + ".xml");
    containerConfiguration.setClassPathScanning(true);

    customizeContainerConfiguration(containerConfiguration);

    try {
      return new DefaultPlexusContainer(containerConfiguration);
    } catch (PlexusContainerException e) {
      e.printStackTrace();
      fail("Failed to create plexus container.");
      return null;
    }
  }
예제 #2
0
  private PlexusContainer createContainer(Class<?> baseClass, Module... modules) {
    log.info("Creating container; baseClass: {}, modules: {}", baseClass, modules);

    Map<Object, Object> context = new HashMap<>();
    context.put("basedir", getBasedir());
    context.putAll(getTestProperties());

    boolean hasPlexusHome = context.containsKey("plexus.home");
    if (!hasPlexusHome) {
      File f = new File(getBasedir(), "target/plexus-home");
      if (!f.isDirectory()) {
        f.mkdir();
      }
      context.put("plexus.home", f.getAbsolutePath());
    }

    // log.info("Context:");
    // for (Entry<Object,Object> entry : context.entrySet()) {
    //  log.info("  {}={}", entry.getKey(), entry.getValue());
    // }

    String plexusXml = baseClass.getName().replace('.', '/') + ".xml";
    log.info("Plexus XML: {}", plexusXml);

    ContainerConfiguration containerConfiguration = new DefaultContainerConfiguration();
    containerConfiguration.setName("test");
    containerConfiguration.setContext(context);
    containerConfiguration.setContainerConfiguration(plexusXml);
    containerConfiguration.setAutoWiring(true);
    containerConfiguration.setClassPathScanning(PlexusConstants.SCANNING_INDEX);

    try {
      return new DefaultPlexusContainer(containerConfiguration, modules);
    } catch (PlexusContainerException e) {
      log.error("Failed to create container", e);
      fail("Failed to create container");
      return null;
    }
  }
예제 #3
0
 @Override
 protected void customizeContainerConfiguration(final ContainerConfiguration configuration) {
   super.customizeContainerConfiguration(configuration);
   configuration.setAutoWiring(true);
   configuration.setClassPathScanning(PlexusConstants.SCANNING_INDEX);
 }
예제 #4
0
 @Override
 protected void customizeContainerConfiguration(ContainerConfiguration configuration) {
   configuration.setAutoWiring(true);
   configuration.setClassPathScanning(PlexusConstants.SCANNING_CACHE);
 }