use of consulo.java.execution.configurations.OwnJavaParameters in project consulo-java by consulo.
the class JavaCommandLineTest method testMainClass.
public void testMainClass() {
try {
OwnJavaParameters javaParameters = new OwnJavaParameters();
javaParameters.setJdk(getProjectJDK());
javaParameters.toCommandLine();
fail("CantRunException (main class is not specified) expected");
} catch (CantRunException e) {
assertEquals(ExecutionBundle.message("main.class.is.not.specified.error.message"), e.getMessage());
}
}
use of consulo.java.execution.configurations.OwnJavaParameters in project consulo-java by consulo.
the class JavaTestFrameworkRunnableState method createJavaParameters.
@Override
protected OwnJavaParameters createJavaParameters() throws ExecutionException {
final OwnJavaParameters javaParameters = new OwnJavaParameters();
Project project = getConfiguration().getProject();
javaParameters.setShortenCommandLine(getConfiguration().getShortenCommandLine(), project);
final Module module = getConfiguration().getConfigurationModule().getModule();
Sdk jdk = module == null ? null : ModuleUtilCore.getSdk(module, JavaModuleExtension.class);
javaParameters.setJdk(jdk);
final String parameters = getConfiguration().getProgramParameters();
getConfiguration().setProgramParameters(null);
try {
JavaParametersUtil.configureConfiguration(javaParameters, getConfiguration());
} finally {
getConfiguration().setProgramParameters(parameters);
}
javaParameters.getClassPath().addFirst(JavaSdkUtil.getJavaRtJarPath());
configureClasspath(javaParameters);
final JavaTestPatcher[] patchers = JavaTestPatcher.EP_NAME.getExtensions();
for (JavaTestPatcher patcher : patchers) {
patcher.patchJavaParameters(module, javaParameters);
}
// Append coverage parameters if appropriate
for (RunConfigurationExtension ext : Extensions.getExtensions(RunConfigurationExtension.EP_NAME)) {
ext.updateJavaParameters(getConfiguration(), javaParameters, getRunnerSettings());
}
if (!StringUtil.isEmptyOrSpaces(parameters)) {
javaParameters.getProgramParametersList().addAll(getNamedParams(parameters));
}
if (ConsoleBuffer.useCycleBuffer()) {
javaParameters.getVMParametersList().addProperty("idea.test.cyclic.buffer.size", String.valueOf(ConsoleBuffer.getCycleBufferSize()));
}
return javaParameters;
}
use of consulo.java.execution.configurations.OwnJavaParameters in project consulo-java by consulo.
the class JavaTestFrameworkRunnableState method writeClassesPerModule.
protected void writeClassesPerModule(String packageName, OwnJavaParameters javaParameters, Map<Module, List<String>> perModule) throws FileNotFoundException, UnsupportedEncodingException, CantRunException {
if (perModule != null) {
final String classpath = getScope() == TestSearchScope.WHOLE_PROJECT ? null : javaParameters.getClassPath().getPathsString();
final PrintWriter wWriter = new PrintWriter(myWorkingDirsFile, CharsetToolkit.UTF8);
try {
wWriter.println(packageName);
for (Module module : perModule.keySet()) {
wWriter.println(module.getModuleDirPath());
wWriter.println(module.getName());
if (classpath == null) {
final OwnJavaParameters parameters = new OwnJavaParameters();
parameters.getClassPath().add(JavaSdkUtil.getJavaRtJarPath());
configureRTClasspath(parameters);
JavaParametersUtil.configureModule(module, parameters, OwnJavaParameters.JDK_AND_CLASSES_AND_TESTS, getConfiguration().isAlternativeJrePathEnabled() ? getConfiguration().getAlternativeJrePath() : null);
wWriter.println(parameters.getClassPath().getPathsString());
} else {
wWriter.println(classpath);
}
final List<String> classNames = perModule.get(module);
wWriter.println(classNames.size());
for (String className : classNames) {
wWriter.println(className);
}
}
} finally {
wWriter.close();
}
}
}
use of consulo.java.execution.configurations.OwnJavaParameters in project consulo-java by consulo.
the class JavaTestFrameworkRunnableState method appendForkInfo.
protected void appendForkInfo(Executor executor) throws ExecutionException {
final String forkMode = getForkMode();
if (Comparing.strEqual(forkMode, "none")) {
if (forkPerModule()) {
if (isExecutorDisabledInForkedMode()) {
final String actionName = UIUtil.removeMnemonic(executor.getStartActionText());
throw new CantRunException("'" + actionName + "' is disabled when per-module working directory is configured.<br/>" + "Please specify single working directory, or change test " + "scope to single module.");
}
} else {
return;
}
} else if (isExecutorDisabledInForkedMode()) {
final String actionName = executor.getActionName();
throw new CantRunException(actionName + " is disabled in fork mode.<br/>Please change fork mode to <none> to " + actionName.toLowerCase(Locale.ENGLISH) + ".");
}
final OwnJavaParameters 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);
try (PrintWriter writer = new PrintWriter(tempFile, CharsetToolkit.UTF8)) {
if (OwnJdkUtil.useDynamicClasspath(getConfiguration().getProject()) && forkPerModule()) {
writer.println("use classpath jar");
} else {
writer.println("");
}
JavaSdkType sdkType = (JavaSdkType) jdk.getSdkType();
GeneralCommandLine commandLine = new GeneralCommandLine();
sdkType.setupCommandLine(commandLine, jdk);
List<String> commandLineList = commandLine.getCommandLineList(null);
for (String line : commandLineList) {
writer.println(line);
}
for (String vmParameter : javaParameters.getVMParametersList().getList()) {
writer.println(vmParameter);
}
}
passForkMode(getForkMode(), tempFile, javaParameters);
} catch (IOException e) {
LOG.error(e);
}
}
use of consulo.java.execution.configurations.OwnJavaParameters in project consulo-java by consulo.
the class DefaultJavaProgramRunner method doExecute.
protected RunContentDescriptor doExecute(@Nonnull RunProfileState state, @Nonnull ExecutionEnvironment env) throws ExecutionException {
FileDocumentManager.getInstance().saveAllDocuments();
ExecutionResult executionResult;
boolean shouldAddDefaultActions = true;
if (state instanceof JavaCommandLine) {
final OwnJavaParameters parameters = ((JavaCommandLine) state).getJavaParameters();
patch(parameters, env.getRunnerSettings(), env.getRunProfile(), true);
ProcessProxy proxy = ProcessProxyFactory.getInstance().createCommandLineProxy((JavaCommandLine) state);
executionResult = state.execute(env.getExecutor(), this);
if (proxy != null) {
ProcessHandler handler = executionResult != null ? executionResult.getProcessHandler() : null;
if (handler != null) {
proxy.attach(handler);
handler.addProcessListener(new ProcessAdapter() {
@Override
public void processTerminated(@Nonnull ProcessEvent event) {
proxy.destroy();
}
});
} else {
proxy.destroy();
}
}
if (state instanceof JavaCommandLineState && !((JavaCommandLineState) state).shouldAddJavaProgramRunnerActions()) {
shouldAddDefaultActions = false;
}
} else {
executionResult = state.execute(env.getExecutor(), this);
}
if (executionResult == null) {
return null;
}
onProcessStarted(env.getRunnerSettings(), executionResult);
final RunContentBuilder contentBuilder = new RunContentBuilder(executionResult, env);
if (shouldAddDefaultActions) {
addDefaultActions(contentBuilder, executionResult);
}
return contentBuilder.showRunContent(env.getContentToReuse());
}
Aggregations