示例#1
0
文件: MavenCli.java 项目: nerro/maven
  static void populateProperties(
      CommandLine commandLine, Properties systemProperties, Properties userProperties) {
    EnvironmentUtils.addEnvVars(systemProperties);

    // ----------------------------------------------------------------------
    // Options that are set on the command line become system properties
    // and therefore are set in the session properties. System properties
    // are most dominant.
    // ----------------------------------------------------------------------

    if (commandLine.hasOption(CLIManager.SET_SYSTEM_PROPERTY)) {
      String[] defStrs = commandLine.getOptionValues(CLIManager.SET_SYSTEM_PROPERTY);

      if (defStrs != null) {
        for (String defStr : defStrs) {
          setCliProperty(defStr, userProperties);
        }
      }
    }

    SystemProperties.addSystemProperties(systemProperties);

    // ----------------------------------------------------------------------
    // Properties containing info about the currently running version of Maven
    // These override any corresponding properties set on the command line
    // ----------------------------------------------------------------------

    Properties buildProperties = CLIReportingUtils.getBuildProperties();

    String mavenVersion = buildProperties.getProperty(CLIReportingUtils.BUILD_VERSION_PROPERTY);
    systemProperties.setProperty("maven.version", mavenVersion);

    String mavenBuildVersion = CLIReportingUtils.createMavenVersionString(buildProperties);
    systemProperties.setProperty("maven.build.version", mavenBuildVersion);
  }
示例#2
0
文件: MavenCli.java 项目: nerro/maven
  private PlexusContainer container(CliRequest cliRequest) throws Exception {
    if (cliRequest.classWorld == null) {
      cliRequest.classWorld =
          new ClassWorld("plexus.core", Thread.currentThread().getContextClassLoader());
    }

    DefaultPlexusContainer container;

    ContainerConfiguration cc =
        new DefaultContainerConfiguration()
            .setClassWorld(cliRequest.classWorld)
            .setRealm(setupContainerRealm(cliRequest))
            .setClassPathScanning(PlexusConstants.SCANNING_INDEX)
            .setAutoWiring(true)
            .setName("maven");

    container =
        new DefaultPlexusContainer(
            cc,
            new AbstractModule() {
              protected void configure() {
                bind(ILoggerFactory.class).toInstance(slf4jLoggerFactory);
              }
            });

    // NOTE: To avoid inconsistencies, we'll use the TCCL exclusively for lookups
    container.setLookupRealm(null);

    container.setLoggerManager(plexusLoggerManager);

    customizeContainer(container);

    container.getLoggerManager().setThresholds(cliRequest.request.getLoggingLevel());

    Thread.currentThread().setContextClassLoader(container.getContainerRealm());

    eventSpyDispatcher = container.lookup(EventSpyDispatcher.class);

    DefaultEventSpyContext eventSpyContext = new DefaultEventSpyContext();
    Map<String, Object> data = eventSpyContext.getData();
    data.put("plexus", container);
    data.put("workingDirectory", cliRequest.workingDirectory);
    data.put("systemProperties", cliRequest.systemProperties);
    data.put("userProperties", cliRequest.userProperties);
    data.put("versionProperties", CLIReportingUtils.getBuildProperties());
    eventSpyDispatcher.init(eventSpyContext);

    // refresh logger in case container got customized by spy
    slf4jLogger = slf4jLoggerFactory.getLogger(this.getClass().getName());

    maven = container.lookup(Maven.class);

    executionRequestPopulator = container.lookup(MavenExecutionRequestPopulator.class);

    modelProcessor = createModelProcessor(container);

    settingsBuilder = container.lookup(SettingsBuilder.class);

    toolchainsBuilder = container.lookup(ToolchainsBuilder.class);

    dispatcher = (DefaultSecDispatcher) container.lookup(SecDispatcher.class, "maven");

    return container;
  }