コード例 #1
0
  private void appendForkInfo(Executor executor) throws ExecutionException {
    final String forkMode = myConfiguration.getForkMode();
    if (Comparing.strEqual(forkMode, "none")) {
      return;
    }

    if (getRunnerSettings().getData() != null) {
      final String actionName = executor.getActionName();
      throw new CantRunException(
          actionName
              + " is disabled in fork mode.<br/>Please change fork mode to &lt;none&gt; to "
              + actionName.toLowerCase()
              + ".");
    }

    final JavaParameters javaParameters = getJavaParameters();
    final Sdk jdk = javaParameters.getJdk();
    if (jdk == null) {
      throw new ExecutionException(
          ExecutionBundle.message("run.configuration.error.no.jdk.specified"));
    }

    try {
      final File tempFile = FileUtil.createTempFile("command.line", "", true);
      final PrintWriter writer = new PrintWriter(tempFile, "UTF-8");
      try {
        writer.println(((JavaSdkType) jdk.getSdkType()).getVMExecutablePath(jdk));
        for (String vmParameter : javaParameters.getVMParametersList().getList()) {
          writer.println(vmParameter);
        }
        writer.println("-classpath");
        writer.println(javaParameters.getClassPath().getPathsString());
      } finally {
        writer.close();
      }

      myJavaParameters
          .getProgramParametersList()
          .add("@@@" + forkMode + ',' + tempFile.getAbsolutePath());
    } catch (Exception e) {
      LOG.error(e);
    }
  }
コード例 #2
0
  protected void initialize() throws ExecutionException {
    JavaParametersUtil.configureConfiguration(myJavaParameters, myConfiguration);
    myJavaParameters.setMainClass(JUnitConfiguration.JUNIT_START_CLASS);
    final Module module = myConfiguration.getConfigurationModule().getModule();
    if (myJavaParameters.getJdk() == null) {
      myJavaParameters.setJdk(
          module != null
              ? ModuleRootManager.getInstance(module).getSdk()
              : ProjectRootManager.getInstance(myProject).getProjectSdk());
    }

    myJavaParameters.getClassPath().add(JavaSdkUtil.getIdeaRtJarPath());
    myJavaParameters.getClassPath().add(PathUtil.getJarPathForClass(JUnitStarter.class));
    myJavaParameters
        .getProgramParametersList()
        .add(JUnitStarter.IDE_VERSION + JUnitStarter.VERSION);
    for (RunConfigurationExtension ext :
        Extensions.getExtensions(RunConfigurationExtension.EP_NAME)) {
      ext.updateJavaParameters(myConfiguration, myJavaParameters, getRunnerSettings());
    }

    final Object[] listeners = Extensions.getExtensions(IDEAJUnitListener.EP_NAME);
    final StringBuilder buf = new StringBuilder();
    for (final Object listener : listeners) {
      boolean enabled = true;
      for (RunConfigurationExtension ext :
          Extensions.getExtensions(RunConfigurationExtension.EP_NAME)) {
        if (ext.isListenerDisabled(myConfiguration, listener, getRunnerSettings())) {
          enabled = false;
          break;
        }
      }
      if (enabled) {
        final Class classListener = listener.getClass();
        buf.append(classListener.getName()).append("\n");
        myJavaParameters.getClassPath().add(PathUtil.getJarPathForClass(classListener));
      }
    }
    if (buf.length() > 0) {
      try {
        myListenersFile = FileUtil.createTempFile("junit_listeners_", "");
        myListenersFile.deleteOnExit();
        myJavaParameters.getProgramParametersList().add("@@" + myListenersFile.getPath());
        FileUtil.writeToFile(myListenersFile, buf.toString().getBytes());
      } catch (IOException e) {
        LOG.error(e);
      }
    }
  }
コード例 #3
0
  protected <T> void addClassesListToJavaParameters(
      Collection<? extends T> elements,
      Function<T, String> nameFunction,
      String packageName,
      boolean createTempFile,
      boolean junit4) {
    try {
      if (createTempFile) {
        myTempFile = FileUtil.createTempFile("idea_junit", ".tmp");
        myTempFile.deleteOnExit();
        myJavaParameters.getProgramParametersList().add("@" + myTempFile.getAbsolutePath());
      }

      final PrintWriter writer = new PrintWriter(myTempFile, "UTF-8");
      try {
        writer.println(packageName);
        final List<String> testNames = new ArrayList<String>();
        for (final T element : elements) {
          final String name = nameFunction.fun(element);
          if (name == null) {
            LOG.error("invalid element " + element);
            return;
          }
          testNames.add(name);
        }
        Collections.sort(testNames); // sort tests in FQN order
        for (String testName : testNames) {
          writer.println(testName);
        }
      } finally {
        writer.close();
      }
    } catch (IOException e) {
      LOG.error(e);
    }
  }
コード例 #4
0
  protected JavaParameters createJavaParameters() throws ExecutionException {

    log.debug("createJavaParameters");

    SubstepsRunConfiguration runConfig =
        (SubstepsRunConfiguration) this.getEnvironment().getRunProfile();

    SubstepsRunnerConfigurationModel model = runConfig.getModel();

    JavaParameters params = model.getJavaParameters();

    params.setWorkingDirectory(model.getWorkingDir());

    if (params.getJdk() == null) {

      log.debug("params on the jdk is null");

      params.setJdk(
          JavaSdkImpl.getInstance().createJdk(model.getVersionString(), model.getHomePath()));

      params.getClassPath().add(model.getClassPathString());
    }

    params.getProgramParametersList().add("prog-args-env", "prg-localhost");

    ParametersList vmParametersList = params.getVMParametersList();

    vmParametersList.addParametersString("-Dfile.encoding=UTF-8");
    vmParametersList.addParametersString("-Dcom.sun.management.jmxremote.port=" + jmxPort);
    vmParametersList.addParametersString("-Dcom.sun.management.jmxremote.authenticate=false");
    vmParametersList.addParametersString("-Dcom.sun.management.jmxremote.ssl=false");
    vmParametersList.addParametersString("-Djava.rmi.server.hostname=localhost");

    //        String rmiClasspathString = "\"file://" +
    // model.getClassPathString().replaceAll(File.pathSeparator, " file://") + "\"";

    //        log.debug("rmi classpath: " + rmiClasspathString);

    //        vmParametersList.addParametersString("-Djava.rmi.server.codebase=" +
    // rmiClasspathString);

    vmParametersList.addParametersString("-Dsun.io.serialization.extendedDebugInfo=true");

    //        System.setProperty("java.rmi.server.codebase", rmiClasspathString);

    //        createServerSocket(params);
    //
    //
    //        if (myServerSocket != null) {
    //            params.getProgramParametersList().add(ForkedDebuggerHelper.DEBUG_SOCKET +
    // myServerSocket.getLocalPort());
    //        }
    //

    log.debug(
        "launching substeps runner with classpath: "
            + params.getClassPath().getPathsString()
            + "\njvm info: "
            + model.getHomePath()
            + " version: "
            + model.getVersionString());

    return params;
  }