use of com.intellij.execution.process.ProcessEvent in project intellij-community by JetBrains.
the class RemoteProcessSupport method getProcessListener.
private ProcessListener getProcessListener(@NotNull final Pair<Target, Parameters> key) {
return new ProcessListener() {
@Override
public void startNotified(ProcessEvent event) {
ProcessHandler processHandler = event.getProcessHandler();
processHandler.putUserData(ProcessHandler.SILENTLY_DESTROY_ON_CLOSE, Boolean.TRUE);
Info o;
synchronized (myProcMap) {
o = myProcMap.get(key);
if (o instanceof PendingInfo) {
myProcMap.put(key, new PendingInfo(((PendingInfo) o).ref, processHandler));
}
}
}
@Override
public void processTerminated(ProcessEvent event) {
if (dropProcessInfo(key, null, event.getProcessHandler())) {
fireModificationCountChanged();
}
}
@Override
public void processWillTerminate(ProcessEvent event, boolean willBeDestroyed) {
if (dropProcessInfo(key, null, event.getProcessHandler())) {
fireModificationCountChanged();
}
}
@Override
public void onTextAvailable(ProcessEvent event, Key outputType) {
String text = StringUtil.notNullize(event.getText());
if (outputType == ProcessOutputTypes.STDERR) {
LOG.warn(text.trim());
} else {
LOG.info(text.trim());
}
RunningInfo result = null;
PendingInfo info;
synchronized (myProcMap) {
Info o = myProcMap.get(key);
logText(key.second, event, outputType, o);
if (o instanceof PendingInfo) {
info = (PendingInfo) o;
if (outputType == ProcessOutputTypes.STDOUT) {
String prefix = "Port/ID:";
if (text.startsWith(prefix)) {
String pair = text.substring(prefix.length()).trim();
int idx = pair.indexOf("/");
result = new RunningInfo(info.handler, Integer.parseInt(pair.substring(0, idx)), pair.substring(idx + 1));
myProcMap.put(key, result);
myProcMap.notifyAll();
}
} else if (outputType == ProcessOutputTypes.STDERR) {
info.stderr.append(text);
}
} else {
info = null;
}
}
if (result != null) {
synchronized (info.ref) {
info.ref.set(result);
info.ref.notifyAll();
}
fireModificationCountChanged();
try {
RemoteDeadHand.TwoMinutesTurkish.startCooking("localhost", result.port);
} catch (Throwable e) {
LOG.warn("The cook failed to start due to " + ExceptionUtil.getRootCause(e));
}
}
}
};
}
use of com.intellij.execution.process.ProcessEvent in project intellij-community by JetBrains.
the class RmiStubsGenerator method generateRmiStubs.
private ExitCode generateRmiStubs(final CompileContext context, Map<ModuleBuildTarget, Collection<ClassItem>> remoteClasses, ModuleChunk chunk, OutputConsumer outputConsumer) {
ExitCode exitCode = ExitCode.NOTHING_DONE;
final Collection<File> classpath = ProjectPaths.getCompilationClasspath(chunk, false);
final StringBuilder buf = new StringBuilder();
for (File file : classpath) {
if (buf.length() > 0) {
buf.append(File.pathSeparator);
}
buf.append(file.getPath());
}
final String classpathString = buf.toString();
final String rmicPath = getPathToRmic(chunk);
final RmicCompilerOptions options = getOptions(context);
final List<ModuleBuildTarget> targetsProcessed = new ArrayList<>(remoteClasses.size());
for (Map.Entry<ModuleBuildTarget, Collection<ClassItem>> entry : remoteClasses.entrySet()) {
try {
final ModuleBuildTarget target = entry.getKey();
final Collection<String> cmdLine = createStartupCommand(target, rmicPath, classpathString, options, entry.getValue());
final Process process = Runtime.getRuntime().exec(ArrayUtil.toStringArray(cmdLine));
final BaseOSProcessHandler handler = new BaseOSProcessHandler(process, StringUtil.join(cmdLine, " "), null) {
@NotNull
@Override
protected Future<?> executeOnPooledThread(@NotNull Runnable task) {
return SharedThreadPool.getInstance().executeOnPooledThread(task);
}
};
final RmicOutputParser stdOutParser = new RmicOutputParser(context, getPresentableName());
final RmicOutputParser stdErrParser = new RmicOutputParser(context, getPresentableName());
handler.addProcessListener(new ProcessAdapter() {
@Override
public void onTextAvailable(ProcessEvent event, Key outputType) {
if (outputType == ProcessOutputTypes.STDOUT) {
stdOutParser.append(event.getText());
} else if (outputType == ProcessOutputTypes.STDERR) {
stdErrParser.append(event.getText());
}
}
@Override
public void processTerminated(ProcessEvent event) {
super.processTerminated(event);
}
});
handler.startNotify();
handler.waitFor();
targetsProcessed.add(target);
if (stdErrParser.isErrorsReported() || stdOutParser.isErrorsReported()) {
break;
} else {
final int exitValue = handler.getProcess().exitValue();
if (exitValue != 0) {
context.processMessage(new CompilerMessage(getPresentableName(), BuildMessage.Kind.ERROR, "RMI stub generation failed"));
break;
}
}
} catch (IOException e) {
context.processMessage(new CompilerMessage(getPresentableName(), e));
break;
}
}
// registering generated files
final Map<File, File[]> fsCache = new THashMap<>(FileUtil.FILE_HASHING_STRATEGY);
for (ModuleBuildTarget target : targetsProcessed) {
final Collection<ClassItem> items = remoteClasses.get(target);
for (ClassItem item : items) {
File[] children = fsCache.get(item.parentDir);
if (children == null) {
children = item.parentDir.listFiles();
if (children == null) {
children = EMPTY_FILE_ARRAY;
}
fsCache.put(item.parentDir, children);
}
final Collection<File> files = item.selectGeneratedFiles(children);
if (!files.isEmpty()) {
final Collection<String> sources = item.compiledClass.getSourceFilesPaths();
for (File generated : files) {
try {
outputConsumer.registerOutputFile(target, generated, sources);
} catch (IOException e) {
context.processMessage(new CompilerMessage(getPresentableName(), e));
}
}
}
}
}
return exitCode;
}
use of com.intellij.execution.process.ProcessEvent in project intellij-community by JetBrains.
the class AppletConfiguration method getState.
@Override
public RunProfileState getState(@NotNull final Executor executor, @NotNull final ExecutionEnvironment env) throws ExecutionException {
return new JavaCommandLineState(env) {
private AppletHtmlFile myHtmlURL = null;
@Override
protected JavaParameters createJavaParameters() throws ExecutionException {
final JavaParameters params = new JavaParameters();
myHtmlURL = getHtmlURL();
if (myHtmlURL != null) {
final int classPathType = myHtmlURL.isHttp() ? JavaParameters.JDK_ONLY : JavaParameters.JDK_AND_CLASSES;
final RunConfigurationModule runConfigurationModule = getConfigurationModule();
JavaParametersUtil.configureModule(runConfigurationModule, params, classPathType, ALTERNATIVE_JRE_PATH_ENABLED ? ALTERNATIVE_JRE_PATH : null);
final String policyFileParameter = getPolicyFileParameter();
if (policyFileParameter != null) {
params.getVMParametersList().add(policyFileParameter);
}
params.getVMParametersList().addParametersString(VM_PARAMETERS);
params.setMainClass("sun.applet.AppletViewer");
params.getProgramParametersList().add(myHtmlURL.getUrl());
}
return params;
}
@Override
@NotNull
protected OSProcessHandler startProcess() throws ExecutionException {
final OSProcessHandler handler = super.startProcess();
final AppletHtmlFile htmlUrl = myHtmlURL;
if (htmlUrl != null) {
handler.addProcessListener(new ProcessAdapter() {
@Override
public void processTerminated(ProcessEvent event) {
htmlUrl.deleteFile();
}
});
}
return handler;
}
};
}
use of com.intellij.execution.process.ProcessEvent in project intellij-community by JetBrains.
the class DefaultJavaProgramRunner method doExecute.
@Override
protected RunContentDescriptor doExecute(@NotNull RunProfileState state, @NotNull ExecutionEnvironment env) throws ExecutionException {
FileDocumentManager.getInstance().saveAllDocuments();
ExecutionResult executionResult;
boolean shouldAddDefaultActions = true;
if (state instanceof JavaCommandLine) {
final JavaParameters 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(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());
}
use of com.intellij.execution.process.ProcessEvent in project intellij-plugins by JetBrains.
the class KarmaConsoleView method registerConsoleContent.
@NotNull
private Content registerConsoleContent(@NotNull final RunnerLayoutUi ui) {
ui.getOptions().setMinimizeActionEnabled(false);
final Content consoleContent = ui.createContent(ExecutionConsole.CONSOLE_CONTENT_ID, getComponent(), "Test Run", AllIcons.Debugger.Console, getPreferredFocusableComponent());
ui.addContent(consoleContent, 1, PlaceInGrid.bottom, false);
consoleContent.setCloseable(false);
final KarmaRootTestProxyFormatter rootFormatter = new KarmaRootTestProxyFormatter(this, myServer);
if (myServer.areBrowsersReady()) {
KarmaUtil.selectAndFocusIfNotDisposed(ui, consoleContent, false, false);
} else {
myServer.onPortBound(() -> {
KarmaUtil.selectAndFocusIfNotDisposed(ui, consoleContent, false, false);
scheduleBrowserCapturingSuggestion();
});
}
final ProcessAdapter listener = new ProcessAdapter() {
@Override
public void processTerminated(ProcessEvent event) {
if (myServer.getProcessHandler().isProcessTerminated()) {
rootFormatter.onServerProcessTerminated();
printServerFinishedInfo();
}
rootFormatter.onTestRunProcessTerminated();
}
};
myExecutionSession.getProcessHandler().addProcessListener(listener);
Disposer.register(this, new Disposable() {
@Override
public void dispose() {
myExecutionSession.getProcessHandler().removeProcessListener(listener);
}
});
return consoleContent;
}
Aggregations