コード例 #1
0
  public Maven3ServerEmbedderImpl(MavenServerSettings settings) throws RemoteException {
    File mavenHome = settings.getMavenHome();
    if (mavenHome != null) {
      System.setProperty("maven.home", mavenHome.getPath());
    }

    myConsoleWrapper = new Maven3ServerConsoleLogger();
    myConsoleWrapper.setThreshold(settings.getLoggingLevel());

    ClassWorld classWorld =
        new ClassWorld("plexus.core", Thread.currentThread().getContextClassLoader());
    MavenCli cli =
        new MavenCli(classWorld) {
          @Override
          protected void customizeContainer(PlexusContainer container) {
            ((DefaultPlexusContainer) container)
                .setLoggerManager(
                    new BaseLoggerManager() {
                      @Override
                      protected Logger createLogger(String s) {
                        return myConsoleWrapper;
                      }
                    });
          }
        };

    Class cliRequestClass;
    try {
      cliRequestClass =
          MavenCli.class.getClassLoader().loadClass("org.apache.maven.cli.MavenCli$CliRequest");
    } catch (ClassNotFoundException e) {
      throw new RuntimeException("Class \"org.apache.maven.cli.MavenCli$CliRequest\" not found");
    }

    Object cliRequest;
    try {
      String[] commandLineOptions = new String[settings.getUserProperties().size()];
      int idx = 0;
      for (Map.Entry<Object, Object> each : settings.getUserProperties().entrySet()) {
        commandLineOptions[idx++] = "-D" + each.getKey() + "=" + each.getValue();
      }

      Constructor constructor =
          cliRequestClass.getDeclaredConstructor(String[].class, ClassWorld.class);
      constructor.setAccessible(true);
      cliRequest = constructor.newInstance(commandLineOptions, classWorld);

      for (String each : new String[] {"initialize", "cli", "properties", "container"}) {
        Method m = MavenCli.class.getDeclaredMethod(each, cliRequestClass);
        m.setAccessible(true);
        m.invoke(cli, cliRequest);
      }
    } catch (InstantiationException e) {
      throw new RuntimeException(e);
    } catch (NoSuchMethodException e) {
      throw new RuntimeException(e);
    } catch (IllegalAccessException e) {
      throw new RuntimeException(e);
    } catch (InvocationTargetException e) {
      throw new RuntimeException(e);
    }

    // reset threshold
    myContainer = FieldAccessor.get(MavenCli.class, cli, "container");
    myContainer.getLoggerManager().setThreshold(settings.getLoggingLevel());

    mySystemProperties =
        FieldAccessor.<Properties>get(cliRequestClass, cliRequest, "systemProperties");

    myMavenSettings =
        buildSettings(
            FieldAccessor.<SettingsBuilder>get(MavenCli.class, cli, "settingsBuilder"),
            settings,
            mySystemProperties,
            FieldAccessor.<Properties>get(cliRequestClass, cliRequest, "userProperties"));

    myLocalRepository = createLocalRepository(settings.getSnapshotUpdatePolicy());
  }
コード例 #2
0
 private void setConsoleAndIndicator(
     MavenServerConsole console, MavenServerProgressIndicator indicator) {
   myConsoleWrapper.setWrappee(console);
   myCurrentIndicator = indicator;
 }