private static void runOutOfProcess( CompileContext compileContext, VirtualFile outputDir, File kotlinHome, File scriptFile) { final SimpleJavaParameters params = new SimpleJavaParameters(); params.setJdk(new SimpleJavaSdkType().createJdk("tmp", SystemProperties.getJavaHome())); params.setMainClass("org.jetbrains.jet.cli.KotlinCompiler"); params.getProgramParametersList().add("-module", scriptFile.getAbsolutePath()); params.getProgramParametersList().add("-output", path(outputDir)); params.getProgramParametersList().add("-tags"); for (File jar : kompilerClasspath(kotlinHome, compileContext)) { params.getClassPath().add(jar); } params.getVMParametersList().addParametersString("-Djava.awt.headless=true -Xmx512m"); // params.getVMParametersList().addParametersString("-agentlib:yjpagent=sampling"); Sdk sdk = params.getJdk(); final GeneralCommandLine commandLine = JdkUtil.setupJVMCommandLine( ((JavaSdkType) sdk.getSdkType()).getVMExecutablePath(sdk), params, false); compileContext.addMessage( INFORMATION, "Invoking out-of-process compiler with arguments: " + commandLine, "", -1, -1); try { final OSProcessHandler processHandler = new OSProcessHandler(commandLine.createProcess(), commandLine.getCommandLineString()) { @Override public Charset getCharset() { return commandLine.getCharset(); } }; ProcessAdapter processListener = createProcessListener(compileContext); processHandler.addProcessListener(processListener); processHandler.startNotify(); processHandler.waitFor(); } catch (Exception e) { compileContext.addMessage(ERROR, "[Internal Error] " + e.getLocalizedMessage(), "", -1, -1); return; } }
private void executeTest(String className, String testMethodName, String dunitPath) { String testPath = className + "." + testMethodName; final String workingDirectory = project.getBasePath(); // final String testFile = configuration.getDFile().getCanonicalPath(); final String dubPath = ToolKey.DUB_KEY.getPath(project); if (dubPath == null || dubPath.isEmpty()) { Notifications.Bus.notify( new Notification( "Dunit Test Runner", "Dub path must be specified", "Dub executable path is empty" + "<br/><a href='configureDLanguageTools'>Configure</a>", NotificationType.WARNING, new DToolsNotificationListener(project)), project); return; } GeneralCommandLine commandLine = new GeneralCommandLine(); commandLine.setWorkDirectory(workingDirectory); commandLine.setExePath(dubPath); ParametersList parametersList = commandLine.getParametersList(); parametersList.addParametersString("--"); parametersList.addParametersString("-v"); parametersList.addParametersString("--filter"); parametersList.addParametersString(testPath + "$"); // regex to locate exact test final StringBuilder builder = new StringBuilder(); try { OSProcessHandler process = new OSProcessHandler(commandLine.createProcess()); process.addProcessListener( new ProcessAdapter() { @Override public void onTextAvailable(ProcessEvent event, Key outputType) { builder.append(event.getText()); } }); process.startNotify(); process.waitFor(); } catch (ExecutionException e) { e.printStackTrace(); } String result = builder.toString(); // call either finished(success) or failed String successPatternString = ".*OK:.*"; Pattern successPattern = Pattern.compile(successPatternString); Matcher successMatcher = successPattern.matcher(result); if (successMatcher.find()) { testFinished(className, testMethodName, 0); testStdOut(className, testMethodName, result); } else if (result.contains("FAILURE:")) { testFailed(className, testMethodName, 0, "Failed", result); } else if (result.contains("SKIP:")) { testIgnored(className, testMethodName); testStdOut(className, testMethodName, result); } else { testFailed(className, testMethodName, 0, "Failed for unknown reasons", result); } }