protected void initializeConfiguration()
      throws ConfigurationProcessingException, ConfigurationResourceNotFoundException,
          PlexusConfigurationException, ContextException, IOException {
    // System userConfiguration

    InputStream is = containerRealm.getResourceAsStream(PlexusConstants.BOOTSTRAP_CONFIGURATION);

    if (is == null) {
      ClassRealm cr = containerRealm;
      String realmStack = "";
      while (cr != null) {
        realmStack +=
            "\n  "
                + cr.getId()
                + " parent="
                + cr.getParent()
                + " ("
                + cr.getResource(PlexusConstants.BOOTSTRAP_CONFIGURATION)
                + ")";
        cr = cr.getParentRealm();
      }

      throw new IllegalStateException(
          "The internal default plexus-bootstrap.xml is missing. "
              + "This is highly irregular, your plexus JAR is most likely corrupt. Realms:"
              + realmStack);
    }

    PlexusConfiguration bootstrapConfiguration =
        PlexusTools.buildConfiguration(
            PlexusConstants.BOOTSTRAP_CONFIGURATION, ReaderFactory.newXmlReader(is));

    // Some of this could probably be collapsed as having a plexus.xml in your
    // META-INF/plexus directory is probably a better solution then specifying
    // a configuration with an URL but I'm leaving the configuration by URL
    // as folks might be using it ... I made this change to accomodate Maven
    // but I think it's better to discover a configuration in a standard
    // place.

    configuration = bootstrapConfiguration;

    if (!containerContext.contains(PlexusConstants.IGNORE_CONTAINER_CONFIGURATION)
        || containerContext.get(PlexusConstants.IGNORE_CONTAINER_CONFIGURATION) != Boolean.TRUE) {
      PlexusXmlComponentDiscoverer discoverer = new PlexusXmlComponentDiscoverer();

      PlexusConfiguration plexusConfiguration =
          discoverer.discoverConfiguration(getContext(), containerRealm);

      if (plexusConfiguration != null) {
        configuration = PlexusConfigurationMerger.merge(plexusConfiguration, configuration);

        processConfigurationsDirectory();
      }
    }

    if (configurationReader != null) {
      // User userConfiguration

      PlexusConfiguration userConfiguration =
          PlexusTools.buildConfiguration(
              "<User Specified Configuration Reader>",
              getInterpolationConfigurationReader(configurationReader));

      // Merger of bootstrapConfiguration and user userConfiguration

      configuration = PlexusConfigurationMerger.merge(userConfiguration, configuration);

      processConfigurationsDirectory();
    }

    // ---------------------------------------------------------------------------
    // Now that we have the configuration we will use the ConfigurationProcessor
    // to inline any external configuration instructions.
    //
    // At his point the variables in the configuration have already been
    // interpolated so we can send in an empty Map because the containerContext
    // values are already there.
    // ---------------------------------------------------------------------------

    ConfigurationProcessor p = new ConfigurationProcessor();

    p.addConfigurationResourceHandler(new FileConfigurationResourceHandler());

    p.addConfigurationResourceHandler(new DirectoryConfigurationResourceHandler());

    configuration = p.process(configuration, Collections.EMPTY_MAP);
  }
Esempio n. 2
0
  protected void initializeConfiguration()
      throws ConfigurationProcessingException, ConfigurationResourceNotFoundException,
          PlexusConfigurationException {
    // System userConfiguration

    InputStream is = coreRealm.getResourceAsStream(BOOTSTRAP_CONFIGURATION);

    if (is == null) {
      throw new IllegalStateException(
          "The internal default plexus-bootstrap.xml is missing. "
              + "This is highly irregular, your plexus JAR is "
              + "most likely corrupt.");
    }

    PlexusConfiguration systemConfiguration =
        PlexusTools.buildConfiguration(BOOTSTRAP_CONFIGURATION, new InputStreamReader(is));

    // ----------------------------------------------------------------------
    //
    // ----------------------------------------------------------------------

    // ----------------------------------------------------------------------
    //
    // ----------------------------------------------------------------------

    // Some of this could probably be collapsed as having a plexus.xml in your
    // META-INF/plexus directory is probably a better solution then specifying
    // a configuration with an URL but I'm leaving the configuration by URL
    // as folks might be using it ... I made this change to accomodate Maven
    // but I think it's better to discover a configuration in a standard
    // place.

    configuration = systemConfiguration;

    PlexusXmlComponentDiscoverer discoverer = new PlexusXmlComponentDiscoverer();
    PlexusConfiguration plexusConfiguration =
        discoverer.discoverConfiguration(getContext(), plexusRealm);

    if (plexusConfiguration != null) {
      configuration = PlexusConfigurationMerger.merge(plexusConfiguration, configuration);

      processConfigurationsDirectory();
    }

    if (configurationReader != null) {
      // User userConfiguration

      PlexusConfiguration userConfiguration =
          PlexusTools.buildConfiguration(
              "<User Specified Configuration Reader>",
              getInterpolationConfigurationReader(configurationReader));

      // Merger of systemConfiguration and user userConfiguration

      configuration = PlexusConfigurationMerger.merge(userConfiguration, configuration);

      processConfigurationsDirectory();
    }

    // ---------------------------------------------------------------------------
    // Now that we have the configuration we will use the ConfigurationProcessor
    // to inline any external configuration instructions.
    //
    // At his point the variables in the configuration have already been
    // interpolated so we can send in an empty Map because the context
    // values are already there.
    // ---------------------------------------------------------------------------

    ConfigurationProcessor p = new ConfigurationProcessor();

    p.addConfigurationResourceHandler(new FileConfigurationResourceHandler());

    p.addConfigurationResourceHandler(new DirectoryConfigurationResourceHandler());

    configuration = p.process(configuration, Collections.EMPTY_MAP);
  }