예제 #1
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);
  }