Search in sources :

Example 1 with OwnJavaParameters

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());
    }
}
Also used : CantRunException(com.intellij.execution.CantRunException) OwnJavaParameters(consulo.java.execution.configurations.OwnJavaParameters)

Example 2 with OwnJavaParameters

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;
}
Also used : Project(com.intellij.openapi.project.Project) OwnJavaParameters(consulo.java.execution.configurations.OwnJavaParameters) JavaModuleExtension(consulo.java.module.extension.JavaModuleExtension) Sdk(com.intellij.openapi.projectRoots.Sdk) Module(com.intellij.openapi.module.Module)

Example 3 with OwnJavaParameters

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();
        }
    }
}
Also used : OwnJavaParameters(consulo.java.execution.configurations.OwnJavaParameters) Module(com.intellij.openapi.module.Module) PrintWriter(java.io.PrintWriter)

Example 4 with OwnJavaParameters

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 &lt;none&gt; 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);
    }
}
Also used : JavaSdkType(com.intellij.openapi.projectRoots.JavaSdkType) OwnJavaParameters(consulo.java.execution.configurations.OwnJavaParameters) Sdk(com.intellij.openapi.projectRoots.Sdk) IOException(java.io.IOException) File(java.io.File) PrintWriter(java.io.PrintWriter)

Example 5 with OwnJavaParameters

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());
}
Also used : ProcessAdapter(com.intellij.execution.process.ProcessAdapter) CapturingProcessAdapter(com.intellij.execution.process.CapturingProcessAdapter) OwnJavaParameters(consulo.java.execution.configurations.OwnJavaParameters) ProcessEvent(com.intellij.execution.process.ProcessEvent) ProcessHandler(com.intellij.execution.process.ProcessHandler) ExecutionResult(com.intellij.execution.ExecutionResult)

Aggregations

OwnJavaParameters (consulo.java.execution.configurations.OwnJavaParameters)13 Sdk (com.intellij.openapi.projectRoots.Sdk)3 CantRunException (com.intellij.execution.CantRunException)2 Module (com.intellij.openapi.module.Module)2 File (java.io.File)2 PrintWriter (java.io.PrintWriter)2 ExecutionException (com.intellij.execution.ExecutionException)1 ExecutionResult (com.intellij.execution.ExecutionResult)1 ParametersList (com.intellij.execution.configurations.ParametersList)1 DefaultRunExecutor (com.intellij.execution.executors.DefaultRunExecutor)1 CapturingProcessAdapter (com.intellij.execution.process.CapturingProcessAdapter)1 ProcessAdapter (com.intellij.execution.process.ProcessAdapter)1 ProcessEvent (com.intellij.execution.process.ProcessEvent)1 ProcessHandler (com.intellij.execution.process.ProcessHandler)1 ExecutionEnvironment (com.intellij.execution.runners.ExecutionEnvironment)1 ProgramRunner (com.intellij.execution.runners.ProgramRunner)1 Project (com.intellij.openapi.project.Project)1 JavaSdkType (com.intellij.openapi.projectRoots.JavaSdkType)1 JavaModuleExtension (consulo.java.module.extension.JavaModuleExtension)1 IOException (java.io.IOException)1